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 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 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 / 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
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 / 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 / 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 / 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 / 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 / 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-plugins.sh
Last active May 14, 2025 05:38
WP CLI + Bash: Batch installer of Wordpress plugins
#!/usr/bin/env bash
## WordPress Plugin Installer using BASH and WP-CLI
# Make executable: chmod u+x wp-plugins
# remember change WPPATH
# array of plugin slugs to install
WPPLUGINS=(
activitypub advanced-database-cleaner categorytinymce classic-editor code-snippets change-last-modified-date disable-gutenberg \