Skip to content

Render the single listing template apart from the content filters - #3185

Merged
tellyworth merged 2 commits into
trunkfrom
fix/isolate-single-listing-content
Nov 16, 2026
Merged

tellyworth merged 2 commits into
trunkfrom
fix/isolate-single-listing-content

Conversation

@tellyworth

@tellyworth tellyworth commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Changes Proposed in this Pull Request

On a single listing page the listing template is rendered from a the_content filter, so everything it prints (fields, forms, output from extensions) is processed by the filters that run afterwards as if it were post content. This renders the template apart from them.

  • job_content() holds the rendered template and returns a placeholder named with a random token. A new filter at the last priority puts the template in its place. Filters in between see only the placeholder; content they add before or after it is kept.
  • Shortcodes in the description of a listing by a trusted author are still expanded, once: by wpjm_the_job_description() after the HTML filter (the same order as before), or by the_job_description when a template calls that filter itself, as older templates did.
  • Nothing else in the template is searched for shortcodes, whoever wrote the listing.
  • The media pass for untrusted listings and wp_filter_content_tags() are applied to the rendered template directly, since the later filters no longer reach it.
  • New filter job_manager_isolate_single_job_content (default true): return false to pass the template through the content filters as before.
  • docs/adr/0002-… records the decision and its consequences.

Behaviour changes to be aware of

  • Shortcodes outside the description are no longer expanded on the single listing page: in the fields of a listing by a trusted author (company name, tagline, and so on), in a theme's copy of the template, or printed from a hook such as single_job_listing_end. Such code can call do_shortcode() on its own text, or the site can use the filter above.
  • Plugins that change post content after priority 10 (rewriting links or images, for example) no longer change the listing template.
  • job_content() now returns the placeholder when called directly.

Testing Instructions

  • vendor/bin/phpunit --filter 'Tests_Single_Listing_Content_Processing|Tests_Listing_Field_Display'
  • View a listing written by an administrator with a shortcode in its description and in its company tagline: the one in the description is expanded, the tagline shows the text.
  • View a listing submitted by an employer or guest: it looks as before (description, company details, video, apply button).
  • Check a block theme and a classic theme, and a plugin that adds something after the content (sharing buttons, related posts): it still appears below the listing.
  • Add add_filter( 'job_manager_isolate_single_job_content', '__return_false' ); and confirm the previous behaviour.

Release Notes

  • Change: The single job listing template is now rendered separately from the post content filters. Shortcodes are expanded only in the description of listings written by users who can edit job listings; shortcodes in other listing fields, in theme template overrides or added through template hooks are shown as text. Use the job_manager_isolate_single_job_content filter to restore the previous behaviour.

Plugin build for d204e8b
📦 Download plugin zip
▶️ Open in playground

tellyworth and others added 2 commits November 16, 2026 12:41
The template prints listing fields, forms and request data inside the_content, where later filters process it as if it
were post content. Hold the rendered template aside, give the later filters a placeholder, and put the template in its
place after the last of them. Shortcodes in the description of a trusted listing are still expanded.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
… filters

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

// A filter may have rewritten the placeholder element, so it is found by its token.
$content = preg_replace_callback(
'/<div\b[^<>]*' . preg_quote( $token, '/' ) . '[^<>]*>\s*<\/div>/',

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is a html regex the best way to do this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so here, with one gap that is now closed in f1887c93. The pattern doesn't parse anyone's HTML: it matches one empty element that this class wrote a moment earlier, located by a random token made for that render. It allows for extra attributes or different quoting because optimisation plugins add attributes to elements. WP_HTML_Tag_Processor can find the element by class but has no public way to replace an element with other markup, so it would only do half the job.

The gap: if a filter changed the placeholder into something the pattern doesn't match (put content inside it, say), the listing was dropped. It is now added after the content instead, with a test.

}

// What the later content filters would have done to the template that is still wanted.
$job_content = $this->strip_untrusted_listing_media( (string) $job_content );

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the string cast?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A job_manager_single_job_content filter can return null or false, and the next two calls expect a string. Moved the cast to its own line with a comment saying so (f1887c93).

return $description;
}

$post = self::get_listing_for_content( null === $post ? null : get_post( $post ) );

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we replace the ternary with something more explicit for readability

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in f1887c93, here and in expand_filtered_description_shortcodes().

@tellyworth tellyworth added this to the 2.4.12 milestone Nov 16, 2026
@tellyworth
tellyworth merged commit f3cea54 into trunk Nov 16, 2026
9 checks passed
@tellyworth
tellyworth deleted the fix/isolate-single-listing-content branch November 16, 2026 05:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant