PluginProbe
ActivityPub / 5.7.0
ActivityPub v5.7.0
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
activitypub / includes / class-options.php

class-options.php in ActivityPub 5.7.0, at includes/class-options.php

125 lines 3.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Options file.
4 *
5 * @package ActivityPub
6 */
7
8 namespace ActivityPub;
9
10 /**
11 * Options class.
12 *
13 * @package ActivityPub
14 */
15 class Options {
16
17 /**
18 * Initialize the options.
19 */
20 public static function init() {
21 \add_filter( 'pre_option_activitypub_actor_mode', array( self::class, 'pre_option_activitypub_actor_mode' ) );
22 \add_filter( 'pre_option_activitypub_authorized_fetch', array( self::class, 'pre_option_activitypub_authorized_fetch' ) );
23 \add_filter( 'pre_option_activitypub_shared_inbox', array( self::class, 'pre_option_activitypub_shared_inbox' ) );
24 \add_filter( 'pre_option_activitypub_vary_header', array( self::class, 'pre_option_activitypub_vary_header' ) );
25
26 \add_filter( 'pre_option_activitypub_allow_likes', array( self::class, 'maybe_disable_interactions' ) );
27 \add_filter( 'pre_option_activitypub_allow_replies', array( self::class, 'maybe_disable_interactions' ) );
28 }
29
30
31 /**
32 * Pre-get option filter for the Actor-Mode.
33 *
34 * @param string|false $pre The pre-get option value.
35 *
36 * @return string|false The actor mode or false if it should not be filtered.
37 */
38 public static function pre_option_activitypub_actor_mode( $pre ) {
39 if ( \defined( 'ACTIVITYPUB_SINGLE_USER_MODE' ) && ACTIVITYPUB_SINGLE_USER_MODE ) {
40 return ACTIVITYPUB_BLOG_MODE;
41 }
42
43 if ( \defined( 'ACTIVITYPUB_DISABLE_USER' ) && ACTIVITYPUB_DISABLE_USER ) {
44 return ACTIVITYPUB_BLOG_MODE;
45 }
46
47 if ( \defined( 'ACTIVITYPUB_DISABLE_BLOG_USER' ) && ACTIVITYPUB_DISABLE_BLOG_USER ) {
48 return ACTIVITYPUB_ACTOR_MODE;
49 }
50
51 return $pre;
52 }
53
54 /**
55 * Pre-get option filter for the Authorized Fetch.
56 *
57 * @param string $pre The pre-get option value.
58 *
59 * @return string If the constant is defined, return the value, otherwise return the pre-get option value.
60 */
61 public static function pre_option_activitypub_authorized_fetch( $pre ) {
62 if ( ! \defined( 'ACTIVITYPUB_AUTHORIZED_FETCH' ) ) {
63 return $pre;
64 }
65
66 if ( ACTIVITYPUB_AUTHORIZED_FETCH ) {
67 return '1';
68 }
69
70 return '0';
71 }
72
73 /**
74 * Pre-get option filter for the Shared Inbox.
75 *
76 * @param string $pre The pre-get option value.
77 *
78 * @return string If the constant is defined, return the value, otherwise return the pre-get option value.
79 */
80 public static function pre_option_activitypub_shared_inbox( $pre ) {
81 if ( ! \defined( 'ACTIVITYPUB_SHARED_INBOX_FEATURE' ) ) {
82 return $pre;
83 }
84
85 if ( ACTIVITYPUB_SHARED_INBOX_FEATURE ) {
86 return '1';
87 }
88
89 return '0';
90 }
91
92 /**
93 * Pre-get option filter for the Vary Header.
94 *
95 * @param string $pre The pre-get option value.
96 *
97 * @return string If the constant is defined, return the value, otherwise return the pre-get option value.
98 */
99 public static function pre_option_activitypub_vary_header( $pre ) {
100 if ( ! \defined( 'ACTIVITYPUB_SEND_VARY_HEADER' ) ) {
101 return $pre;
102 }
103
104 if ( ACTIVITYPUB_SEND_VARY_HEADER ) {
105 return '1';
106 }
107
108 return '0';
109 }
110
111 /**
112 * Disallow interactions if the constant is set.
113 *
114 * @param bool $pre_option The value of the option.
115 * @return bool|string The value of the option.
116 */
117 public static function maybe_disable_interactions( $pre_option ) {
118 if ( ACTIVITYPUB_DISABLE_INCOMING_INTERACTIONS ) {
119 return '0';
120 }
121
122 return $pre_option;
123 }
124 }
125