slug = $args['slug']; $this->name = $args['name']; $this->date_option = 'ogf_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 ); } /** * Seconds to words. * * @param int $seconds Seconds in time. * @return string */ public function seconds_to_words( $seconds ) { // Get the years. $years = absint( $seconds / YEAR_IN_SECONDS ) % 100; if ( $years > 0 ) { /* translators: Number of years */ return sprintf( _n( 'a year', '%s years', $years, 'olympus-google-fonts' ), $years ); } // Get the weeks. $weeks = absint( intval( $seconds ) / WEEK_IN_SECONDS ) % 52; if ( $weeks > 1 ) { /* translators: Number of weeks */ return sprintf( _n( 'a week', '%s weeks', $weeks, 'olympus-google-fonts' ), $weeks ); } // Get the days. $days = absint( intval( $seconds ) / DAY_IN_SECONDS ) % 7; if ( $days > 1 ) { /* translators: Number of days */ return sprintf( _n( '%s day', '%s days', $days, 'olympus-google-fonts' ), $days ); } return sprintf( _n( '%s second', '%s seconds', $seconds, 'olympus-google-fonts' ), intval( $seconds ) ); } /** * 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() { if ( is_plugin_active( 'google-fonts-pro/google-fonts-pro.php' ) ) { return; } ?> review(); } /** * Output review content. */ public function review() { $no_bug_url = wp_nonce_url( admin_url( '?' . $this->nobug_option . '=true' ), 'ogf-notification-nonce' ); $time = $this->seconds_to_words( time() - get_site_option( $this->date_option ) ); ?>
<?php echo esc_attr__( 'Google Fonts WordPress Plugin', 'olympus-google-fonts' ); ?>

%1$s for %2$s now! Could you please do me a BIG favor and give it a 5-star rating on WordPress to help us spread the word and boost our motivation?', 'olympus-google-fonts' ), esc_html( $this->name ), esc_html( $time ) ); ?>

%2$s', esc_url( 'https://wordpress.org/support/view/plugin-reviews/olympus-google-fonts#new-post' ), esc_html__( 'Leave a Review', 'olympus-google-fonts' ) ); ?>
nobug_option ] ) || ! current_user_can( 'manage_options' ) ) ) { return; } add_site_option( $this->nobug_option, true ); } } endif; /* * Instantiate the OGF_Notifications class. */ new OGF_Notifications( array( 'slug' => 'ogf', 'name' => __( 'Google Fonts for WordPress', 'olympus-google-fonts' ), 'time_limit' => WEEK_IN_SECONDS, ) );