Skip to content

Commit 0b30656

Browse files
authored
Change default settings based on caching behaviour (#1640)
* Change default settings based on caching behaviour Change the default behaviour of the plugin based on the caching plugins that are installed. This PR is an extension to #1639 and #1638 * fix phpcs issues * seems to not properly work with the plugin so let's wait for the first that needs it. * fix whitespaces * Add changelog
1 parent c7100d9 commit 0b30656

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: minor
2+
Type: added
3+
4+
Adjusted the plugin's default behavior based on the caching plugins installed.

includes/class-options.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public static function init() {
2626
\add_filter( 'pre_option_activitypub_allow_likes', array( self::class, 'maybe_disable_interactions' ) );
2727
\add_filter( 'pre_option_activitypub_allow_replies', array( self::class, 'maybe_disable_interactions' ) );
2828

29+
\add_filter( 'default_option_activitypub_negotiate_content', array( self::class, 'default_option_activitypub_negotiate_content' ) );
2930
\add_filter( 'option_activitypub_max_image_attachments', array( self::class, 'default_max_image_attachments' ) );
3031
}
3132

@@ -114,6 +115,7 @@ public static function pre_option_activitypub_vary_header( $pre ) {
114115
* Disallow interactions if the constant is set.
115116
*
116117
* @param bool $pre The value of the option.
118+
*
117119
* @return bool|string The value of the option.
118120
*/
119121
public static function maybe_disable_interactions( $pre ) {
@@ -137,4 +139,31 @@ public static function default_max_image_attachments( $value ) {
137139

138140
return $value;
139141
}
142+
143+
/**
144+
* Default option filter for the Content-Negotiation.
145+
*
146+
* @see https://github.com/Automattic/wordpress-activitypub/wiki/Caching
147+
*
148+
* @param string $default_value The default value of the option.
149+
*
150+
* @return string The default value of the option.
151+
*/
152+
public static function default_option_activitypub_negotiate_content( $default_value ) {
153+
$disable_for_plugins = array(
154+
'wp-optimize/wp-optimize.php',
155+
'wp-rocket/wp-rocket.php',
156+
'w3-total-cache/w3-total-cache.php',
157+
'wp-fastest-cache/wp-fastest-cache.php',
158+
'sg-cachepress/sg-cachepress.php',
159+
);
160+
161+
foreach ( $disable_for_plugins as $plugin ) {
162+
if ( \is_plugin_active( $plugin ) ) {
163+
return '0';
164+
}
165+
}
166+
167+
return $default_value;
168+
}
140169
}

0 commit comments

Comments
 (0)