fix: global usages follow the Theme Builder access (ruling Q17 M1)

GlobalUsages gets the Theme Builder access injected as a closure
(ThemeBuilderAccess::usageState(), wired at both construction sites through
DiviIntegration::globalUsages()). Theme Builder posts are named only while
the Theme Builder is visible to the account, otherwise only counted (also
in blocked_ids); a global edit that changes them needs canUse(), a writable
"Divi Theme Builder" group and edit_post. Without an injected access the
fail-safe default checks what canUse() checks. The duplicate
THEME_BUILDER_TYPES list gives way to DiviThemeBuilder::postTypes().

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01At3V6SjwbMe6eMzVGW3Hs7
This commit is contained in:
2026-09-27 23:00:36 +02:00
co-authored by Claude Opus 5.5
parent 7590da4d96
commit 43dc3fb889
11 changed files with 271 additions and 32 deletions
@@ -33,6 +33,25 @@ final class ThemeBuilderAccessTest extends TestCase
self::assertToolError(ThemeBuilderFixtures::access()->canUse(), 'forbidden');
}
/** Ruling Q17 M1 (review I-2): what a global library edit may do with Theme Builder posts (GlobalUsages). */
public function testUsageStateOfAGlobalEdit(): void
{
LibraryFixtures::given([]);
self::assertSame(['visible' => true, 'usable' => true], ThemeBuilderFixtures::access()->usageState());
self::assertSame(['visible' => true, 'usable' => false], ThemeBuilderFixtures::access([], false)->usageState());
self::assertSame(
['visible' => false, 'usable' => false],
ThemeBuilderFixtures::access([], true, null, false)->usageState()
);
self::assertSame(
['visible' => false, 'usable' => false],
ThemeBuilderFixtures::access(['theme_builder'])->usageState()
);
LibraryFixtures::given([], ['edit_theme_options']);
self::assertSame(['visible' => false, 'usable' => false], ThemeBuilderFixtures::access()->usageState());
}
/** Ruling Q15: Divi's Theme Builder page also needs edit_theme_options (theme-builder.php:2059-2063). */
public function testWithoutEditThemeOptionsTheThemeBuilderIsHidden(): void
{