slug = $args['slug']; $this->name = $args['name']; $this->date_option = $this->slug . '_activation_date'; $this->nobug_option = $this->slug . '_no_bug'; if ( isset( $args['time_limit'] ) ) { $this->time_limit = $args['time_limit']; } else { $this->time_limit = WEEK_IN_SECONDS; } // Add actions. add_action( 'admin_init', array( $this, 'check_installation_date' ) ); add_action( 'admin_init', array( $this, 'set_no_bug' ), 5 ); } /** * Check date on admin initiation and add to admin notice if it was more than the time limit. */ public function check_installation_date() { if ( ! get_site_option( $this->nobug_option ) || false === get_site_option( $this->nobug_option ) ) { add_site_option( $this->date_option, time() ); // Retrieve the activation date. $install_date = get_site_option( $this->date_option ); // If difference between install date and now is greater than time limit, then display notice. //if ( time() - $install_date > $this->time_limit ) { add_action( 'admin_notices', array( $this, 'display_admin_notice' ) ); //} } } /** * Display the admin notice. */ public function display_admin_notice() { $screen = get_current_screen(); if ( isset( $screen->base ) && ( 'plugins' === $screen->base || 'advance-menu-manager-lite' === $screen->id ) ) { $no_bug_url = wp_nonce_url( admin_url( 'plugins.php?' . $this->nobug_option . '=true' ), 'editorsAMM-feedback-nounce' ); $time = $this->seconds_to_words( time() - get_site_option( $this->date_option ) ); ?>
1 ) { /* translators: Number of years */ return sprintf( __( '%s years', PLUGIN_SLUG ), $years ); } elseif ( $years > 0 ) { return __( 'a year', PLUGIN_SLUG ); } // Get the weeks. $weeks = intval( $seconds ) / WEEK_IN_SECONDS % 52; if ( $weeks > 1 ) { /* translators: Number of weeks */ return sprintf( __( '%s weeks', PLUGIN_SLUG ), $weeks ); } elseif ( $weeks > 0 ) { return __( 'a week', PLUGIN_SLUG ); } // Get the days. $days = intval( $seconds ) / DAY_IN_SECONDS % 7; if ( $days > 1 ) { /* translators: Number of days */ return sprintf( __( '%s days', PLUGIN_SLUG ), $days ); } elseif ( $days > 0 ) { return __( 'a day', PLUGIN_SLUG ); } // Get the hours. $hours = intval( $seconds ) / HOUR_IN_SECONDS % 24; if ( $hours > 1 ) { /* translators: Number of hours */ return sprintf( __( '%s hours', PLUGIN_SLUG ), $hours ); } elseif ( $hours > 0 ) { return __( 'an hour', PLUGIN_SLUG ); } // Get the minutes. $minutes = intval( $seconds ) / MINUTE_IN_SECONDS % 60; if ( $minutes > 1 ) { /* translators: Number of minutes */ return sprintf( __( '%s minutes', PLUGIN_SLUG ), $minutes ); } elseif ( $minutes > 0 ) { return __( 'a minute', PLUGIN_SLUG ); } // Get the seconds. $seconds = intval( $seconds ) % 60; if ( $seconds > 1 ) { /* translators: Number of seconds */ return sprintf( __( '%s seconds', PLUGIN_SLUG ), $seconds ); } elseif ( $seconds > 0 ) { return __( 'a second', PLUGIN_SLUG ); } } /** * Set the plugin to no longer bug users if user asks not to be. */ public function set_no_bug() { // Bail out if not on correct page. // phpcs:ignore if ( ! isset( $_GET['_wpnonce'] ) || ( ! wp_verify_nonce( $_GET['_wpnonce'], 'editorsAMM-feedback-nounce' ) || ! is_admin() || ! isset( $_GET[ $this->nobug_option ] ) || ! current_user_can( 'manage_options' ) ) ) { return; } add_site_option( $this->nobug_option, true ); } } /* * Instantiate the SizeChart_User_Feedback class. */ new Amm_User_Feedback( array( 'slug' => 'editors_amm_plugin_feedback', 'name' => PLUGIN_NAME, 'time_limit' => WEEK_IN_SECONDS, ) );