Skip to content

Instantly share code, notes, and snippets.

@strangerstudios
Last active April 12, 2021 22:39
Show Gist options
  • Select an option

  • Save strangerstudios/bbb2697547b90a65967cf2a9779a6367 to your computer and use it in GitHub Desktop.

Select an option

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
<?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' );
@tajdara
Copy link

tajdara commented Jul 3, 2020

@laurenhagan0306
Copy link

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