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/clone/wp-conte.../plugins/advanced.../classes
File: ad-health-notices.php
<?php // phpcs:ignoreFile
[0] Fix | Delete
use AdvancedAds\Utilities\Conditional;
[1] Fix | Delete
[2] Fix | Delete
/**
[3] Fix | Delete
* Container class for Ad Health notice handling
[4] Fix | Delete
*
[5] Fix | Delete
* @package WordPress
[6] Fix | Delete
* @subpackage Advanced Ads Plugin
[7] Fix | Delete
* @since 1.12
[8] Fix | Delete
*
[9] Fix | Delete
* related scripts / functions
[10] Fix | Delete
*
[11] Fix | Delete
* advads_push_notice() function to push notifications using AJAX in admin/assets/js/admin-global.js
[12] Fix | Delete
* push_ad_health_notice() in Advanced_Ads_Ad_Ajax_Callbacks to push notifications sent via AJAX
[13] Fix | Delete
* Advanced_Ads_Checks – for the various checks
[14] Fix | Delete
* list of notification texts in admin/includes/ad-health-notices.php
[15] Fix | Delete
*/
[16] Fix | Delete
class Advanced_Ads_Ad_Health_Notices {
[17] Fix | Delete
[18] Fix | Delete
/**
[19] Fix | Delete
* Instance of this class.
[20] Fix | Delete
*
[21] Fix | Delete
* @var object
[22] Fix | Delete
*/
[23] Fix | Delete
protected static $instance = null;
[24] Fix | Delete
[25] Fix | Delete
/**
[26] Fix | Delete
* Options
[27] Fix | Delete
*
[28] Fix | Delete
* @var array
[29] Fix | Delete
*/
[30] Fix | Delete
protected $options;
[31] Fix | Delete
[32] Fix | Delete
/**
[33] Fix | Delete
* All detected notices
[34] Fix | Delete
*
[35] Fix | Delete
* Structure is
[36] Fix | Delete
* [notice_key] => array(
[37] Fix | Delete
* 'text' - if not given, it uses the default text for output )
[38] Fix | Delete
* 'orig_key' - original notice key
[39] Fix | Delete
* )
[40] Fix | Delete
*
[41] Fix | Delete
* @var array
[42] Fix | Delete
*/
[43] Fix | Delete
public $notices = [];
[44] Fix | Delete
[45] Fix | Delete
/**
[46] Fix | Delete
* All ignored notices
[47] Fix | Delete
*
[48] Fix | Delete
* @var array
[49] Fix | Delete
*/
[50] Fix | Delete
public $ignore = [];
[51] Fix | Delete
[52] Fix | Delete
/**
[53] Fix | Delete
* All displayed notices ($notices minus $hidden)
[54] Fix | Delete
*
[55] Fix | Delete
* @var array
[56] Fix | Delete
*/
[57] Fix | Delete
public $displayed_notices = [];
[58] Fix | Delete
[59] Fix | Delete
/**
[60] Fix | Delete
* Load default notices
[61] Fix | Delete
*
[62] Fix | Delete
* @var array
[63] Fix | Delete
*/
[64] Fix | Delete
public $default_notices = [];
[65] Fix | Delete
[66] Fix | Delete
/**
[67] Fix | Delete
* The last notice key saved
[68] Fix | Delete
*
[69] Fix | Delete
* @var string
[70] Fix | Delete
*/
[71] Fix | Delete
public $last_saved_notice_key = false;
[72] Fix | Delete
[73] Fix | Delete
/**
[74] Fix | Delete
* Name of the transient saved for daily checks in the backend
[75] Fix | Delete
*
[76] Fix | Delete
* @const string
[77] Fix | Delete
*/
[78] Fix | Delete
const DAILY_CHECK_TRANSIENT_NAME = 'advanced-ads-daily-ad-health-check-ran';
[79] Fix | Delete
[80] Fix | Delete
/**
[81] Fix | Delete
* Plugin class
[82] Fix | Delete
*
[83] Fix | Delete
* @var string
[84] Fix | Delete
*/
[85] Fix | Delete
private $plugin;
[86] Fix | Delete
[87] Fix | Delete
/**
[88] Fix | Delete
* Advanced_Ads_Ad_Health_Notices constructor.
[89] Fix | Delete
*/
[90] Fix | Delete
public function __construct() {
[91] Fix | Delete
[92] Fix | Delete
// failsafe for there were some reports of 502 errors.
[93] Fix | Delete
if ( 1 < did_action( 'plugins_loaded' ) ) {
[94] Fix | Delete
return;
[95] Fix | Delete
}
[96] Fix | Delete
[97] Fix | Delete
// stop here if notices are disabled.
[98] Fix | Delete
if ( ! self::notices_enabled() ) {
[99] Fix | Delete
return;
[100] Fix | Delete
}
[101] Fix | Delete
[102] Fix | Delete
// load default notices.
[103] Fix | Delete
if ( [] === $this->default_notices ) {
[104] Fix | Delete
include ADVADS_ABSPATH . '/admin/includes/ad-health-notices.php';
[105] Fix | Delete
$this->default_notices = $advanced_ads_ad_health_notices;
[106] Fix | Delete
}
[107] Fix | Delete
[108] Fix | Delete
// fills the class arrays.
[109] Fix | Delete
$this->load_notices();
[110] Fix | Delete
[111] Fix | Delete
/**
[112] Fix | Delete
* Run checks
[113] Fix | Delete
* needs to run after plugins_loaded with priority 10
[114] Fix | Delete
* current_screen seems like the perfect hook
[115] Fix | Delete
*/
[116] Fix | Delete
add_action( 'current_screen', [ $this, 'run_checks' ], 20 );
[117] Fix | Delete
[118] Fix | Delete
// add notification when an ad expires.
[119] Fix | Delete
add_action( 'advanced-ads-ad-expired', [ $this, 'ad_expired' ], 10, 2 );
[120] Fix | Delete
}
[121] Fix | Delete
[122] Fix | Delete
/**
[123] Fix | Delete
* Check if notices are enabled using "disable-notices" option in plugin settings
[124] Fix | Delete
*
[125] Fix | Delete
* @return bool
[126] Fix | Delete
*/
[127] Fix | Delete
public static function notices_enabled() {
[128] Fix | Delete
$options = Advanced_Ads::get_instance()->options();
[129] Fix | Delete
[130] Fix | Delete
return empty( $options['disable-notices'] );
[131] Fix | Delete
}
[132] Fix | Delete
[133] Fix | Delete
/**
[134] Fix | Delete
* Return an instance of this class.
[135] Fix | Delete
*
[136] Fix | Delete
* @return object A single instance of this class.
[137] Fix | Delete
*/
[138] Fix | Delete
public static function get_instance() {
[139] Fix | Delete
[140] Fix | Delete
// If the single instance hasn't been set, set it now.
[141] Fix | Delete
if ( null === self::$instance ) {
[142] Fix | Delete
self::$instance = new self();
[143] Fix | Delete
}
[144] Fix | Delete
[145] Fix | Delete
return self::$instance;
[146] Fix | Delete
}
[147] Fix | Delete
[148] Fix | Delete
/**
[149] Fix | Delete
* Load notice arrays
[150] Fix | Delete
*/
[151] Fix | Delete
public function load_notices() {
[152] Fix | Delete
[153] Fix | Delete
$options = $this->options();
[154] Fix | Delete
[155] Fix | Delete
// load notices from "notices".
[156] Fix | Delete
$this->notices = isset( $options['notices'] ) ? $options['notices'] : [];
[157] Fix | Delete
[158] Fix | Delete
/**
[159] Fix | Delete
* Cleanup notices
[160] Fix | Delete
*/
[161] Fix | Delete
foreach ( $this->notices as $_key => $_notice ) {
[162] Fix | Delete
// without valid key caused by an issue prior to 1.13.3.
[163] Fix | Delete
if ( empty( $_key ) ) {
[164] Fix | Delete
unset( $this->notices[ $_key ] );
[165] Fix | Delete
};
[166] Fix | Delete
[167] Fix | Delete
$time = current_time( 'timestamp', 0 );
[168] Fix | Delete
$notice_array = $this->get_notice_array_for_key( $_key );
[169] Fix | Delete
[170] Fix | Delete
// handle notices with a timeout.
[171] Fix | Delete
if ( isset( $_notice['closed'] ) ) {
[172] Fix | Delete
// remove notice when timeout expired – was closed longer ago than timeout set in the notice options.
[173] Fix | Delete
if ( empty( $notice_array['timeout'] )
[174] Fix | Delete
|| ( ( $time - $_notice['closed'] ) > $notice_array['timeout'] ) ) {
[175] Fix | Delete
$this->remove( $_key );
[176] Fix | Delete
} else {
[177] Fix | Delete
// just ignore notice if timeout is still valid.
[178] Fix | Delete
unset( $this->notices[ $_key ] );
[179] Fix | Delete
}
[180] Fix | Delete
}
[181] Fix | Delete
[182] Fix | Delete
// check if notice still exists.
[183] Fix | Delete
if ( [] === $this->get_notice_array_for_key( $_key ) ) {
[184] Fix | Delete
unset( $this->notices[ $_key ] );
[185] Fix | Delete
}
[186] Fix | Delete
}
[187] Fix | Delete
[188] Fix | Delete
// unignore notices if `show-hidden=true` is set in the URL.
[189] Fix | Delete
if ( isset( $_GET['advads_nonce'] ) && wp_verify_nonce( wp_unslash( $_GET['advads_nonce'] ), 'advanced-ads-show-hidden-notices' )
[190] Fix | Delete
&& isset( $_GET['advads-show-hidden-notices'] ) && 'true' === $_GET['advads-show-hidden-notices'] ) {
[191] Fix | Delete
$this->unignore();
[192] Fix | Delete
// remove the argument from the URL.
[193] Fix | Delete
add_filter( 'removable_query_args', [ $this, 'remove_query_vars_after_notice_update' ] );
[194] Fix | Delete
}
[195] Fix | Delete
[196] Fix | Delete
// load hidden notices.
[197] Fix | Delete
$this->ignore = $this->get_valid_ignored();
[198] Fix | Delete
[199] Fix | Delete
// get displayed notices
[200] Fix | Delete
// get keys of notices.
[201] Fix | Delete
$notice_keys = array_keys( $this->notices );
[202] Fix | Delete
$this->displayed_notices = array_diff( $notice_keys, $this->ignore );
[203] Fix | Delete
}
[204] Fix | Delete
[205] Fix | Delete
/**
[206] Fix | Delete
* Remove query var from URL after notice was updated
[207] Fix | Delete
*
[208] Fix | Delete
* @param array $removable_query_args array with removable query vars.
[209] Fix | Delete
* @return array updated query vars.
[210] Fix | Delete
*/
[211] Fix | Delete
public function remove_query_vars_after_notice_update( $removable_query_args ) {
[212] Fix | Delete
$removable_query_args[] = 'advads-show-hidden-notices';
[213] Fix | Delete
$removable_query_args[] = 'advads_nonce';
[214] Fix | Delete
[215] Fix | Delete
return $removable_query_args;
[216] Fix | Delete
}
[217] Fix | Delete
[218] Fix | Delete
/**
[219] Fix | Delete
* Manage when to run checks
[220] Fix | Delete
* - only when users have ads
[221] Fix | Delete
* - once per day on any backend page
[222] Fix | Delete
* - on each Advanced Ads related page
[223] Fix | Delete
*/
[224] Fix | Delete
public function run_checks() {
[225] Fix | Delete
[226] Fix | Delete
// run in WP Admin only and if there are any ads.
[227] Fix | Delete
if ( ! is_admin() || ! Advanced_Ads::get_number_of_ads() ) {
[228] Fix | Delete
return;
[229] Fix | Delete
}
[230] Fix | Delete
[231] Fix | Delete
// don’t run on AJAX calls.
[232] Fix | Delete
if ( wp_doing_ajax() ) {
[233] Fix | Delete
return;
[234] Fix | Delete
}
[235] Fix | Delete
[236] Fix | Delete
// run only daily unless we are on an Advanced Ads related page.
[237] Fix | Delete
if ( ! Conditional::is_screen_advanced_ads()
[238] Fix | Delete
&& get_transient( self::DAILY_CHECK_TRANSIENT_NAME ) ) {
[239] Fix | Delete
return;
[240] Fix | Delete
}
[241] Fix | Delete
[242] Fix | Delete
$this->checks();
[243] Fix | Delete
}
[244] Fix | Delete
[245] Fix | Delete
/**
[246] Fix | Delete
* General checks done on each Advanced Ads-related page or once per day
[247] Fix | Delete
*/
[248] Fix | Delete
public function checks() {
[249] Fix | Delete
[250] Fix | Delete
if ( ! Advanced_Ads_Checks::php_version_minimum() ) {
[251] Fix | Delete
$this->add( 'old_php' );
[252] Fix | Delete
} else {
[253] Fix | Delete
$this->remove( 'old_php' );
[254] Fix | Delete
}
[255] Fix | Delete
if ( count( Advanced_Ads_Checks::conflicting_plugins() ) ) {
[256] Fix | Delete
$this->add( 'conflicting_plugins' );
[257] Fix | Delete
} else {
[258] Fix | Delete
$this->remove( 'conflicting_plugins' );
[259] Fix | Delete
}
[260] Fix | Delete
if ( count( Advanced_Ads_Checks::php_extensions() ) ) {
[261] Fix | Delete
$this->add( 'php_extensions_missing' );
[262] Fix | Delete
} else {
[263] Fix | Delete
$this->remove( 'php_extensions_missing' );
[264] Fix | Delete
}
[265] Fix | Delete
if ( Advanced_Ads_Checks::ads_disabled() ) {
[266] Fix | Delete
$this->add( 'ads_disabled' );
[267] Fix | Delete
} else {
[268] Fix | Delete
$this->remove( 'ads_disabled' );
[269] Fix | Delete
}
[270] Fix | Delete
if ( Advanced_Ads_Checks::get_defined_constants() ) {
[271] Fix | Delete
$this->add( 'constants_enabled' );
[272] Fix | Delete
} else {
[273] Fix | Delete
$this->remove( 'constants_enabled' );
[274] Fix | Delete
}
[275] Fix | Delete
if ( Advanced_Ads_Checks::assets_expired() ) {
[276] Fix | Delete
$this->add( 'assets_expired' );
[277] Fix | Delete
} else {
[278] Fix | Delete
$this->remove( 'assets_expired' );
[279] Fix | Delete
}
[280] Fix | Delete
if ( Advanced_Ads_Checks::licenses_invalid() ) {
[281] Fix | Delete
$this->add( 'license_invalid' );
[282] Fix | Delete
} else {
[283] Fix | Delete
$this->remove( 'license_invalid' );
[284] Fix | Delete
}
[285] Fix | Delete
if ( class_exists( 'BuddyPress', false ) && ! defined( 'AAP_VERSION' ) ) {
[286] Fix | Delete
$this->add( 'buddypress_no_pro' );
[287] Fix | Delete
} else {
[288] Fix | Delete
$this->remove( 'buddypress_no_pro' );
[289] Fix | Delete
}
[290] Fix | Delete
if ( class_exists( 'bbPress', false ) && ! defined( 'AAP_VERSION' ) ) {
[291] Fix | Delete
$this->add( 'bbpress_no_pro' );
[292] Fix | Delete
} else {
[293] Fix | Delete
$this->remove( 'bbpress_no_pro' );
[294] Fix | Delete
}
[295] Fix | Delete
if ( defined( 'ICL_SITEPRESS_VERSION' ) ) {
[296] Fix | Delete
$this->add( 'WPML_active' );
[297] Fix | Delete
} else {
[298] Fix | Delete
$this->remove( 'WPML_active' );
[299] Fix | Delete
}
[300] Fix | Delete
if ( Advanced_Ads_Checks::active_amp_plugin() ) {
[301] Fix | Delete
$this->add( 'AMP_active' );
[302] Fix | Delete
} else {
[303] Fix | Delete
$this->remove( 'AMP_active' );
[304] Fix | Delete
}
[305] Fix | Delete
if ( Advanced_Ads_Checks::wp_engine_hosting() ) {
[306] Fix | Delete
$this->add( 'wpengine' );
[307] Fix | Delete
}
[308] Fix | Delete
if ( count( Advanced_Ads_Checks::ads_txt_plugins() ) ) {
[309] Fix | Delete
$this->add( 'ads_txt_plugins_enabled' );
[310] Fix | Delete
} else {
[311] Fix | Delete
$this->remove( 'ads_txt_plugins_enabled' );
[312] Fix | Delete
}
[313] Fix | Delete
if ( count( Advanced_Ads_Checks::header_footer_plugins() ) ) {
[314] Fix | Delete
$this->add( 'header_footer_plugins_enabled' );
[315] Fix | Delete
} else {
[316] Fix | Delete
$this->remove( 'header_footer_plugins_enabled' );
[317] Fix | Delete
}
[318] Fix | Delete
[319] Fix | Delete
set_transient( self::DAILY_CHECK_TRANSIENT_NAME, true, DAY_IN_SECONDS );
[320] Fix | Delete
}
[321] Fix | Delete
[322] Fix | Delete
/**
[323] Fix | Delete
* Add a notice to the queue
[324] Fix | Delete
*
[325] Fix | Delete
* @param string $notice_key notice key to be added to the notice array.
[326] Fix | Delete
* @param array $atts additional attributes.
[327] Fix | Delete
*
[328] Fix | Delete
* attributes
[329] Fix | Delete
* - append_key string attached to the key; enables to create multiple messages for one original key
[330] Fix | Delete
* - append_text text added to the default message
[331] Fix | Delete
* - ad_id ID of an ad, attaches the link to the ad edit page to the message
[332] Fix | Delete
*/
[333] Fix | Delete
public function add( $notice_key, $atts = [] ) {
[334] Fix | Delete
[335] Fix | Delete
// stop here if notices are disabled.
[336] Fix | Delete
if ( empty( $notice_key ) || ! self::notices_enabled() ) {
[337] Fix | Delete
return;
[338] Fix | Delete
}
[339] Fix | Delete
[340] Fix | Delete
// add string to key.
[341] Fix | Delete
if ( ! empty( $atts['append_key'] ) ) {
[342] Fix | Delete
$orig_notice_key = $notice_key;
[343] Fix | Delete
$notice_key .= $atts['append_key'];
[344] Fix | Delete
}
[345] Fix | Delete
[346] Fix | Delete
$notice_key = esc_attr( $notice_key );
[347] Fix | Delete
$options_before = $options = $this->options();
[348] Fix | Delete
[349] Fix | Delete
// load notices from "queue".
[350] Fix | Delete
$notices = isset( $options['notices'] ) ? $options['notices'] : [];
[351] Fix | Delete
[352] Fix | Delete
// check if notice_key was already saved, this prevents the same notice from showing up in different forms.
[353] Fix | Delete
if ( isset( $notices[ $notice_key ] ) ) {
[354] Fix | Delete
return;
[355] Fix | Delete
}
[356] Fix | Delete
[357] Fix | Delete
// save the new notice key.
[358] Fix | Delete
$notices[ $notice_key ] = [];
[359] Fix | Delete
[360] Fix | Delete
// save text, if given.
[361] Fix | Delete
if ( ! empty( $atts['text'] ) ) {
[362] Fix | Delete
$notices[ $notice_key ]['text'] = $atts['text'];
[363] Fix | Delete
}
[364] Fix | Delete
[365] Fix | Delete
// attach link to ad, if given.
[366] Fix | Delete
if ( ! empty( $atts['ad_id'] ) ) {
[367] Fix | Delete
$id = absint( $atts['ad_id'] );
[368] Fix | Delete
$ad = \Advanced_Ads\Ad_Repository::get( $id );
[369] Fix | Delete
if ( $id && isset( $ad->title ) && '' !== $ad->title ) {
[370] Fix | Delete
$edit_link = ' <a href="' . get_edit_post_link( $id ) . '">' . $ad->title . '</a>';
[371] Fix | Delete
$notices[ $notice_key ]['append_text'] = isset( $notices[ $notice_key ]['append_text'] ) ? $notices[ $notice_key ]['append_text'] . $edit_link : $edit_link;
[372] Fix | Delete
}
[373] Fix | Delete
}
[374] Fix | Delete
[375] Fix | Delete
// save the original key, if we manipulated it.
[376] Fix | Delete
if ( ! empty( $atts['append_key'] ) ) {
[377] Fix | Delete
$notices[ $notice_key ]['orig_key'] = $orig_notice_key;
[378] Fix | Delete
}
[379] Fix | Delete
[380] Fix | Delete
// add more text.
[381] Fix | Delete
if ( ! empty( $atts['append_text'] ) ) {
[382] Fix | Delete
$notices[ $notice_key ]['append_text'] = esc_attr( $atts['append_text'] );
[383] Fix | Delete
}
[384] Fix | Delete
[385] Fix | Delete
// add current time – we store localized time including the offset set in WP.
[386] Fix | Delete
$notices[ $notice_key ]['time'] = current_time( 'timestamp', 0 );
[387] Fix | Delete
[388] Fix | Delete
$this->last_saved_notice_key = $notice_key;
[389] Fix | Delete
[390] Fix | Delete
$options['notices'] = $notices;
[391] Fix | Delete
// update db if changed.
[392] Fix | Delete
if ( $options_before !== $options ) {
[393] Fix | Delete
$this->update_options( $options );
[394] Fix | Delete
[395] Fix | Delete
// update already registered notices.
[396] Fix | Delete
$this->load_notices();
[397] Fix | Delete
}
[398] Fix | Delete
}
[399] Fix | Delete
[400] Fix | Delete
/**
[401] Fix | Delete
* Updating an existing notice or add it, if it doesn’t exist, yet
[402] Fix | Delete
*
[403] Fix | Delete
* @param string $notice_key notice key to be added to the notice array.
[404] Fix | Delete
* @param array $atts additional attributes.
[405] Fix | Delete
*
[406] Fix | Delete
* attributes:
[407] Fix | Delete
* - append_text – text added to the default message
[408] Fix | Delete
*/
[409] Fix | Delete
public function update( $notice_key, $atts = [] ) {
[410] Fix | Delete
[411] Fix | Delete
// stop here if notices are disabled.
[412] Fix | Delete
if ( empty( $notice_key ) || ! self::notices_enabled() ) {
[413] Fix | Delete
return;
[414] Fix | Delete
}
[415] Fix | Delete
[416] Fix | Delete
// check if the notice already exists.
[417] Fix | Delete
$notice_key = esc_attr( $notice_key );
[418] Fix | Delete
$options = $this->options();
[419] Fix | Delete
$options_before = $options;
[420] Fix | Delete
[421] Fix | Delete
// load notices from "queue".
[422] Fix | Delete
$notices = isset( $options['notices'] ) ? $options['notices'] : [];
[423] Fix | Delete
[424] Fix | Delete
// check if notice_key was already saved, this prevents the same notice from showing up in different forms.
[425] Fix | Delete
if ( ! isset( $notices[ $notice_key ] ) ) {
[426] Fix | Delete
$this->add( $notice_key, $atts );
[427] Fix | Delete
[428] Fix | Delete
$notice_key = $this->last_saved_notice_key;
[429] Fix | Delete
[430] Fix | Delete
// just in case, get notices again.
[431] Fix | Delete
$notices = $this->notices;
[432] Fix | Delete
} else {
[433] Fix | Delete
// add more text if this is an update.
[434] Fix | Delete
if ( ! empty( $atts['append_text'] ) ) {
[435] Fix | Delete
$notices[ $notice_key ]['append_text'] = isset( $notices[ $notice_key ]['append_text'] ) ? $notices[ $notice_key ]['append_text'] . $atts['append_text'] : $atts['append_text'];
[436] Fix | Delete
}
[437] Fix | Delete
// add `closed` marker, if given.
[438] Fix | Delete
if ( ! empty( $atts['closed'] ) ) {
[439] Fix | Delete
$notices[ $notice_key ]['closed'] = absint( $atts['closed'] );
[440] Fix | Delete
}
[441] Fix | Delete
}
[442] Fix | Delete
[443] Fix | Delete
// update db.
[444] Fix | Delete
$options['notices'] = $notices;
[445] Fix | Delete
[446] Fix | Delete
// update db if changed.
[447] Fix | Delete
if ( $options_before !== $options ) {
[448] Fix | Delete
$this->update_options( $options );
[449] Fix | Delete
[450] Fix | Delete
// update already registered notices.
[451] Fix | Delete
$this->load_notices();
[452] Fix | Delete
}
[453] Fix | Delete
[454] Fix | Delete
}
[455] Fix | Delete
[456] Fix | Delete
/**
[457] Fix | Delete
* Decide based on the notice, whether to remove or ignore it
[458] Fix | Delete
*
[459] Fix | Delete
* @param string $notice_key key of the notice.
[460] Fix | Delete
*/
[461] Fix | Delete
public function hide( $notice_key ) {
[462] Fix | Delete
if ( empty( $notice_key ) ) {
[463] Fix | Delete
return;
[464] Fix | Delete
}
[465] Fix | Delete
[466] Fix | Delete
// get original notice array for the "hide" attribute.
[467] Fix | Delete
$notice_array = $this->get_notice_array_for_key( $notice_key );
[468] Fix | Delete
[469] Fix | Delete
// handle notices with a timeout.
[470] Fix | Delete
// set `closed` timestamp if the notice definition has a timeout information.
[471] Fix | Delete
if ( isset( $notice_array['timeout'] ) ) {
[472] Fix | Delete
$this->update( $notice_key, [ 'closed' => current_time( 'timestamp', 0 ) ] );
[473] Fix | Delete
[474] Fix | Delete
return;
[475] Fix | Delete
}
[476] Fix | Delete
[477] Fix | Delete
if ( isset( $notice_array['hide'] ) && false === $notice_array['hide'] ) {
[478] Fix | Delete
// remove item.
[479] Fix | Delete
self::get_instance()->remove( $notice_key );
[480] Fix | Delete
} else {
[481] Fix | Delete
// hide item.
[482] Fix | Delete
self::get_instance()->ignore( $notice_key );
[483] Fix | Delete
}
[484] Fix | Delete
[485] Fix | Delete
}
[486] Fix | Delete
[487] Fix | Delete
/**
[488] Fix | Delete
* Remove notice
[489] Fix | Delete
* Would remove it from "notice" array. The notice can be added anytime again
[490] Fix | Delete
* practically, this allows users to "skip" an notice if they are sure that it was only temporary
[491] Fix | Delete
*
[492] Fix | Delete
* @param string $notice_key notice key to be removed.
[493] Fix | Delete
*/
[494] Fix | Delete
public function remove( $notice_key ) {
[495] Fix | Delete
[496] Fix | Delete
// stop here if notices are disabled.
[497] Fix | Delete
if ( empty( $notice_key ) || ! self::notices_enabled() ) {
[498] Fix | Delete
return;
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function