PluginProbe ʕ •ᴥ•ʔ
Rank Math SEO – AI SEO Tools to Dominate SEO Rankings / 1.0.267
Rank Math SEO – AI SEO Tools to Dominate SEO Rankings v1.0.267
1.0.272 1.0.271 1.0.271.1 1.0.270 1.0.269 trunk 1.0.216 1.0.217 1.0.218 1.0.219 1.0.220 1.0.221 1.0.222 1.0.223 1.0.224 1.0.225 1.0.226 1.0.227 1.0.227.1 1.0.228 1.0.229 1.0.230 1.0.231 1.0.232 1.0.233 1.0.234 1.0.234.1 1.0.235 1.0.236 1.0.237 1.0.238 1.0.239 1.0.240 1.0.241 1.0.242 1.0.243 1.0.244 1.0.245 1.0.246 1.0.247 1.0.248 1.0.249 1.0.250 1.0.251 1.0.251.1 1.0.252 1.0.252.1 1.0.253 1.0.254 1.0.255 1.0.256 1.0.257 1.0.258 1.0.259 1.0.259.1 1.0.260 1.0.261 1.0.262 1.0.263 1.0.264 1.0.264.1 1.0.265 1.0.266 1.0.266.1 1.0.267 1.0.268
seo-by-rank-math / vendor / wp-media / wp-mixpanel / src / Optin.php
seo-by-rank-math / vendor / wp-media / wp-mixpanel / src Last commit date
Classes 10 months ago Optin.php 9 months ago Tracking.php 8 months ago TrackingPlugin.php 7 months ago WPConsumer.php 10 months ago
Optin.php
100 lines
1 <?php
2 declare(strict_types=1);
3
4 namespace WPMedia\Mixpanel;
5
6 class Optin {
7 /**
8 * The plugin slug.
9 *
10 * @var string
11 */
12 private $plugin_slug;
13
14 /**
15 * The capability required to enable/disable the opt-in.
16 *
17 * @var string
18 */
19 private $capability;
20
21 /**
22 * Constructor.
23 *
24 * @param string $plugin_slug The plugin slug.
25 * @param string $capability The capability required to enable/disable the opt-in.
26 */
27 public function __construct( string $plugin_slug, string $capability ) {
28 $this->plugin_slug = $plugin_slug;
29 $this->capability = $capability;
30 }
31
32 /**
33 * Check if the opt-in is enabled.
34 *
35 * @return bool True if the opt-in is enabled, false otherwise.
36 */
37 public function is_enabled(): bool {
38 if ( ! current_user_can( $this->capability ) ) {
39 return false;
40 }
41
42 $optin = get_option( $this->plugin_slug . '_mixpanel_optin', false );
43
44 if ( ! $optin ) {
45 return false;
46 }
47
48 return true;
49 }
50
51 /**
52 * Check if tracking is allowed.
53 *
54 * @return bool
55 */
56 public function can_track(): bool {
57 return (bool) get_option( $this->plugin_slug . '_mixpanel_optin', false );
58 }
59
60 /**
61 * Enable the opt-in.
62 *
63 * @return void
64 */
65 public function enable(): void {
66 if ( $this->is_enabled() ) {
67 return;
68 }
69
70 update_option( $this->plugin_slug . '_mixpanel_optin', true );
71
72 /**
73 * Fires when the Mixpanel opt-in status changes to enabled.
74 *
75 * @param bool $status The opt-in status.
76 */
77 do_action( $this->plugin_slug . '_mixpanel_optin_changed', true );
78 }
79
80 /**
81 * Disable the opt-in.
82 *
83 * @return void
84 */
85 public function disable(): void {
86 if ( ! $this->is_enabled() ) {
87 return;
88 }
89
90 delete_option( $this->plugin_slug . '_mixpanel_optin' );
91
92 /**
93 * Fires when the Mixpanel opt-in status changes to disabled.
94 *
95 * @param bool $status The opt-in status.
96 */
97 do_action( $this->plugin_slug . '_mixpanel_optin_changed', false );
98 }
99 }
100