[ Index ] |
PHP Cross Reference of WordPress |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Generated classname block support flag. 4 * 5 * @package WordPress 6 */ 7 8 /** 9 * Get the generated classname from a given block name. 10 * 11 * @since 5.6.0 12 * 13 * @access private 14 * 15 * @param string $block_name Block Name. 16 * @return string Generated classname. 17 */ 18 function wp_get_block_default_classname( $block_name ) { 19 // Generated HTML classes for blocks follow the `wp-block-{name}` nomenclature. 20 // Blocks provided by WordPress drop the prefixes 'core/' or 'core-' (historically used in 'core-embed/'). 21 $classname = 'wp-block-' . preg_replace( 22 '/^core-/', 23 '', 24 str_replace( '/', '-', $block_name ) 25 ); 26 27 /** 28 * Filters the default block className for server rendered blocks. 29 * 30 * @since 5.6.0 31 * 32 * @param string $class_name The current applied classname. 33 * @param string $block_name The block name. 34 */ 35 $classname = apply_filters( 'block_default_classname', $classname, $block_name ); 36 37 return $classname; 38 } 39 40 /** 41 * Add the generated classnames to the output. 42 * 43 * @since 5.6.0 44 * 45 * @access private 46 * 47 * @param WP_Block_Type $block_type Block Type. 48 * @param array $block_attributes Block attributes. 49 * 50 * @return array Block CSS classes and inline styles. 51 */ 52 function wp_apply_generated_classname_support( $block_type, $block_attributes ) { 53 $has_generated_classname_support = true; 54 $attributes = array(); 55 if ( property_exists( $block_type, 'supports' ) ) { 56 $has_generated_classname_support = _wp_array_get( $block_type->supports, array( 'className' ), true ); 57 } 58 if ( $has_generated_classname_support ) { 59 $block_classname = wp_get_block_default_classname( $block_type->name ); 60 61 if ( $block_classname ) { 62 $attributes['class'] = $block_classname; 63 } 64 } 65 66 return $attributes; 67 } 68 69 // Register the block support. 70 WP_Block_Supports::get_instance()->register( 71 'generated-classname', 72 array( 73 'apply' => 'wp_apply_generated_classname_support', 74 ) 75 );
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sat Apr 10 01:00:03 2021 | Cross-referenced by PHPXref 0.7.1 |