WordPress.org

Make WordPress Core

Ticket #21578: term_meta.2.diff

File term_meta.2.diff, 5.0 KB (added by hughwillfayle, 21 months ago)

Replaced Doc Errors

  • wp-includes/taxonomy.php

     
    32843278 
    32853279        return $parent; 
    32863280} 
     3281 
     3282/** 
     3283 * Retrieve term meta field for a term. 
     3284 * 
     3285 * @since 3.5.0 
     3286 * @link http://codex.wordpress.org/Function_Reference/get_term_meta 
     3287 * 
     3288 * @param int $term_id Term ID. 
     3289 * @param string $key Optional. The meta key to retrieve. By default, returns data for all keys. 
     3290 * @param bool $single Whether to return a single value. 
     3291 * @return mixed Will be an array if $single is false. Will be value of meta data field if $single 
     3292 *  is true. 
     3293 */ 
     3294function get_term_meta( $term_id, $key = '', $single = FALSE ) { 
     3295        return get_metadata( 'term', $term_id, $key, $single ); 
     3296} 
     3297 
     3298/** 
     3299 * Update term meta field based on term ID. 
     3300 * 
     3301 * Use the $prev_value parameter to differentiate between meta fields with the 
     3302 * same key and term ID. 
     3303 * 
     3304 * If the meta field for the term does not exist, it will be added. 
     3305 * 
     3306 * @since 3.5.0 
     3307 * @uses $wpdb 
     3308 * @link http://codex.wordpress.org/Function_Reference/update_term_meta 
     3309 * 
     3310 * @param int $term_id Term ID. 
     3311 * @param string $meta_key Metadata key. 
     3312 * @param mixed $meta_value Metadata value. 
     3313 * @param mixed $prev_value Optional. Previous value to check before removing. 
     3314 * @return bool False on failure, true if success. 
     3315 */ 
     3316function update_term_meta( $term_id, $meta_key, $meta_value, $prev_value = '' ) { 
     3317 
     3318        return update_metadata( 'term', $term_id, $meta_key, $meta_value, $prev_value ); 
     3319} 
     3320 
     3321/** 
     3322 * Delete everything from term meta matching meta key. 
     3323 * 
     3324 * @since 3.5.0 
     3325 * @uses $wpdb 
     3326 * 
     3327 * @param string $term_meta_key Key to search for when deleting. 
     3328 * @return bool Whether the term meta key was deleted from the database 
     3329 */ 
     3330function delete_term_meta_by_key( $term_meta_key ) { 
     3331        return delete_metadata( 'term', null, $term_meta_key, '', TRUE ); 
     3332} 
     3333 
     3334/** 
     3335 * Retrieve term meta fields, based on term ID. 
     3336 * 
     3337 * The term meta fields are retrieved from the cache where possible, 
     3338 * so the function is optimized to be called more than once. 
     3339 * 
     3340 * @since 3.5.0 
     3341 * @link http://codex.wordpress.org/Function_Reference/get_term_custom 
     3342 * 
     3343 * @param int $term_id term ID. 
     3344 * @return array 
     3345 */ 
     3346function get_term_custom( $term_id = 0 ) { 
     3347        $term_id = absint( $term_id ); 
     3348        if ( ! $term_id ) 
     3349                $term_id = get_the_ID(); 
     3350 
     3351        return get_term_meta( $term_id ); 
     3352} 
     3353 
     3354/** 
     3355 * Retrieve meta field names for a term. 
     3356 * 
     3357 * If there are no meta fields, then nothing (null) will be returned. 
     3358 * 
     3359 * @since 3.5.0 
     3360 * @link http://codex.wordpress.org/Function_Reference/get_term_custom_keys 
     3361 * 
     3362 * @param int $term_id term ID 
     3363 * @return array|null Either array of the keys, or null if keys could not be retrieved. 
     3364 */ 
     3365function get_term_custom_keys( $term_id = 0 ) { 
     3366        $custom = get_term_custom( $term_id ); 
     3367 
     3368        if ( ! is_array( $custom ) ) 
     3369                return; 
     3370 
     3371        if ( $keys = array_keys( $custom ) ) 
     3372                return $keys; 
     3373} 
     3374 
     3375/** 
     3376 * Retrieve values for a custom term field. 
     3377 * 
     3378 * The parameters must not be considered optional. All of the term meta fields 
     3379 * will be retrieved and only the meta field key values returned. 
     3380 * 
     3381 * @since 3.5.0 
     3382 * @link http://codex.wordpress.org/Function_Reference/get_term_custom_values 
     3383 * 
     3384 * @param string $key Meta field key. 
     3385 * @param int $term_id Term ID 
     3386 * @return array Meta field values. 
     3387 */ 
     3388function get_term_custom_values( $key = '', $term_id = 0 ) { 
     3389        if ( ! $key ) 
     3390                return null; 
     3391 
     3392        $custom = get_term_custom( $term_id ); 
     3393 
     3394        return isset( $custom[ $key ] ) ? $custom[ $key ] : null; 
     3395} 
     3396 No newline at end of file 
  • wp-includes/wp-db.php

     
    197197         * @var array 
    198198         */ 
    199199        var $tables = array( 'posts', 'comments', 'links', 'options', 'postmeta', 
    200                 'terms', 'term_taxonomy', 'term_relationships', 'commentmeta' ); 
     200                'terms', 'termmeta', 'term_taxonomy', 'term_relationships', 'commentmeta' ); 
    201201 
    202202        /** 
    203203         * List of deprecated WordPress tables 
     
    294294         * @var string 
    295295         */ 
    296296        var $terms; 
     297         
     298        /** 
     299         * WordPress Term meta table 
     300         * 
     301         * @since 3.5.0 
     302         * @access public 
     303         * @var string 
     304         */ 
     305        var $termmeta; 
    297306 
    298307        /** 
    299308         * WordPress Term Relationships table 
  • wp-admin/includes/schema.php

     
    5454 UNIQUE KEY slug (slug), 
    5555 KEY name (name) 
    5656) $charset_collate; 
     57CREATE TABLE $wpdb->termmeta ( 
     58  meta_id bigint(20) unsigned NOT NULL auto_increment, 
     59  term_id bigint(20) unsigned NOT NULL default '0', 
     60  meta_key varchar(255) default NULL, 
     61  meta_value longtext, 
     62  PRIMARY KEY  (meta_id), 
     63  KEY term_id (term_id), 
     64  KEY meta_key (meta_key) 
     65) $charset_collate; 
    5766CREATE TABLE $wpdb->term_taxonomy ( 
    5867 term_taxonomy_id bigint(20) unsigned NOT NULL auto_increment, 
    5968 term_id bigint(20) unsigned NOT NULL default 0,