WordPress.org

Make WordPress Core

Ticket #21479: 21479.1.patch

File 21479.1.patch, 2.3 KB (added by iandstewart, 21 months ago)

Modifying ryanimel's patch to flush out the cool cats when a user delete's categories too (and props to ryanimel for catching that right away)

  • wp-content/themes/twentytwelve/functions.php

     
    316316        // Translators: 1 is category, 2 is tag, 3 is the date and 4 is the author's name. 
    317317        if ( '' != $tag_list ) { 
    318318                $utility_text = __( 'This entry was posted in %1$s and tagged %2$s on %3$s by %4$s.', 'twentytwelve' ); 
    319         } elseif ( '' != $categories_list ) { 
     319        } elseif ( '' != $categories_list && twentytwelve_categorized_site() ) { 
    320320                $utility_text = __( 'This entry was posted in %1$s on %3$s by %4$s.', 'twentytwelve' ); 
    321321        } else { 
    322322                $utility_text = __( 'This entry was posted on %3$s by %4$s.', 'twentytwelve' ); 
     
    333333endif; 
    334334 
    335335/** 
     336 * Returns true if a blog has more than one category. 
     337 *  
     338 * (Cribbed from _s theme.) 
     339 * 
     340 * @since Twenty Twelve 1.0 
     341 */ 
     342function twentytwelve_categorized_site() { 
     343        if ( false === ( $all_the_cool_cats = get_transient( 'twentytwelve_all_the_cool_cats' ) ) ) { 
     344                // Create an array of all the categories that are attached to posts 
     345                $all_the_cool_cats = get_categories( array( 
     346                        'hide_empty' => 1, 
     347                ) ); 
     348 
     349                // Count the number of categories that are attached to posts 
     350                $all_the_cool_cats = count( $all_the_cool_cats ); 
     351 
     352                set_transient( 'twentytwelve_all_the_cool_cats', $all_the_cool_cats ); 
     353        } 
     354 
     355        if ( '1' != $all_the_cool_cats ) { 
     356                // This site has more than 1 category so twentytwelve_categorized_site should return true 
     357                return true; 
     358        } else { 
     359                // This site has only 1 category so twentytwelve_categorized_site should return false 
     360                return false; 
     361        } 
     362} 
     363 
     364/** 
     365 * Flush out the transients used in twentytwelve_categorized_site 
     366 * 
     367 * @since Twenty Twelve 1.0 
     368 */ 
     369function twentytwelve_category_transient_flusher() { 
     370        // Like, beat it. Dig? 
     371        delete_transient( 'twentytwelve_all_the_cool_cats' ); 
     372} 
     373add_action( 'edit_category', 'twentytwelve_category_transient_flusher' ); 
     374add_action( 'delete_category', 'twentytwelve_category_transient_flusher' ); 
     375add_action( 'save_post', 'twentytwelve_category_transient_flusher' ); 
     376 
     377 
     378/** 
    336379 * Extends the default WordPress body class to denote: 
    337380 * 1. Using a full-width layout, when no active widgets in the sidebar 
    338381 *    or full-width template.