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:
@@ -205,12 +205,12 @@ final class DiviDynamicSourcesAbility implements Ability
|
||||
return '{{post:' . $post . '}}';
|
||||
}
|
||||
|
||||
if (! str_starts_with($name, 'post_link_url_')) {
|
||||
if (! str_starts_with($name, DynamicContentRules::LINK_PREFIX)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Review M-9: {{link:}} refuses attachments (status inherit); internal types ("_…") are no link targets.
|
||||
$type = substr($name, strlen('post_link_url_'));
|
||||
// Review M-9/P10: {{link:}} and the full form refuse attachments; internal types ("_…") are no link targets.
|
||||
$type = substr($name, strlen(DynamicContentRules::LINK_PREFIX));
|
||||
|
||||
return $type === 'attachment' || str_starts_with($type, '_') ? null : '{{link:<ID>}}';
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -48,4 +48,9 @@ final class WpValueSanitizer implements ValueSanitizer
|
||||
{
|
||||
return current_user_can('read_post', $id);
|
||||
}
|
||||
|
||||
public function linkTargetType(int $id): ?string
|
||||
{
|
||||
return (new WpLinkTargets())->postTypeOf($id);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user