PluginProbe
Additional Terms Lite for WooCommerce / trunk
Additional Terms Lite for WooCommerce vtrunk
1.7.3 1.7.2.1 trunk 1.0.1 1.0.2 1.1.0 1.2.0 1.2.1 1.2.2 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.4.0 1.4.1 1.5.0 1.5.1 1.5.2 1.6.0 1.6.1 1.6.2 1.6.3 All 35 releases
woo-additional-terms / src / Enhancements / Rate.php

Rate.php in Additional Terms Lite for WooCommerce trunk, at src/Enhancements/Rate.php

95 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * The plugin rate class.
4 *
5 * @since 1.4.1
6 *
7 * @package woo-additional-terms
8 */
9
10 namespace Woo_Additional_Terms\Enhancements;
11
12 use Woo_Additional_Terms\Helper;
13
14 /**
15 * Class Rate.
16 */
17 class Rate {
18
19 /**
20 * Rated (already) option name.
21 *
22 * @since 1.5.2
23 *
24 * @var string
25 */
26 const OPTION_NAME = 'woo_additional_terms_rated';
27
28 /**
29 * Rate transient name.
30 *
31 * @since 1.4.1
32 *
33 * @var string
34 */
35 const TRANSIENT_NAME = 'woo_additional_terms_rate';
36
37
38 /**
39 * Setup hooks and filters.
40 *
41 * @since 1.6.0
42 *
43 * @return void
44 */
45 public function setup() {
46
47 add_action( 'woo_additional_terms_admin_notices', array( $this, 'admin_notice' ) );
48 }
49
50 /**
51 * Display the rate the plugin notice.
52 *
53 * @since 1.4.1
54 *
55 * @return void
56 */
57 public function admin_notice() {
58
59 // Bail early if the rate notice has been dismissed.
60 if (
61 get_option( self::OPTION_NAME )
62 || get_transient( self::TRANSIENT_NAME )
63 ) {
64 return;
65 }
66
67 $usage_timestamp = woo_additional_terms()->service( 'options' )->get_usage_timestamp();
68
69 // If the usage timestamp is empty, add it and bail.
70 if ( empty( $usage_timestamp ) ) {
71 // Add the activation timestamp.
72 woo_additional_terms()->service( 'options' )->add_usage_timestamp();
73
74 return;
75 }
76
77 // Bail early if the plugin recently installed.
78 if ( time() < ( $usage_timestamp + WEEK_IN_SECONDS ) ) {
79 return;
80 }
81
82 // Enqueue the assets.
83 wp_enqueue_style( 'woo-additional-terms-rate' );
84 wp_enqueue_script( 'woo-additional-terms-dismiss' );
85
86 // Display the notice.
87 woo_additional_terms()->service( 'template_manager' )->echo_template(
88 'notices/rate.php',
89 array(
90 'usage_timestamp' => human_time_diff( $usage_timestamp ),
91 )
92 );
93 }
94 }
95