: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
* The admin-specific functionality of the plugin.
* @link https://passwordprotectwp.com
* @package Password_Protect_Page
* @subpackage Password_Protect_Page/admin
* The admin-specific functionality of the plugin.
* Defines the plugin name, version, and two examples hooks for how to
* enqueue the admin-specific stylesheet and JavaScript.
* @package Password_Protect_Page
* @subpackage Password_Protect_Page/admin
* @author BWPS <hello@preventdirectaccess.com>
* @var string $plugin_name The ID of this plugin.
* The version of this plugin.
* @var string $version The current version of this plugin.
* @var PPW_Password_Services
* @var PPW_Password_Subscribe
private $subscribe_services;
* Asset service in Free version
* @var PPW_Asset_Services
private $free_asset_services;
* Initialize the class and set its properties.
* @param string $plugin_name The name of this plugin.
* @param string $version The version of this plugin.
public function __construct( $plugin_name, $version ) {
$this->plugin_name = $plugin_name;
$this->version = $version;
$this->free_services = new PPW_Password_Services();
$this->subscribe_services = new PPW_Password_Subscribe();
$this->free_asset_services = new PPW_Asset_Services( null, null );
* Register the stylesheets and javascript for the admin area.
public function enqueue_assets() {
* This function is provided for demonstration purposes only.
* An instance of this class should be passed to the run() function
* defined in Password_Protect_Page_Loader as all of the hooks are defined
* in that particular class.
* The Password_Protect_Page_Loader will then create the relationship
* between the defined hooks and the functions defined in this
if ( function_exists( 'get_current_screen' ) ) {
$is_pro_activated = apply_filters( PPW_Constants::HOOK_IS_PRO_ACTIVATE, false );
$screen = get_current_screen();
$assert_services = new PPW_Asset_Services( $screen->id, $_GET ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- We no need to verify nonce for enqueue assets
if ( ! $is_pro_activated ) {
$assert_services->load_assets_for_entire_site_tab();
$assert_services->load_assets_for_general_tab();
$assert_services->load_assets_for_entire_site_page();
$assert_services->load_assets_for_shortcode_page();
$assert_services->load_assets_for_external_page();
$assert_services->load_assets_for_external_configuration();
$assert_services->load_assets_for_shortcodes();
$assert_services->load_css_hide_feature_set_password_wp();
$assert_services->load_js_show_notice_deactivate_plugin();
$assert_services->load_assets_for_misc_tab();
$assert_services->load_assets_for_category_page();
$assert_services->load_assets_for_troubleshoot_tab();
$assert_services->load_assets_for_shortcode_setting();
wp_enqueue_style( 'ppw-pro-sidebar-css', PPW_DIR_URL . 'admin/css/ppw-pro-sidebar.css', array(), PPW_VERSION, 'all');
* Add metabox to set password in page and post
public function ppw_free_add_custom_meta_box_to_edit_page() {
include PPW_DIR_PATH . 'includes/views/meta-box/view-ppw-meta-box.php';
public function ppw_free_set_password() {
$setting_keys = array( 'save_password', 'id_page_post', 'is_role_selected', 'ppwp_multiple_password' );
if ( ppw_free_error_before_create_password( $_REQUEST, $setting_keys ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- We handle nonce verification in this function
'message' => PPW_Constants::BAD_REQUEST_MESSAGE,
if ( ! isset( $_REQUEST['settings'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- We handle nonce verification above.
'message' => PPW_Constants::BAD_REQUEST_MESSAGE,
$data_settings = $_REQUEST['settings']; // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- We no need to verify nonce for enqueue assets, Don't need use wp_unslash(), and no need to sanitize settings params.
$new_role_password = $data_settings['save_password'];
$id = $data_settings['id_page_post'];
$role_selected = $data_settings['is_role_selected'];
$new_global_passwords = is_array( $data_settings['ppwp_multiple_password'] ) ? $data_settings['ppwp_multiple_password'] : array();
$free_services = new PPW_Password_Services();
$current_roles_password = $free_services->create_new_password( $id, $role_selected, $new_global_passwords, $new_role_password );
wp_send_json( $current_roles_password );
* Check when user enter password
public function ppw_handle_enter_password() {
if ( ! array_key_exists( 'post_password', $_POST ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing -- This request for default login form postpass action of WordPress with the action 'post_password' for the hook 'login_form_ppw_postpass', will handle on others.
wp_safe_redirect( wp_get_referer() );
// Get post_id from referer url if Post data is not exist post_id.
$post_id = ppw_get_post_id_from_request();
if ( empty( $post_id ) ) {
wp_safe_redirect( wp_get_referer() );
$password = wp_unslash( $_POST['post_password'] ); // phpcs:ignore -- not sanitize password because we allow all character.
$this->free_services->handle_after_enter_password_in_password_form( $post_id, $password );
* This feature will support some user which use postpass and enable protection type of plugin.
public function ppw_handle_enter_password_for_default_action() {
if ( ! array_key_exists( 'post_password', $_POST ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing -- This request for default login form postpass action of WordPress for the hook 'login_form_postpass', will handle on others.
// Get post id from request.
$post_id = ppw_get_post_id_from_request();
if ( empty( $post_id ) ) {
// Get post type to check post type selected in setting page.
$post_type = get_post_type( $post_id );
$password = wp_unslash( $_POST['post_password'] ); // phpcs:ignore -- not sanitize password because we allow all character and verify nonce for the hook 'login_form_postpass'.
if ( ! empty( $post_type ) && ppw_is_post_type_selected_in_setting( $post_type ) ) {
$this->free_services->handle_after_enter_password_in_password_form( $post_id, $password );
* Handle redirect after enter password
public function ppw_handle_redirect_after_enter_password( $is_valid ) {
$free_service = new PPW_Password_Services();
$free_service->handle_redirect_after_enter_password( $is_valid );
* Add row action protect/unprotect posts and pages
* @param array $actions An array of row action.
* @param stdClass $post The post object.
public function ppw_custom_row_action( $actions, $post ) {
$post_status = $post->post_status;
$post_type = $post->post_type;
if ( ! in_array( $post_type, array( 'page', 'post' ), true ) || 'trash' === $post_status || ! current_user_can( 'edit_post', $post_id ) ) {
wp_enqueue_style( 'ppw-row-action-css', PPW_DIR_URL . 'admin/css/ppw-row-action.css', array(), PPW_VERSION, 'all');
wp_enqueue_script( 'ppw-row-action-js', PPW_DIR_URL . 'admin/js/dist/ppw-row-action.js', array( 'jquery' ), PPW_VERSION, true );
'ajax_url' => admin_url( 'admin-ajax.php' ),
'nonce' => wp_create_nonce( PPW_Constants::ROW_ACTION_NONCE ),
'plugin_name' => 'Password Protect WordPress Lite',
$this->free_asset_services->load_toastr_lib();
return $this->free_services->generate_custom_row_action( $actions, $post );
* Handle feature update post status in row action.
public function handle_update_post_status() {
$_request = wp_unslash( $_REQUEST );
if ( ! isset( $_request['nonce'] ) || ! wp_verify_nonce( $_request['nonce'], PPW_Constants::ROW_ACTION_NONCE ) ) {
'message' => PPW_Constants::BAD_REQUEST_MESSAGE,
return $this->free_services->update_post_status( $_request );
public function ppw_add_menu() {
$setting_page = new PPW_Settings();
add_menu_page( 'Protect Password Settings', 'Password Protect WordPress', ppw_get_allowed_capability(), PPW_Constants::MENU_NAME, array(
), PPW_DIR_URL . 'admin/images/ppw-icon-20x20.png' );
add_submenu_page( PPW_Constants::MENU_NAME, __( 'PPWP › Settings', PPW_Constants::DOMAIN ), __( 'Settings', PPW_Constants::DOMAIN ), ppw_get_allowed_capability(), PPW_Constants::MENU_NAME );
$this->partial_protection_submenu();
// Hide sitewide when Pro activate.
if ( ! is_pro_active_and_valid_license() ) {
$this->sitewide_submenu();
$this->load_external_submenu();
public function sitewide_submenu() {
$setting_page = new PPW_Sitewide_Settings();
add_submenu_page( PPW_Constants::MENU_NAME, __( 'PPWP › Sitewide', PPW_Constants::DOMAIN ), __( 'Sitewide Protection', PPW_Constants::DOMAIN ), ppw_get_allowed_capability(), PPW_Constants::SITEWIDE_PAGE_PREFIX, array(
public function load_external_submenu() {
$setting_page = new PPW_External_Settings();
PPW_Constants::MENU_NAME,
__( 'PPWP › Integrations', PPW_Constants::DOMAIN ),
__( 'Integrations', PPW_Constants::DOMAIN ),
ppw_get_allowed_capability(),
PPW_Constants::EXTERNAL_SERVICES_PREFIX,
* Add Partial Protection submenu.
public function partial_protection_submenu() {
$setting_page = new PPW_Partial_Protection_Settings();
add_submenu_page( PPW_Constants::MENU_NAME, __( 'PPWP › Partial Protection', PPW_Constants::DOMAIN ), __( 'Partial Protection', PPW_Constants::DOMAIN ),
ppw_get_allowed_capability(), PPW_Constants::PCP_PAGE_PREFIX, array(
* Hide sitewide tab content in Free version.
public function ppw_handle_custom_tab( $tabs ) {
$tab_key = array_search( 'entire_site', $tabs, true );
if ( false !== $tab_key ) {
unset( $tabs[ $tab_key ] );
* Hide sitewide tab in Free version.
public function ppw_handle_add_new_tab( $tabs ) {
$tab_key = array_search( 'entire_site', array_column( $tabs, 'tab' ), true );
if ( false !== $tab_key ) {
unset( $tabs[ $tab_key ] );
* Handle hide shortcode tab in Free version.
* @param array $tabs List of tabs in setting page.
public function ppw_handle_hide_shortcode_tab( $tabs ) {
foreach ( $tabs as $key => $tab ) {
if ( array( 'tab' => 'shortcodes', 'tab_name' => 'Shortcodes' ) === $tab ) {
* Handle hide shortcode content in Free version.
* @param array $tabs List of tabs in setting page.
public function ppw_handle_hide_shortcode_content( $tabs ) {
$tab_key = array_search( 'shortcodes', $tabs, true );
if ( false !== $tab_key ) {
unset( $tabs[ $tab_key ] );
public function ppw_free_render_content_general() {
<div class="ppw_setting_page">
include PPW_DIR_PATH . 'includes/views/general/view-ppw-general.php';
include PPW_DIR_PATH . 'includes/views/sidebar/view-ppw-sidebar.php';
public function ppw_free_render_content_entire_site() {
<div class="ppw_setting_page">
include PPW_DIR_PATH . 'includes/views/entire-site/view-ppw-entire-site.php';
include PPW_DIR_PATH . 'includes/views/sidebar/view-ppw-sidebar.php';
* Render shortcodes content.
public function ppw_free_render_content_shortcodes() {
<div class="ppw_setting_page">
include PPW_DIR_PATH . 'includes/views/shortcode/view-ppw-shortcode-settings.php';
ppw_free_render_sidebar();
public function ppw_free_render_content_pcp_general_tab() {
<div class="ppw_setting_page">
include PPW_DIR_PATH . 'includes/views/partial-protection/view-ppw-pcp-general.php';
ppw_free_render_sidebar();
public function ppw_free_render_content_external_recaptcha() {
<div class="ppw_setting_page">
include PPW_DIR_PATH . 'includes/views/external/view-ppw-general.php';
ppw_free_render_sidebar();
public function ppw_free_render_content_external_configuration() {
<div class="ppw_setting_page">
include PPW_DIR_PATH . 'includes/views/external/view-ppw-general-configuration.php';
ppw_free_render_sidebar();
* Render Master Passwords tab
public function ppw_free_render_content_master_passwords() {
wp_enqueue_script( 'ppw-master-passwords-js', PPW_DIR_URL . 'includes/views/master-passwords/assets/ppw-master-passwords.js', array( 'jquery' ), PPW_VERSION, true );
wp_enqueue_style( 'ppw-master-passwords-css', PPW_DIR_URL . 'includes/views/master-passwords/assets/ppw-master-passwords.css', array(), PPW_VERSION, 'all' );
$post_types_selected = $this->free_services->get_protection_post_types_select();
$protection_types = apply_filters( 'ppw_master_password_protection_types', array() );
$allowed_protection_type = ppw_allowed_master_protection_type();
'ppw-master-passwords-js',
'restUrl' => get_rest_url(),
'nonce' => wp_create_nonce( 'wp_rest' ),
'roles' => array_keys( get_editable_roles() ),
'postTypes' => $post_types_selected,
'pro' => is_pro_active_and_valid_license(),
'protectionTypes' => $protection_types,
'allowedProtectionType' => $allowed_protection_type,
include PPW_DIR_PATH . 'includes/views/master-passwords/view-ppw-master-passwords.php';