Filter adjustments to the memberlite_get_cpts function#317
Filter adjustments to the memberlite_get_cpts function#317RachelRVasquez wants to merge 4 commits into
memberlite_get_cpts function#317Conversation
…an empty string or array, gaurds against non-string/non-array values like false/null/integer, gaurd against nested arrays
There was a problem hiding this comment.
Pull request overview
This PR updates memberlite_get_customizer_cpts() to consolidate CPT selection into a single filter (memberlite_customizer_cpts) with PMPro CPT slugs provided as the default value, and adds stronger normalization/guard behavior for unexpected filter return types.
Changes:
- Removes the separate
memberlite_pmpro_cpt_layout_settings_enabledfilter and uses PMPro CPT slugs as the default passed tomemberlite_customizer_cpts. - Adds coercion/normalization for filter returns (unexpected types →
[], comma-separated string → array, strips invalid elements).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
flintfromthebasement
left a comment
There was a problem hiding this comment.
PR: #317 — Filter adjustments to the memberlite_get_cpts function
RachieVee → dev | 1 file, +23 -42 lines
#317
Summary
Clean simplification. The consolidation to a single filter is correct, the guard logic is solid, and the end-to-end behavior is equivalent to the old code — unregistered CPTs still get filtered out in the final get_post_type_object() loop. Two minor issues; ready to merge after the Yoda condition is fixed.
Issues
-
Minor
inc/extras.php:37—$cache === nullshould benull === $cache. WordPress Coding Standards require Yoda conditions for comparisons, and the PR checks off WP standards compliance. The rest of the file uses the Yoda form (the old code hadnull === $cache). -
Minor
inc/extras.php:23— The docblock says "PMPro CPTs, if registered, are defaults." The "if registered" qualifier is misleading: the filter now always receives all three PMPro slugs as defaults regardless of whether those post types exist — the registration check happens later in theget_post_type_object()loop, not at the filter call site. A more accurate description: "PMPro CPT slugs are passed as defaults; unregistered ones are filtered out before caching."
Looks Good
The two-phase guard — coerce unexpected types to [] first, then handle strings — is cleaner than the old single is_array() fallback-to-pre-filter pattern, and correctly handles the false/null case that the old code missed. The final get_post_type_object() + show_ui check as the registration gate is the right place to do it.
|
Replying to Flint's PR Review: We're okay not using Yoda conditionals. I skimmed the rest of the file and did not see any conditionals using Yoda, and if there are, that is out of scope for this PR. As for the docblock, I've updated that. 👍 |
Skip slugs already collected so a duplicate returned via the memberlite_customizer_cpts filter cannot double-register Customizer sections or double-bind the JS sidebar/columns visibility toggles (which produced a stutter in the "Other Post Types" panel). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
All Submissions:
Changes proposed in this Pull Request:
A follow up to #303
Consolidates
memberlite_get_customizer_cpts()from two filters down to one. The PMPro CPTs (pmpro_course, pmpro_lesson, pmpro_series) are now passed as the default value tomemberlite_customizer_cpts, removing the need for the separatememberlite_pmpro_cpt_layout_settings_enabled(never released) filter. Adds return value guards: unexpected types coerce to[], a comma-separated string is exploded into an array, and non-string or empty elements are stripped before use.memberlite_pmpro_cpt_layout_settings_enabledwas removed, but it was never publicly released.How to test the changes in this Pull Request:
element is silently dropped.
Other information:
Changelog entry