summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/jetpack/_inc/lib/admin-pages/class.jetpack-react-page.php')
-rw-r--r--plugins/jetpack/_inc/lib/admin-pages/class.jetpack-react-page.php79
1 files changed, 44 insertions, 35 deletions
diff --git a/plugins/jetpack/_inc/lib/admin-pages/class.jetpack-react-page.php b/plugins/jetpack/_inc/lib/admin-pages/class.jetpack-react-page.php
index 57a81a19..45f7d1e5 100644
--- a/plugins/jetpack/_inc/lib/admin-pages/class.jetpack-react-page.php
+++ b/plugins/jetpack/_inc/lib/admin-pages/class.jetpack-react-page.php
@@ -9,10 +9,8 @@ class Jetpack_React_Page extends Jetpack_Admin_Page {
protected $is_redirecting = false;
function get_page_hook() {
- $title = _x( 'Jetpack', 'The menu item label', 'jetpack' );
-
// Add the main admin Jetpack menu
- return add_menu_page( 'Jetpack', $title, 'jetpack_admin_page', 'jetpack', array( $this, 'render' ), 'div' );
+ return add_menu_page( 'Jetpack', 'Jetpack', 'jetpack_admin_page', 'jetpack', array( $this, 'render' ), 'div' );
}
function add_page_actions( $hook ) {
@@ -109,7 +107,6 @@ class Jetpack_React_Page extends Jetpack_Admin_Page {
function render_nojs_configurable( $module_name ) {
$module_name = preg_replace( '/[^\da-z\-]+/', '', $_GET['configure'] );
- include_once( JETPACK__PLUGIN_DIR . '_inc/header.php' );
echo '<div class="wrap configure-module">';
if ( Jetpack::is_module( $module_name ) && current_user_can( 'jetpack_configure_modules' ) ) {
@@ -167,41 +164,27 @@ class Jetpack_React_Page extends Jetpack_Admin_Page {
}
function additional_styles() {
- $rtl = is_rtl() ? '.rtl' : '';
-
- wp_enqueue_style( 'dops-css', plugins_url( "_inc/build/admin.dops-style$rtl.css", JETPACK__PLUGIN_FILE ), array(), JETPACK__VERSION );
- wp_enqueue_style( 'components-css', plugins_url( "_inc/build/style.min$rtl.css", JETPACK__PLUGIN_FILE ), array(), JETPACK__VERSION );
+ Jetpack_Admin_Page::load_wrapper_styles();
}
function page_admin_scripts() {
- if ( $this->is_redirecting ) {
+ if ( $this->is_redirecting || isset( $_GET['configure'] ) ) {
return; // No need for scripts on a fallback page
}
- $is_dev_mode = Jetpack::is_development_mode();
-
// Enqueue jp.js and localize it
wp_enqueue_script( 'react-plugin', plugins_url( '_inc/build/admin.js', JETPACK__PLUGIN_FILE ), array(), JETPACK__VERSION, true );
- if ( ! $is_dev_mode && Jetpack::is_active() ) {
+ if ( ! Jetpack::is_development_mode() && Jetpack::is_active() ) {
// Required for Analytics
wp_enqueue_script( 'jp-tracks', '//stats.wp.com/w.js', array(), gmdate( 'YW' ), true );
}
- // Collecting roles that can view site stats.
- $stats_roles = array();
- $enabled_roles = function_exists( 'stats_get_option' ) ? stats_get_option( 'roles' ) : array( 'administrator' );
-
- if ( ! function_exists( 'get_editable_roles' ) ) {
- require_once ABSPATH . 'wp-admin/includes/user.php';
- }
- foreach ( get_editable_roles() as $slug => $role ) {
- $stats_roles[ $slug ] = array(
- 'name' => translate_user_role( $role['name'] ),
- 'canView' => is_array( $enabled_roles ) ? in_array( $slug, $enabled_roles, true ) : false,
- );
- }
+ // Add objects to be passed to the initial state of the app
+ wp_localize_script( 'react-plugin', 'Initial_State', $this->get_initial_state() );
+ }
+ function get_initial_state() {
// Load API endpoint base classes and endpoints for getting the module list fed into the JS Admin Page
require_once JETPACK__PLUGIN_DIR . '_inc/lib/core-api/class.jetpack-core-api-xmlrpc-consumer-endpoint.php';
require_once JETPACK__PLUGIN_DIR . '_inc/lib/core-api/class.jetpack-core-api-module-endpoints.php';
@@ -217,11 +200,19 @@ class Jetpack_React_Page extends Jetpack_Admin_Page {
$modules[ $slug ]['long_description'] = html_entity_decode( $data['long_description'] );
}
- // Get last post, to build the link to Customizer in the Related Posts module.
- $last_post = get_posts( array( 'posts_per_page' => 1 ) );
- $last_post = isset( $last_post[0] ) && $last_post[0] instanceof WP_Post
- ? get_permalink( $last_post[0]->ID )
- : get_home_url();
+ // Collecting roles that can view site stats.
+ $stats_roles = array();
+ $enabled_roles = function_exists( 'stats_get_option' ) ? stats_get_option( 'roles' ) : array( 'administrator' );
+
+ if ( ! function_exists( 'get_editable_roles' ) ) {
+ require_once ABSPATH . 'wp-admin/includes/user.php';
+ }
+ foreach ( get_editable_roles() as $slug => $role ) {
+ $stats_roles[ $slug ] = array(
+ 'name' => translate_user_role( $role['name'] ),
+ 'canView' => is_array( $enabled_roles ) ? in_array( $slug, $enabled_roles, true ) : false,
+ );
+ }
// Get information about current theme.
$current_theme = wp_get_theme();
@@ -234,8 +225,13 @@ class Jetpack_React_Page extends Jetpack_Admin_Page {
}
}
- // Add objects to be passed to the initial state of the app
- wp_localize_script( 'react-plugin', 'Initial_State', array(
+ // Get last post, to build the link to Customizer in the Related Posts module.
+ $last_post = get_posts( array( 'posts_per_page' => 1 ) );
+ $last_post = isset( $last_post[0] ) && $last_post[0] instanceof WP_Post
+ ? get_permalink( $last_post[0]->ID )
+ : get_home_url();
+
+ return array(
'WP_API_root' => esc_url_raw( rest_url() ),
'WP_API_nonce' => wp_create_nonce( 'wp_rest' ),
'pluginBaseUrl' => plugins_url( '', JETPACK__PLUGIN_FILE ),
@@ -243,18 +239,20 @@ class Jetpack_React_Page extends Jetpack_Admin_Page {
'isActive' => Jetpack::is_active(),
'isStaging' => Jetpack::is_staging_site(),
'devMode' => array(
- 'isActive' => $is_dev_mode,
+ 'isActive' => Jetpack::is_development_mode(),
'constant' => defined( 'JETPACK_DEV_DEBUG' ) && JETPACK_DEV_DEBUG,
'url' => site_url() && false === strpos( site_url(), '.' ),
'filter' => apply_filters( 'jetpack_development_mode', false ),
),
'isPublic' => '1' == get_option( 'blog_public' ),
'isInIdentityCrisis' => Jetpack::validate_sync_error_idc_option(),
+ 'sandboxDomain' => JETPACK__SANDBOX_DOMAIN,
),
'connectUrl' => Jetpack::init()->build_connect_url( true, false, false ),
'dismissedNotices' => $this->get_dismissed_jetpack_notices(),
'isDevVersion' => Jetpack::is_development_version(),
'currentVersion' => JETPACK__VERSION,
+ 'is_gutenberg_available' => Jetpack_Gutenberg::is_gutenberg_available(),
'getModules' => $modules,
'showJumpstart' => jetpack_show_jumpstart(),
'rawUrl' => Jetpack::build_raw_urls( get_home_url() ),
@@ -289,6 +287,7 @@ class Jetpack_React_Page extends Jetpack_Admin_Page {
'showPromotions' => apply_filters( 'jetpack_show_promotions', true ),
'isAtomicSite' => jetpack_is_atomic_site(),
'plan' => Jetpack::get_active_plan(),
+ 'showBackups' => Jetpack::show_backups_ui(),
),
'themeData' => array(
'name' => $current_theme->get( 'Name' ),
@@ -298,7 +297,7 @@ class Jetpack_React_Page extends Jetpack_Admin_Page {
),
),
'locale' => Jetpack::get_i18n_data_json(),
- 'localeSlug' => join( '-', explode( '_', jetpack_get_user_locale() ) ),
+ 'localeSlug' => join( '-', explode( '_', get_user_locale() ) ),
'jetpackStateNotices' => array(
'messageCode' => Jetpack::state( 'message' ),
'errorCode' => Jetpack::state( 'error' ),
@@ -307,7 +306,17 @@ class Jetpack_React_Page extends Jetpack_Admin_Page {
'tracksUserData' => Jetpack_Tracks_Client::get_connected_user_tracks_identity(),
'currentIp' => function_exists( 'jetpack_protect_get_ip' ) ? jetpack_protect_get_ip() : false,
'lastPostUrl' => esc_url( $last_post ),
- ) );
+ 'externalServicesConnectUrls' => $this->get_external_services_connect_urls()
+ );
+ }
+
+ function get_external_services_connect_urls() {
+ $connect_urls = array();
+ jetpack_require_lib( 'class.jetpack-keyring-service-helper' );
+ foreach ( Jetpack_Keyring_Service_Helper::$SERVICES as $service_name => $service_info ) {
+ $connect_urls[ $service_name ] = Jetpack_Keyring_Service_Helper::connect_url( $service_name, $service_info[ 'for' ] );
+ }
+ return $connect_urls;
}
/**