diff --git a/.github/changelog/1552-from-description b/.github/changelog/1552-from-description new file mode 100644 index 000000000..84eea39b2 --- /dev/null +++ b/.github/changelog/1552-from-description @@ -0,0 +1,4 @@ +Significance: patch +Type: changed + +Add option to enable/disable the `Vary` Header to the "Advanced Settings". diff --git a/activitypub.php b/activitypub.php index ca3672e92..0a89fded8 100644 --- a/activitypub.php +++ b/activitypub.php @@ -67,16 +67,17 @@ function rest_init() { * Initialize plugin. */ function plugin_init() { - \add_action( 'init', array( __NAMESPACE__ . '\Migration', 'init' ) ); \add_action( 'init', array( __NAMESPACE__ . '\Activitypub', 'init' ) ); + \add_action( 'init', array( __NAMESPACE__ . '\Comment', 'init' ) ); \add_action( 'init', array( __NAMESPACE__ . '\Dispatcher', 'init' ) ); \add_action( 'init', array( __NAMESPACE__ . '\Handler', 'init' ) ); \add_action( 'init', array( __NAMESPACE__ . '\Hashtag', 'init' ) ); - \add_action( 'init', array( __NAMESPACE__ . '\Mention', 'init' ) ); - \add_action( 'init', array( __NAMESPACE__ . '\Scheduler', 'init' ) ); - \add_action( 'init', array( __NAMESPACE__ . '\Comment', 'init' ) ); \add_action( 'init', array( __NAMESPACE__ . '\Link', 'init' ) ); \add_action( 'init', array( __NAMESPACE__ . '\Mailer', 'init' ) ); + \add_action( 'init', array( __NAMESPACE__ . '\Mention', 'init' ) ); + \add_action( 'init', array( __NAMESPACE__ . '\Migration', 'init' ), 1 ); + \add_action( 'init', array( __NAMESPACE__ . '\Options', 'init' ) ); + \add_action( 'init', array( __NAMESPACE__ . '\Scheduler', 'init' ) ); if ( site_supports_blocks() ) { \add_action( 'init', array( __NAMESPACE__ . '\Blocks', 'init' ) ); diff --git a/includes/class-activitypub.php b/includes/class-activitypub.php index c623d0bd7..902050f01 100644 --- a/includes/class-activitypub.php +++ b/includes/class-activitypub.php @@ -49,15 +49,9 @@ public static function init() { \add_action( 'updated_postmeta', array( self::class, 'updated_postmeta' ), 10, 4 ); \add_action( 'added_post_meta', array( self::class, 'updated_postmeta' ), 10, 4 ); - \add_filter( 'pre_option_activitypub_actor_mode', array( self::class, 'pre_option_activitypub_actor_mode' ) ); - \add_filter( 'pre_option_activitypub_authorized_fetch', array( self::class, 'pre_option_activitypub_authorized_fetch' ) ); - \add_filter( 'pre_option_activitypub_shared_inbox', array( self::class, 'pre_option_activitypub_shared_inbox' ) ); \add_action( 'init', array( self::class, 'register_user_meta' ), 11 ); - \add_filter( 'pre_option_activitypub_allow_likes', array( self::class, 'maybe_disable_interactions' ) ); - \add_filter( 'pre_option_activitypub_allow_replies', array( self::class, 'maybe_disable_interactions' ) ); - // Register several post_types. self::register_post_types(); @@ -96,37 +90,38 @@ public static function uninstall() { \remove_filter( 'pre_wp_update_comment_count_now', array( Comment::class, 'pre_wp_update_comment_count_now' ) ); Migration::update_comment_counts( 2000 ); - delete_option( 'activitypub_actor_mode' ); - delete_option( 'activitypub_allow_likes' ); - delete_option( 'activitypub_allow_replies' ); - delete_option( 'activitypub_attribution_domains' ); - delete_option( 'activitypub_authorized_fetch' ); - delete_option( 'activitypub_application_user_private_key' ); - delete_option( 'activitypub_application_user_public_key' ); - delete_option( 'activitypub_blog_user_also_known_as' ); - delete_option( 'activitypub_blog_user_moved_to' ); - delete_option( 'activitypub_blog_user_private_key' ); - delete_option( 'activitypub_blog_user_public_key' ); - delete_option( 'activitypub_blog_description' ); - delete_option( 'activitypub_blog_identifier' ); - delete_option( 'activitypub_custom_post_content' ); - delete_option( 'activitypub_db_version' ); - delete_option( 'activitypub_default_extra_fields' ); - delete_option( 'activitypub_enable_blog_user' ); - delete_option( 'activitypub_enable_users' ); - delete_option( 'activitypub_header_image' ); - delete_option( 'activitypub_last_post_with_permalink_as_id' ); - delete_option( 'activitypub_mailer_new_follower' ); - delete_option( 'activitypub_mailer_new_dm' ); - delete_option( 'activitypub_max_image_attachments' ); - delete_option( 'activitypub_migration_lock' ); - delete_option( 'activitypub_object_type' ); - delete_option( 'activitypub_outbox_purge_days' ); - delete_option( 'activitypub_shared_inbox' ); - delete_option( 'activitypub_support_post_types' ); - delete_option( 'activitypub_use_hashtags' ); - delete_option( 'activitypub_use_opengraph' ); - delete_option( 'activitypub_use_permalink_as_id_for_blog' ); + \delete_option( 'activitypub_actor_mode' ); + \delete_option( 'activitypub_allow_likes' ); + \delete_option( 'activitypub_allow_replies' ); + \delete_option( 'activitypub_attribution_domains' ); + \delete_option( 'activitypub_authorized_fetch' ); + \delete_option( 'activitypub_application_user_private_key' ); + \delete_option( 'activitypub_application_user_public_key' ); + \delete_option( 'activitypub_blog_user_also_known_as' ); + \delete_option( 'activitypub_blog_user_moved_to' ); + \delete_option( 'activitypub_blog_user_private_key' ); + \delete_option( 'activitypub_blog_user_public_key' ); + \delete_option( 'activitypub_blog_description' ); + \delete_option( 'activitypub_blog_identifier' ); + \delete_option( 'activitypub_custom_post_content' ); + \delete_option( 'activitypub_db_version' ); + \delete_option( 'activitypub_default_extra_fields' ); + \delete_option( 'activitypub_enable_blog_user' ); + \delete_option( 'activitypub_enable_users' ); + \delete_option( 'activitypub_header_image' ); + \delete_option( 'activitypub_last_post_with_permalink_as_id' ); + \delete_option( 'activitypub_mailer_new_follower' ); + \delete_option( 'activitypub_mailer_new_dm' ); + \delete_option( 'activitypub_max_image_attachments' ); + \delete_option( 'activitypub_migration_lock' ); + \delete_option( 'activitypub_object_type' ); + \delete_option( 'activitypub_outbox_purge_days' ); + \delete_option( 'activitypub_shared_inbox' ); + \delete_option( 'activitypub_support_post_types' ); + \delete_option( 'activitypub_use_hashtags' ); + \delete_option( 'activitypub_use_opengraph' ); + \delete_option( 'activitypub_use_permalink_as_id_for_blog' ); + \delete_option( 'activitypub_vary_header' ); } /** @@ -209,7 +204,7 @@ public static function add_headers() { if ( ! headers_sent() ) { \header( 'Link: <' . esc_url( $id ) . '>; title="ActivityPub (JSON)"; rel="alternate"; type="application/activity+json"', false ); - if ( ACTIVITYPUB_SEND_VARY_HEADER ) { + if ( \get_option( 'activitypub_vary_header' ) ) { // Send Vary header for Accept header. \header( 'Vary: Accept', false ); } @@ -396,68 +391,6 @@ public static function pre_get_avatar_data( $args, $id_or_email ) { return $args; } - /** - * Pre-get option filter for the Actor-Mode. - * - * @param string|false $pre The pre-get option value. - * - * @return string|false The actor mode or false if it should not be filtered. - */ - public static function pre_option_activitypub_actor_mode( $pre ) { - if ( \defined( 'ACTIVITYPUB_SINGLE_USER_MODE' ) && ACTIVITYPUB_SINGLE_USER_MODE ) { - return ACTIVITYPUB_BLOG_MODE; - } - - if ( \defined( 'ACTIVITYPUB_DISABLE_USER' ) && ACTIVITYPUB_DISABLE_USER ) { - return ACTIVITYPUB_BLOG_MODE; - } - - if ( \defined( 'ACTIVITYPUB_DISABLE_BLOG_USER' ) && ACTIVITYPUB_DISABLE_BLOG_USER ) { - return ACTIVITYPUB_ACTOR_MODE; - } - - return $pre; - } - - /** - * Pre-get option filter for the Authorized Fetch. - * - * @param string $pre The pre-get option value. - * - * @return string If the constant is defined, return the value, otherwise return the pre-get option value. - */ - public static function pre_option_activitypub_authorized_fetch( $pre ) { - if ( ! \defined( 'ACTIVITYPUB_AUTHORIZED_FETCH' ) ) { - return $pre; - } - - if ( ACTIVITYPUB_AUTHORIZED_FETCH ) { - return '1'; - } - - return '0'; - } - - /** - * Pre-get option filter for the Shared Inbox. - * - * @param string $pre The pre-get option value. - * - * @return string If the constant is defined, return the value, otherwise return the pre-get option value. - */ - public static function pre_option_activitypub_shared_inbox( $pre ) { - if ( ! \defined( 'ACTIVITYPUB_SHARED_INBOX_FEATURE' ) ) { - return $pre; - } - - if ( ACTIVITYPUB_SHARED_INBOX_FEATURE ) { - return '1'; - } - - return '0'; - } - - /** * Store permalink in meta, to send delete Activity. * @@ -902,18 +835,4 @@ public static function register_user_meta() { ) ); } - - /** - * Disallow interactions if the constant is set. - * - * @param bool $pre_option The value of the option. - * @return bool|string The value of the option. - */ - public static function maybe_disable_interactions( $pre_option ) { - if ( ACTIVITYPUB_DISABLE_INCOMING_INTERACTIONS ) { - return '0'; - } - - return $pre_option; - } } diff --git a/includes/class-options.php b/includes/class-options.php new file mode 100644 index 000000000..d30ef9ade --- /dev/null +++ b/includes/class-options.php @@ -0,0 +1,124 @@ + 'activitypub_outbox_purge_days' ) ); + if ( ! defined( 'ACTIVITYPUB_SEND_VARY_HEADER' ) ) { + \add_settings_field( + 'activitypub_vary_header', + \__( 'Vary Header', 'activitypub' ), + array( self::class, 'render_vary_header_field' ), + 'activitypub_advanced_settings', + 'activitypub_advanced_settings', + array( 'label_for' => 'activitypub_vary_header' ) + ); + } + if ( ! defined( 'ACTIVITYPUB_AUTHORIZED_FETCH' ) ) { \add_settings_field( 'activitypub_authorized_fetch', @@ -101,6 +112,24 @@ public static function render_outbox_purge_days_field() { ) . '

'; } + /** + * Render vary header field. + */ + public static function render_vary_header_field() { + $value = \get_option( 'activitypub_vary_header', '0' ); + ?> +

+ +

+

+ +

+ false, ); + $info['activitypub']['fields']['vary_header'] = array( + 'label' => \__( 'Vary Header', 'activitypub' ), + 'value' => \esc_attr( (int) \get_option( 'activitypub_vary_header', '0' ) ), + 'private' => false, + ); + $info['activitypub']['fields']['shared_inbox'] = array( 'label' => \__( 'Shared Inbox', 'activitypub' ), 'value' => \esc_attr( (int) \get_option( 'activitypub_shared_inbox', '0' ) ), diff --git a/includes/wp-admin/class-settings.php b/includes/wp-admin/class-settings.php index 537a56c46..c0d9f4d0f 100644 --- a/includes/wp-admin/class-settings.php +++ b/includes/wp-admin/class-settings.php @@ -177,6 +177,16 @@ public static function register_settings() { ) ); + \register_setting( + 'activitypub_advanced', + 'activitypub_vary_header', + array( + 'type' => 'boolean', + 'description' => \__( 'Add the Vary header to the ActivityPub response.', 'activitypub' ), + 'default' => false, + ) + ); + \register_setting( 'activitypub_advanced', 'activitypub_authorized_fetch',