diff --git a/admin/class-tmdo-admin.php b/admin/class-tmdo-admin.php index 9f11387..e4fbc65 100644 --- a/admin/class-tmdo-admin.php +++ b/admin/class-tmdo-admin.php @@ -3490,7 +3490,7 @@ wpdo.getListings({ per_page: 3 }).then(r => console.log(r));' console.log(r));' 0 + || TMDO_Term_Comment_Misc_Bucket::count_rows( 'comment' ) > 0; + + if ( $unset && $has_rows ) { + update_option( TMDO_Term_Comment_Misc_Bucket::OPT_ENABLED, '1', false ); + } + + update_option( self::MISC_BUCKET_DEFAULT_FLAG, '1', true ); } // ── v2.0.0 entity + audit + shadow_diffs schema (PR-2) ───────────────── diff --git a/includes/integrations/class-tmdo-term-comment-garbage-filter.php b/includes/integrations/class-tmdo-term-comment-garbage-filter.php index 75b2b52..1056a68 100644 --- a/includes/integrations/class-tmdo-term-comment-garbage-filter.php +++ b/includes/integrations/class-tmdo-term-comment-garbage-filter.php @@ -109,12 +109,12 @@ final class TMDO_Term_Comment_Garbage_Filter { } /** - * Check the admin toggle. Defaults to enabled. + * Check the admin toggle. Defaults to disabled. * * @return bool */ public static function is_enabled(): bool { - return (bool) get_option( self::OPT_ENABLED, '1' ); + return (bool) get_option( self::OPT_ENABLED, '0' ); } /** diff --git a/includes/integrations/class-tmdo-term-comment-misc-bucket.php b/includes/integrations/class-tmdo-term-comment-misc-bucket.php index 7bc52bb..80c5a55 100644 --- a/includes/integrations/class-tmdo-term-comment-misc-bucket.php +++ b/includes/integrations/class-tmdo-term-comment-misc-bucket.php @@ -95,12 +95,13 @@ final class TMDO_Term_Comment_Misc_Bucket { } /** - * Check the admin toggle. Defaults to enabled. + * Check the admin toggle. Defaults to disabled; sites that already hold misc + * rows keep it on via TMDO_Installer::maybe_preserve_misc_bucket_default(). * * @return bool */ public static function is_enabled(): bool { - return (bool) get_option( self::OPT_ENABLED, '1' ); + return (bool) get_option( self::OPT_ENABLED, '0' ); } /** diff --git a/tests/integration/TermCommentGarbageFilterTest.php b/tests/integration/TermCommentGarbageFilterTest.php index 36a69b0..2fd5d21 100644 --- a/tests/integration/TermCommentGarbageFilterTest.php +++ b/tests/integration/TermCommentGarbageFilterTest.php @@ -152,9 +152,9 @@ class TermCommentGarbageFilterTest extends TestCase { // ── is_enabled toggle ─────────────────────────────────────────────────── - public function test_is_enabled_defaults_true(): void { + public function test_is_enabled_defaults_false(): void { delete_option( WPDO_Term_Comment_Garbage_Filter::OPT_ENABLED ); - $this->assertTrue( WPDO_Term_Comment_Garbage_Filter::is_enabled() ); + $this->assertFalse( WPDO_Term_Comment_Garbage_Filter::is_enabled() ); } public function test_is_enabled_respects_zero_value(): void { diff --git a/tests/integration/TermCommentMiscBucketTest.php b/tests/integration/TermCommentMiscBucketTest.php index 2bca15c..28b0c31 100644 --- a/tests/integration/TermCommentMiscBucketTest.php +++ b/tests/integration/TermCommentMiscBucketTest.php @@ -189,11 +189,59 @@ class TermCommentMiscBucketTest extends TestCase { // ── is_enabled toggle ─────────────────────────────────────────────────── - public function test_is_enabled_defaults_true(): void { + public function test_is_enabled_defaults_false(): void { delete_option( WPDO_Term_Comment_Misc_Bucket::OPT_ENABLED ); + $this->assertFalse( WPDO_Term_Comment_Misc_Bucket::is_enabled() ); + } + + // ── one-time default migration for sites that already use the bucket ───── + + public function test_preserve_default_keeps_bucket_on_when_misc_has_rows(): void { + $this->reset_preserve_state(); + WPDO_Term_Comment_Misc_Bucket::on_term_update( null, 1, 'a', 'x', '' ); + + TMDO_Installer::maybe_preserve_misc_bucket_default(); + + $this->assertSame( '1', get_option( WPDO_Term_Comment_Misc_Bucket::OPT_ENABLED ) ); $this->assertTrue( WPDO_Term_Comment_Misc_Bucket::is_enabled() ); } + public function test_preserve_default_leaves_bucket_off_when_misc_empty(): void { + $this->reset_preserve_state(); + + TMDO_Installer::maybe_preserve_misc_bucket_default(); + + $this->assertFalse( get_option( WPDO_Term_Comment_Misc_Bucket::OPT_ENABLED ) ); + $this->assertFalse( WPDO_Term_Comment_Misc_Bucket::is_enabled() ); + $this->assertNotEmpty( get_option( TMDO_Installer::MISC_BUCKET_DEFAULT_FLAG ) ); + } + + public function test_preserve_default_respects_explicit_off(): void { + $this->reset_preserve_state(); + update_option( WPDO_Term_Comment_Misc_Bucket::OPT_ENABLED, '0' ); + WPDO_Term_Comment_Misc_Bucket::on_term_update( null, 1, 'a', 'x', '' ); + + TMDO_Installer::maybe_preserve_misc_bucket_default(); + + $this->assertSame( '0', get_option( WPDO_Term_Comment_Misc_Bucket::OPT_ENABLED ) ); + delete_option( WPDO_Term_Comment_Misc_Bucket::OPT_ENABLED ); + } + + public function test_preserve_default_runs_only_once(): void { + $this->reset_preserve_state(); + TMDO_Installer::maybe_preserve_misc_bucket_default(); // Empty tables: stays off, flag set. + WPDO_Term_Comment_Misc_Bucket::on_term_update( null, 1, 'a', 'x', '' ); + + TMDO_Installer::maybe_preserve_misc_bucket_default(); + + $this->assertFalse( get_option( WPDO_Term_Comment_Misc_Bucket::OPT_ENABLED ) ); + } + + private function reset_preserve_state(): void { + delete_option( WPDO_Term_Comment_Misc_Bucket::OPT_ENABLED ); + delete_option( TMDO_Installer::MISC_BUCKET_DEFAULT_FLAG ); + } + public function test_is_enabled_respects_zero_value(): void { update_option( WPDO_Term_Comment_Misc_Bucket::OPT_ENABLED, '0' ); $this->assertFalse( WPDO_Term_Comment_Misc_Bucket::is_enabled() );