Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query Pagination: do not render pagination container if there's no pagination #33635

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions packages/block-library/src/query-pagination/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@ import { queryPagination as icon } from '@wordpress/icons';
*/
import metadata from './block.json';
import edit from './edit';
import save from './save';

const { name } = metadata;
export { metadata, name };

export const settings = {
icon,
edit,
save,
};
26 changes: 25 additions & 1 deletion packages/block-library/src/query-pagination/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,36 @@
* @package WordPress
*/

/**
* Renders the `core/query-pagination` block on the server.
*
* @param array $attributes Block attributes.
* @param string $content Block default content.
*
* @return string Returns the wrapper for the Query pagination.
*/
function render_block_core_query_pagination( $attributes, $content ) {
$wrapper_attributes = get_block_wrapper_attributes();

if ( empty( $content ) || ctype_space( $content ) ) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For some reason the $content is a long string of whitespace when it's empty, so I added the ctype_space condition.

return '';
}
return sprintf(
'<div %1$s>%2$s</div>',
$wrapper_attributes,
$content
);
}

/**
* Registers the `core/query-pagination` block on the server.
*/
function register_block_core_query_pagination() {
register_block_type_from_metadata(
__DIR__ . '/query-pagination'
__DIR__ . '/query-pagination',
array(
'render_callback' => 'render_block_core_query_pagination',
)
);
}
add_action( 'init', 'register_block_core_query_pagination' );
12 changes: 0 additions & 12 deletions packages/block-library/src/query-pagination/save.js

This file was deleted.