| 1 |
<?php |
| 2 |
use BetterDocs\WPNotice\Notices; |
| 3 |
|
| 4 |
class BetterDocs_Admin_Notice { |
| 5 |
private static $_instance = null; |
| 6 |
private $insights = null; |
| 7 |
|
| 8 |
public static function get_instance(){ |
| 9 |
if( static::$_instance === null ) { |
| 10 |
static::$_instance = new static; |
| 11 |
} |
| 12 |
|
| 13 |
return static::$_instance; |
| 14 |
} |
| 15 |
|
| 16 |
public function __construct(){ |
| 17 |
$this->plugin_usage_insights(); |
| 18 |
|
| 19 |
add_action('admin_init', [$this, 'notices']); |
| 20 |
} |
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
/** |
| 25 |
* Admin notices for Review and others. |
| 26 |
* |
| 27 |
* @return void |
| 28 |
*/ |
| 29 |
public function notices(){ |
| 30 |
if( ! class_exists('\BetterDocs\WPNotice\Notices') ) { |
| 31 |
require_once BETTERDOCS_DIR_PATH . '/admin/wp-notice/wpnotice.php'; |
| 32 |
} |
| 33 |
|
| 34 |
$notices = new Notices([ |
| 35 |
'id' => 'betterdocs', |
| 36 |
'store' => 'options', |
| 37 |
'storage_key' => 'notices', |
| 38 |
'version' => '1.0.0', |
| 39 |
'lifetime' => 3, |
| 40 |
'styles' => BETTERDOCS_ADMIN_URL . 'assets/css/notices.css', |
| 41 |
]); |
| 42 |
|
| 43 |
/** |
| 44 |
* Review Notice |
| 45 |
* @var mixed $message |
| 46 |
*/ |
| 47 |
|
| 48 |
$message = __( |
| 49 |
'We hope you\'re enjoying BetterDocs! Could you please do us a BIG favor and give it a 5-star rating on WordPress to help us spread the word and boost our motivation?', |
| 50 |
'essential-blocks' |
| 51 |
); |
| 52 |
|
| 53 |
$_review_notice = [ |
| 54 |
'thumbnail' => BETTERDOCS_ADMIN_URL . 'assets/img/betterdocs-icon.svg', |
| 55 |
'html' => '<p>'. $message .'</p>', |
| 56 |
'links' => [ |
| 57 |
'later' => array( |
| 58 |
'link' => 'https://wordpress.org/support/plugin/essential-blocks/reviews/#new-post', |
| 59 |
'target' => '_blank', |
| 60 |
'label' => __( 'Sure, you deserve it!', 'essential-blocks' ), |
| 61 |
'icon_class' => 'dashicons dashicons-external', |
| 62 |
), |
| 63 |
'allready' => array( |
| 64 |
'label' => __( 'I already did', 'essential-blocks' ), |
| 65 |
'icon_class' => 'dashicons dashicons-smiley', |
| 66 |
'attributes' => [ |
| 67 |
'data-dismiss' => true |
| 68 |
], |
| 69 |
), |
| 70 |
'maybe_later' => array( |
| 71 |
'label' => __( 'Maybe Later', 'essential-blocks' ), |
| 72 |
'icon_class' => 'dashicons dashicons-calendar-alt', |
| 73 |
'attributes' => [ |
| 74 |
'data-later' => true, |
| 75 |
'class' => 'dismiss-btn' |
| 76 |
], |
| 77 |
), |
| 78 |
'support' => array( |
| 79 |
'link' => 'https://wpdeveloper.com/support', |
| 80 |
'attributes' => [ |
| 81 |
'target' => '_blank', |
| 82 |
], |
| 83 |
'label' => __( 'I need help', 'essential-blocks' ), |
| 84 |
'icon_class' => 'dashicons dashicons-sos', |
| 85 |
), |
| 86 |
'never_show_again' => array( |
| 87 |
'label' => __( 'Never show again', 'essential-blocks' ), |
| 88 |
'icon_class' => 'dashicons dashicons-dismiss', |
| 89 |
'attributes' => [ |
| 90 |
'data-dismiss' => true |
| 91 |
], |
| 92 |
) |
| 93 |
] |
| 94 |
]; |
| 95 |
|
| 96 |
$notices->add( |
| 97 |
'review', |
| 98 |
$_review_notice, |
| 99 |
[ |
| 100 |
// 'start' => $notices->time(), |
| 101 |
'start' => $notices->strtotime('+20 days'), |
| 102 |
'recurrence' => 30, |
| 103 |
'dismissible' => true, |
| 104 |
// 'refresh' => BETTERDOCS_VERSION, |
| 105 |
'screens' => [ |
| 106 |
'dashboard', 'plugins', 'themes', 'edit-page', |
| 107 |
'edit-post', 'users', 'tools', 'options-general', |
| 108 |
'nav-menus' |
| 109 |
] |
| 110 |
] |
| 111 |
); |
| 112 |
|
| 113 |
/** |
| 114 |
* Opt-In Notice |
| 115 |
*/ |
| 116 |
if( $this->insights != null ) { |
| 117 |
$notices->add( |
| 118 |
'opt_in', |
| 119 |
[ $this->insights, 'notice' ], |
| 120 |
[ |
| 121 |
'classes' => 'updated put-dismiss-notice', |
| 122 |
'start' => $notices->time(), |
| 123 |
// 'start' => $notices->strtotime('+20 days'), |
| 124 |
// 'refresh' => BETTERDOCS_VERSION, |
| 125 |
'dismissible' => true, |
| 126 |
'do_action' => 'wpdeveloper_notice_clicked_for_betterdocs', |
| 127 |
] |
| 128 |
); |
| 129 |
} |
| 130 |
|
| 131 |
$notices->init(); |
| 132 |
} |
| 133 |
|
| 134 |
public function plugin_usage_insights(){ |
| 135 |
if( ! class_exists('BetterDocs_Plugin_Usage_Tracker') ) { |
| 136 |
require_once BETTERDOCS_DIR_PATH . '/includes/class-betterdocs-usage-tracker.php'; |
| 137 |
} |
| 138 |
|
| 139 |
$this->insights = BetterDocs_Plugin_Usage_Tracker::get_instance( BETTERDOCS_FILE, [ |
| 140 |
'opt_in' => true, |
| 141 |
'goodbye_form' => true, |
| 142 |
'item_id' => 'c7b16777b4f1b83f6083' |
| 143 |
] ); |
| 144 |
$this->insights->set_notice_options(array( |
| 145 |
'notice' => __('Want to help make <strong>BetterDocs</strong> even more awesome? You can get a <strong>10% discount coupon</strong> for Premium extensions if you allow us to track the usage.', 'betterdocs'), |
| 146 |
'extra_notice' => __('We collect non-sensitive diagnostic data and plugin usage information. |
| 147 |
Your site URL, WordPress & PHP version, plugins & themes and email address to send you the |
| 148 |
discount coupon. This data lets us make sure this plugin always stays compatible with the most |
| 149 |
popular plugins and themes. No spam, I promise.', 'betterdocs'), |
| 150 |
)); |
| 151 |
$this->insights->init(); |
| 152 |
} |
| 153 |
} |
| 154 |
|
| 155 |
BetterDocs_Admin_Notice::get_instance(); |