@@ -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