Skip to content

Commit 889cb63

Browse files
committed
Set rest read/write status on cmb object instead of CMB2_REST_Access object.
1 parent 0bad2da commit 889cb63

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

includes/CMB2.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ class CMB2 extends CMB2_Base {
6969
'taxonomies' => array(),
7070
'new_user_section' => 'add-new-user', // or 'add-existing-user'
7171
'new_term_section' => true,
72+
'rest_read' => false,
73+
'rest_write' => false,
7274
);
7375

7476
/**

includes/CMB2_REST_Access.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ public function __construct( CMB2 $cmb ) {
5151
$this->cmb = $cmb;
5252
self::$boxes[ $cmb->cmb_id ] = $cmb;
5353

54-
$show_value = $this->cmb->prop( 'show_in_rest' );
55-
$this->can_read = 'write_only' !== $show_value;
56-
$this->can_write = in_array( $show_value, array( 'read_and_write', 'write_only' ), true );
54+
$show_value = $this->cmb->prop( 'show_in_rest' );
55+
$this->cmb->rest_read = 'write_only' !== $show_value;
56+
$this->cmb->rest_write = in_array( $show_value, array( 'read_and_write', 'write_only' ), true );
5757
}
5858

5959
public function universal_hooks() {
@@ -100,7 +100,7 @@ protected function prepare_read_write_fields() {
100100
}
101101

102102
protected function maybe_add_read_field( $field_id, $show_in_rest ) {
103-
$can_read = $this->can_read
103+
$can_read = $this->cmb->rest_read
104104
? 'write_only' !== $show_in_rest
105105
: in_array( $show_in_rest, array( 'read_and_write', 'read_only' ), true );
106106

@@ -110,7 +110,7 @@ protected function maybe_add_read_field( $field_id, $show_in_rest ) {
110110
}
111111

112112
protected function maybe_add_write_field( $field_id, $show_in_rest ) {
113-
$can_update = $this->can_write
113+
$can_update = $this->cmb->rest_write
114114
? 'read_only' !== $show_in_rest
115115
: in_array( $show_in_rest, array( 'read_and_write', 'write_only' ), true );
116116

@@ -237,7 +237,7 @@ public function field_can_update( $field_id ) {
237237

238238
$field = $this->cmb->get_field( $field_id );
239239
$show_in_rest = $field ? $field->args( 'show_in_rest' ) : 'no';
240-
$can_update = $this->can_write
240+
$can_update = $this->cmb->rest_write
241241
? 'read_only' !== $show_in_rest
242242
: in_array( $show_in_rest, array( 'read_and_write', 'write_only' ), true );
243243

tests/test-cmb-core.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ public function setUp() {
117117
'taxonomies' => array(),
118118
'new_user_section' => 'add-new-user', // or 'add-existing-user'
119119
'new_term_section' => true,
120+
'rest_read' => false,
121+
'rest_write' => false,
120122
);
121123

122124
$this->cmb = new CMB2( $this->metabox_array );

0 commit comments

Comments
 (0)