Skip to content

Instantly share code, notes, and snippets.

View WPprodigy's full-sized avatar
🖥️
🍕🍕🍕

Caleb Burks WPprodigy

🖥️
🍕🍕🍕
View GitHub Profile
@WPprodigy
WPprodigy / ignore-cron-events.php
Created December 23, 2022 09:50
Prevent certain cron events from existing
<?php
function get_cron_events_to_ignore() {
return [
'a8c_cron_control_force_publish_missed_schedules',
'a8c_cron_control_confirm_scheduled_posts',
];
}
// If an ignorable cron event runs, let's unschedule it so it runs no more.
@WPprodigy
WPprodigy / action-scheduler.php
Last active November 17, 2021 09:48
Dynamic Queue adjustments for autoscaling Action Scheduler.
<?php
/*
* Dynamic Queue adjustments for autoscaling Action Scheduler.
*
* Every few minutes, this checks to see if the AS queue has exceeded a certain
* threshold of "due now" actions. And if so, will schedule additional queues to run
* concurrently in cron until the queue is caught up.
*
* Scales directly off of cron control's JOB_CONCURRENCY_LIMIT.
@WPprodigy
WPprodigy / example.php
Last active July 29, 2020 13:16
Avoid 2FA during JSON API OAuth flow
<?php
/*
* Jetpack's JSON API Authorization flow needs to run free of the 2FA checks.
* JP already does additional validation on top of the normal login, so we can rely on that as the 2fa here.
*
* First we hook into wp_login right before the VIP Two_Factor_Core plugin does.
* Then if the situation is right, remove the additional 2FA login step.
*/
add_action( 'wp_login', function( $user_login, $user ) {
@WPprodigy
WPprodigy / example.php
Last active July 29, 2020 11:07
Prevent 2FA from being enforced for JP JSON API requests.
<?php
// Prevent 2FA from being enforced for JP JSON API requests.
add_filter( 'wpcom_vip_is_two_factor_forced', function( $forced ) {
$current_user = wp_get_current_user();
if ( vip_is_jetpack_xml_rpc_json_api_request() && isset( $current_user->user_login ) && 'example_username' === $current_user->user_login ) {
$forced = false;
}
return $forced;
<?php
if ( ! class_exists( 'WPCOM_VIP_CLI_Command' ) || ! ( defined( 'WP_CLI' ) && WP_CLI ) ) {
return;
}
WP_CLI::add_command( 'vip-remove-old-revisions', 'VIP_Remove_Old_Revisions_Command' );
class VIP_Remove_Old_Revisions_Command extends WPCOM_VIP_CLI_Command {
@WPprodigy
WPprodigy / wp-create
Created December 21, 2019 08:11
WP local site creation script. Made for use with https://laravel.com/docs/6.x/valet
#!/bin/bash
# Usage: wp-create sitename
if [ $# -eq 0 ]; then
echo "Need to provide the directory name to be created."
exit 1
fi
# set up new folder to house the WP install
@WPprodigy
WPprodigy / srm-filter.php
Last active July 3, 2019 22:01
Conditionally remove a SRM redirect.
<?php
/*
* Remove the SRM redirect for 'doc_id' query strings after a certain ID is reached.
*/
add_filter( 'srm_registered_redirects', function( $redirects, $requested_path ) {
// The last post ID that we want to be automatically redirected.
$redirect_breakpoint_id = 565000;
// The SRM post ID for the redirect we will conditionally remove.
@WPprodigy
WPprodigy / functions.php
Created May 14, 2019 22:24
Give a default error message when login attempt failed.
<?php
/**
* Return a more abstract error message when an invalid password was entered but for a valid username.
*
* @param null|WP_User|WP_Error $user WP_User if the user is authenticated, WP_Error or null otherwise.
*/
add_filter( 'authenticate', function( $user ) {
if ( is_wp_error( $user ) && 'incorrect_password' === $user->get_error_code() ) {
$user = new WP_Error( 'authentication_failed', __( '<strong>ERROR</strong>: Invalid username, email address or incorrect password.' ) );
@WPprodigy
WPprodigy / functions.php
Last active June 23, 2022 23:25
WC backend performance enhancements
<?php
// We don't need this query to run if it's asking for all comments (post_id = 0).
add_filter( 'wp_count_comments', function ( $count, $post_id ) {
if ( 0 === $post_id ) {
$stats = array(
'approved' => 0,
'moderated' => 0,
'spam' => 0,
'trash' => 0,
@WPprodigy
WPprodigy / functions.php
Last active September 9, 2020 20:55
Co-Author Plus ES query fix
<?php
/**
* Co-Author Plus ES query fix.
*
* With CAP, authors are attached either with the traditional
* author field or via an "author" taxonomy. So we need to check both.
*/
add_filter( 'es_posts_request', function( $es_args, $query ) {
if ( ! $query->is_author() ) {