Edit File by line
/home/zeestwma/richards.../wp-inclu.../blocks
File: archives.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Server-side rendering of the `core/archives` block.
[2] Fix | Delete
*
[3] Fix | Delete
* @package WordPress
[4] Fix | Delete
*/
[5] Fix | Delete
[6] Fix | Delete
/**
[7] Fix | Delete
* Renders the `core/archives` block on server.
[8] Fix | Delete
*
[9] Fix | Delete
* @since 5.0.0
[10] Fix | Delete
*
[11] Fix | Delete
* @see WP_Widget_Archives
[12] Fix | Delete
*
[13] Fix | Delete
* @param array $attributes The block attributes.
[14] Fix | Delete
*
[15] Fix | Delete
* @return string Returns the post content with archives added.
[16] Fix | Delete
*/
[17] Fix | Delete
function render_block_core_archives( $attributes ) {
[18] Fix | Delete
$show_post_count = ! empty( $attributes['showPostCounts'] );
[19] Fix | Delete
$type = isset( $attributes['type'] ) ? $attributes['type'] : 'monthly';
[20] Fix | Delete
[21] Fix | Delete
$class = 'wp-block-archives-list';
[22] Fix | Delete
[23] Fix | Delete
if ( ! empty( $attributes['displayAsDropdown'] ) ) {
[24] Fix | Delete
[25] Fix | Delete
$class = 'wp-block-archives-dropdown';
[26] Fix | Delete
[27] Fix | Delete
$dropdown_id = wp_unique_id( 'wp-block-archives-' );
[28] Fix | Delete
$title = __( 'Archives' );
[29] Fix | Delete
[30] Fix | Delete
/** This filter is documented in wp-includes/widgets/class-wp-widget-archives.php */
[31] Fix | Delete
$dropdown_args = apply_filters(
[32] Fix | Delete
'widget_archives_dropdown_args',
[33] Fix | Delete
array(
[34] Fix | Delete
'type' => $type,
[35] Fix | Delete
'format' => 'option',
[36] Fix | Delete
'show_post_count' => $show_post_count,
[37] Fix | Delete
)
[38] Fix | Delete
);
[39] Fix | Delete
[40] Fix | Delete
$dropdown_args['echo'] = 0;
[41] Fix | Delete
[42] Fix | Delete
$archives = wp_get_archives( $dropdown_args );
[43] Fix | Delete
[44] Fix | Delete
$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $class ) );
[45] Fix | Delete
[46] Fix | Delete
switch ( $dropdown_args['type'] ) {
[47] Fix | Delete
case 'yearly':
[48] Fix | Delete
$label = __( 'Select Year' );
[49] Fix | Delete
break;
[50] Fix | Delete
case 'monthly':
[51] Fix | Delete
$label = __( 'Select Month' );
[52] Fix | Delete
break;
[53] Fix | Delete
case 'daily':
[54] Fix | Delete
$label = __( 'Select Day' );
[55] Fix | Delete
break;
[56] Fix | Delete
case 'weekly':
[57] Fix | Delete
$label = __( 'Select Week' );
[58] Fix | Delete
break;
[59] Fix | Delete
default:
[60] Fix | Delete
$label = __( 'Select Post' );
[61] Fix | Delete
break;
[62] Fix | Delete
}
[63] Fix | Delete
[64] Fix | Delete
$show_label = empty( $attributes['showLabel'] ) ? ' screen-reader-text' : '';
[65] Fix | Delete
[66] Fix | Delete
$block_content = '<label for="' . $dropdown_id . '" class="wp-block-archives__label' . $show_label . '">' . esc_html( $title ) . '</label>
[67] Fix | Delete
<select id="' . esc_attr( $dropdown_id ) . '" name="archive-dropdown">
[68] Fix | Delete
<option value="">' . esc_html( $label ) . '</option>' . $archives . '</select>';
[69] Fix | Delete
[70] Fix | Delete
// Inject the dropdown script immediately after the select dropdown.
[71] Fix | Delete
$block_content .= block_core_archives_build_dropdown_script( $dropdown_id );
[72] Fix | Delete
[73] Fix | Delete
return sprintf(
[74] Fix | Delete
'<div %1$s>%2$s</div>',
[75] Fix | Delete
$wrapper_attributes,
[76] Fix | Delete
$block_content
[77] Fix | Delete
);
[78] Fix | Delete
}
[79] Fix | Delete
[80] Fix | Delete
/** This filter is documented in wp-includes/widgets/class-wp-widget-archives.php */
[81] Fix | Delete
$archives_args = apply_filters(
[82] Fix | Delete
'widget_archives_args',
[83] Fix | Delete
array(
[84] Fix | Delete
'type' => $type,
[85] Fix | Delete
'show_post_count' => $show_post_count,
[86] Fix | Delete
)
[87] Fix | Delete
);
[88] Fix | Delete
[89] Fix | Delete
$archives_args['echo'] = 0;
[90] Fix | Delete
[91] Fix | Delete
$archives = wp_get_archives( $archives_args );
[92] Fix | Delete
[93] Fix | Delete
$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $class ) );
[94] Fix | Delete
[95] Fix | Delete
if ( empty( $archives ) ) {
[96] Fix | Delete
return sprintf(
[97] Fix | Delete
'<div %1$s>%2$s</div>',
[98] Fix | Delete
$wrapper_attributes,
[99] Fix | Delete
__( 'No archives to show.' )
[100] Fix | Delete
);
[101] Fix | Delete
}
[102] Fix | Delete
[103] Fix | Delete
return sprintf(
[104] Fix | Delete
'<ul %1$s>%2$s</ul>',
[105] Fix | Delete
$wrapper_attributes,
[106] Fix | Delete
$archives
[107] Fix | Delete
);
[108] Fix | Delete
}
[109] Fix | Delete
[110] Fix | Delete
/**
[111] Fix | Delete
* Generates the inline script for an archives dropdown field.
[112] Fix | Delete
*
[113] Fix | Delete
* @since 6.9.0
[114] Fix | Delete
*
[115] Fix | Delete
* @param string $dropdown_id ID of the dropdown field.
[116] Fix | Delete
*
[117] Fix | Delete
* @return string Returns the dropdown onChange redirection script.
[118] Fix | Delete
*/
[119] Fix | Delete
function block_core_archives_build_dropdown_script( $dropdown_id ) {
[120] Fix | Delete
ob_start();
[121] Fix | Delete
[122] Fix | Delete
$exports = array( $dropdown_id, home_url() );
[123] Fix | Delete
?>
[124] Fix | Delete
<script>
[125] Fix | Delete
( ( [ dropdownId, homeUrl ] ) => {
[126] Fix | Delete
const dropdown = document.getElementById( dropdownId );
[127] Fix | Delete
function onSelectChange() {
[128] Fix | Delete
setTimeout( () => {
[129] Fix | Delete
if ( 'escape' === dropdown.dataset.lastkey ) {
[130] Fix | Delete
return;
[131] Fix | Delete
}
[132] Fix | Delete
if ( dropdown.value ) {
[133] Fix | Delete
location.href = dropdown.value;
[134] Fix | Delete
}
[135] Fix | Delete
}, 250 );
[136] Fix | Delete
}
[137] Fix | Delete
function onKeyUp( event ) {
[138] Fix | Delete
if ( 'Escape' === event.key ) {
[139] Fix | Delete
dropdown.dataset.lastkey = 'escape';
[140] Fix | Delete
} else {
[141] Fix | Delete
delete dropdown.dataset.lastkey;
[142] Fix | Delete
}
[143] Fix | Delete
}
[144] Fix | Delete
function onClick() {
[145] Fix | Delete
delete dropdown.dataset.lastkey;
[146] Fix | Delete
}
[147] Fix | Delete
dropdown.addEventListener( 'keyup', onKeyUp );
[148] Fix | Delete
dropdown.addEventListener( 'click', onClick );
[149] Fix | Delete
dropdown.addEventListener( 'change', onSelectChange );
[150] Fix | Delete
} )( <?php echo wp_json_encode( $exports, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ); ?> );
[151] Fix | Delete
</script>
[152] Fix | Delete
<?php
[153] Fix | Delete
return wp_get_inline_script_tag(
[154] Fix | Delete
trim( str_replace( array( '<script>', '</script>' ), '', ob_get_clean() ) ) .
[155] Fix | Delete
"\n//# sourceURL=" . rawurlencode( __FUNCTION__ )
[156] Fix | Delete
);
[157] Fix | Delete
}
[158] Fix | Delete
[159] Fix | Delete
/**
[160] Fix | Delete
* Register archives block.
[161] Fix | Delete
*
[162] Fix | Delete
* @since 5.0.0
[163] Fix | Delete
*/
[164] Fix | Delete
function register_block_core_archives() {
[165] Fix | Delete
register_block_type_from_metadata(
[166] Fix | Delete
__DIR__ . '/archives',
[167] Fix | Delete
array(
[168] Fix | Delete
'render_callback' => 'render_block_core_archives',
[169] Fix | Delete
)
[170] Fix | Delete
);
[171] Fix | Delete
}
[172] Fix | Delete
add_action( 'init', 'register_block_core_archives' );
[173] Fix | Delete
[174] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function