Skip to content

Instantly share code, notes, and snippets.

View eksiscloud's full-sized avatar

Jakke Lehtonen eksiscloud

View GitHub Profile
@eksiscloud
eksiscloud / wpcli.sh
Created October 23, 2019 14:29
WP CLI without root/sudo
#!/usr/bin/env bash
#
# install WP CLI at your home-dir. Change if you want something else
# make executable: chmod u+x wpcli.sh
# use ./wpcli.sh
#
mkdir ~/wp-cli
wget -q https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar -O ~/wp-cli/wp
chmod 755 ~/wp-cli/wp
export PATH="$PATH:~/wp-cli"
@eksiscloud
eksiscloud / wp_widget_backup
Created October 23, 2019 19:26
Wordpress: Backup active widgets and locations
#!/usr/bin/env bash
#
# Backup your widgets before you give a try to new theme
#
# https://guides.wp-bullet.com/using-wp-cli-backup-restore-wordpress-widgets/
#
# create array of all widgets in the wp_options table
WIDGETSARRAY=($(wp db query "SELECT option_name FROM $(wp db prefix --allow-root)options WHERE option_name LIKE 'widget\_%'" --skip-column-names --allow-root))
# loop through widgets
@eksiscloud
eksiscloud / wp_widget_restore
Created October 23, 2019 19:30
Wordpress: Restore active widgets and locations
#!/usr/bin/env bash
#
# Restore your widgets after tried new theme
#
# https://guides.wp-bullet.com/using-wp-cli-backup-restore-wordpress-widgets/
#
# loop through widget backups
for WIDGETBACKUP in /tmp/widgets/*.txt
do
# extract filename
@eksiscloud
eksiscloud / policy
Last active October 26, 2019 18:12
AWS Lambda: Custom IAM user policy for SES forwarding
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents"
],
@eksiscloud
eksiscloud / monitrc
Last active October 28, 2019 18:45
Starting point for new install of Monit server monitoring
set daemon 60 #check services every 60 seconds
set logfile /var/log/monit.log
set idfile /var/lib/monit/id
set statefile /var/lib/monit/state
#Event queue
set eventqueue
basedir /var/lib/monit/events # set the base directory where events will be stored
slots 100 # optionally limit the queue size
@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>';
}