/**
  * Updates site settings for authorized users
  *
  * @return (array)
  */
 public function update_settings()
 {
     // $this->input() retrieves posted arguments whitelisted and casted to the $request_format
     // specs that get passed in when this class is instantiated
     /**
      * Filters the settings to be updated on the site.
      *
      * @since 3.6.0
      *
      * @param array $input Associative array of site settings to be updated.
      */
     $input = apply_filters('rest_api_update_site_settings', $this->input());
     $jetpack_relatedposts_options = array();
     $sharing_options = array();
     $updated = array();
     foreach ($input as $key => $value) {
         if (!is_array($value)) {
             $value = trim($value);
         }
         $value = wp_unslash($value);
         switch ($key) {
             case 'default_ping_status':
             case 'default_comment_status':
                 // settings are stored as closed|open
                 $coerce_value = $value ? 'open' : 'closed';
                 if (update_option($key, $coerce_value)) {
                     $updated[$key] = $value;
                 }
                 break;
             case 'jetpack_protect_whitelist':
                 if (function_exists('jetpack_protect_save_whitelist')) {
                     $result = jetpack_protect_save_whitelist($value);
                     if (is_wp_error($result)) {
                         return $result;
                     }
                     $updated[$key] = jetpack_protect_format_whitelist();
                 }
                 break;
             case 'jetpack_sync_non_public_post_stati':
                 Jetpack_Options::update_option('sync_non_public_post_stati', $value);
                 break;
             case 'jetpack_relatedposts_enabled':
             case 'jetpack_relatedposts_show_thumbnails':
             case 'jetpack_relatedposts_show_headline':
                 if (!$this->jetpack_relatedposts_supported()) {
                     break;
                 }
                 if ('jetpack_relatedposts_enabled' === $key && method_exists('Jetpack', 'is_module_active') && $this->jetpack_relatedposts_supported()) {
                     $before_action = Jetpack::is_module_active('related-posts');
                     if ($value) {
                         Jetpack::activate_module('related-posts', false, false);
                     } else {
                         Jetpack::deactivate_module('related-posts');
                     }
                     $after_action = Jetpack::is_module_active('related-posts');
                     if ($after_action == $before_action) {
                         break;
                     }
                 }
                 $just_the_key = substr($key, 21);
                 $jetpack_relatedposts_options[$just_the_key] = $value;
                 break;
             case 'social_notifications_like':
             case 'social_notifications_reblog':
             case 'social_notifications_subscribe':
                 // settings are stored as on|off
                 $coerce_value = $value ? 'on' : 'off';
                 if (update_option($key, $coerce_value)) {
                     $updated[$key] = $value;
                 }
                 break;
             case 'wga':
                 if (!isset($value['code']) || !preg_match('/^$|^UA-[\\d-]+$/i', $value['code'])) {
                     return new WP_Error('invalid_code', 'Invalid UA ID');
                 }
                 $wga = get_option('wga', array());
                 $wga['code'] = $value['code'];
                 // maintain compatibility with wp-google-analytics
                 if (update_option('wga', $wga)) {
                     $updated[$key] = $value;
                 }
                 $enabled_or_disabled = $wga['code'] ? 'enabled' : 'disabled';
                 do_action('jetpack_bump_stats_extras', 'google-analytics', $enabled_or_disabled);
                 $business_plugins = WPCOM_Business_Plugins::instance();
                 $business_plugins->activate_plugin('wp-google-analytics');
                 break;
             case 'jetpack_comment_likes_enabled':
                 // settings are stored as 1|0
                 $coerce_value = (int) $value;
                 if (update_option($key, $coerce_value)) {
                     $updated[$key] = $value;
                 }
                 break;
                 // Sharing options
             // Sharing options
             case 'sharing_button_style':
             case 'sharing_show':
             case 'sharing_open_links':
                 $sharing_options[preg_replace('/^sharing_/', '', $key)] = $value;
                 break;
             case 'sharing_label':
                 $sharing_options[$key] = $value;
                 break;
                 // Keyring token option
             // Keyring token option
             case 'eventbrite_api_token':
                 // These options can only be updated for sites hosted on WordPress.com
                 if (defined('IS_WPCOM') && IS_WPCOM) {
                     if (empty($value) || WPCOM_JSON_API::is_falsy($value)) {
                         if (delete_option($key)) {
                             $updated[$key] = null;
                         }
                     } else {
                         if (update_option($key, $value)) {
                             $updated[$key] = (int) $value;
                         }
                     }
                 }
                 break;
                 // no worries, we've already whitelisted and casted arguments above
             // no worries, we've already whitelisted and casted arguments above
             default:
                 if (update_option($key, $value)) {
                     $updated[$key] = $value;
                 }
         }
     }
     if (count($jetpack_relatedposts_options)) {
         // track new jetpack_relatedposts options against old
         $old_relatedposts_options = Jetpack_Options::get_option('relatedposts');
         if (Jetpack_Options::update_option('relatedposts', $jetpack_relatedposts_options)) {
             foreach ($jetpack_relatedposts_options as $key => $value) {
                 if ($value !== $old_relatedposts_options[$key]) {
                     $updated['jetpack_relatedposts_' . $key] = $value;
                 }
             }
         }
     }
     if (!empty($sharing_options) && class_exists('Sharing_Service')) {
         $ss = new Sharing_Service();
         // Merge current values with updated, since Sharing_Service expects
         // all values to be included when updating
         $current_sharing_options = $ss->get_global_options();
         foreach ($current_sharing_options as $key => $val) {
             if (!isset($sharing_options[$key])) {
                 $sharing_options[$key] = $val;
             }
         }
         $updated_social_options = $ss->set_global_options($sharing_options);
         if (isset($input['sharing_button_style'])) {
             $updated['sharing_button_style'] = (string) $updated_social_options['button_style'];
         }
         if (isset($input['sharing_label'])) {
             // Sharing_Service won't report label as updated if set to default
             $updated['sharing_label'] = (string) $sharing_options['sharing_label'];
         }
         if (isset($input['sharing_show'])) {
             $updated['sharing_show'] = (array) $updated_social_options['show'];
         }
         if (isset($input['sharing_open_links'])) {
             $updated['sharing_open_links'] = (string) $updated_social_options['open_links'];
         }
     }
     return array('updated' => $updated);
 }
 public function render_network_admin_settings_page()
 {
     $this->network_admin_page_header();
     $options = wp_parse_args(get_site_option($this->settings_name), $this->setting_defaults);
     $modules = array();
     $module_slugs = Jetpack::get_available_modules();
     foreach ($module_slugs as $slug) {
         $module = Jetpack::get_module($slug);
         $module['module'] = $slug;
         $modules[] = $module;
     }
     usort($modules, array('Jetpack', 'sort_modules'));
     if (!isset($options['modules'])) {
         $options['modules'] = $modules;
     }
     $data = array('modules' => $modules, 'options' => $options, 'jetpack_protect_whitelist' => jetpack_protect_format_whitelist());
     Jetpack::init()->load_view('admin/network-settings.php', $data);
     $this->network_admin_page_footer();
 }
 /**
  * Remove 'validate_callback' item from options available for module.
  * Fetch current option value and add to array of module options.
  * Prepare values of module options that need special handling, like those saved in wpcom.
  *
  * @since 4.3.0
  *
  * @param string $module Module slug.
  * @return array
  */
 public static function prepare_options_for_response($module = '')
 {
     $options = self::get_module_available_options($module);
     if (!is_array($options) || empty($options)) {
         return $options;
     }
     foreach ($options as $key => $value) {
         if (isset($options[$key]['validate_callback'])) {
             unset($options[$key]['validate_callback']);
         }
         $default_value = isset($options[$key]['default']) ? $options[$key]['default'] : '';
         $current_value = get_option($key, $default_value);
         $options[$key]['current_value'] = self::cast_value($current_value, $options[$key]);
     }
     // Some modules need special treatment.
     switch ($module) {
         case 'monitor':
             // Status of user notifications
             $options['monitor_receive_notifications']['current_value'] = self::cast_value(self::get_remote_value('monitor', 'monitor_receive_notifications'), $options['monitor_receive_notifications']);
             break;
         case 'post-by-email':
             // Email address
             $options['post_by_email_address']['current_value'] = self::cast_value(self::get_remote_value('post-by-email', 'post_by_email_address'), $options['post_by_email_address']);
             break;
         case 'protect':
             // Protect
             $options['jetpack_protect_key']['current_value'] = get_site_option('jetpack_protect_key', false);
             if (!function_exists('jetpack_protect_format_whitelist')) {
                 @(include JETPACK__PLUGIN_DIR . 'modules/protect/shared-functions.php');
             }
             $options['jetpack_protect_global_whitelist']['current_value'] = jetpack_protect_format_whitelist();
             break;
         case 'related-posts':
             // It's local, but it must be broken apart since it's saved as an array.
             $options = self::split_options($options, Jetpack_Options::get_option('relatedposts'));
             break;
         case 'verification-tools':
             // It's local, but it must be broken apart since it's saved as an array.
             $options = self::split_options($options, get_option('verification_services_codes'));
             break;
         case 'sharedaddy':
             // It's local, but it must be broken apart since it's saved as an array.
             if (!class_exists('Sharing_Service') && !@(include JETPACK__PLUGIN_DIR . 'modules/sharedaddy/sharing-service.php')) {
                 break;
             }
             $sharer = new Sharing_Service();
             $options = self::split_options($options, $sharer->get_global_options());
             $options['sharing_services']['current_value'] = $sharer->get_blog_services();
             break;
         case 'site-icon':
             // Return site icon ID and URL to make it more complete.
             $options['site_icon_id']['current_value'] = Jetpack_Options::get_option('site_icon_id');
             if (!function_exists('jetpack_site_icon_url')) {
                 @(include JETPACK__PLUGIN_DIR . 'modules/site-icon/site-icon-functions.php');
             }
             $options['site_icon_url']['current_value'] = jetpack_site_icon_url();
             break;
         case 'after-the-deadline':
             if (!function_exists('AtD_get_options')) {
                 @(include JETPACK__PLUGIN_DIR . 'modules/after-the-deadline.php');
             }
             $atd_options = array_merge(AtD_get_options(get_current_user_id(), 'AtD_options'), AtD_get_options(get_current_user_id(), 'AtD_check_when'));
             unset($atd_options['name']);
             foreach ($atd_options as $key => $value) {
                 $options[$key]['current_value'] = self::cast_value($value, $options[$key]);
             }
             $atd_options = AtD_get_options(get_current_user_id(), 'AtD_guess_lang');
             $options['guess_lang']['current_value'] = self::cast_value(isset($atd_options['true']), $options['guess_lang']);
             $options['ignored_phrases']['current_value'] = AtD_get_setting(get_current_user_id(), 'AtD_ignored_phrases');
             unset($options['unignore_phrase']);
             break;
         case 'minileven':
             $options['wp_mobile_excerpt']['current_value'] = 1 === intval($options['wp_mobile_excerpt']['current_value']) ? 'enabled' : 'disabled';
             $options['wp_mobile_featured_images']['current_value'] = 1 === intval($options['wp_mobile_featured_images']['current_value']) ? 'enabled' : 'disabled';
             break;
         case 'stats':
             // It's local, but it must be broken apart since it's saved as an array.
             if (!function_exists('stats_get_options')) {
                 @(include JETPACK__PLUGIN_DIR . 'modules/stats.php');
             }
             $options = self::split_options($options, stats_get_options());
             break;
     }
     return $options;
 }
 /**
  * Updates site settings for authorized users
  *
  * @return (array)
  */
 public function update_settings()
 {
     // $this->input() retrieves posted arguments whitelisted and casted to the $request_format
     // specs that get passed in when this class is instantiated
     /**
      * Filters the settings to be updated on the site.
      *
      * @module json-api
      *
      * @since 3.6.0
      *
      * @param array $input Associative array of site settings to be updated.
      */
     $input = apply_filters('rest_api_update_site_settings', $this->input());
     $jetpack_relatedposts_options = array();
     $sharing_options = array();
     $updated = array();
     foreach ($input as $key => $value) {
         if (!is_array($value)) {
             $value = trim($value);
         }
         $value = wp_unslash($value);
         switch ($key) {
             case 'default_ping_status':
             case 'default_comment_status':
                 // settings are stored as closed|open
                 $coerce_value = $value ? 'open' : 'closed';
                 if (update_option($key, $coerce_value)) {
                     $updated[$key] = $value;
                 }
                 break;
             case 'jetpack_protect_whitelist':
                 if (function_exists('jetpack_protect_save_whitelist')) {
                     $result = jetpack_protect_save_whitelist($value);
                     if (is_wp_error($result)) {
                         return $result;
                     }
                     $updated[$key] = jetpack_protect_format_whitelist();
                 }
                 break;
             case 'jetpack_sync_non_public_post_stati':
                 Jetpack_Options::update_option('sync_non_public_post_stati', $value);
                 break;
             case 'jetpack_relatedposts_enabled':
             case 'jetpack_relatedposts_show_thumbnails':
             case 'jetpack_relatedposts_show_headline':
                 if (!$this->jetpack_relatedposts_supported()) {
                     break;
                 }
                 if ('jetpack_relatedposts_enabled' === $key && method_exists('Jetpack', 'is_module_active') && $this->jetpack_relatedposts_supported()) {
                     $before_action = Jetpack::is_module_active('related-posts');
                     if ($value) {
                         Jetpack::activate_module('related-posts', false, false);
                     } else {
                         Jetpack::deactivate_module('related-posts');
                     }
                     $after_action = Jetpack::is_module_active('related-posts');
                     if ($after_action == $before_action) {
                         break;
                     }
                 }
                 $just_the_key = substr($key, 21);
                 $jetpack_relatedposts_options[$just_the_key] = $value;
                 break;
             case 'social_notifications_like':
             case 'social_notifications_reblog':
             case 'social_notifications_subscribe':
                 // settings are stored as on|off
                 $coerce_value = $value ? 'on' : 'off';
                 if (update_option($key, $coerce_value)) {
                     $updated[$key] = $value;
                 }
                 break;
             case 'wga':
                 if (!isset($value['code']) || !preg_match('/^$|^UA-[\\d-]+$/i', $value['code'])) {
                     return new WP_Error('invalid_code', 'Invalid UA ID');
                 }
                 $wga = get_option('wga', array());
                 $wga['code'] = $value['code'];
                 // maintain compatibility with wp-google-analytics
                 if (update_option('wga', $wga)) {
                     $updated[$key] = $value;
                 }
                 $enabled_or_disabled = $wga['code'] ? 'enabled' : 'disabled';
                 /** This action is documented in modules/widgets/social-media-icons.php */
                 do_action('jetpack_bump_stats_extras', 'google-analytics', $enabled_or_disabled);
                 $business_plugins = WPCOM_Business_Plugins::instance();
                 $business_plugins->activate_plugin('wp-google-analytics');
                 break;
             case 'jetpack_testimonial':
             case 'jetpack_portfolio':
             case 'jetpack_comment_likes_enabled':
                 // settings are stored as 1|0
                 $coerce_value = (int) $value;
                 if (update_option($key, $coerce_value)) {
                     $updated[$key] = (bool) $value;
                 }
                 break;
             case 'jetpack_testimonial_posts_per_page':
             case 'jetpack_portfolio_posts_per_page':
                 // settings are stored as numeric
                 $coerce_value = (int) $value;
                 if (update_option($key, $coerce_value)) {
                     $updated[$key] = $coerce_value;
                 }
                 break;
                 // Sharing options
             // Sharing options
             case 'sharing_button_style':
             case 'sharing_show':
             case 'sharing_open_links':
                 $sharing_options[preg_replace('/^sharing_/', '', $key)] = $value;
                 break;
             case 'sharing_label':
                 $sharing_options[$key] = $value;
                 break;
                 // Keyring token option
             // Keyring token option
             case 'eventbrite_api_token':
                 // These options can only be updated for sites hosted on WordPress.com
                 if (defined('IS_WPCOM') && IS_WPCOM) {
                     if (empty($value) || WPCOM_JSON_API::is_falsy($value)) {
                         if (delete_option($key)) {
                             $updated[$key] = null;
                         }
                     } else {
                         if (update_option($key, $value)) {
                             $updated[$key] = (int) $value;
                         }
                     }
                 }
                 break;
             case 'holidaysnow':
                 if (empty($value) || WPCOM_JSON_API::is_falsy($value)) {
                     if (function_exists('jetpack_holiday_snow_option_name') && delete_option(jetpack_holiday_snow_option_name())) {
                         $updated[$key] = false;
                     }
                 } else {
                     if (function_exists('jetpack_holiday_snow_option_name') && update_option(jetpack_holiday_snow_option_name(), 'letitsnow')) {
                         $updated[$key] = true;
                     }
                 }
                 break;
             case 'timezone_string':
                 // Map UTC+- timezones to gmt_offsets and set timezone_string to empty
                 // https://github.com/WordPress/WordPress/blob/4.4.2/wp-admin/options.php#L175
                 if (!empty($value) && preg_match('/^UTC[+-]/', $value)) {
                     $gmt_offset = preg_replace('/UTC\\+?/', '', $value);
                     if (update_option('gmt_offset', $gmt_offset)) {
                         $updated['gmt_offset'] = $gmt_offset;
                     }
                     $value = '';
                 }
                 // Always set timezone_string either with the given value or with an
                 // empty string
                 if (update_option($key, $value)) {
                     $updated[$key] = $value;
                 }
                 break;
             default:
                 //allow future versions of this endpoint to support additional settings keys
                 if (has_filter('site_settings_endpoint_update_' . $key)) {
                     /**
                      * Filter current site setting value to be updated.
                      *
                      * @module json-api
                      *
                      * @since 3.9.3
                      *
                      * @param mixed $response_item A single site setting value.
                      */
                     $value = apply_filters('site_settings_endpoint_update_' . $key, $value);
                     $updated[$key] = $value;
                     continue;
                 }
                 // no worries, we've already whitelisted and casted arguments above
                 if (update_option($key, $value)) {
                     $updated[$key] = $value;
                 }
         }
     }
     if (count($jetpack_relatedposts_options)) {
         // track new jetpack_relatedposts options against old
         $old_relatedposts_options = Jetpack_Options::get_option('relatedposts');
         if (Jetpack_Options::update_option('relatedposts', $jetpack_relatedposts_options)) {
             foreach ($jetpack_relatedposts_options as $key => $value) {
                 if ($value !== $old_relatedposts_options[$key]) {
                     $updated['jetpack_relatedposts_' . $key] = $value;
                 }
             }
         }
     }
     if (!empty($sharing_options) && class_exists('Sharing_Service')) {
         $ss = new Sharing_Service();
         // Merge current values with updated, since Sharing_Service expects
         // all values to be included when updating
         $current_sharing_options = $ss->get_global_options();
         foreach ($current_sharing_options as $key => $val) {
             if (!isset($sharing_options[$key])) {
                 $sharing_options[$key] = $val;
             }
         }
         $updated_social_options = $ss->set_global_options($sharing_options);
         if (isset($input['sharing_button_style'])) {
             $updated['sharing_button_style'] = (string) $updated_social_options['button_style'];
         }
         if (isset($input['sharing_label'])) {
             // Sharing_Service won't report label as updated if set to default
             $updated['sharing_label'] = (string) $sharing_options['sharing_label'];
         }
         if (isset($input['sharing_show'])) {
             $updated['sharing_show'] = (array) $updated_social_options['show'];
         }
         if (isset($input['sharing_open_links'])) {
             $updated['sharing_open_links'] = (string) $updated_social_options['open_links'];
         }
     }
     return array('updated' => $updated);
 }
Example #5
0
				<br /><br /><input type='submit' class='button-primary' value='<?php 
    echo esc_attr(__('Get an API Key', 'jetpack'));
    ?>
' />
			</p>
		</form>
	</div>

<?php 
} else {
    // api key is good, show white list options
    ?>

	<?php 
    global $current_user;
    $whitelist = jetpack_protect_format_whitelist($this->whitelist);
    // todo remove 'local' from schema when we merge next iteration on calypso
    ?>
	<div class="protect-whitelist">

		<form id="editable-whitelist" method="post">
			<h3><?php 
    _e('Whitelist Management', 'jetpack');
    ?>
</h3>

			<?php 
    if (!empty($this->whitelist_error)) {
        ?>
				<p class="error"><?php 
        _e('One of your IP addresses was not valid.', 'jetpack');
Example #6
0
				<br /><br /><input type='submit' class='button-primary' value='<?php 
    echo esc_attr(__('Get an API Key', 'jetpack'));
    ?>
' />
			</p>
		</form>
	</div>

<?php 
} else {
    // api key is good, show white list options
    ?>

	<?php 
    global $current_user;
    $whitelist = jetpack_protect_format_whitelist();
    ?>
	<div class="protect-whitelist">

		<form id="editable-whitelist" method="post">
			<h3><?php 
    _e('Whitelist Management', 'jetpack');
    ?>
</h3>

			<?php 
    if (!empty($this->whitelist_error)) {
        ?>
				<p class="error"><?php 
        _e('One of your IP addresses was not valid.', 'jetpack');
        ?>