Make WordPress Core

Ticket #33720: 33720_add_ech_arg_wp_terms_checklist.diff

File 33720_add_ech_arg_wp_terms_checklist.diff, 3.4 KB (added by kevinlangleyjr, 10 years ago)

Adding echo arg to wp_terms_checklist() function to allow returning of the generated markup or echo by default

  • wp-admin/includes/template.php

     
    169169 * @param array|string $args {
    170170 *     Optional. Array or string of arguments for generating a terms checklist. Default empty array.
    171171 *
    172  *     @type int    $descendants_and_self ID of the category to output along with its descendants.
    173  *                                        Default 0.
    174  *     @type array  $selected_cats        List of categories to mark as checked. Default false.
    175  *     @type array  $popular_cats         List of categories to receive the "popular-category" class.
    176  *                                        Default false.
    177  *     @type object $walker               Walker object to use to build the output.
    178  *                                        Default is a Walker_Category_Checklist instance.
    179  *     @type string $taxonomy             Taxonomy to generate the checklist for. Default 'category'.
    180  *     @type bool   $checked_ontop        Whether to move checked items out of the hierarchy and to
    181  *                                        the top of the list. Default true.
     172 *     @type int      $descendants_and_self ID of the category to output along with its descendants.
     173 *                                          Default 0.
     174 *     @type array    $selected_cats        List of categories to mark as checked. Default false.
     175 *     @type array    $popular_cats         List of categories to receive the "popular-category" class.
     176 *                                          Default false.
     177 *     @type object   $walker               Walker object to use to build the output.
     178 *                                          Default is a Walker_Category_Checklist instance.
     179 *     @type string   $taxonomy             Taxonomy to generate the checklist for. Default 'category'.
     180 *     @type bool     $checked_ontop        Whether to move checked items out of the hierarchy and to
     181 *                                          the top of the list. Default true.
     182 *     @type bool|int $echo                 Whether to echo or return the generated markup. Accepts 0, 1, or their
     183 *                                          bool equivalents. Default 1.
    182184 * }
    183185 */
    184186function wp_terms_checklist( $post_id = 0, $args = array() ) {
     
    188190                'popular_cats' => false,
    189191                'walker' => null,
    190192                'taxonomy' => 'category',
    191                 'checked_ontop' => true
     193                'checked_ontop' => true,
     194                'echo' => 1
    192195        );
    193196
    194197        /**
     
    251254                $categories = (array) get_terms( $taxonomy, array( 'get' => 'all' ) );
    252255        }
    253256
     257        $output = '';
     258
    254259        if ( $r['checked_ontop'] ) {
    255260                // Post process $categories rather than adding an exclude to the get_terms() query to keep the query the same across all posts (for any query cache)
    256261                $checked_categories = array();
     
    264269                }
    265270
    266271                // Put checked cats on top
    267                 echo call_user_func_array( array( $walker, 'walk' ), array( $checked_categories, 0, $args ) );
     272                $output .= call_user_func_array( array( $walker, 'walk' ), array( $checked_categories, 0, $args ) );
    268273        }
    269274        // Then the rest of them
    270         echo call_user_func_array( array( $walker, 'walk' ), array( $categories, 0, $args ) );
     275        $output .= call_user_func_array( array( $walker, 'walk' ), array( $categories, 0, $args ) );
     276
     277        if( $r['echo'] ){
     278                echo $output;
     279        }
     280
     281        return $output;
    271282}
    272283
    273284/**