• thannah

    (@thannah)


    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/

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

    (@essaysnark)

    Thread Starter thannah

    (@thannah)

    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

    (@essaysnark)

    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

    (@thannah)

    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.