: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
if ( ! class_exists( 'PPW_Entire_Site_Services' ) ) {
class PPW_Entire_Site_Services {
function validate_auth_cookie_entire_site() {
$cookie_elements = $this->parse_cookie_entire_site();
if ( false === $cookie_elements ) {
if ( (int) $cookie_elements[1] < time() ) {
$password = ppw_core_get_setting_entire_site_type_string( PPW_Constants::PASSWORD_ENTIRE_SITE );
//$hash = hash_hmac( 'md5', PPW_Constants::ENTIRE_SITE_COOKIE_NAME, $password );
$hash = hash_hmac( 'md5', PPW_Constants::COOKIE_EXPIRED_SITEWIDE, $password );
return $cookie_elements[0] === $hash;
function parse_cookie_entire_site() {
$_cookie = wp_unslash( $_COOKIE );
//$cookie_name = PPW_Constants::ENTIRE_SITE_COOKIE_NAME;
$cookie_name = PPW_Constants::COOKIE_EXPIRED_SITEWIDE;
if ( empty( $_cookie[ $cookie_name ] ) ) {
$cookie = $_cookie[ $cookie_name ];
$cookie_elements = explode( '|', $cookie );
if ( count( $cookie_elements ) !== 2 ) {
* Check is valid password
public function entire_site_is_valid_password( $password ) {
$_request = wp_unslash( $_REQUEST ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Processing form data without nonce verification. - Not verify nonce for password validate.
if ( ! isset( $_request['input_wp_protect_password'] ) ) {
$password_input = $_request['input_wp_protect_password'];
$validated = md5( $password_input ) === $password;
return apply_filters( 'ppw_sitewide_valid_password', $validated );
* @param string $password Password.
public function entire_site_set_password_to_cookie( $password ) {
$expiration = time() + 7 * DAY_IN_SECONDS;
$cookie_expired = ppw_core_get_setting_type_string_sitewide( PPW_Constants::COOKIE_EXPIRED_SITEWIDE );
if ( ! empty( $cookie_expired ) ) {
$time = explode( ' ', $cookie_expired )[0];
$unit = ppw_core_get_unit_time( $cookie_expired );
$expiration = time() + (int) $time * $unit;
//$hash = hash_hmac( 'md5', PPW_Constants::ENTIRE_SITE_COOKIE_NAME, $password );
$hash = hash_hmac( 'md5', PPW_Constants::COOKIE_EXPIRED_SITEWIDE, $password );
$cookie = $hash . '|' . $expiration;
$expiration = apply_filters( 'ppw_sitewide_cookie_expiration', $expiration, $password );
ppw_free_bypass_cache_with_cookie_for_pro_version( $cookie, $expiration );
//setcookie( PPW_Constants::ENTIRE_SITE_COOKIE_NAME, $cookie, $expiration, COOKIEPATH, COOKIE_DOMAIN );
setcookie( PPW_Constants::COOKIE_EXPIRED_SITEWIDE, $cookie, $expiration, COOKIEPATH, COOKIE_DOMAIN );
* Redirect after enter password
public function entire_site_redirect_after_enter_password() {
// Can get the HTTP_REFERER first as the redirect URL that:
// Fixes the private link redirection belonged to PPP Pro.
$_server = wp_unslash( $_SERVER );
if ( ! empty( $_server['HTTP_REFERER'] ) ) {
$current_url = $_server['HTTP_REFERER'];
$current_url = add_query_arg( $wp->query_string, '', home_url( $wp->request ) );
// TODO: consider to user wp_safe_redirect.
wp_redirect( $current_url );
* Handle before update settings for entire site
public function handle_before_update_settings( $data_settings ) {
if ( array_key_exists( PPW_Constants::IS_PROTECT_ENTIRE_SITE, $data_settings ) && $data_settings[ PPW_Constants::IS_PROTECT_ENTIRE_SITE ] === "true" ) {
if ( ! array_key_exists( PPW_Constants::SET_NEW_PASSWORD_ENTIRE_SITE, $data_settings ) ) {
return $this->create_new_password( $data_settings );
if ( array_key_exists( PPW_Constants::SET_NEW_PASSWORD_ENTIRE_SITE, $data_settings ) && $data_settings[ PPW_Constants::SET_NEW_PASSWORD_ENTIRE_SITE ] === "true" ) {
return $this->change_password( $data_settings );
if ( array_key_exists( PPW_Constants::COOKIE_EXPIRED_SITEWIDE, $data_settings ) ) {
$password_for_website = ppw_core_get_setting_entire_site_type_string(PPW_Constants::PASSWORD_ENTIRE_SITE);
$data_settings[PPW_Constants::PASSWORD_ENTIRE_SITE] = $password_for_website;
// Update sitewide expiration cookies
update_option( PPW_Constants::ENTIRE_SITE_OPTIONS, $data_settings );
return delete_option( PPW_Constants::ENTIRE_SITE_OPTIONS );
* Create new password entire site
public function create_new_password( $data_settings ) {
$data_settings[ PPW_Constants::PASSWORD_ENTIRE_SITE ] = md5( $data_settings[ PPW_Constants::PASSWORD_ENTIRE_SITE ] );
update_option( PPW_Constants::ENTIRE_SITE_OPTIONS, $data_settings );
* Change password entire site
public function change_password( $data_settings ) {
$data_settings[ PPW_Constants::PASSWORD_ENTIRE_SITE ] = md5( $data_settings[ PPW_Constants::PASSWORD_ENTIRE_SITE ] );
unset( $data_settings[ PPW_Constants::SET_NEW_PASSWORD_ENTIRE_SITE ] );
update_option( PPW_Constants::ENTIRE_SITE_OPTIONS, $data_settings );