WP_Widget_Block::get_dynamic_classname()
Calculates the classname to use in the block widget's container HTML.
Usually this is set to $this->widget_options['classname'] by dynamic_sidebar(). In this case, however, we want to set the classname dynamically depending on the block contained by this block widget.
If a block widget contains a block that has an equivalent legacy widget, we display that legacy widget's class name. This helps with theme backwards compatibility.
Метод класса: WP_Widget_Block{}
Хуки из метода
Возвращает
Строку
. The classname to use in the block widget's container HTML.
Использование
// private - только в коде основоного (родительского) класса $result = $this->get_dynamic_classname( $content );
- $content(строка) (обязательный)
- The HTML content of the current block widget.
Список изменений
С версии 5.8.0 | Введена. |
Код WP_Widget_Block::get_dynamic_classname() WP Widget Block::get dynamic classname WP 6.8
private function get_dynamic_classname( $content ) { $blocks = parse_blocks( $content ); $block_name = isset( $blocks[0] ) ? $blocks[0]['blockName'] : null; switch ( $block_name ) { case 'core/paragraph': $classname = 'widget_block widget_text'; break; case 'core/calendar': $classname = 'widget_block widget_calendar'; break; case 'core/search': $classname = 'widget_block widget_search'; break; case 'core/html': $classname = 'widget_block widget_custom_html'; break; case 'core/archives': $classname = 'widget_block widget_archive'; break; case 'core/latest-posts': $classname = 'widget_block widget_recent_entries'; break; case 'core/latest-comments': $classname = 'widget_block widget_recent_comments'; break; case 'core/tag-cloud': $classname = 'widget_block widget_tag_cloud'; break; case 'core/categories': $classname = 'widget_block widget_categories'; break; case 'core/audio': $classname = 'widget_block widget_media_audio'; break; case 'core/video': $classname = 'widget_block widget_media_video'; break; case 'core/image': $classname = 'widget_block widget_media_image'; break; case 'core/gallery': $classname = 'widget_block widget_media_gallery'; break; case 'core/rss': $classname = 'widget_block widget_rss'; break; default: $classname = 'widget_block'; } /** * The classname used in the block widget's container HTML. * * This can be set according to the name of the block contained by the block widget. * * @since 5.8.0 * * @param string $classname The classname to be used in the block widget's container HTML, * e.g. 'widget_block widget_text'. * @param string $block_name The name of the block contained by the block widget, * e.g. 'core/paragraph'. */ return apply_filters( 'widget_block_dynamic_classname', $classname, $block_name ); }