Making WordPress.org

Changeset 7718


Ignore:
Timestamp:
10/04/2018 09:21:01 PM (7 years ago)
Author:
coffee2code
Message:

developer.wordpress.org: Add WP-CLI command last-parsed with subcommands date, import-dir, and version.

Ex: wp devhub last-parsed version

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/cli-commands.php

    r7717 r7718  
    141141    }
    142142
     143    /**
     144     * Returns information pertaining to the last parsing.
     145     *
     146     * ## OPTIONS
     147     *
     148     * <key>
     149     * : The information from the last parsing to obtain. One of: 'date', 'import-dir', 'version'.
     150     *
     151     * ## EXAMPLES
     152     *
     153     *     wp devhub last-parsed version
     154     *
     155     * @when after_wp_load
     156     * @subcommand last-parsed
     157     */
     158    public function last_parsed( $args, $assoc_args ) {
     159        list( $key ) = $args;
     160
     161        $valid_values = array(
     162            'date'       => 'wp_parser_last_import',
     163            'import-dir' => 'wp_parser_root_import_dir',
     164            'version'    => 'wp_parser_imported_wp_version',
     165        );
     166
     167        if ( empty( $valid_values[ $key ] ) ) {
     168            WP_CLI::error( 'Invalid value provided. Must be one of: ' . implode( ', ', array_keys( $valid_values ) ) );
     169        }
     170
     171        $option = $valid_values[ $key ];
     172
     173        $value = get_option( $option );
     174
     175        if ( 'date' === $key ) {
     176            $value = date_i18n( 'Y-m-d H:i', $value );
     177        }
     178
     179        if ( ! $value ) {
     180            WP_CLI::error( 'No value from previous parsing of WordPress source was detected.' );
     181        } else {
     182            WP_CLI::log( $value );
     183        }
     184    }
     185
    143186}
    144187
Note: See TracChangeset for help on using the changeset viewer.