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