Skip to content

Instantly share code, notes, and snippets.

@csalzano
Created June 23, 2022 02:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save csalzano/f10727dfff7614decbe663912d9c86d9 to your computer and use it in GitHub Desktop.
Save csalzano/f10727dfff7614decbe663912d9c86d9 to your computer and use it in GitHub Desktop.
WordPress plugin. Allows logged-in administrators to bypass password protection on pages and posts.
<?php
defined( 'ABSPATH' ) or exit;
/**
* Plugin Name: Password Protection Admin Bypass
* Description: Allows logged-in administrators to bypass password protection on pages and posts.
* Version: 1.0.0
* Author: Corey Salzano
* Author URI: https://github.com/csalzano
* Plugin URI: https://gist.github.com/csalzano/f10727dfff7614decbe663912d9c86d9
* License: GPLv2
*/
/**
* breakfast_password_protection_admin_bypass
*
* @param bool $required Whether the user needs to supply a password. True if password has not been
* provided or is incorrect, false if password has been supplied or is not required.
* @param WP_Post $post Post object.
* @return bool
*/
function breakfast_password_protection_admin_bypass( $required, $post )
{
if( ! $required )
{
return $required;
}
return ! in_array( 'administrator', wp_get_current_user()->roles );
}
add_filter( 'post_password_required', 'breakfast_password_protection_admin_bypass', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment