feat: {{link:ID}} placeholder via Divi's post_link_url dynamic content
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace LIT\MCP\Integrations\Divi\Pages;
|
||||
|
||||
use LIT\MCP\Integrations\Divi\Compose\LinkTargets;
|
||||
use WP_Post;
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* {{link:<ID>}} targets from WordPress: the entry exists, lives (no trash, auto-draft or
|
||||
* revision) and the current user may read it (read_post, like select_post settings, S37).
|
||||
* Missing and unreadable entries give the same null (no existence oracle).
|
||||
*/
|
||||
final class WpLinkTargets implements LinkTargets
|
||||
{
|
||||
private const DEAD = ['trash', 'auto-draft', 'inherit'];
|
||||
|
||||
public function postTypeOf(int $id): ?string
|
||||
{
|
||||
$post = get_post($id);
|
||||
if (! $post instanceof WP_Post || in_array((string) $post->post_status, self::DEAD, true)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return current_user_can('read_post', $id) ? (string) $post->post_type : null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user