// Redirect author page requests. add_action( 'template_redirect', function() { global $wp_query; if ( isset( $_GET['author'] ) …
Extract data attributes from WooCommerce html tag
/** * Extraction utility to get attributes from an HTML tag. * * Example given defaults to WooCommerce "data-" attributes, but you …
Add additional scheduling options to WordPress
add_filter( 'cron_schedules', 'my_add_intervals' ); function my_add_intervals( $schedules ) { // Add a weekly …
Block access to wp-admin
// Blocks access to /wp-admin/ for any user without the identified capability (edit_options=administrator) add_action( 'init', …
Delete orphaned post meta
DELETE pm FROM wp_postmeta pm LEFT JOIN wp_posts wp ON wp.ID = pm.post_id WHERE wp.ID IS NULL …
Get a list of orphaned post meta
SELECT * FROM wp_postmeta pm LEFT JOIN wp_posts wp ON wp.ID = pm.post_id WHERE wp.ID IS NULL …
Get email domain from a user’s email
// Verbose example to show steps: $user_email = "example@domain.com"; $email_array = explode( "@", $user_email ); $email_domain = …
Restrict all site access to a specific IP address
add_action( 'init', function() { $ip = ( ! empty( $_SERVER['HTTP_CLIENT_IP'] ) ) ? $_SERVER['HTTP_CLIENT_IP'] : …
Override the WP random password generator with custom generator
// Override the WP random password generator with a custom random password. add_filter( 'random_password', 'my_random_password' ); …