'manage_options', 'prefix' => 'worb', 'snooze_days' => 7, 'review_url' => '', 'notice_class' => 'notice-info', 'need_help_url' => '', ); $args = wp_parse_args( $args, $default_args ); /** * Setup variables */ $this->slug = sanitize_title( $plugin_slug ); $this->prefix = ( $args['prefix'] !== '' ) ? sanitize_title( $args['prefix'] ) : $default_args['prefix']; $this->capability = ( $args['capability'] !== '' ) ? $args['capability'] : $default_args['capability']; $this->snooze_days = ( intval( $args['snooze_days'] ) > 0 ) ? intval( $args['snooze_days'] ) : $default_args['snooze_days']; $this->review_url = ( $args['review_url'] != '' ) ? $args['review_url'] : $this->default_review_url(); $this->need_help_url = $args['need_help_url']; $this->notice_class = $args['notice_class']; $this->messages = $messages; /** * Plugin activation hook */ register_activation_hook( $plugin_file, array( $this, 'set_check_timestamp' ) ); register_deactivation_hook( $plugin_file, array( $this, 'deactivation_cleanup' ) ); /** * Hooks */ add_action( 'admin_init', array( $this, 'check' ), 20 ); } } /** * Delete any stored data on deactivation. * * @return void */ public function deactivation_cleanup() { delete_option( $this->get_option_name( 'check' ) ); delete_option( $this->get_option_name( 'nobug' ) ); } /** * Create a relevant option name * * @param string $suffix Appended to prefix and plugin slug. * * @return string */ private function get_option_name( $suffix ) { $option_name = implode( '_', array( $this->prefix, $this->slug, $suffix ) ); if ( strlen( $option_name ) > 150 ) { error_log( 'long option name. consider revising. ' . $option_name ); } return $option_name; } /** * Sets the check timestamp option if one does not exist. Or overrides if forced. * * @return void */ public function set_check_timestamp( $force = false ) { if ( $force ) { update_option( $this->get_option_name( 'check' ), time() ); } elseif ( ! get_option( $this->get_option_name( 'check' ) ) ) { add_option( $this->get_option_name( 'check' ), time() ); } } /** * Compares current timestamp to the check timestamp. Adds admin_notices hook if necessary. * * @return void */ public function check() { if ( current_user_can( $this->capability ) ) { if ( ! get_option( $this->get_option_name( 'nobug' ) ) ) { $check_timestamp = get_option( $this->get_option_name( 'check' ) ); if ( ! $check_timestamp ) { $this->set_check_timestamp(); } else { $notice_date = strtotime( '+' . $this->snooze_days . ' days', $check_timestamp ); if ( time() >= $notice_date ) { add_action( 'admin_notices', array( $this, 'display_admin_notice' ) ); add_action( 'wp_ajax_' . $this->action_string(), array( $this, 'actions' ) ); add_action( 'admin_enqueue_scripts', array( $this, 'enqueue' ) ); add_action( 'admin_print_footer_scripts', array( $this, 'notice_script' ) ); } } } } } /** * Sets the nobug option in the database * * @return void */ private function set_nobug_option() { update_option( $this->get_option_name( 'nobug' ), true ); } /** * Creates a URL to plugin reviews. * * @return string */ private function default_review_url() { return 'https://wordpress.org/support/plugin/' . $this->slug . '/reviews/'; } /** * Get the current URL. * * @return string */ public static function current_url() { $url = ( isset( $_SERVER['HTTPS'] ) && sanitize_text_field( wp_unslash( $_SERVER['HTTPS'] ) ) == 'on' ? 'https' : 'http' ) . '://'; $host = ( isset( $_SERVER['HTTP_HOST'] ) ) ? sanitize_text_field( wp_unslash( $_SERVER['HTTP_HOST'] ) ) : ''; $request_uri = ( isset( $_SERVER['REQUEST_URI'] ) ) ? sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : ''; return sanitize_url( $url . $host . $request_uri ); } /** * Displays the admin review banner. */ public function display_admin_notice() { $showhelp = isset( $this->need_help_url ) && $this->need_help_url ? true : false; if ( $showhelp && ( strtolower( $this->need_help_url ) === strtolower( $this->current_url() ) ) ) { $showhelp = false; } ?>
messages['intro'] ); ?>
messages['rate_link_text'] ); ?> need_help_url, site_url() ) !== false ) { $target = ''; } else { $target = ' target="_blank" rel="noopener noreferrer"'; } ?> > messages['need_help_text'] ); ?> messages['remind_link_text'] ); ?> messages['nobug_link_text'] ); ?>