2021-11-08 21:17:17 -05:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Server-side rendering of the `core/post-navigation-link` block.
|
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Renders the `core/post-navigation-link` block on the server.
|
|
|
|
*
|
|
|
|
* @param array $attributes Block attributes.
|
|
|
|
* @param string $content Block default content.
|
|
|
|
*
|
|
|
|
* @return string Returns the next or previous post link that is adjacent to the current post.
|
|
|
|
*/
|
|
|
|
function render_block_core_post_navigation_link( $attributes, $content ) {
|
|
|
|
if ( ! is_singular() ) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
2022-04-12 11:12:47 -04:00
|
|
|
// Get the navigation type to show the proper link. Available options are `next|previous`.
|
2021-11-08 21:17:17 -05:00
|
|
|
$navigation_type = isset( $attributes['type'] ) ? $attributes['type'] : 'next';
|
|
|
|
// Allow only `next` and `previous` in `$navigation_type`.
|
|
|
|
if ( ! in_array( $navigation_type, array( 'next', 'previous' ), true ) ) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
$classes = "post-navigation-link-$navigation_type";
|
|
|
|
if ( isset( $attributes['textAlign'] ) ) {
|
|
|
|
$classes .= " has-text-align-{$attributes['textAlign']}";
|
|
|
|
}
|
2023-09-26 10:23:26 -04:00
|
|
|
$wrapper_attributes = get_block_wrapper_attributes(
|
|
|
|
array(
|
|
|
|
'class' => $classes,
|
|
|
|
)
|
|
|
|
);
|
2021-11-08 21:17:17 -05:00
|
|
|
// Set default values.
|
|
|
|
$format = '%link';
|
|
|
|
$link = 'next' === $navigation_type ? _x( 'Next', 'label for next post link' ) : _x( 'Previous', 'label for previous post link' );
|
|
|
|
$label = '';
|
|
|
|
|
Update editor related npm packages for 6.4 RC1.
The npm packages needed a second part to the update for 6.4 RC1.
Props isabel_brison, andrewserong, jsnajdr, wildworks, joen, mciampini, tyxla, youknowriad, ramonopoly, spacedmonkey, dmsnell, mikachan, kishanjasani, czapla, siobhyb, darerodz, luisherranz
See #59411.
Built from https://develop.svn.wordpress.org/trunk@56945
git-svn-id: http://core.svn.wordpress.org/trunk@56456 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2023-10-16 15:17:19 -04:00
|
|
|
// Only use hardcoded values here, otherwise we need to add escaping where these values are used.
|
2023-02-07 02:04:52 -05:00
|
|
|
$arrow_map = array(
|
|
|
|
'none' => '',
|
|
|
|
'arrow' => array(
|
|
|
|
'next' => '→',
|
|
|
|
'previous' => '←',
|
|
|
|
),
|
|
|
|
'chevron' => array(
|
|
|
|
'next' => '»',
|
|
|
|
'previous' => '«',
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
2021-11-08 21:17:17 -05:00
|
|
|
// 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 ) {
|
2022-04-12 11:12:47 -04:00
|
|
|
$format = '<span class="post-navigation-link__label">' . wp_kses_post( $label ) . '</span> %link';
|
2021-11-08 21:17:17 -05:00
|
|
|
}
|
|
|
|
$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 ) {
|
2022-04-12 11:12:47 -04:00
|
|
|
$link = '<span class="post-navigation-link__label">' . wp_kses_post( $label ) . '</span> <span class="post-navigation-link__title">%title</span>';
|
2021-11-08 21:17:17 -05:00
|
|
|
} 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(
|
|
|
|
'<span class="post-navigation-link__label">%1$s</span> <span class="post-navigation-link__title">%2$s</span>',
|
2022-04-12 11:12:47 -04:00
|
|
|
wp_kses_post( $label ),
|
2021-11-08 21:17:17 -05:00
|
|
|
'%title'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-07 02:04:52 -05:00
|
|
|
// Display arrows.
|
Update editor related npm packages for 6.4 RC1.
The npm packages needed a second part to the update for 6.4 RC1.
Props isabel_brison, andrewserong, jsnajdr, wildworks, joen, mciampini, tyxla, youknowriad, ramonopoly, spacedmonkey, dmsnell, mikachan, kishanjasani, czapla, siobhyb, darerodz, luisherranz
See #59411.
Built from https://develop.svn.wordpress.org/trunk@56945
git-svn-id: http://core.svn.wordpress.org/trunk@56456 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2023-10-16 15:17:19 -04:00
|
|
|
if ( isset( $attributes['arrow'] ) && 'none' !== $attributes['arrow'] && isset( $arrow_map[ $attributes['arrow'] ] ) ) {
|
2023-02-07 02:04:52 -05:00
|
|
|
$arrow = $arrow_map[ $attributes['arrow'] ][ $navigation_type ];
|
|
|
|
|
|
|
|
if ( 'next' === $navigation_type ) {
|
2023-09-26 10:23:26 -04:00
|
|
|
$format = '%link<span class="wp-block-post-navigation-link__arrow-next is-arrow-' . $attributes['arrow'] . '" aria-hidden="true">' . $arrow . '</span>';
|
2023-02-07 02:04:52 -05:00
|
|
|
} else {
|
2023-09-26 10:23:26 -04:00
|
|
|
$format = '<span class="wp-block-post-navigation-link__arrow-previous is-arrow-' . $attributes['arrow'] . '" aria-hidden="true">' . $arrow . '</span>%link';
|
2023-02-07 02:04:52 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-31 07:59:56 -05:00
|
|
|
/*
|
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 16:07:12 -05:00
|
|
|
* The dynamic portion of the function name, `$navigation_type`,
|
|
|
|
* Refers to the type of adjacency, 'next' or 'previous'.
|
|
|
|
*
|
2024-01-31 07:59:56 -05:00
|
|
|
* @see https://developer.wordpress.org/reference/functions/get_previous_post_link/
|
|
|
|
* @see https://developer.wordpress.org/reference/functions/get_next_post_link/
|
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 16:07:12 -05:00
|
|
|
*/
|
2021-11-08 21:17:17 -05:00
|
|
|
$get_link_function = "get_{$navigation_type}_post_link";
|
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 16:07:12 -05:00
|
|
|
|
2024-02-09 13:22:22 -05:00
|
|
|
if ( ! empty( $attributes['taxonomy'] ) ) {
|
|
|
|
$content = $get_link_function( $format, $link, true, '', $attributes['taxonomy'] );
|
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 16:07:12 -05:00
|
|
|
} else {
|
|
|
|
$content = $get_link_function( $format, $link );
|
|
|
|
}
|
|
|
|
|
2021-11-08 21:17:17 -05:00
|
|
|
return sprintf(
|
|
|
|
'<div %1$s>%2$s</div>',
|
|
|
|
$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' );
|