* @link https://editorsConditionalFees.com * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License */ // Exit if accessed directly. if ( !defined( 'ABSPATH' ) ) { exit; } /** * Main Feedback Notice Class */ if ( !class_exists( 'AUSM_User_Feedback' ) ) { class AUSM_User_Feedback { /** * Slug. * * @var string $slug */ private $slug ; /** * Name. * * @var string $name */ private $name ; /** * No Bug Option. * * @var string $nobug_option */ public $nobug_option ; /** * Other Plugins notice Option. * * @var string $other_plugins_option */ public $other_plugins_option ; /** * Activation Date Option. * * @var string $date_option */ public $date_option ; /** * Class constructor. * * @param string $args Arguments. */ public function __construct( $args ) { $this->slug = $args['slug']; $this->name = $args['name']; $this->date_option = $this->slug . '_activation_date'; $this->nobug_option = $this->slug . '_no_bug'; $this->other_plugins_option = $this->slug . '_other_plugins_option'; // Add actions. add_action( 'admin_init', array( $this, 'check_installation_date' ) ); /** Check user review block flag */ add_action( 'admin_init', array( $this, 'set_no_bug' ), 5 ); /** Check the condition for other plugins admin notice block flag */ add_action( 'admin_init', array( $this, 'set_other_plugins_option' ), 5 ); } /** * Seconds to words. * * @param string $seconds Seconds in time. */ public function seconds_to_words( $seconds ) { // Get the years. $years = intval( $seconds ) / YEAR_IN_SECONDS % 100; if ( $years > 1 ) { /* translators: Number of years */ return sprintf( __( '%s years', 'advanced-usps-shipping-method' ), $years ); } elseif ( $years > 0 ) { return __( 'a year', 'advanced-usps-shipping-method' ); } // Get the weeks. $weeks = intval( $seconds ) / WEEK_IN_SECONDS % 52; if ( $weeks > 1 ) { /* translators: Number of weeks */ return sprintf( __( '%s weeks', 'advanced-usps-shipping-method' ), $weeks ); } elseif ( $weeks > 0 ) { return __( 'a week', 'advanced-usps-shipping-method' ); } // Get the days. $days = intval( $seconds ) / DAY_IN_SECONDS % 7; if ( $days > 1 ) { /* translators: Number of days */ return sprintf( __( '%s days', 'advanced-usps-shipping-method' ), $days ); } elseif ( $days > 0 ) { return __( 'a day', 'advanced-usps-shipping-method' ); } // Get the hours. $hours = intval( $seconds ) / HOUR_IN_SECONDS % 24; if ( $hours > 1 ) { /* translators: Number of hours */ return sprintf( __( '%s hours', 'advanced-usps-shipping-method' ), $hours ); } elseif ( $hours > 0 ) { return __( 'an hour', 'advanced-usps-shipping-method' ); } // Get the minutes. $minutes = intval( $seconds ) / MINUTE_IN_SECONDS % 60; if ( $minutes > 1 ) { /* translators: Number of minutes */ return sprintf( __( '%s minutes', 'advanced-usps-shipping-method' ), $minutes ); } elseif ( $minutes > 0 ) { return __( 'a minute', 'advanced-usps-shipping-method' ); } // Get the seconds. $seconds = intval( $seconds ) % 60; if ( $seconds > 1 ) { /* translators: Number of seconds */ return sprintf( __( '%s seconds', 'advanced-usps-shipping-method' ), $seconds ); } elseif ( $seconds > 0 ) { return __( 'a second', 'advanced-usps-shipping-method' ); } } /** * Check date on admin initiation and add to admin notice if it was more than the time limit. */ public function check_installation_date() { /** Review block notice after 7 days */ 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 ); //set the 7 days seconds $after_day = WEEK_IN_SECONDS; // If difference between install date and now is greater than time limit, then display notice. if ( time() - $install_date > $after_day ) { add_action( 'admin_notices', array( $this, 'display_admin_notice' ) ); } } /* Other plugins notice after 5 days */ if ( !get_site_option( $this->other_plugins_option ) || false === get_site_option( $this->other_plugins_option ) ) { add_site_option( $this->date_option, time() ); // Retrieve the activation date. $install_date = get_site_option( $this->date_option ); //set the 5 days seconds $after_5_day = DAY_IN_SECONDS * 5; // If difference between install date and now is greater than 5 days, then display notice. if ( time() - $install_date > $after_5_day ) { add_action( 'admin_notices', array( $this, 'display_admin_notice_other_plugins' ) ); } } } /** * Display the admin notice for other plugins after 5 day of installation. */ public function display_admin_notice_other_plugins() { $screen = get_current_screen(); if ( isset( $screen->base ) && ('plugins' === $screen->base || 'dotstore-plugins_page_advanced-usps-shipping-method' === $screen->base) ) { $no_bug_url = wp_nonce_url( add_query_arg( $this->other_plugins_option, 'true', wc_get_current_admin_url() ), 'editorsConditionalFees-feedback-nounce' ); $time = $this->seconds_to_words( time() - get_site_option( $this->date_option ) ); ?>