Skip to content

Commit e5d16f1

Browse files
authored
Merge pull request #28 from spacedmonkey/try/new-post-types
Add support for new post types found in WordPress 5.9
2 parents 0a33b72 + f8e1f35 commit e5d16f1

File tree

5 files changed

+32
-9
lines changed

5 files changed

+32
-9
lines changed

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77

88
**Requires at least:** 5.8
99

10-
**Tested up to:** 5.5
10+
**Tested up to:** 5.9
1111

1212
**Requires PHP:** 7.0.0
1313

14-
**Stable tag:** 0.4.0
14+
**Stable tag:** 0.5.0
1515

1616
**License:** GPLv3 or later
1717

@@ -61,6 +61,9 @@ Installation requires you to check the project out in plugin directory and do a
6161

6262
## Changelog ##
6363

64+
### 0.5.0 ###
65+
* Add support for new post types added in WordPress 5.9.
66+
6467
### 0.4.0 ###
6568
* Added support for block based widget, added in WordPress 5.8. Block data is added to the /wp/v2/widgets endpoint.
6669

composer.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@
2323
"platform": {
2424
"php": "7.0"
2525
},
26-
"sort-packages": true
26+
"sort-packages": true,
27+
"allow-plugins": {
28+
"dealerdirect/phpcodesniffer-composer-installer": true,
29+
"composer/installers": true
30+
}
2731
},
2832
"require-dev": {
2933
"squizlabs/php_codesniffer": "^3.6",

readme.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ Contributors: spacedmonkey
33
Donate link: https://github.com/sponsors/spacedmonkey
44
Tags: blocks, gutenberg, api, wp-json, rest-api
55
Requires at least: 5.5
6-
Tested up to: 5.8
6+
Tested up to: 5.9
77
Requires PHP: 7.0.0
8-
Stable tag: 0.4.0
8+
Stable tag: 0.5.0
99
License: GPLv3 or later
1010
License URI: https://www.gnu.org/licenses/gpl-3.0.en.html
1111

@@ -51,6 +51,10 @@ An example of output, can be found in the screenshots.
5151
1. Add fields to the rest api.
5252

5353
== Changelog ==
54+
55+
= 0.5.0 =
56+
* Add support for new post types added in WordPress 5.9.
57+
5458
= 0.4.0 =
5559
* Added support for block based widget, added in WordPress 5.8. Block data is added to the /wp/v2/widgets endpoint.
5660

src/posts.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,11 @@ function get_post_types_with_editor() {
3030
if ( ! function_exists( 'use_block_editor_for_post_type' ) ) {
3131
require_once ABSPATH . 'wp-admin/includes/post.php';
3232
}
33+
$post_types = array_filter( $post_types, 'use_block_editor_for_post_type' );
34+
$post_types[] = 'wp_navigation';
35+
$post_types = array_filter( $post_types, 'post_type_exists' );
3336

34-
return array_filter( $post_types, 'use_block_editor_for_post_type' );
37+
return $post_types;
3538
}
3639

3740
/**
@@ -84,7 +87,11 @@ function wp_rest_blocks_init() {
8487
* @return bool
8588
*/
8689
function has_blocks_get_callback( array $object ) {
87-
$post = get_post( $object['id'] );
90+
if ( isset( $object['content']['raw'] ) ) {
91+
return has_blocks( $object['content']['raw'] );
92+
}
93+
$id = ! empty( $object['wp_id'] ) ? $object['wp_id'] : $object['id'];
94+
$post = get_post( $id );
8895
if ( ! $post ) {
8996
return false;
9097
}
@@ -100,7 +107,12 @@ function has_blocks_get_callback( array $object ) {
100107
* @return array
101108
*/
102109
function blocks_get_callback( array $object ) {
103-
$post = get_post( $object['id'] );
110+
$id = ! empty( $object['wp_id'] ) ? $object['wp_id'] : $object['id'];
111+
if ( isset( $object['content']['raw'] ) ) {
112+
return get_blocks( $object['content']['raw'], $id );
113+
}
114+
$id = ! empty( $object['wp_id'] ) ? $object['wp_id'] : $object['id'];
115+
$post = get_post( $id );
104116
$output = [];
105117
if ( ! $post ) {
106118
return $output;

wp-rest-blocks.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Author URI: https://www.spacedmonkey.com/
88
* Text Domain: wp-rest-blocks
99
* Domain Path: /languages
10-
* Version: 0.4.0
10+
* Version: 0.5.0
1111
* Requires at least: 5.5
1212
* Requires PHP: 7.0
1313
*

0 commit comments

Comments
 (0)