state() public static method

SET: state( $key, $value ); GET: $value = state( $key );
public static state ( string $key = null, string $value = null, boolean $restate = false )
$key string
$value string
$restate boolean private
Ejemplo n.º 1
0
function jetpack_json_api_configuration_load()
{
    if (isset($_POST['action']) && $_POST['action'] == 'save_options' && wp_verify_nonce($_POST['_wpnonce'], 'json-api')) {
        Jetpack_Options::update_option('json_api_full_management', isset($_POST['json_api_full_management']));
        Jetpack::state('message', 'module_configured');
        wp_safe_redirect(Jetpack::module_configuration_url('json-api'));
        exit;
    }
}
 /**
  * @author scotchfield
  * @runInSeparateProcess
  * @covers Jetpack_Client_Server::authorize
  * @since 3.2
  */
 public function test_jetpack_client_server_authorize_data_error()
 {
     $author_id = $this->factory->user->create(array('role' => 'administrator'));
     wp_set_current_user($author_id);
     $client_server = $this->getMock('Jetpack_Client_Server', array('check_admin_referer', 'wp_safe_redirect', 'do_exit'));
     $data_error = 'test_error';
     $_GET['error'] = $data_error;
     $client_server->authorize();
     $this->assertEquals($data_error, Jetpack::state('error'));
 }
Ejemplo n.º 3
0
function minileven_configuration_load()
{
    if (isset($_POST['action']) && $_POST['action'] == 'save_options' && $_POST['_wpnonce'] == wp_create_nonce('minileven')) {
        if (isset($_POST['wp_mobile_excerpt'])) {
            update_option('wp_mobile_excerpt', '1' == $_POST['wp_mobile_excerpt'] ? '1' : '0');
        }
        update_option('wp_mobile_app_promos', isset($_POST['wp_mobile_app_promos']) ? '1' : '0');
        Jetpack::state('message', 'module_configured');
        wp_safe_redirect(Jetpack::module_configuration_url('minileven'));
        exit;
    }
}
Ejemplo n.º 4
0
 public function jetpack_configuration_load()
 {
     if (Jetpack::is_user_connected() && !self::is_active()) {
         Jetpack::deactivate_module($this->module);
         Jetpack::state('message', 'module_deactivated');
         wp_safe_redirect(Jetpack::admin_url('page=jetpack'));
         die;
     }
     if (!empty($_POST['action']) && $_POST['action'] == 'monitor-save') {
         check_admin_referer('monitor-settings');
         $this->update_option_receive_jetpack_monitor_notification(isset($_POST['receive_jetpack_monitor_notification']));
         Jetpack::state('message', 'module_configured');
         wp_safe_redirect(Jetpack::module_configuration_url($this->module));
     }
 }
Ejemplo n.º 5
0
/**
 * Module Name: Monitor
 * Module Description: Jetpack Monitor will keep tabs on your site, and alert you the moment that downtime is detected.
 * Sort Order: 55
 * First Introduced: 2.6
 * Requires Connection: Yes
 * Auto Activate: No
 */
function jetpack_monitor_toggle()
{
    $jetpack = Jetpack::init();
    if (!$jetpack->current_user_is_connection_owner()) {
        Jetpack::state('module', 'monitor');
        Jetpack::state('error', 'master_user_required');
        // Technically this call to `wp_safe_redirect` is not required because
        // `Jetpack::activate_module` already sets up a redirect. However, this
        // might not stay the case forever so it's clearer to do it here as well.
        wp_safe_redirect(Jetpack::admin_url('page=jetpack'));
        die;
    }
    $jetpack->sync->register('noop');
    if (false !== strpos(current_filter(), 'jetpack_activate_module_')) {
        Jetpack::check_privacy(__FILE__);
    }
}
 /**
  * Authorizations
  */
 function client_authorize()
 {
     $data = stripslashes_deep($_GET);
     $data['auth_type'] = 'client';
     $jetpack = $this->get_jetpack();
     $role = $jetpack->translate_current_user_to_role();
     $redirect = isset($data['redirect']) ? esc_url_raw((string) $data['redirect']) : '';
     $this->check_admin_referer("jetpack-authorize_{$role}_{$redirect}");
     $result = $this->authorize($data);
     if (is_wp_error($result)) {
         Jetpack::state('error', $result->get_error_code());
     }
     if (wp_validate_redirect($redirect)) {
         $this->wp_safe_redirect($redirect);
     } else {
         $this->wp_safe_redirect(Jetpack::admin_url());
     }
     $this->do_exit();
 }
 /**
  * Will initialize hooks to display the new and legacy connection banners if the current user can
  * connect Jetpack, if Jetpack has not been deactivated, and if the current page is the plugins page.
  *
  * This method should not be called if the site is connected to WordPress.com or if the site is in development mode.
  *
  * @since 4.4.0
  *
  * @param $current_screen
  */
 function maybe_initialize_hooks($current_screen)
 {
     // Don't show the connect notice anywhere but the plugins.php after activating
     if ('plugins' !== $current_screen->base) {
         return;
     }
     if (!current_user_can('jetpack_connect')) {
         return;
     }
     if (self::check_ab_test_not_expired() && 2 == self::get_random_connection_banner_value()) {
         add_action('admin_notices', array($this, 'render_banner'));
         add_action('admin_enqueue_scripts', array($this, 'enqueue_banner_scripts'));
     } else {
         add_action('admin_notices', array($this, 'render_legacy_banner'));
     }
     add_action('admin_print_styles', array(Jetpack::init(), 'admin_banner_styles'));
     if (Jetpack::state('network_nag')) {
         add_action('network_admin_notices', array($this, 'network_connect_notice'));
     }
 }
 function jetpack_my_jetpack_change_user()
 {
     if (!isset($_POST['_my_jetpack_nonce']) || !wp_verify_nonce($_POST['_my_jetpack_nonce'], 'jetpack_change_primary_user')) {
         wp_die(__('Failed permissions, please try again.', 'jetpack'));
         exit;
     }
     if (isset($_POST['jetpack-new-master'])) {
         $old_master_user = Jetpack_Options::get_option('master_user');
         $new_master_user = $_POST['jetpack-new-master'];
         $user_token = Jetpack_Data::get_access_token($new_master_user);
         $is_user_connected = $user_token && !is_wp_error($user_token);
         if (current_user_can('manage_options') && $is_user_connected) {
             Jetpack::log('switch_master_user', array('old_master' => $old_master_user, 'new_master' => $new_master_user));
             Jetpack_Options::update_option('master_user', $new_master_user);
             Jetpack::state('message', 'switch_master');
             //My Jetpack primary user successfully changed, send to MC Stats
             Jetpack::init()->stat('admin', 'change-primary-successful');
             Jetpack::init()->do_stats('server_side');
             // Change the blog owner dotcom side
             $this->wpcom_switch_blog_owner($new_master_user);
         }
     }
 }
Ejemplo n.º 9
0
function stats_print_wp_remote_error($get, $url)
{
    $state_name = 'stats_remote_error_' . substr(md5($url), 0, 8);
    $previous_error = Jetpack::state($state_name);
    $error = md5(serialize(compact('get', 'url')));
    Jetpack::state($state_name, $error);
    if ($error !== $previous_error) {
        ?>
	<div class="wrap">
	<p><?php 
        _e('We were unable to get your stats just now. Please reload this page to try again.', 'jetpack');
        ?>
</p>
	</div>
<?php 
        return;
    }
    ?>
	<div class="wrap">
	<p><?php 
    printf(__('We were unable to get your stats just now. Please reload this page to try again. If this error persists, please <a href="%1$s" target="_blank">contact support</a>. In your report please include the information below.', 'jetpack'), 'http://support.wordpress.com/contact/?jetpack=needs-service');
    ?>
</p>
	<pre>
	User Agent: "<?php 
    echo esc_html($_SERVER['HTTP_USER_AGENT']);
    ?>
"
	Page URL: "http<?php 
    echo (is_ssl() ? 's' : '') . '://' . esc_html($_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
    ?>
"
	API URL: "<?php 
    echo esc_url($url);
    ?>
"
<?php 
    if (is_wp_error($get)) {
        foreach ($get->get_error_codes() as $code) {
            foreach ($get->get_error_messages($code) as $message) {
                ?>
	<?php 
                print $code . ': "' . $message . '"';
                ?>

<?php 
            }
        }
    } else {
        $get_code = wp_remote_retrieve_response_code($get);
        $content_length = strlen(wp_remote_retrieve_body($get));
        ?>
	Response code: "<?php 
        print $get_code;
        ?>
"
	Content length: "<?php 
        print $content_length;
        ?>
"

<?php 
    }
    ?>
</pre>
	</div>
	<?php 
}
 static function deactivate_jetpack_modules()
 {
     check_ajax_referer(self::AJAX_NONCE, 'nonce');
     // shamelessly copied from class.jetpack.php
     $modules = $_REQUEST['modules'];
     $modules = array_map('sanitize_key', $modules);
     // $modules_filtered = Jetpack::init()->filter_default_modules( $modules );
     foreach ($modules as $module_slug) {
         Jetpack::log('deactivate', $module_slug);
         Jetpack::deactivate_module($module_slug);
         Jetpack::state('message', 'module_deactivated');
     }
     wp_send_json_success($modules);
 }
Ejemplo n.º 11
0
 /**
  * Runs before the VideoPress Configuration screen loads, useful
  * to update options and yield errors.
  */
 function jetpack_configuration_load()
 {
     $this->enqueue_admin_scripts();
     /**
      * Save configuration
      */
     if (!empty($_POST['action']) && $_POST['action'] == 'videopress-save') {
         check_admin_referer('videopress-settings');
         $options = $this->get_options();
         if (isset($_POST['blog_id']) && in_array($_POST['blog_id'], wp_list_pluck($options['blogs'], 'blog_id'))) {
             $options['blog_id'] = $_POST['blog_id'];
         }
         // Allow the None setting too.
         if (isset($_POST['blog_id']) && $_POST['blog_id'] == 0) {
             $options['blog_id'] = 0;
         }
         /**
          * @see $this->can()
          */
         if (isset($_POST['videopress-access']) && in_array($_POST['videopress-access'], array('', 'read', 'edit', 'delete'))) {
             $options['access'] = $_POST['videopress-access'];
         }
         $options['freedom'] = isset($_POST['videopress-freedom']);
         $options['hd'] = isset($_POST['videopress-hd']);
         // Allow upload only if some level of access has been granted, and uploads were allowed.
         $options['allow-upload'] = false;
         if (!empty($options['access']) && isset($_POST['videopress-upload'])) {
             $options['allow-upload'] = true;
         }
         $this->update_options($options);
         Jetpack::state('message', 'module_configured');
         wp_safe_redirect(Jetpack::module_configuration_url($this->module));
     }
     /**
      * Refresh the list of available WordPress.com blogs
      */
     if (!empty($_GET['videopress']) && $_GET['videopress'] == 'refresh-blogs') {
         check_admin_referer('videopress-settings');
         $options = $this->get_options();
         $result = $this->query('jetpack.vpGetBlogs');
         if (!is_wp_error($result)) {
             $options['blogs'] = $result;
             $this->update_options($options);
         }
         wp_safe_redirect(Jetpack::module_configuration_url($this->module));
     }
 }
Ejemplo n.º 12
0
 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));
 }
Ejemplo n.º 13
0
 /**
  * Provides functionality for the Jetpack > Sites page.
  * Does not do the display!
  *
  * @since 2.9
  */
 public function jetpack_sites_list()
 {
     Jetpack::init();
     if (isset($_GET['action'])) {
         switch ($_GET['action']) {
             case 'subsiteregister':
                 /*
                  * @todo check_admin_referer( 'jetpack-subsite-register' );
                  */
                 Jetpack::log('subsiteregister');
                 // If !$_GET['site_id'] stop registration and error
                 if (!isset($_GET['site_id']) || empty($_GET['site_id'])) {
                     // Log error to state cookie for display later
                     /**
                      * @todo Make state messages show on Jetpack NA pages
                      **/
                     Jetpack::state('missing_site_id', 'Site ID must be provided to register a sub-site');
                     break;
                 }
                 // Send data to register endpoint and retrieve shadow blog details
                 $result = $this->do_subsiteregister();
                 $url = $this->get_url('network_admin_page');
                 if (is_wp_error($result)) {
                     $url = add_query_arg('action', 'connection_failed', $url);
                 } else {
                     $url = add_query_arg('action', 'connected', $url);
                 }
                 wp_safe_redirect($url);
                 break;
             case 'subsitedisconnect':
                 Jetpack::log('subsitedisconnect');
                 if (!isset($_GET['site_id']) || empty($_GET['site_id'])) {
                     Jetpack::state('missing_site_id', 'Site ID must be provided to disconnect a sub-site');
                     break;
                 }
                 $this->do_subsitedisconnect();
                 break;
             case 'connected':
             case 'connection_failed':
                 add_action('jetpack_notices', array($this, 'show_jetpack_notice'));
                 break;
         }
     }
 }
 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'))));
 }
 function handle_unrecognized_action($action)
 {
     switch ($action) {
         case 'bulk-activate':
             if (!current_user_can('jetpack_activate_modules')) {
                 break;
             }
             $modules = (array) $_GET['modules'];
             $modules = array_map('sanitize_key', $modules);
             check_admin_referer('bulk-jetpack_page_jetpack_modules');
             foreach ($modules as $module) {
                 Jetpack::log('activate', $module);
                 Jetpack::activate_module($module, false);
             }
             // The following two lines will rarely happen, as Jetpack::activate_module normally exits at the end.
             wp_safe_redirect(wp_get_referer());
             exit;
         case 'bulk-deactivate':
             if (!current_user_can('jetpack_deactivate_modules')) {
                 break;
             }
             $modules = (array) $_GET['modules'];
             $modules = array_map('sanitize_key', $modules);
             check_admin_referer('bulk-jetpack_page_jetpack_modules');
             foreach ($modules as $module) {
                 Jetpack::log('deactivate', $module);
                 Jetpack::deactivate_module($module);
                 Jetpack::state('message', 'module_deactivated');
             }
             Jetpack::state('module', $modules);
             wp_safe_redirect(wp_get_referer());
             exit;
         default:
             return;
     }
 }
Ejemplo n.º 16
0
 function authorize()
 {
     $data = stripslashes_deep($_GET);
     $args = array();
     $redirect = isset($data['redirect']) ? esc_url_raw((string) $data['redirect']) : '';
     do {
         $jetpack = Jetpack::init();
         $role = $jetpack->translate_current_user_to_role();
         if (!$role) {
             Jetpack::state('error', 'no_role');
             break;
         }
         $cap = $jetpack->translate_role_to_cap($role);
         if (!$cap) {
             Jetpack::state('error', 'no_cap');
             break;
         }
         check_admin_referer("jetpack-authorize_{$role}_{$redirect}");
         if (!empty($data['error'])) {
             Jetpack::state('error', $data['error']);
             break;
         }
         if (empty($data['state'])) {
             Jetpack::state('error', 'no_state');
             break;
         }
         if (!ctype_digit($data['state'])) {
             Jetpack::state('error', 'invalid_state');
             break;
         }
         $current_user_id = get_current_user_id();
         if ($current_user_id != $data['state']) {
             Jetpack::state('error', 'wrong_state');
             break;
         }
         if (empty($data['code'])) {
             Jetpack::state('error', 'no_code');
             break;
         }
         $token = $this->get_token($data);
         if (is_wp_error($token)) {
             if ($error = $token->get_error_code()) {
                 Jetpack::state('error', $error);
             } else {
                 Jetpack::state('error', 'invalid_token');
             }
             Jetpack::state('error_description', $token->get_error_message());
             break;
         }
         if (!$token) {
             Jetpack::state('error', 'no_token');
             break;
         }
         $is_master_user = !Jetpack::is_active();
         Jetpack::update_user_token($current_user_id, sprintf('%s.%d', $token, $current_user_id), $is_master_user);
         if ($is_master_user) {
             Jetpack::state('message', 'authorized');
         } else {
             Jetpack::state('message', 'linked');
             // Don't activate anything since we are just connecting a user.
             break;
         }
         if ($active_modules = Jetpack::get_option('active_modules')) {
             Jetpack::delete_option('active_modules');
             Jetpack::activate_default_modules(999, 1, $active_modules);
         } else {
             Jetpack::activate_default_modules();
         }
         $jetpack->sync->register('noop');
         // Spawn a sync to make sure the Jetpack Servers know what modules are active.
         // Start nonce cleaner
         wp_clear_scheduled_hook('jetpack_clean_nonces');
         wp_schedule_event(time(), 'hourly', 'jetpack_clean_nonces');
     } while (false);
     if (wp_validate_redirect($redirect)) {
         wp_safe_redirect($redirect);
     } else {
         wp_safe_redirect(Jetpack::admin_url());
     }
     exit;
 }
 /**
  * Activates a series of valid Jetpack modules and initializes some options.
  *
  * @since 4.1.0
  *
  * @param WP_REST_Request $data {
  *     Array of parameters received by request.
  * }
  *
  * @return bool|WP_Error True if Jumpstart succeeded. Otherwise, a WP_Error instance with the corresponding error.
  */
 public static function jumpstart_activate($data)
 {
     $modules = Jetpack::get_available_modules();
     $activate_modules = array();
     foreach ($modules as $module) {
         $module_info = Jetpack::get_module($module);
         if (isset($module_info['feature']) && is_array($module_info['feature']) && in_array('Jumpstart', $module_info['feature'])) {
             $activate_modules[] = $module;
         }
     }
     // Collect success/error messages like modules that are properly activated.
     $result = array('activated_modules' => array(), 'failed_modules' => array());
     // Update the jumpstart option
     if ('new_connection' === Jetpack_Options::get_option('jumpstart')) {
         $result['jumpstart_activated'] = Jetpack_Options::update_option('jumpstart', 'jumpstart_activated');
     }
     // Check for possible conflicting plugins
     $module_slugs_filtered = Jetpack::init()->filter_default_modules($activate_modules);
     foreach ($module_slugs_filtered as $module_slug) {
         Jetpack::log('activate', $module_slug);
         if (Jetpack::activate_module($module_slug, false, false)) {
             $result['activated_modules'][] = $module_slug;
         } else {
             $result['failed_modules'][] = $module_slug;
         }
         Jetpack::state('message', 'no_message');
     }
     // Set the default sharing buttons and set to display on posts if none have been set.
     $sharing_services = get_option('sharing-services');
     $sharing_options = get_option('sharing-options');
     if (empty($sharing_services['visible'])) {
         // Default buttons to set
         $visible = array('twitter', 'facebook', 'google-plus-1');
         $hidden = array();
         // Set some sharing settings
         $sharing = new Sharing_Service();
         $sharing_options['global'] = array('button_style' => 'icon', 'sharing_label' => $sharing->default_sharing_label, 'open_links' => 'same', 'show' => array('post'), 'custom' => isset($sharing_options['global']['custom']) ? $sharing_options['global']['custom'] : array());
         $result['sharing_options'] = update_option('sharing-options', $sharing_options);
         $result['sharing_services'] = update_option('sharing-services', array('visible' => $visible, 'hidden' => $hidden));
     }
     // If all Jumpstart modules were activated
     if (empty($result['failed_modules'])) {
         return rest_ensure_response(array('code' => 'success', 'message' => esc_html__('Jumpstart done.', 'jetpack'), 'data' => $result));
     }
     return new WP_Error('jumpstart_failed', esc_html(sprintf(_n('Jumpstart failed activating this module: %s.', 'Jumpstart failed activating these modules: %s.', count($result['failed_modules']), 'jetpack'), join(', ', $result['failed_modules']))), array('status' => 400));
 }
Ejemplo n.º 18
0
 function authorize()
 {
     $data = stripslashes_deep($_GET);
     $args = array();
     do {
         $jetpack = Jetpack::init();
         $role = $jetpack->translate_current_user_to_role();
         if (!$role) {
             Jetpack::state('error', 'no_role');
             break;
         }
         $cap = $jetpack->translate_role_to_cap($role);
         if (!$cap) {
             Jetpack::state('error', 'no_cap');
             break;
         }
         check_admin_referer("jetpack-authorize_{$role}");
         if (!empty($data['error'])) {
             Jetpack::state('error', $data['error']);
             break;
         }
         if (empty($data['state'])) {
             Jetpack::state('error', 'no_state');
             break;
         }
         if (!ctype_digit($data['state'])) {
             Jetpack::state('error', 'invalid_state');
             break;
         }
         $current_user_id = get_current_user_id();
         if ($current_user_id != $data['state']) {
             Jetpack::state('error', 'wrong_state');
             break;
         }
         if (empty($data['code'])) {
             Jetpack::state('error', 'no_code');
             break;
         }
         $token = $this->get_token($data);
         if (is_wp_error($token)) {
             if ($error = $token->get_error_code()) {
                 Jetpack::state('error', $error);
             } else {
                 Jetpack::state('error', 'invalid_token');
             }
             Jetpack::state('error_description', $token->get_error_message());
             break;
         }
         if (!$token) {
             Jetpack::state('error', 'no_token');
             break;
         }
         update_option('jetpack_user_token', sprintf('%s.%d', $token, $current_user_id), true);
         Jetpack::state('message', 'authorized');
         // Now look for standalone plugins and disable if active.
         $deactivated = array();
         foreach ($jetpack->plugins_to_deactivate as $probable_file => $probable_title) {
             if ($this->deactivate_plugin($probable_file, $probable_title)) {
                 $deactivated[] = $probable_file;
             }
         }
         if ($deactivated) {
             Jetpack::state('deactivated_plugins', join(',', $deactivated));
             $url = add_query_arg(array('action' => 'activate_default_modules', '_wpnonce' => wp_create_nonce('activate_default_modules')), Jetpack::admin_url());
             wp_safe_redirect($url);
             exit;
         }
         Jetpack::activate_default_modules();
         // Start nonce cleaner
         wp_clear_scheduled_hook('jetpack_clean_nonces');
         wp_schedule_event(time(), 'hourly', 'jetpack_clean_nonces');
     } while (false);
     wp_redirect(Jetpack::admin_url());
     exit;
 }
Ejemplo n.º 19
0
 function authorize()
 {
     $data = stripslashes_deep($_GET);
     $args = array();
     do {
         $jetpack = Jetpack::init();
         $role = $jetpack->translate_current_user_to_role();
         if (!$role) {
             Jetpack::state('error', 'no_role');
             break;
         }
         $cap = $jetpack->translate_role_to_cap($role);
         if (!$cap) {
             Jetpack::state('error', 'no_cap');
             break;
         }
         check_admin_referer("jetpack-authorize_{$role}");
         if (!empty($data['error'])) {
             Jetpack::state('error', $data['error']);
             break;
         }
         if (empty($data['state'])) {
             Jetpack::state('error', 'no_state');
             break;
         }
         if (!ctype_digit($data['state'])) {
             Jetpack::state('error', 'invalid_state');
             break;
         }
         $current_user_id = get_current_user_id();
         if ($current_user_id != $data['state']) {
             Jetpack::state('error', 'wrong_state');
             break;
         }
         if (empty($data['code'])) {
             Jetpack::state('error', 'no_code');
             break;
         }
         $token = $this->get_token($data);
         if (is_wp_error($token)) {
             if ($error = $token->get_error_code()) {
                 Jetpack::state('error', $error);
             } else {
                 Jetpack::state('error', 'invalid_token');
             }
             Jetpack::state('error_description', $token->get_error_message());
             break;
         }
         if (!$token) {
             Jetpack::state('error', 'no_token');
             break;
         }
         Jetpack::update_option('user_token', sprintf('%s.%d', $token, $current_user_id), true);
         Jetpack::state('message', 'authorized');
         if ($active_modules = Jetpack::get_option('active_modules')) {
             Jetpack::delete_option('active_modules');
             Jetpack::activate_default_modules(999, 1, $active_modules);
         } else {
             Jetpack::activate_default_modules();
         }
         // Start nonce cleaner
         wp_clear_scheduled_hook('jetpack_clean_nonces');
         wp_schedule_event(time(), 'hourly', 'jetpack_clean_nonces');
     } while (false);
     wp_safe_redirect(Jetpack::admin_url());
     exit;
 }
 function authorize($data = array())
 {
     $redirect = isset($data['redirect']) ? esc_url_raw((string) $data['redirect']) : '';
     $jetpack_unique_connection = Jetpack_Options::get_option('unique_connection');
     // Checking if site has been active/connected previously before recording unique connection
     if (!$jetpack_unique_connection) {
         // jetpack_unique_connection option has never been set
         $jetpack_unique_connection = array('connected' => 0, 'disconnected' => 0, 'version' => '3.6.1');
         update_option('jetpack_unique_connection', $jetpack_unique_connection);
         //track unique connection
         $jetpack = $this->get_jetpack();
         $jetpack->stat('connections', 'unique-connection');
         $jetpack->do_stats('server_side');
     }
     // increment number of times connected
     $jetpack_unique_connection['connected'] += 1;
     Jetpack_Options::update_option('unique_connection', $jetpack_unique_connection);
     $role = Jetpack::translate_current_user_to_role();
     if (!$role) {
         return new Jetpack_Error('no_role', 'Invalid request.', 400);
     }
     $cap = Jetpack::translate_role_to_cap($role);
     if (!$cap) {
         return new Jetpack_Error('no_cap', 'Invalid request.', 400);
     }
     if (!empty($data['error'])) {
         return new Jetpack_Error($data['error'], 'Error included in the request.', 400);
     }
     if (!isset($data['state'])) {
         return new Jetpack_Error('no_state', 'Request must include state.', 400);
     }
     if (!ctype_digit($data['state'])) {
         return new Jetpack_Error($data['error'], 'State must be an integer.', 400);
     }
     $current_user_id = get_current_user_id();
     if ($current_user_id != $data['state']) {
         return new Jetpack_Error('wrong_state', 'State does not match current user.', 400);
     }
     if (empty($data['code'])) {
         return new Jetpack_Error('no_code', 'Request must include an authorization code.', 400);
     }
     $token = $this->get_token($data);
     if (is_wp_error($token)) {
         $code = $token->get_error_code();
         if (empty($code)) {
             $code = 'invalid_token';
         }
         return new Jetpack_Error($code, $token->get_error_message(), 400);
     }
     if (!$token) {
         return new Jetpack_Error('no_token', 'Error generating token.', 400);
     }
     $is_master_user = !Jetpack::is_active();
     Jetpack::update_user_token($current_user_id, sprintf('%s.%d', $token, $current_user_id), $is_master_user);
     if (!$is_master_user) {
         Jetpack::state('message', 'linked');
         // Don't activate anything since we are just connecting a user.
         return 'linked';
     }
     $redirect_on_activation_error = 'client' === $data['auth_type'] ? true : false;
     if ($active_modules = Jetpack_Options::get_option('active_modules')) {
         Jetpack::delete_active_modules();
         Jetpack::activate_default_modules(999, 1, $active_modules, $redirect_on_activation_error);
     } else {
         Jetpack::activate_default_modules(false, false, array(), $redirect_on_activation_error);
     }
     // Start nonce cleaner
     wp_clear_scheduled_hook('jetpack_clean_nonces');
     wp_schedule_event(time(), 'hourly', 'jetpack_clean_nonces');
     Jetpack::state('message', 'authorized');
     return 'authorized';
 }
Ejemplo n.º 21
0
 function authorize()
 {
     $data = stripslashes_deep($_GET);
     $args = array();
     $redirect = isset($data['redirect']) ? esc_url_raw((string) $data['redirect']) : '';
     $jetpack_unique_connection = Jetpack_Options::get_option('unique_connection');
     // Checking if site has been active/connected previously before recording unique connection
     if (!$jetpack_unique_connection) {
         // jetpack_unique_connection option has never been set
         $jetpack_unique_connection = array('connected' => 0, 'disconnected' => 0);
         update_option('jetpack_unique_connection', $jetpack_unique_connection);
         //track unique connection
         $jetpack = Jetpack::init();
         $jetpack->stat('connections', 'unique-connection');
         $jetpack->do_stats('server_side');
     }
     // increment number of times connected
     $jetpack_unique_connection['connected'] += 1;
     Jetpack_Options::update_option('unique_connection', $jetpack_unique_connection);
     do {
         $jetpack = $this->get_jetpack();
         $role = $jetpack->translate_current_user_to_role();
         if (!$role) {
             Jetpack::state('error', 'no_role');
             break;
         }
         $cap = $jetpack->translate_role_to_cap($role);
         if (!$cap) {
             Jetpack::state('error', 'no_cap');
             break;
         }
         $this->check_admin_referer("jetpack-authorize_{$role}_{$redirect}");
         if (!empty($data['error'])) {
             Jetpack::state('error', $data['error']);
             break;
         }
         if (empty($data['state'])) {
             Jetpack::state('error', 'no_state');
             break;
         }
         if (!ctype_digit($data['state'])) {
             Jetpack::state('error', 'invalid_state');
             break;
         }
         $current_user_id = get_current_user_id();
         if ($current_user_id != $data['state']) {
             Jetpack::state('error', 'wrong_state');
             break;
         }
         if (empty($data['code'])) {
             Jetpack::state('error', 'no_code');
             break;
         }
         $token = $this->get_token($data);
         if (is_wp_error($token)) {
             if ($error = $token->get_error_code()) {
                 Jetpack::state('error', $error);
             } else {
                 Jetpack::state('error', 'invalid_token');
             }
             Jetpack::state('error_description', $token->get_error_message());
             break;
         }
         if (!$token) {
             Jetpack::state('error', 'no_token');
             break;
         }
         $is_master_user = !Jetpack::is_active();
         Jetpack::update_user_token($current_user_id, sprintf('%s.%d', $token, $current_user_id), $is_master_user);
         if ($is_master_user) {
             Jetpack::state('message', 'authorized');
         } else {
             Jetpack::state('message', 'linked');
             // Don't activate anything since we are just connecting a user.
             break;
         }
         if ($active_modules = Jetpack_Options::get_option('active_modules')) {
             Jetpack_Options::delete_option('active_modules');
             Jetpack::activate_default_modules(999, 1, $active_modules);
         } else {
             Jetpack::activate_default_modules();
         }
         // Sync all registers options and constants
         do_action('jetpack_sync_all_registered_options');
         // Start nonce cleaner
         wp_clear_scheduled_hook('jetpack_clean_nonces');
         wp_schedule_event(time(), 'hourly', 'jetpack_clean_nonces');
     } while (false);
     if (wp_validate_redirect($redirect)) {
         $this->wp_safe_redirect($redirect);
     } else {
         $this->wp_safe_redirect(Jetpack::admin_url());
     }
     $this->do_exit();
 }
Ejemplo n.º 22
0
function stats_configuration_load()
{
    if (isset($_POST['action']) && $_POST['action'] == 'save_options' && $_POST['_wpnonce'] == wp_create_nonce('stats')) {
        $options = stats_get_options();
        $options['admin_bar'] = isset($_POST['admin_bar']) && $_POST['admin_bar'];
        $options['reg_users'] = isset($_POST['reg_users']) && $_POST['reg_users'];
        $options['roles'] = array('administrator');
        foreach (get_editable_roles() as $role => $details) {
            if (isset($_POST["role_{$role}"]) && $_POST["role_{$role}"]) {
                $options['roles'][] = $role;
            }
        }
        stats_set_options($options);
        stats_update_blog();
        Jetpack::state('message', 'module_configured');
        wp_redirect(Jetpack::module_configuration_url('stats'));
        exit;
    }
}
Ejemplo n.º 23
0
 public static function check_privacy($file)
 {
     static $is_site_publicly_accessible = null;
     if (is_null($is_site_publicly_accessible)) {
         $is_site_publicly_accessible = false;
         Jetpack::load_xml_rpc_client();
         $rpc = new Jetpack_IXR_Client();
         $success = $rpc->query('jetpack.isSitePubliclyAccessible', home_url());
         if ($success) {
             $response = $rpc->getResponse();
             if ($response) {
                 $is_site_publicly_accessible = true;
             }
         }
         Jetpack_Options::update_option('public', (int) $is_site_publicly_accessible);
     }
     if ($is_site_publicly_accessible) {
         return;
     }
     $module_slug = self::get_module_slug($file);
     $privacy_checks = Jetpack::state('privacy_checks');
     if (!$privacy_checks) {
         $privacy_checks = $module_slug;
     } else {
         $privacy_checks .= ",{$module_slug}";
     }
     Jetpack::state('privacy_checks', $privacy_checks);
 }
    /**
     * Shows a notice message to users after they save Module config settings
     * @param  string $module_id
     * @return null
     */
    function show_notices_update_settings($module_id)
    {
        $state = Jetpack::state('message');
        switch ($state) {
            case 'module_activated':
                if ($module = Jetpack::get_module(Jetpack::state('module'))) {
                    $message = sprintf(__('<strong>%s Activated!</strong> You can change the setting of it here.', 'jetpack'), $module['name']);
                }
                break;
            case 'module_configured':
                $message = __('<strong>Module settings were saved.</strong> ', 'jetpack');
                break;
            case 'no_message':
                break;
        }
        if (isset($message)) {
            ?>
			<div id="message" class="jetpack-message">
				<div class="squeezer">
					<h2><?php 
            echo wp_kses($message, array('strong' => array(), 'a' => array('href' => true), 'br' => true));
            ?>
</h2>
					<?php 
            /**
             * Fires within the displayed message when a feature configuation is updated.
             *
             * This is a dynamic hook with `$module_id` being the slug of the module being updated.
             *
             * @since 3.4.0
             */
            do_action('jetpack_notices_update_settings_' . $module_id);
            ?>
				</div>
			</div>
			<?php 
        }
        add_action('jetpack_notices', array(Jetpack::init(), 'admin_notices'));
    }