Skip to content
4 changes: 4 additions & 0 deletions .github/changelog/1552-from-description
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: changed

Add option to enable/disable the `Vary` Header to the "Advanced Settings".
9 changes: 5 additions & 4 deletions activitypub.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' ) );
Expand Down
147 changes: 33 additions & 114 deletions includes/class-activitypub.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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' );
}

/**
Expand Down Expand Up @@ -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 );
}
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -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;
}
}
124 changes: 124 additions & 0 deletions includes/class-options.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
<?php
/**
* Options file.
*
* @package ActivityPub
*/

namespace ActivityPub;

/**
* Options class.
*
* @package ActivityPub
*/
class Options {

/**
* Initialize the options.
*/
public static function init() {
\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_filter( 'pre_option_activitypub_vary_header', array( self::class, 'pre_option_activitypub_vary_header' ) );

\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' ) );
}


/**
* 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';
}

/**
* Pre-get option filter for the Vary Header.
*
* @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_vary_header( $pre ) {
if ( ! \defined( 'ACTIVITYPUB_SEND_VARY_HEADER' ) ) {
return $pre;
}

if ( ACTIVITYPUB_SEND_VARY_HEADER ) {
return '1';
}

return '0';
}

/**
* 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;
}
}
1 change: 0 additions & 1 deletion includes/constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
\defined( 'ACTIVITYPUB_DISABLE_REWRITES' ) || \define( 'ACTIVITYPUB_DISABLE_REWRITES', false );
\defined( 'ACTIVITYPUB_DISABLE_INCOMING_INTERACTIONS' ) || \define( 'ACTIVITYPUB_DISABLE_INCOMING_INTERACTIONS', false );
\defined( 'ACTIVITYPUB_DISABLE_OUTGOING_INTERACTIONS' ) || \define( 'ACTIVITYPUB_DISABLE_OUTGOING_INTERACTIONS', false );
\defined( 'ACTIVITYPUB_SEND_VARY_HEADER' ) || \define( 'ACTIVITYPUB_SEND_VARY_HEADER', false );
\defined( 'ACTIVITYPUB_DEFAULT_OBJECT_TYPE' ) || \define( 'ACTIVITYPUB_DEFAULT_OBJECT_TYPE', 'wordpress-post-format' );
\defined( 'ACTIVITYPUB_OUTBOX_PROCESSING_BATCH_SIZE' ) || \define( 'ACTIVITYPUB_OUTBOX_PROCESSING_BATCH_SIZE', 100 );

Expand Down
29 changes: 29 additions & 0 deletions includes/wp-admin/class-advanced-settings-fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@ public static function register_advanced_fields() {
array( 'label_for' => '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',
Expand Down Expand Up @@ -101,6 +112,24 @@ public static function render_outbox_purge_days_field() {
) . '</p>';
}

/**
* Render vary header field.
*/
public static function render_vary_header_field() {
$value = \get_option( 'activitypub_vary_header', '0' );
?>
<p>
<label>
<input type="checkbox" id="activitypub_vary_header" name="activitypub_vary_header" value="1" <?php checked( '1', $value ); ?> />
<?php echo \wp_kses( \__( 'Help prevent incorrect caching of ActivityPub responses.', 'activitypub' ), array( 'code' => array() ) ); ?>
</label>
</p>
<p class="description">
<?php \esc_html_e( 'Enable this if you notice your site showing technical content instead of normal web pages, or if your ActivityPub connections seem unreliable. This setting helps your site deliver the right format of content to different services automatically.', 'activitypub' ); ?>
</p>
<?php
}

/**
* Render use Authorized Fetch field.
*/
Expand Down
6 changes: 6 additions & 0 deletions includes/wp-admin/class-health-check.php
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,12 @@ public static function debug_information( $info ) {
'private' => 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' ) ),
Expand Down
Loading
Loading