Skip to content

Instantly share code, notes, and snippets.

Avatar
🖥️
🍕🍕🍕

Caleb Burks WPprodigy

🖥️
🍕🍕🍕
View GitHub Profile
@WPprodigy
WPprodigy / example.php
Last active Jul 29, 2020
Avoid 2FA during JSON API OAuth flow
View example.php
<?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 Jul 29, 2020
Prevent 2FA from being enforced for JP JSON API requests.
View example.php
<?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;
View vip-remove-old-revisions-command.php
<?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 Dec 21, 2019
WP local site creation script. Made for use with https://laravel.com/docs/6.x/valet
View wp-create
#!/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 Jul 3, 2019
Conditionally remove a SRM redirect.
View srm-filter.php
<?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
Give a default error message when login attempt failed.
View functions.php
<?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 Feb 28, 2019
WC backend performance enhancements
View functions.php
<?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 Sep 9, 2020
Co-Author Plus ES query fix
View functions.php
<?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() ) {
@WPprodigy
WPprodigy / functions.php
Created Nov 12, 2018
Specify which users should show up in Edit Flow user lists.
View functions.php
<?php
// Specify which users should show up in Edit Flow user lists.
add_filter( 'ef_users_select_form_get_users_args', function( $args ) {
unset( $args['who'] );
$args['role__in'] = array( 'administrator', 'editor', 'author' );
return $args;
} );
@WPprodigy
WPprodigy / functions.php
Last active Nov 3, 2018
Disable WordPress email notifications for pingbacks and trackbacks.
View functions.php
<?php
// Don't send notification emails for pingbacks and trackbacks.
add_filter( 'notify_post_author', function( $maybe_notify, $comment_ID ) {
$comment_type = get_comment_type( $comment_ID );
if ( in_array( $comment_type, array( 'pingback', 'trackback' ), true ) ) {
$maybe_notify = false;
}
You can’t perform that action at this time.