Make WordPress Core


Ignore:
Timestamp:
09/04/2015 09:24:04 PM (11 years ago)
Author:
boonebgorges
Message:

Allow wp_terms_checklist() to return markup rather than echoing it.

Props kevinlangleyjr.
Fixes #33720.

File:
1 edited

Legend:

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

    r33891 r33904  
    165165 *
    166166 * @since 3.0.0
     167 * @since 4.4.0 Introduced the `$echo` argument.
    167168 *
    168169 * @param int          $post_id Optional. Post ID. Default 0.
    … …  
    180181 *     @type bool   $checked_ontop        Whether to move checked items out of the hierarchy and to
    181182 *                                        the top of the list. Default true.
     183 *     @type bool   $echo                 Whether to echo the generated markup. False to return the markup instead
     184 *                                        of echoing it. Default true.
    182185 * }
    183186 */
    … …  
    189192                'walker' => null,
    190193                'taxonomy' => 'category',
    191                 'checked_ontop' => true
     194                'checked_ontop' => true,
     195                'echo' => true,
    192196        );
    193197
    … …  
    252256        }
    253257
     258        $output = '';
     259
    254260        if ( $r['checked_ontop'] ) {
    255261                // 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)
    … …  
    265271
    266272                // Put checked cats on top
    267                 echo call_user_func_array( array( $walker, 'walk' ), array( $checked_categories, 0, $args ) );
     273                $output .= call_user_func_array( array( $walker, 'walk' ), array( $checked_categories, 0, $args ) );
    268274        }
    269275        // Then the rest of them
    270         echo call_user_func_array( array( $walker, 'walk' ), array( $categories, 0, $args ) );
     276        $output .= call_user_func_array( array( $walker, 'walk' ), array( $categories, 0, $args ) );
     277
     278        if ( $r['echo'] ) {
     279                echo $output;
     280        }
     281
     282        return $output;
    271283}
    272284
Note: See TracChangeset for help on using the changeset viewer.