Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
07/14/2021 04:44:28 PM (5 years ago)
Author:
imath
Message:

Merge the BP Blocks plugin's 'bp/friends' Block

  • introduce the bp_get_dynamic_template_part() function which let you use a JavaScript template inside PHP thanks to the bp_core_replace_tokens_in_text() function.
  • Adds a new assets/widgets/friends.php JavaScript template to our two template packs.
  • Adds a new Core JavaScript file which acts like a parent class to all dynamic widgets front-end scripts (friends, groups, members).
  • Add this front-end script to the Friends component.
  • Adapt Grunt sass tasks.
  • Add the Block JavaScript source files into src/js/bp-friends/js/blocks.
  • Add the Block Scss source file into src/bp-friends/sass.
  • Generate the development files to ease testing.

Fixes #8521

File:
1 edited

Legend:

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

    r12726 r13002  
    8686function bp_get_asset_template_part( $slug, $name = null, $args = array() ) {
    8787        return bp_get_template_part( "assets/{$slug}", $name, $args );
     88}
     89
     90/**
     91 * Get a dynamic template part.
     92 *
     93 * @since 9.0.0
     94 *
     95 * @param string $template     The Template Pack's relative path to the templata.
     96 *                             Optional.
     97 * @param string $type         Whether to use the template for JavaScript or PHP.
     98 *                             Optional. Defaults to `js`.
     99 * @param array  $tokens       The data to use to customize the template. Optional.
     100 * @param array  $allowed_tags The allowed tags to use. Optional.
     101 * @return string HTML/JS output.
     102 */
     103function bp_get_dynamic_template_part( $template = '', $type = 'js', $tokens = array(), $allowed_tags = array() ) {
     104        $template_string = '';
     105
     106        if ( ! $template ) {
     107                return '';
     108        }
     109
     110        // Use the BP Theme Compat API to allow template override.
     111        $template_path = bp_locate_template( $template );
     112        if ( $template_path ) {
     113                $template_string = file_get_contents( $template_path );
     114        }
     115
     116        if ( ! $template_string ) {
     117                return '';
     118        }
     119
     120        if ( ! $allowed_tags ) {
     121                $allowed_tags = array(
     122                        'li'   => array( 'class' => true ),
     123                        'div'  => array( 'class' => true ),
     124                        'span' => array( 'class' => true ),
     125                        'a'    => array(
     126                                'href'            => true,
     127                                'class'           => true,
     128                                'data-bp-tooltip' => true,
     129                        ),
     130                        'img'  => array(
     131                                'src'     => true,
     132                                'class'   => true,
     133                                'loading' => true,
     134                        ),
     135                );
     136        }
     137
     138        if ( 'js' !== $type ) {
     139                $template_string = wp_kses( $template_string, $allowed_tags );
     140
     141                return bp_core_replace_tokens_in_text( $template_string, $tokens );
     142        }
     143
     144        return $template_string;
    88145}
    89146
Note: See TracChangeset for help on using the changeset viewer.