Requirement, Call, ConstantRequirement, Mirror, Problem, FeatureStatus, CompatibilityMatrix, Manifest, ManifestCheck sowie Fingerprints und LineDiff liegen jetzt im divi-freien Kern. Neu: GlobalRequirement, CompatibilityMatrix::fromProblems(), ManifestCheck-Option signatures, DiviManifestCheck::create() und DiviAreas. Divi-Verhalten unverändert. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
72 lines
2.4 KiB
PHP
72 lines
2.4 KiB
PHP
<?php
|
||
|
||
declare(strict_types=1);
|
||
|
||
namespace LIT\MCP\Integrations\Divi\Library;
|
||
|
||
use Closure;
|
||
use LIT\MCP\Abilities\Errors;
|
||
use LIT\MCP\Compatibility\Call;
|
||
use LIT\MCP\Integrations\Divi\Release\DiviAdapter;
|
||
use LIT\MCP\Integrations\Divi\Release\DiviAreas;
|
||
use LIT\MCP\Integrations\Divi\Release\DiviFeature;
|
||
use LIT\MCP\Compatibility\Manifest;
|
||
use WP_Error;
|
||
|
||
defined('ABSPATH') || exit;
|
||
|
||
/**
|
||
* Adapter "Bibliothek" (spec §3) for Divi's role editor (E3, E15): et_pb_is_allowed() (Divi's builder/core.php)
|
||
* answers for the current user's role, "dangerous" options (theme_builder,
|
||
* read_dynamic_content_custom_fields) default to off for every role but administrator. When
|
||
* Divi no longer has the function, nothing is allowed – DiviCompatibility reports it.
|
||
* Not final so tests can pass a check.
|
||
*/
|
||
class DiviRoles implements DiviAdapter
|
||
{
|
||
private const LABELS = [
|
||
'divi_library' => 'Divi-Bibliothek',
|
||
'save_library' => 'In der Bibliothek speichern',
|
||
'add_library' => 'Aus der Bibliothek hinzufügen',
|
||
'edit_global_library' => 'Globale Bibliothekselemente bearbeiten',
|
||
'read_dynamic_content_custom_fields' => 'Dynamic Content: benutzerdefinierte Felder lesen',
|
||
'theme_builder' => 'Theme Builder',
|
||
];
|
||
|
||
public static function manifest(): Manifest
|
||
{
|
||
return new Manifest(
|
||
DiviAreas::LIBRARY,
|
||
calls: [new Call('et_pb_is_allowed', 1)],
|
||
features: [DiviFeature::Roles]
|
||
);
|
||
}
|
||
|
||
/** @param (Closure(string): bool)|null $check Test seam; null = Divi's et_pb_is_allowed(). */
|
||
public function __construct(private ?Closure $check = null)
|
||
{
|
||
}
|
||
|
||
public function allows(string $capability): bool
|
||
{
|
||
if ($this->check !== null) {
|
||
return ($this->check)($capability);
|
||
}
|
||
|
||
return function_exists('et_pb_is_allowed') && (bool) et_pb_is_allowed($capability);
|
||
}
|
||
|
||
/** Null when the role allows $capability, else a forbidden error naming the option. */
|
||
public function refusal(string $capability): ?WP_Error
|
||
{
|
||
if ($this->allows($capability)) {
|
||
return null;
|
||
}
|
||
|
||
return Errors::forbidden(
|
||
sprintf('Die Divi-Rolle dieses Kontos erlaubt „%s“ nicht.', self::LABELS[$capability] ?? $capability),
|
||
'Einen Administrator bitten, das Recht unter Divi → Rollen-Editor freizugeben.'
|
||
);
|
||
}
|
||
}
|