fix: full-form internal links follow the {{link:}} target rules (ruling P10)

One PostIdParser for {{link:}} and select_post; post_link_url_<type> needs a
living, readable, non-attachment target of exactly that type.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-09-27 14:54:51 +02:00
co-authored by Claude Opus 5.5
parent c615522cf6
commit 06f13799de
14 changed files with 229 additions and 28 deletions
@@ -10,9 +10,10 @@ 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).
* {{link:<ID>}} and post_link_url_* targets from WordPress (ruling P10): the entry exists, lives
* (no trash, auto-draft or revision), is no attachment (whatever its status) 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
{
@@ -21,7 +22,11 @@ final class WpLinkTargets implements LinkTargets
public function postTypeOf(int $id): ?string
{
$post = get_post($id);
if (! $post instanceof WP_Post || in_array((string) $post->post_status, self::DEAD, true)) {
if (
! $post instanceof WP_Post
|| in_array((string) $post->post_status, self::DEAD, true)
|| $post->post_type === 'attachment'
) {
return null;
}