Edit File by line
/home/zeestwma/redstone.../wp-inclu.../blocks
File: post-navigation-link.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Server-side rendering of the `core/post-navigation-link` block.
[2] Fix | Delete
*
[3] Fix | Delete
* @package WordPress
[4] Fix | Delete
*/
[5] Fix | Delete
[6] Fix | Delete
/**
[7] Fix | Delete
* Renders the `core/post-navigation-link` block on the server.
[8] Fix | Delete
*
[9] Fix | Delete
* @since 5.9.0
[10] Fix | Delete
*
[11] Fix | Delete
* @param array $attributes Block attributes.
[12] Fix | Delete
* @param string $content Block default content.
[13] Fix | Delete
*
[14] Fix | Delete
* @return string Returns the next or previous post link that is adjacent to the current post.
[15] Fix | Delete
*/
[16] Fix | Delete
function render_block_core_post_navigation_link( $attributes, $content ) {
[17] Fix | Delete
if ( ! is_singular() ) {
[18] Fix | Delete
return '';
[19] Fix | Delete
}
[20] Fix | Delete
[21] Fix | Delete
// Get the navigation type to show the proper link. Available options are `next|previous`.
[22] Fix | Delete
$navigation_type = isset( $attributes['type'] ) ? $attributes['type'] : 'next';
[23] Fix | Delete
// Allow only `next` and `previous` in `$navigation_type`.
[24] Fix | Delete
if ( ! in_array( $navigation_type, array( 'next', 'previous' ), true ) ) {
[25] Fix | Delete
return '';
[26] Fix | Delete
}
[27] Fix | Delete
$classes = "post-navigation-link-$navigation_type";
[28] Fix | Delete
if ( isset( $attributes['textAlign'] ) ) {
[29] Fix | Delete
$classes .= " has-text-align-{$attributes['textAlign']}";
[30] Fix | Delete
}
[31] Fix | Delete
$wrapper_attributes = get_block_wrapper_attributes(
[32] Fix | Delete
array(
[33] Fix | Delete
'class' => $classes,
[34] Fix | Delete
)
[35] Fix | Delete
);
[36] Fix | Delete
// Set default values.
[37] Fix | Delete
$format = '%link';
[38] Fix | Delete
$link = 'next' === $navigation_type ? _x( 'Next', 'label for next post link' ) : _x( 'Previous', 'label for previous post link' );
[39] Fix | Delete
$label = '';
[40] Fix | Delete
[41] Fix | Delete
// Only use hardcoded values here, otherwise we need to add escaping where these values are used.
[42] Fix | Delete
$arrow_map = array(
[43] Fix | Delete
'none' => '',
[44] Fix | Delete
'arrow' => array(
[45] Fix | Delete
'next' => '→',
[46] Fix | Delete
'previous' => '←',
[47] Fix | Delete
),
[48] Fix | Delete
'chevron' => array(
[49] Fix | Delete
'next' => '»',
[50] Fix | Delete
'previous' => '«',
[51] Fix | Delete
),
[52] Fix | Delete
);
[53] Fix | Delete
[54] Fix | Delete
// If a custom label is provided, make this a link.
[55] Fix | Delete
// `$label` is used to prepend the provided label, if we want to show the page title as well.
[56] Fix | Delete
if ( isset( $attributes['label'] ) && ! empty( $attributes['label'] ) ) {
[57] Fix | Delete
$label = "{$attributes['label']}";
[58] Fix | Delete
$link = $label;
[59] Fix | Delete
}
[60] Fix | Delete
[61] Fix | Delete
// If we want to also show the page title, make the page title a link and prepend the label.
[62] Fix | Delete
if ( isset( $attributes['showTitle'] ) && $attributes['showTitle'] ) {
[63] Fix | Delete
/*
[64] Fix | Delete
* If the label link option is not enabled but there is a custom label,
[65] Fix | Delete
* display the custom label as text before the linked title.
[66] Fix | Delete
*/
[67] Fix | Delete
if ( ! $attributes['linkLabel'] ) {
[68] Fix | Delete
if ( $label ) {
[69] Fix | Delete
$format = '<span class="post-navigation-link__label">' . wp_kses_post( $label ) . '</span> %link';
[70] Fix | Delete
}
[71] Fix | Delete
$link = '%title';
[72] Fix | Delete
} elseif ( isset( $attributes['linkLabel'] ) && $attributes['linkLabel'] ) {
[73] Fix | Delete
// If the label link option is enabled and there is a custom label, display it before the title.
[74] Fix | Delete
if ( $label ) {
[75] Fix | Delete
$link = '<span class="post-navigation-link__label">' . wp_kses_post( $label ) . '</span> <span class="post-navigation-link__title">%title</span>';
[76] Fix | Delete
} else {
[77] Fix | Delete
/*
[78] Fix | Delete
* If the label link option is enabled and there is no custom label,
[79] Fix | Delete
* add a colon between the label and the post title.
[80] Fix | Delete
*/
[81] Fix | Delete
$label = 'next' === $navigation_type ? _x( 'Next:', 'label before the title of the next post' ) : _x( 'Previous:', 'label before the title of the previous post' );
[82] Fix | Delete
$link = sprintf(
[83] Fix | Delete
'<span class="post-navigation-link__label">%1$s</span> <span class="post-navigation-link__title">%2$s</span>',
[84] Fix | Delete
wp_kses_post( $label ),
[85] Fix | Delete
'%title'
[86] Fix | Delete
);
[87] Fix | Delete
}
[88] Fix | Delete
}
[89] Fix | Delete
}
[90] Fix | Delete
[91] Fix | Delete
// Display arrows.
[92] Fix | Delete
if ( isset( $attributes['arrow'] ) && 'none' !== $attributes['arrow'] && isset( $arrow_map[ $attributes['arrow'] ] ) ) {
[93] Fix | Delete
$arrow = $arrow_map[ $attributes['arrow'] ][ $navigation_type ];
[94] Fix | Delete
[95] Fix | Delete
if ( 'next' === $navigation_type ) {
[96] Fix | Delete
$format = '%link<span class="wp-block-post-navigation-link__arrow-next is-arrow-' . $attributes['arrow'] . '" aria-hidden="true">' . $arrow . '</span>';
[97] Fix | Delete
} else {
[98] Fix | Delete
$format = '<span class="wp-block-post-navigation-link__arrow-previous is-arrow-' . $attributes['arrow'] . '" aria-hidden="true">' . $arrow . '</span>%link';
[99] Fix | Delete
}
[100] Fix | Delete
}
[101] Fix | Delete
[102] Fix | Delete
/*
[103] Fix | Delete
* The dynamic portion of the function name, `$navigation_type`,
[104] Fix | Delete
* Refers to the type of adjacency, 'next' or 'previous'.
[105] Fix | Delete
*
[106] Fix | Delete
* @see https://developer.wordpress.org/reference/functions/get_previous_post_link/
[107] Fix | Delete
* @see https://developer.wordpress.org/reference/functions/get_next_post_link/
[108] Fix | Delete
*/
[109] Fix | Delete
$get_link_function = "get_{$navigation_type}_post_link";
[110] Fix | Delete
[111] Fix | Delete
if ( ! empty( $attributes['taxonomy'] ) ) {
[112] Fix | Delete
$content = $get_link_function( $format, $link, true, '', $attributes['taxonomy'] );
[113] Fix | Delete
} else {
[114] Fix | Delete
$content = $get_link_function( $format, $link );
[115] Fix | Delete
}
[116] Fix | Delete
[117] Fix | Delete
return sprintf(
[118] Fix | Delete
'<div %1$s>%2$s</div>',
[119] Fix | Delete
$wrapper_attributes,
[120] Fix | Delete
$content
[121] Fix | Delete
);
[122] Fix | Delete
}
[123] Fix | Delete
[124] Fix | Delete
/**
[125] Fix | Delete
* Registers the `core/post-navigation-link` block on the server.
[126] Fix | Delete
*
[127] Fix | Delete
* @since 5.9.0
[128] Fix | Delete
*/
[129] Fix | Delete
function register_block_core_post_navigation_link() {
[130] Fix | Delete
register_block_type_from_metadata(
[131] Fix | Delete
__DIR__ . '/post-navigation-link',
[132] Fix | Delete
array(
[133] Fix | Delete
'render_callback' => 'render_block_core_post_navigation_link',
[134] Fix | Delete
)
[135] Fix | Delete
);
[136] Fix | Delete
}
[137] Fix | Delete
add_action( 'init', 'register_block_core_post_navigation_link' );
[138] Fix | Delete
[139] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function