PHP Class Core_Command, wp-cli

## EXAMPLES # Download WordPress core $ wp core download --locale=nl_NL Downloading WordPress 4.5.2 (nl_NL)... md5 hash verified: c5366d05b521831dd0b29dfc386e56a5 Success: WordPress downloaded. # Install WordPress $ wp core install --url=example.com --title=Example --admin_user=supervisor --admin_password=strongpassword [email protected] Success: WordPress installed successfully. # Display the WordPress version $ wp core version 4.5.2
Inheritance: extends WP_CLI_Command
显示文件 Open project: wp-cli/wp-cli Class Usage Examples

Public Methods

Method Description
check_update ( $_, $assoc_args ) Check for WordPress updates via Version Check API.
config ( $_, $assoc_args ) Generate a wp-config.php file.
download ( $args, $assoc_args ) Download core WordPress files.
install ( $args, $assoc_args ) Runs the standard WordPress installation process.
is_installed ( $_, $assoc_args ) Check if WordPress is installed.
multisite_convert ( $args, $assoc_args ) Transform a single-site install into a WordPress multisite install.
multisite_install ( $args, $assoc_args ) Install WordPress multisite from scratch.
update ( $args, $assoc_args ) Update WordPress to a newer version.
update_db ( $_, $assoc_args ) Run the WordPress database update procedure.
verify_checksums ( $args, $assoc_args ) Verify WordPress files against WordPress.org's checksums.
version ( $args = [], $assoc_args = [] ) Display the WordPress version.
wp_new_blog_notification ( )

Private Methods

Method Description
_install ( $assoc_args )
_multisite_convert ( $assoc_args )
_read ( $url )
_set_multisite_defaults ( $assoc_args )
add_site_admins ( $site_user ) copied from populate_network()
cleanup_extra_files ( $version_from, $version_to, $locale )
create_initial_blog ( $network_id, $blog_id, $domain, $path, $subdomain_install, $site_user ) copied from populate_network()
find_var ( string $var_name, string $code ) : integer | string | null Search for the value assigned to variable $var_name in PHP code $code.
get_clean_basedomain ( )
get_core_checksums ( string $version, string $locale ) : boolean | array Security copy of the core function with Requests - Gets the checksums for the given version of WordPress.
get_download_offer ( $locale )
get_download_url ( $version, string $locale = 'en_US', string $file_type = 'zip' ) : string Gets download url based on version, locale and desired file type.
get_initial_locale ( )
get_updates ( $assoc_args ) Returns update information
get_wp_core_files ( )
get_wp_details ( ) : array Get version information from wp-includes/version.php.
modify_wp_config ( $content )
only_core_files_filter ( $file )

Method Details

check_update() public method

Lists the most recent versions when there are updates available, or success message when up to date. ## OPTIONS [--minor] : Compare only the first two parts of the version number. [--major] : Compare only the first part of the version number. [--field=] : Prints the value of a single field for each update. [--fields=] : Limit the output to specific object fields. Defaults to version,update_type,package_url. [--format=] : Render output in a particular format. --- default: table options: - table - csv - count - json - yaml --- ## EXAMPLES $ wp core check-update +---------+-------------+-------------------------------------------------------------+ | version | update_type | package_url | +---------+-------------+-------------------------------------------------------------+ | 4.5.2 | major | https://downloads.wordpress.org/release/wordpress-4.5.2.zip | +---------+-------------+-------------------------------------------------------------+
public check_update ( $_, $assoc_args )

config() public method

Creates a new wp-config.php with database constants, and verifies that the database constants are correct. ## OPTIONS --dbname= : Set the database name. --dbuser= : Set the database user. [--dbpass=] : Set the database user password. [--dbhost=] : Set the database host. --- default: localhost --- [--dbprefix=] : Set the database table prefix. --- default: wp_ --- [--dbcharset=] : Set the database charset. --- default: utf8 --- [--dbcollate=] : Set the database collation. --- default: --- [--locale=] : Set the WPLANG constant. Defaults to $wp_local_package variable. [--extra-php] : If set, the command copies additional PHP code into wp-config.php from STDIN. [--skip-salts] : If set, keys and salts won't be generated, but should instead be passed via --extra-php. [--skip-check] : If set, the database connection is not checked. ## EXAMPLES # Standard wp-config.php file $ wp core config --dbname=testing --dbuser=wp --dbpass=securepswd --locale=ro_RO Success: Generated 'wp-config.php' file. # Enable WP_DEBUG and WP_DEBUG_LOG $ wp core config --dbname=testing --dbuser=wp --dbpass=securepswd --extra-php <
public config ( $_, $assoc_args )

download() public method

Downloads and extracts WordPress core files to the specified path. Uses an archive file stored in cache if WordPress has been previously downloaded. ## OPTIONS [--path=] : Specify the path in which to install WordPress. [--locale=] : Select which language you want to download. [--version=] : Select which version you want to download. Accepts a version number, 'latest' or 'nightly' [--force] : Overwrites existing files, if present. ## EXAMPLES $ wp core download --locale=nl_NL Downloading WordPress 4.5.2 (nl_NL)... md5 hash verified: c5366d05b521831dd0b29dfc386e56a5 Success: WordPress downloaded.
public download ( $args, $assoc_args )

install() public method

Creates the WordPress tables in the database using the URL, title, and default admin user details provided. Performs the famous 5 minute install in seconds or less. Note: if you've installed WordPress in a subdirectory, then you'll need to wp option update siteurl after wp core install. For instance, if WordPress is installed in the /wp directory and your domain is wp.dev, then you'll need to run wp option update siteurl http://wp.dev/wp for your WordPress install to function properly. Note: When using custom user tables (e.g. CUSTOM_USER_TABLE), the admin email and password are ignored if the user_login already exists. If the user_login doesn't exist, a new user will be created. ## OPTIONS --url= : The address of the new site. --title= : The title of the new site. --admin_user= : The name of the admin user. [--admin_password=] : The password for the admin user. Defaults to randomly generated string. --admin_email= : The email address for the admin user. [--skip-email] : Don't send an email notification to the new admin user. ## EXAMPLES # Install WordPress in 5 seconds $ wp core install --url=example.com --title=Example --admin_user=supervisor --admin_password=strongpassword [email protected] Success: WordPress installed successfully. # Install WordPress without disclosing admin_password to bash history $ wp core install --url=example.com --title=Example --admin_user=supervisor [email protected] --prompt=admin_password < admin_password.txt
public install ( $args, $assoc_args )

is_installed() public method

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
public is_installed ( $_, $assoc_args )

multisite_convert() public method

Creates the multisite database tables, and adds the multisite constants to wp-config.php. For those using WordPress with Apache, remember to update the .htaccess file with the appropriate multisite rewrite rules. ## OPTIONS [--title=] : The title of the new network. [--base=] : Base path after the domain name that each site url will start with. --- default: / --- [--subdomains] : If passed, the network will use subdomains, instead of subdirectories. Doesn't work with 'localhost'. ## EXAMPLES $ wp core multisite-convert Set up multisite database tables. Added multisite constants to wp-config.php. Success: Network installed. Don't forget to set up rewrite rules.
public multisite_convert ( $args, $assoc_args )

multisite_install() public method

Creates the WordPress tables in the database using the URL, title, and default admin user details provided. Then, creates the multisite tables in the database and adds multisite constants to the wp-config.php. ## OPTIONS [--url=] : The address of the new site. [--base=] : Base path after the domain name that each site url in the network will start with. --- default: / --- [--subdomains] : If passed, the network will use subdomains, instead of subdirectories. Doesn't work with 'localhost'. --title= : The title of the new site. --admin_user= : The name of the admin user. --- default: admin --- [--admin_password=] : The password for the admin user. Defaults to randomly generated string. --admin_email= : The email address for the admin user. [--skip-email] : Don't send an email notification to the new admin user. ## EXAMPLES $ wp core multisite-install --title="Welcome to the WordPress" \ > --admin_user="admin" --admin_password="password" \ > --admin_email="[email protected]" Single site database tables already present. Set up multisite database tables. Added multisite constants to wp-config.php. Success: Network installed. Don't forget to set up rewrite rules.
public multisite_install ( $args, $assoc_args )

update() public method

Defaults to updating WordPress to the latest version. ## OPTIONS [] : Path to zip file to use, instead of downloading from wordpress.org. [--minor] : Only perform updates for minor releases (e.g. update from WP 4.3 to 4.3.3 instead of 4.4.2). [--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=] : Select which language you want to download. ## EXAMPLES # Update WordPress $ wp core update Updating to version 4.5.2 (en_US)... Downloading update from https://downloads.wordpress.org/release/wordpress-4.5.2-no-content.zip... Unpacking the update... Cleaning up files... No files found that need cleaned up Success: WordPress updated successfully. # Update WordPress to latest version of 3.8 release $ wp core update --version=3.8 ../latest.zip Updating to version 3.8 ()... Unpacking the update... Cleaning up files... File removed: wp-admin/js/tags-box.js ... File removed: wp-admin/js/updates.min. 377 files cleaned up Success: WordPress updated successfully. # Update WordPress to 3.1 forcefully $ wp core update --version=3.1 --force Updating to version 3.1 (en_US)... Downloading update from https://wordpress.org/wordpress-3.1.zip... Unpacking the update... Warning: Failed to fetch checksums. Please cleanup files manually. Success: WordPress updated successfully.
public update ( $args, $assoc_args )

update_db() public method

[--network] : Update databases for all sites on a network [--dry-run] : Compare database versions without performing the update. ## EXAMPLES # Update the WordPress database $ wp core update-db Success: WordPress database upgraded successfully from db version 36686 to 35700. # Update databases for all sites on a network $ wp core update-db --network WordPress database upgraded successfully from db version 35700 to 29630 on example.com/ Success: WordPress database upgraded on 123/123 sites
public update_db ( $_, $assoc_args )

verify_checksums() public method

Downloads md5 checksums for the current version from WordPress.org, and compares those checksums against the currently installed files. For security, avoids loading WordPress when verifying checksums. ## OPTIONS [--version=] : Verify checksums against a specific version of WordPress. [--locale=] : Verify checksums against a specific locale of WordPress. ## EXAMPLES # Verify checksums $ wp core verify-checksums Success: WordPress install verifies against checksums. # Verify checksums for given WordPress version $ wp core verify-checksums --version=4.0 Success: WordPress install verifies against checksums. # Verify checksums for given locale $ wp core verify-checksums --locale=en_US Success: WordPress install verifies against checksums. # Verify checksums for given locale $ wp core verify-checksums --locale=ja Warning: File doesn't verify against checksum: wp-includes/version.php Warning: File doesn't verify against checksum: readme.html Warning: File doesn't verify against checksum: wp-config-sample.php Error: WordPress install doesn't verify against checksums.
public verify_checksums ( $args, $assoc_args )

version() public method

## OPTIONS [--extra] : Show extended version information. ## EXAMPLES # Display the WordPress version $ wp core version 4.5.2 # Display WordPress version along with other information $ wp core version --extra WordPress version: 4.5.2 Database revision: 36686 TinyMCE version: 4.310 (4310-20160418) Package language: en_US
public version ( $args = [], $assoc_args = [] )

wp_new_blog_notification() public method