Make WordPress Core


Ignore:
Timestamp:
12/12/2007 05:14:00 AM (17 years ago)
Author:
ryan
Message:

Defer term counting during import. Props tellyworth. fixes #5377

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/taxonomy.php

    r6364 r6376  
    13181318}
    13191319
     1320// enable or disable term count deferring
     1321// if no value is supplied, the current value of the defer setting is returned
     1322function wp_defer_term_counting($defer=NULL) {
     1323    static $_defer = false;
     1324   
     1325    if ( is_bool($defer) ) {
     1326        $_defer = $defer;
     1327        // flush any deferred counts
     1328        if ( !$defer )
     1329            wp_update_term_count( NULL, NULL, true );
     1330    }
     1331   
     1332    return $_defer;
     1333}
     1334
    13201335/**
    13211336 * wp_update_term_count() - Updates the amount of terms in taxonomy
     
    13351350 * @return bool If no terms will return false, and if successful will return true.
    13361351 */
    1337 function wp_update_term_count( $terms, $taxonomy ) {
    1338     global $wpdb;
     1352function wp_update_term_count( $terms, $taxonomy, $do_deferred=false ) {
     1353    static $_deferred = array();
     1354
     1355    if ( $do_deferred ) {
     1356        foreach ( array_keys($_deferred) as $tax ) {
     1357            wp_update_term_count_now( $_deferred[$tax], $tax );
     1358            unset( $_deferred[$tax] );
     1359        }
     1360    }
    13391361
    13401362    if ( empty($terms) )
     
    13431365    if ( !is_array($terms) )
    13441366        $terms = array($terms);
     1367
     1368    if ( wp_defer_term_counting() ) {
     1369        if ( !isset($_deferred[$taxonomy]) )
     1370            $_deferred[$taxonomy] = array();
     1371        $_deferred[$taxonomy] = array_unique( array_merge($_deferred[$taxonomy], $terms) );
     1372        return true;
     1373    }
     1374   
     1375    return wp_update_term_count_now( $terms, $taxonomy );
     1376}
     1377
     1378function wp_update_term_count_now( $terms, $taxonomy ) {
     1379    global $wpdb;
    13451380
    13461381    $terms = array_map('intval', $terms);
Note: See TracChangeset for help on using the changeset viewer.