Skip to content

Instantly share code, notes, and snippets.

View decodist's full-sized avatar

Decodist decodist

View GitHub Profile
@decodist
decodist / cli-command.php
Last active August 23, 2023 13:26
WordPress CLI Class
<?php
/**
* Custom WordPress CLI Command Plugin
*
* @package decodist
* @author Jason Shaw
* @since 1.0.0
* @license GPL
*
*/
@decodist
decodist / regex.txt
Last active June 24, 2021 20:13
Regex to find URLs that include one of multiple strings or words, excluding multiple other strings or words
^https:\/\/www.domain.com(?!.*(?:exclude1|exclude2)).*(?:include1|include2|include3).*$
@decodist
decodist / wp-user-login-time.sql
Last active December 2, 2020 16:41
Find Wordpress users who have logged in at some point, but not within the past year
SELECT u.id, u.user_login, u.user_email, u.user_registered,
from_unixtime(
trim( trailing ';}}' from
RIGHT(
um.meta_value,
(LENGTH(um.meta_value) - LOCATE('login',um.meta_value) - 8)
)
)
,'%Y-%m-%d') as last_login
FROM wp_users u, wp_usermeta um
<?php
#put these at the top of any PHP file to output server errors
ini_set('error_reporting', E_ALL);
ini_set('display_errors', 'On');
@decodist
decodist / table-size.sql
Created September 10, 2020 11:53
List all MySQL tables in size order
SELECT
table_schema as `Database`,
table_name AS `Table`,
round(((data_length + index_length) / 1024 / 1024), 2) `Size in MB`
FROM information_schema.TABLES
ORDER BY (data_length + index_length) DESC;
@decodist
decodist / filesizes.sh
Created September 9, 2020 13:27
Find size of Wordpress install on Linux
#Show a list of the largest files (change "/wproot" to the actual root folder)
find /wproot -type f -exec du -Sh {} + | sort -rh | head -n 20
#Show size of WP root folder
du -sh /wproot
#Show size of wp-content folder
du -sh /wproot/wp-content
#Show size of uploads folder
@decodist
decodist / post-author.php
Last active July 7, 2020 11:00
Add author info to WordPress blog post using a shortcode
<?php
//add any of the following shortcode functions to your theme's functions.php file
//display the author name which is linked to the About page
function author_name_shortcode(){
global $post;
$post_id = $post->ID;
$author = get_the_author($post_id);
$linkedAuthor = "<a href='/about'>".$author."</a>";
return $linkedAuthor;