Title: PmPro Code isn&#039;t working
Last modified: August 24, 2016

---

# PmPro Code isn't working

 *  [thannah](https://wordpress.org/support/users/thannah/)
 * (@thannah)
 * [11 years ago](https://wordpress.org/support/topic/pmpro-code-isnt-working/)
 * I added a custom button to my website that is only allowed on one level. I’m 
   attempting to use the code below but I’m not getting results. Either the button
   deletes from everyone profile or I get a syntax error
 *     ```
       <!--?php
       	if(pmpro_hasMembershipLevel(array(5,'My Level Name')))
       	{
       	?-->
       	//Place your HTML or PHP code here if the user is in the required membership level
       	...
       	<!--?php
       	}
       ?-->
       ```
   
 * I’m placing php script in it place. Am I doing something wrong? I also tried
 *     ```
       <?php
       if(pmpro_hasMembershipLevel(array(5,'My Level Name')))
       {
       // PHP HERE
       }
       ?>
       ```
   
 * [https://wordpress.org/plugins/paid-memberships-pro/](https://wordpress.org/plugins/paid-memberships-pro/)

Viewing 4 replies - 1 through 4 (of 4 total)

 *  [essaysnark](https://wordpress.org/support/users/essaysnark/)
 * (@essaysnark)
 * [11 years ago](https://wordpress.org/support/topic/pmpro-code-isnt-working/#post-6062236)
 * Here is a post with the correct usage:
 * [https://wordpress.org/support/topic/plugin-paid-memberships-pro-if-a-certain-level-display-suchandsuch?replies=3](https://wordpress.org/support/topic/plugin-paid-memberships-pro-if-a-certain-level-display-suchandsuch?replies=3)
 * What is your actual code?
 *  Thread Starter [thannah](https://wordpress.org/support/users/thannah/)
 * (@thannah)
 * [11 years ago](https://wordpress.org/support/topic/pmpro-code-isnt-working/#post-6062244)
 * Thanks. My exact code is below.
 *     ```
       <center><p>
   
                       <?php
                       @session_start();
                       $id = bp_loggedin_user_id();
   
                       $obj = get_userdata( $id );
                       $user = $obj->data;
   
                       if (empty($id)) {
                           unset($_SESSION['admin_user']);
                           $_SESSION['admin_user'] = array();
                       } else {
                           $_SESSION['admin_user']['employee_name'] = $user->user_login;
                           $_SESSION['admin_user']['email'] = $user->user_email;
                           $_SESSION['admin_user']['id'] = bp_loggedin_user_id();
                           $_SESSION['admin_user']['type'] = 3;
                       }
   
                       global $bp;
   
                       $_SESSION['front_user']['bid'] = $bp->displayed_user->id;
   
                       if ($_SESSION['front_user']['bid'] == @$_SESSION['admin_user']['id']) {
                           ?>
                          Manage my services, prices, etc. <button onclick="window.open('https://www.salonidm.com/gzappointment/index.php?controller=GzAdmin&action=dashboard', '_blank', 'height=970,width=1000,toolbar=0,location=0,menubar=0,scrollbars=1');">Edit My Services</button>
                           <?php
                       } else {
                           ?>
   
                           Click button to view my schedule <button onclick="window.open('https://www.salonidm.com/gzappointment/preview.php', '_blank', 'height=970,width=1000,toolbar=0,location=0,menubar=0,scrollbars=1');">Book me now</button>
                           <?php
                       }
                       ?>
   
               </center>
       ```
   
 *  [essaysnark](https://wordpress.org/support/users/essaysnark/)
 * (@essaysnark)
 * [11 years ago](https://wordpress.org/support/topic/pmpro-code-isnt-working/#post-6062248)
 * There’s no PMPro level check in that code.
 * There’s probably an easier way to do what you want to do, either using the PMPro
   shortcodes in a page or post, or by using a widget in a sidebar and controlling
   access using Widget Logic.
 *  Thread Starter [thannah](https://wordpress.org/support/users/thannah/)
 * (@thannah)
 * [11 years ago](https://wordpress.org/support/topic/pmpro-code-isnt-working/#post-6062250)
 * It’s not a widget. It’s a custom button. I’m not sure where to put the pmpro 
   code with the code above. At first I did something like this which did the trick
   but it hid the button for all users.
 *     ```
       <!--?php
       	if(pmpro_hasMembershipLevel('5'))
       	{
       	?-->
        <?php
                       @session_start();
                       $id = bp_loggedin_user_id();
   
                       $obj = get_userdata( $id );
                       $user = $obj->data;
   
                       if (empty($id)) {
                           unset($_SESSION['admin_user']);
                           $_SESSION['admin_user'] = array();
                       } else {
                           $_SESSION['admin_user']['employee_name'] = $user->user_login;
                           $_SESSION['admin_user']['email'] = $user->user_email;
                           $_SESSION['admin_user']['id'] = bp_loggedin_user_id();
                           $_SESSION['admin_user']['type'] = 3;
                       }
   
                       global $bp;
   
                       $_SESSION['front_user']['bid'] = $bp->displayed_user->id;
   
                       if ($_SESSION['front_user']['bid'] == @$_SESSION['admin_user']['id']) {
                           ?>
                          Manage my services, prices, etc. <button onclick="window.open('https://www.salonidm.com/gzappointment/index.php?controller=GzAdmin&action=dashboard', '_blank', 'height=970,width=1000,toolbar=0,location=0,menubar=0,scrollbars=1');">Edit My Services</button>
                           <?php
                       } else {
                           ?>
   
                           Click button to view my schedule <button onclick="window.open('https://www.salonidm.com/gzappointment/preview.php', '_blank', 'height=970,width=1000,toolbar=0,location=0,menubar=0,scrollbars=1');">Book me now</button>
                           <?php
                       }
                       ?>
   
       <!--?php
       	}
       ?-->
       ```
   

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘PmPro Code isn't working’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/paid-memberships-pro_f1dacb.svg)
 * [Paid Memberships Pro - Content Restriction, User Registration, & Paid Subscriptions](https://wordpress.org/plugins/paid-memberships-pro/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/paid-memberships-pro/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/paid-memberships-pro/)
 * [Active Topics](https://wordpress.org/support/plugin/paid-memberships-pro/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/paid-memberships-pro/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/paid-memberships-pro/reviews/)

 * 4 replies
 * 2 participants
 * Last reply from: [thannah](https://wordpress.org/support/users/thannah/)
 * Last activity: [11 years ago](https://wordpress.org/support/topic/pmpro-code-isnt-working/#post-6062250)
 * Status: not resolved