_id
stringlengths
2
7
title
stringlengths
3
151
partition
stringclasses
3 values
text
stringlengths
33
8k
language
stringclasses
1 value
meta_information
dict
q14700
FileCache.remove
train
public function remove( $key ) { if ( ! $this->enabled ) { return false; } $filename = $this->filename( $key ); if (
php
{ "resource": "" }
q14701
FileCache.clean
train
public function clean() { if ( ! $this->enabled ) { return false; } $ttl = $this->ttl; $max_size = $this->max_size; // unlink expired files if ( $ttl > 0 ) { try { $expire = new \DateTime(); } catch ( \Exception $e ) { \WP_CLI::error( $e->getMessage() ); } $expire->modify( '-' . $ttl . ' seconds' ); $finder = $this->get_finder()->date( 'until ' . $expire->format( 'Y-m-d H:i:s' ) ); foreach ( $finder as $file ) { unlink( $file->getRealPath() ); } } //
php
{ "resource": "" }
q14702
FileCache.clear
train
public function clear() { if ( ! $this->enabled ) { return false; } $finder = $this->get_finder(); foreach ( $finder as
php
{ "resource": "" }
q14703
FileCache.prune
train
public function prune() { if ( ! $this->enabled ) { return false; } /** @var Finder $finder */ $finder = $this->get_finder()->sortByName(); $files_to_delete = array(); foreach ( $finder as $file ) { $pieces = explode( '-', $file->getBasename( $file->getExtension() ) ); $timestamp = end( $pieces ); // No way to compare versions, do nothing. if ( ! is_numeric( $timestamp ) ) { continue; } $basename_without_timestamp
php
{ "resource": "" }
q14704
FileCache.ensure_dir_exists
train
protected function ensure_dir_exists( $dir ) { if ( ! is_dir( $dir ) ) { // Disable the cache if a null device like /dev/null is being used. if ( preg_match( '{(^|[\\\\/])(\$null|nul|NUL|/dev/null)([\\\\/]|$)}', $dir ) ) { return false; } if ( ! @mkdir( $dir, 0777, true ) ) { $error = error_get_last();
php
{ "resource": "" }
q14705
FileCache.prepare_write
train
protected function prepare_write( $key ) { if ( ! $this->enabled ) { return false; } $filename = $this->filename( $key ); if (
php
{ "resource": "" }
q14706
FileCache.validate_key
train
protected function validate_key( $key ) { $url_parts = Utils\parse_url( $key, -1, false ); if ( ! empty( $url_parts['scheme'] ) ) { // is url $parts = array( 'misc' ); $parts[] = $url_parts['scheme'] . '-' . $url_parts['host'] . ( empty( $url_parts['port'] ) ? '' : '-' . $url_parts['port'] ); $parts[] = substr( $url_parts['path'], 1 ) . ( empty( $url_parts['query'] ) ? '' : '-' . $url_parts['query'] ); }
php
{ "resource": "" }
q14707
Execution.write
train
protected function write( $handle, $str ) { switch ( $handle ) { case STDOUT:
php
{ "resource": "" }
q14708
Inflector.ucwords
train
public static function ucwords( $string, $delimiters = " \n\t\r\0\x0B-" ) { return preg_replace_callback( '/[^' . preg_quote( $delimiters, '/' )
php
{ "resource": "" }
q14709
Inflector.pluralize
train
public static function pluralize( $word ) { if ( isset( self::$cache['pluralize'][ $word ] ) ) { return self::$cache['pluralize'][ $word ]; } if ( ! isset( self::$plural['merged']['irregular'] ) ) { self::$plural['merged']['irregular'] = self::$plural['irregular']; } if ( ! isset( self::$plural['merged']['uninflected'] ) ) { self::$plural['merged']['uninflected'] = array_merge( self::$plural['uninflected'], self::$uninflected ); } if ( ! isset( self::$plural['cacheUninflected'] ) || ! isset( self::$plural['cacheIrregular'] ) ) { self::$plural['cacheUninflected'] = '(?:' . implode( '|', self::$plural['merged']['uninflected']
php
{ "resource": "" }
q14710
SynopsisValidator.enough_positionals
train
public function enough_positionals( $args ) { $positional = $this->query_spec( array( 'type' => 'positional', 'optional' => false,
php
{ "resource": "" }
q14711
SynopsisValidator.unknown_positionals
train
public function unknown_positionals( $args ) { $positional_repeating = $this->query_spec( array( 'type' => 'positional', 'repeating' => true, ) ); // At least one positional supports as many as possible. if ( ! empty( $positional_repeating ) ) {
php
{ "resource": "" }
q14712
SynopsisValidator.validate_assoc
train
public function validate_assoc( $assoc_args ) { $assoc_spec = $this->query_spec( array( 'type' => 'assoc', ) ); $errors = array( 'fatal' => array(), 'warning' => array(), ); $to_unset = array(); foreach ( $assoc_spec as $param ) { $key = $param['name']; if ( ! isset( $assoc_args[ $key ] ) ) { if ( ! $param['optional'] ) { $errors['fatal'][ $key ] = "missing --$key parameter"; }
php
{ "resource": "" }
q14713
SynopsisValidator.unknown_assoc
train
public function unknown_assoc( $assoc_args ) { $generic = $this->query_spec( array( 'type' => 'generic', ) ); if ( count( $generic ) ) { return array(); } $known_assoc = array(); foreach ( $this->spec as $param )
php
{ "resource": "" }
q14714
SynopsisValidator.query_spec
train
private function query_spec( $args, $operator = 'AND' ) { $operator = strtoupper( $operator ); $count = count( $args ); $filtered = array(); foreach ( $this->spec as $key => $to_match ) { $matched = 0; foreach ( $args as $m_key => $m_value ) { if ( array_key_exists( $m_key, $to_match ) && $m_value === $to_match[ $m_key ] ) { $matched++; }
php
{ "resource": "" }
q14715
Autoloader.add_namespace
train
public function add_namespace( $root, $base_dir, $prefix = '', $suffix = '.php', $lowercase = false, $underscores = false ) { $this->namespaces[] = array( 'root' => $this->normalize_root( (string) $root ), 'base_dir' => $this->add_trailing_slash( (string) $base_dir ),
php
{ "resource": "" }
q14716
Autoloader.autoload
train
public function autoload( $class ) { // Iterate over namespaces to find a match. foreach ( $this->namespaces as $namespace ) { // Move on if the object does not belong to the current namespace. if ( 0 !== strpos( $class, $namespace['root'] ) ) { continue; } // Remove namespace root level to correspond with root filesystem, and // replace the namespace separator "\" by the system-dependent directory separator. $filename = str_replace( array( $namespace['root'], '\\' ), array( '', DIRECTORY_SEPARATOR ), $class ); // Remove a leading backslash from the class name. $filename = $this->remove_leading_backslash( $filename ); // Change to lower case if requested. if ( $namespace['lowercase'] ) { $filename = strtolower( $filename ); }
php
{ "resource": "" }
q14717
WpHttpCacheManager.filter_pre_http_request
train
public function filter_pre_http_request( $response, $args, $url ) { // check if whitelisted if ( ! isset( $this->whitelist[ $url ] ) ) { return $response; } // check if downloading if ( 'GET' !== $args['method'] || empty( $args['filename'] ) ) { return $response; } // check cache and export to designated location $filename = $this->cache->has( $this->whitelist[ $url ]['key'], $this->whitelist[ $url ]['ttl'] ); if ( $filename ) { WP_CLI::log( sprintf( 'Using cached file \'%s\'...', $filename ) ); if ( copy( $filename, $args['filename'] ) )
php
{ "resource": "" }
q14718
WpHttpCacheManager.filter_http_response
train
public function filter_http_response( $response, $args, $url ) { // check if whitelisted if ( ! isset( $this->whitelist[ $url ] ) ) { return $response; } // check if downloading if ( 'GET' !== $args['method'] || empty( $args['filename'] )
php
{ "resource": "" }
q14719
WpHttpCacheManager.whitelist_package
train
public function whitelist_package( $url, $group, $slug, $version, $ttl = null ) { $ext = pathinfo( Utils\parse_url( $url, PHP_URL_PATH ), PATHINFO_EXTENSION ); $key =
php
{ "resource": "" }
q14720
WpHttpCacheManager.whitelist_url
train
public function whitelist_url( $url, $key = null, $ttl = null ) { $key
php
{ "resource": "" }
q14721
AutoloaderStep.get_custom_vendor_folder
train
protected function get_custom_vendor_folder() { $maybe_composer_json = WP_CLI_ROOT . '/../../../composer.json'; if ( ! is_readable( $maybe_composer_json ) ) { return false; } $composer = json_decode( file_get_contents( $maybe_composer_json ) ); if
php
{ "resource": "" }
q14722
Subcommand.get_parameters
train
private function get_parameters( $spec = array() ) { $local_parameters = array_column( $spec, 'name' ); $global_parameters = array_column( WP_CLI\SynopsisParser::parse( $this->get_global_params() ),
php
{ "resource": "" }
q14723
Runner.register_early_invoke
train
public function register_early_invoke( $when, $command ) { $this->early_invoke[ $when
php
{ "resource": "" }
q14724
Runner.do_early_invoke
train
private function do_early_invoke( $when ) { if ( ! isset( $this->early_invoke[ $when ] ) ) { return; } // Search the value of @when from the command method. $real_when = ''; $r = $this->find_command_to_run( $this->arguments ); if ( is_array( $r ) ) { list( $command, $final_args, $cmd_path ) =
php
{ "resource": "" }
q14725
Runner.get_global_config_path
train
public function get_global_config_path() { if ( getenv( 'WP_CLI_CONFIG_PATH' ) ) { $config_path = getenv( 'WP_CLI_CONFIG_PATH' ); $this->global_config_path_debug = 'Using global config from WP_CLI_CONFIG_PATH env var: ' . $config_path; } else { $config_path = Utils\get_home_dir() . '/.wp-cli/config.yml';
php
{ "resource": "" }
q14726
Runner.get_project_config_path
train
public function get_project_config_path() { $config_files = array( 'wp-cli.local.yml', 'wp-cli.yml', ); // Stop looking upward when we find we have emerged from a subdirectory // installation into a parent installation $project_config_path = Utils\find_file_upward( $config_files, getcwd(), function (
php
{ "resource": "" }
q14727
Runner.get_packages_dir_path
train
public function get_packages_dir_path() { if ( getenv( 'WP_CLI_PACKAGES_DIR' ) ) { $packages_dir = Utils\trailingslashit( getenv( 'WP_CLI_PACKAGES_DIR' ) ); } else {
php
{ "resource": "" }
q14728
Runner.extract_subdir_path
train
private static function extract_subdir_path( $index_path ) { $index_code = file_get_contents( $index_path ); if ( ! preg_match( '|^\s*require\s*\(?\s*(.+?)/wp-blog-header\.php([\'"])|m', $index_code, $matches ) ) { return false; } $wp_path_src = $matches[1] . $matches[2]; $wp_path_src = Utils\replace_path_consts( $wp_path_src, $index_path
php
{ "resource": "" }
q14729
Runner.find_wp_root
train
private function find_wp_root() { if ( ! empty( $this->config['path'] ) ) { $path = $this->config['path']; if ( ! Utils\is_path_absolute( $path ) ) { $path = getcwd() . '/' . $path; } return $path; } if ( $this->cmd_starts_with( array( 'core', 'download' ) ) ) { return getcwd(); } $dir = getcwd(); while ( is_readable( $dir ) ) { if ( file_exists( "$dir/wp-load.php" ) ) { return $dir;
php
{ "resource": "" }
q14730
Runner.set_wp_root
train
private static function set_wp_root( $path ) { if ( ! defined( 'ABSPATH' ) ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedConstantFound -- Declaring a WP native constant. define( 'ABSPATH', Utils\normalize_path( Utils\trailingslashit( $path ) ) ); } elseif ( ! is_null( $path ) ) { WP_CLI::error_multi_line( array( 'The --path parameter cannot be used when
php
{ "resource": "" }
q14731
Runner.guess_url
train
private static function guess_url( $assoc_args ) { if ( isset( $assoc_args['blog'] ) ) { $assoc_args['url'] = $assoc_args['blog']; } if ( isset( $assoc_args['url'] ) ) { $url = $assoc_args['url']; if ( true === $url
php
{ "resource": "" }
q14732
Runner.find_command_to_run
train
public function find_command_to_run( $args ) { $command = \WP_CLI::get_root_command(); WP_CLI::do_hook( 'find_command_to_run_pre' ); $cmd_path = array(); while ( ! empty( $args ) && $command->can_have_subcommands() ) { $cmd_path[] = $args[0]; $full_name = implode( ' ', $cmd_path ); $subcommand = $command->find_subcommand( $args ); if ( ! $subcommand ) { if ( count( $cmd_path ) > 1 ) { $child = array_pop( $cmd_path ); $parent_name = implode( ' ', $cmd_path ); $suggestion = $this->get_subcommand_suggestion( $child, $command ); return sprintf( "'%s' is not a registered subcommand of '%s'. See 'wp help %s' for available subcommands.%s", $child, $parent_name, $parent_name, ! empty( $suggestion ) ? PHP_EOL . "Did you mean '{$suggestion}'?" : ''
php
{ "resource": "" }
q14733
Runner.run_command
train
public function run_command( $args, $assoc_args = array(), $options = array() ) { WP_CLI::do_hook( 'before_run_command' ); if ( ! empty( $options['back_compat_conversions'] ) ) { list( $args, $assoc_args ) = self::back_compat_conversions( $args, $assoc_args ); } $r = $this->find_command_to_run( $args ); if ( is_string( $r ) ) { WP_CLI::error( $r ); } list( $command, $final_args, $cmd_path ) = $r; $name = implode( ' ', $cmd_path );
php
{ "resource": "" }
q14734
Runner.show_synopsis_if_composite_command
train
public function show_synopsis_if_composite_command() { $r = $this->find_command_to_run( $this->arguments ); if ( is_array( $r ) ) { list( $command ) = $r;
php
{ "resource": "" }
q14735
Runner.generate_ssh_command
train
private function generate_ssh_command( $bits, $wp_command ) { $escaped_command = ''; // Set default values. foreach ( array( 'scheme', 'user', 'host', 'port', 'path' ) as $bit ) { if ( ! isset( $bits[ $bit ] ) ) { $bits[ $bit ] = null; } WP_CLI::debug( 'SSH ' . $bit . ': ' . $bits[ $bit ], 'bootstrap' ); } $is_tty = function_exists( 'posix_isatty' ) && posix_isatty( STDOUT ); if ( 'docker' === $bits['scheme'] ) { $command = 'docker exec %s%s%s sh -c %s'; $escaped_command = sprintf( $command, $bits['user'] ? '--user ' . escapeshellarg( $bits['user'] ) . ' ' : '', $is_tty ? '-t ' : '', escapeshellarg( $bits['host'] ), escapeshellarg( $wp_command ) ); } if ( 'docker-compose' === $bits['scheme'] ) { $command
php
{ "resource": "" }
q14736
Runner.is_command_disabled
train
public function is_command_disabled( $command ) { $path = implode( ' ', array_slice( \WP_CLI\Dispatcher\get_path( $command ), 1 ) ); return
php
{ "resource": "" }
q14737
Runner.get_wp_config_code
train
public function get_wp_config_code() { $wp_config_path = Utils\locate_wp_config(); $wp_config_code = explode( "\n", file_get_contents( $wp_config_path ) ); $found_wp_settings = false; $lines_to_run = array(); foreach ( $wp_config_code as $line ) { if ( preg_match( '/^\s*require.+wp-settings\.php/', $line ) ) { $found_wp_settings = true; continue; } $lines_to_run[] = $line; } if ( !
php
{ "resource": "" }
q14738
Runner.load_wordpress
train
public function load_wordpress() { static $wp_cli_is_loaded; // Globals not explicitly globalized in WordPress global $site_id, $wpdb, $public, $current_site, $current_blog, $path, $shortcode_tags; if ( ! empty( $wp_cli_is_loaded ) ) { return; } $wp_cli_is_loaded = true; WP_CLI::debug( 'Begin WordPress load', 'bootstrap' ); WP_CLI::do_hook( 'before_wp_load' ); $this->check_wp_version(); $wp_config_path = Utils\locate_wp_config(); if ( ! $wp_config_path ) { WP_CLI::error( "'wp-config.php' not found.\n" . 'Either create one manually or use `wp config create`.' ); } WP_CLI::debug( 'wp-config.php path: ' . $wp_config_path, 'bootstrap' ); WP_CLI::do_hook( 'before_wp_config_load' ); // Load wp-config.php code, in the global scope $wp_cli_original_defined_vars = get_defined_vars(); eval( $this->get_wp_config_code() ); // phpcs:ignore Squiz.PHP.Eval.Discouraged foreach ( get_defined_vars() as $key => $var ) { if ( array_key_exists( $key, $wp_cli_original_defined_vars ) || 'wp_cli_original_defined_vars' === $key ) { continue; } // phpcs:ignore PHPCompatibility.Variables.ForbiddenGlobalVariableVariable.NonBareVariableFound global ${$key}; // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound ${$key} = $var; } $this->maybe_update_url_from_domain_constant(); WP_CLI::do_hook( 'after_wp_config_load' ); $this->do_early_invoke( 'after_wp_config_load' ); // Prevent error notice from wp_guess_url() when core isn't installed if ( $this->cmd_starts_with( array( 'core', 'is-installed' ) ) && ! defined( 'COOKIEHASH' ) ) { define( 'COOKIEHASH', md5( 'wp-cli' ) ); } // Load WP-CLI utilities require WP_CLI_ROOT . '/php/utils-wp.php'; // Set up WordPress bootstrap actions and filters $this->setup_bootstrap_hooks(); // Load Core, mu-plugins, plugins, themes etc. if ( Utils\wp_version_compare( '4.6-alpha-37575', '>=' ) ) { if ( $this->cmd_starts_with( array( 'help' ) ) ) { // Hack: define `WP_DEBUG` and `WP_DEBUG_DISPLAY` to get
php
{ "resource": "" }
q14739
Runner.setup_skip_plugins_filters
train
private function setup_skip_plugins_filters() { $wp_cli_filter_active_plugins = function( $plugins ) { $skipped_plugins = WP_CLI::get_runner()->config['skip-plugins']; if ( true === $skipped_plugins ) { return array(); } if ( ! is_array( $plugins ) ) { return $plugins; } foreach ( $plugins as $a => $b ) { // active_sitewide_plugins stores plugin name as the key. if ( false !== strpos( current_filter(), 'active_sitewide_plugins' ) && Utils\is_plugin_skipped( $a ) ) { unset( $plugins[ $a ] ); // active_plugins stores plugin name as the value. } elseif ( false !== strpos( current_filter(), 'active_plugins' ) && Utils\is_plugin_skipped( $b ) ) { unset( $plugins[ $a ] ); } } // Reindex because active_plugins expects a numeric index. if ( false !== strpos( current_filter(), 'active_plugins' ) ) { $plugins = array_values( $plugins
php
{ "resource": "" }
q14740
Runner.action_setup_theme_wp_cli_skip_themes
train
public function action_setup_theme_wp_cli_skip_themes() { $wp_cli_filter_active_theme = function( $value ) { $skipped_themes = WP_CLI::get_runner()->config['skip-themes']; if ( true === $skipped_themes ) { return ''; } if ( ! is_array( $skipped_themes ) ) { $skipped_themes = explode( ',', $skipped_themes ); } $checked_value = $value; // Always check against the stylesheet value // This ensures a child theme can be skipped when template differs if ( false !== stripos( current_filter(), 'option_template' ) ) { $checked_value = get_option( 'stylesheet' ); } if ( '' === $checked_value || in_array( $checked_value, $skipped_themes, true ) ) { return ''; } return $value; }; $hooks
php
{ "resource": "" }
q14741
Runner.auto_check_update
train
private function auto_check_update() { // `wp cli update` only works with Phars at this time. if ( ! Utils\inside_phar() ) { return; } $existing_phar = realpath( $_SERVER['argv'][0] ); // Phar needs to be writable to be easily updateable. if ( ! is_writable( $existing_phar ) || ! is_writable( dirname( $existing_phar ) ) ) { return; } // Only check for update when a human is operating. if ( ! function_exists( 'posix_isatty' ) || ! posix_isatty( STDOUT ) ) { return; } // Allow hosts and other providers to disable automatic check update. if ( getenv( 'WP_CLI_DISABLE_AUTO_CHECK_UPDATE' ) ) { return; } // Permit configuration of number of days between checks. $days_between_checks = getenv( 'WP_CLI_AUTO_CHECK_UPDATE_DAYS' ); if ( false === $days_between_checks ) { $days_between_checks = 1; } $cache = WP_CLI::get_cache(); $cache_key = 'wp-cli-update-check'; // Bail early on the first check, so we don't always check on an unwritable cache. if ( ! $cache->has( $cache_key ) ) { $cache->write( $cache_key, time() ); return;
php
{ "resource": "" }
q14742
Runner.enumerate_commands
train
private function enumerate_commands( CompositeCommand $command, array &$list, $parent = '' ) { foreach ( $command->get_subcommands() as $subcommand ) { /** @var CompositeCommand $subcommand */ $command_string = empty( $parent ) ? $subcommand->get_name()
php
{ "resource": "" }
q14743
Extractor.extract
train
public static function extract( $tarball_or_zip, $dest ) { if ( preg_match( '/\.zip$/', $tarball_or_zip ) ) { return self::extract_zip( $tarball_or_zip, $dest ); } if ( preg_match( '/\.tar\.gz$/', $tarball_or_zip ) ) {
php
{ "resource": "" }
q14744
Extractor.extract_zip
train
private static function extract_zip( $zipfile, $dest ) { if ( ! class_exists( 'ZipArchive' ) ) { throw new \Exception( 'Extracting a zip file requires ZipArchive.' ); } $zip = new ZipArchive(); $res = $zip->open( $zipfile ); if ( true === $res ) { $tempdir = implode( DIRECTORY_SEPARATOR, array( dirname( $zipfile ), Utils\basename( $zipfile, '.zip' ), $zip->getNameIndex( 0 ),
php
{ "resource": "" }
q14745
Extractor.extract_tarball
train
private static function extract_tarball( $tarball, $dest ) { if ( class_exists( 'PharData' ) ) { try { $phar = new PharData( $tarball ); $tempdir = implode( DIRECTORY_SEPARATOR, array( dirname( $tarball ), Utils\basename( $tarball, '.tar.gz' ), $phar->getFilename(), ) ); $phar->extractTo( dirname( $tempdir ), null, true ); self::copy_overwrite_files( $tempdir, $dest ); self::rmdir( dirname( $tempdir ) ); return; } catch ( \Exception $e ) { WP_CLI::warning( "PharData failed, falling back to 'tar xz' (" . $e->getMessage() . ')' ); // Fall through to trying `tar xz` below } } // Note: directory must exist for tar --directory to
php
{ "resource": "" }
q14746
Extractor.copy_overwrite_files
train
public static function copy_overwrite_files( $source, $dest ) { $iterator = new RecursiveIteratorIterator( new RecursiveDirectoryIterator( $source, RecursiveDirectoryIterator::SKIP_DOTS ), RecursiveIteratorIterator::SELF_FIRST ); $error = 0; if ( ! is_dir( $dest ) ) { mkdir( $dest, 0777, true ); } foreach ( $iterator as $item ) { $dest_path = $dest . DIRECTORY_SEPARATOR . $iterator->getSubPathName(); if ( $item->isDir() ) { if ( ! is_dir( $dest_path ) ) { mkdir( $dest_path ); } } else { if ( file_exists( $dest_path ) && is_writable( $dest_path ) ) { copy( $item, $dest_path ); } elseif (
php
{ "resource": "" }
q14747
Extractor.rmdir
train
public static function rmdir( $dir ) { $files = new RecursiveIteratorIterator( new RecursiveDirectoryIterator( $dir, RecursiveDirectoryIterator::SKIP_DOTS ), RecursiveIteratorIterator::CHILD_FIRST ); foreach ( $files as $fileinfo ) {
php
{ "resource": "" }
q14748
Extractor.zip_error_msg
train
public static function zip_error_msg( $error_code ) { // From https://github.com/php/php-src/blob/php-5.3.0/ext/zip/php_zip.c#L2623-L2646 static $zip_err_msgs = array( ZipArchive::ER_OK => 'No error', ZipArchive::ER_MULTIDISK => 'Multi-disk zip archives not supported', ZipArchive::ER_RENAME => 'Renaming temporary file failed', ZipArchive::ER_CLOSE => 'Closing zip archive failed', ZipArchive::ER_SEEK => 'Seek error', ZipArchive::ER_READ => 'Read error', ZipArchive::ER_WRITE => 'Write error', ZipArchive::ER_CRC => 'CRC error', ZipArchive::ER_ZIPCLOSED => 'Containing zip archive was closed', ZipArchive::ER_NOENT => 'No such file', ZipArchive::ER_EXISTS => 'File already exists', ZipArchive::ER_OPEN => 'Can\'t open file', ZipArchive::ER_TMPOPEN => 'Failure to create temporary file', ZipArchive::ER_ZLIB => 'Zlib error',
php
{ "resource": "" }
q14749
Extractor.tar_error_msg
train
public static function tar_error_msg( $process_run ) { $stderr = trim( $process_run->stderr ); $nl_pos = strpos( $stderr, "\n" ); if ( false !== $nl_pos ) { $stderr = trim( substr( $stderr, 0, $nl_pos ) );
php
{ "resource": "" }
q14750
Base._line
train
protected function _line( $message, $label, $color, $handle = STDOUT ) { // phpcs:ignore PSR2.Methods.MethodDeclaration.Underscore -- Used in third party
php
{ "resource": "" }
q14751
InitializeLogger.declare_loggers
train
private function declare_loggers() { $logger_dir = WP_CLI_ROOT . '/php/WP_CLI/Loggers'; $iterator = new \DirectoryIterator( $logger_dir ); // Make sure the base class is declared first. include_once "$logger_dir/Base.php"; foreach ( $iterator as
php
{ "resource": "" }
q14752
CLI_Cache_Command.cache_clear
train
public function cache_clear() { $cache = WP_CLI::get_cache(); if ( ! $cache->is_enabled() ) { WP_CLI::error( 'Cache directory does
php
{ "resource": "" }
q14753
CLI_Cache_Command.cache_prune
train
public function cache_prune() { $cache = WP_CLI::get_cache(); if ( ! $cache->is_enabled() ) { WP_CLI::error( 'Cache directory does
php
{ "resource": "" }
q14754
RootCommand.find_subcommand
train
public function find_subcommand( &$args ) { $command = array_shift( $args ); Utils\load_command( $command ); if ( ! isset(
php
{ "resource": "" }
q14755
CommandFactory.create_subcommand
train
private static function create_subcommand( $parent, $name, $callable, $reflection ) { $doc_comment = self::get_doc_comment( $reflection ); $docparser = new \WP_CLI\DocParser( $doc_comment ); if ( is_array( $callable ) ) { if ( ! $name ) { $name = $docparser->get_tag( 'subcommand' ); } if ( ! $name ) { $name = $reflection->name; } } if ( ! $doc_comment ) { \WP_CLI::debug( null === $doc_comment ? "Failed to get doc comment for {$name}." : "No doc comment for {$name}.", 'commandfactory' ); } $when_invoked = function ( $args,
php
{ "resource": "" }
q14756
CommandFactory.create_composite_command
train
private static function create_composite_command( $parent, $name, $callable ) { $reflection = new ReflectionClass( $callable ); $doc_comment = self::get_doc_comment( $reflection ); if ( ! $doc_comment ) { \WP_CLI::debug( null === $doc_comment ? "Failed to get doc comment for {$name}." : "No doc comment for {$name}.", 'commandfactory' ); } $docparser = new \WP_CLI\DocParser( $doc_comment ); $container = new CompositeCommand( $parent, $name, $docparser ); foreach ( $reflection->getMethods() as $method ) { if ( ! self::is_good_method( $method ) )
php
{ "resource": "" }
q14757
CommandFactory.create_namespace
train
private static function create_namespace( $parent, $name, $callable ) { $reflection = new ReflectionClass( $callable ); $doc_comment = self::get_doc_comment( $reflection ); if ( ! $doc_comment ) { \WP_CLI::debug( null === $doc_comment ? "Failed to get doc comment for {$name}."
php
{ "resource": "" }
q14758
CommandFactory.get_doc_comment
train
private static function get_doc_comment( $reflection ) { $doc_comment = $reflection->getDocComment(); if ( false !== $doc_comment || ! ( ini_get( 'opcache.enable_cli' ) && ! ini_get( 'opcache.save_comments' ) ) ) { // Either have doc comment, or no doc comment and save comments enabled - standard situation. if ( ! getenv( 'WP_CLI_TEST_GET_DOC_COMMENT' ) ) { return $doc_comment; } } $filename = $reflection->getFileName(); if ( isset( self::$file_contents[ $filename ] ) ) { $contents = self::$file_contents[ $filename ]; } elseif ( is_readable( $filename ) ) { $contents = file_get_contents( $filename ); if ( is_string( $contents ) && '' !== $contents ) { $contents
php
{ "resource": "" }
q14759
Formatter.display_item
train
public function display_item( $item, $ascii_pre_colorized = false ) { if ( isset( $this->args['field'] ) ) { $item = (object) $item; $key = $this->find_item_key( $item, $this->args['field'] ); $value = $item->$key; if ( in_array( $this->args['format'], array(
php
{ "resource": "" }
q14760
Formatter.format
train
private function format( $items, $ascii_pre_colorized = false ) { $fields = $this->args['fields']; switch ( $this->args['format'] ) { case 'count': if ( ! is_array( $items ) ) { $items = iterator_to_array( $items ); } echo count( $items ); break; case 'ids': if ( ! is_array( $items ) ) { $items = iterator_to_array( $items ); } echo implode( ' ', $items ); break; case 'table': self::show_table( $items, $fields, $ascii_pre_colorized ); break; case 'csv': \WP_CLI\Utils\write_csv( STDOUT, $items, $fields ); break; case 'json': case 'yaml': $out = array(); foreach ( $items as $item ) { $out[] = \WP_CLI\Utils\pick_fields( $item, $fields ); }
php
{ "resource": "" }
q14761
Formatter.show_single_field
train
private function show_single_field( $items, $field ) { $key = null; $values = array(); foreach ( $items as $item ) { $item = (object) $item; if ( null === $key ) { $key = $this->find_item_key( $item, $field ); } if ( 'json' === $this->args['format'] ) { $values[] = $item->$key; } else { \WP_CLI::print_value(
php
{ "resource": "" }
q14762
Formatter.show_multiple_fields
train
private function show_multiple_fields( $data, $format, $ascii_pre_colorized = false ) { $true_fields = array(); foreach ( $this->args['fields'] as $field ) { $true_fields[] = $this->find_item_key( $data, $field ); } foreach ( $data as $key => $value ) { if ( ! in_array( $key, $true_fields, true ) ) { if ( is_array( $data ) ) { unset( $data[ $key ] ); } elseif ( is_object( $data ) ) { unset( $data->$key ); } } } switch ( $format ) { case 'table': case 'csv': $rows = $this->assoc_array_to_rows( $data ); $fields = array( 'Field', 'Value' ); if ( 'table' === $format ) {
php
{ "resource": "" }
q14763
Formatter.assoc_array_to_rows
train
private function assoc_array_to_rows( $fields ) { $rows = array(); foreach ( $fields as $field => $value ) { if ( ! is_string( $value ) ) { $value = json_encode( $value );
php
{ "resource": "" }
q14764
Formatter.transform_item_values_to_json
train
public function transform_item_values_to_json( $item ) { foreach ( $this->args['fields'] as $field ) { $true_field = $this->find_item_key( $item, $field ); $value = is_object( $item ) ? $item->$true_field : $item[
php
{ "resource": "" }
q14765
Help_Command.parse_reference_links
train
private static function parse_reference_links( $longdesc ) { $description = ''; foreach ( explode( "\n", $longdesc ) as $line ) { if ( 0 === strpos( $line, '#' ) ) { break; } $description .= $line . "\n"; } // Fires if it has description text at the head of `$longdesc`. if ( $description ) { $links = array(); // An array of URLs from the description. $pattern = '/\[.+?\]\((https?:\/\/.+?)\)/'; $newdesc = preg_replace_callback( $pattern, function( $matches ) use ( &$links ) { static $count = 0; $count++; $links[] = $matches[1]; return str_replace( '(' . $matches[1] . ')', '[' . $count . ']', $matches[0] ); }, $description
php
{ "resource": "" }
q14766
CompositeCommand.show_usage
train
public function show_usage() { $methods = $this->get_subcommands(); $i = 0; foreach ( $methods as $name => $subcommand ) { $prefix = ( 0 === $i ) ? 'usage: ' : ' or: '; $i++; if ( \WP_CLI::get_runner()->is_command_disabled( $subcommand )
php
{ "resource": "" }
q14767
CompositeCommand.find_subcommand
train
public function find_subcommand( &$args ) { $name = array_shift( $args ); $subcommands = $this->get_subcommands(); if ( ! isset( $subcommands[ $name ] ) )
php
{ "resource": "" }
q14768
CompositeCommand.get_aliases
train
private static function get_aliases( $subcommands ) { $aliases = array(); foreach ( $subcommands as
php
{ "resource": "" }
q14769
CLI_Command.info
train
public function info( $_, $assoc_args ) { $php_bin = Utils\get_php_binary(); // php_uname() $mode argument was only added with PHP 7.0+. Fall back to // entire string for older versions. $system_os = PHP_MAJOR_VERSION < 7 ? php_uname() : sprintf( '%s %s %s %s', php_uname( 's' ), php_uname( 'r' ), php_uname( 'v' ), php_uname( 'm' ) ); $shell = getenv( 'SHELL' ); if ( ! $shell && Utils\is_windows() ) { $shell = getenv( 'ComSpec' ); } $runner = WP_CLI::get_runner(); $packages_dir = $runner->get_packages_dir_path(); if ( ! is_dir( $packages_dir ) ) { $packages_dir = null; } if ( \WP_CLI\Utils\get_flag_value( $assoc_args, 'format' ) === 'json' ) { $info = array( 'php_binary_path' => $php_bin, 'global_config_path' => $runner->global_config_path, 'project_config_path' => $runner->project_config_path, 'wp_cli_dir_path' => WP_CLI_ROOT, 'wp_cli_packages_dir_path' => $packages_dir, 'wp_cli_version' => WP_CLI_VERSION, 'system_os' => $system_os, 'shell' => $shell, ); WP_CLI::line( json_encode( $info ) ); } else { WP_CLI::line( "OS:\t" . $system_os ); WP_CLI::line( "Shell:\t" . $shell );
php
{ "resource": "" }
q14770
CLI_Command.check_update
train
public function check_update( $_, $assoc_args ) { $updates = $this->get_updates( $assoc_args ); if ( $updates ) { $formatter = new \WP_CLI\Formatter( $assoc_args, array( 'version', 'update_type', 'package_url' ) ); $formatter->display_items( $updates ); } elseif ( empty(
php
{ "resource": "" }
q14771
CLI_Command.param_dump
train
public function param_dump( $_, $assoc_args ) { $spec = \WP_CLI::get_configurator()->get_spec(); if ( \WP_CLI\Utils\get_flag_value( $assoc_args, 'with-values' ) ) { $config = \WP_CLI::get_configurator()->to_array(); // Copy current config values to $spec foreach ( $spec as $key => $value ) { $current = null; if ( isset( $config[0][ $key ] ) ) {
php
{ "resource": "" }
q14772
CLI_Command.completions
train
public function completions( $_, $assoc_args ) { $line = substr( $assoc_args['line'],
php
{ "resource": "" }
q14773
CLI_Command.get_update_type_str
train
private function get_update_type_str( $assoc_args ) { $update_type = ' '; foreach ( array( 'major', 'minor', 'patch' )
php
{ "resource": "" }
q14774
CLI_Command.has_command
train
public function has_command( $_, $assoc_args ) { // If command is input as a string, then explode it into array. $command = explode( ' ', implode( ' ', $_ ) ); WP_CLI::halt(
php
{ "resource": "" }
q14775
CLI_Alias_Command.get
train
public function get( $args, $assoc_args ) { list( $alias ) = $args; $aliases = WP_CLI::get_runner()->aliases; if ( empty( $aliases[ $alias ] ) ) { WP_CLI::error( "No alias found with key '{$alias}'." );
php
{ "resource": "" }
q14776
CLI_Alias_Command.delete
train
public function delete( $args, $assoc_args ) { list( $alias ) = $args; $config = ( ! empty( $assoc_args['config'] ) ? $assoc_args['config'] : '' ); list( $config_path, $aliases ) = $this->get_aliases_data( $config, $alias ); $this->validate_config_file( $config_path ); if ( empty( $aliases[ $alias ]
php
{ "resource": "" }
q14777
CLI_Alias_Command.get_aliases_data
train
private function get_aliases_data( $config, $alias ) { $global_config_path = WP_CLI::get_runner()->get_global_config_path(); $global_aliases = Spyc::YAMLLoad( $global_config_path ); $project_config_path = WP_CLI::get_runner()->get_project_config_path(); $project_aliases = Spyc::YAMLLoad( $project_config_path ); if ( 'global' === $config ) { $config_path = $global_config_path; $aliases = $global_aliases; } elseif ( 'project' === $config
php
{ "resource": "" }
q14778
CLI_Alias_Command.build_aliases
train
private function build_aliases( $aliases, $alias, $assoc_args, $is_grouping, $grouping = '', $is_update = false ) { if ( $is_grouping ) { $valid_assoc_args = array( 'config', 'grouping' ); $invalid_args = array_diff( array_keys( $assoc_args ), $valid_assoc_args ); // Check for invalid args. if ( ! empty( $invalid_args ) ) { $args_info = implode( ',', $invalid_args ); WP_CLI::error( "--grouping argument works alone. Found invalid arg(s) '$args_info'." ); } } if ( $is_update ) { $this->validate_alias_type( $aliases, $alias, $assoc_args, $grouping ); } if ( ! $is_grouping ) { foreach ( $assoc_args as $key => $value ) { if ( strpos( $key, 'set-' ) !== false ) { $alias_key_info = explode( '-', $key ); $alias_key = empty( $alias_key_info[1]
php
{ "resource": "" }
q14779
CLI_Alias_Command.validate_input
train
private function validate_input( $assoc_args, $grouping ) { // Check if valid arguments were passed. $arg_match = preg_grep( '/^set-(\w+)/i', array_keys( $assoc_args ) ); // Verify passed-arguments. if ( empty( $grouping ) && empty( $arg_match )
php
{ "resource": "" }
q14780
CLI_Alias_Command.validate_alias_type
train
private function validate_alias_type( $aliases, $alias, $assoc_args, $grouping ) { $alias_data = $aliases[ $alias ]; $group_aliases_match = preg_grep( '/^@(\w+)/i', $alias_data ); $arg_match = preg_grep( '/^set-(\w+)/i', array_keys( $assoc_args
php
{ "resource": "" }
q14781
CLI_Alias_Command.process_aliases
train
private function process_aliases( $aliases, $alias, $config_path, $operation = '' ) { // Convert data to YAML string. $yaml_data =
php
{ "resource": "" }
q14782
DocParser.remove_decorations
train
private static function remove_decorations( $comment ) { $comment = preg_replace( '|^/\*\*[\r\n]+|', '', $comment ); $comment = preg_replace( '|\n[\t ]*\*/$|',
php
{ "resource": "" }
q14783
DocParser.get_longdesc
train
public function get_longdesc() { $shortdesc = $this->get_shortdesc(); if ( ! $shortdesc ) { return ''; } $longdesc = substr( $this->doc_comment, strlen( $shortdesc ) ); $lines = array(); foreach ( explode( "\n", $longdesc ) as
php
{ "resource": "" }
q14784
DocParser.get_arg_or_param_args
train
private function get_arg_or_param_args( $regex ) { $bits = explode( "\n", $this->doc_comment ); $within_arg = false; $within_doc = false; $document = array(); foreach ( $bits as $bit ) { if ( preg_match( $regex, $bit ) ) { $within_arg = true; } if ( $within_arg && $within_doc && '---' === $bit ) { $within_doc = false; } if ( $within_arg && ! $within_doc && '---' === $bit )
php
{ "resource": "" }
q14785
RegisterDeferredCommands.add_deferred_commands
train
public function add_deferred_commands() { $deferred_additions = \WP_CLI::get_deferred_additions(); foreach ( $deferred_additions as $name => $addition ) { \WP_CLI::debug( sprintf( 'Adding deferred command: %s => %s', $name, json_encode( $addition )
php
{ "resource": "" }
q14786
Contrib_List_Command.get_project_milestones
train
private static function get_project_milestones( $project, $args = array() ) { $request_url = sprintf(
php
{ "resource": "" }
q14787
Contrib_List_Command.parse_contributors_from_pull_requests
train
private static function parse_contributors_from_pull_requests( $pull_requests ) { $contributors = array(); foreach ( $pull_requests as $pull_request ) { if ( ! empty( $pull_request->user ) ) {
php
{ "resource": "" }
q14788
Contrib_List_Command.make_github_api_request
train
private static function make_github_api_request( $url, $args = array() ) { $headers = array( 'Accept' => 'application/vnd.github.v3+json', 'User-Agent' => 'WP-CLI', ); $token = getenv( 'GITHUB_TOKEN' ); if ( false !== $token ) { $headers['Authorization'] = 'token ' . $token; } $response = Utils\http_request( 'GET', $url, $args, $headers ); if ( 200 !== $response->status_code ) {
php
{ "resource": "" }
q14789
Query.adjust_offset_for_shrinking_result_set
train
private function adjust_offset_for_shrinking_result_set() { if ( empty( $this->count_query ) ) { return; } $row_count = $this->db->get_var( $this->count_query ); if (
php
{ "resource": "" }
q14790
Configurator.get_aliases
train
public function get_aliases() { $runtime_alias = getenv( 'WP_CLI_RUNTIME_ALIAS' ); if ( false !== $runtime_alias ) { $returned_aliases = array(); foreach ( json_decode( $runtime_alias, true ) as $key => $value ) { if ( preg_match( '#' . self::ALIAS_REGEX . '#', $key ) ) { $returned_aliases[ $key ] = array(); foreach ( self::$alias_spec as
php
{ "resource": "" }
q14791
Configurator.parse_args
train
public function parse_args( $arguments ) { list( $positional_args, $mixed_args, $global_assoc, $local_assoc ) = self::extract_assoc( $arguments ); list( $assoc_args, $runtime_config )
php
{ "resource": "" }
q14792
Configurator.extract_assoc
train
public static function extract_assoc( $arguments ) { $positional_args = array(); $assoc_args = array(); $global_assoc = array(); $local_assoc = array(); foreach ( $arguments as $arg ) { $positional_arg = null; $assoc_arg = null; if ( preg_match( '|^--no-([^=]+)$|', $arg, $matches ) ) { $assoc_arg = array( $matches[1], false ); } elseif ( preg_match( '|^--([^=]+)$|', $arg, $matches ) ) { $assoc_arg = array( $matches[1], true ); } elseif ( preg_match( '|^--([^=]+)=(.*)|s', $arg, $matches ) ) { $assoc_arg = array( $matches[1], $matches[2] ); } else { $positional = $arg; } if ( ! is_null( $assoc_arg ) ) { $assoc_args[] =
php
{ "resource": "" }
q14793
Configurator.unmix_assoc_args
train
private function unmix_assoc_args( $mixed_args, $global_assoc = array(), $local_assoc = array() ) { $assoc_args = array(); $runtime_config = array(); if ( getenv( 'WP_CLI_STRICT_ARGS_MODE' ) ) { foreach ( $global_assoc as $tmp ) { list( $key, $value ) = $tmp; if ( isset( $this->spec[ $key ] ) && false !== $this->spec[ $key ]['runtime'] ) { $this->assoc_arg_to_runtime_config( $key, $value, $runtime_config ); } } foreach ( $local_assoc as $tmp ) { $assoc_args[ $tmp[0] ] = $tmp[1]; } } else { foreach ( $mixed_args as $tmp ) { list( $key, $value ) = $tmp;
php
{ "resource": "" }
q14794
Configurator.merge_yml
train
public function merge_yml( $path, $current_alias = null ) { $yaml = self::load_yml( $path ); if ( ! empty( $yaml['_']['inherit'] ) ) { $this->merge_yml( $yaml['_']['inherit'], $current_alias ); } // Prepare the base path for absolutized alias paths $yml_file_dir = $path ? dirname( $path ) : false; foreach ( $yaml as $key => $value ) { if ( preg_match( '#' . self::ALIAS_REGEX . '#', $key ) ) { $this->aliases[ $key ] = array(); $is_alias = false; foreach ( self::$alias_spec as $i ) { if ( isset( $value[ $i ] ) ) { if ( 'path' === $i && ! isset( $value['ssh'] ) ) { self::absolutize( $value[ $i ], $yml_file_dir ); } $this->aliases[ $key ][ $i ] = $value[ $i ]; $is_alias = true; } } // If it's not an alias, it might be a group of aliases if ( ! $is_alias && is_array( $value ) ) { $alias_group = array(); foreach ( $value as $i => $k ) { if ( preg_match( '#' . self::ALIAS_REGEX . '#', $k ) ) { $alias_group[] = $k; } } $this->aliases[ $key ] = $alias_group;
php
{ "resource": "" }
q14795
Configurator.merge_array
train
public function merge_array( $config ) { foreach ( $this->spec as $key => $details ) { if ( false !== $details['runtime'] && isset( $config[ $key ] ) ) { $value = $config[ $key ]; if ( 'require' === $key ) { $value = \WP_CLI\Utils\expand_globs( $value ); } if ( $details['multiple'] ) {
php
{ "resource": "" }
q14796
Configurator.load_yml
train
private static function load_yml( $yml_file ) { if ( ! $yml_file ) { return array(); } $config = Spyc::YAMLLoad( $yml_file ); // Make sure config-file-relative paths are made absolute. $yml_file_dir = dirname( $yml_file ); if ( isset( $config['path'] ) ) { self::absolutize( $config['path'], $yml_file_dir ); } if ( isset( $config['require'] ) ) { self::arrayify( $config['require'] ); $config['require'] = \WP_CLI\Utils\expand_globs( $config['require'] ); foreach ( $config['require'] as &$path ) { self::absolutize( $path, $yml_file_dir ); } } // Backwards compat // Command 'core config' was moved to 'config create'. if ( isset( $config['core config'] ) ) { $config['config create'] = $config['core config']; unset( $config['core config'] ); } // Command 'checksum core' was moved to
php
{ "resource": "" }
q14797
Configurator.absolutize
train
private static function absolutize( &$path, $base ) { if ( ! empty( $path
php
{ "resource": "" }
q14798
WP_CLI.set_url
train
public static function set_url( $url ) { self::debug( 'Set URL: ' .
php
{ "resource": "" }
q14799
WP_CLI.add_hook
train
public static function add_hook( $when, $callback ) { if ( array_key_exists( $when, self::$hooks_passed ) ) { self::debug( sprintf( 'Immediately invoking on passed hook "%s": %s', $when, Utils\describe_callable( $callback ) ), 'hooks' );
php
{ "resource": "" }