Edit File by line
/home/barbar84/www/wp-inclu.../blocks
File: categories.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Server-side rendering of the `core/categories` block.
[2] Fix | Delete
*
[3] Fix | Delete
* @package WordPress
[4] Fix | Delete
*/
[5] Fix | Delete
[6] Fix | Delete
/**
[7] Fix | Delete
* Renders the `core/categories` block on server.
[8] Fix | Delete
*
[9] Fix | Delete
* @param array $attributes The block attributes.
[10] Fix | Delete
*
[11] Fix | Delete
* @return string Returns the categories list/dropdown markup.
[12] Fix | Delete
*/
[13] Fix | Delete
function render_block_core_categories( $attributes ) {
[14] Fix | Delete
static $block_id = 0;
[15] Fix | Delete
$block_id++;
[16] Fix | Delete
[17] Fix | Delete
$args = array(
[18] Fix | Delete
'echo' => false,
[19] Fix | Delete
'hierarchical' => ! empty( $attributes['showHierarchy'] ),
[20] Fix | Delete
'orderby' => 'name',
[21] Fix | Delete
'show_count' => ! empty( $attributes['showPostCounts'] ),
[22] Fix | Delete
'title_li' => '',
[23] Fix | Delete
);
[24] Fix | Delete
[25] Fix | Delete
if ( ! empty( $attributes['displayAsDropdown'] ) ) {
[26] Fix | Delete
$id = 'wp-block-categories-' . $block_id;
[27] Fix | Delete
$args['id'] = $id;
[28] Fix | Delete
$args['show_option_none'] = __( 'Select Category' );
[29] Fix | Delete
$wrapper_markup = '<div %1$s>%2$s</div>';
[30] Fix | Delete
$items_markup = wp_dropdown_categories( $args );
[31] Fix | Delete
$type = 'dropdown';
[32] Fix | Delete
[33] Fix | Delete
if ( ! is_admin() ) {
[34] Fix | Delete
// Inject the dropdown script immediately after the select dropdown.
[35] Fix | Delete
$items_markup = preg_replace(
[36] Fix | Delete
'#(?<=</select>)#',
[37] Fix | Delete
build_dropdown_script_block_core_categories( $id ),
[38] Fix | Delete
$items_markup,
[39] Fix | Delete
1
[40] Fix | Delete
);
[41] Fix | Delete
}
[42] Fix | Delete
} else {
[43] Fix | Delete
$wrapper_markup = '<ul %1$s>%2$s</ul>';
[44] Fix | Delete
$items_markup = wp_list_categories( $args );
[45] Fix | Delete
$type = 'list';
[46] Fix | Delete
}
[47] Fix | Delete
[48] Fix | Delete
$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => "wp-block-categories-{$type}" ) );
[49] Fix | Delete
[50] Fix | Delete
return sprintf(
[51] Fix | Delete
$wrapper_markup,
[52] Fix | Delete
$wrapper_attributes,
[53] Fix | Delete
$items_markup
[54] Fix | Delete
);
[55] Fix | Delete
}
[56] Fix | Delete
[57] Fix | Delete
/**
[58] Fix | Delete
* Generates the inline script for a categories dropdown field.
[59] Fix | Delete
*
[60] Fix | Delete
* @param string $dropdown_id ID of the dropdown field.
[61] Fix | Delete
*
[62] Fix | Delete
* @return string Returns the dropdown onChange redirection script.
[63] Fix | Delete
*/
[64] Fix | Delete
function build_dropdown_script_block_core_categories( $dropdown_id ) {
[65] Fix | Delete
ob_start();
[66] Fix | Delete
?>
[67] Fix | Delete
<script type='text/javascript'>
[68] Fix | Delete
/* <![CDATA[ */
[69] Fix | Delete
( function() {
[70] Fix | Delete
var dropdown = document.getElementById( '<?php echo esc_js( $dropdown_id ); ?>' );
[71] Fix | Delete
function onCatChange() {
[72] Fix | Delete
if ( dropdown.options[ dropdown.selectedIndex ].value > 0 ) {
[73] Fix | Delete
location.href = "<?php echo home_url(); ?>/?cat=" + dropdown.options[ dropdown.selectedIndex ].value;
[74] Fix | Delete
}
[75] Fix | Delete
}
[76] Fix | Delete
dropdown.onchange = onCatChange;
[77] Fix | Delete
})();
[78] Fix | Delete
/* ]]> */
[79] Fix | Delete
</script>
[80] Fix | Delete
<?php
[81] Fix | Delete
return ob_get_clean();
[82] Fix | Delete
}
[83] Fix | Delete
[84] Fix | Delete
/**
[85] Fix | Delete
* Registers the `core/categories` block on server.
[86] Fix | Delete
*/
[87] Fix | Delete
function register_block_core_categories() {
[88] Fix | Delete
register_block_type_from_metadata(
[89] Fix | Delete
__DIR__ . '/categories',
[90] Fix | Delete
array(
[91] Fix | Delete
'render_callback' => 'render_block_core_categories',
[92] Fix | Delete
)
[93] Fix | Delete
);
[94] Fix | Delete
}
[95] Fix | Delete
add_action( 'init', 'register_block_core_categories' );
[96] Fix | Delete
[97] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function