Skip to content

Instantly share code, notes, and snippets.

View eksiscloud's full-sized avatar

Jakke Lehtonen eksiscloud

View GitHub Profile
@eksiscloud
eksiscloud / functions.php
Created October 28, 2019 09:13
Wordpress: Use Amazon SES with PHPMailer
add_action( 'phpmailer_init', 'set_phpmailer_details' );
function set_phpmailer_details( $phpmailer ) {
$phpmailer->isSMTP();
$phpmailer->Host = 'SMTP_endpoint'; //Amazon SES SMTP endpoint for your region
$phpmailer->SMTPAuth = true;
$phpmailer->Port = 587;
$phpmailer->Username = 'Amazon_SES_USERNAME';
$phpmailer->Password = 'Amazon_SES_PASSWORD';
$phpmailer->SMTPSecure = 'tls';
$phpmailer->From = get_option('admin_email'); //your verified email address
@eksiscloud
eksiscloud / functions.php
Last active November 5, 2019 12:07
Wordpress: Show ID of post/page at admin
add_filter('manage_posts_columns', 'posts_columns_id', 5);
add_action('manage_posts_custom_column', 'posts_custom_id_columns', 5, 2);
add_filter('manage_pages_columns', 'posts_columns_id', 5);
add_action('manage_pages_custom_column', 'posts_custom_id_columns', 5, 2);
function posts_columns_id($defaults){
$defaults['wps_post_id'] = __('ID');
return $defaults;
}
function posts_custom_id_columns($column_name, $id){
@eksiscloud
eksiscloud / plugin.php
Created November 6, 2019 08:46
Wordpress: Plugin headers
<?php
/*
Plugin Name: NeatSnippet
Description: Show at plugin description | You can have even <a href="example.com">a link</a> here
*/
/* Start Adding Functions Below this Line */
/* Stop Adding Functions Below this Line */
?>
@eksiscloud
eksiscloud / functions.php
Created November 9, 2019 22:58
Seriously Simple Podcasting: Use categories of Wordpress
// Podcast to wp-category
add_action( 'init', 'ssp_add_categories_to_podcast' );
function ssp_add_categories_to_podcast () {
register_taxonomy_for_object_type( 'category', 'podcast' );
}
add_action( 'pre_get_posts', 'ssp_add_podcast_to_category_archives' );
function ssp_add_podcast_to_category_archives( $query ){
if( is_admin() ) {
@eksiscloud
eksiscloud / functions.php
Created November 13, 2019 08:48
Wordpress archives of posts: Alphabetically order
function custom_pre_get_posts($query) {
// validate
if(!is_admin() && $query->is_main_query()) {
if(is_archive()) {
$query->set('orderby', 'title'); // order posts by title
$query->set('order', 'ASC'); // and in ascending order
}
}
}
@eksiscloud
eksiscloud / functions.php
Created December 4, 2019 14:43
Add WooCommerce customer username to edit/view order admin page
// Add WooCommerce customer username to edit/view order admin page
add_action( 'woocommerce_admin_order_data_after_billing_address', 'woo_display_order_username', 10, 1 );
function woo_display_order_username( $order ){
global $post;
$customer_user = get_post_meta( $post->ID, '_customer_user', true );
echo '<p><strong style="display: block;">'.__('Customer Username').':</strong> <a href="user-edit.php?user_id=' . $customer_user . '">' . get_user_meta( $customer_user, 'nickname', true ) . '</a></p>';
}
@eksiscloud
eksiscloud / functions.php
Created December 4, 2019 14:47
Woocommerce: Remove euro symbol without CSS
function eksis_remove_wc_currency_symbol( $currency_symbol, $currency ) {
if (!is_cart()){
$currency_symbol = '';
return $currency_symbol;
}
}
add_filter('woocommerce_currency_symbol', 'eksis_remove_wc_currency_symbol', 10, 2);
@eksiscloud
eksiscloud / functions.php
Last active June 22, 2020 10:20
Wordpress: Allow/disallow uploading different type/mime files
add_filter( 'upload_mimes', 'my_mime_types', 1, 1 );
function my_mime_types( $mime_types ) {
$mime_types['jpg|jpeg|jpe'] = 'image/jpeg';
$mime_types['gif'] = 'image/gif';
$mime_types['png'] = 'image/png';
$mime_types['bmp'] = 'image/bmp';
$mime_types['tiff|tif'] = 'image/tiff';
$mime_types['ico'] = 'image/x-icon';
$mime_types['asf|asx'] = 'video/x-ms-asf';
@eksiscloud
eksiscloud / wget
Last active March 19, 2021 12:03
Warm up of reverse proxy like Varnish using wget
wget --spider -o wget.log -e robots=off -r -l 5 -p -S -T3 --header="X-Bypass-Cache: 1" -H --domains=example.tld --show-progress www.example.tld
# Options explained
# --spider: Crawl the site
# -o wget.log: Keep the log
# -e robots=off: Ignore robots.txt
# -r: specify recursive download
# -l 5: Depth to search. I.e 1 means 'crawl the homepages'. 2 means 'crawl the homepage and all pages it links to'...
# -p: get all images, etc. needed to display HTML page
# -S: print server response (to the log)
@eksiscloud
eksiscloud / example.tld.conf
Last active December 22, 2019 20:40
Nginx: Virtual host and SSL + HTTP/2 before Varnish in port 8080 (backend is Apache2), redirecting from port 80 to port 443, map for normal 301 redirects
map_hash_bucket_size 256;
map $request_uri $new_uri {
include /etc/nginx/snippets/includes/301.example.tld.map;
}
server {
listen <ip-address>:443 ssl http2;
server_name example.tld www.example.tld;