コード例 #1
0
ファイル: taxonomy.php プロジェクト: Jaace/wp-cli
 public function __construct()
 {
     if (\WP_CLI\Utils\wp_version_compare(3.7, '<')) {
         // remove description for wp <= 3.7
         $this->fields = array_values(array_diff($this->fields, array('description')));
     }
     parent::__construct();
 }
コード例 #2
0
ファイル: cron.php プロジェクト: wp-cli/wp-cli
 /**
  * Spawn a request to `wp-cron.php` and return the response.
  *
  * This function is designed to mimic the functionality in `spawn_cron()`
  * with the addition of returning the result of the `wp_remote_post()`
  * request.
  *
  * @return WP_Error|array The response or WP_Error on failure.
  */
 protected static function get_cron_spawn()
 {
     $sslverify = \WP_CLI\Utils\wp_version_compare(4.0, '<');
     $doing_wp_cron = sprintf('%.22F', microtime(true));
     $cron_request = apply_filters('cron_request', array('url' => site_url('wp-cron.php?doing_wp_cron=' . $doing_wp_cron), 'key' => $doing_wp_cron, 'args' => array('timeout' => 3, 'blocking' => true, 'sslverify' => apply_filters('https_local_ssl_verify', $sslverify))));
     # Enforce a blocking request in case something that's hooked onto the 'cron_request' filter sets it to false
     $cron_request['args']['blocking'] = true;
     $result = wp_remote_post($cron_request['url'], $cron_request['args']);
     return $result;
 }
コード例 #3
0
ファイル: user.php プロジェクト: voldemortensen/wp-cli
 /**
  * Acommodate three different behaviors for wp_new_user_notification()
  * - 4.3.1 and above: expect second argument to be deprecated
  * - 4.3: Second argument was repurposed as $notify
  * - Below 4.3: Send the password in the notification
  *
  * @param string $user_id
  * @param string $password
  */
 private static function wp_new_user_notification($user_id, $password)
 {
     if (\WP_CLI\Utils\wp_version_compare('4.3.1', '>=')) {
         wp_new_user_notification($user_id, null, 'both');
     } else {
         if (\WP_CLI\Utils\wp_version_compare('4.3', '>=')) {
             wp_new_user_notification($user_id, 'both');
         } else {
             wp_new_user_notification($user_id, $password);
         }
     }
 }
コード例 #4
0
ファイル: term.php プロジェクト: ryanshoover/wp-cli
 *
 * --format=json
 * : Encode/decode values as JSON.
 *
 * ## EXAMPLES
 *
 *     wp term meta set category 123 description "Mary is a WordPress developer."
 */
class Term_Meta_Command extends \WP_CLI\CommandWithMeta
{
    protected $meta_type = 'term';
    /**
     * Check that the term ID exists
     *
     * @param int
     */
    protected function check_object_id($object_id)
    {
        $term = get_term($object_id);
        if (!$term) {
            WP_CLI::error("Could not find the term with ID {$object_id}.");
        }
        return $term->term_id;
    }
}
WP_CLI::add_command('term', 'Term_Command');
WP_CLI::add_command('term meta', 'Term_Meta_Command', array('before_invoke' => function () {
    if (\WP_CLI\Utils\wp_version_compare('4.4', '<')) {
        WP_CLI::error("Requires WordPress 4.4 or greater.");
    }
}));
コード例 #5
0
ファイル: core.php プロジェクト: Faisalawanisee/wp-cli
 /**
  * Update WordPress.
  *
  * ## OPTIONS
  *
  * [<zip>]
  * : Path to zip file to use, instead of downloading from wordpress.org.
  *
  * [--minor]
  * : Only perform updates for minor releases.
  *
  * [--version=<version>]
  * : Update to a specific version, instead of to the latest version.
  *
  * [--force]
  * : Update even when installed WP version is greater than the requested version.
  *
  * [--locale=<locale>]
  * : Select which language you want to download.
  *
  * ## EXAMPLES
  *
  *     wp core update
  *
  *     wp core update --version=3.8 ../latest.zip
  *
  *     wp core update --version=3.1 --force
  *
  * @alias upgrade
  */
 function update($args, $assoc_args)
 {
     global $wp_version;
     $update = $from_api = null;
     $upgrader = 'WP_CLI\\CoreUpgrader';
     if (empty($args[0]) && empty($assoc_args['version']) && \WP_CLI\Utils\get_flag_value($assoc_args, 'minor')) {
         $updates = $this->get_updates(array('minor' => true));
         if (!empty($updates)) {
             $assoc_args['version'] = $updates[0]['version'];
         } else {
             WP_CLI::success('WordPress is at the latest minor release.');
             return;
         }
     }
     if (!empty($args[0])) {
         $upgrader = 'WP_CLI\\NonDestructiveCoreUpgrader';
         $version = \WP_CLI\Utils\get_flag_value($assoc_args, 'version');
         $update = (object) array('response' => 'upgrade', 'current' => $version, 'download' => $args[0], 'packages' => (object) array('partial' => null, 'new_bundled' => null, 'no_content' => null, 'full' => $args[0]), 'version' => $version, 'locale' => null);
     } else {
         if (empty($assoc_args['version'])) {
             wp_version_check();
             $from_api = get_site_transient('update_core');
             if (!empty($from_api->updates)) {
                 list($update) = $from_api->updates;
             }
         } else {
             if (\WP_CLI\Utils\wp_version_compare($assoc_args['version'], '<') || \WP_CLI\Utils\get_flag_value($assoc_args, 'force')) {
                 $version = $assoc_args['version'];
                 $locale = \WP_CLI\Utils\get_flag_value($assoc_args, 'locale', get_locale());
                 $new_package = $this->get_download_url($version, $locale);
                 $update = (object) array('response' => 'upgrade', 'current' => $assoc_args['version'], 'download' => $new_package, 'packages' => (object) array('partial' => null, 'new_bundled' => null, 'no_content' => null, 'full' => $new_package), 'version' => $version, 'locale' => $locale);
             }
         }
     }
     if (!empty($update) && ($update->version != $wp_version || \WP_CLI\Utils\get_flag_value($assoc_args, 'force'))) {
         require_once ABSPATH . 'wp-admin/includes/upgrade.php';
         if ($update->version) {
             WP_CLI::log("Updating to version {$update->version} ({$update->locale})...");
         } else {
             WP_CLI::log("Starting update...");
         }
         $GLOBALS['wp_cli_update_obj'] = $update;
         $result = Utils\get_upgrader($upgrader)->upgrade($update);
         unset($GLOBALS['wp_cli_update_obj']);
         if (is_wp_error($result)) {
             $msg = WP_CLI::error_to_string($result);
             if ('up_to_date' != $result->get_error_code()) {
                 WP_CLI::error($msg);
             } else {
                 WP_CLI::success($msg);
             }
         } else {
             WP_CLI::success('WordPress updated successfully.');
         }
     } else {
         WP_CLI::success('WordPress is up to date.');
     }
 }