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/content-.../inc
File: class-ps-public.php
<?php
[0] Fix | Delete
[1] Fix | Delete
namespace passster;
[2] Fix | Delete
[3] Fix | Delete
use Exception ;
[4] Fix | Delete
class PS_Public
[5] Fix | Delete
{
[6] Fix | Delete
/**
[7] Fix | Delete
* Contains instance or null
[8] Fix | Delete
*
[9] Fix | Delete
* @var object|null
[10] Fix | Delete
*/
[11] Fix | Delete
private static $instance = null ;
[12] Fix | Delete
/**
[13] Fix | Delete
* Constructor for PS_Public
[14] Fix | Delete
*/
[15] Fix | Delete
public function __construct()
[16] Fix | Delete
{
[17] Fix | Delete
add_shortcode( 'content_protector', array( $this, 'render_shortcode' ) );
[18] Fix | Delete
add_shortcode( 'passster', array( $this, 'render_shortcode' ) );
[19] Fix | Delete
add_filter( 'the_content', array( $this, 'filter_the_content' ) );
[20] Fix | Delete
add_filter( 'acf_the_content', array( $this, 'filter_the_content' ) );
[21] Fix | Delete
add_filter( 'get_the_excerpt', array( $this, 'filter_the_content' ) );
[22] Fix | Delete
add_action( 'template_redirect', array( $this, 'check_global_proctection' ) );
[23] Fix | Delete
}
[24] Fix | Delete
[25] Fix | Delete
/**
[26] Fix | Delete
* Returns instance of PS_Public.
[27] Fix | Delete
*
[28] Fix | Delete
* @return object
[29] Fix | Delete
*/
[30] Fix | Delete
public static function get_instance()
[31] Fix | Delete
{
[32] Fix | Delete
if ( null === self::$instance ) {
[33] Fix | Delete
self::$instance = new self();
[34] Fix | Delete
}
[35] Fix | Delete
return self::$instance;
[36] Fix | Delete
}
[37] Fix | Delete
[38] Fix | Delete
/**
[39] Fix | Delete
* Render the Passster shortcode.
[40] Fix | Delete
*
[41] Fix | Delete
* @param array $atts array of attributes.
[42] Fix | Delete
* @param string|null $content the current content.
[43] Fix | Delete
*
[44] Fix | Delete
* @return string
[45] Fix | Delete
*/
[46] Fix | Delete
public function render_shortcode( array $atts, string $content = null ) : string
[47] Fix | Delete
{
[48] Fix | Delete
// check if valid before restrict anything.
[49] Fix | Delete
$valid = PS_Conditional::is_valid( $atts );
[50] Fix | Delete
$options = get_option( 'passster' );
[51] Fix | Delete
if ( $valid ) {
[52] Fix | Delete
[53] Fix | Delete
if ( !empty($atts['area']) ) {
[54] Fix | Delete
$area_id = esc_html( $atts['area'] );
[55] Fix | Delete
$area = get_post( $area_id );
[56] Fix | Delete
$content = $area->post_content;
[57] Fix | Delete
do_action( 'passster_content_unlocked' );
[58] Fix | Delete
return apply_filters( 'the_content', str_replace( '{post-id}', get_the_id(), $content ) );
[59] Fix | Delete
} else {
[60] Fix | Delete
$content = apply_filters( 'the_content', $content );
[61] Fix | Delete
do_action( 'passster_content_unlocked' );
[62] Fix | Delete
return apply_filters( 'passster_content', $content );
[63] Fix | Delete
}
[64] Fix | Delete
[65] Fix | Delete
}
[66] Fix | Delete
// do nothing if no atts.
[67] Fix | Delete
if ( empty($atts) ) {
[68] Fix | Delete
return $content;
[69] Fix | Delete
}
[70] Fix | Delete
// Set default form.
[71] Fix | Delete
$form = PS_Form::get_password_form();
[72] Fix | Delete
// Password.
[73] Fix | Delete
[74] Fix | Delete
if ( !empty($atts['password']) ) {
[75] Fix | Delete
$form = PS_Form::get_password_form();
[76] Fix | Delete
$form = str_replace( '[PASSSTER_TYPE]', 'password', $form );
[77] Fix | Delete
}
[78] Fix | Delete
[79] Fix | Delete
// Area.
[80] Fix | Delete
[81] Fix | Delete
if ( !empty($atts['area']) ) {
[82] Fix | Delete
$area_id = esc_html( $atts['area'] );
[83] Fix | Delete
$form = str_replace( '[PASSSTER_AREA]', $area_id, $form );
[84] Fix | Delete
}
[85] Fix | Delete
[86] Fix | Delete
// Page.
[87] Fix | Delete
[88] Fix | Delete
if ( !empty($atts['protection']) ) {
[89] Fix | Delete
$form = str_replace( '[PASSSTER_PROTECTION]', 'full', $form );
[90] Fix | Delete
} else {
[91] Fix | Delete
if ( !empty($atts['area']) ) {
[92] Fix | Delete
$form = str_replace( '[PASSSTER_PROTECTION]', 'area', $form );
[93] Fix | Delete
}
[94] Fix | Delete
}
[95] Fix | Delete
[96] Fix | Delete
// Redirect.
[97] Fix | Delete
[98] Fix | Delete
if ( !empty($atts['redirect']) ) {
[99] Fix | Delete
$form = str_replace( '[PASSSTER_REDIRECT]', esc_url( $atts['redirect'] ), $form );
[100] Fix | Delete
} else {
[101] Fix | Delete
$form = str_replace( '[PASSSTER_REDIRECT]', '', $form );
[102] Fix | Delete
}
[103] Fix | Delete
[104] Fix | Delete
// headline.
[105] Fix | Delete
[106] Fix | Delete
if ( !empty($atts['headline']) ) {
[107] Fix | Delete
$form = str_replace( '[PASSSTER_FORM_HEADLINE]', esc_html( $atts['headline'] ), $form );
[108] Fix | Delete
} else {
[109] Fix | Delete
$form = str_replace( '[PASSSTER_FORM_HEADLINE]', $options['headline'], $form );
[110] Fix | Delete
}
[111] Fix | Delete
[112] Fix | Delete
// instruction.
[113] Fix | Delete
[114] Fix | Delete
if ( !empty($atts['instruction']) ) {
[115] Fix | Delete
$form = str_replace( '[PASSSTER_FORM_INSTRUCTIONS]', esc_html( $atts['instruction'] ), $form );
[116] Fix | Delete
} else {
[117] Fix | Delete
$form = str_replace( '[PASSSTER_FORM_INSTRUCTIONS]', $options['instruction'], $form );
[118] Fix | Delete
}
[119] Fix | Delete
[120] Fix | Delete
// placeholder.
[121] Fix | Delete
[122] Fix | Delete
if ( !empty($atts['placeholder']) ) {
[123] Fix | Delete
$form = str_replace( '[PASSSTER_PLACEHOLDER]', esc_html( $atts['placeholder'] ), $form );
[124] Fix | Delete
} else {
[125] Fix | Delete
$form = str_replace( '[PASSSTER_PLACEHOLDER]', $options['placeholder'], $form );
[126] Fix | Delete
}
[127] Fix | Delete
[128] Fix | Delete
// button.
[129] Fix | Delete
[130] Fix | Delete
if ( !empty($atts['button']) ) {
[131] Fix | Delete
$form = str_replace( '[PASSSTER_BUTTON_LABEL]', esc_html( $atts['button'] ), $form );
[132] Fix | Delete
} else {
[133] Fix | Delete
$form = str_replace( '[PASSSTER_BUTTON_LABEL]', $options['button_label'], $form );
[134] Fix | Delete
}
[135] Fix | Delete
[136] Fix | Delete
// modify id.
[137] Fix | Delete
[138] Fix | Delete
if ( !empty($atts['id']) ) {
[139] Fix | Delete
$form = str_replace( '[PASSSTER_ID]', 'ps-' . esc_html( $atts['id'] ), $form );
[140] Fix | Delete
} else {
[141] Fix | Delete
$form = str_replace( '[PASSSTER_ID]', 'ps-' . wp_rand( 10, 1000 ), $form );
[142] Fix | Delete
}
[143] Fix | Delete
[144] Fix | Delete
// hide or not.
[145] Fix | Delete
[146] Fix | Delete
if ( !empty($atts['hide']) ) {
[147] Fix | Delete
$form = str_replace( '[PASSSTER_HIDE]', ' passster-hide', $form );
[148] Fix | Delete
} else {
[149] Fix | Delete
$form = str_replace( '[PASSSTER_HIDE]', '', $form );
[150] Fix | Delete
}
[151] Fix | Delete
[152] Fix | Delete
// ACF field.
[153] Fix | Delete
[154] Fix | Delete
if ( !empty($atts['acf']) ) {
[155] Fix | Delete
$form = str_replace( '[PASSSTER_ACF]', ' data-acf="' . esc_html( $atts['acf'] ) . '"', $form );
[156] Fix | Delete
} else {
[157] Fix | Delete
$form = str_replace( '[PASSSTER_ACF]', '', $form );
[158] Fix | Delete
}
[159] Fix | Delete
[160] Fix | Delete
return $form;
[161] Fix | Delete
}
[162] Fix | Delete
[163] Fix | Delete
/**
[164] Fix | Delete
* Filters the_content with Passster.
[165] Fix | Delete
*
[166] Fix | Delete
* @param string $content given content.
[167] Fix | Delete
*
[168] Fix | Delete
* @return string
[169] Fix | Delete
* @throws Exception
[170] Fix | Delete
*/
[171] Fix | Delete
public function filter_the_content( string $content ) : string
[172] Fix | Delete
{
[173] Fix | Delete
$post_id = get_the_id();
[174] Fix | Delete
$activate_protection = get_post_meta( $post_id, 'passster_activate_protection', true );
[175] Fix | Delete
// user restriction.
[176] Fix | Delete
$user_restriction_type = get_post_meta( $post_id, 'passster_user_restriction_type', true );
[177] Fix | Delete
$user_restriction = get_post_meta( $post_id, 'passster_user_restriction', true );
[178] Fix | Delete
// Redirection.
[179] Fix | Delete
$redirection = get_post_meta( $post_id, 'passster_redirect_url', true );
[180] Fix | Delete
// texts.
[181] Fix | Delete
$headline = get_post_meta( $post_id, 'passster_headline', true );
[182] Fix | Delete
$instruction = get_post_meta( $post_id, 'passster_instruction', true );
[183] Fix | Delete
$placeholder = get_post_meta( $post_id, 'passster_placeholder', true );
[184] Fix | Delete
$button = get_post_meta( $post_id, 'passster_button', true );
[185] Fix | Delete
$id = get_post_meta( $post_id, 'passster_id', true );
[186] Fix | Delete
if ( !$activate_protection ) {
[187] Fix | Delete
return $content;
[188] Fix | Delete
}
[189] Fix | Delete
// build atts array to validate.
[190] Fix | Delete
$atts = array();
[191] Fix | Delete
$shortcode = '';
[192] Fix | Delete
$password = get_post_meta( $post_id, 'passster_password', true );
[193] Fix | Delete
$atts['password'] = $password;
[194] Fix | Delete
$shortcode = '[passster password="' . $password . '" protection="full" ';
[195] Fix | Delete
if ( !empty($redirection) ) {
[196] Fix | Delete
$shortcode .= 'redirect="' . $redirection . '" ';
[197] Fix | Delete
}
[198] Fix | Delete
if ( !empty($headline) ) {
[199] Fix | Delete
$shortcode .= 'headline="' . $headline . '" ';
[200] Fix | Delete
}
[201] Fix | Delete
if ( !empty($instruction) ) {
[202] Fix | Delete
$shortcode .= 'instruction="' . $instruction . '" ';
[203] Fix | Delete
}
[204] Fix | Delete
if ( !empty($placeholder) ) {
[205] Fix | Delete
$shortcode .= 'placeholder="' . $placeholder . '" ';
[206] Fix | Delete
}
[207] Fix | Delete
if ( !empty($button) ) {
[208] Fix | Delete
$shortcode .= 'button="' . $button . '" ';
[209] Fix | Delete
}
[210] Fix | Delete
if ( !empty($id) ) {
[211] Fix | Delete
$shortcode .= 'id="' . $id . '" ';
[212] Fix | Delete
}
[213] Fix | Delete
$shortcode .= ']{content}[/passster]';
[214] Fix | Delete
// check if valid before restrict anything.
[215] Fix | Delete
$valid = PS_Conditional::is_valid( $atts );
[216] Fix | Delete
if ( $valid ) {
[217] Fix | Delete
return $content;
[218] Fix | Delete
}
[219] Fix | Delete
// replace placeholder with content.
[220] Fix | Delete
$shortcode = str_replace( '{content}', $content, $shortcode );
[221] Fix | Delete
return do_shortcode( $shortcode );
[222] Fix | Delete
}
[223] Fix | Delete
[224] Fix | Delete
/**
[225] Fix | Delete
* Redirect if global protection is activated and no password is set.
[226] Fix | Delete
*
[227] Fix | Delete
* @return void
[228] Fix | Delete
* @throws Exception
[229] Fix | Delete
*/
[230] Fix | Delete
public function check_global_proctection()
[231] Fix | Delete
{
[232] Fix | Delete
$options = get_option( 'passster' );
[233] Fix | Delete
// Allow Elementor editing the page.
[234] Fix | Delete
$elementor_preview = filter_input( INPUT_GET, 'elementor-preview', FILTER_SANITIZE_STRING );
[235] Fix | Delete
if ( $elementor_preview ) {
[236] Fix | Delete
return;
[237] Fix | Delete
}
[238] Fix | Delete
// Allow Live Canvas Editor.
[239] Fix | Delete
$live_canvas_preview = filter_input( INPUT_GET, 'lc_action_launch_editing', FILTER_SANITIZE_STRING );
[240] Fix | Delete
if ( $live_canvas_preview ) {
[241] Fix | Delete
return;
[242] Fix | Delete
}
[243] Fix | Delete
if ( !isset( $options['global_protection_id'] ) ) {
[244] Fix | Delete
return;
[245] Fix | Delete
}
[246] Fix | Delete
if ( !isset( $options['activate_global_protection'] ) ) {
[247] Fix | Delete
return;
[248] Fix | Delete
}
[249] Fix | Delete
// Build $atts array based on protection settings.
[250] Fix | Delete
$post_id = esc_html( $options['global_protection_id'] );
[251] Fix | Delete
$is_active = esc_html( $options['activate_global_protection'] );
[252] Fix | Delete
$atts = array();
[253] Fix | Delete
$password = get_post_meta( $post_id, 'passster_password', true );
[254] Fix | Delete
$atts['password'] = esc_html( $password );
[255] Fix | Delete
if ( !empty($post_id) ) {
[256] Fix | Delete
[257] Fix | Delete
if ( $is_active ) {
[258] Fix | Delete
if ( is_page( $post_id ) || is_single( $post_id ) ) {
[259] Fix | Delete
return;
[260] Fix | Delete
}
[261] Fix | Delete
// Check excluded pages.
[262] Fix | Delete
if ( isset( $options['exclude_pages'] ) ) {
[263] Fix | Delete
foreach ( $options['exclude_pages'] as $excluded_page_id ) {
[264] Fix | Delete
if ( is_page( $excluded_page_id ) ) {
[265] Fix | Delete
return;
[266] Fix | Delete
}
[267] Fix | Delete
}
[268] Fix | Delete
}
[269] Fix | Delete
// Check if cookie is set.
[270] Fix | Delete
[271] Fix | Delete
if ( empty($_COOKIE['passster']) || !PS_Conditional::is_valid( $atts ) ) {
[272] Fix | Delete
$global_protection_url = get_permalink( $post_id );
[273] Fix | Delete
wp_redirect( esc_url_raw( $global_protection_url ) );
[274] Fix | Delete
exit;
[275] Fix | Delete
}
[276] Fix | Delete
[277] Fix | Delete
}
[278] Fix | Delete
[279] Fix | Delete
}
[280] Fix | Delete
}
[281] Fix | Delete
[282] Fix | Delete
}
[283] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function