PluginProbe ʕ •ᴥ•ʔ
MainWP Child Reports / 2.0.3
MainWP Child Reports v2.0.3
0.0.1 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9.1 1.9.2 1.9.3 2.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.1 2.1.1 2.2 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.3 2.3.1 trunk
mainwp-child-reports / classes / class-plugin.php
mainwp-child-reports / classes Last commit date
class-admin.php 6 years ago class-alert-trigger.php 6 years ago class-alert-type.php 6 years ago class-alert.php 6 years ago class-alerts-list.php 6 years ago class-alerts.php 6 years ago class-author.php 6 years ago class-cli.php 6 years ago class-connector.php 6 years ago class-connectors.php 6 years ago class-date-interval.php 6 years ago class-db-driver-wpdb.php 6 years ago class-db-driver.php 6 years ago class-db.php 6 years ago class-export.php 6 years ago class-exporter.php 6 years ago class-filter-input.php 6 years ago class-form-generator.php 6 years ago class-install.php 6 years ago class-list-table.php 6 years ago class-live-update.php 6 years ago class-log.php 6 years ago class-mainwp-child-report-helper.php 6 years ago class-network.php 6 years ago class-plugin.php 6 years ago class-preview-list-table.php 6 years ago class-query.php 6 years ago class-record.php 6 years ago class-settings.php 6 years ago class-uninstall.php 6 years ago debug.log 6 years ago
class-plugin.php
232 lines
1 <?php
2 namespace WP_MainWP_Stream;
3
4 class Plugin {
5 /**
6 * Plugin version number
7 *
8 * @const string
9 */
10 const VERSION = '3.5.5';
11
12 /**
13 * WP-CLI command
14 *
15 * @const string
16 */
17 const WP_CLI_COMMAND = 'mainwp_stream';
18
19 /**
20 * @var Admin
21 */
22 public $admin;
23
24 /**
25 * @var Alerts
26 */
27 public $alerts;
28
29 /**
30 * @var Alerts_List
31 */
32 public $alerts_list;
33
34 /**
35 * @var Connectors
36 */
37 public $connectors;
38
39 /**
40 * @var DB
41 */
42 public $db;
43
44 /**
45 * @var Log
46 */
47 public $log;
48
49 /**
50 * @var Settings
51 */
52 public $settings;
53
54 /**
55 * @var Install
56 */
57 public $install;
58
59 /**
60 * URLs and Paths used by the plugin
61 *
62 * @var array
63 */
64 public $locations = array();
65
66
67 /**
68 * @var Child_Helper
69 */
70 public $child_helper;
71
72 /**
73 * Class constructor
74 */
75 public function __construct() {
76 $locate = $this->locate_plugin();
77
78 $this->locations = array(
79 'plugin' => $locate['plugin_basename'],
80 'dir' => $locate['dir_path'],
81 'url' => $locate['dir_url'],
82 'inc_dir' => $locate['dir_path'] . 'includes/',
83 'class_dir' => $locate['dir_path'] . 'classes/',
84 );
85
86 spl_autoload_register( array( $this, 'autoload' ) );
87
88 // Load helper functions
89 require_once $this->locations['inc_dir'] . 'functions.php';
90
91 // Load DB helper interface/class
92 $driver_class = apply_filters( 'wp_mainwp_stream_db_driver', '\WP_MainWP_Stream\DB_Driver_WPDB' );
93 $driver = null;
94
95 if ( class_exists( $driver_class ) ) {
96 $driver = new $driver_class();
97 $this->db = new DB( $driver );
98 }
99
100 $error = false;
101 if ( ! $this->db ) {
102 $error = esc_html__( 'Stream: Could not load chosen DB driver.', 'mainwp-child-reports' );
103 } elseif ( ! $driver instanceof DB_Driver ) {
104 $error = esc_html__( 'Stream: DB driver must implement DB Driver interface.', 'mainwp-child-reports' );
105 }
106
107 if ( $error ) {
108 wp_die(
109 esc_html( $error ),
110 esc_html__( 'Reports DB Error', 'mainwp-child-reports' )
111 );
112 }
113
114 // Load languages
115 add_action( 'plugins_loaded', array( $this, 'i18n' ) );
116
117 // Load logger class
118 $this->log = apply_filters( 'wp_mainwp_stream_log_handler', new Log( $this ) );
119
120 // Load settings and connectors after widgets_init and before the default init priority
121 add_action( 'init', array( $this, 'init' ), 9 );
122
123
124 // Change DB driver after plugin loaded if any add-ons want to replace
125 add_action( 'plugins_loaded', array( $this, 'plugins_loaded' ), 20 );
126
127 // Load admin area classes
128 if ( is_admin() || ( defined( 'WP_MAINWP_STREAM_DEV_DEBUG' ) && WP_MAINWP_STREAM_DEV_DEBUG ) || ( defined( 'WP_CLI' ) && WP_CLI ) ) {
129 $this->admin = new Admin( $this );
130 $this->install = $driver->setup_storage( $this );
131 } elseif ( defined( 'DOING_CRON' ) && DOING_CRON ) {
132 $this->admin = new Admin( $this, $driver );
133 }
134 $this->child_helper = new MainWP_Child_Report_Helper( $this );
135
136 // Load WP-CLI command
137 if ( defined( 'WP_CLI' ) && WP_CLI ) {
138 \WP_CLI::add_command( self::WP_CLI_COMMAND, 'WP_MainWP_Stream\CLI' );
139 }
140 }
141
142 /**
143 * Autoloader for classes
144 *
145 * @param string $class
146 */
147 public function autoload( $class ) {
148 if ( ! preg_match( '/^(?P<namespace>.+)\\\\(?P<autoload>[^\\\\]+)$/', $class, $matches ) ) {
149 return;
150 }
151
152 static $reflection;
153
154 if ( empty( $reflection ) ) {
155 $reflection = new \ReflectionObject( $this );
156 }
157
158 if ( $reflection->getNamespaceName() !== $matches['namespace'] ) {
159 return;
160 }
161
162 $autoload_name = $matches['autoload'];
163 $autoload_dir = \trailingslashit( $this->locations['class_dir'] );
164 $autoload_path = sprintf( '%sclass-%s.php', $autoload_dir, strtolower( str_replace( '_', '-', $autoload_name ) ) );
165
166 if ( is_readable( $autoload_path ) ) {
167 require_once $autoload_path;
168 }
169 }
170
171 /**
172 * Loads the translation files.
173 *
174 * @action plugins_loaded
175 */
176 public function i18n() {
177 load_plugin_textdomain( 'mainwp-child-reports', false, dirname( $this->locations['plugin'] ) . '/languages/' );
178 }
179
180 /*
181 * Load Settings, Notifications, and Connectors
182 *
183 * @action init
184 */
185 public function init() {
186 $this->settings = new Settings( $this );
187 $this->connectors = new Connectors( $this );
188 $this->alerts = new Alerts( $this );
189 $this->alerts_list = new Alerts_List( $this );
190
191 }
192
193 /**
194 * Version of plugin_dir_url() which works for plugins installed in the plugins directory,
195 * and for plugins bundled with themes.
196 *
197 * @throws \Exception
198 *
199 * @return array
200 */
201 private function locate_plugin() {
202 $dir_url = trailingslashit( plugins_url( '', dirname( __FILE__ ) ) );
203 $dir_path = plugin_dir_path( dirname( __FILE__ ) );
204 $dir_basename = basename( $dir_path );
205 $plugin_basename = trailingslashit( $dir_basename ) . $dir_basename . '.php';
206
207 return compact( 'dir_url', 'dir_path', 'dir_basename', 'plugin_basename' );
208 }
209
210 /**
211 * Getter for the version number.
212 *
213 * @return string
214 */
215 public function get_version() {
216 return self::VERSION;
217 }
218
219 /**
220 * Change plugin database driver in case driver plugin loaded after stream
221 */
222 public function plugins_loaded() {
223 // Load DB helper interface/class
224 $driver_class = apply_filters( 'wp_mainwp_stream_db_driver', '\WP_MainWP_Stream\DB_Driver_WPDB' );
225
226 if ( class_exists( $driver_class ) ) {
227 $driver = new $driver_class();
228 $this->db = new DB( $driver );
229 }
230 }
231 }
232