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 / classes / analytify-base.php

analytify-base.php in Analytify – Google Analytics Dashboard For WordPress (GA4 analytics tracking) trunk, at classes/analytify-base.php

204 lines 4.8 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 for this plugin structure
2
3 /**
4 * Base class for Analytify functionality.
5 *
6 * This class provides the foundation for all Analytify classes,
7 * including common properties and methods for plugin management.
8 *
9 * @package WP_Analytify
10 * @since 1.0.0
11 */
12 class Analytify_Base {
13
14 /**
15 * Plugin settings.
16 *
17 * @var mixed
18 */
19 protected $settings;
20 /**
21 * Plugin file path.
22 *
23 * @var string
24 */
25 protected $plugin_file_path;
26 /**
27 * Plugin directory path.
28 *
29 * @var string
30 */
31 protected $plugin_dir_path;
32 /**
33 * Plugin folder name.
34 *
35 * @var string
36 */
37 protected $plugin_folder_name;
38 /**
39 * Plugin basename.
40 *
41 * @var string
42 */
43 protected $plugin_basename;
44 /**
45 * Plugin title.
46 *
47 * @var string
48 */
49 protected $plugin_title;
50 /**
51 * Plugin slug.
52 *
53 * @var string
54 */
55 protected $plugin_slug;
56 /**
57 * Core slug.
58 *
59 * @var string
60 */
61 protected $core_slug;
62 /**
63 * Template directory.
64 *
65 * @var string
66 */
67 protected $template_dir;
68 /**
69 * Whether this is an addon.
70 *
71 * @var bool
72 */
73 protected $is_addon = false;
74 /**
75 * Whether this is the pro version.
76 *
77 * @var bool
78 */
79 protected $is_pro = false;
80
81 /**
82 * Plugin base.
83 *
84 * @var string
85 */
86 protected $plugin_base;
87
88 /**
89 * Constructor.
90 *
91 * @param string $plugin_file_path The plugin file path.
92 */
93 public function __construct( $plugin_file_path ) {
94
95 $this->load_settings();
96
97 $this->plugin_file_path = $plugin_file_path;
98 $this->plugin_dir_path = plugin_dir_path( $plugin_file_path );
99 $this->plugin_folder_name = basename( $this->plugin_dir_path );
100 $this->plugin_basename = plugin_basename( $plugin_file_path );
101 $this->template_dir = $this->plugin_dir_path . 'template' . DIRECTORY_SEPARATOR;
102 $this->plugin_title = ucwords( str_ireplace( '-', ' ', basename( $plugin_file_path ) ) );
103 $this->plugin_title = str_ireplace( array( 'wp', 'analytify', 'pro', '.php' ), array( 'WP', 'ANALYTIFY', 'PRO', '' ), $this->plugin_title );
104
105 $this->plugin_slug = basename( $plugin_file_path, '.php' );
106
107 // Used to add admin menus and to identify the core version.
108 $this->core_slug = ( $this->is_pro || $this->is_addon ) ? 'wp-analytify-pro' : 'wp-analytify';
109
110 if ( is_multisite() ) {
111 $this->plugin_base = 'settings.php?page=' . $this->core_slug;
112 } else {
113 $this->plugin_base = 'tools.php?page=' . $this->core_slug;
114 }
115
116 if ( $this->is_addon || $this->is_pro ) {
117 $this->pro_addon_construct();
118 }
119
120 add_action( 'init', array( $this, 'load_plugin_textdomain' ) );
121 }
122
123
124 /**
125 * Load plugin settings.
126 *
127 * @return void
128 */
129 public function load_settings() {
130
131 if ( ! is_null( $this->settings ) ) {
132 return;
133 }
134
135 $update_settings = false;
136 $this->settings = get_site_option( 'wpanalytify_settings' );
137
138 /*
139 * Settings were previously stored and retrieved using get_option and update_option respectively.
140 * Here we update the subsite option to a network wide option if applicable.
141 */
142 if ( false === $this->settings && is_multisite() && is_network_admin() ) {
143 $this->settings = get_option( 'wpanalytify_settings' );
144 if ( false !== $this->settings ) {
145 $update_settings = true;
146 delete_option( 'wpanalytify_settings' );
147 }
148 }
149
150 $default_settings = array(
151 'profiles' => array(),
152 'licence' => '',
153 'analytify_posts_stats' => array( 'post', 'page' ),
154 'post_analytics_disable_back' => 1,
155 'post_analytics_settings_back' => array( 'show-overall-back' ),
156 'post_analytics_access_back' => array( 'editor', 'administrator' ),
157 'display_tracking_code' => array( 'administrator' ),
158 'show_welcome_page' => 0,
159 );
160
161 // If we still don't have settings exist this must be a fresh install, set up some default settings.
162 if ( false === $this->settings ) {
163 $this->settings = $default_settings;
164 $update_settings = true;
165 } else {
166 /*
167 * When new settings are added an existing customer's db won't have the new settings.
168 * They're added here to circumvent array index errors in debug mode.
169 */
170 foreach ( $default_settings as $key => $value ) {
171 if ( ! isset( $this->settings[ $key ] ) ) {
172 $this->settings[ $key ] = $value;
173 $update_settings = true;
174 }
175 }
176 }
177
178 if ( $update_settings ) {
179 update_site_option( 'wpanalytify_settings', $this->settings );
180 }
181 }
182
183
184 /**
185 * Load plugin textdomain.
186 *
187 * @access public
188 * @since 2.0
189 * @return void
190 */
191 public function load_plugin_textdomain() {
192 load_plugin_textdomain( 'wp-analytify', false, dirname( plugin_basename( $this->plugin_file_path ) ) . '/languages/' );
193 }
194
195
196 /**
197 * Pro addon constructor.
198 *
199 * @return void
200 */
201 public function pro_addon_construct() {
202 }
203 }
204