id = $id; $this->app = $app; if ( ! empty( $options ) ) { foreach ( $options as $key => $_value ) { $this->{$key} = $_value; } } $this->hook = $this->app->app . '_wpnotice_dismiss_notice'; add_action( 'wp_ajax_' . $this->hook, [ $this, 'ajax_maybe_dismiss_notice' ] ); } /** * Print the script for dismissing the notice. * * @access public * @return void * @since 1.0 */ public function print_script() { $nonce = wp_create_nonce( 'wpnotice_dismiss_notice_' . $this->id ); $_id = '#wpnotice-' . esc_attr( $this->app->app ) . '-' . esc_attr( $this->id ); ?> hook !== $_POST['action'] ) { return; } // Sanity check: Early exit if the ID of the notice is not the one from this object. if ( ! isset( $_POST['id'] ) || $this->id !== $_POST['id'] ) { return; } // Security check: Make sure nonce is OK. check_ajax_referer( 'wpnotice_dismiss_notice_' . $this->id, 'nonce', true ); if ( isset( $_POST['later'] ) ) { $_recurrence = intval( $this->recurrence ) || 15; $_queue = $this->app->storage()->get(); $_queue[ $this->id ]['start'] = $this->strtotime( "+$_recurrence days" ); $_queue[ $this->id ]['expire'] = $this->strtotime( "+" . ( $_recurrence + 3 ) . " days" ); $this->app->storage()->save( $_queue ); return; } // If we got this far, we need to dismiss the notice. $this->dismiss_notice(); } /** * Actually dismisses the notice. * * @access private * @return bool * @since 1.0 */ public function dismiss_notice() { if ( ! defined( 'WPNOTICE_EXPIRED_TIME' ) ) { define( 'WPNOTICE_EXPIRED_TIME', HOUR_IN_SECONDS * 10 ); } set_transient( 'wpnotice_priority_time_expired', true, time() + WPNOTICE_EXPIRED_TIME ); if ( 'user' === $this->scope ) { return $this->app->storage()->save_meta( $this->id ); } $_key = $this->app->app . '_' . $this->id . '_notice_dismissed'; return $this->app->storage()->save( $_key ); } /** * Check if is dismissed or not * @return boolean */ public function is_dismissed() { if ( 'user' === $this->scope ) { return $this->app->storage()->get_meta( $this->id ); } $_key = $this->app->app . '_' . $this->id . '_notice_dismissed'; return $this->app->storage()->get( $_key ); } }