halt() public static method

Permits script execution to be overloaded by WP_CLI::runcommand()
public static halt ( integer $return_code )
$return_code integer
Example #1
0
 /**
  * Get the value for an option.
  *
  * ## OPTIONS
  *
  * <key>
  * : Key for the option.
  *
  * [--format=<format>]
  * : Get value in a particular format.
  * ---
  * default: var_export
  * options:
  *   - var_export
  *   - json
  *   - yaml
  * ---
  *
  * ## EXAMPLES
  *
  *     # Get option.
  *     $ wp option get home
  *     http://example.com
  *
  *     # Get option in JSON format.
  *     $ wp option get active_plugins --format=json
  *     {"0":"dynamically-dynamic-sidebar\/dynamically-dynamic-sidebar.php","1":"monster-widget\/monster-widget.php","2":"show-current-template\/show-current-template.php","3":"theme-check\/theme-check.php","5":"wordpress-importer\/wordpress-importer.php"}
  */
 public function get($args, $assoc_args)
 {
     list($key) = $args;
     $value = get_option($key);
     if (false === $value) {
         WP_CLI::halt(1);
     }
     WP_CLI::print_value($value, $assoc_args);
 }
Example #2
0
 /**
  * Check if WordPress is installed.
  *
  * Determines whether WordPress is installed by checking if the standard
  * database tables are installed. Doesn't produce output; uses exit codes
  * to communicate whether WordPress is installed.
  *
  * [--network]
  * : Check if this is a multisite install.
  *
  * ## EXAMPLES
  *
  *     # Check whether WordPress is installed; exit status 0 if installed, otherwise 1
  *     $ wp core is-installed
  *     $ echo $?
  *     1
  *
  *     # Bash script for checking whether WordPress is installed or not
  *     if ! $(wp core is-installed); then
  *         wp core install
  *     fi
  *
  * @subcommand is-installed
  */
 public function is_installed($_, $assoc_args)
 {
     if (\WP_CLI\Utils\get_flag_value($assoc_args, 'network')) {
         if (is_blog_installed() && is_multisite()) {
             WP_CLI::halt(0);
         } else {
             WP_CLI::halt(1);
         }
     } else {
         if (is_blog_installed()) {
             WP_CLI::halt(0);
         } else {
             WP_CLI::halt(1);
         }
     }
 }
Example #3
0
 /**
  * Check if the plugin is installed.
  *
  * Returns exit code 0 when installed, 1 when uninstalled.
  *
  * ## OPTIONS
  *
  * <plugin>
  * : The plugin to check.
  *
  * ## EXAMPLES
  *
  *     # Check whether plugin is installed; exit status 0 if installed, otherwise 1
  *     $ wp plugin is-installed hello-dolly
  *     $ echo $?
  *     1
  *
  * @subcommand is-installed
  */
 public function is_installed($args, $assoc_args = array())
 {
     if ($this->fetcher->get($args[0])) {
         WP_CLI::halt(0);
     } else {
         WP_CLI::halt(1);
     }
 }
Example #4
0
 private function validate_args($args)
 {
     $has_errors = false;
     foreach ($args as $key => $value) {
         if (is_callable(array($this, 'check_' . $key))) {
             $result = call_user_func(array($this, 'check_' . $key), $value);
             if (false === $result) {
                 $has_errors = true;
             }
         }
     }
     if ($has_errors) {
         WP_CLI::halt(1);
     }
 }
Example #5
0
 /**
  * Check if the theme is installed.
  *
  * Returns exit code 0 when installed, 1 when uninstalled.
  *
  * ## OPTIONS
  *
  * <theme>
  * : The theme to check.
  *
  * ## EXAMPLES
  *
  *     # Check whether theme is installed; exit status 0 if installed, otherwise 1
  *     $ wp theme is-installed hello-dolly
  *     $ echo $?
  *     1
  *
  * @subcommand is-installed
  */
 public function is_installed($args, $assoc_args = array())
 {
     $theme = wp_get_theme($args[0]);
     if ($theme->exists()) {
         WP_CLI::halt(0);
     } else {
         WP_CLI::halt(1);
     }
 }