Skip to content

refactor: simplify YoastLlmsTxt by merging duplicate rewrite methods#29

Open
jdevalk wants to merge 3 commits intomainfrom
optimize/yoast-llms-txt
Open

refactor: simplify YoastLlmsTxt by merging duplicate rewrite methods#29
jdevalk wants to merge 3 commits intomainfrom
optimize/yoast-llms-txt

Conversation

@jdevalk
Copy link
Member

@jdevalk jdevalk commented Feb 26, 2026

Summary

  • Removes rewrite_page_link, which was functionally identical to rewrite_post_link — same body, same logic, different parameter name only
  • Routes the page_link filter to rewrite_post_link instead, since get_post_type() accepts both a WP_Post object and an integer post ID
  • Updates the rewrite_post_link docblock to reflect that it now handles all three permalink filters (post_link, page_link, post_type_link)

Test plan

  • Verify page URLs get .md appended during llms.txt generation
  • Verify post URLs get .md appended during llms.txt generation
  • Verify CPT URLs get .md appended during llms.txt generation
  • Confirm all three filters are properly removed after stop() is called (no filter leakage)

🤖 Generated with Claude Code

Joost de Valk and others added 2 commits February 26, 2026 15:09
Removes `rewrite_page_link` which was functionally identical to
`rewrite_post_link`. Since `get_post_type()` accepts both a WP_Post
object and an integer post ID, a single method handles all three
permalink filters (post_link, page_link, post_type_link).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Refactors the Yoast llms.txt integration to reduce duplication by using a single permalink rewrite method for posts, pages, and CPTs during Yoast’s llms.txt generation flow.

Changes:

  • Replaced repeated add_action calls with a foreach loop over Yoast regeneration triggers.
  • Routed the page_link filter to rewrite_post_link and removed the duplicate rewrite_page_link method.
  • Updated rewrite_post_link docblock to reflect its broader usage and accepted parameter types.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 39 to 40
add_action( $action, [ $this, 'start' ], 9 );
add_action( $action, [ $this, 'stop' ], 11 );
Copy link

Copilot AI Feb 26, 2026

Choose a reason for hiding this comment

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

update_option_wpseo / update_option_wpseo_llmstxt are core update_option_{$option} actions that pass arguments (old value, new value, option). With add_action(..., 9) the default accepted args is 1, so WordPress will pass an argument into start()/stop() which declare no parameters; this will throw an ArgumentCountError on PHP 8+. Fix by setting accepted args to 0 in these add_action calls, or update start/stop signatures to accept (and ignore) the incoming args.

Suggested change
add_action( $action, [ $this, 'start' ], 9 );
add_action( $action, [ $this, 'stop' ], 11 );
add_action( $action, [ $this, 'start' ], 9, 0 );
add_action( $action, [ $this, 'stop' ], 11, 0 );

Copilot uses AI. Check for mistakes.
Set accepted_args to 0 for start()/stop() add_action calls so WordPress
does not pass arguments into these parameter-less methods. The
update_option_{$option} hook fires with 3 args (old, new, option name),
which would cause an ArgumentCountError on PHP 8+ with the default
accepted_args of 1.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.

2 participants