PluginProbe
Stream – Activity Log & Audit Trail / 3.2.0
Stream – Activity Log & Audit Trail v3.2.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
stream / classes / class-connectors.php

class-connectors.php in Stream – Activity Log & Audit Trail 3.2.0, at classes/class-connectors.php

206 lines 5.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace WP_Stream;
3
4 class Connectors {
5 /**
6 * Hold Plugin class
7 * @var Plugin
8 */
9 public $plugin;
10
11 /**
12 * Connectors registered
13 *
14 * @var array
15 */
16 public $connectors = array();
17
18 /**
19 * Contexts registered to Connectors
20 *
21 * @var array
22 */
23 public $contexts = array();
24
25 /**
26 * Action taxonomy terms
27 * Holds slug to localized label association
28 *
29 * @var array
30 */
31 public $term_labels = array(
32 'stream_connector' => array(),
33 'stream_context' => array(),
34 'stream_action' => array(),
35 );
36
37 /**
38 * Admin notice messages
39 *
40 * @var array
41 */
42 protected $admin_notices = array();
43
44 /**
45 * Class constructor.
46 *
47 * @param Plugin $plugin The main Plugin class.
48 */
49 public function __construct( $plugin ) {
50 $this->plugin = $plugin;
51 $this->load_connectors();
52 }
53
54 /**
55 * Load built-in connectors
56 */
57 public function load_connectors() {
58 $connectors = array(
59 // Core
60 'blogs',
61 'comments',
62 'editor',
63 'installer',
64 'media',
65 'menus',
66 'posts',
67 'settings',
68 'taxonomies',
69 'users',
70 'widgets',
71
72 // Extras
73 'acf',
74 'bbpress',
75 'buddypress',
76 'edd',
77 'gravityforms',
78 'jetpack',
79 'user-switching',
80 'woocommerce',
81 'wordpress-seo',
82 );
83
84 $classes = array();
85 foreach ( $connectors as $connector ) {
86 include_once $this->plugin->locations['dir'] . '/connectors/class-connector-' . $connector . '.php';
87 $class_name = sprintf( '\WP_Stream\Connector_%s', str_replace( '-', '_', $connector ) );
88 if ( ! class_exists( $class_name ) ) {
89 continue;
90 }
91 $class = new $class_name( $this->plugin->log );
92
93 // Check if the Connector extends WP_Stream\Connector
94 if ( ! is_subclass_of( $class, 'WP_Stream\Connector' ) ) {
95 continue;
96 }
97
98 // Check if the Connector is allowed to be registered in the WP Admin
99 if ( is_admin() && ! $class->register_admin ) {
100 continue;
101 }
102
103 // Check if the Connector is allowed to be registered in the WP Frontend
104 if ( ! is_admin() && ! $class->register_frontend ) {
105 continue;
106 }
107
108 if ( $class->is_dependency_satisfied() ) {
109 $classes[ $class->name ] = $class;
110 }
111 }
112
113 /**
114 * Allows for adding additional connectors via classes that extend Connector.
115 *
116 * @param array $classes An array of Connector objects.
117 */
118 $this->connectors = apply_filters( 'wp_stream_connectors', $classes );
119
120 if ( empty( $this->connectors ) ) {
121 return;
122 }
123
124 foreach ( $this->connectors as $connector ) {
125 if ( ! method_exists( $connector, 'get_label' ) ) {
126 continue;
127 }
128 $this->term_labels['stream_connector'][ $connector->name ] = $connector->get_label();
129 }
130
131 // Get excluded connectors
132 $excluded_connectors = array();
133
134 foreach ( $this->connectors as $connector ) {
135 if ( ! method_exists( $connector, 'get_label' ) ) {
136 $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 continue;
138 }
139 if ( ! method_exists( $connector, 'register' ) ) {
140 $this->plugin->admin->notice( sprintf( __( '%s class wasn\'t loaded because it doesn\'t implement the register method.', 'stream' ), $connector->name, 'Connector' ), true );
141 continue;
142 }
143 if ( ! method_exists( $connector, 'get_context_labels' ) ) {
144 $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 continue;
146 }
147 if ( ! method_exists( $connector, 'get_action_labels' ) ) {
148 $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 continue;
150 }
151
152 // Check if the connectors extends the Connector class, if not skip it.
153 if ( ! is_subclass_of( $connector, '\WP_Stream\Connector' ) ) {
154 $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 continue;
156 }
157
158 // Store connector label
159 if ( ! in_array( $connector->name, $this->term_labels['stream_connector'], true ) ) {
160 $this->term_labels['stream_connector'][ $connector->name ] = $connector->get_label();
161 }
162
163 $connector_name = $connector->name;
164 $is_excluded = in_array( $connector_name, $excluded_connectors, true );
165
166 /**
167 * Allows excluded connectors to be overridden and registered.
168 *
169 * @param bool $is_excluded True if excluded, otherwise false.
170 * @param string $connector The current connector's slug.
171 * @param array $excluded_connectors An array of all excluded connector slugs.
172 */
173 $is_excluded_connector = apply_filters( 'wp_stream_check_connector_is_excluded', $is_excluded, $connector_name, $excluded_connectors );
174
175 if ( $is_excluded_connector ) {
176 continue;
177 }
178
179 $connector->register();
180
181 // Link context labels to their connector
182 $this->contexts[ $connector->name ] = $connector->get_context_labels();
183
184 // Add new terms to our label lookup array
185 $this->term_labels['stream_action'] = array_merge(
186 $this->term_labels['stream_action'],
187 $connector->get_action_labels()
188 );
189 $this->term_labels['stream_context'] = array_merge(
190 $this->term_labels['stream_context'],
191 $connector->get_context_labels()
192 );
193 }
194
195 $labels = $this->term_labels['stream_connector'];
196
197 /**
198 * Fires after all connectors have been registered.
199 *
200 * @param array $labels All register connectors labels array
201 * @param Connectors $connectors The Connectors object
202 */
203 do_action( 'wp_stream_after_connectors_registration', $labels, $this );
204 }
205 }
206