PluginProbe
Code Snippets / trunk
Code Snippets vtrunk
4.0.0-beta.2 3.10.2 3.10.1 3.10.0 3.10.0-beta.2 3.10.0-beta.1 4.0.0-beta.1 3.9.6 trunk 2.10.0 2.10.1 2.12.0 2.12.1 2.13.0 2.13.1 2.13.2 2.13.3 2.14.0 2.14.1 2.14.2 2.14.3 2.14.4 2.14.5 2.14.6 3.0.0 All 65 releases
← All changes | php/Plugin.php +60 -30 3.10.0-beta.1 → trunk View file →
@@ -2,8 +2,12 @@
2 2
3 3 namespace Code_Snippets;
4 4
5 5 use Code_Snippets\Admin\Bootstrap_Admin;
6 +use Code_Snippets\Admin\Feedback_Error_Capture;
7 +use Code_Snippets\Admin\Feedback_Panel;
8 +use Code_Snippets\Admin\Menus\Manage\Manage_Menu;
9 +use Code_Snippets\Client\Feedback_Client;
6 10 use Code_Snippets\Controller\Cloud_Search_Controller;
7 11 use Code_Snippets\Core\DB;
8 12 use Code_Snippets\Core\Licensing;
9 13 use Code_Snippets\Core\Upgrader;
@@ -13,14 +17,19 @@
13 17 use Code_Snippets\Integration\Evaluate_Functions;
14 18 use Code_Snippets\Integration\Promotions\Promotion_Manager;
15 19 use Code_Snippets\Integration\Shortcodes;
16 20 use Code_Snippets\Model\Basic_Cloud_Connection;
21 +use Code_Snippets\Model\Feedback_Connection;
17 22 use Code_Snippets\REST_API\Cloud\Cloud_Snippets_REST_Controller;
23 +use Code_Snippets\REST_API\Feedback\Feedback_REST_Controller;
18 24 use Code_Snippets\REST_API\Import\File_Import_REST_Controller;
19 25 use Code_Snippets\REST_API\Import\Plugins_Import_REST_Controller;
20 -use Code_Snippets\REST_API\Snippets\Preferences_REST_Controller;
26 +use Code_Snippets\REST_API\Preferences\Demos_Seen_REST_Controller;
27 +use Code_Snippets\REST_API\Preferences\Insights_View_Rest_Controller;
28 +use Code_Snippets\REST_API\Preferences\Snippet_View_REST_Controller;
21 29 use Code_Snippets\REST_API\Snippets\Recently_Active_REST_Controller;
22 30 use Code_Snippets\REST_API\Snippets\Snippets_REST_Controller;
31 +use function Code_Snippets\Settings\are_settings_unified;
23 32
24 33 /**
25 34 * The main plugin class
26 35 *
@@ -106,9 +115,9 @@
106 115 require_once __DIR__ . '/snippet-ops.php';
107 116 }
108 117
109 118 /**
110 - * Initialise the plugin and load all necessary classes.
119 + * Initialize the plugin and load all necessary classes.
111 120 */
112 121 public function load_plugin() {
113 122 $this->load_utilities();
114 123
@@ -124,8 +133,9 @@
124 133
125 134 if ( is_admin() ) {
126 135 $this->admin = new Bootstrap_Admin();
127 136 new Promotion_Manager();
137 + new Feedback_Error_Capture( new Feedback_Panel() );
128 138 }
129 139
130 140 new Shortcodes();
131 141 new MCE_Plugin();
@@ -131,12 +141,8 @@
131 141 new MCE_Plugin();
132 142 new Upgrader( PLUGIN_VERSION, $this->db );
133 143 new Admin_Bar();
134 144
135 - if ( is_admin() ) {
136 - new Promotion_Manager();
137 - }
138 -
139 145 $this->init_snippet_files();
140 146
141 147 add_action( 'rest_api_init', [ $this, 'init_rest_api' ], 1 );
142 148 }
@@ -150,17 +156,23 @@
150 156 $cloud_search = new Cloud_Search_Controller( $this->cloud_connection );
151 157
152 158 new Snippets_REST_Controller();
153 159 new Recently_Active_REST_Controller();
154 - new Preferences_REST_Controller();
160 +
161 + new Snippet_View_REST_Controller();
162 + new Insights_View_Rest_Controller();
163 + new Demos_Seen_REST_Controller();
164 +
155 165 new Plugins_Import_REST_Controller();
156 166 new File_Import_REST_Controller();
157 167
158 168 new Cloud_Snippets_REST_Controller( $cloud_search );
169 +
170 + new Feedback_REST_Controller( new Feedback_Client( new Feedback_Connection() ) );
159 171 }
160 172
161 173 /**
162 - * Initialises the snippet files component.
174 + * Initializes the snippet files component.
163 175 *
164 176 * @return void
165 177 */
166 178 private function init_snippet_files() {
@@ -199,8 +211,9 @@
199 211 $edit = [ 'edit', 'edit-snippet' ];
200 212 $import = [ 'import', 'import-snippets', 'import-code-snippets' ];
201 213 $settings = [ 'settings', 'snippets-settings' ];
202 214 $cloud = [ 'cloud', 'cloud-snippets' ];
215 + $insights = [ 'insights', 'code-snippets-insights' ];
203 216 $welcome = [ 'welcome', 'getting-started', 'code-snippets' ];
204 217
205 218 if ( in_array( $menu, $edit, true ) ) {
206 219 return 'edit-snippet';
@@ -211,8 +224,10 @@
211 224 } elseif ( in_array( $menu, $settings, true ) ) {
212 225 return 'snippets-settings';
213 226 } elseif ( in_array( $menu, $cloud, true ) ) {
214 227 return 'snippets&subpage=cloud-community';
228 + } elseif ( in_array( $menu, $insights, true ) ) {
229 + return 'code-snippets-insights';
215 230 } elseif ( in_array( $menu, $welcome, true ) ) {
216 231 return 'code-snippets-welcome';
217 232 } else {
218 233 return 'snippets';
@@ -240,15 +255,22 @@
240 255 } else {
241 256 $url = 'admin.php?page=' . $slug;
242 257 }
243 258
244 - if ( 'network' === $context ) {
259 + if ( 'snippets-settings' === $slug && are_settings_unified() ) {
245 260 return network_admin_url( $url );
246 - } elseif ( 'admin' === $context ) {
247 - return admin_url( $url );
248 - } else {
249 - return self_admin_url( $url );
250 261 }
262 +
263 + switch ( $context ) {
264 + case 'network':
265 + return network_admin_url( $url );
266 +
267 + case 'admin':
268 + return admin_url( $url );
269 +
270 + default:
271 + return self_admin_url( $url );
272 + }
251 273 }
252 274
253 275 /**
254 276 * Allow redirecting to the Code Snippets site.
@@ -332,9 +354,9 @@
332 354 : $this->get_cap_name();
333 355 }
334 356
335 357 /**
336 - * Localise a plugin script to provide the CODE_SNIPPETS object.
358 + * Localize a plugin script to provide the CODE_SNIPPETS object.
337 359 *
338 360 * @param string $handle Script handle.
339 361 *
340 362 * @return void
@@ -343,18 +365,22 @@
343 365 wp_localize_script(
344 366 $handle,
345 367 'CODE_SNIPPETS',
346 368 [
347 - 'debug' => defined( 'WP_DEBUG' ) && WP_DEBUG,
348 - 'isLicensed' => $this->licensing->is_licensed(),
349 - 'isCloudConnected' => $this->cloud_connection->is_authenticated(),
350 - 'hideUpsell' => Settings\get_setting( 'general', 'hide_upgrade_menu' ),
351 - 'snippetView' => Preferences_REST_Controller::get_snippet_view(),
352 - 'restAPI' => [
369 + 'debug' => defined( 'WP_DEBUG' ) && WP_DEBUG,
370 + 'isLicensed' => $this->licensing->is_licensed(),
371 + 'isCloudConnected' => $this->cloud_connection->is_authenticated(),
372 + 'hideUpsell' => Settings\get_setting( 'general', 'hide_upgrade_menu' ),
373 + 'snippetView' => Snippet_View_REST_Controller::get_snippet_view(),
374 + 'insightsChartViews' => Insights_View_Rest_Controller::get_insights_chart_views(),
375 + 'demosSeen' => Demos_Seen_REST_Controller::get_demos_seen(),
376 + 'restAPI' => [
353 377 'base' => esc_url_raw( rest_url() ),
354 378 'snippets' => esc_url_raw( rest_url( Snippets_REST_Controller::get_base_route() ) ),
355 379 'recentlyActive' => esc_url_raw( rest_url( Recently_Active_REST_Controller::get_base_route() ) ),
356 - 'preferences' => esc_url_raw( rest_url( Preferences_REST_Controller::get_base_route() ) ),
380 + 'snippetView' => esc_url_raw( rest_url( Snippet_View_REST_Controller::get_base_route() ) ),
381 + 'insightsView' => esc_url_raw( rest_url( Insights_View_Rest_Controller::get_base_route() ) ),
382 + 'demosSeen' => esc_url_raw( rest_url( Demos_Seen_REST_Controller::get_base_route() ) ),
357 383 'importPlugins' => esc_url_raw( rest_url( Plugins_Import_REST_Controller::get_base_route() ) ),
358 384 'importFiles' => esc_url_raw( rest_url( File_Import_REST_Controller::get_base_route() ) ),
359 385 'nonce' => wp_create_nonce( 'wp_rest' ),
360 386 'cloud' => [
@@ -361,17 +387,21 @@
361 387 'token' => $this->cloud_connection->get_local_token(),
362 388 'snippets' => esc_url_raw( rest_url( Cloud_Snippets_REST_Controller::get_base_route() ) ),
363 389 ],
364 390 ],
365 - 'urls' => [
366 - 'plugin' => esc_url_raw( plugins_url( '', PLUGIN_FILE ) ),
367 - 'manage' => esc_url_raw( $this->get_menu_url() ),
368 - 'edit' => esc_url_raw( $this->get_menu_url( 'edit' ) ),
369 - 'addNew' => esc_url_raw( $this->get_menu_url( 'add' ) ),
370 - 'welcome' => esc_url_raw( $this->get_menu_url( 'welcome' ) ),
371 - 'import' => esc_url_raw( $this->get_menu_url( 'import' ) ),
372 - 'settings' => esc_url_raw( $this->get_menu_url( 'settings' ) ),
373 - 'cloud' => esc_url_raw( $this->cloud_connection->get_base_url() ),
391 + 'urls' => [
392 + 'plugin' => esc_url_raw( plugins_url( '', PLUGIN_FILE ) ),
393 + 'manage' => esc_url_raw( $this->get_menu_url() ),
394 + 'edit' => esc_url_raw( $this->get_menu_url( 'edit' ) ),
395 + 'addNew' => esc_url_raw( $this->get_menu_url( 'add' ) ),
396 + 'insights' => esc_url_raw( $this->get_menu_url( 'insights' ) ),
397 + 'welcome' => esc_url_raw( $this->get_menu_url( 'welcome' ) ),
398 + 'import' => esc_url_raw( $this->get_menu_url( 'import' ) ),
399 + 'cloud' => esc_url_raw( $this->cloud_connection->get_base_url() ),
400 + 'demoReset' => esc_url_raw( Manage_Menu::get_demo_reset_url() ),
401 + 'settings' => ! are_settings_unified() || is_super_admin()
402 + ? esc_url_raw( $this->get_menu_url( 'settings' ) )
403 + : null,
374 404 ],
375 405 ]
376 406 );
377 407 }