Files
WP-LIT-MCP/src/Integrations/Divi/Pages/DiviFlags.php
T

39 lines
1.3 KiB
PHP

<?php
declare(strict_types=1);
namespace LIT\MCP\Integrations\Divi\Pages;
use RuntimeException;
/**
* Marks an entry as a Divi 5 builder layout, like the Visual Builder's own save does
* (Divi 5.2.1 SyncToServerController.php:382-387: _et_pb_use_divi_5 = "on", legacy
* _et_pb_use_builder = "on", and _et_pb_show_page_creation = "off" so the builder does not show
* its page creation flow on the first open). Ruling S11: update_post_meta() returns false for
* an unchanged value too, so success is checked by reading the flags back. Used by DiviSaver
* (inside FollowUp) and the Divi content creation.
*/
final class DiviFlags
{
public const FLAGS = [
'_et_pb_use_divi_5' => 'on',
'_et_pb_use_builder' => 'on',
'_et_pb_show_page_creation' => 'off',
];
/** @throws RuntimeException When a flag does not read back as set. */
public static function set(int $postId): void
{
foreach (self::FLAGS as $key => $value) {
update_post_meta($postId, $key, $value);
}
foreach (self::FLAGS as $key => $value) {
if (get_post_meta($postId, $key, true) !== $value) {
throw new RuntimeException(sprintf('Divi flag %s of post %d is not "%s".', $key, $postId, $value));
}
}
}
}