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/sitepres.../classes/notices
File: class-wpml-notice-render.php
<?php
[0] Fix | Delete
[1] Fix | Delete
/**
[2] Fix | Delete
* @author OnTheGo Systems
[3] Fix | Delete
*/
[4] Fix | Delete
class WPML_Notice_Render {
[5] Fix | Delete
private $dismiss_html_added;
[6] Fix | Delete
private $hide_html_added;
[7] Fix | Delete
private $collapse_html_added;
[8] Fix | Delete
[9] Fix | Delete
public function render( WPML_Notice $notice ) {
[10] Fix | Delete
echo $this->get_html( $notice );
[11] Fix | Delete
}
[12] Fix | Delete
[13] Fix | Delete
/**
[14] Fix | Delete
* @param WPML_Notice $notice
[15] Fix | Delete
*
[16] Fix | Delete
* @return string
[17] Fix | Delete
*/
[18] Fix | Delete
public function get_html( WPML_Notice $notice ) {
[19] Fix | Delete
$result = '';
[20] Fix | Delete
[21] Fix | Delete
if ( $this->must_display_notice( $notice ) ) {
[22] Fix | Delete
if ( $notice->should_be_text_only() ) {
[23] Fix | Delete
return $notice->get_text();
[24] Fix | Delete
}
[25] Fix | Delete
[26] Fix | Delete
$actions_html = $this->get_actions_html( $notice );
[27] Fix | Delete
[28] Fix | Delete
$temp_types = $notice->get_css_class_types();
[29] Fix | Delete
foreach ( $temp_types as $temp_type ) {
[30] Fix | Delete
if ( strpos( $temp_type, 'notice-' ) === false ) {
[31] Fix | Delete
$temp_types[] = 'notice-' . $temp_type;
[32] Fix | Delete
}
[33] Fix | Delete
if ( strpos( $temp_type, 'notice-' ) === 0 ) {
[34] Fix | Delete
$temp_types[] = substr( $temp_type, 0, strlen( 'notice-' ) );
[35] Fix | Delete
}
[36] Fix | Delete
}
[37] Fix | Delete
$temp_classes = $notice->get_css_classes();
[38] Fix | Delete
[39] Fix | Delete
$classes = array_merge( $temp_classes, $temp_types );
[40] Fix | Delete
[41] Fix | Delete
if ( $this->hide_html_added || $this->dismiss_html_added || $notice->can_be_hidden() || $notice->can_be_dismissed() ) {
[42] Fix | Delete
$classes[] = 'is-dismissible';
[43] Fix | Delete
}
[44] Fix | Delete
$classes[] = 'notice';
[45] Fix | Delete
$classes[] = 'otgs-notice';
[46] Fix | Delete
[47] Fix | Delete
$classes = array_unique( $classes );
[48] Fix | Delete
[49] Fix | Delete
$class = implode( ' ', $classes );
[50] Fix | Delete
[51] Fix | Delete
$result .= '<div class="' . $class . '" data-id="' . esc_attr( $notice->get_id() ) . '" data-group="' . esc_attr( $notice->get_group() ) . '"';
[52] Fix | Delete
$result .= $this->get_data_nonce_attribute();
[53] Fix | Delete
[54] Fix | Delete
if ( $this->hide_html_added || $notice->can_be_hidden() ) {
[55] Fix | Delete
$result .= ' data-hide-text="' . __( 'Hide', 'sitepress' ) . '" ';
[56] Fix | Delete
}
[57] Fix | Delete
$result .= '>';
[58] Fix | Delete
[59] Fix | Delete
if ( $notice->can_be_collapsed() ) {
[60] Fix | Delete
$result .= $this->sanitize_and_format_text( $this->get_collapsed_html( $notice ) );
[61] Fix | Delete
} else {
[62] Fix | Delete
$result .= '<p>' . $this->sanitize_and_format_text( $notice->get_text() ) . '</p>';
[63] Fix | Delete
}
[64] Fix | Delete
[65] Fix | Delete
$this->dismiss_html_added = false;
[66] Fix | Delete
$this->hide_html_added = false;
[67] Fix | Delete
$this->collapse_html_added = false;
[68] Fix | Delete
[69] Fix | Delete
$result .= $actions_html;
[70] Fix | Delete
[71] Fix | Delete
if ( $notice->can_be_hidden() ) {
[72] Fix | Delete
$result .= $this->get_hide_html();
[73] Fix | Delete
}
[74] Fix | Delete
[75] Fix | Delete
if ( $notice->can_be_dismissed() ) {
[76] Fix | Delete
$result .= $this->get_dismiss_html();
[77] Fix | Delete
}
[78] Fix | Delete
[79] Fix | Delete
if ( $notice->can_be_collapsed() ) {
[80] Fix | Delete
$result .= $this->get_collapse_html();
[81] Fix | Delete
}
[82] Fix | Delete
[83] Fix | Delete
if ( $notice->get_nonce_action() ) {
[84] Fix | Delete
$result .= $this->add_nonce( $notice );
[85] Fix | Delete
}
[86] Fix | Delete
[87] Fix | Delete
$result .= '</div>';
[88] Fix | Delete
}
[89] Fix | Delete
[90] Fix | Delete
return $result;
[91] Fix | Delete
}
[92] Fix | Delete
[93] Fix | Delete
/**
[94] Fix | Delete
* @param WPML_Notice $notice
[95] Fix | Delete
*
[96] Fix | Delete
* @return string
[97] Fix | Delete
*/
[98] Fix | Delete
private function add_nonce( $notice ) {
[99] Fix | Delete
return wp_nonce_field( $notice->get_nonce_action(), $notice->get_nonce_action(), true, false );
[100] Fix | Delete
}
[101] Fix | Delete
[102] Fix | Delete
public function must_display_notice( WPML_Notice $notice ) {
[103] Fix | Delete
if ( ! $notice->is_for_current_user() || ! $notice->is_user_cap_allowed() ) {
[104] Fix | Delete
return false;
[105] Fix | Delete
}
[106] Fix | Delete
[107] Fix | Delete
return $this->is_current_page_allowed( $notice ) && $this->is_allowed_by_callback( $notice );
[108] Fix | Delete
}
[109] Fix | Delete
[110] Fix | Delete
/**
[111] Fix | Delete
* @param WPML_Notice $notice
[112] Fix | Delete
*
[113] Fix | Delete
* @return string
[114] Fix | Delete
*/
[115] Fix | Delete
private function get_actions_html( WPML_Notice $notice ) {
[116] Fix | Delete
$actions_html = '';
[117] Fix | Delete
if ( $notice->get_actions() ) {
[118] Fix | Delete
/** @var WPML_Notice_Action $action */
[119] Fix | Delete
$actions_html .= '<div class="otgs-notice-actions">';
[120] Fix | Delete
foreach ( $notice->get_actions() as $action ) {
[121] Fix | Delete
$actions_html .= $this->get_action_html( $action );
[122] Fix | Delete
}
[123] Fix | Delete
[124] Fix | Delete
$actions_html .= '</div>';
[125] Fix | Delete
[126] Fix | Delete
return $actions_html;
[127] Fix | Delete
}
[128] Fix | Delete
[129] Fix | Delete
return $actions_html;
[130] Fix | Delete
}
[131] Fix | Delete
[132] Fix | Delete
private function sanitize_and_format_text( $text ) {
[133] Fix | Delete
$backticks_pattern = '|`(.*)`|U';
[134] Fix | Delete
preg_match_all( $backticks_pattern, $text, $matches );
[135] Fix | Delete
[136] Fix | Delete
$sanitized_notice = $text;
[137] Fix | Delete
if ( 2 === count( $matches ) ) {
[138] Fix | Delete
$matches_to_sanitize = $matches[1];
[139] Fix | Delete
[140] Fix | Delete
/** @var array $matches_to_sanitize */
[141] Fix | Delete
foreach ( $matches_to_sanitize as &$match_to_sanitize ) {
[142] Fix | Delete
$match_to_sanitize = '<pre>' . esc_html( $match_to_sanitize ) . '</pre>';
[143] Fix | Delete
}
[144] Fix | Delete
unset( $match_to_sanitize );
[145] Fix | Delete
[146] Fix | Delete
$sanitized_notice = str_replace( $matches[0], $matches_to_sanitize, $sanitized_notice );
[147] Fix | Delete
}
[148] Fix | Delete
[149] Fix | Delete
return stripslashes( $sanitized_notice );
[150] Fix | Delete
}
[151] Fix | Delete
[152] Fix | Delete
/**
[153] Fix | Delete
* @param null|string $localized_text
[154] Fix | Delete
*
[155] Fix | Delete
* @return string
[156] Fix | Delete
*/
[157] Fix | Delete
private function get_hide_html( $localized_text = null ) {
[158] Fix | Delete
$hide_html = '';
[159] Fix | Delete
$hide_html .= '<span class="otgs-notice-hide notice-hide"><span class="screen-reader-text">';
[160] Fix | Delete
if ( $localized_text ) {
[161] Fix | Delete
$hide_html .= esc_html( $localized_text );
[162] Fix | Delete
} else {
[163] Fix | Delete
$hide_html .= esc_html__( 'Hide this notice.', 'sitepress' );
[164] Fix | Delete
}
[165] Fix | Delete
$hide_html .= '</span></span>';
[166] Fix | Delete
[167] Fix | Delete
return $hide_html;
[168] Fix | Delete
}
[169] Fix | Delete
[170] Fix | Delete
/**
[171] Fix | Delete
* @param null|string $localized_text
[172] Fix | Delete
*
[173] Fix | Delete
* @return string
[174] Fix | Delete
*/
[175] Fix | Delete
private function get_dismiss_html( $localized_text = null ) {
[176] Fix | Delete
$dismiss_html = '';
[177] Fix | Delete
$dismiss_html .= '<span class="otgs-notice-dismiss notice-dismiss">';
[178] Fix | Delete
$dismiss_html .= '<span class="screen-reader-text"><input class="otgs-notice-dismiss-check" type="checkbox" value="1" />';
[179] Fix | Delete
if ( $localized_text ) {
[180] Fix | Delete
$dismiss_html .= esc_html( $localized_text );
[181] Fix | Delete
} else {
[182] Fix | Delete
$dismiss_html .= esc_html__( 'Dismiss this notice.', 'sitepress' );
[183] Fix | Delete
}
[184] Fix | Delete
$dismiss_html .= '</span></span>';
[185] Fix | Delete
[186] Fix | Delete
return $dismiss_html;
[187] Fix | Delete
}
[188] Fix | Delete
[189] Fix | Delete
/**
[190] Fix | Delete
* @param string|null $localized_text
[191] Fix | Delete
*
[192] Fix | Delete
* @return string
[193] Fix | Delete
*/
[194] Fix | Delete
private function get_collapse_html( $localized_text = null ) {
[195] Fix | Delete
$hide_html = '<span class="otgs-notice-collapse-hide"><span class="screen-reader-text">';
[196] Fix | Delete
if ( $localized_text ) {
[197] Fix | Delete
$hide_html .= esc_html( $localized_text );
[198] Fix | Delete
} else {
[199] Fix | Delete
$hide_html .= esc_html__( 'Hide this notice.', 'sitepress' );
[200] Fix | Delete
}
[201] Fix | Delete
$hide_html .= '</span></span>';
[202] Fix | Delete
[203] Fix | Delete
return $hide_html;
[204] Fix | Delete
}
[205] Fix | Delete
[206] Fix | Delete
/**
[207] Fix | Delete
* @param WPML_Notice $notice
[208] Fix | Delete
* @param string|null $localized_text
[209] Fix | Delete
*
[210] Fix | Delete
* @return string
[211] Fix | Delete
*/
[212] Fix | Delete
private function get_collapsed_html( WPML_Notice $notice, $localized_text = null ) {
[213] Fix | Delete
$content = '
[214] Fix | Delete
<div class="otgs-notice-collapsed-text">
[215] Fix | Delete
<p>%s
[216] Fix | Delete
<span class="otgs-notice-collapse-show notice-collapse"><span class="screen-reader-text">
[217] Fix | Delete
%s
[218] Fix | Delete
</span></span>
[219] Fix | Delete
</p>
[220] Fix | Delete
</div>
[221] Fix | Delete
<div class="otgs-notice-collapse-text">
[222] Fix | Delete
%s
[223] Fix | Delete
</div>
[224] Fix | Delete
';
[225] Fix | Delete
[226] Fix | Delete
$content = sprintf(
[227] Fix | Delete
$content,
[228] Fix | Delete
$notice->get_collapsed_text(),
[229] Fix | Delete
$localized_text ? esc_html( $localized_text ) : esc_html__( 'Show this notice.', 'sitepress' ),
[230] Fix | Delete
$notice->get_text()
[231] Fix | Delete
);
[232] Fix | Delete
[233] Fix | Delete
return $content;
[234] Fix | Delete
}
[235] Fix | Delete
[236] Fix | Delete
/**
[237] Fix | Delete
* @param WPML_Notice_Action $action
[238] Fix | Delete
*
[239] Fix | Delete
* @return string
[240] Fix | Delete
*/
[241] Fix | Delete
private function get_action_html( $action ) {
[242] Fix | Delete
$action_html = '';
[243] Fix | Delete
if ( $action->can_hide() ) {
[244] Fix | Delete
$action_html .= $this->get_hide_html( $action->get_text() );
[245] Fix | Delete
$this->hide_html_added = true;
[246] Fix | Delete
} elseif ( $action->can_dismiss() ) {
[247] Fix | Delete
$action_html .= $this->get_dismiss_html( $action->get_text() );
[248] Fix | Delete
$this->dismiss_html_added = true;
[249] Fix | Delete
} else {
[250] Fix | Delete
if ( $action->get_url() ) {
[251] Fix | Delete
$action_html .= $this->get_action_anchor( $action );
[252] Fix | Delete
} else {
[253] Fix | Delete
$action_html .= $action->get_text();
[254] Fix | Delete
}
[255] Fix | Delete
}
[256] Fix | Delete
[257] Fix | Delete
return $action_html;
[258] Fix | Delete
}
[259] Fix | Delete
[260] Fix | Delete
/**
[261] Fix | Delete
* @param WPML_Notice_Action $action
[262] Fix | Delete
*
[263] Fix | Delete
* @return string
[264] Fix | Delete
*/
[265] Fix | Delete
private function get_action_anchor( WPML_Notice_Action $action ) {
[266] Fix | Delete
$anchor_attributes = array();
[267] Fix | Delete
[268] Fix | Delete
$action_url = '<a';
[269] Fix | Delete
[270] Fix | Delete
$anchor_attributes['href'] = esc_url_raw( $action->get_url() );
[271] Fix | Delete
if ( $action->get_link_target() ) {
[272] Fix | Delete
$anchor_attributes['target'] = $action->get_link_target();
[273] Fix | Delete
}
[274] Fix | Delete
[275] Fix | Delete
$action_url_classes = array( 'notice-action' );
[276] Fix | Delete
if ( $action->must_display_as_button() ) {
[277] Fix | Delete
$button_style = 'button-secondary';
[278] Fix | Delete
if ( is_string( $action->must_display_as_button() ) ) {
[279] Fix | Delete
$button_style = $action->must_display_as_button();
[280] Fix | Delete
}
[281] Fix | Delete
$action_url_classes[] = esc_attr( $button_style );
[282] Fix | Delete
$action_url_classes[] = 'notice-action-' . esc_attr( $button_style );
[283] Fix | Delete
} else {
[284] Fix | Delete
$action_url_classes[] = 'notice-action-link';
[285] Fix | Delete
}
[286] Fix | Delete
$anchor_attributes['class'] = implode( ' ', $action_url_classes );
[287] Fix | Delete
[288] Fix | Delete
if ( $action->get_group_to_dismiss() ) {
[289] Fix | Delete
$anchor_attributes['data-dismiss-group'] = esc_attr( $action->get_group_to_dismiss() );
[290] Fix | Delete
}
[291] Fix | Delete
if ( $action->get_js_callback() ) {
[292] Fix | Delete
$anchor_attributes['data-js-callback'] = esc_attr( $action->get_js_callback() )
[293] Fix | Delete
. '"';
[294] Fix | Delete
}
[295] Fix | Delete
[296] Fix | Delete
foreach ( $anchor_attributes as $name => $value ) {
[297] Fix | Delete
$action_url .= ' ' . $name . '="' . $value . '"';
[298] Fix | Delete
}
[299] Fix | Delete
[300] Fix | Delete
$action_url .= $this->get_data_nonce_attribute();
[301] Fix | Delete
$action_url .= '>';
[302] Fix | Delete
$action_url .= $action->get_text();
[303] Fix | Delete
$action_url .= '</a>';
[304] Fix | Delete
[305] Fix | Delete
return $action_url;
[306] Fix | Delete
}
[307] Fix | Delete
[308] Fix | Delete
/**
[309] Fix | Delete
* @return string
[310] Fix | Delete
*/
[311] Fix | Delete
private function get_data_nonce_attribute() {
[312] Fix | Delete
return ' data-nonce="' . wp_create_nonce( WPML_Notices::NONCE_NAME ) . '"';
[313] Fix | Delete
}
[314] Fix | Delete
[315] Fix | Delete
/**
[316] Fix | Delete
* @param WPML_Notice $notice
[317] Fix | Delete
*
[318] Fix | Delete
* @return bool
[319] Fix | Delete
*/
[320] Fix | Delete
private function is_current_screen_allowed( WPML_Notice $notice ) {
[321] Fix | Delete
$allow_current_screen = true;
[322] Fix | Delete
$restrict_to_screen_ids = $notice->get_restrict_to_screen_ids();
[323] Fix | Delete
if ( $restrict_to_screen_ids && function_exists( 'get_current_screen' ) ) {
[324] Fix | Delete
$screen = get_current_screen();
[325] Fix | Delete
$allow_current_screen = $screen && in_array( $screen->id, $restrict_to_screen_ids, true );
[326] Fix | Delete
}
[327] Fix | Delete
[328] Fix | Delete
return $allow_current_screen;
[329] Fix | Delete
}
[330] Fix | Delete
[331] Fix | Delete
/**
[332] Fix | Delete
* @param WPML_Notice $notice
[333] Fix | Delete
* @param string $current_page
[334] Fix | Delete
*
[335] Fix | Delete
* @return bool
[336] Fix | Delete
*/
[337] Fix | Delete
private function is_current_page_prefix_allowed( WPML_Notice $notice, $current_page ) {
[338] Fix | Delete
$restrict_to_page_prefixes = $notice->get_restrict_to_page_prefixes();
[339] Fix | Delete
if ( $current_page && $restrict_to_page_prefixes ) {
[340] Fix | Delete
$allow_current_page_prefix = false;
[341] Fix | Delete
foreach ( $restrict_to_page_prefixes as $restrict_to_prefix ) {
[342] Fix | Delete
if ( stripos( $current_page, $restrict_to_prefix ) === 0 ) {
[343] Fix | Delete
$allow_current_page_prefix = true;
[344] Fix | Delete
break;
[345] Fix | Delete
}
[346] Fix | Delete
}
[347] Fix | Delete
[348] Fix | Delete
return $allow_current_page_prefix;
[349] Fix | Delete
}
[350] Fix | Delete
[351] Fix | Delete
return true;
[352] Fix | Delete
}
[353] Fix | Delete
[354] Fix | Delete
/**
[355] Fix | Delete
* @param WPML_Notice $notice
[356] Fix | Delete
*
[357] Fix | Delete
* @return bool
[358] Fix | Delete
*/
[359] Fix | Delete
private function is_current_page_allowed( WPML_Notice $notice ) {
[360] Fix | Delete
$current_page = array_key_exists( 'page', $_GET ) ? $_GET['page'] : null;
[361] Fix | Delete
[362] Fix | Delete
if ( ! $this->is_current_screen_allowed( $notice ) ) {
[363] Fix | Delete
return false;
[364] Fix | Delete
}
[365] Fix | Delete
[366] Fix | Delete
if ( $current_page ) {
[367] Fix | Delete
[368] Fix | Delete
$exclude_from_pages = $notice->get_exclude_from_pages();
[369] Fix | Delete
if ( $exclude_from_pages && in_array( $current_page, $exclude_from_pages, true ) ) {
[370] Fix | Delete
return false;
[371] Fix | Delete
}
[372] Fix | Delete
[373] Fix | Delete
if ( ! $this->is_current_page_prefix_allowed( $notice, $current_page ) ) {
[374] Fix | Delete
return false;
[375] Fix | Delete
}
[376] Fix | Delete
[377] Fix | Delete
$restrict_to_pages = $notice->get_restrict_to_pages();
[378] Fix | Delete
if ( $restrict_to_pages && ! in_array( $current_page, $restrict_to_pages, true ) ) {
[379] Fix | Delete
return false;
[380] Fix | Delete
}
[381] Fix | Delete
}
[382] Fix | Delete
[383] Fix | Delete
return true;
[384] Fix | Delete
}
[385] Fix | Delete
[386] Fix | Delete
/**
[387] Fix | Delete
* @param WPML_Notice $notice
[388] Fix | Delete
*
[389] Fix | Delete
* @return bool
[390] Fix | Delete
*/
[391] Fix | Delete
private function is_allowed_by_callback( WPML_Notice $notice ) {
[392] Fix | Delete
$allow_by_callback = true;
[393] Fix | Delete
$display_callbacks = $notice->get_display_callbacks();
[394] Fix | Delete
if ( $display_callbacks ) {
[395] Fix | Delete
$allow_by_callback = false;
[396] Fix | Delete
foreach ( $display_callbacks as $callback ) {
[397] Fix | Delete
if ( is_callable( $callback ) && call_user_func( $callback ) ) {
[398] Fix | Delete
$allow_by_callback = true;
[399] Fix | Delete
break;
[400] Fix | Delete
}
[401] Fix | Delete
}
[402] Fix | Delete
}
[403] Fix | Delete
[404] Fix | Delete
return $allow_by_callback;
[405] Fix | Delete
}
[406] Fix | Delete
}
[407] Fix | Delete
[408] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function