Making WordPress.org


Ignore:
Timestamp:
05/23/2014 05:48:41 AM (10 years ago)
Author:
coffee2code
Message:

Code Reference: Separate get_current_version() into functions to retrieve actual version and one to retrieve its term object. See #484.

  • get_current_version() now returns a string of the actual version of parsed WP code (or best effort)
  • Prefer 'wp_parser_imported_wp_version' option value as set in newer version of parser
  • Add get_current_version_term() to return wp-parser-since term object for the major version of parsed WP code
  • Add argument to permit get_current_version_term() to return term object for actual version
File:
1 edited

Legend:

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

    r610 r638  
    250250
    251251    /**
    252      * Get current (latest) since major version (X.Y.0) term object.
    253      *
     252     * Get current version of the parsed WP code.
     253     *
     254     * Prefers the 'wp_parser_imported_wp_version' option value set by more
     255     * recent versions of the parser. Failing that, it checks the
     256     * WP_CORE_LATEST_RELEASE constant (set on wp.org) though this is not
     257     * guaranteed to be the latest parsed version. Failing that, it uses a
     258     * hardcoded value, which isn't guaranteed either.
     259     *
     260     * @return string
     261     */
     262    function get_current_version() {
     263        $current_version = get_option( 'wp_parser_imported_wp_version' );
     264
     265        if ( empty( $current_version ) ) {
     266            $current_version = defined( 'WP_CORE_LATEST_RELEASE' ) ? WP_CORE_LATEST_RELEASE : '3.9.1';
     267        }
     268
     269        return $current_version;
     270    }
     271
     272    /**
     273     * Get current (latest) version of the parsed WP code as a wp-parser-since
     274     * term object.
     275     *
     276     * By default returns the major version (X.Y.0) term object because minor
     277     * releases rarely add enough, if any, new things to feature.
     278     *
     279     * @param  boolean $ignore_minor Use the major release version X.Y.0 instead of the actual version X.Y.Z?
    254280     * @return object
    255281     */
    256     function get_current_version() {
    257 
    258         $current_version = defined( 'WP_CORE_LATEST_RELEASE' ) ? WP_CORE_LATEST_RELEASE : '3.9';
    259         $version_parts = explode( '.', $current_version, 3 );
    260         if ( count( $version_parts ) == 2 ) {
    261             $version_parts[] = '0';
    262         } else {
    263             $version_parts[2] = '0';
    264         }
    265         $current_version = implode( '.', $version_parts );
     282    function get_current_version_term( $ignore_minor = true ) {
     283        $current_version = get_current_version();
     284
     285        if ( $ignore_minor ) {
     286            $version_parts = explode( '.', $current_version, 3 );
     287            if ( count( $version_parts ) == 2 ) {
     288                $version_parts[] = '0';
     289            } else {
     290                $version_parts[2] = '0';
     291            }
     292            $current_version = implode( '.', $version_parts );
     293        }
    266294
    267295        $version = get_terms( 'wp-parser-since', array(
     
    570598
    571599}
    572 
Note: See TracChangeset for help on using the changeset viewer.