Refactor Note "has plugin been installed for" login into reusable trait.
This commit is contained in:
parent
bece81b757
commit
ed17b3f951
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
/**
|
||||
* WC Admin Note Traits
|
||||
*
|
||||
* WC Admin Note Traits class that houses shared functionality across notes.
|
||||
*
|
||||
* @package WooCommerce Admin/Classes
|
||||
*/
|
||||
|
||||
namespace Automattic\WooCommerce\Admin\Notes;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* NoteTraits class.
|
||||
*/
|
||||
trait NoteTraits {
|
||||
/**
|
||||
* Test how long WooCommerce Admin has been active.
|
||||
*
|
||||
* @param int $seconds Time in seconds to check.
|
||||
* @return bool Whether or not WooCommerce admin has been active for $seconds.
|
||||
*/
|
||||
public static function wc_admin_active_for( $seconds ) {
|
||||
// Getting install timestamp reference class-wc-admin-install.php.
|
||||
$wc_admin_installed = get_option( 'wc_admin_install_timestamp', false );
|
||||
|
||||
if ( false === $wc_admin_installed ) {
|
||||
update_option( 'wc_admin_install_timestamp', time() );
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return ( ( time() - $wc_admin_installed ) >= $seconds );
|
||||
}
|
||||
}
|
|
@ -15,6 +15,10 @@ defined( 'ABSPATH' ) || exit;
|
|||
* WC_Admin_Notes_Facebook_Extension
|
||||
*/
|
||||
class WC_Admin_Notes_Facebook_Extension {
|
||||
/**
|
||||
* Note traits.
|
||||
*/
|
||||
use NoteTraits;
|
||||
|
||||
/**
|
||||
* Name of the note for use in the database.
|
||||
|
@ -32,23 +36,15 @@ class WC_Admin_Notes_Facebook_Extension {
|
|||
* Possibly add Facebook extension note.
|
||||
*/
|
||||
public static function possibly_add_facebook_note() {
|
||||
$wc_admin_installed = get_option( 'wc_admin_install_timestamp', false );
|
||||
if ( false === $wc_admin_installed ) {
|
||||
$wc_admin_installed = time();
|
||||
update_option( 'wc_admin_install_timestamp', $wc_admin_installed );
|
||||
}
|
||||
|
||||
// Only show the Facebook note to stores with products.
|
||||
$products = wp_count_posts( 'product' );
|
||||
if ( (int) $products->publish < 1 ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$current_time = time();
|
||||
$three_days_in_seconds = 3 * DAY_IN_SECONDS;
|
||||
|
||||
// We want to show the Facebook note after day 3.
|
||||
if ( $current_time - $wc_admin_installed < $three_days_in_seconds ) {
|
||||
$three_days_in_seconds = 3 * DAY_IN_SECONDS;
|
||||
if ( ! self::wc_admin_active_for( $three_days_in_seconds ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -15,6 +15,11 @@ defined( 'ABSPATH' ) || exit;
|
|||
* WC_Admin_Notes_Giving_Feedback_Notes
|
||||
*/
|
||||
class WC_Admin_Notes_Giving_Feedback_Notes {
|
||||
/**
|
||||
* Note traits.
|
||||
*/
|
||||
use NoteTraits;
|
||||
|
||||
/**
|
||||
* Add notes for admin giving feedback.
|
||||
*/
|
||||
|
@ -36,18 +41,9 @@ class WC_Admin_Notes_Giving_Feedback_Notes {
|
|||
return;
|
||||
}
|
||||
|
||||
// Getting install timestamp reference class-wc-admin-install.php.
|
||||
$wc_admin_installed = get_option( 'wc_admin_install_timestamp', false );
|
||||
if ( false === $wc_admin_installed ) {
|
||||
$wc_admin_installed = time();
|
||||
update_option( 'wc_admin_install_timestamp', $wc_admin_installed );
|
||||
}
|
||||
|
||||
$current_time = time();
|
||||
$three_days_in_seconds = 259200;
|
||||
|
||||
// We need to show Admin Giving feeback notification after 3 days of install.
|
||||
if ( $current_time - $wc_admin_installed < $three_days_in_seconds ) {
|
||||
$three_days_in_seconds = 3 * DAY_IN_SECONDS;
|
||||
if ( ! self::wc_admin_active_for( $three_days_in_seconds ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -15,6 +15,10 @@ defined( 'ABSPATH' ) || exit;
|
|||
* WC_Admin_Notes_Mobile_App
|
||||
*/
|
||||
class WC_Admin_Notes_Mobile_App {
|
||||
/**
|
||||
* Note traits.
|
||||
*/
|
||||
use NoteTraits;
|
||||
|
||||
/**
|
||||
* Name of the note for use in the database.
|
||||
|
@ -25,18 +29,9 @@ class WC_Admin_Notes_Mobile_App {
|
|||
* Possibly add mobile app note.
|
||||
*/
|
||||
public static function possibly_add_mobile_app_note() {
|
||||
|
||||
$wc_admin_installed = get_option( 'wc_admin_install_timestamp', false );
|
||||
if ( false === $wc_admin_installed ) {
|
||||
$wc_admin_installed = time();
|
||||
update_option( 'wc_admin_install_timestamp', $wc_admin_installed );
|
||||
}
|
||||
|
||||
$current_time = time();
|
||||
$two_days_in_seconds = 172800;
|
||||
|
||||
// We want to show the mobile app note after day 2.
|
||||
if ( $current_time - $wc_admin_installed < $two_days_in_seconds ) {
|
||||
$two_days_in_seconds = 2 * DAY_IN_SECONDS;
|
||||
if ( ! self::wc_admin_active_for( $two_days_in_seconds ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue