Make WordPress Core


Ignore:
Timestamp:
09/05/2013 11:31:28 PM (12 years ago)
Author:
wonderboymusic
Message:

Move get_meta_type() into the WP_Meta_Query class as get_cast_for_type(). WP_Query can then access it like: $this->meta_query->get_cast_for_type().

See #21621, [25255].

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/meta.php

    r25255 r25269  
    604604}
    605605
    606 /**
    607  * Given a meta type, return the appropriate alias if applicable
    608  *
    609  * @since 3.7.0
    610  *
    611  * @see WP_Meta_Query
    612  *
    613  * @param string $type MySQL type to cast meta_value
    614  * @return string MySQL type
    615  */
    616 function get_meta_type( $type = '' ) {
    617     if ( empty( $type ) )
    618         return 'CHAR';
    619 
    620     $meta_type = strtoupper( $type );
    621 
    622     if ( ! in_array( $meta_type, array( 'BINARY', 'CHAR', 'DATE', 'DATETIME', 'DECIMAL', 'SIGNED', 'TIME', 'UNSIGNED', 'NUMERIC' ) ) )
    623         return 'CHAR';
    624 
    625     if ( 'NUMERIC' == $meta_type )
    626         $meta_type = 'SIGNED';
    627 
    628     return $meta_type;
    629 }
    630606/**
    631607 * Container class for a multiple metadata query
     
    714690
    715691    /**
     692     * Given a meta type, return the appropriate alias if applicable
     693     *
     694     * @since 3.7.0
     695     *
     696     * @param string $type MySQL type to cast meta_value
     697     * @return string MySQL type
     698     */
     699    function get_cast_for_type( $type = '' ) {
     700        if ( empty( $type ) )
     701            return 'CHAR';
     702
     703        $meta_type = strtoupper( $type );
     704
     705        if ( ! in_array( $meta_type, array( 'BINARY', 'CHAR', 'DATE', 'DATETIME', 'DECIMAL', 'SIGNED', 'TIME', 'UNSIGNED', 'NUMERIC' ) ) )
     706            return 'CHAR';
     707
     708        if ( 'NUMERIC' == $meta_type )
     709            $meta_type = 'SIGNED';
     710
     711        return $meta_type;
     712    }
     713
     714    /**
    716715     * Generates SQL clauses to be appended to a main query.
    717716     *
     
    769768        foreach ( $queries as $k => $q ) {
    770769            $meta_key = isset( $q['key'] ) ? trim( $q['key'] ) : '';
    771             $meta_type = get_meta_type( isset( $q['type'] ) ? $q['type'] : '' );
     770            $meta_type = $this->get_cast_for_type( isset( $q['type'] ) ? $q['type'] : '' );
    772771
    773772            $meta_value = isset( $q['value'] ) ? $q['value'] : null;
Note: See TracChangeset for help on using the changeset viewer.