Skip to content

Commit

Permalink
Query Pagination: Don't render an empty container (#35092)
Browse files Browse the repository at this point in the history
* Query Pagination: Don't render an empty container
* ESLint: Add missing semicolon
* Update block fixtures
* Call get_block_wrapper_attributes directly
  • Loading branch information
Mamaduka authored Sep 29, 2021
1 parent 608a105 commit c489f23
Show file tree
Hide file tree
Showing 12 changed files with 76 additions and 16 deletions.
19 changes: 19 additions & 0 deletions packages/block-library/src/query-pagination/deprecated.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* WordPress dependencies
*/
import { InnerBlocks, useBlockProps } from '@wordpress/block-editor';

const deprecated = [
// Version with wrapper `div` element.
{
save() {
return (
<div { ...useBlockProps.save() }>
<InnerBlocks.Content />
</div>
);
},
},
];

export default deprecated;
2 changes: 2 additions & 0 deletions packages/block-library/src/query-pagination/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { queryPagination as icon } from '@wordpress/icons';
import metadata from './block.json';
import edit from './edit';
import save from './save';
import deprecated from './deprecated';

const { name } = metadata;
export { metadata, name };
Expand All @@ -17,4 +18,5 @@ export const settings = {
icon,
edit,
save,
deprecated,
};
25 changes: 24 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,35 @@
* @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 ) {
if ( empty( trim( $content ) ) ) {
return '';
}

return sprintf(
'<div %1$s>%2$s</div>',
get_block_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' );
8 changes: 2 additions & 6 deletions packages/block-library/src/query-pagination/save.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
/**
* WordPress dependencies
*/
import { InnerBlocks, useBlockProps } from '@wordpress/block-editor';
import { InnerBlocks } from '@wordpress/block-editor';

export default function save() {
return (
<div { ...useBlockProps.save() }>
<InnerBlocks.Content />
</div>
);
return <InnerBlocks.Content />;
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
<!-- wp:query-pagination -->
<div class="wp-block-query-pagination"></div>
<!-- /wp:query-pagination -->
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
"paginationArrow": "none"
},
"innerBlocks": [],
"originalContent": "<div class=\"wp-block-query-pagination\"></div>"
"originalContent": ""
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
"blockName": "core/query-pagination",
"attrs": {},
"innerBlocks": [],
"innerHTML": "\n<div class=\"wp-block-query-pagination\"></div>\n",
"innerContent": [
"\n<div class=\"wp-block-query-pagination\"></div>\n"
]
"innerHTML": "\n",
"innerContent": [ "\n" ]
}
]
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
<!-- wp:query-pagination -->
<div class="wp-block-query-pagination"></div>
<!-- /wp:query-pagination -->
<!-- wp:query-pagination /-->
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<!-- wp:query-pagination -->
<div class="wp-block-query-pagination"></div>
<!-- /wp:query-pagination -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[
{
"clientId": "_clientId_0",
"name": "core/query-pagination",
"isValid": true,
"attributes": {},
"innerBlocks": [],
"originalContent": "<div class=\"wp-block-query-pagination\"></div>"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[
{
"blockName": "core/query-pagination",
"attrs": {},
"innerBlocks": [],
"innerHTML": "\n<div class=\"wp-block-query-pagination\"></div>\n",
"innerContent": [
"\n<div class=\"wp-block-query-pagination\"></div>\n"
]
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!-- wp:query-pagination /-->

0 comments on commit c489f23

Please sign in to comment.