Changeset 12998
- Timestamp:
- 07/14/2021 08:52:00 AM (4 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-core/bp-core-blocks.php
r12995 r12998 163 163 return new BP_Block( $args ); 164 164 } 165 166 /** 167 * Gets a Widget Block list of classnames. 168 * 169 * @since 9.0.0 170 * 171 * @param string $block_name The Block name. 172 * @return array The list of widget classnames for the Block. 173 */ 174 function bp_blocks_get_widget_block_classnames( $block_name = '' ) { 175 $components = bp_core_get_active_components( array(), 'objects' ); 176 $components['core'] = buddypress()->core; 177 $classnames = array(); 178 179 foreach ( $components as $component ) { 180 if ( isset( $component->block_globals[ $block_name ] ) ) { 181 $block_props = $component->block_globals[ $block_name ]->props; 182 183 if ( isset( $block_props['widget_classnames'] ) && $block_props['widget_classnames'] ) { 184 $classnames = (array) $block_props['widget_classnames']; 185 break; 186 } 187 } 188 } 189 190 return $classnames; 191 } 192 193 /** 194 * Make sure the BP Widget Block classnames are included into Widget Blocks. 195 * 196 * @since 9.0.0 197 * 198 * @param string $classname The classname to be used in the block widget's container HTML. 199 * @param string $block_name The name of the block. 200 * @return string The classname to be used in the block widget's container HTML. 201 */ 202 function bp_widget_block_dynamic_classname( $classname, $block_name ) { 203 $bp_classnames = bp_blocks_get_widget_block_classnames( $block_name ); 204 205 if ( $bp_classnames ) { 206 $bp_classnames = array_map( 'sanitize_html_class', $bp_classnames ); 207 $classname .= ' ' . implode( ' ', $bp_classnames ); 208 } 209 210 return $classname; 211 } 212 add_filter( 'widget_block_dynamic_classname', 'bp_widget_block_dynamic_classname', 10, 2 ); -
trunk/src/bp-core/bp-core-template.php
r12997 r12998 3873 3873 ); 3874 3874 3875 if ( $block_name ) {3875 if ( $block_name && bp_is_running_wp( '5.0.0', '>=' ) ) { 3876 3876 $widget_blocks = get_option( 'widget_block', array() ); 3877 3877 $sidebars = wp_get_sidebars_widgets(); -
trunk/src/bp-core/classes/class-bp-component.php
r12994 r12998 140 140 */ 141 141 public $search_query_arg = 's'; 142 143 /** 144 * An array of globalized data for BP Blocks. 145 * 146 * @since 9.0.0 147 * 148 * @var array 149 */ 150 public $block_globals = array(); 142 151 143 152 /** Methods ***************************************************************/ … … 206 215 * 207 216 * @since 1.5.0 208 * 217 * @since 9.0.0 Adds the `$block_globals` argument to the `$args` parameter. 209 218 * 210 219 * @param array $args { … … 222 231 * @type array $global_tables Optional. An array of database table names. 223 232 * @type array $meta_tables Optional. An array of metadata table names. 233 * @type array $block_globals Optional. An array of globalized data for BP Blocks. 224 234 * } 225 235 */ … … 242 252 'global_tables' => '', 243 253 'meta_tables' => '', 254 'block_globals' => array(), 244 255 ) ); 245 256 … … 306 317 if ( ! empty( $r['meta_tables'] ) ) { 307 318 $this->register_meta_tables( $r['meta_tables'] ); 319 } 320 321 /** 322 * Filters the $blocks global value. 323 * 324 * @since 9.0.0 325 * 326 * @param array $blocks a list of global properties for blocks keyed 327 * by their corresponding block name. 328 */ 329 $block_globals = apply_filters( 'bp_' . $this->id . '_block_globals', $r['block_globals'] ); 330 if ( is_array( $block_globals ) && array_filter( $block_globals ) ) { 331 foreach ( $block_globals as $block_name => $block_props ) { 332 $this->block_globals[ $block_name ] = new stdClass(); 333 334 // Initialize an `items` property for Widget Block occurrences. 335 $this->block_globals[ $block_name ]->items = array(); 336 337 // Set the global properties for the Block. 338 $this->block_globals[ $block_name ]->props = (array) $block_props; 339 } 308 340 } 309 341 -
trunk/tests/phpunit/testcases/core/class-bp-component.php
r12994 r12998 2 2 3 3 include_once BP_TESTS_DIR . '/assets/bp-rest-api-controllers.php'; 4 include_once BP_TESTS_DIR . '/assets/class-bptest-component.php'; 4 5 5 6 /** … … 69 70 ) ); 70 71 } 72 73 /** 74 * @group bp_blocks 75 */ 76 public function test_component_block_globals() { 77 $expected = array( 78 'dynamic_widget_classname' => 'widget_example_classname', 79 ); 80 81 $example = new BPTest_Component( 82 array( 83 'globals' => array( 84 'block_globals' => array( 85 'bp/example-block' => $expected, 86 ) 87 ), 88 ) 89 ); 90 91 do_action( 'bp_setup_globals' ); 92 93 $this->assertEquals( $expected, $example->block_globals['bp/example-block']->props ); 94 } 71 95 }
Note: See TracChangeset
for help on using the changeset viewer.