get_jetpack_options_for_reset() public static method

It is used in class.jetpack-cli.php to reset options
public static get_jetpack_options_for_reset ( )
コード例 #1
0
 /**
  * Manage Jetpack Options
  *
  * ## OPTIONS
  *
  * list   : List all jetpack options and their values
  * delete : Delete an option
  *          - can only delete options that are white listed.
  * update : update an option
  *          - can only update option strings
  * get    : get the value of an option
  *
  * ## EXAMPLES
  *
  * wp jetpack options list
  * wp jetpack options get    <option_name>
  * wp jetpack options delete <option_name>
  * wp jetpack options update <option_name> [<option_value>]
  *
  * @synopsis <list|get|delete|update> [<option_name>] [<option_value>]
  */
 public function options($args, $assoc_args)
 {
     $action = isset($args[0]) ? $args[0] : 'list';
     $safe_to_modify = Jetpack::get_jetpack_options_for_reset();
     // Jumpstart is special
     array_push($safe_to_modify, 'jumpstart');
     // Is the option flagged as unsafe?
     $flagged = !in_array($args[1], $safe_to_modify);
     if (!in_array($action, array('list', 'get', 'delete', 'update'))) {
         WP_CLI::error(sprintf(__('%s is not a valid command.', 'jetpack'), $action));
     }
     if (isset($args[0])) {
         if ('get' == $args[0] && isset($args[1])) {
             $action = 'get';
         } else {
             if ('delete' == $args[0] && isset($args[1])) {
                 $action = 'delete';
             } else {
                 if ('update' == $args[0] && isset($args[1])) {
                     $action = 'update';
                 } else {
                     $action = 'list';
                 }
             }
         }
     }
     // Bail if the option isn't found
     $option = isset($args[1]) ? Jetpack_Options::get_option($args[1]) : false;
     if (isset($args[1]) && !$option && 'update' !== $args[0]) {
         WP_CLI::error(__('Option not found or is empty.  Use "list" to list option names', 'jetpack'));
     }
     // Let's print_r the option if it's an array
     // Used in the 'get' and 'list' actions
     $option = is_array($option) ? print_r($option) : $option;
     switch ($action) {
         case 'get':
             WP_CLI::success("\t" . $option);
             break;
         case 'delete':
             jetpack_cli_are_you_sure($flagged);
             Jetpack_Options::delete_option($args[1]);
             WP_CLI::success(sprintf(__('Deleted option: %s', 'jetpack'), $args[1]));
             break;
         case 'update':
             jetpack_cli_are_you_sure($flagged);
             // Updating arrays would get pretty tricky...
             $value = Jetpack_Options::get_option($args[1]);
             if ($value && is_array($value)) {
                 WP_CLI::error(__('Sorry, no updating arrays at this time', 'jetpack'));
             }
             Jetpack_Options::update_option($args[1], $args[2]);
             WP_CLI::success(sprintf(_x('Updated option: %s to "%s"', 'Updating an option from "this" to "that".', 'jetpack'), $args[1], $args[2]));
             break;
         case 'list':
             $options_compact = Jetpack_Options::get_option_names();
             $options_non_compact = Jetpack_Options::get_option_names('non_compact');
             $options_private = Jetpack_Options::get_option_names('private');
             $options = array_merge($options_compact, $options_non_compact, $options_private);
             // Table headers
             WP_CLI::line("\t" . str_pad(__('Option', 'jetpack'), 30) . __('Value', 'jetpack'));
             // List out the options and their values
             // Tell them if the value is empty or not
             // Tell them if it's an array
             foreach ($options as $option) {
                 $value = Jetpack_Options::get_option($option);
                 if (!$value) {
                     WP_CLI::line("\t" . str_pad($option, 30) . 'Empty');
                     continue;
                 }
                 if (!is_array($value)) {
                     WP_CLI::line("\t" . str_pad($option, 30) . $value);
                 } else {
                     if (is_array($value)) {
                         WP_CLI::line("\t" . str_pad($option, 30) . 'Array - Use "get <option>" to read option array.');
                     }
                 }
             }
             $option_text = '{' . _x('option', 'a variable command that a user can write, provided in the printed instructions', 'jetpack') . '}';
             $value_text = '{' . _x('value', 'the value that they want to update the option to', 'jetpack') . '}';
             WP_CLI::success(_x("Above are your options. You may 'get', 'delete', and 'update' them.", "'get', 'delete', and 'update' are commands - do not translate.", 'jetpack') . "\n" . str_pad('wp jetpack options get', 26) . $option_text . "\n" . str_pad('wp jetpack options delete', 26) . $option_text . "\n" . str_pad('wp jetpack options update', 26) . "{$option_text} {$value_text}" . "\n" . _x("Type 'wp jetpack options' for more info.", "'wp jetpack options' is a command - do not translate.", 'jetpack') . "\n");
             break;
     }
 }
コード例 #2
0
 /**
  * Reset Jetpack options
  *
  * @since 4.3.0
  *
  * @param WP_REST_Request $data {
  *     Array of parameters received by request.
  *
  *     @type string $options Available options to reset are options|modules
  * }
  *
  * @return bool|WP_Error True if options were reset. Otherwise, a WP_Error instance with the corresponding error.
  */
 public static function reset_jetpack_options($data)
 {
     $param = $data->get_json_params();
     if (!isset($param['reset']) || $param['reset'] !== true) {
         return new WP_Error('invalid_param', esc_html__('Invalid Parameter', 'jetpack'), array('status' => 404));
     }
     if (isset($data['options'])) {
         $data = $data['options'];
         switch ($data) {
             case 'options':
                 $options_to_reset = Jetpack::get_jetpack_options_for_reset();
                 // Reset the Jetpack options
                 foreach ($options_to_reset['jp_options'] as $option_to_reset) {
                     Jetpack_Options::delete_option($option_to_reset);
                 }
                 foreach ($options_to_reset['wp_options'] as $option_to_reset) {
                     delete_option($option_to_reset);
                 }
                 // Reset to default modules
                 $default_modules = Jetpack::get_default_modules();
                 Jetpack::update_active_modules($default_modules);
                 // Jumpstart option is special
                 Jetpack_Options::update_option('jumpstart', 'new_connection');
                 return rest_ensure_response(array('code' => 'success', 'message' => esc_html__('Jetpack options reset.', 'jetpack')));
                 break;
             case 'modules':
                 $default_modules = Jetpack::get_default_modules();
                 Jetpack::update_active_modules($default_modules);
                 return rest_ensure_response(array('code' => 'success', 'message' => esc_html__('Modules reset to default.', 'jetpack')));
                 break;
             default:
                 return new WP_Error('invalid_param', esc_html__('Invalid Parameter', 'jetpack'), array('status' => 404));
         }
     }
     return new WP_Error('required_param', esc_html__('Missing parameter "type".', 'jetpack'), array('status' => 404));
 }