function __construct() { $this->jetpack = Jetpack::init(); self::$block_page_rendering_for_idc = Jetpack::validate_sync_error_idc_option() && !Jetpack_Options::get_option('safe_mode_confirmed'); if (!self::$block_page_rendering_for_idc) { add_action('admin_enqueue_scripts', array($this, 'additional_styles')); } }
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 __construct() { $this->jetpack = Jetpack::init(); self::$block_page_rendering_for_idc = Jetpack::validate_sync_error_idc_option() && !Jetpack_Options::get_option('safe_mode_confirmed'); }
function test_sync_error_idc_validation_returns_false_and_cleans_up_when_opted_out() { Jetpack_Options::update_option('sync_error_idc', Jetpack::get_sync_error_idc_option()); Jetpack_Constants::set_constant('JETPACK_SYNC_IDC_OPTIN', false); $this->assertFalse(Jetpack::validate_sync_error_idc_option()); $this->assertFalse(Jetpack_Options::get_option('sync_error_idc')); }
function test_sync_error_idc_validation_success_when_idc_404() { add_filter('pre_http_request', array($this, '__idc_check_404')); add_filter('jetpack_sync_idc_optin', '__return_true'); Jetpack_Options::update_option('sync_error_idc', Jetpack::get_sync_error_idc_option()); $this->assertTrue(Jetpack::validate_sync_error_idc_option()); $this->assertNotEquals(false, get_transient('jetpack_idc_allowed')); $this->assertEquals('1', get_transient('jetpack_idc_allowed')); // Cleanup remove_filter('pre_http_request', array($this, '__idc_check_404')); remove_filter('jetpack_sync_idc_optin', '__return_true'); delete_transient('jetpack_idc_allowed'); }