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/ninja-fo.../includes/Admin
File: Notices.php
<?php if ( ! defined( 'ABSPATH' ) ) exit;
[0] Fix | Delete
[1] Fix | Delete
/**
[2] Fix | Delete
* NF_Notices Class
[3] Fix | Delete
*
[4] Fix | Delete
* Can be simply used be adding another line into the nf_admin_notices() function under notices.php
[5] Fix | Delete
*
[6] Fix | Delete
* Can be extended to create more advanced notices to include triggered events
[7] Fix | Delete
*
[8] Fix | Delete
* @since 2.9
[9] Fix | Delete
*/
[10] Fix | Delete
[11] Fix | Delete
class NF_Admin_Notices
[12] Fix | Delete
{
[13] Fix | Delete
// Highlander the instance
[14] Fix | Delete
static $instance;
[15] Fix | Delete
[16] Fix | Delete
public static function instance()
[17] Fix | Delete
{
[18] Fix | Delete
if ( ! isset( self::$instance ) ) {
[19] Fix | Delete
self::$instance = new NF_Notices();
[20] Fix | Delete
}
[21] Fix | Delete
[22] Fix | Delete
return self::$instance;
[23] Fix | Delete
}
[24] Fix | Delete
[25] Fix | Delete
public $notice_spam = 0;
[26] Fix | Delete
public $notice_spam_max = 1;
[27] Fix | Delete
[28] Fix | Delete
// Basic actions to run
[29] Fix | Delete
public function __construct(){
[30] Fix | Delete
[31] Fix | Delete
// Runs the admin notice ignore function incase a dismiss button has been clicked
[32] Fix | Delete
add_action( 'admin_init', array( $this, 'admin_notice_ignore' ) );
[33] Fix | Delete
[34] Fix | Delete
// Runs the admin notice temp ignore function incase a temp dismiss link has been clicked
[35] Fix | Delete
add_action( 'admin_init', array( $this, 'admin_notice_temp_ignore' ) );
[36] Fix | Delete
[37] Fix | Delete
}
[38] Fix | Delete
[39] Fix | Delete
// Checks to ensure notices aren't disabled and the user has the correct permissions.
[40] Fix | Delete
public function nf_admin_notice() {
[41] Fix | Delete
[42] Fix | Delete
$nf_settings = get_option( 'ninja_forms_settings' );
[43] Fix | Delete
if ( ! isset( $nf_settings[ 'disable_admin_notices' ] ) || ( isset( $nf_settings[ 'disable_admin_notices' ] ) && $nf_settings[ 'disable_admin_notices' ] == 0 ) ){
[44] Fix | Delete
if ( current_user_can( apply_filters( 'ninja_forms_admin_parent_menu_capabilities', 'manage_options' ) ) ) {
[45] Fix | Delete
return true;
[46] Fix | Delete
}
[47] Fix | Delete
}
[48] Fix | Delete
return false;
[49] Fix | Delete
[50] Fix | Delete
}
[51] Fix | Delete
[52] Fix | Delete
// Primary notice function that can be called from an outside function sending necessary variables
[53] Fix | Delete
public function admin_notice( $admin_notices ) {
[54] Fix | Delete
[55] Fix | Delete
// Check options
[56] Fix | Delete
if ( ! $this->nf_admin_notice() ) {
[57] Fix | Delete
return false;
[58] Fix | Delete
}
[59] Fix | Delete
[60] Fix | Delete
foreach ( $admin_notices as $slug => $admin_notice ) {
[61] Fix | Delete
[62] Fix | Delete
if ( isset ( $admin_notice[ 'ignore_spam' ] ) && true == $admin_notice[ 'ignore_spam' ] ) {
[63] Fix | Delete
$ignore_spam = true;
[64] Fix | Delete
} else {
[65] Fix | Delete
$ignore_spam = false;
[66] Fix | Delete
}
[67] Fix | Delete
[68] Fix | Delete
// Call for spam protection
[69] Fix | Delete
if ( ! $ignore_spam && $this->anti_notice_spam() ) {
[70] Fix | Delete
continue;
[71] Fix | Delete
}
[72] Fix | Delete
[73] Fix | Delete
// Check for proper page to display on
[74] Fix | Delete
if ( isset( $admin_notices[ $slug ][ 'pages' ] ) && is_array( $admin_notices[ $slug ][ 'pages' ] )
[75] Fix | Delete
|| isset( $admin_notices[ $slug ][ 'blacklist' ] ) && is_array( $admin_notices[ $slug ][ 'blacklist' ] )
[76] Fix | Delete
) {
[77] Fix | Delete
[78] Fix | Delete
if( ( isset( $admin_notices[ $slug ][ 'blacklist' ] ) && $this->admin_notice_pages_blacklist( $admin_notices[ $slug ][ 'blacklist' ] ) )
[79] Fix | Delete
|| ( isset( $admin_notices[ $slug ][ 'pages' ] ) && ! $this->admin_notice_pages( $admin_notices[ $slug ][ 'pages' ] ) )
[80] Fix | Delete
) {
[81] Fix | Delete
continue;
[82] Fix | Delete
}
[83] Fix | Delete
}
[84] Fix | Delete
[85] Fix | Delete
[86] Fix | Delete
[87] Fix | Delete
// Check for required fields
[88] Fix | Delete
if ( ! $this->required_fields( $admin_notices[ $slug ] ) ) {
[89] Fix | Delete
[90] Fix | Delete
// Get the current date then set start date to either passed value or current date value and add interval
[91] Fix | Delete
$current_date = current_time( "n/j/Y" );
[92] Fix | Delete
$start = ( isset( $admin_notices[ $slug ][ 'start' ] ) ? $admin_notices[ $slug ][ 'start' ] : $current_date );
[93] Fix | Delete
$start = date( "n/j/Y", strtotime( $start ) );
[94] Fix | Delete
$date_array = explode( '/', $start );
[95] Fix | Delete
$interval = ( isset( $admin_notices[ $slug ][ 'int' ] ) ? $admin_notices[ $slug ][ 'int' ] : 0 );
[96] Fix | Delete
$date_array[1] += $interval;
[97] Fix | Delete
$start = date( "n/j/Y", mktime( 0, 0, 0, $date_array[0], $date_array[1], $date_array[2] ) );
[98] Fix | Delete
[99] Fix | Delete
// This is the main notices storage option
[100] Fix | Delete
$admin_notices_option = get_option( 'nf_admin_notice', array() );
[101] Fix | Delete
// Check if the message is already stored and if so just grab the key otherwise store the message and its associated date information
[102] Fix | Delete
if ( ! array_key_exists( $slug, $admin_notices_option ) ) {
[103] Fix | Delete
$admin_notices_option[ $slug ][ 'start' ] = $start;
[104] Fix | Delete
$admin_notices_option[ $slug ][ 'int' ] = $interval;
[105] Fix | Delete
update_option( 'nf_admin_notice', $admin_notices_option );
[106] Fix | Delete
}
[107] Fix | Delete
[108] Fix | Delete
// Sanity check to ensure we have accurate information
[109] Fix | Delete
// New date information will not overwrite old date information
[110] Fix | Delete
$admin_display_check = ( isset( $admin_notices_option[ $slug ][ 'dismissed' ] ) ? $admin_notices_option[ $slug ][ 'dismissed'] : 0 );
[111] Fix | Delete
$admin_display_start = ( isset( $admin_notices_option[ $slug ][ 'start' ] ) ? $admin_notices_option[ $slug ][ 'start'] : $start );
[112] Fix | Delete
$admin_display_interval = ( isset( $admin_notices_option[ $slug ][ 'int' ] ) ? $admin_notices_option[ $slug ][ 'int'] : $interval );
[113] Fix | Delete
$admin_display_msg = ( isset( $admin_notices[ $slug ][ 'msg' ] ) ? $admin_notices[ $slug ][ 'msg'] : '' );
[114] Fix | Delete
$admin_display_title = ( isset( $admin_notices[ $slug ][ 'title' ] ) ? $admin_notices[ $slug ][ 'title'] : '' );
[115] Fix | Delete
$admin_display_link = ( isset( $admin_notices[ $slug ][ 'link' ] ) ? $admin_notices[ $slug ][ 'link' ] : '' );
[116] Fix | Delete
$admin_can_dismiss = ( isset( $admin_notices[ $slug ][ 'dismiss' ] ) ? $admin_notices[ $slug ][ 'dismiss' ] : 1 );
[117] Fix | Delete
$output_css = false;
[118] Fix | Delete
[119] Fix | Delete
// Ensure the notice hasn't been hidden and that the current date is after the start date
[120] Fix | Delete
if ( $admin_display_check == 0 && strtotime( $admin_display_start ) <= strtotime( $current_date ) ) {
[121] Fix | Delete
[122] Fix | Delete
// Get remaining query string
[123] Fix | Delete
$query_str = esc_url( add_query_arg( 'nf_admin_notice_ignore', $slug ) );
[124] Fix | Delete
[125] Fix | Delete
// Admin notice display output
[126] Fix | Delete
echo '<div class="update-nag nf-admin-notice">';
[127] Fix | Delete
echo '<div class="nf-notice-logo"></div>';
[128] Fix | Delete
echo '<div class="nf-notice-container">';
[129] Fix | Delete
echo '<div class="nf-notice-title">';
[130] Fix | Delete
echo esc_html( $admin_display_title );
[131] Fix | Delete
echo '</div>';
[132] Fix | Delete
echo ' <p class="nf-notice-body">';
[133] Fix | Delete
echo $admin_display_msg;
[134] Fix | Delete
echo ' </p>';
[135] Fix | Delete
echo '<ul class="nf-notice-links">
[136] Fix | Delete
' . $admin_display_link . '
[137] Fix | Delete
</ul>';
[138] Fix | Delete
echo '</div>';
[139] Fix | Delete
if ( $admin_can_dismiss ) {
[140] Fix | Delete
echo '<a href="' . wp_nonce_url( esc_attr( $query_str ) ) . '" class="dashicons dashicons-dismiss"><span class="sr-only">Dismiss</span></a>';
[141] Fix | Delete
}
[142] Fix | Delete
echo '</div>';
[143] Fix | Delete
[144] Fix | Delete
$this->notice_spam += 1;
[145] Fix | Delete
$output_css = true;
[146] Fix | Delete
}
[147] Fix | Delete
if ( $output_css ) {
[148] Fix | Delete
wp_enqueue_style( 'nf-admin-notices', Ninja_Forms::$url .'assets/css/admin-notices.css?nf_ver=' . Ninja_Forms::VERSION );
[149] Fix | Delete
}
[150] Fix | Delete
}
[151] Fix | Delete
}
[152] Fix | Delete
[153] Fix | Delete
// die( 'done looping' );
[154] Fix | Delete
}
[155] Fix | Delete
[156] Fix | Delete
// Spam protection check
[157] Fix | Delete
public function anti_notice_spam() {
[158] Fix | Delete
[159] Fix | Delete
if ( $this->notice_spam >= $this->notice_spam_max ) {
[160] Fix | Delete
return true;
[161] Fix | Delete
}
[162] Fix | Delete
[163] Fix | Delete
return false;
[164] Fix | Delete
}
[165] Fix | Delete
[166] Fix | Delete
// Ignore function that gets ran at admin init to ensure any messages that were dismissed get marked
[167] Fix | Delete
public function admin_notice_ignore() {
[168] Fix | Delete
[169] Fix | Delete
// If user clicks to ignore the notice, update the option to not show it again
[170] Fix | Delete
if ( isset($_GET['nf_admin_notice_ignore']) && current_user_can( apply_filters( 'ninja_forms_admin_parent_menu_capabilities', 'manage_options' ) ) ) {
[171] Fix | Delete
[172] Fix | Delete
if ( ! check_admin_referer() ) {
[173] Fix | Delete
$query_str = remove_query_arg( array( 'nf_admin_notice_ignore', '_wpnonce' ) );
[174] Fix | Delete
wp_safe_redirect( $query_str );
[175] Fix | Delete
exit;
[176] Fix | Delete
}
[177] Fix | Delete
$admin_notices_option = get_option( 'nf_admin_notice', array() );
[178] Fix | Delete
$admin_notices_option[ WPN_Helper::sanitize_text_field($_GET[ 'nf_admin_notice_ignore' ]) ][ 'dismissed' ] = 1;
[179] Fix | Delete
update_option( 'nf_admin_notice', $admin_notices_option );
[180] Fix | Delete
$query_str = remove_query_arg( array( 'nf_admin_notice_ignore', '_wpnonce' ) );
[181] Fix | Delete
wp_safe_redirect( $query_str );
[182] Fix | Delete
exit;
[183] Fix | Delete
}
[184] Fix | Delete
}
[185] Fix | Delete
[186] Fix | Delete
// Temp Ignore function that gets ran at admin init to ensure any messages that were temp dismissed get their start date changed
[187] Fix | Delete
public function admin_notice_temp_ignore() {
[188] Fix | Delete
[189] Fix | Delete
// If user clicks to temp ignore the notice, update the option to change the start date - default interval of 14 days
[190] Fix | Delete
if ( isset($_GET['nf_admin_notice_temp_ignore']) && current_user_can( apply_filters( 'ninja_forms_admin_parent_menu_capabilities', 'manage_options' ) ) ) {
[191] Fix | Delete
[192] Fix | Delete
$admin_notices_option = get_option( 'nf_admin_notice', array() );
[193] Fix | Delete
[194] Fix | Delete
$current_date = current_time( "n/j/Y" );
[195] Fix | Delete
$date_array = explode( '/', $current_date );
[196] Fix | Delete
$interval = ( isset( $_GET[ 'nf_int' ] ) ? intval($_GET[ 'nf_int' ]) : 14 );
[197] Fix | Delete
$date_array[1] += $interval;
[198] Fix | Delete
$new_start = date( "n/j/Y", mktime( 0, 0, 0, $date_array[0], $date_array[1], $date_array[2] ) );
[199] Fix | Delete
[200] Fix | Delete
$admin_notices_option[ WPN_Helper::sanitize_text_field($_GET[ 'nf_admin_notice_temp_ignore' ]) ][ 'start' ] = $new_start;
[201] Fix | Delete
$admin_notices_option[ WPN_Helper::sanitize_text_field($_GET[ 'nf_admin_notice_temp_ignore' ]) ][ 'dismissed' ] = 0;
[202] Fix | Delete
update_option( 'nf_admin_notice', $admin_notices_option );
[203] Fix | Delete
$query_str = remove_query_arg( array( 'nf_admin_notice_temp_ignore', 'nf_int' ) );
[204] Fix | Delete
wp_redirect( $query_str );
[205] Fix | Delete
exit;
[206] Fix | Delete
}
[207] Fix | Delete
}
[208] Fix | Delete
[209] Fix | Delete
public function admin_notice_pages_blacklist( $pages ) {
[210] Fix | Delete
[211] Fix | Delete
foreach( $pages as $key => $page ) {
[212] Fix | Delete
if ( is_array( $page ) ) {
[213] Fix | Delete
if ( isset( $_GET[ 'page' ] ) && $_GET[ 'page'] == $page[0] && isset( $_GET[ 'tab' ] ) && $_GET[ 'tab' ] == $page[1] ) {
[214] Fix | Delete
return true;
[215] Fix | Delete
}
[216] Fix | Delete
} else {
[217] Fix | Delete
if ( get_current_screen()->id === $page ) {
[218] Fix | Delete
return true;
[219] Fix | Delete
}
[220] Fix | Delete
if ( isset( $_GET[ 'page' ] ) && $_GET[ 'page'] == $page ) {
[221] Fix | Delete
return true;
[222] Fix | Delete
}
[223] Fix | Delete
}
[224] Fix | Delete
}
[225] Fix | Delete
return false;
[226] Fix | Delete
}
[227] Fix | Delete
[228] Fix | Delete
// Page check function - This should be called from class extensions if the notice should only show on specific admin pages
[229] Fix | Delete
// Expects an array in the form of IE: array( 'dashboard', 'ninja-forms', array( 'ninja-forms', 'builder' ) )
[230] Fix | Delete
// Function accepts dashboard as a special check and also whatever is passed to page or tab as parameters
[231] Fix | Delete
// The above example will display on dashboard and all of the pages that have page=ninja-forms and any page=ninja-forms&tab=builder which is redundant in the example
[232] Fix | Delete
public function admin_notice_pages( $pages ) {
[233] Fix | Delete
[234] Fix | Delete
foreach( $pages as $key => $page ) {
[235] Fix | Delete
if ( is_array( $page ) ) {
[236] Fix | Delete
if ( isset( $_GET[ 'page' ] ) && $_GET[ 'page'] == $page[0] && isset( $_GET[ 'tab' ] ) && $_GET[ 'tab' ] == $page[1] ) {
[237] Fix | Delete
return true;
[238] Fix | Delete
}
[239] Fix | Delete
} else {
[240] Fix | Delete
if ( $page == 'all' ) {
[241] Fix | Delete
return true;
[242] Fix | Delete
}
[243] Fix | Delete
if ( get_current_screen()->id === $page ) {
[244] Fix | Delete
return true;
[245] Fix | Delete
}
[246] Fix | Delete
if ( isset( $_GET[ 'page' ] ) && $_GET[ 'page'] == $page ) {
[247] Fix | Delete
return true;
[248] Fix | Delete
}
[249] Fix | Delete
}
[250] Fix | Delete
}
[251] Fix | Delete
return false;
[252] Fix | Delete
}
[253] Fix | Delete
[254] Fix | Delete
// Required fields check
[255] Fix | Delete
public function required_fields( $fields ) {
[256] Fix | Delete
[257] Fix | Delete
if ( ! isset( $fields[ 'msg' ] ) || ( isset( $fields[ 'msg' ] ) && empty( $fields[ 'msg' ] ) ) ) {
[258] Fix | Delete
return true;
[259] Fix | Delete
}
[260] Fix | Delete
[261] Fix | Delete
if ( ! isset( $fields[ 'title' ] ) || ( isset( $fields[ 'title' ] ) && empty( $fields[ 'title' ] ) ) ) {
[262] Fix | Delete
return true;
[263] Fix | Delete
}
[264] Fix | Delete
[265] Fix | Delete
return false;
[266] Fix | Delete
}
[267] Fix | Delete
[268] Fix | Delete
// Special parameters function that is to be used in any extension of this class
[269] Fix | Delete
public function special_parameters( $admin_notices ) {
[270] Fix | Delete
// Intentionally left blank
[271] Fix | Delete
}
[272] Fix | Delete
[273] Fix | Delete
}
[274] Fix | Delete
[275] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function