Skip to content

Filter adjustments to the memberlite_get_cpts function#317

Open
RachelRVasquez wants to merge 4 commits into
strangerstudios:devfrom
RachelRVasquez:adjust-get-cpts-filters
Open

Filter adjustments to the memberlite_get_cpts function#317
RachelRVasquez wants to merge 4 commits into
strangerstudios:devfrom
RachelRVasquez:adjust-get-cpts-filters

Conversation

@RachelRVasquez

Copy link
Copy Markdown
Collaborator

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 to memberlite_customizer_cpts, removing the need for the separate memberlite_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_enabled was removed, but it was never publicly released.

How to test the changes in this Pull Request:

  1. Confirm PMPro CPTs appear as expected in the Customizer (Courses, Lessons, Series sections present when the add-on is active).
  2. Add a filter returning a custom CPT slug and confirm it appears in the Customizer alongside the PMPro CPTs.
  3. Add a filter returning an empty array ([]) or empty string ('') and confirm all CPT Customizer sections disappear with no PHP warnings.
  4. Add a filter returning a comma-separated string (e.g. 'pmpro_course, my_cpt') and confirm both slugs are recognized.
  5. Add a filter that pushes a nested array as an element (e.g. $cpts[] = ['pmpro_series']) and confirm no "array to string conversion" warning in the debug log and the bad
    element is silently dropped.
  6. Add a filter returning null or false and confirm no warnings and an empty CPT list.

Other information:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you successfully run tests with your changes locally?

Changelog entry

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 to memberlite_customizer_cpts, removing the need for the separate memberlite_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.

…an empty string or array, gaurds against non-string/non-array values like false/null/integer, gaurd against nested arrays
@RachelRVasquez RachelRVasquez marked this pull request as ready for review June 17, 2026 13:15
@RachelRVasquez RachelRVasquez requested a review from Copilot June 17, 2026 13:15

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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_enabled filter and uses PMPro CPT slugs as the default passed to memberlite_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.

Comment thread inc/extras.php
Comment thread inc/extras.php

@flintfromthebasement flintfromthebasement left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 === null should be null === $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 had null === $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 the get_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.

@RachelRVasquez

Copy link
Copy Markdown
Collaborator Author

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>
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.

4 participants