Skip to content

Instantly share code, notes, and snippets.

@pavlo-bondarchuk
Created June 15, 2020 11:01
Show Gist options
  • Select an option

  • Save pavlo-bondarchuk/8f59e0aa144e01a561d5983568a27b76 to your computer and use it in GitHub Desktop.

Select an option

Save pavlo-bondarchuk/8f59e0aa144e01a561d5983568a27b76 to your computer and use it in GitHub Desktop.
Simple return callback generator
/**
* Simple return callback generator.
*
* Usage:
* add_filter( 'filter_name', __return( 'Return value' ) );
* add_shortcode( 'year', __return( date( 'Y' ) ) );
*
* @param mixed $return
*
* @return Closure
*/
function __return( $return = null )
{
return static function () use ( $return ) {
return $return;
};
}
if ( defined( 'WP_ENV' ) && WP_ENV !== 'production' && ! is_admin() )
{
add_filter( 'pre_option_blog_public', '__return_zero' );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment