Created
June 23, 2022 02:27
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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