Last active
April 12, 2021 22:39
-
-
Save strangerstudios/bbb2697547b90a65967cf2a9779a6367 to your computer and use it in GitHub Desktop.
Show the "Favorite" button ONLY to members of Level ID 1 when using the Favorites Plugin for WordPress Raw
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
| <?php | |
| /* | |
| This recipe restricts display of the "Favorite" button for | |
| the Favorites Plugin by Kyle Phillips (https://wordpress.org/plugins/favorites/). | |
| Be sure to turn off the automatic display of the button under Settings > Favorites > Display. | |
| The button will be shown to members of Level ID 1 only. | |
| */ | |
| function my_pmpro_level_1_only_favorites( $content ) { | |
| //Don't show the favorites button on PMPro pages | |
| $excluded_pages = array(pmpro_getOption('billing_page_id'), pmpro_getOption('account_page_id'), pmpro_getOption('levels_page_id'), pmpro_getOption('checkout_page_id'), pmpro_getOption('confirmation_page_id')); | |
| //Show the favorites button for members of level 1 | |
| if( function_exists( 'pmpro_hasMembershipLevel' ) && | |
| pmpro_hasMembershipLevel( '1' ) && //update this line with your level ID | |
| //'post' === get_post_type( ) && //add this line to restrict to 'posts' only | |
| !is_page( $excluded_pages ) ) { | |
| if( function_exists( 'get_favorites_button) { | |
| $content .= get_favorites_button(); | |
| } | |
| } | |
| return $content; | |
| } | |
| add_filter( 'the_content', 'my_pmpro_level_1_only_favorites' ); |
This recipe is included in the blog post on "Allow Members to Favorite Posts using the Favorites Plugin for WordPress" at Paid Memberships Pro here: https://www.paidmembershipspro.com/allow-members-favorite-posts-using-favorites-plugin-wordpress/
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Line 18 needs a fix as per my gist https://gist.github.com/tajdara/6314a9fd903726876122c260a0a0413f