refactor: simplify YoastLlmsTxt by merging duplicate rewrite methods#29
refactor: simplify YoastLlmsTxt by merging duplicate rewrite methods#29
Conversation
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>
There was a problem hiding this comment.
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_actioncalls with aforeachloop over Yoast regeneration triggers. - Routed the
page_linkfilter torewrite_post_linkand removed the duplicaterewrite_page_linkmethod. - Updated
rewrite_post_linkdocblock to reflect its broader usage and accepted parameter types.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/Integration/YoastLlmsTxt.php
Outdated
| add_action( $action, [ $this, 'start' ], 9 ); | ||
| add_action( $action, [ $this, 'stop' ], 11 ); |
There was a problem hiding this comment.
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.
| 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 ); |
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>
Summary
rewrite_page_link, which was functionally identical torewrite_post_link— same body, same logic, different parameter name onlypage_linkfilter torewrite_post_linkinstead, sinceget_post_type()accepts both aWP_Postobject and an integer post IDrewrite_post_linkdocblock to reflect that it now handles all three permalink filters (post_link,page_link,post_type_link)Test plan
.mdappended during llms.txt generation.mdappended during llms.txt generation.mdappended during llms.txt generationstop()is called (no filter leakage)🤖 Generated with Claude Code