fbpx

BuddyPress and MemberMouse

BuddyPress allows you to build any kind of community website using WordPress, with member profiles, activity streams, user groups, messaging, and more. Using BuddyPress with MemberMouse allows you to sell access to these features as a component of your membership offering.

Installing BuddyPress
  1. In the left column of your WordPress Admin Panel, select Plugins > Add New
  2. In the search box at the top-right, type “BuddyPress”
  3. Click Install on the BuddyPress plugin
  4. Click Activate when installation is complete
Creating BuddyPress Pages

BuddyPress requires a number of blank pages to perform its functions. Since MemberMouse will be handling new user registrations, some of the default pages are not required, but you will need to create new pages for Members and Activity Streams. If you've had BuddyPress installed for some time, these pages may have already been created, and you'll just need to note their URLs. To create a page:

  1. In the left column, select Pages > Add New
  2. Give the page a title. This will determine the default URL of the page
  3. Click Publish

For example, you could create pages with titles Members and Activity. Once you have created these pages, you'll need to associate them with their functions in BuddyPress:

  1. In the left column, select Settings > BuddyPress
  2. Switch to the Pages tab
  3. For each option in the Directories section, choose the page you created for that purpose
  4. Click Save Settings

Be sure to note the URLs for the pages in question, because you'll need them later when restricting access to them.

Protecting BuddyPress Pages

BuddyPress uses a unique loading mechanism that bypasses standard MemberMouse content protection, so you'll need to utilize a different method to restrict access to these pages that takes advantage of the MemberMouse PHP Interface. PHP is the programming language that WordPress and all your plugins are written in. Don't worry, it's not as scary as it sounds!

In summary, you'll install a plugin that allows us to execute PHP code on pages you specify, insert a code segment, and then edit that code as needed for your specific content protection scenario. The MemberMouse Support Team is available to assist you in modifying the content protection code for your specific needs. Please note that for issues affecting the function of BuddyPress, or any other third-party plugin, support will be provided by the plugin author.

Before you begin, you'll need to create the Membership Levels and/or Bundles you'll be using to protect access to the social networking features of your site. If you're not sure which to use, our team can help you decide. Once these have been created, you'll need their ID numbers, located in MemberMouse > Product Settings, on the Membership Levels and Bundles tabs, respectively. The ID number is located in the left column, please make a note of the ID and whether it belongs to a membership level or bundle.

Next, you'll install Woody Ad Snippets, the plugin that will insert your content protection code:

  1. In the left column, select Plugins > Add New
  2. In the search box at the top right, type “Woody Ad Snippets”
  3. Click the Install button for the Woody Ad Snippets plugin
  4. Click Activate when installation is complete

Once the plugin has been installed, we'll create and configure a new snippet:

  1. In the left column, select Woody Snippets > Add Snippet
  2. In the Universal Snippet box, click Create Item
  3. Give the snippet a title, such as “BuddyPress Content Protection”
  4. Paste the following code into the text input box beneath
<?php
if ( class_exists( 'MemberMouse' ) ) {
$restrictBP = ( mm_member_decision(array("isMember"=>"false")) );
  if ( $restrictBP == true ) {
         $url = get_site_url();
         $url .= "/mm-error/?message=You+are+not+logged+in+or+do+not+have+social+networking+access";
        wp_safe_redirect( $url );
    }
}
?>

Now, you'll need to customize this code as needed to prevent access to BuddyPress pages by unauthorized visitors. The example above restricts these pages to any logged-in member, and the code to do this is:

$restrictBP = ( mm_member_decision(array(“isMember”=>”false”)) );

Here are a few examples. The first restricts access to logged-in members with Membership Level ID 1:

$restrictBP = ( mm_member_decision(array(“isMember”=>”false”)) || mm_member_decision(array(“isMember”=>”true”, “membershipId”=>”!1″)) );

The next example restricts access to logged-in members with either Membership Level ID 1 or 2:

$restrictBP = ( mm_member_decision(array(“isMember”=>”false”)) || mm_member_decision(array(“isMember”=>”true”, “membershipId”=>”!(1|2)”)) );

This one restricts access to logged-in members with Bundle ID 1:

$restrictBP = ( mm_member_decision(array(“isMember”=>”false”)) || mm_member_decision(array(“isMember”=>”true”, “hasBundle”=>”!1″)) );

Once you've adjusted this line to suit your needs, the last task is to finish configuring the snippet so that it will run on the appropriate pages:

  1. In the Conditional execution logic section, set Display on IF

  2. Set the Condition drop-down to Current Page

  3. Set the Logic drop-down to Equals

  4. Enter the Relative URL of your BuddyPress Members Page
  5. Click the OR button on the right to add an additional line

  6. On the next line, set the Condition drop-down to Current Page

  7. Set the Logic drop-down to Equals

  8. Enter the Relative URL of your BuddyPress Activity Streams Page

  9. In the Base Options section, set Where to execute as Automatic Insertion

  10. In the Insert Location drop-down, select Header

  11. Click Publish on the right to publish your snippet
Testing BuddyPress Page Protection

It's always recommended to test content protection from the perspective of the member. There are three scenarios that you'll want to test:

Non-Member

You can test this just by opening an Incognito/Private Browsing Window, and visiting the two pages. Generally speaking, most customers allow only members to access their social networking pages, and the default code includes this restriction.

Member with Access

The easiest way to test this is to Create a New Test Member with the appropriate membership level and/or bundles, and login as this member using your Incognito/Private Browsing window. Our article on Providing Complimentary Access can be used to provision your test member with any paid membership or bundles required for testing.

Then, log into your site with the test member account, and visit the two BuddyPress pages to see if access is allowed.

Member without Access

In situations where not all members will have access, you can adjust the membership and/or bundles as required on the test account so that the member should not have access. There's no need to log out of your site and back in with the test account. Just adjust the account settings in Manage Members, return to your Incognito/Private Browsing window, and attempt to view the BuddyPress pages again.

Was this article helpful?

Related Articles