PluginProbe
Analytify – Google Analytics Dashboard For WordPress (GA4 analytics tracking) / trunk
Analytify – Google Analytics Dashboard For WordPress (GA4 analytics tracking) vtrunk
9.1.2 9.1.1 9.1.0 9.0.2 9.0.1 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.1.0 1.1.1 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.3.0 1.3.1 1.3.2 All 153 releases
wp-analytify / inc / plugin-lifecycle.php

plugin-lifecycle.php in Analytify – Google Analytics Dashboard For WordPress (GA4 analytics tracking) trunk, at inc/plugin-lifecycle.php

170 lines 4.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName -- File naming is acceptable
2 /**
3 * Plugin Lifecycle Component for WP Analytify
4 *
5 * This file contains all plugin activation, deactivation, and uninstall functions
6 * that were previously in the main plugin file.
7 *
8 * @package WP_Analytify
9 * @since 8.0.0
10 */
11
12 if ( ! defined( 'ABSPATH' ) ) {
13 exit;
14 }
15
16 /**
17 * Plugin Lifecycle Component Class
18 */
19 class Analytify_Plugin_Lifecycle {
20
21 /**
22 * Main plugin instance
23 *
24 * @var WP_Analytify
25 */
26 private $analytify;
27
28 /**
29 * Constructor
30 *
31 * @param WP_Analytify $analytify Main plugin instance.
32 */
33 public function __construct( $analytify ) {
34 $this->analytify = $analytify;
35 }
36
37 /**
38 * Run on plugin activation.
39 *
40 * @since 1.2.2
41 * @return void
42 */
43 public function activate() {
44
45 // update version.
46 if ( ! get_option( 'pa_google_token' ) ) {
47 update_option( 'wpa_current_version', '2.1.2' );
48 }
49
50 // Return if settings already added in DB.
51 $_admin_settings = get_option( 'wp-analytify-admin' );
52 if ( $_admin_settings && 'on' === $_admin_settings['enable_back_end'] && ! empty( $_admin_settings['show_analytics_roles_back_end'] ) ) {
53 return;
54 }
55
56 // Load default settings on new install.
57 if ( ! get_option( 'analytify_default_settings' ) ) {
58 $profile_tab_settings = array(
59 'exclude_users_tracking' => array( 'administrator' ),
60 );
61
62 update_option( 'wp-analytify-profile', $profile_tab_settings );
63
64 $admin_tab_settings = array(
65 'enable_back_end' => 'on',
66 'show_analytics_roles_back_end' => array( 'administrator', 'editor' ),
67 'show_analytics_post_types_back_end' => array( 'post', 'page' ),
68 'show_panels_back_end' => array( 'show-overall-dashboard', 'show-social-dashboard', 'show-geographic-dashboard', 'show-system-stats', 'show-keywords-dashboard', 'show-referrer-dashboard' ),
69 );
70
71 update_option( 'wp-analytify-admin', $admin_tab_settings );
72
73 $dashboard_tab_settings['show_analytics_panels_dashboard'] = array(
74 'show-real-time',
75 'show-compare-stats',
76 'show-overall-dashboard',
77 'show-top-pages-dashboard',
78 'show-geographic-dashboard',
79 'show-system-stats',
80 'show-keywords-dashboard',
81 'show-social-dashboard',
82 'show-referrer-dashboard',
83 'show-page-stats-dashboard',
84 );
85
86 $dashboard_tab_settings['show_analytics_roles_dashboard'] = array( 'administrator' );
87
88 update_option( 'wp-analytify-dashboard', $dashboard_tab_settings );
89
90 $advanced_tab_settings = array(
91 'gtag_tracking_mode' => 'gtag',
92 'google_analytics_version' => 'ga4',
93 );
94
95 update_option( 'wp-analytify-advanced', $advanced_tab_settings );
96
97 // Update meta so default settings load only one time.
98 update_option( 'analytify_default_settings', 'done' );
99
100 update_option( 'analytify_active_date', gmdate( 'l jS F Y h:i:s A' ) . date_default_timezone_get() );
101 }
102 }
103
104 /**
105 * Delete option values on plugin deactivation.
106 *
107 * @since 1.2.2
108 * @return void
109 */
110 public function deactivate() {
111 // Delete welcome page check on de-activate.
112 delete_option( 'show_welcome_page' );
113 }
114
115 /**
116 * Delete plugin settings meta on deleting the plugin
117 *
118 * @return void
119 */
120 public function uninstall() {
121
122 $plugin_dir = defined( 'WP_ANALYTIFY_PLUGIN_DIR' ) ? WP_ANALYTIFY_PLUGIN_DIR : dirname( __DIR__ );
123 require_once $plugin_dir . '/classes/analytify-utils.php';
124
125 $remove_settings_on_uninstall = WPANALYTIFY_Utils::get_option( 'uninstall_analytify_settings', 'wp-analytify-advanced', false );
126
127 if ( $remove_settings_on_uninstall && 'on' === $remove_settings_on_uninstall ) {
128
129 require_once $plugin_dir . '/classes/analytify-factory-reset.php';
130
131 // Remove all the settings on uninstall.
132 ( new Analytify_Factory_Reset() )->remove_settings();
133 }
134 }
135
136 /**
137 * Send status of subscriber who opt-in for improving the product.
138 *
139 * @param string $email Users email.
140 * @param string $status Plugin status.
141 * @return void
142 */
143 public function send_status( $email, $status ) {
144 $url = 'https://analytify.io/plugin-manager/';
145
146 if ( '' === $email ) {
147 $email = 'track@analytify.io';
148 }
149
150 $fields = array(
151 'email' => $email,
152 'site' => get_site_url(),
153 'status' => $status,
154 'type' => 'FREE',
155 );
156
157 wp_remote_post(
158 $url,
159 array(
160 'method' => 'POST',
161 'timeout' => 5,
162 'httpversion' => '1.0',
163 'blocking' => false,
164 'headers' => array(),
165 'body' => $fields,
166 )
167 );
168 }
169 }
170