get_option_names() публичный статический Метод

Returns an array of option names for a given type.
public static get_option_names ( string $type = 'compact' ) : array
$type string The type of option to return. Defaults to 'compact'.
Результат array
Пример #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
 public static function get_option_names($type = 'compact')
 {
     return Jetpack_Options::get_option_names($type);
 }
 public static function get_jetpack_options_for_reset()
 {
     $jetpack_options = Jetpack_Options::get_option_names();
     $jetpack_options_non_compat = Jetpack_Options::get_option_names('non_compact');
     $jetpack_options_private = Jetpack_Options::get_option_names('private');
     $all_jp_options = array_merge($jetpack_options, $jetpack_options_non_compat, $jetpack_options_private);
     // A manual build of the wp options
     $wp_options = array('sharing-options', 'disabled_likes', 'disabled_reblogs', 'jetpack_comments_likes_enabled', 'wp_mobile_excerpt', 'wp_mobile_featured_images', 'wp_mobile_app_promos', 'stats_options', 'stats_dashboard_widget', 'safecss_preview_rev', 'safecss_rev', 'safecss_revision_migrated', 'nova_menu_order', 'jetpack_portfolio', 'jetpack_portfolio_posts_per_page', 'jetpack_testimonial', 'jetpack_testimonial_posts_per_page', 'wp_mobile_custom_css', 'sharedaddy_disable_resources', 'sharing-options', 'sharing-services', 'site_icon_temp_data', 'featured-content', 'site_logo');
     // Flag some Jetpack options as unsafe
     $unsafe_options = array('id', 'master_user', 'version', 'jumpstart', 'activated', 'register', 'blog_token', 'user_token', 'user_tokens');
     // Remove the unsafe Jetpack options
     foreach ($unsafe_options as $unsafe_option) {
         if (false !== ($key = array_search($unsafe_option, $all_jp_options))) {
             unset($all_jp_options[$key]);
         }
     }
     $options = array('jp_options' => $all_jp_options, 'wp_options' => $wp_options);
     return $options;
 }