--- a/wp/wp-includes/blocks/categories.php Thu Sep 29 08:06:27 2022 +0200
+++ b/wp/wp-includes/blocks/categories.php Fri Sep 05 18:40:08 2025 +0200
@@ -8,13 +8,15 @@
/**
* Renders the `core/categories` block on server.
*
+ * @since 5.0.0
+ *
* @param array $attributes The block attributes.
*
* @return string Returns the categories list/dropdown markup.
*/
function render_block_core_categories( $attributes ) {
static $block_id = 0;
- $block_id++;
+ ++$block_id;
$args = array(
'echo' => false,
@@ -22,6 +24,7 @@
'orderby' => 'name',
'show_count' => ! empty( $attributes['showPostCounts'] ),
'title_li' => '',
+ 'hide_empty' => empty( $attributes['showEmpty'] ),
);
if ( ! empty( $attributes['showOnlyTopLevel'] ) && $attributes['showOnlyTopLevel'] ) {
$args['parent'] = 0;
@@ -62,6 +65,8 @@
/**
* Generates the inline script for a categories dropdown field.
*
+ * @since 5.0.0
+ *
* @param string $dropdown_id ID of the dropdown field.
*
* @return string Returns the dropdown onChange redirection script.
@@ -69,25 +74,25 @@
function build_dropdown_script_block_core_categories( $dropdown_id ) {
ob_start();
?>
- <script type='text/javascript'>
- /* <![CDATA[ */
+ <script>
( function() {
var dropdown = document.getElementById( '<?php echo esc_js( $dropdown_id ); ?>' );
function onCatChange() {
if ( dropdown.options[ dropdown.selectedIndex ].value > 0 ) {
- location.href = "<?php echo home_url(); ?>/?cat=" + dropdown.options[ dropdown.selectedIndex ].value;
+ location.href = "<?php echo esc_url( home_url() ); ?>/?cat=" + dropdown.options[ dropdown.selectedIndex ].value;
}
}
dropdown.onchange = onCatChange;
})();
- /* ]]> */
</script>
<?php
- return ob_get_clean();
+ return wp_get_inline_script_tag( str_replace( array( '<script>', '</script>' ), '', ob_get_clean() ) );
}
/**
* Registers the `core/categories` block on server.
+ *
+ * @since 5.0.0
*/
function register_block_core_categories() {
register_block_type_from_metadata(