Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/wp-conte.../plugins/password.../includes/services
File: class-ppw-shortcode.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* PPWP Shortcoe
[2] Fix | Delete
*/
[3] Fix | Delete
[4] Fix | Delete
if ( ! class_exists( 'PPW_Shortcode' ) ) {
[5] Fix | Delete
/**
[6] Fix | Delete
*
[7] Fix | Delete
* Class PPW_Shortcode
[8] Fix | Delete
*/
[9] Fix | Delete
class PPW_Shortcode {
[10] Fix | Delete
[11] Fix | Delete
/**
[12] Fix | Delete
* Short code attributes.
[13] Fix | Delete
*
[14] Fix | Delete
* @var array
[15] Fix | Delete
*/
[16] Fix | Delete
private $attributes;
[17] Fix | Delete
[18] Fix | Delete
/**
[19] Fix | Delete
* Supported roles.
[20] Fix | Delete
*
[21] Fix | Delete
* @var array
[22] Fix | Delete
*/
[23] Fix | Delete
private $supported_roles;
[24] Fix | Delete
[25] Fix | Delete
/**
[26] Fix | Delete
* Supported post types.
[27] Fix | Delete
*
[28] Fix | Delete
* @var array
[29] Fix | Delete
*/
[30] Fix | Delete
private $supported_post_types;
[31] Fix | Delete
[32] Fix | Delete
/**
[33] Fix | Delete
* The main class name which using to add the index.
[34] Fix | Delete
*
[35] Fix | Delete
* @var string
[36] Fix | Delete
*/
[37] Fix | Delete
private $main_class_name;
[38] Fix | Delete
[39] Fix | Delete
/**
[40] Fix | Delete
* Register the short code ppwp_content_protector with WordPress
[41] Fix | Delete
* and include the asserts for it.
[42] Fix | Delete
*/
[43] Fix | Delete
public function __construct() {
[44] Fix | Delete
$this->attributes = apply_filters(
[45] Fix | Delete
PPW_Constants::HOOK_SHORT_CODE_ATTRS,
[46] Fix | Delete
array(
[47] Fix | Delete
'passwords' => '',
[48] Fix | Delete
'headline' => PPW_Constants::DEFAULT_SHORTCODE_HEADLINE,
[49] Fix | Delete
'description' => PPW_Constants::DEFAULT_SHORTCODE_DESCRIPTION,
[50] Fix | Delete
'id' => '',
[51] Fix | Delete
'class' => '',
[52] Fix | Delete
'placeholder' => '',
[53] Fix | Delete
'button' => PPW_Constants::DEFAULT_SHORTCODE_BUTTON,
[54] Fix | Delete
'whitelisted_roles' => '',
[55] Fix | Delete
'group' => '',
[56] Fix | Delete
'label' => PPW_Constants::DEFAULT_SHORTCODE_LABEL,
[57] Fix | Delete
'error_msg' => PPW_Constants::DEFAULT_SHORTCODE_ERROR_MSG,
[58] Fix | Delete
'loading' => PPW_Constants::DEFAULT_SHORTCODE_LOADING,
[59] Fix | Delete
'on' => '',
[60] Fix | Delete
'off' => '',
[61] Fix | Delete
'acf_field' => '',
[62] Fix | Delete
'show_password' => PPW_Constants::DEFAULT_SHORTCODE_SHOW_PASSWORD,
[63] Fix | Delete
'show_password_text' => PPW_Constants::DEFAULT_SHORTCODE_SHOW_PASSWORD_TEXT,
[64] Fix | Delete
'section' => 0,
[65] Fix | Delete
'desc_above_btn' => PPW_Constants::DEFAULT_SHORTCODE_DESC_ABOVE_PWD_BTN,
[66] Fix | Delete
'desc_below_form' => PPW_Constants::DEFAULT_SHORTCODE_DESC_BELOW_PWD_FORM,
[67] Fix | Delete
)
[68] Fix | Delete
);
[69] Fix | Delete
[70] Fix | Delete
// Defined by WordPress: https://wordpress.org/support/article/roles-and-capabilities/.
[71] Fix | Delete
$this->supported_roles = apply_filters(
[72] Fix | Delete
PPW_Constants::HOOK_SUPPORTED_WHITELIST_ROLES,
[73] Fix | Delete
array(
[74] Fix | Delete
'administrator',
[75] Fix | Delete
'editor',
[76] Fix | Delete
'author',
[77] Fix | Delete
'contributor',
[78] Fix | Delete
'subscriber',
[79] Fix | Delete
)
[80] Fix | Delete
);
[81] Fix | Delete
[82] Fix | Delete
$this->supported_post_types = apply_filters(
[83] Fix | Delete
PPW_Constants::HOOK_SUPPORTED_POST_TYPES,
[84] Fix | Delete
array(
[85] Fix | Delete
'page',
[86] Fix | Delete
'post',
[87] Fix | Delete
)
[88] Fix | Delete
);
[89] Fix | Delete
[90] Fix | Delete
add_shortcode( PPW_Constants::PPW_HOOK_SHORT_CODE_NAME, array( $this, 'render_shortcode' ) );
[91] Fix | Delete
add_filter( 'ppw_content_shortcode_source', array( $this, 'render_block_content' ), 15 );
[92] Fix | Delete
[93] Fix | Delete
// Support page builder.
[94] Fix | Delete
add_action( 'the_post', array( $this, 'maybe_remove_ppwp_shortcode' ), 10 );
[95] Fix | Delete
add_action( 'the_post', array( $this, 'maybe_add_ppwp_shortcode' ), 99999 );
[96] Fix | Delete
[97] Fix | Delete
[98] Fix | Delete
/**
[99] Fix | Delete
* Need to keep the old Pro version work, because the sidewide shortcode is using global var ppwContentGlobal.
[100] Fix | Delete
*/
[101] Fix | Delete
if ( defined( 'PPW_PRO_VERSION' ) ) {
[102] Fix | Delete
$pro_version = ppw_get_pro_version();
[103] Fix | Delete
if ( version_compare( $pro_version, '1.2.2', '<' ) ) {
[104] Fix | Delete
add_action( 'wp_enqueue_scripts', array( $this, 'add_scripts' ) );
[105] Fix | Delete
}
[106] Fix | Delete
}
[107] Fix | Delete
[108] Fix | Delete
$this->main_class_name = PPW_Constants::DEFAULT_SHORTCODE_CLASS_NAME;
[109] Fix | Delete
}
[110] Fix | Delete
[111] Fix | Delete
/**
[112] Fix | Delete
* Maybe remove shortcode before WPBakery and WordPress do_shortcode in FrontEnd.
[113] Fix | Delete
*/
[114] Fix | Delete
public function maybe_remove_ppwp_shortcode() {
[115] Fix | Delete
if ( ! ppw_free_has_support_shortcode_page_builder() ) {
[116] Fix | Delete
return;
[117] Fix | Delete
}
[118] Fix | Delete
[119] Fix | Delete
remove_shortcode( PPW_Constants::PPW_HOOK_SHORT_CODE_NAME );
[120] Fix | Delete
}
[121] Fix | Delete
[122] Fix | Delete
/**
[123] Fix | Delete
* Maybe add shortcode back.
[124] Fix | Delete
*/
[125] Fix | Delete
public function maybe_add_ppwp_shortcode() {
[126] Fix | Delete
if ( ! ppw_free_has_support_shortcode_page_builder() ) {
[127] Fix | Delete
return;
[128] Fix | Delete
}
[129] Fix | Delete
[130] Fix | Delete
add_filter( 'the_content', function ( $content ) {
[131] Fix | Delete
add_shortcode( PPW_Constants::PPW_HOOK_SHORT_CODE_NAME, array( $this, 'render_shortcode' ) );
[132] Fix | Delete
[133] Fix | Delete
/* translators: Opening curly double quote. */
[134] Fix | Delete
$opening_quote = _x( '&#8220;', 'opening curly double quote' );
[135] Fix | Delete
/* translators: Closing curly double quote. */
[136] Fix | Delete
$closing_quote = _x( '&#8221;', 'closing curly double quote' );
[137] Fix | Delete
/* translators: Apostrophe, for example in 'cause or can't. */
[138] Fix | Delete
$apos = _x( '&#8217;', 'apostrophe' );
[139] Fix | Delete
/* translators: Prime, for example in 9' (nine feet). */
[140] Fix | Delete
$prime = _x( '&#8242;', 'prime' );
[141] Fix | Delete
/* translators: Double prime, for example in 9" (nine inches). */
[142] Fix | Delete
$double_prime = _x( '&#8243;', 'double prime' );
[143] Fix | Delete
/* translators: Opening curly single quote. */
[144] Fix | Delete
$opening_single_quote = _x( '&#8216;', 'opening curly single quote' );
[145] Fix | Delete
/* translators: Closing curly single quote. */
[146] Fix | Delete
$closing_single_quote = _x( '&#8217;', 'closing curly single quote' );
[147] Fix | Delete
[148] Fix | Delete
$matches = ppw_free_search_shortcode_content( $content );
[149] Fix | Delete
if ( ! empty( $matches ) ) {
[150] Fix | Delete
foreach ( $matches as $match ) {
[151] Fix | Delete
// The shortcode argument list
[152] Fix | Delete
$old_argument_shortcode = $match[3];
[153] Fix | Delete
$argument_shortcode = $match[3];
[154] Fix | Delete
[155] Fix | Delete
$argument_shortcode = str_replace( $opening_quote, '"', $argument_shortcode );
[156] Fix | Delete
$argument_shortcode = str_replace( $closing_quote, '"', $argument_shortcode );
[157] Fix | Delete
$argument_shortcode = str_replace( $apos, '\'', $argument_shortcode );
[158] Fix | Delete
$argument_shortcode = str_replace( $prime, '\'', $argument_shortcode );
[159] Fix | Delete
$argument_shortcode = str_replace( $double_prime, '"', $argument_shortcode );
[160] Fix | Delete
$argument_shortcode = str_replace( $opening_single_quote, '\'', $argument_shortcode );
[161] Fix | Delete
$argument_shortcode = str_replace( $closing_single_quote, '\'', $argument_shortcode );
[162] Fix | Delete
[163] Fix | Delete
$content = str_replace( $old_argument_shortcode, $argument_shortcode, $content );
[164] Fix | Delete
}
[165] Fix | Delete
}
[166] Fix | Delete
[167] Fix | Delete
$content = do_shortcode( $content );
[168] Fix | Delete
[169] Fix | Delete
return $content;
[170] Fix | Delete
}, 99999 );
[171] Fix | Delete
}
[172] Fix | Delete
[173] Fix | Delete
/**
[174] Fix | Delete
* Get short code instance
[175] Fix | Delete
*
[176] Fix | Delete
* @return PPW_Shortcode
[177] Fix | Delete
*/
[178] Fix | Delete
public static function get_instance() {
[179] Fix | Delete
return new PPW_Shortcode();
[180] Fix | Delete
}
[181] Fix | Delete
[182] Fix | Delete
/**
[183] Fix | Delete
* Render password form or restricted content
[184] Fix | Delete
* 0. Check current post type is in whitelist types
[185] Fix | Delete
* 1. Check is valid attributes
[186] Fix | Delete
* 2. Check whitelist roles
[187] Fix | Delete
* 3. Check password is correct compare to Cookie
[188] Fix | Delete
* 4. Show form
[189] Fix | Delete
*
[190] Fix | Delete
* @param array $attrs list of attributes including password.
[191] Fix | Delete
* @param string $content the content inside short code.
[192] Fix | Delete
*
[193] Fix | Delete
* @return string
[194] Fix | Delete
*/
[195] Fix | Delete
public function render_shortcode( $attrs, $content = null ) {
[196] Fix | Delete
global $page;
[197] Fix | Delete
[198] Fix | Delete
// In case the shortcode is outside in the loop, the page is 0.
[199] Fix | Delete
$number = ! empty( $page ) ? $page : 1;
[200] Fix | Delete
[201] Fix | Delete
$this->attributes = apply_filters( 'ppw_pcp_attributes', $this->attributes, $number );
[202] Fix | Delete
$attrs = shortcode_atts(
[203] Fix | Delete
$this->attributes,
[204] Fix | Delete
$attrs
[205] Fix | Delete
);
[206] Fix | Delete
[207] Fix | Delete
$message = $this->is_valid_shortcode( $attrs, $content );
[208] Fix | Delete
$message = apply_filters( 'ppw_pcp_valid_shortcode', $message, $attrs );
[209] Fix | Delete
if ( true !== $message ) {
[210] Fix | Delete
return $this->get_invalid_shortcode_message( $message, $attrs );
[211] Fix | Delete
}
[212] Fix | Delete
[213] Fix | Delete
$content = sprintf(
[214] Fix | Delete
'<div class="%s">%s</div>',
[215] Fix | Delete
$this->get_main_class_name( $attrs ),
[216] Fix | Delete
do_shortcode( $content )
[217] Fix | Delete
);
[218] Fix | Delete
[219] Fix | Delete
$whitelisted_roles = apply_filters( PPW_Constants::HOOK_SHORT_CODE_WHITELISTED_ROLES, $attrs['whitelisted_roles'] );
[220] Fix | Delete
[221] Fix | Delete
if ( $this->is_whitelisted_role( $whitelisted_roles ) ) {
[222] Fix | Delete
// Remember to wrap the content between the parent div. If you want to replace the shortcode content.
[223] Fix | Delete
return apply_filters( PPW_Constants::HOOK_SHORTCODE_RENDER_CONTENT, $content, $attrs );
[224] Fix | Delete
}
[225] Fix | Delete
[226] Fix | Delete
// Unlock content by datetime.
[227] Fix | Delete
$unlocked = apply_filters( 'ppw_shortcode_unlock_content', $this->is_unlock_content_by_time( $attrs ), $attrs );
[228] Fix | Delete
if ( $unlocked ) {
[229] Fix | Delete
return apply_filters( PPW_Constants::HOOK_SHORTCODE_RENDER_CONTENT, $content, $attrs );
[230] Fix | Delete
}
[231] Fix | Delete
[232] Fix | Delete
do_action( PPW_Constants::HOOK_SHORT_CODE_BEFORE_CHECK_PASSWORD, $content );
[233] Fix | Delete
[234] Fix | Delete
// Passwords attribute format: passwords="123 345 898942".
[235] Fix | Delete
$passwords = apply_filters( PPW_Constants::HOOK_SHORTCODE_PASSWORDS, array_filter( explode( ' ', trim( $attrs['passwords'] ) ), 'strlen' ), $attrs );
[236] Fix | Delete
[237] Fix | Delete
foreach ( $passwords as $password ) {
[238] Fix | Delete
// When passwords attribute having special characters eg: <script>alert('hello')</script>. WP will encode the HTML tag. Need to decode to compare the value in Cookie.
[239] Fix | Delete
$hashed_password = wp_hash_password( wp_specialchars_decode( $password ) );
[240] Fix | Delete
if ( $this->is_valid_password( $hashed_password ) ) {
[241] Fix | Delete
// Remember to wrap the content between the parent div. If you want to replace the shortcode content.
[242] Fix | Delete
return apply_filters( PPW_Constants::HOOK_SHORTCODE_RENDER_CONTENT, $content, $attrs );
[243] Fix | Delete
}
[244] Fix | Delete
}
[245] Fix | Delete
[246] Fix | Delete
do_action( PPW_Constants::HOOK_SHORT_CODE_AFTER_CHECK_PASSWORD, $content );
[247] Fix | Delete
[248] Fix | Delete
$this->add_scripts();
[249] Fix | Delete
[250] Fix | Delete
// Show custom text instead of password form.
[251] Fix | Delete
$custom_form = apply_filters( PPW_Constants::HOOK_SHORTCODE_BEFORE_RENDER_PASSWORD_FORM, false, $attrs );
[252] Fix | Delete
if ( false !== $custom_form ) {
[253] Fix | Delete
return sprintf(
[254] Fix | Delete
'<div class="%s">%s</div>',
[255] Fix | Delete
$this->get_main_class_name( $attrs ),
[256] Fix | Delete
$this->massage_attributes( $custom_form )
[257] Fix | Delete
);
[258] Fix | Delete
}
[259] Fix | Delete
[260] Fix | Delete
$password_form = $this->get_restricted_content_form( $attrs, $number );
[261] Fix | Delete
[262] Fix | Delete
return apply_filters( 'ppw_pcp_password_form', $password_form, $attrs );
[263] Fix | Delete
}
[264] Fix | Delete
[265] Fix | Delete
/**
[266] Fix | Delete
* Show content if user set on_date or off_date attribute.
[267] Fix | Delete
* $on_date: Date to unlock content
[268] Fix | Delete
* $off_date: Date to protect content.
[269] Fix | Delete
*
[270] Fix | Delete
* @param array $attrs Attributes.
[271] Fix | Delete
*
[272] Fix | Delete
* @return false True is unlock content else false.
[273] Fix | Delete
*/
[274] Fix | Delete
private function is_unlock_content_by_time( $attrs ) {
[275] Fix | Delete
$on_date = false;
[276] Fix | Delete
if ( '' !== $attrs['on'] ) {
[277] Fix | Delete
$on_date = strtotime( $attrs['on'] );
[278] Fix | Delete
}
[279] Fix | Delete
[280] Fix | Delete
$off_date = false;
[281] Fix | Delete
if ( '' !== $attrs['off'] ) {
[282] Fix | Delete
$off_date = strtotime( $attrs['off'] );
[283] Fix | Delete
}
[284] Fix | Delete
[285] Fix | Delete
// Show password form if on_date and off_date are empty.
[286] Fix | Delete
if ( ! $on_date && ! $off_date ) {
[287] Fix | Delete
return false;
[288] Fix | Delete
}
[289] Fix | Delete
[290] Fix | Delete
$now = current_time( 'timestamp' );
[291] Fix | Delete
[292] Fix | Delete
// Unlock content between on_date and off_date.
[293] Fix | Delete
if ( $on_date && $off_date && $on_date <= $now && $off_date >= $now ) {
[294] Fix | Delete
return apply_filters( 'ppw_shortcode_unlock_content_by_time', true, $attrs );
[295] Fix | Delete
}
[296] Fix | Delete
[297] Fix | Delete
// Unlock content from on_date.
[298] Fix | Delete
if ( $on_date && ! $off_date && $now >= $on_date ) {
[299] Fix | Delete
return apply_filters( 'ppw_shortcode_unlock_content_by_time', true, $attrs );
[300] Fix | Delete
}
[301] Fix | Delete
[302] Fix | Delete
return false;
[303] Fix | Delete
}
[304] Fix | Delete
[305] Fix | Delete
/**
[306] Fix | Delete
* Require javascript bundle file for shortcode.
[307] Fix | Delete
*/
[308] Fix | Delete
public function add_scripts() {
[309] Fix | Delete
static $count_script = 0;
[310] Fix | Delete
$count_script ++;
[311] Fix | Delete
[312] Fix | Delete
$assert_folder = '/public/js/dist';
[313] Fix | Delete
$is_using_pcp_recaptcha = PPW_Recaptcha::get_instance()->using_pcp_recaptcha();
[314] Fix | Delete
[315] Fix | Delete
wp_enqueue_script(
[316] Fix | Delete
'ppw-cookie',
[317] Fix | Delete
PPW_DIR_URL . "$assert_folder/ppw-rc-form.bundle.js",
[318] Fix | Delete
array( 'jquery' ),
[319] Fix | Delete
PPW_VERSION,
[320] Fix | Delete
false
[321] Fix | Delete
);
[322] Fix | Delete
wp_localize_script(
[323] Fix | Delete
'ppw-cookie',
[324] Fix | Delete
'ppwContentGlobal',
[325] Fix | Delete
array(
[326] Fix | Delete
'ajax_url' => admin_url( 'admin-ajax.php' ),
[327] Fix | Delete
'restUrl' => get_rest_url(),
[328] Fix | Delete
'ajax_nonce' => wp_create_nonce( 'ppw_pcp_nonce' ),
[329] Fix | Delete
'nonce' => wp_create_nonce( 'wp_rest' ),
[330] Fix | Delete
'cookieExpiration' => $this->get_cookie_expiration(),
[331] Fix | Delete
'supportedClassNames' => apply_filters(
[332] Fix | Delete
'ppw_shortcode_supported_class_name',
[333] Fix | Delete
array(
[334] Fix | Delete
'defaultType' => PPW_Constants::DEFAULT_SHORTCODE_CLASS_NAME,
[335] Fix | Delete
)
[336] Fix | Delete
),
[337] Fix | Delete
'label' => array(
[338] Fix | Delete
'LOADING' => _x( 'Loading...', PPW_Constants::CONTEXT_PCP_PASSWORD_FORM, PPW_Constants::DOMAIN ),
[339] Fix | Delete
),
[340] Fix | Delete
'isUsingPCPRecaptcha' => $is_using_pcp_recaptcha
[341] Fix | Delete
)
[342] Fix | Delete
);
[343] Fix | Delete
[344] Fix | Delete
// Avoid conflict with updating post on Gutenberg when updating post.
[345] Fix | Delete
if ( ! defined( 'REST_REQUEST' ) || ! REST_REQUEST ) {
[346] Fix | Delete
if ( $is_using_pcp_recaptcha && $count_script === 1 ) {
[347] Fix | Delete
add_action( 'wp_footer', function () {
[348] Fix | Delete
PPW_Recaptcha::get_instance()->add_recaptcha_to_head();
[349] Fix | Delete
} );
[350] Fix | Delete
}
[351] Fix | Delete
}
[352] Fix | Delete
}
[353] Fix | Delete
[354] Fix | Delete
/**
[355] Fix | Delete
* Check whether short code is valid.
[356] Fix | Delete
*
[357] Fix | Delete
* @param array $attrs Shortcode attributes.
[358] Fix | Delete
* @param string $content Short code content.
[359] Fix | Delete
*
[360] Fix | Delete
* @return string
[361] Fix | Delete
*/
[362] Fix | Delete
private function is_valid_shortcode( $attrs, $content ) {
[363] Fix | Delete
if ( ! $this->is_supported_post_types( get_post_type() ) ) {
[364] Fix | Delete
/* translators: %s: Short code name */
[365] Fix | Delete
$message = sprintf( __( 'Our Free version [%s] shortcode doesn\'t support Custom Post Type', PPW_Constants::DOMAIN ), PPW_Constants::PPW_HOOK_SHORT_CODE_NAME );
[366] Fix | Delete
[367] Fix | Delete
return apply_filters( PPW_Constants::HOOK_SHORTCODE_NOT_SUPPORT_TYPE_ERROR_MESSAGE, $message );
[368] Fix | Delete
}
[369] Fix | Delete
[370] Fix | Delete
/* translators: %s: Short code name */
[371] Fix | Delete
$message = sprintf( __( '[%s] Empty content, invalid attributes or values', PPW_Constants::DOMAIN ), PPW_Constants::PPW_HOOK_SHORT_CODE_NAME );
[372] Fix | Delete
$message = apply_filters( PPW_Constants::HOOK_SHORT_CODE_ERROR_MESSAGE, $message );
[373] Fix | Delete
[374] Fix | Delete
if ( $this->is_empty_content( $content, $attrs ) ) {
[375] Fix | Delete
return $message;
[376] Fix | Delete
}
[377] Fix | Delete
[378] Fix | Delete
if ( ! $this->is_valid_attributes( $attrs ) ) {
[379] Fix | Delete
return $message;
[380] Fix | Delete
}
[381] Fix | Delete
[382] Fix | Delete
return true;
[383] Fix | Delete
}
[384] Fix | Delete
[385] Fix | Delete
/**
[386] Fix | Delete
* @param $attrs
[387] Fix | Delete
*/
[388] Fix | Delete
private function is_valid_date( $attrs ) {
[389] Fix | Delete
if ( '' !== $attrs['on'] && ! ppw_free_validate_date( $attrs['on'] ) ) {
[390] Fix | Delete
return false;
[391] Fix | Delete
}
[392] Fix | Delete
if ( '' !== $attrs['off'] && ! ppw_free_validate_date( $attrs['off'] ) ) {
[393] Fix | Delete
return false;
[394] Fix | Delete
}
[395] Fix | Delete
[396] Fix | Delete
return true;
[397] Fix | Delete
}
[398] Fix | Delete
[399] Fix | Delete
/**
[400] Fix | Delete
* Check if the password is valid, comparing with cookie.
[401] Fix | Delete
*
[402] Fix | Delete
* @param string $password Password.
[403] Fix | Delete
*
[404] Fix | Delete
* @return bool
[405] Fix | Delete
*/
[406] Fix | Delete
private function is_valid_password( $password ) {
[407] Fix | Delete
[408] Fix | Delete
$is_valid = apply_filters( 'ppw_shortcode_is_valid_password_with_cookie', false, $password, $_COOKIE );
[409] Fix | Delete
[410] Fix | Delete
if ( $is_valid ) {
[411] Fix | Delete
[412] Fix | Delete
return apply_filters( 'ppw_shortcode_after_check_is_valid_password_with_cookie', $is_valid, $password, array() );
[413] Fix | Delete
[414] Fix | Delete
}
[415] Fix | Delete
[416] Fix | Delete
$cookie_name = 'ppw_rc-' . get_the_ID();
[417] Fix | Delete
if ( ! isset( $_COOKIE[ $cookie_name ] ) ) {
[418] Fix | Delete
return false;
[419] Fix | Delete
}
[420] Fix | Delete
[421] Fix | Delete
//global $wp_hasher;
[422] Fix | Delete
$cookie_val = json_decode( wp_unslash( $_COOKIE[ $cookie_name ] ) ); // phpcs:ignore -- Here do not need to sanitize $_COOKIE data, because we use it for comparision.
[423] Fix | Delete
if ( ! is_array( $cookie_val ) ) {
[424] Fix | Delete
return false;
[425] Fix | Delete
}
[426] Fix | Delete
[427] Fix | Delete
foreach ( $cookie_val as $val ) {
[428] Fix | Delete
if ( get_the_ID() !== (int) $val->post_id ) {
[429] Fix | Delete
continue;
[430] Fix | Delete
}
[431] Fix | Delete
[432] Fix | Delete
foreach ( $val->passwords as $cookie_pass ) {
[433] Fix | Delete
//if ( $wp_hasher->CheckPassword( $cookie_pass, $password ) ) {
[434] Fix | Delete
if ( wp_check_password( $cookie_pass, $password ) ) {
[435] Fix | Delete
return true;
[436] Fix | Delete
}
[437] Fix | Delete
}
[438] Fix | Delete
}
[439] Fix | Delete
[440] Fix | Delete
return false;
[441] Fix | Delete
}
[442] Fix | Delete
[443] Fix | Delete
/**
[444] Fix | Delete
* Get restricted content form.
[445] Fix | Delete
*
[446] Fix | Delete
* @param array $attrs Short-code attributes.
[447] Fix | Delete
* @param int $number Short-code attributes.
[448] Fix | Delete
*
[449] Fix | Delete
* @return array|mixed
[450] Fix | Delete
*/
[451] Fix | Delete
private function get_restricted_content_form( $attrs, $number ) {
[452] Fix | Delete
$checkbox = '';
[453] Fix | Delete
if ( wp_validate_boolean( $attrs['show_password'] ) ) {
[454] Fix | Delete
$checkbox = '<label class="ppw-pcp-checkbox-label"><input class="ppw-pcp-checkbox" type="checkbox" /> ' . _x( $this->massage_attributes( $attrs['show_password_text'] ), PPW_Constants::CONTEXT_PCP_PASSWORD_FORM, PPW_Constants::DOMAIN ) . '</label>';
[455] Fix | Delete
}
[456] Fix | Delete
[457] Fix | Delete
$desc_above_btn = '';
[458] Fix | Delete
if ( wp_validate_boolean( $attrs['desc_above_btn'] ) ) {
[459] Fix | Delete
$desc_above_btn = '<span class="ppw-pcp-pf-desc-above-btn">'._x( $this->massage_attributes( $attrs['desc_above_btn'] ), PPW_Constants::CONTEXT_PCP_PASSWORD_FORM, PPW_Constants::DOMAIN ).'</span>';
[460] Fix | Delete
}
[461] Fix | Delete
[462] Fix | Delete
// Temp hide recaptcha on section protection.
[463] Fix | Delete
if ( PPW_Recaptcha::get_instance()->using_pcp_recaptcha() && empty( $attrs['section'] ) ) {
[464] Fix | Delete
$recaptcha_input = PPW_Recaptcha::get_instance()->get_recaptcha_input();
[465] Fix | Delete
} else {
[466] Fix | Delete
$recaptcha_input = '';
[467] Fix | Delete
}
[468] Fix | Delete
[469] Fix | Delete
ob_start();
[470] Fix | Delete
include apply_filters(
[471] Fix | Delete
PPW_Constants::HOOK_SHORT_CODE_TEMPLATE,
[472] Fix | Delete
PPW_DIR_PATH . 'includes/views/shortcode/view-ppw-restriced-content-form.php'
[473] Fix | Delete
);
[474] Fix | Delete
[475] Fix | Delete
$form_template = ob_get_contents();
[476] Fix | Delete
ob_end_clean();
[477] Fix | Delete
[478] Fix | Delete
$className = '' === $attrs['class'] ? $this->get_main_class_name( $attrs ) : $this->get_main_class_name( $attrs ) . ' ' . $attrs['class'];
[479] Fix | Delete
[480] Fix | Delete
// phpcs:disable
[481] Fix | Delete
$form_params = array(
[482] Fix | Delete
PPW_Constants::SHORT_CODE_FORM_HEADLINE => _x( $this->massage_attributes( $attrs['headline'] ), PPW_Constants::CONTEXT_PCP_PASSWORD_FORM, PPW_Constants::DOMAIN ),
[483] Fix | Delete
PPW_Constants::SHORT_CODE_FORM_INSTRUCT => _x( $this->massage_attributes( $attrs['description'] ), PPW_Constants::CONTEXT_PCP_PASSWORD_FORM, PPW_Constants::DOMAIN ),
[484] Fix | Delete
PPW_Constants::SHORT_CODE_FORM_PLACEHOLDER => _x( $this->massage_attributes( $attrs['placeholder'] ), PPW_Constants::CONTEXT_PCP_PASSWORD_FORM, PPW_Constants::DOMAIN ),
[485] Fix | Delete
PPW_Constants::SHORT_CODE_FORM_AUTH => get_the_ID(),
[486] Fix | Delete
PPW_Constants::SHORT_CODE_BUTTON => _x( wp_kses_post( $attrs['button'] ), PPW_Constants::CONTEXT_PCP_PASSWORD_FORM, PPW_Constants::DOMAIN ),
[487] Fix | Delete
PPW_Constants::SHORT_CODE_FORM_CURRENT_URL => $this->get_the_permalink_without_cache( wp_rand( 0, 100 ) ),
[488] Fix | Delete
PPW_Constants::SHORT_CODE_FORM_ID => esc_attr( '' === $attrs['id'] ? get_the_ID() . wp_rand( 0, 1000 ) : wp_kses_post( $attrs['id'] ) ),
[489] Fix | Delete
PPW_Constants::SHORT_CODE_FORM_CLASS => esc_attr( $className ),
[490] Fix | Delete
PPW_Constants::SHORT_CODE_PASSWORD_LABEL => _x( $this->massage_attributes( $attrs['label'] ), PPW_Constants::CONTEXT_PCP_PASSWORD_FORM, PPW_Constants::DOMAIN ),
[491] Fix | Delete
PPW_Constants::SHORTCODE_ABOVE_PASSWORD_INPUT => apply_filters( 'ppw_pcp_above_password_field', '', $attrs ),
[492] Fix | Delete
PPW_Constants::SHORTCODE_BELOW_PASSWORD_INPUT => apply_filters( 'ppw_pcp_below_password_field', '', $attrs ),
[493] Fix | Delete
PPW_Constants::SHORT_CODE_FORM_ERROR_MESSAGE => '',
[494] Fix | Delete
PPW_Constants::SHORTCODE_DESC_ABOVE_BTN => $desc_above_btn,
[495] Fix | Delete
PPW_Constants::SHORTCODE_DESC_BELOW_FORM => _x( $this->massage_attributes( $attrs['desc_below_form'] ), PPW_Constants::CONTEXT_PCP_PASSWORD_FORM, PPW_Constants::DOMAIN ),
[496] Fix | Delete
'[PPW_PAGE]' => $number,
[497] Fix | Delete
'[PPW_CHECKBOX]' => $checkbox,
[498] Fix | Delete
'[PPW_BUTTON_LOADING]' => esc_attr_x( $attrs['loading'], PPW_Constants::CONTEXT_PCP_PASSWORD_FORM, PPW_Constants::DOMAIN ),
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function