PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.2
Jetpack – WP Security, Backup, Speed, & Growth v16.2
16.2 16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 13.9.2 14.0.1 14.1.1 14.2.2 All 502 releases
jetpack / _inc / site-switcher.php

site-switcher.php in Jetpack – WP Security, Backup, Speed, & Growth 16.2, at _inc/site-switcher.php

70 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Site Switcher for Command Palette
4 * Enqueues the site switcher UI and loads the compact sites list endpoint
5 *
6 * @package automattic/jetpack
7 */
8
9 use Automattic\Jetpack\Connection\Manager as Connection_Manager;
10
11 if ( ! defined( 'ABSPATH' ) ) {
12 exit( 0 );
13 }
14
15 // Load the Jetpack endpoint (not needed on WordPress.com simple sites)
16 if ( ! ( defined( 'IS_WPCOM' ) && IS_WPCOM ) ) {
17 require_once __DIR__ . '/site-switcher-endpoint.php';
18 }
19
20 /**
21 * Enqueue site switcher scripts in all wp-admin pages.
22 */
23 function jetpack_site_switcher_enqueue_scripts() {
24 // Only enqueue for users connected to WordPress.com (unless on WPCOM where all users are connected)
25 if ( ! ( defined( 'IS_WPCOM' ) && IS_WPCOM ) ) {
26 $connection_manager = new Connection_Manager();
27 if ( ! $connection_manager->is_user_connected() ) {
28 return;
29 }
30 }
31
32 // Load asset file for dependencies and version
33 $asset_file = JETPACK__PLUGIN_DIR . '_inc/build/site-switcher.min.asset.php';
34 $asset = file_exists( $asset_file ) ? require $asset_file : array(
35 'dependencies' => array( 'wp-api-fetch', 'wp-commands', 'wp-element', 'wp-i18n', 'wp-icons' ),
36 'version' => JETPACK__VERSION,
37 );
38
39 // Register and enqueue site switcher JavaScript
40 wp_enqueue_script(
41 'jetpack-site-switcher',
42 plugins_url( '_inc/build/site-switcher.min.js', JETPACK__PLUGIN_FILE ),
43 $asset['dependencies'],
44 $asset['version'],
45 true
46 );
47
48 // Pass configuration to JavaScript
49 $api_path = ( defined( 'IS_WPCOM' ) && IS_WPCOM )
50 ? '/rest/v1.1/me/sites/compact'
51 : '/jetpack/v4/sites/compact';
52
53 wp_add_inline_script(
54 'jetpack-site-switcher',
55 sprintf(
56 'window.jetpackSiteSwitcherConfig = %s;',
57 wp_json_encode(
58 array(
59 'userId' => get_current_user_id(),
60 'apiPath' => $api_path,
61 ),
62 JSON_HEX_TAG | JSON_HEX_AMP | JSON_UNESCAPED_SLASHES
63 )
64 ),
65 'before'
66 );
67 }
68
69 add_action( 'admin_enqueue_scripts', 'jetpack_site_switcher_enqueue_scripts' );
70