Consolidate get_post_types_names() into Settings - #776
Merged
Conversation
Contributor
|
Test merged PR on Playground |
Contributor
✅ Code Coverage Report
📊 File-level Coverage Changes (1 files)📈 Coverage Improved
ℹ️ About this report
|
Contributor
🔍 WordPress Plugin Check Report
📊 Report
|
| 📍 Line | 🔖 Check | 💬 Message |
|---|---|---|
232 |
WordPressVIPMinimum.Performance.WPQueryParams.PostNotIn_post__not_in | Using exclusionary parameters, like post__not_in, in calls to get_posts() should be done with caution, see https://docs.wpvip.com/databases/optimize-queries/using-post__not_in/ for more information. |
377 |
WordPressVIPMinimum.Performance.WPQueryParams.PostNotIn_post__not_in | Using exclusionary parameters, like post__not_in, in calls to get_posts() should be done with caution, see https://docs.wpvip.com/databases/optimize-queries/using-post__not_in/ for more information. |
381 |
WordPressVIPMinimum.Performance.WPQueryParams.PostNotIn_post__not_in | Using exclusionary parameters, like post__not_in, in calls to get_posts() should be done with caution, see https://docs.wpvip.com/databases/optimize-queries/using-post__not_in/ for more information. |
388 |
WordPressVIPMinimum.Performance.WPQueryParams.PostNotIn_post__not_in | Using exclusionary parameters, like post__not_in, in calls to get_posts() should be done with caution, see https://docs.wpvip.com/databases/optimize-queries/using-post__not_in/ for more information. |
📁 classes/suggested-tasks/data-collector/class-unpublished-content.php (1 warning)
| 📍 Line | 🔖 Check | 💬 Message |
|---|---|---|
103 |
WordPressVIPMinimum.Performance.WPQueryParams.PostNotIn_post__not_in | Using exclusionary parameters, like post__not_in, in calls to get_posts() should be done with caution, see https://docs.wpvip.com/databases/optimize-queries/using-post__not_in/ for more information. |
📁 classes/suggested-tasks/data-collector/class-yoast-orphaned-content.php (1 warning)
| 📍 Line | 🔖 Check | 💬 Message |
|---|---|---|
111 |
PluginCheck.Security.DirectDB.UnescapedDBParameter | Unescaped parameter $query used in $wpdb->get_row()\n$query assigned unsafely at line 98. |
📁 classes/suggested-tasks/data-collector/class-terms-without-description.php (1 warning)
| 📍 Line | 🔖 Check | 💬 Message |
|---|---|---|
108 |
PluginCheck.Security.DirectDB.UnescapedDBParameter | Unescaped parameter $query used in $wpdb->get_results()\n$query assigned unsafely at line 106. |
📁 classes/suggested-tasks/data-collector/class-terms-without-posts.php (1 warning)
| 📍 Line | 🔖 Check | 💬 Message |
|---|---|---|
120 |
PluginCheck.Security.DirectDB.UnescapedDBParameter | Unescaped parameter $query used in $wpdb->get_results()\n$query assigned unsafely at line 118. |
📁 classes/activities/class-query.php (2 warnings)
| 📍 Line | 🔖 Check | 💬 Message |
|---|---|---|
71 |
PluginCheck.Security.DirectDB.UnescapedDBParameter | Unescaped parameter $table_name used in $wpdb->query()\n$table_name assigned unsafely at line 58. |
163 |
PluginCheck.Security.DirectDB.UnescapedDBParameter | Unescaped parameter $where_args used in $wpdb->get_results()\n$where_args assigned unsafely at line 153. |
🤖 Generated by WordPress Plugin Check Action • Learn more about Plugin Check
Two copies of get_post_types_names() existed: Settings::get_post_types_names() and Content_Helpers::get_post_types_names(). The Settings version has become the canonical one -- it is what the newer suggested-task and data-collector classes call, it carries the init-timing guard, and it is where the exclusion list is maintained. The Content_Helpers copy had drifted behind, and its filtering logic differs in three ways: - It does not exclude elementor_library, which Elementor registers as public + viewable, so it passes the viewability check. - It does not honour the progress_planner_public_post_types filter. - Its empty-case fallback returns a raw [ 'post', 'page' ] without checking those post types are still registered and public. Each copy holds its own static cache, warmed independently on first call. In a normal request both warm after init and agree, so the drift is latent rather than actively breaking sites -- but two functions answering the same question no longer share filtering rules, and any future change to the exclusion list or the filter lands in only one. Point the six remaining Content_Helpers call sites at Settings and reduce Content_Helpers::get_post_types_names() to a deprecated shim so external callers keep working. All six run well after init (shutdown, wp_insert_post, admin widget rendering), so no call site is moved earlier by this change. The null guards in Content_Scan and Content are left in place: they still protect the get_activity_from_post() calls in those methods, and in Content_Scan::get_total_pages() the guard doubles as a deliberate circuit-breaker that halts the scan during plugin updates. Implements #433.
ilicfilip
force-pushed
the
filip/consolidate-post-types-names
branch
from
August 25, 2026 12:28
d01c6e2 to
714cdbc
Compare
ilicfilip
marked this pull request as ready for review
August 25, 2026 12:34
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements #433. Replaces #467, which had drifted ~2300 commits behind
developand conflicted in 6 of its 7 files.The problem
Two copies of
get_post_types_names()exist indevelop, and callers were split roughly evenly between them (5 each):classes/class-settings.php:119classes/activities/class-content-helpers.php:22Settingshas become the canonical one — it's what the newer suggested-task and data-collector classes call, it carries theinit-timing guard, and it's where the exclusion list has been maintained.The
Content_Helperscopy drifted behind. Its filtering logic differs in three ways:elementor_library— excluded bySettings, not byContent_Helpers. Elementor registers it as public + viewable, so it passes theContent_Helpersviewability check.progress_planner_public_post_typesfilter — only honoured bySettings. Anything filtered out there still passes throughContent_Helpers.Content_Helpersreturns a raw[ 'post', 'page' ]without checking those post types are still registered and public;Settingsintersects against public types first.Each copy holds its own
staticcache, warmed independently on first call. In a normal request both warm afterinitand agree, so the drift is latent rather than actively breaking sites — but it means two functions that are supposed to answer the same question no longer share filtering rules, and any future change to the exclusion list or the filter only lands in one of them.The change
Content_Helperscall sites atSettings.Content_Helpers::get_post_types_names()to a deprecated one-line shim, so any external caller keeps working.Net: 9 insertions, 16 deletions across 6 files. One cache and one set of filtering rules instead of two.
Note on direction
#467 consolidated the other way — deleting
Settings::get_post_types_names()and moving it intoContent_Helpers. Since that PR was opened,developsettled onSettingsas the home (that's where theprpl_recommendationsexclusion was added). Rebasing #467 would have meant reverting that decision, which is why this is a fresh change rather than a rebase.Note on init ordering
All six migrated call sites run well after
init—shutdown,wp_insert_post, and admin widget rendering — so all CPTs are registered by the time they read. The shared cache is warmed byTasks_Manager::init()atinitpriority 99, after the priority 0–10 where CPTs normally register. No call site is moved earlier by this PR.Note on the null guards
The
null === $content_helpersguards inContent_ScanandContentare deliberately left in place — they still protect theget_activity_from_post()calls in those methods. InContent_Scan::get_total_pages()the guard no longer covers any$content_helpersusage, but it doubles as an intentional circuit-breaker returning0to halt the scan during plugin updates (added in #743), so removing it would change update-time behaviour beyond this PR's scope.Verification
composer check-cs -- --warning-severity=6— clean (exit 0)composer phpstan— no errorscomposer test— OK (398 tests, 1203 assertions)Note that the test suite has no existing coverage of
get_post_types_names(), so the suite passing is not by itself evidence for this change. I additionally ran a throwaway differential harness comparing the oldContent_Helpersimplementation against the new delegate across 10 scenarios (public CPT, non-public CPT,elementor_library,attachment, theprogress_planner_public_post_typesfilter, unregistered post types, empty settings) and confirmed both entry points return identical results. That harness was not committed.The two
wpdberrorlines that appear in the test output are pre-existing; they reproduce identically on unmodifieddevelop.