Skip to:
Content

BuddyPress.org

Changeset 12726


Ignore:
Timestamp:
09/19/2020 06:19:45 PM (4 years ago)
Author:
dcavins
Message:

Pass extra args to template loading files.

Starting in WordPress 5.5, the template loading
functions will now allow additional arguments to be
passed through to the matched template file using a
new $args parameter.

This changeset passes an extra argument through
the BuddyPress template loading wrapper functions
to the underlying WordPress functions.

Props imath.

Fixes #8350.

Location:
trunk
Files:
3 added
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-core/bp-core-template-loader.php

    r12546 r12726  
    1919 *
    2020 * @since 1.7.0
     21 * @since 7.0.0 Added $args parameter.
    2122 *
    2223 * @param string      $slug Template part slug. Used to generate filenames,
     
    2425 * @param string|null $name Optional. Template part name. Used to generate
    2526 *                          secondary filenames, eg 'personal' for 'activity-personal.php'.
     27 * @param array       $args Optional. Extra args to pass to locate_template().
    2628 * @return false|string Path to located template. See {@link bp_locate_template()}.
    2729 */
    28 function bp_get_template_part( $slug, $name = null ) {
     30function bp_get_template_part( $slug, $name = null, $args = array() ) {
    2931
    3032    /**
     
    3436     *
    3537     * @since 1.7.0
     38     * @since 7.0.0 Added $args parameter.
    3639     *
    3740     * @param string $slug Template part slug requested.
    3841     * @param string $name Template part name requested.
    39      */
    40     do_action( 'get_template_part_' . $slug, $slug, $name );
     42     * @param array  $args Extra args to pass to locate_template().
     43     */
     44    do_action( 'get_template_part_' . $slug, $slug, $name, $args );
    4145
    4246    // Setup possible parts.
     
    5155     *
    5256     * @since 1.7.0
     57     * @since 7.0.0 Added $args parameter.
    5358     *
    5459     * @param array  $templates Array of templates located.
    5560     * @param string $slug      Template part slug requested.
    5661     * @param string $name      Template part name requested.
    57      */
    58     $templates = apply_filters( 'bp_get_template_part', $templates, $slug, $name );
     62     * @param array  $args      Extra args to pass to locate_template().
     63     */
     64    $templates = apply_filters( 'bp_get_template_part', $templates, $slug, $name, $args );
    5965
    6066    // Return the part that is found.
    61     return bp_locate_template( $templates, true, false );
     67    return bp_locate_template( $templates, true, false, $args );
    6268}
    6369
     
    6975 *
    7076 * @since 2.6.0
     77 * @since 7.0.0 Added $args parameter.
    7178 *
    7279 * @see bp_get_template_part() for full documentation.
     
    7481 * @param string      $slug Template slug.
    7582 * @param string|null $name Template name.
     83 * @param array       $args Optional. Extra args to pass to locate_template().
    7684 * @return false|string
    7785 */
    78 function bp_get_asset_template_part( $slug, $name = null ) {
    79     return bp_get_template_part( "assets/{$slug}", $name );
     86function bp_get_asset_template_part( $slug, $name = null, $args = array() ) {
     87    return bp_get_template_part( "assets/{$slug}", $name, $args );
    8088}
    8189
     
    8896 *
    8997 * @since 1.7.0
     98 * @since 7.0.0 Added $args parameter.
    9099 *
    91100 * @param string|array $template_names Template file(s) to search for, in order.
     
    94103 * @param bool         $require_once   Optional. Whether to require_once or require. Has
    95104 *                                     no effect if $load is false. Default: true.
     105 * @param array        $args           Optional. Extra args to pass to locate_template().
    96106 * @return string The template filename if one is located.
    97107 */
    98 function bp_locate_template( $template_names, $load = false, $require_once = true ) {
     108function bp_locate_template( $template_names, $load = false, $require_once = true, $args = array() ) {
    99109
    100110    // Bail when there are no templates to locate.
     
    141151     * 'bp_get_template_part' or add a new location to the template stack.
    142152     */
    143     do_action( 'bp_locate_template', $located, $template_name, $template_names, $template_locations, $load, $require_once );
     153    do_action( 'bp_locate_template', $located, $template_name, $template_names, $template_locations, $load, $require_once, $args );
    144154
    145155    /**
     
    153163
    154164    if ( $load_template && $load && ! empty( $located ) ) {
    155         load_template( $located, $require_once );
     165        load_template( $located, $require_once, $args );
    156166    }
    157167
     
    321331 *
    322332 * @since 1.7.0
    323  *
    324  * @see bp_get_template_part() for a description of $slug and $name params.
     333 * @since 7.0.0 Added $args parameter.
     334 *
     335 * @see bp_get_template_part() for a description of $slug, $name and $args params.
    325336 *
    326337 * @param string      $slug See {@link bp_get_template_part()}.
     
    328339 * @param bool        $echo If true, template content will be echoed. If false,
    329340 *                          returned. Default: true.
     341 * @param array       $args See {@link bp_get_template_part()}.
    330342 * @return string|null If $echo, returns the template content.
    331343 */
    332 function bp_buffer_template_part( $slug, $name = null, $echo = true ) {
     344function bp_buffer_template_part( $slug, $name = null, $echo = true, $args = array() ) {
    333345    ob_start();
    334346
     
    336348    remove_filter( 'the_content', 'bp_replace_the_content' );
    337349
    338     bp_get_template_part( $slug, $name );
     350    bp_get_template_part( $slug, $name, $args );
    339351
    340352    // Remove 'bp_replace_the_content' filter to prevent infinite loops.
Note: See TracChangeset for help on using the changeset viewer.