Skip to content

Commit 854fba6

Browse files
authored
Move default visibility logic to UI and classic editor (#2378)
1 parent 0b90b5d commit 854fba6

File tree

9 files changed

+338
-121
lines changed

9 files changed

+338
-121
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: minor
2+
Type: changed
3+
4+
Moved default visibility handling from the server to the editor UI, ensuring consistent and flexible ActivityPub visibility settings across both block and classic editors.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<?php return array('dependencies' => array('react-jsx-runtime', 'wp-components', 'wp-core-data', 'wp-data', 'wp-edit-post', 'wp-editor', 'wp-element', 'wp-i18n', 'wp-plugins', 'wp-primitives', 'wp-url'), 'version' => '2e0397f8327aae6f3e13');
1+
<?php return array('dependencies' => array('react-jsx-runtime', 'wp-components', 'wp-core-data', 'wp-data', 'wp-edit-post', 'wp-editor', 'wp-element', 'wp-i18n', 'wp-plugins', 'wp-primitives', 'wp-url'), 'version' => 'c0707a36ca43854f47b7');

build/editor-plugin/plugin.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

includes/class-post-types.php

Lines changed: 23 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ public static function init() {
3636

3737
\add_filter( 'add_post_metadata', array( self::class, 'prevent_empty_post_meta' ), 10, 4 );
3838
\add_filter( 'update_post_metadata', array( self::class, 'prevent_empty_post_meta' ), 10, 4 );
39-
\add_filter( 'default_post_metadata', array( self::class, 'default_post_meta_data' ), 10, 3 );
4039

4140
// Add support for ActivityPub to custom post types.
4241
foreach ( \get_option( 'activitypub_support_post_types', array( 'post' ) ) as $post_type ) {
@@ -523,6 +522,29 @@ public static function register_activitypub_post_meta() {
523522
},
524523
)
525524
);
525+
526+
\register_post_meta(
527+
$post_type,
528+
'activitypub_status',
529+
array(
530+
'type' => 'string',
531+
'single' => true,
532+
'show_in_rest' => true,
533+
'sanitize_callback' => function ( $value ) {
534+
$schema = array(
535+
'type' => 'string',
536+
'enum' => array( 'pending', 'federated', 'failed' ),
537+
'default' => 'pending',
538+
);
539+
540+
if ( \is_wp_error( \rest_validate_enum( $value, $schema, '' ) ) ) {
541+
return $schema['default'];
542+
}
543+
544+
return $value;
545+
},
546+
)
547+
);
526548
}
527549
}
528550

@@ -578,36 +600,4 @@ public static function prevent_empty_post_meta( $check, $object_id, $meta_key, $
578600

579601
return $check;
580602
}
581-
582-
/**
583-
* Adjusts default post meta values.
584-
*
585-
* @param mixed $meta_value The meta value.
586-
* @param int $object_id ID of the object metadata is for.
587-
* @param string $meta_key Metadata key.
588-
*
589-
* @return string|null The meta value.
590-
*/
591-
public static function default_post_meta_data( $meta_value, $object_id, $meta_key ) {
592-
if ( 'activitypub_content_visibility' !== $meta_key ) {
593-
return $meta_value;
594-
}
595-
596-
// If meta value is already explicitly set, respect the author's choice.
597-
if ( $meta_value ) {
598-
return $meta_value;
599-
}
600-
601-
// If the post is federated, return the default visibility.
602-
if ( 'federated' === \get_post_meta( $object_id, 'activitypub_status', true ) ) {
603-
return $meta_value;
604-
}
605-
606-
// If the post is not federated and older than a month, return local visibility.
607-
if ( \get_the_date( 'U', $object_id ) < \strtotime( '-1 month' ) ) {
608-
return ACTIVITYPUB_CONTENT_VISIBILITY_LOCAL;
609-
}
610-
611-
return $meta_value;
612-
}
613603
}

0 commit comments

Comments
 (0)