Skip to content

Instantly share code, notes, and snippets.

@JPry
Last active September 14, 2020 09:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JPry/623fbbff1d008f783f2406711e4a6813 to your computer and use it in GitHub Desktop.
Save JPry/623fbbff1d008f783f2406711e4a6813 to your computer and use it in GitHub Desktop.
<?php
/**
* Plugin Name: JPry local tweaks.
* Plugin URI: https://gist.github.com/JPry/623fbbff1d008f783f2406711e4a6813
* Description: Local development tweaks. Place this in the mu-plugins directory.
* Version: 1.0
* Author: Jeremy Pry
* Author URI: http://jeremypry.com/
* License: MIT
*
* @package JPry\LocalTweaks
*/
// Prevent direct access to this file.
if ( ! defined( 'ABSPATH' ) ) {
die( "You can't do anything by accessing this file directly." );
}
// No handling fatal error handling on local.
add_filter( 'wp_fatal_error_handler_enabled', '__return_false' );
// Filter the length of time the auth cookie is valid..
add_filter( 'auth_cookie_expiration', function( $length ) {
return 30 * DAY_IN_SECONDS;
} );
/**
* Disable updates for plugins controlled by Git.
*
* @param stdClass $value The transient value.
*/
add_filter( 'pre_set_site_transient_update_plugins', function( $value ) {
if ( ! isset( $value->response ) ) {
return $value;
}
foreach ( $value->response as $file => $data ) {
$split = explode( '/', $file );
$maybe_git = WP_PLUGIN_DIR . "/{$split[0]}/.git";
if ( file_exists( $maybe_git ) && is_dir( $maybe_git ) ) {
$value->no_update[ $file ] = $data;
unset( $value->response[ $file ] );
}
}
return $value;
}, 20 );
// In some cases, a local setup can't connect to wordpress.org, and these trigger errors.
add_action( 'admin_init', function() {
remove_action( 'load-plugins.php', 'wp_update_plugins' );
remove_action( 'load-update.php', 'wp_update_plugins' );
remove_action( 'load-update-core.php', 'wp_update_plugins' );
remove_action( 'admin_init', '_maybe_update_plugins' );
remove_action( 'wp_update_plugins', 'wp_update_plugins' );
}, 20 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment