PluginProbe
ActivityPub / 7.0.0
ActivityPub v7.0.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 7.0.0, at includes/class-options.php

178 lines 4.6 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 class Options {
14
15 /**
16 * Initialize the options.
17 */
18 public static function init() {
19 \add_filter( 'pre_option_activitypub_actor_mode', array( self::class, 'pre_option_activitypub_actor_mode' ) );
20 \add_filter( 'pre_option_activitypub_authorized_fetch', array( self::class, 'pre_option_activitypub_authorized_fetch' ) );
21 \add_filter( 'pre_option_activitypub_shared_inbox', array( self::class, 'pre_option_activitypub_shared_inbox' ) );
22 \add_filter( 'pre_option_activitypub_vary_header', array( self::class, 'pre_option_activitypub_vary_header' ) );
23
24 \add_filter( 'pre_option_activitypub_allow_likes', array( self::class, 'maybe_disable_interactions' ) );
25 \add_filter( 'pre_option_activitypub_allow_replies', array( self::class, 'maybe_disable_interactions' ) );
26
27 \add_filter( 'default_option_activitypub_negotiate_content', array( self::class, 'default_option_activitypub_negotiate_content' ) );
28 \add_filter( 'option_activitypub_max_image_attachments', array( self::class, 'default_max_image_attachments' ) );
29 }
30
31 /**
32 * Delete all options.
33 */
34 public static function delete() {
35 global $wpdb;
36
37 // phpcs:ignore WordPress.DB.DirectDatabaseQuery
38 $wpdb->query( "DELETE FROM $wpdb->options WHERE option_name LIKE 'activitypub_%'" );
39 }
40
41 /**
42 * Pre-get option filter for the Actor-Mode.
43 *
44 * @param string|false $pre The pre-get option value.
45 *
46 * @return string|false The actor mode or false if it should not be filtered.
47 */
48 public static function pre_option_activitypub_actor_mode( $pre ) {
49 if ( \defined( 'ACTIVITYPUB_SINGLE_USER_MODE' ) && ACTIVITYPUB_SINGLE_USER_MODE ) {
50 return ACTIVITYPUB_BLOG_MODE;
51 }
52
53 if ( \defined( 'ACTIVITYPUB_DISABLE_USER' ) && ACTIVITYPUB_DISABLE_USER ) {
54 return ACTIVITYPUB_BLOG_MODE;
55 }
56
57 if ( \defined( 'ACTIVITYPUB_DISABLE_BLOG_USER' ) && ACTIVITYPUB_DISABLE_BLOG_USER ) {
58 return ACTIVITYPUB_ACTOR_MODE;
59 }
60
61 return $pre;
62 }
63
64 /**
65 * Pre-get option filter for the Authorized Fetch.
66 *
67 * @param string $pre The pre-get option value.
68 *
69 * @return string If the constant is defined, return the value, otherwise return the pre-get option value.
70 */
71 public static function pre_option_activitypub_authorized_fetch( $pre ) {
72 if ( ! \defined( 'ACTIVITYPUB_AUTHORIZED_FETCH' ) ) {
73 return $pre;
74 }
75
76 if ( ACTIVITYPUB_AUTHORIZED_FETCH ) {
77 return '1';
78 }
79
80 return '0';
81 }
82
83 /**
84 * Pre-get option filter for the Shared Inbox.
85 *
86 * @param string $pre The pre-get option value.
87 *
88 * @return string If the constant is defined, return the value, otherwise return the pre-get option value.
89 */
90 public static function pre_option_activitypub_shared_inbox( $pre ) {
91 if ( ! \defined( 'ACTIVITYPUB_SHARED_INBOX_FEATURE' ) ) {
92 return $pre;
93 }
94
95 if ( ACTIVITYPUB_SHARED_INBOX_FEATURE ) {
96 return '1';
97 }
98
99 return '0';
100 }
101
102 /**
103 * Pre-get option filter for the Vary Header.
104 *
105 * @param string $pre The pre-get option value.
106 *
107 * @return string If the constant is defined, return the value, otherwise return the pre-get option value.
108 */
109 public static function pre_option_activitypub_vary_header( $pre ) {
110 if ( ! \defined( 'ACTIVITYPUB_SEND_VARY_HEADER' ) ) {
111 return $pre;
112 }
113
114 if ( ACTIVITYPUB_SEND_VARY_HEADER ) {
115 return '1';
116 }
117
118 return '0';
119 }
120
121 /**
122 * Disallow interactions if the constant is set.
123 *
124 * @param bool $pre The value of the option.
125 *
126 * @return bool|string The value of the option.
127 */
128 public static function maybe_disable_interactions( $pre ) {
129 if ( ACTIVITYPUB_DISABLE_INCOMING_INTERACTIONS ) {
130 return '0';
131 }
132
133 return $pre;
134 }
135
136 /**
137 * Default max image attachments.
138 *
139 * @param string $value The value of the option.
140 *
141 * @return string|int The value of the option.
142 */
143 public static function default_max_image_attachments( $value ) {
144 if ( ! \is_numeric( $value ) ) {
145 $value = ACTIVITYPUB_MAX_IMAGE_ATTACHMENTS;
146 }
147
148 return $value;
149 }
150
151 /**
152 * Default option filter for the Content-Negotiation.
153 *
154 * @see https://github.com/Automattic/wordpress-activitypub/wiki/Caching
155 *
156 * @param string $default_value The default value of the option.
157 *
158 * @return string The default value of the option.
159 */
160 public static function default_option_activitypub_negotiate_content( $default_value ) {
161 $disable_for_plugins = array(
162 'wp-optimize/wp-optimize.php',
163 'wp-rocket/wp-rocket.php',
164 'w3-total-cache/w3-total-cache.php',
165 'wp-fastest-cache/wp-fastest-cache.php',
166 'sg-cachepress/sg-cachepress.php',
167 );
168
169 foreach ( $disable_for_plugins as $plugin ) {
170 if ( \is_plugin_active( $plugin ) ) {
171 return '0';
172 }
173 }
174
175 return $default_value;
176 }
177 }
178