From a415c29efee45520ae252d2aa28f1083a521cd7b Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 09:56:49 +0200 Subject: Adding upstream version 6.4.3+dfsg1. Signed-off-by: Daniel Baumann --- wp-includes/blocks/post-navigation-link.php | 124 ++++++++++++++++++++++++++++ 1 file changed, 124 insertions(+) create mode 100644 wp-includes/blocks/post-navigation-link.php (limited to 'wp-includes/blocks/post-navigation-link.php') diff --git a/wp-includes/blocks/post-navigation-link.php b/wp-includes/blocks/post-navigation-link.php new file mode 100644 index 0000000..add112c --- /dev/null +++ b/wp-includes/blocks/post-navigation-link.php @@ -0,0 +1,124 @@ + $classes, + ) + ); + // Set default values. + $format = '%link'; + $link = 'next' === $navigation_type ? _x( 'Next', 'label for next post link' ) : _x( 'Previous', 'label for previous post link' ); + $label = ''; + + // Only use hardcoded values here, otherwise we need to add escaping where these values are used. + $arrow_map = array( + 'none' => '', + 'arrow' => array( + 'next' => '→', + 'previous' => '←', + ), + 'chevron' => array( + 'next' => '»', + 'previous' => '«', + ), + ); + + // If a custom label is provided, make this a link. + // `$label` is used to prepend the provided label, if we want to show the page title as well. + if ( isset( $attributes['label'] ) && ! empty( $attributes['label'] ) ) { + $label = "{$attributes['label']}"; + $link = $label; + } + + // If we want to also show the page title, make the page title a link and prepend the label. + if ( isset( $attributes['showTitle'] ) && $attributes['showTitle'] ) { + /* + * If the label link option is not enabled but there is a custom label, + * display the custom label as text before the linked title. + */ + if ( ! $attributes['linkLabel'] ) { + if ( $label ) { + $format = '' . wp_kses_post( $label ) . ' %link'; + } + $link = '%title'; + } elseif ( isset( $attributes['linkLabel'] ) && $attributes['linkLabel'] ) { + // If the label link option is enabled and there is a custom label, display it before the title. + if ( $label ) { + $link = '' . wp_kses_post( $label ) . ' %title'; + } else { + /* + * If the label link option is enabled and there is no custom label, + * add a colon between the label and the post title. + */ + $label = 'next' === $navigation_type ? _x( 'Next:', 'label before the title of the next post' ) : _x( 'Previous:', 'label before the title of the previous post' ); + $link = sprintf( + '%1$s %2$s', + wp_kses_post( $label ), + '%title' + ); + } + } + } + + // Display arrows. + if ( isset( $attributes['arrow'] ) && 'none' !== $attributes['arrow'] && isset( $arrow_map[ $attributes['arrow'] ] ) ) { + $arrow = $arrow_map[ $attributes['arrow'] ][ $navigation_type ]; + + if ( 'next' === $navigation_type ) { + $format = '%link'; + } else { + $format = '%link'; + } + } + + // The dynamic portion of the function name, `$navigation_type`, + // refers to the type of adjacency, 'next' or 'previous'. + $get_link_function = "get_{$navigation_type}_post_link"; + $content = $get_link_function( $format, $link ); + return sprintf( + '
%2$s
', + $wrapper_attributes, + $content + ); +} + +/** + * Registers the `core/post-navigation-link` block on the server. + */ +function register_block_core_post_navigation_link() { + register_block_type_from_metadata( + __DIR__ . '/post-navigation-link', + array( + 'render_callback' => 'render_block_core_post_navigation_link', + ) + ); +} +add_action( 'init', 'register_block_core_post_navigation_link' ); -- cgit v1.2.3