$item->ID, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID', 'fields' => 'ids', 'posts_per_page' => $actual_count, ) ); // Transform IDs into associative arrays. $media_ids = \array_map( static function ( $id ) { return array( 'id' => $id ); }, $query->get_posts() ); return \array_merge( $attachments, $media_ids ); } /** * Add ActivityPub meta box to the post editor. * * @param string $post_type The post type. */ public static function add_meta_box( $post_type ) { // Only add for post types that support ActivityPub. if ( ! \post_type_supports( $post_type, 'activitypub' ) ) { return; } \add_meta_box( 'activitypub-settings', \__( 'Fediverse ⁂', 'activitypub' ), array( self::class, 'render_meta_box' ), $post_type, 'side', 'default' ); } /** * Render the ActivityPub meta box. * * @param \WP_Post $post The post object. */ public static function render_meta_box( $post ) { // Add nonce for security. \wp_nonce_field( 'activitypub_meta_box', 'activitypub_meta_box_nonce' ); // Get current values. $content_warning = \get_post_meta( $post->ID, 'activitypub_content_warning', true ); $max_image_attachments = \get_post_meta( $post->ID, 'activitypub_max_image_attachments', true ); $content_visibility = self::get_default_visibility( $post ); $default_quote_policy = \get_option( 'activitypub_default_quote_policy', ACTIVITYPUB_INTERACTION_POLICY_ANYONE ); $quote_interaction = \get_post_meta( $post->ID, 'activitypub_interaction_policy_quote', true ) ?: $default_quote_policy; ?>








\__( 'Anyone', 'activitypub' ), ACTIVITYPUB_INTERACTION_POLICY_FOLLOWERS => \__( 'Followers only', 'activitypub' ), ACTIVITYPUB_INTERACTION_POLICY_ME => \__( 'Just me', 'activitypub' ), ); return $labels[ $policy ] ?? $labels[ ACTIVITYPUB_INTERACTION_POLICY_ANYONE ]; } /** * Get default visibility based on post age and federation status. * * @param \WP_Post $post The post object. * * @return string The default visibility value. */ private static function get_default_visibility( $post ) { // If already set, use that value. $saved_visibility = \get_post_meta( $post->ID, 'activitypub_content_visibility', true ); if ( $saved_visibility ) { return $saved_visibility; } // If post is federated, use public. $status = \get_post_meta( $post->ID, 'activitypub_status', true ); if ( ACTIVITYPUB_OBJECT_STATE_FEDERATED === $status ) { return ACTIVITYPUB_CONTENT_VISIBILITY_PUBLIC; } // If post is older than 1 month, default to local. $post_timestamp = \strtotime( $post->post_date ); $one_month_ago = \strtotime( '-30 days' ); if ( $post_timestamp < $one_month_ago ) { return ACTIVITYPUB_CONTENT_VISIBILITY_LOCAL; } // Default to public for new posts. return ACTIVITYPUB_CONTENT_VISIBILITY_PUBLIC; } /** * Save ActivityPub meta data. * * @param int $post_id The post ID. */ public static function save_meta_data( $post_id ) { // Check if this is an autosave. if ( \defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { return; } // Only process for post types that support ActivityPub. if ( ! \post_type_supports( \get_post_type( $post_id ), 'activitypub' ) ) { return; } // Check user permissions. if ( ! \current_user_can( 'edit_post', $post_id ) ) { return; } // Verify nonce is present and valid. if ( ! isset( $_POST['activitypub_meta_box_nonce'] ) ) { return; } if ( ! \wp_verify_nonce( \sanitize_text_field( \wp_unslash( $_POST['activitypub_meta_box_nonce'] ) ), 'activitypub_meta_box' ) ) { return; } // Save content warning. if ( isset( $_POST['activitypub_content_warning'] ) ) { $content_warning = \sanitize_text_field( \wp_unslash( $_POST['activitypub_content_warning'] ) ); if ( ! empty( $content_warning ) ) { \update_post_meta( $post_id, 'activitypub_content_warning', $content_warning ); } else { \delete_post_meta( $post_id, 'activitypub_content_warning' ); } } // Save max image attachments. if ( isset( $_POST['activitypub_max_image_attachments'] ) ) { $max_images = \absint( $_POST['activitypub_max_image_attachments'] ); \update_post_meta( $post_id, 'activitypub_max_image_attachments', $max_images ); } // Save content visibility. if ( isset( $_POST['activitypub_content_visibility'] ) ) { $visibility = \sanitize_text_field( \wp_unslash( $_POST['activitypub_content_visibility'] ) ); \update_post_meta( $post_id, 'activitypub_content_visibility', $visibility ); } // Save quote interaction policy. if ( isset( $_POST['activitypub_interaction_policy_quote'] ) ) { $quote_policy = \sanitize_text_field( \wp_unslash( $_POST['activitypub_interaction_policy_quote'] ) ); \update_post_meta( $post_id, 'activitypub_interaction_policy_quote', $quote_policy ); } } }