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

62 lines
1.8 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
declare(strict_types=1);
namespace LIT\MCP\Integrations\Divi\Pages;
use LIT\MCP\Abilities\Rev;
use LIT\MCP\Integrations\Divi\BlockTree\Document;
use LIT\MCP\Integrations\Divi\BlockTree\NodeIndex;
use WP_Post;
defined('ABSPATH') || exit;
/**
* An entry loaded for the Divi tools: the post, its parsed tree, the path index and the
* tree_rev (hash of post_content – the optimistic lock of the Divi tools, ruling P16; the
* post-level lock stays `rev` = Rev::ofPost()).
*/
final class DiviPage
{
public function __construct(
public readonly WP_Post $post,
public readonly Document $document,
public readonly NodeIndex $index,
private bool $libraryItem = false
) {
}
/** Whether the entry is a Divi Library entry (et_pb_layout), loaded through LibraryAccess. */
public function isLibraryItem(): bool
{
return $this->libraryItem;
}
public function treeRev(): string
{
return Rev::of((string) $this->post->post_content);
}
/** Whether post_content is a Divi 5 layout (or empty, so a first section can be added). */
public function isDiviLayout(): bool
{
$content = (string) $this->post->post_content;
return trim($content) === '' || str_contains($content, '<!-- wp:divi/');
}
public function editUrl(): string
{
// A library entry has no public permalink (public: false); Divi's library list opens it here.
return $this->libraryItem
? (string) get_edit_post_link($this->post, 'raw')
: self::builderUrl($this->post);
}
/** The entry opened in the Divi Visual Builder – the edit_url of every Divi write (review I-1). */
public static function builderUrl(WP_Post|int $post): string
{
return (string) add_query_arg('et_fb', '1', (string) get_permalink($post));
}
}