Razvan Mocanu on "[Plugin: Paid Member Subscriptions - membership & content restriction] Content restriction code for custom PHP page"

ساخت وبلاگ

Hi,

I have a custom PHP page and I'm displaying it as custom template. I am using if (is_user_logged_in()) to check whether user is logged in. Is there a piece of code that I could add to my page so that the system would check whether user has also an active subscription plan?

Of course adding shortcode via WordPress to this page doesn't work. I would need to edit this page in notepad and add something.

Please let me know.

Regards,
Przemyslaw

https://wordpress.org/plugins/paid-member-subscriptions/

Hi Przemyslaw,

You can add the following function to functions.php file:

function pmsc_has_subscription_active($user_id, $subscription_plan_id){ $member = pms_get_member( $user_id ); $member_subscription = $member->get_subscription( $subscription_plan_id ); if(!empty( $member_subscription['status'] ) && $member_subscription['status'] == 'active'){ retu true; }else{ retu false; }
}

Here is how to apply it:

$plan_id = 100;
if(pmsc_has_subscription_active(get_current_user_id(), $plan_id )){ // code if current user has the subscription plan with ID $plan_id active.
}

The subscription plan ID can be found in the URL when editing a subscription plan in PMS -> Subscription Plans.

WordPress ...
ما را در سایت WordPress دنبال می کنید

برچسب : نویسنده : استخدام کار wpss بازدید : 312 تاريخ : دوشنبه 14 تير 1395 ساعت: 21:01