PluginProbe
ActivityPub / 8.0.2
ActivityPub v8.0.2
9.3.1 9.3.0 9.2.2 9.2.1 9.2.0 9.1.0 9.0.2 9.0.1 9.0.0 8.3.0 8.2.1 8.2.0 8.1.1 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.2.0 1.3.0 2.0.0 2.0.1 2.1.0 2.1.1 All 160 releases
← All changes | includes/class-options.php +10 -385 9.3.08.0.2 View file →
@@ -26,12 +26,8 @@
26 26 \add_filter( 'pre_option_activitypub_vary_header', array( self::class, 'pre_option_activitypub_vary_header' ) );
27 27 \add_filter( 'pre_option_activitypub_following_ui', array( self::class, 'pre_option_activitypub_following_ui' ) );
28 28 \add_filter( 'pre_option_activitypub_create_posts', array( self::class, 'pre_option_activitypub_create_posts' ) );
29 29
30 - \add_filter( 'pre_option_activitypub_distribution_mode', array( self::class, 'pre_option_activitypub_distribution_mode' ) );
31 - \add_filter( 'activitypub_dispatcher_batch_size', array( self::class, 'filter_dispatcher_batch_size' ) );
32 - \add_filter( 'activitypub_scheduler_async_batch_pause', array( self::class, 'filter_scheduler_batch_pause' ), 10, 2 );
33 -
34 30 \add_filter( 'pre_option_activitypub_allow_likes', array( self::class, 'maybe_disable_interactions' ) );
35 31 \add_filter( 'pre_option_activitypub_allow_replies', array( self::class, 'maybe_disable_interactions' ) );
36 32
37 33 \add_filter( 'default_option_activitypub_negotiate_content', array( self::class, 'default_option_activitypub_negotiate_content' ) );
@@ -38,12 +34,8 @@
38 34 \add_filter( 'option_activitypub_max_image_attachments', array( self::class, 'default_max_image_attachments' ) );
39 35 \add_filter( 'option_activitypub_support_post_types', array( self::class, 'support_post_types_ensure_array' ) );
40 36 \add_filter( 'option_activitypub_object_type', array( self::class, 'default_object_type' ) );
41 37
42 - \add_filter( 'option_activitypub_outbox_purge_days', array( self::class, 'sanitize_purge_days' ) );
43 - \add_filter( 'option_activitypub_inbox_purge_days', array( self::class, 'sanitize_purge_days' ) );
44 - \add_filter( 'option_activitypub_ap_post_purge_days', array( self::class, 'sanitize_purge_days' ) );
45 -
46 38 \add_action( 'update_option_activitypub_relay_mode', array( self::class, 'relay_mode_changed' ), 10, 2 );
47 39 }
48 40
49 41 /**
@@ -206,26 +198,8 @@
206 198 );
207 199
208 200 \register_setting(
209 201 'activitypub',
210 - 'activitypub_default_feature_policy',
211 - array(
212 - 'type' => 'string',
213 - 'description' => 'Default policy for who can include this site\'s actors in featured collections (FEP-7aa9).',
214 - 'default' => ACTIVITYPUB_INTERACTION_POLICY_ME,
215 - 'sanitize_callback' => static function ( $value ) {
216 - $allowed = array(
217 - ACTIVITYPUB_INTERACTION_POLICY_ANYONE,
218 - ACTIVITYPUB_INTERACTION_POLICY_FOLLOWERS,
219 - ACTIVITYPUB_INTERACTION_POLICY_ME,
220 - );
221 - return \in_array( $value, $allowed, true ) ? $value : ACTIVITYPUB_INTERACTION_POLICY_ME;
222 - },
223 - )
224 - );
225 -
226 - \register_setting(
227 - 'activitypub',
228 202 'activitypub_relays',
229 203 array(
230 204 'type' => 'array',
231 205 'description' => 'Relays',
@@ -251,14 +225,11 @@
251 225 \register_setting(
252 226 'activitypub_advanced',
253 227 'activitypub_outbox_purge_days',
254 228 array(
255 - 'type' => 'integer',
256 - 'description' => 'Number of days to keep items in the Outbox.',
257 - 'default' => ACTIVITYPUB_OUTBOX_PURGE_DAYS,
258 - 'sanitize_callback' => static function ( $value ) {
259 - return \max( 1, \absint( $value ) );
260 - },
229 + 'type' => 'integer',
230 + 'description' => 'Number of days to keep items in the Outbox.',
231 + 'default' => 180,
261 232 )
262 233 );
263 234
264 235 \register_setting(
@@ -264,14 +235,11 @@
264 235 \register_setting(
265 236 'activitypub_advanced',
266 237 'activitypub_inbox_purge_days',
267 238 array(
268 - 'type' => 'integer',
269 - 'description' => 'Number of days to keep items in the Inbox.',
270 - 'default' => ACTIVITYPUB_INBOX_PURGE_DAYS,
271 - 'sanitize_callback' => static function ( $value ) {
272 - return \max( 1, \absint( $value ) );
273 - },
239 + 'type' => 'integer',
240 + 'description' => 'Number of days to keep items in the Inbox.',
241 + 'default' => 180,
274 242 )
275 243 );
276 244
277 245 \register_setting(
@@ -277,14 +245,11 @@
277 245 \register_setting(
278 246 'activitypub_advanced',
279 247 'activitypub_ap_post_purge_days',
280 248 array(
281 - 'type' => 'integer',
282 - 'description' => 'Number of days to keep remote posts.',
283 - 'default' => ACTIVITYPUB_AP_POST_PURGE_DAYS,
284 - 'sanitize_callback' => static function ( $value ) {
285 - return \max( 1, \absint( $value ) );
286 - },
249 + 'type' => 'integer',
250 + 'description' => 'Number of days to keep remote posts.',
251 + 'default' => 30,
287 252 )
288 253 );
289 254
290 255 \register_setting(
@@ -322,9 +287,9 @@
322 287 'activitypub_rfc9421_signature',
323 288 array(
324 289 'type' => 'boolean',
325 290 'description' => 'Use RFC-9421 signature.',
326 - 'default' => true,
291 + 'default' => false,
327 292 )
328 293 );
329 294
330 295 \register_setting(
@@ -358,18 +323,8 @@
358 323 );
359 324
360 325 \register_setting(
361 326 'activitypub_advanced',
362 - 'activitypub_api',
363 - array(
364 - 'type' => 'boolean',
365 - 'description' => 'Enable the ActivityPub API to allow third-party clients.',
366 - 'default' => false,
367 - )
368 - );
369 -
370 - \register_setting(
371 - 'activitypub_advanced',
372 327 'activitypub_object_type',
373 328 array(
374 329 'type' => 'string',
375 330 'description' => 'The Activity-Object-Type',
@@ -392,47 +347,8 @@
392 347 'sanitize_callback' => 'absint',
393 348 )
394 349 );
395 350
396 - $default_distribution = self::get_distribution_preset_values()['default'];
397 -
398 - \register_setting(
399 - 'activitypub_advanced',
400 - 'activitypub_distribution_mode',
401 - array(
402 - 'type' => 'string',
403 - 'description' => \__( 'Distribution mode for federation delivery.', 'activitypub' ),
404 - 'default' => 'default',
405 - 'sanitize_callback' => array( self::class, 'sanitize_distribution_mode' ),
406 - )
407 - );
408 -
409 - \register_setting(
410 - 'activitypub_advanced',
411 - 'activitypub_custom_batch_size',
412 - array(
413 - 'type' => 'integer',
414 - 'description' => \__( 'Custom batch size for federation delivery.', 'activitypub' ),
415 - 'default' => $default_distribution['batch_size'],
416 - 'sanitize_callback' => static function ( $value ) {
417 - return \min( 500, \max( 1, \absint( $value ) ) );
418 - },
419 - )
420 - );
421 -
422 - \register_setting(
423 - 'activitypub_advanced',
424 - 'activitypub_custom_batch_pause',
425 - array(
426 - 'type' => 'integer',
427 - 'description' => \__( 'Custom pause in seconds between batches.', 'activitypub' ),
428 - 'default' => $default_distribution['pause'],
429 - 'sanitize_callback' => static function ( $value ) {
430 - return \min( 3600, \absint( $value ) );
431 - },
432 - )
433 - );
434 -
435 351 /*
436 352 * Options Group: activitypub_blog
437 353 */
438 354 \register_setting(
@@ -499,28 +415,8 @@
499 415 );
500 416
501 417 \register_setting(
502 418 'activitypub_blog',
503 - 'activitypub_mailer_annual_report',
504 - array(
505 - 'type' => 'integer',
506 - 'description' => 'Send the annual Fediverse Year in Review email.',
507 - 'default' => 1,
508 - )
509 - );
510 -
511 - \register_setting(
512 - 'activitypub_blog',
513 - 'activitypub_mailer_monthly_report',
514 - array(
515 - 'type' => 'integer',
516 - 'description' => 'Send a monthly Fediverse stats report email.',
517 - 'default' => 0,
518 - )
519 - );
520 -
521 - \register_setting(
522 - 'activitypub_blog',
523 419 'activitypub_blog_user_also_known_as',
524 420 array(
525 421 'type' => 'array',
526 422 'description' => 'An array of URLs that the blog user is known by.',
@@ -731,279 +627,8 @@
731 627 $value = ACTIVITYPUB_DEFAULT_OBJECT_TYPE;
732 628 }
733 629
734 630 return $value;
735 - }
736 -
737 - /**
738 - * Pre-get option filter for the Distribution Mode.
739 - *
740 - * @since 9.0.0
741 - *
742 - * @param string|false $pre The pre-get option value.
743 - *
744 - * @return string|false The distribution mode or false if it should not be filtered.
745 - */
746 - public static function pre_option_activitypub_distribution_mode( $pre ) {
747 - return self::resolve_distribution_mode( $pre, ACTIVITYPUB_DISTRIBUTION_MODE );
748 - }
749 -
750 - /**
751 - * Whether the distribution mode is locked to a valid preset by the
752 - * `ACTIVITYPUB_DISTRIBUTION_MODE` constant.
753 - *
754 - * Returns true only when the constant is set to a key recognized by
755 - * `get_distribution_preset_values()`. Invalid constant values fall back
756 - * to `'default'` at runtime (see `resolve_distribution_mode()`) but the
757 - * UI stays visible so admins can spot the misconfiguration.
758 - *
759 - * @since 9.0.0
760 - *
761 - * @return bool True when the constant pins the mode to a valid preset.
762 - */
763 - public static function is_distribution_mode_locked() {
764 - if ( false === ACTIVITYPUB_DISTRIBUTION_MODE ) {
765 - return false;
766 - }
767 -
768 - return \in_array( ACTIVITYPUB_DISTRIBUTION_MODE, \array_keys( self::get_distribution_preset_values() ), true );
769 - }
770 -
771 - /**
772 - * Resolve the distribution mode against the wp-config constant.
773 - *
774 - * Extracted from `pre_option_activitypub_distribution_mode()` so the
775 - * constant-lock path can be exercised from tests without redefining
776 - * the real constant.
777 - *
778 - * Only preset modes are honored via the constant. The 'custom' mode
779 - * is excluded because its batch size and pause values are still read
780 - * from the database, which would defeat the purpose of locking the
781 - * mode via wp-config.php.
782 - *
783 - * @since 9.0.0
784 - *
785 - * @param string|false $pre The pre-get option value.
786 - * @param mixed $constant_value The value of `ACTIVITYPUB_DISTRIBUTION_MODE`.
787 - *
788 - * @return string|false Mode if locked, `$pre` otherwise.
789 - */
790 - public static function resolve_distribution_mode( $pre, $constant_value ) {
791 - if ( false === $constant_value ) {
792 - return $pre;
793 - }
794 -
795 - $allowed = \array_keys( self::get_distribution_preset_values() );
796 -
797 - if ( \in_array( $constant_value, $allowed, true ) ) {
798 - return $constant_value;
799 - }
800 -
801 - \_doing_it_wrong(
802 - __METHOD__,
803 - \sprintf(
804 - /* translators: %s: invalid constant value */
805 - \esc_html__( 'ACTIVITYPUB_DISTRIBUTION_MODE value %s is not a valid preset; falling back to default.', 'activitypub' ),
806 - \esc_html( (string) $constant_value )
807 - ),
808 - '9.0.0'
809 - );
810 -
811 - return 'default';
812 - }
813 -
814 - /**
815 - * Get the raw batch_size/pause values for each distribution preset.
816 - *
817 - * Single source of truth for the preset values, used in the hot path
818 - * (get_distribution_params, sanitize_distribution_mode, resolve_distribution_mode)
819 - * to avoid running translation calls just to check keys or numbers.
820 - *
821 - * @since 9.0.0
822 - *
823 - * @return array Associative array of mode => { batch_size, pause }.
824 - */
825 - private static function get_distribution_preset_values() {
826 - return array(
827 - 'default' => array(
828 - 'batch_size' => 100,
829 - 'pause' => 15,
830 - ),
831 - 'balanced' => array(
832 - 'batch_size' => 50,
833 - 'pause' => 30,
834 - ),
835 - 'eco' => array(
836 - 'batch_size' => 20,
837 - 'pause' => 30,
838 - ),
839 - );
840 - }
841 -
842 - /**
843 - * Get the available distribution mode presets with UI labels.
844 - *
845 - * Decorates `get_distribution_preset_values()` with translated labels
846 - * and descriptions for use in the admin settings page.
847 - *
848 - * @since 9.0.0
849 - *
850 - * @return array Associative array of mode => { batch_size, pause, label, description }.
851 - */
852 - public static function get_distribution_modes() {
853 - $modes = self::get_distribution_preset_values();
854 -
855 - $modes['default']['label'] = \__( 'Default', 'activitypub' );
856 - $modes['default']['description'] = \sprintf(
857 - /* translators: 1: batch size, 2: pause in seconds */
858 - \__( 'Deliver activities as fast as possible (<code>%1$d</code> per batch, <code>%2$ds</code> pause).', 'activitypub' ),
859 - $modes['default']['batch_size'],
860 - $modes['default']['pause']
861 - );
862 - $modes['balanced']['label'] = \__( 'Balanced', 'activitypub' );
863 - $modes['balanced']['description'] = \sprintf(
864 - /* translators: 1: batch size, 2: pause in seconds */
865 - \__( 'Moderate pace with reasonable pauses between batches (<code>%1$d</code> per batch, <code>%2$ds</code> pause).', 'activitypub' ),
866 - $modes['balanced']['batch_size'],
867 - $modes['balanced']['pause']
868 - );
869 - $modes['eco']['label'] = \__( 'Eco Mode', 'activitypub' );
870 - $modes['eco']['description'] = \sprintf(
871 - /* translators: 1: batch size, 2: pause in seconds */
872 - \__( 'Gentle on server resources, ideal for shared hosting (<code>%1$d</code> per batch, <code>%2$ds</code> pause).', 'activitypub' ),
873 - $modes['eco']['batch_size'],
874 - $modes['eco']['pause']
875 - );
876 -
877 - return $modes;
878 - }
879 -
880 - /**
881 - * Sanitize the distribution mode option.
882 - *
883 - * Restricts the stored value to a known preset (from
884 - * `get_distribution_modes()`) or `'custom'`. Anything else
885 - * falls back to `'default'`.
886 - *
887 - * @since 9.0.0
888 - *
889 - * @param string $value The submitted option value.
890 - *
891 - * @return string A valid distribution mode key.
892 - */
893 - public static function sanitize_distribution_mode( $value ) {
894 - $allowed = \array_merge( \array_keys( self::get_distribution_preset_values() ), array( 'custom' ) );
895 -
896 - return \in_array( $value, $allowed, true ) ? $value : 'default';
897 - }
898 -
899 - /**
900 - * Get distribution parameters for the current mode.
901 - *
902 - * @since 9.0.0
903 - *
904 - * @return array { mode: string, batch_size: int, pause: int }
905 - */
906 - public static function get_distribution_params() {
907 - $mode = \get_option( 'activitypub_distribution_mode', 'default' );
908 - $modes = self::get_distribution_preset_values();
909 -
910 - if ( isset( $modes[ $mode ] ) ) {
911 - return array(
912 - 'mode' => $mode,
913 - 'batch_size' => $modes[ $mode ]['batch_size'],
914 - 'pause' => $modes[ $mode ]['pause'],
915 - );
916 - }
917 -
918 - // Custom mode reads its values from dedicated options; any other
919 - // unrecognized mode falls back to the default preset so callers
920 - // always receive a valid configuration.
921 - if ( 'custom' !== $mode ) {
922 - return array(
923 - 'mode' => 'default',
924 - 'batch_size' => $modes['default']['batch_size'],
925 - 'pause' => $modes['default']['pause'],
926 - );
927 - }
928 -
929 - $default_params = $modes['default'];
930 -
931 - return array(
932 - 'mode' => 'custom',
933 - 'batch_size' => \max( 1, \absint( \get_option( 'activitypub_custom_batch_size', $default_params['batch_size'] ) ) ),
934 - 'pause' => \absint( \get_option( 'activitypub_custom_batch_pause', $default_params['pause'] ) ),
935 - );
936 - }
937 -
938 - /**
939 - * Filter the dispatcher batch size based on distribution mode.
940 - *
941 - * In `'default'` mode the upstream value is passed through so the
942 - * `ACTIVITYPUB_OUTBOX_PROCESSING_BATCH_SIZE` constant and other filters
943 - * still win; any explicit mode imposes its own batch size.
944 - *
945 - * @since 9.0.0
946 - *
947 - * @param int $batch_size The default batch size.
948 - *
949 - * @return int The batch size for the current distribution mode.
950 - */
951 - public static function filter_dispatcher_batch_size( $batch_size ) {
952 - $params = self::get_distribution_params();
953 -
954 - return 'default' === $params['mode'] ? $batch_size : $params['batch_size'];
955 - }
956 -
957 - /**
958 - * Filter the scheduler batch pause based on distribution mode.
959 - *
960 - * Only delivery batches (`activitypub_send_activity`) are affected. Every
961 - * mode imposes its own delivery pause: `'default'` is the fast preset, which
962 - * is intentionally shorter than the generic async-batch baseline, so it does
963 - * not pass the upstream value through.
964 - *
965 - * @since 9.0.0
966 - *
967 - * @param int $pause The default pause in seconds.
968 - * @param string|false|null $hook The async batch hook being scheduled.
969 - *
970 - * @return int The pause for the current distribution mode.
971 - */
972 - public static function filter_scheduler_batch_pause( $pause, $hook = null ) {
973 - if ( 'activitypub_send_activity' !== $hook ) {
974 - return $pause;
975 - }
976 -
977 - return self::get_distribution_params()['pause'];
978 - }
979 -
980 - /**
981 - * Sanitize purge day values.
982 - *
983 - * Ensures the value is a non-negative integer. Returns the
984 - * registered default when the stored value is empty or false
985 - * (option not properly set), but allows 0 to disable purging.
986 - *
987 - * @since 8.1.0
988 - *
989 - * @param mixed $value The stored option value.
990 - *
991 - * @return int The sanitized value.
992 - */
993 - public static function sanitize_purge_days( $value ) {
994 - if ( '' === $value || false === $value ) {
995 - $filter = \current_filter();
996 - $defaults = array(
997 - 'option_activitypub_outbox_purge_days' => ACTIVITYPUB_OUTBOX_PURGE_DAYS,
998 - 'option_activitypub_inbox_purge_days' => ACTIVITYPUB_INBOX_PURGE_DAYS,
999 - 'option_activitypub_ap_post_purge_days' => ACTIVITYPUB_AP_POST_PURGE_DAYS,
1000 - );
1001 -
1002 - return $defaults[ $filter ] ?? ACTIVITYPUB_OUTBOX_PURGE_DAYS;
1003 - }
1004 -
1005 - return \max( 1, \absint( $value ) );
1006 631 }
1007 632
1008 633 /**
1009 634 * Handle relay mode option changes.