false, 'last_shown' => 0, 'times_shown' => 0, ) ); } } /** * Show the notice if conditions are met. */ public function maybe_show_notice() { if ( ! current_user_can( 'manage_options' ) ) { return; } $state = get_option( $this->option_key, array() ); if ( ! empty( $state['dismissed'] ) ) { return; } $times_shown = isset( $state['times_shown'] ) ? (int) $state['times_shown'] : 0; if ( $times_shown >= count( $this->show_at_days ) ) { $state['dismissed'] = true; update_option( $this->option_key, $state ); return; } $activation_time = (int) get_option( $this->activation_key, 0 ); if ( 0 === $activation_time ) { return; } $days_since_activation = floor( ( time() - $activation_time ) / DAY_IN_SECONDS ); $next_show_day = $this->show_at_days[ $times_shown ]; if ( $days_since_activation < $next_show_day ) { return; } $this->render_notice(); $state['times_shown'] = $times_shown + 1; $state['last_shown'] = time(); if ( $state['times_shown'] >= count( $this->show_at_days ) ) { $state['dismissed'] = true; } update_option( $this->option_key, $state ); } /** * Render the admin notice HTML. */ private function render_notice() { $dismiss_nonce = wp_create_nonce( 'bfas_dismiss_coffee_nonce' ); ?>

☕ Enjoying 2FOX4 Before After? paypal_url ) . '" target="_blank" rel="noopener noreferrer">', '' ), array( 'a' => array( 'href' => array(), 'target' => array(), 'rel' => array(), ), ) ); ?>

option_key, array() ); if ( ! empty( $state['dismissed'] ) ) { return; } $script = " jQuery(document).on('click', '.bfas-coffee-notice .notice-dismiss', function() { jQuery.post(ajaxurl, { action: 'bfas_dismiss_coffee', nonce: jQuery('.bfas-coffee-notice').data('bfas-nonce') }); }); "; wp_add_inline_script( 'jquery-core', $script ); } /** * AJAX handler: permanently dismiss the notice. */ public function dismiss_notice() { check_ajax_referer( 'bfas_dismiss_coffee_nonce', 'nonce' ); if ( ! current_user_can( 'manage_options' ) ) { wp_die( -1 ); } update_option( $this->option_key, array( 'dismissed' => true, 'last_shown' => time(), 'times_shown' => count( $this->show_at_days ), ) ); wp_die( 1 ); } }