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

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