Skip to content

Commit baa0ced

Browse files
pfefferleobenland
andauthored
Advanced Settings (#1449)
* Advanced Settings * fix phpcs * fix phpdoc * Add changelog * add option support * enable "Advanced Settings" tab if one of the advanced settings were already changed * fix phpcs * add missing punctuation mark * phpcs fixes * Add `WP Admin` feature * simplify function * added changelog file * more descriptive function name * fix phpcs * bring back relays * Add settings * save settings the same way we do with the welcome page * use consistent wording * fix phpcs * remove unused code * output escaping * added backslashes * re-add interaction settings * fix settings * Fix phpcs * remove migration * register user meta instead of setting * Update includes/wp-admin/class-settings-fields.php Co-authored-by: Konstantin Obenland <[email protected]> * Update includes/functions.php Co-authored-by: Konstantin Obenland <[email protected]> * Update includes/wp-admin/class-settings.php Co-authored-by: Konstantin Obenland <[email protected]> * Update includes/wp-admin/class-advanced-settings-fields.php Co-authored-by: Konstantin Obenland <[email protected]> * re-order * do not show if const is used * define as global * define as global * moved it to the wrong place 😂 --------- Co-authored-by: Konstantin Obenland <[email protected]>
1 parent 7f5ee1d commit baa0ced

File tree

9 files changed

+273
-168
lines changed

9 files changed

+273
-168
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: added
3+
4+
Advanced Settings tab, with special settings for advanced users.

activitypub.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ function plugin_admin_init() {
100100
\add_action( 'admin_init', array( __NAMESPACE__ . '\WP_Admin\Settings', 'init' ) );
101101
\add_action( 'admin_init', array( __NAMESPACE__ . '\WP_Admin\Settings_Fields', 'init' ) );
102102
\add_action( 'admin_init', array( __NAMESPACE__ . '\WP_Admin\Welcome_Fields', 'init' ) );
103+
\add_action( 'admin_init', array( __NAMESPACE__ . '\WP_Admin\Advanced_Settings_Fields', 'init' ) );
103104
\add_action( 'admin_init', array( __NAMESPACE__ . '\WP_Admin\Blog_Settings_Fields', 'init' ) );
104105
\add_action( 'admin_init', array( __NAMESPACE__ . '\WP_Admin\User_Settings_Fields', 'init' ) );
105106

includes/class-activitypub.php

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ public static function init() {
4949

5050
\add_action( 'updated_postmeta', array( self::class, 'updated_postmeta' ), 10, 4 );
5151
\add_action( 'added_post_meta', array( self::class, 'updated_postmeta' ), 10, 4 );
52-
\add_filter( 'pre_option_activitypub_actor_mode', array( self::class, 'pre_get_option' ) );
52+
\add_filter( 'pre_option_activitypub_actor_mode', array( self::class, 'pre_option_activitypub_actor_mode' ) );
53+
\add_filter( 'pre_option_activitypub_authorized_fetch', array( self::class, 'pre_option_activitypub_authorized_fetch' ) );
5354

5455
\add_action( 'init', array( self::class, 'register_user_meta' ), 11 );
5556

@@ -397,7 +398,7 @@ public static function pre_get_avatar_data( $args, $id_or_email ) {
397398
*
398399
* @return string|false The actor mode or false if it should not be filtered.
399400
*/
400-
public static function pre_get_option( $pre ) {
401+
public static function pre_option_activitypub_actor_mode( $pre ) {
401402
if ( \defined( 'ACTIVITYPUB_SINGLE_USER_MODE' ) && ACTIVITYPUB_SINGLE_USER_MODE ) {
402403
return ACTIVITYPUB_BLOG_MODE;
403404
}
@@ -413,6 +414,25 @@ public static function pre_get_option( $pre ) {
413414
return $pre;
414415
}
415416

417+
/**
418+
* Pre-get option filter for the Authorized Fetch.
419+
*
420+
* @param string $pre The pre-get option value.
421+
*
422+
* @return string If the constant is defined, return the value, otherwise return the pre-get option value.
423+
*/
424+
public static function pre_option_activitypub_authorized_fetch( $pre ) {
425+
if ( ! \defined( 'ACTIVITYPUB_AUTHORIZED_FETCH' ) ) {
426+
return $pre;
427+
}
428+
429+
if ( ACTIVITYPUB_AUTHORIZED_FETCH ) {
430+
return '1';
431+
}
432+
433+
return '0';
434+
}
435+
416436
/**
417437
* Store permalink in meta, to send delete Activity.
418438
*
@@ -832,6 +852,18 @@ public static function register_user_meta() {
832852
'sanitize_callback' => 'absint',
833853
)
834854
);
855+
856+
\register_meta(
857+
'user',
858+
'activitypub_show_advanced_tab',
859+
array(
860+
'type' => 'integer',
861+
'description' => 'Whether to show the advanced tab.',
862+
'single' => true,
863+
'default' => 0,
864+
'sanitize_callback' => 'absint',
865+
)
866+
);
835867
}
836868

837869
/**

includes/functions.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1414,14 +1414,7 @@ function get_upload_baseurl() {
14141414
* @return boolean True if Authorized-Fetch is enabled, false otherwise.
14151415
*/
14161416
function use_authorized_fetch() {
1417-
$use = false;
1418-
1419-
// Prefer the constant over the option.
1420-
if ( \defined( 'ACTIVITYPUB_AUTHORIZED_FETCH' ) ) {
1421-
$use = ACTIVITYPUB_AUTHORIZED_FETCH;
1422-
} else {
1423-
$use = (bool) \get_option( 'activitypub_authorized_fetch', '0' );
1424-
}
1417+
$use = (bool) \get_option( 'activitypub_authorized_fetch' );
14251418

14261419
/**
14271420
* Filters whether to use Authorized-Fetch.
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
<?php
2+
/**
3+
* Advanced Settings Fields file.
4+
*
5+
* @package ActivityPub
6+
*/
7+
8+
namespace ActivityPub\WP_Admin;
9+
10+
/**
11+
* Advanced Settings Fields class.
12+
*/
13+
class Advanced_Settings_Fields {
14+
15+
/**
16+
* Initialize.
17+
*/
18+
public static function init() {
19+
\add_action( 'load-settings_page_activitypub', array( self::class, 'register_advanced_fields' ) );
20+
}
21+
22+
/**
23+
* Register settings.
24+
*/
25+
public static function register_advanced_fields() {
26+
\add_settings_section(
27+
'activitypub_advanced_settings',
28+
\__( 'Advanced Settings', 'activitypub' ),
29+
array( self::class, 'render_advanced_settings_section' ),
30+
'activitypub_advanced_settings'
31+
);
32+
33+
\add_settings_field(
34+
'activitypub_outbox_purge_days',
35+
\__( 'Outbox Retention Period', 'activitypub' ),
36+
array( self::class, 'render_outbox_purge_days_field' ),
37+
'activitypub_advanced_settings',
38+
'activitypub_advanced_settings',
39+
array( 'label_for' => 'activitypub_outbox_purge_days' )
40+
);
41+
42+
if ( ! defined( 'ACTIVITYPUB_AUTHORIZED_FETCH' ) ) {
43+
\add_settings_field(
44+
'activitypub_authorized_fetch',
45+
\__( 'Authorized Fetch', 'activitypub' ),
46+
array( self::class, 'render_authorized_fetch_field' ),
47+
'activitypub_advanced_settings',
48+
'activitypub_advanced_settings',
49+
array( 'label_for' => 'activitypub_authorized_fetch' )
50+
);
51+
}
52+
}
53+
54+
/**
55+
* Render Advanced Settings Section.
56+
*/
57+
public static function render_advanced_settings_section() {
58+
?>
59+
<p>
60+
<?php
61+
$allowed_html = array(
62+
'a' => array(
63+
'href' => true,
64+
'target' => true,
65+
),
66+
);
67+
echo \wp_kses( \__( 'Advanced settings allow deep customization but can affect your site&#8217;s functionality, security, or performance if misconfigured. Only proceed if you fully understand the changes, and always back up your site beforehand. If unsure, consult <a href="https://github.com/Automattic/wordpress-activitypub/tree/trunk/docs" target="_blank">documentation</a> or seek <a href="https://wordpress.org/support/plugin/activitypub/" target="_blank">expert advice</a>.', 'activitypub' ), $allowed_html );
68+
?>
69+
</p>
70+
<?php
71+
}
72+
73+
/**
74+
* Render outbox purge days field.
75+
*/
76+
public static function render_outbox_purge_days_field() {
77+
$value = \get_option( 'activitypub_outbox_purge_days', 180 );
78+
echo '<input type="number" id="activitypub_outbox_purge_days" name="activitypub_outbox_purge_days" value="' . esc_attr( $value ) . '" class="small-text" min="0" max="365" />';
79+
echo '<p class="description">' . \wp_kses(
80+
sprintf(
81+
// translators: 1: Definition of Outbox; 2: Default value (180).
82+
\__( 'Maximum number of days to keep items in the <abbr title="%1$s">Outbox</abbr>. A lower value might be better for sites with lots of activity to maintain site performance. Default: <code>%2$s</code>', 'activitypub' ),
83+
\esc_attr__( 'A virtual location on a user&#8217;s profile where all the activities (posts, likes, replies) they publish are stored, acting as a feed that other users can access to see their publicly shared content', 'activitypub' ),
84+
\esc_html( 180 )
85+
),
86+
array(
87+
'abbr' => array( 'title' => array() ),
88+
'code' => array(),
89+
)
90+
) . '</p>';
91+
}
92+
93+
/**
94+
* Render use Authorized Fetch field.
95+
*/
96+
public static function render_authorized_fetch_field() {
97+
$value = \get_option( 'activitypub_authorized_fetch', '1' );
98+
?>
99+
<p>
100+
<label>
101+
<input type="checkbox" id="activitypub_authorized_fetch" name="activitypub_authorized_fetch" value="1" <?php checked( '1', $value ); ?> />
102+
<?php \esc_html_e( 'Require HTTP signature authentication on ActivityPub representations of public posts and profiles.', 'activitypub' ); ?>
103+
</label>
104+
</p>
105+
<p class="description">
106+
<?php \esc_html_e( '⚠ Secure mode has its limitations, which is why it is not enabled by default. It is not fully supported by all software in the fediverse, and some features may break, especially when interacting with Mastodon servers older than version 3.0. Additionally, since it requires authentication for public content, caching is not possible, leading to higher computational costs.', 'activitypub' ); ?>
107+
</p>
108+
<p class="description">
109+
<?php \esc_html_e( '⚠ Secure mode does not hide the HTML representations of public posts and profiles. While HTML is a less consistent format (that potentially changes often) compared to first-class ActivityPub representations or the REST API, it still poses a potential risk for content scraping.', 'activitypub' ); ?>
110+
</p>
111+
<?php
112+
}
113+
}

0 commit comments

Comments
 (0)