PluginProbe
Stream – Activity Log & Audit Trail / 3.8.0
Stream – Activity Log & Audit Trail v3.8.0
4.4.0 4.3.0 4.2.2 4.2.1 trunk 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.1 3.1.1 3.10.0 3.2.0 3.2.1 3.2.2 3.2.3 All 50 releases
← All changes | classes/class-connectors.php +84 -12 3.2.23.8.0 View file →
@@ -1,16 +1,27 @@
1 1 <?php
2 +/**
3 + * Validates and loads core connectors, integrated connectors, and
4 + * connectors registered using the "wp_stream_connectors" hook.
5 + *
6 + * @package WP_Stream
7 + */
8 +
2 9 namespace WP_Stream;
3 10
11 +/**
12 + * Class - Connectors
13 + */
4 14 class Connectors {
5 15 /**
6 - * Hold Plugin class
16 + * Holds instance of plugin object
17 + *
7 18 * @var Plugin
8 19 */
9 20 public $plugin;
10 21
11 22 /**
12 - * Connectors registered
23 + * Registered connectors.
13 24 *
14 25 * @var array
15 26 */
16 27 public $connectors = array();
@@ -23,8 +34,9 @@
23 34 public $contexts = array();
24 35
25 36 /**
26 37 * Action taxonomy terms
38 + *
27 39 * Holds slug to localized label association
28 40 *
29 41 * @var array
30 42 */
@@ -43,9 +55,9 @@
43 55
44 56 /**
45 57 * Class constructor.
46 58 *
47 - * @param Plugin $plugin The main Plugin class.
59 + * @param Plugin $plugin Instance of plugin object.
48 60 */
49 61 public function __construct( $plugin ) {
50 62 $this->plugin = $plugin;
51 63 $this->load_connectors();
@@ -55,9 +67,11 @@
55 67 * Load built-in connectors
56 68 */
57 69 public function load_connectors() {
58 70 $connectors = array(
59 - // Core
71 + /**
72 + * Core Connectors
73 + */
60 74 'blogs',
61 75 'comments',
62 76 'editor',
63 77 'installer',
@@ -68,9 +82,11 @@
68 82 'taxonomies',
69 83 'users',
70 84 'widgets',
71 85
72 - // Extras
86 + /**
87 + * Integrated Connectors
88 + */
73 89 'acf',
74 90 'bbpress',
75 91 'buddypress',
76 92 'edd',
@@ -75,8 +91,9 @@
75 91 'buddypress',
76 92 'edd',
77 93 'gravityforms',
78 94 'jetpack',
95 + 'mercator',
79 96 'user-switching',
80 97 'woocommerce',
81 98 'wordpress-seo',
82 99 );
@@ -82,30 +99,38 @@
82 99 );
83 100
84 101 $classes = array();
85 102 foreach ( $connectors as $connector ) {
103 + // Load connector class file.
86 104 include_once $this->plugin->locations['dir'] . '/connectors/class-connector-' . $connector . '.php';
105 +
106 + // Set fully qualified class name.
87 107 $class_name = sprintf( '\WP_Stream\Connector_%s', str_replace( '-', '_', $connector ) );
108 +
109 + // Bail if no class loaded.
88 110 if ( ! class_exists( $class_name ) ) {
89 111 continue;
90 112 }
113 +
114 + // Initialize connector.
91 115 $class = new $class_name( $this->plugin->log );
92 116
93 - // Check if the Connector extends WP_Stream\Connector
117 + // Check if the connector class extends WP_Stream\Connector.
94 118 if ( ! is_subclass_of( $class, 'WP_Stream\Connector' ) ) {
95 119 continue;
96 120 }
97 121
98 - // Check if the Connector is allowed to be registered in the WP Admin
122 + // Check if the connector events are allowed to be registered in the WP Admin.
99 123 if ( is_admin() && ! $class->register_admin ) {
100 124 continue;
101 125 }
102 126
103 - // Check if the Connector is allowed to be registered in the WP Frontend
127 + // Check if the connector events are allowed to be registered in the WP Frontend.
104 128 if ( ! is_admin() && ! $class->register_frontend ) {
105 129 continue;
106 130 }
107 131
132 + // Run any final validations the connector may have before used.
108 133 if ( $class->is_dependency_satisfied() ) {
109 134 $classes[ $class->name ] = $class;
110 135 }
111 136 }
@@ -127,25 +152,31 @@
127 152 }
128 153 $this->term_labels['stream_connector'][ $connector->name ] = $connector->get_label();
129 154 }
130 155
131 - // Get excluded connectors
156 + // Get excluded connectors.
132 157 $excluded_connectors = array();
133 158
134 159 foreach ( $this->connectors as $connector ) {
160 +
161 + // Register error for invalid any connector class.
135 162 if ( ! method_exists( $connector, 'get_label' ) ) {
163 + /* translators: %s: connector class name, intended to provide help to developers (e.g. "Connector_BuddyPress") */
136 164 $this->plugin->admin->notice( sprintf( __( '%s class wasn\'t loaded because it doesn\'t implement the get_label method.', 'stream' ), $connector->name, 'Connector' ), true );
137 165 continue;
138 166 }
139 167 if ( ! method_exists( $connector, 'register' ) ) {
168 + /* translators: %s: connector class name, intended to provide help to developers (e.g. "Connector_BuddyPress") */
140 169 $this->plugin->admin->notice( sprintf( __( '%s class wasn\'t loaded because it doesn\'t implement the register method.', 'stream' ), $connector->name, 'Connector' ), true );
141 170 continue;
142 171 }
143 172 if ( ! method_exists( $connector, 'get_context_labels' ) ) {
173 + /* translators: %s: connector class name, intended to provide help to developers (e.g. "Connector_BuddyPress") */
144 174 $this->plugin->admin->notice( sprintf( __( '%s class wasn\'t loaded because it doesn\'t implement the get_context_labels method.', 'stream' ), $connector->name, 'Connector' ), true );
145 175 continue;
146 176 }
147 177 if ( ! method_exists( $connector, 'get_action_labels' ) ) {
178 + /* translators: %s: connector class name, intended to provide help to developers (e.g. "Connector_BuddyPress") */
148 179 $this->plugin->admin->notice( sprintf( __( '%s class wasn\'t loaded because it doesn\'t implement the get_action_labels method.', 'stream' ), $connector->name, 'Connector' ), true );
149 180 continue;
150 181 }
151 182
@@ -150,13 +181,14 @@
150 181 }
151 182
152 183 // Check if the connectors extends the Connector class, if not skip it.
153 184 if ( ! is_subclass_of( $connector, '\WP_Stream\Connector' ) ) {
185 + /* translators: %s: connector class name, intended to provide help to developers (e.g. "Connector_BuddyPress") */
154 186 $this->plugin->admin->notice( sprintf( __( '%1$s class wasn\'t loaded because it doesn\'t extends the %2$s class.', 'stream' ), $connector->name, 'Connector' ), true );
155 187 continue;
156 188 }
157 189
158 - // Store connector label
190 + // Store connector label.
159 191 if ( ! in_array( $connector->name, $this->term_labels['stream_connector'], true ) ) {
160 192 $this->term_labels['stream_connector'][ $connector->name ] = $connector->get_label();
161 193 }
162 194
@@ -177,12 +209,12 @@
177 209 }
178 210
179 211 $connector->register();
180 212
181 - // Link context labels to their connector
213 + // Link context labels to their connector.
182 214 $this->contexts[ $connector->name ] = $connector->get_context_labels();
183 215
184 - // Add new terms to our label lookup array
216 + // Add new terms to our label lookup array.
185 217 $this->term_labels['stream_action'] = array_merge(
186 218 $this->term_labels['stream_action'],
187 219 $connector->get_action_labels()
188 220 );
@@ -200,6 +232,46 @@
200 232 * @param array $labels All register connectors labels array
201 233 * @param Connectors $connectors The Connectors object
202 234 */
203 235 do_action( 'wp_stream_after_connectors_registration', $labels, $this );
236 + }
237 +
238 + /**
239 + * Unregisters the context hooks for all connectors.
240 + */
241 + public function unload_connectors() {
242 + foreach ( $this->connectors as $connector ) {
243 + $connector->unregister();
244 + }
245 + }
246 +
247 + /**
248 + * Reregisters the context hooks for all connectors.
249 + */
250 + public function reload_connectors() {
251 + foreach ( $this->connectors as $connector ) {
252 + $connector->register();
253 + }
254 + }
255 +
256 + /**
257 + * Unregisters the context hooks for a connectors.
258 + *
259 + * @param string $name Name of the connector.
260 + */
261 + public function unload_connector( $name ) {
262 + if ( ! empty( $this->connectors[ $name ] ) ) {
263 + $this->connectors[ $name ]->unregister();
264 + }
265 + }
266 +
267 + /**
268 + * Reregisters the context hooks for a connector.
269 + *
270 + * @param string $name Name of the connector.
271 + */
272 + public function reload_connector( $name ) {
273 + if ( ! empty( $this->connectors[ $name ] ) ) {
274 + $this->connectors[ $name ]->register();
275 + }
204 276 }
205 277 }