Last active
January 23, 2020 00:44
-
-
Save robertuniqid/75198217157037b5eec71ab80c8272f1 to your computer and use it in GitHub Desktop.
Wishlist Integration - Changes Over time.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** 13 Sep 2016 | |
* @param $user_id | |
* @param $post_id | |
* @param string $post_type | |
* @return bool | |
*/ | |
function member_can_access($user_id, $post_id, $post_type = 'courses') { | |
if( !function_exists( 'wlmapi_get_member_levels' ) ) | |
return true; | |
@$levels = array_keys( wlmapi_get_member_levels($user_id) ); | |
if( !is_array( $levels ) ) | |
return false; | |
if( empty( $levels ) ) | |
return false; | |
global $WishListMemberInstance; | |
@$content_levels = $WishListMemberInstance->GetContentLevels( $post_type, $post_id ); | |
if( !is_array( $content_levels ) ) | |
return true; | |
$intersection = array_intersect( $levels, $content_levels ); | |
if( empty( $intersection ) ) | |
return false; | |
return true; | |
} | |
/** 10 May 2017 | |
* @param $user_id | |
* @param $post_id | |
* @return bool | |
*/ | |
function member_can_access($user_id, $post_id ) { | |
if( !function_exists( 'wlmapi_get_member_levels' ) ) | |
return true; | |
@$levels = array_keys( wlmapi_get_member_levels($user_id) ); | |
if( !is_array( $levels ) ) | |
return false; | |
if( empty( $levels ) ) | |
return false; | |
global $WishListMemberInstance; | |
@$content_levels = $WishListMemberInstance->GetContentLevels( $post_type, $post_id ); | |
if( !is_array( $content_levels ) ) | |
return true; | |
if( empty( $content_levels ) ) | |
return true; | |
$intersection = array_intersect( $levels, $content_levels ); | |
if( empty( $intersection ) ) | |
return false; | |
return true; | |
} | |
/** | |
* 27 Aug 2018 - used within Wishlist Integration ( released version ) | |
* @param $user_id | |
* @param $post_id | |
* @return bool | |
*/ | |
public function member_can_access($user_id, $post_id ) { | |
if( function_exists( 'wlmapi_member_can_access' ) ) | |
return wlmapi_member_can_access( $user_id, get_post_type( $post_id ), $post_id ); | |
@$levels = array_keys( wlmapi_get_member_levels($user_id) ); | |
if( !is_array( $levels ) ) | |
return false; | |
if( empty( $levels ) ) | |
return false; | |
global $WishListMemberInstance; | |
@$content_levels = $WishListMemberInstance->GetContentLevels( get_post_type( $post_id ), $post_id ); | |
if( !is_array( $content_levels ) ) | |
return true; | |
if( empty( $content_levels ) ) | |
return true; | |
$intersection = array_intersect( $levels, $content_levels ); | |
if( empty( $intersection ) ) | |
return false; | |
return true; | |
} | |
/** | |
* 27 Aug 2018 - the only code required to actually work, but we had to support older versions too. | |
* @param $user_id | |
* @param $post_id | |
* @return bool | |
*/ | |
public function member_can_access($user_id, $post_id ) { | |
return wlmapi_member_can_access( $user_id, get_post_type( $post_id ), $post_id ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment