Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 96e6437

Browse files
pfefferleobenland
andauthoredMay 13, 2025
Change: Move delete_options to Options::class (#1694)
Co-authored-by: Konstantin Obenland <[email protected]>
1 parent 533532b commit 96e6437

File tree

3 files changed

+52
-43
lines changed

3 files changed

+52
-43
lines changed
 

‎includes/class-activitypub.php

Lines changed: 2 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
namespace Activitypub;
99

1010
use Exception;
11+
use Activitypub\Options;
1112
use Activitypub\Collection\Actors;
1213
use Activitypub\Collection\Outbox;
1314
use Activitypub\Collection\Followers;
@@ -90,45 +91,7 @@ public static function uninstall() {
9091
\remove_filter( 'pre_wp_update_comment_count_now', array( Comment::class, 'pre_wp_update_comment_count_now' ) );
9192
Migration::update_comment_counts( 2000 );
9293

93-
\delete_option( 'activitypub_actor_mode' );
94-
\delete_option( 'activitypub_allow_likes' );
95-
\delete_option( 'activitypub_allow_replies' );
96-
\delete_option( 'activitypub_attribution_domains' );
97-
\delete_option( 'activitypub_authorized_fetch' );
98-
\delete_option( 'activitypub_application_user_private_key' );
99-
\delete_option( 'activitypub_application_user_public_key' );
100-
\delete_option( 'activitypub_blog_user_also_known_as' );
101-
\delete_option( 'activitypub_blog_user_mailer_new_dm' );
102-
\delete_option( 'activitypub_blog_user_mailer_new_follower' );
103-
\delete_option( 'activitypub_blog_user_mailer_new_mention' );
104-
\delete_option( 'activitypub_blog_user_moved_to' );
105-
\delete_option( 'activitypub_blog_user_private_key' );
106-
\delete_option( 'activitypub_blog_user_public_key' );
107-
\delete_option( 'activitypub_blog_description' );
108-
\delete_option( 'activitypub_blog_identifier' );
109-
\delete_option( 'activitypub_checklist_blocks_visited' );
110-
\delete_option( 'activitypub_checklist_fediverse_intro_visited' );
111-
\delete_option( 'activitypub_checklist_health_check_issues' );
112-
\delete_option( 'activitypub_checklist_profile_setup_visited' );
113-
\delete_option( 'activitypub_checklist_settings_visited' );
114-
\delete_option( 'activitypub_content_negotiation' );
115-
\delete_option( 'activitypub_custom_post_content' );
116-
\delete_option( 'activitypub_db_version' );
117-
\delete_option( 'activitypub_default_extra_fields' );
118-
\delete_option( 'activitypub_enable_blog_user' );
119-
\delete_option( 'activitypub_enable_users' );
120-
\delete_option( 'activitypub_header_image' );
121-
\delete_option( 'activitypub_last_post_with_permalink_as_id' );
122-
\delete_option( 'activitypub_max_image_attachments' );
123-
\delete_option( 'activitypub_migration_lock' );
124-
\delete_option( 'activitypub_object_type' );
125-
\delete_option( 'activitypub_outbox_purge_days' );
126-
\delete_option( 'activitypub_shared_inbox' );
127-
\delete_option( 'activitypub_support_post_types' );
128-
\delete_option( 'activitypub_use_hashtags' );
129-
\delete_option( 'activitypub_use_opengraph' );
130-
\delete_option( 'activitypub_use_permalink_as_id_for_blog' );
131-
\delete_option( 'activitypub_vary_header' );
94+
Options::delete();
13295
}
13396

13497
/**

‎includes/class-options.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,13 @@
22
/**
33
* Options file.
44
*
5-
* @package ActivityPub
5+
* @package Activitypub
66
*/
77

8-
namespace ActivityPub;
8+
namespace Activitypub;
99

1010
/**
1111
* Options class.
12-
*
13-
* @package ActivityPub
1412
*/
1513
class Options {
1614

@@ -30,6 +28,15 @@ public static function init() {
3028
\add_filter( 'option_activitypub_max_image_attachments', array( self::class, 'default_max_image_attachments' ) );
3129
}
3230

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+
}
3340

3441
/**
3542
* Pre-get option filter for the Actor-Mode.

‎tests/includes/class-test-options.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
/**
3+
* Test file for Activitypub Options class.
4+
*
5+
* @package Activitypub
6+
*/
7+
8+
namespace Activitypub\Tests;
9+
10+
use Activitypub\Options;
11+
12+
/**
13+
* Test class for Activitypub Options.
14+
*/
15+
class Test_Options extends \WP_UnitTestCase {
16+
/**
17+
* Test that delete() removes all options with the activitypub_ prefix.
18+
*/
19+
public function test_delete_removes_all_activitypub_options() {
20+
\add_option( 'activitypub_test_option_1', 'value1' );
21+
\add_option( 'activitypub_test_option_2', 'value2' );
22+
\add_option( 'activitypub_test_option_3', 'value3' );
23+
\add_option( 'no_activitypub_test_option', 'value4' );
24+
25+
$this->assertEquals( 'value1', \get_option( 'activitypub_test_option_1' ) );
26+
$this->assertEquals( 'value2', \get_option( 'activitypub_test_option_2' ) );
27+
$this->assertEquals( 'value3', \get_option( 'activitypub_test_option_3' ) );
28+
$this->assertEquals( 'value4', \get_option( 'no_activitypub_test_option' ) );
29+
30+
Options::delete();
31+
32+
\wp_cache_flush();
33+
34+
$this->assertFalse( \get_option( 'activitypub_test_option_1', false ) );
35+
$this->assertFalse( \get_option( 'activitypub_test_option_2', false ) );
36+
$this->assertFalse( \get_option( 'activitypub_test_option_3', false ) );
37+
$this->assertEquals( 'value4', \get_option( 'no_activitypub_test_option' ) );
38+
}
39+
}

0 commit comments

Comments
 (0)