Skip to content

Commit

Permalink
Fix content-visibility in block editor
Browse files Browse the repository at this point in the history
The current version throws an error if the user wants to switch from a different visibility to `public`
  • Loading branch information
pfefferle committed Feb 11, 2025
1 parent f0546b5 commit 34187c0
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions includes/class-blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,24 +51,26 @@ public static function register_postmeta() {
},
)
);

\register_post_meta(
$post_type,
'activitypub_content_visibility',
array(
'show_in_rest' => true,
'single' => true,
'type' => 'string',
'sanitize_callback' => function ( $visibility ) {
$options = array(
ACTIVITYPUB_CONTENT_VISIBILITY_QUIET_PUBLIC,
ACTIVITYPUB_CONTENT_VISIBILITY_LOCAL,
'single' => true,
'show_in_rest' => true,
'sanitize_callback' => function ( $value ) {
$schema = array(
'type' => 'string',
'enum' => array( ACTIVITYPUB_CONTENT_VISIBILITY_PUBLIC, ACTIVITYPUB_CONTENT_VISIBILITY_QUIET_PUBLIC, ACTIVITYPUB_CONTENT_VISIBILITY_PRIVATE, ACTIVITYPUB_CONTENT_VISIBILITY_LOCAL ),
'default' => ACTIVITYPUB_CONTENT_VISIBILITY_PUBLIC,
);

if ( in_array( $visibility, $options, true ) ) {
return $visibility;
if ( is_wp_error( rest_validate_enum( $value, $schema, '' ) ) ) {
return $schema['default'];
}

return null;
return $value;
},
)
);
Expand Down

0 comments on commit 34187c0

Please sign in to comment.