Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

We need a pmpro_is_page() wrapper. #1958

Open
ideadude opened this issue Feb 18, 2022 · 1 comment
Open

We need a pmpro_is_page() wrapper. #1958

ideadude opened this issue Feb 18, 2022 · 1 comment

Comments

@ideadude
Copy link
Member

There are numerous places in add ons and custom code where we write something like this:
global $pmpro_pages; if ( is_page( $pmpro_pages['confirmation'] ) ) { // do something on the confirmation page }

This looks good and works most of the time. The problem is that sometimes the confirmation page may not be set, and so our code there becomes effectively a check for is_page(null) which returns true on ANY page, not just the confirmation page.

A function that returned false if the request page tag/id was empty and otherwise returned true if we were on that specific page would be useful.

We should probably just accept the PMPro page string (confirmation, checkout, billing, etc) and look up the post id from the $pmpro_pages global in the new function.

In the meantime, until we have something like this available, you can write something like this:
global $pmpro_pages; if ( ! empty( $pmpro_pages['confirmation'] && is_page( $pmpro_pages['confirmation'] ) ) { // do something on the confirmation page }

@andrewlimaza
Copy link
Contributor

andrewlimaza commented Nov 11, 2022

Something to also think about regarding improving this wrapper is to check the page's content for our particular shortcodes or blocks.

This only returns true when the confirmation page is assigned to the PMPro page settings (but having a custom confirmation page that isn't linked to PMPro's page settings will return false in some of our Add Ons).

Maybe two functions or a parameter to check for shortcode could be neat. The possible solutions:

  1. Two functions pmpro_is_page( 'confirmation' ) (checks is_page) and pmpro_maybe_is_page( 'confirmation' ) which checks for is_page and shortcode/block.

OR

  1. pmpro_is_page( 'levels', $shortcode = true ) that way developers can do a 'force check' to see if it's either the PMPro set page or the page contains a shortcode or block.

I'm leaning towards the second one instead, as we usually do force checks in some other methods.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants