Skip to content

Commit b686a99

Browse files
authored
Ensure support_post_types option returns an array (#2339)
1 parent 832b505 commit b686a99

File tree

4 files changed

+19
-3
lines changed

4 files changed

+19
-3
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: patch
2+
Type: fixed
3+
4+
Added a safeguard to ensure the plugin works correctly even when no post types are selected.

includes/class-options.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public static function init() {
2626

2727
\add_filter( 'default_option_activitypub_negotiate_content', array( self::class, 'default_option_activitypub_negotiate_content' ) );
2828
\add_filter( 'option_activitypub_max_image_attachments', array( self::class, 'default_max_image_attachments' ) );
29+
\add_filter( 'option_activitypub_support_post_types', array( self::class, 'support_post_types_ensure_array' ) );
2930
\add_filter( 'option_activitypub_object_type', array( self::class, 'default_object_type' ) );
3031
}
3132

@@ -176,6 +177,17 @@ public static function default_max_image_attachments( $value ) {
176177
return $value;
177178
}
178179

180+
/**
181+
* Ensure support post types is an array.
182+
*
183+
* @param string[] $value The value of the option.
184+
*
185+
* @return string[] The value of the option.
186+
*/
187+
public static function support_post_types_ensure_array( $value ) {
188+
return (array) $value;
189+
}
190+
179191
/**
180192
* Default object type.
181193
*

includes/wp-admin/class-settings-fields.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,8 @@ public static function render_max_image_attachments_field() {
283283
* Render support post types field.
284284
*/
285285
public static function render_support_post_types_field() {
286-
$post_types = get_post_types( array( 'public' => true ), 'objects' );
287-
$supported_post_types = (array) get_option( 'activitypub_support_post_types', array( 'post' ) );
286+
$post_types = \get_post_types( array( 'public' => true ), 'objects' );
287+
$supported_post_types = \get_option( 'activitypub_support_post_types', array( 'post' ) );
288288
?>
289289
<fieldset>
290290
<?php esc_html_e( 'Automatically publish items of the selected post types to the fediverse:', 'activitypub' ); ?>

integration/class-wp-rest-cache.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public static function transition_post_status( $new_status, $old_status, $post )
101101
return;
102102
}
103103

104-
$post_types = (array) \get_option( 'activitypub_support_post_types', array() );
104+
$post_types = \get_option( 'activitypub_support_post_types', array() );
105105
$post_types[] = Outbox::POST_TYPE;
106106

107107
if ( ! \in_array( $post->post_type, $post_types, true ) ) {

0 commit comments

Comments
 (0)