function page_admin_scripts() { if ($this->is_redirecting) { 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) { // Required for Analytics wp_enqueue_script('jp-tracks', '//stats.wp.com/w.js', array(), gmdate('YW'), true); } $localeSlug = explode('_', get_locale()); $localeSlug = $localeSlug[0]; // Collecting roles that can view site stats $stats_roles = array(); $enabled_roles = function_exists('stats_get_option') ? stats_get_option('roles') : array('administrator'); 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); } $response = rest_do_request(new WP_REST_Request('GET', '/jetpack/v4/module/all')); $modules = $response->get_data(); // Preparing translated fields for JSON encoding by transforming all HTML entities to // respective characters. foreach ($modules as $slug => $data) { $modules[$slug]['name'] = html_entity_decode($data['name']); $modules[$slug]['description'] = html_entity_decode($data['description']); $modules[$slug]['short_description'] = html_entity_decode($data['short_description']); $modules[$slug]['long_description'] = html_entity_decode($data['long_description']); } // Add objects to be passed to the initial state of the app wp_localize_script('react-plugin', 'Initial_State', array('WP_API_root' => esc_url_raw(rest_url()), 'WP_API_nonce' => wp_create_nonce('wp_rest'), 'pluginBaseUrl' => plugins_url('', JETPACK__PLUGIN_FILE), 'connectionStatus' => array('isActive' => Jetpack::is_active(), 'isStaging' => Jetpack::is_staging_site(), 'devMode' => array('isActive' => $is_dev_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()), 'dismissedNotices' => $this->get_dismissed_jetpack_notices(), 'isDevVersion' => Jetpack::is_development_version(), 'currentVersion' => JETPACK__VERSION, 'happinessGravIds' => jetpack_get_happiness_gravatar_ids(), 'getModules' => $modules, 'showJumpstart' => jetpack_show_jumpstart(), 'rawUrl' => Jetpack::build_raw_urls(get_home_url()), 'adminUrl' => esc_url(admin_url()), 'stats' => array('data' => array('general' => false, 'day' => false, 'week' => false, 'month' => false), 'roles' => $stats_roles), 'settingNames' => array('jetpack_holiday_snow_enabled' => function_exists('jetpack_holiday_snow_option_name') ? jetpack_holiday_snow_option_name() : false), 'userData' => array('currentUser' => jetpack_current_user_data()), 'locale' => $this->get_i18n_data(), 'localeSlug' => $localeSlug, 'jetpackStateNotices' => array('messageCode' => Jetpack::state('message'), 'errorCode' => Jetpack::state('error'), 'errorDescription' => Jetpack::state('error_description')), 'tracksUserData' => Jetpack_Tracks_Client::get_connected_user_tracks_identity(), 'currentIp' => function_exists('jetpack_protect_get_ip') ? jetpack_protect_get_ip() : false)); }
function page_admin_scripts() { // Enqueue jp.js and localize it wp_enqueue_script('react-plugin', plugins_url('_inc/build/admin.js', JETPACK__PLUGIN_FILE), array(), time(), true); wp_enqueue_style('dops-css', plugins_url('_inc/build/dops-style.css', JETPACK__PLUGIN_FILE), array(), time()); wp_enqueue_style('components-css', plugins_url('_inc/build/style.min.css', JETPACK__PLUGIN_FILE), array(), time()); $localeSlug = explode('_', get_locale()); $localeSlug = $localeSlug[0]; // Add objects to be passed to the initial state of the app wp_localize_script('react-plugin', 'Initial_State', array('WP_API_root' => esc_url_raw(rest_url()), 'WP_API_nonce' => wp_create_nonce('wp_rest'), 'pluginBaseUrl' => plugins_url('', JETPACK__PLUGIN_FILE), 'connectionStatus' => array('isActive' => Jetpack::is_active(), 'isStaging' => Jetpack::is_staging_site(), 'devMode' => array('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))), 'dismissedNotices' => $this->get_dismissed_jetpack_notices(), 'isDevVersion' => Jetpack::is_development_version(), 'currentVersion' => JETPACK__VERSION, 'happinessGravIds' => jetpack_get_happiness_gravatar_ids(), 'getModules' => Jetpack_Core_Json_Api_Endpoints::get_modules(), 'showJumpstart' => jetpack_show_jumpstart(), 'rawUrl' => Jetpack::build_raw_urls(get_home_url()), 'adminUrl' => esc_url(admin_url()), 'statsData' => build_initial_stats_shape(), 'settingNames' => array('jetpack_holiday_snow_enabled' => function_exists('jetpack_holiday_snow_option_name') ? jetpack_holiday_snow_option_name() : false), 'userData' => array('othersLinked' => jetpack_get_other_linked_users(), 'currentUser' => jetpack_current_user_data()), 'locale' => $this->get_i18n_data(), 'localeSlug' => $localeSlug, 'jetpackStateNotices' => array('messageCode' => Jetpack::state('message'), 'errorCode' => Jetpack::state('error'), 'errorDescription' => Jetpack::state('error_description')))); }