The WLMAPIMethods class is the service class for the helper functions in core/api-helper/functions.php. The class does all the work of connecting to the WishList Member API, authenticating, checking internal vs external connection, caching, and processing requests.
The class defaults to connecting to the local WishList Member install. However, it can be used directly to connect to an external WishList Member site. Use of the class directly does require WordPress.
This class along with wlmapiclass.php and functions.php are already installed in the latest version of WishList Member. You do NOT need to include them in your plugin/theme if you have WishList Member installed on your site. Simply begin calling functions or using the class to get started.
Methods
__construct($cache_time = 3600, $url = false, $api_key = false)
Constructor method for the class. Auto-generates defaults when using the helper functions in core/api-helper/functions.php. When used directly, you can specify a $url and $api_key of an external site to connect to and use WishList Member data from that site.
getAPIkey($raw = false)
Gets the API key for the local site. Used primarily with the helper functions. $raw specifies if you want the cached version of this request or not (which is useful for testing).
loadAPI()
Connects to the API, authenticates, and preps the $api object for use. This method won't work if called directly. It will return a “Not Authenticated” error if called directly. It's used in the following methods to ease the loading of the API in requests.
get_levels($raw = false)
Returns an array of all the membership levels in the current install. $raw specifies if you want the cached version of this request or not (which is useful for testing).
get_level($level_id, $raw = false)
Returns an array of data for the specified membership level. $raw specifies if you want the cached version of this request or not (which is useful for testing).
create_level($args)
Creates a new level according to the specified arguments. See wlmapi_create_level for a list of accepted arguments.
update_level($level_id, $args)
Updates the specified level according to the specified arguments. See wlmapi_update_level for a list of accepted arguments.
delete_level($level_id)
Deletes the specified membership level.
get_level_members($level_id, $raw = false)
Retrieves an array list of all members in the specified membership level. $raw specifies if you want the cached version of this request or not (which is useful for testing).
add_member_to_level($level_id, $args)
Adds the specified user to the specified membership level. See wlmapi_add_member_to_level for a list of accepted arguments.
remove_member_from_level($level_id, $member_id)
Removes the specified member from the specified membership level.
get_level_member_data($level_id, $member_id, $raw = false)
Retrieves membership level information for an individual member. $raw specifies if you want the cached version of this request or not (which is useful for testing).
update_level_member_data($level_id, $member_id, $args)
Updates membership level information for an individual member. See wlmapi_update_level_member_data for a list of accepted arguments.
get_level_posts($level_id, $raw = false)
Retrieves an array list of all posts in a membership level. $raw specifies if you want the cached version of this request or not (which is useful for testing).
get_level_post_type($level_id, $post_type, $raw = false)
Retrieves an array list of all posts in a membership level of the specified post type. $raw specifies if you want the cached version of this request or not (which is useful for testing).
add_post_to_level($level_id, $args)
Adds a post to a membership level. See wlmapi_add_post_to_level for a list of accepted arguments.
remove_post_from_level($level_id, $post_id)
Removes a post from a membership level.
get_level_pages($level_id, $raw = false)
Retrieves an array list of all pages in a membership level. $raw specifies if you want the cached version of this request or not (which is useful for testing).
add_page_to_level($level_id, $args)
Adds a page to a membership level. See wlmapi_add_page_to_level for a list of accepted arguments.
remove_page_from_level($level_id, $page_id)
Removes a page from a membership level.
get_level_commented_posts($level_id, $raw = false)
Retrieves an array list of all posts with comments in a membership level. $raw specifies if you want the cached version of this request or not (which is useful for testing).
add_post_comments_to_level($level_id, $args)
Adds a post's comments to a membership level. See wlmapi_add_post_comments_to_level for a list of accepted arguments.
remove_post_comments_from_level($level_id, $post_id)
Removes a post's comments from a membership level.
get_level_categories($level_id, $raw = false)
Retrieves an array list of all categories in a membership level. $raw specifies if you want the cached version of this request or not (which is useful for testing).
add_category_to_level($level_id, $args)
Adds a category to a membership level. See wlmapi_add_category_to_level for a list of accepted arguments.
remove_category_from_level($level_id, $category_id)
Removes a category from a membership level.
get_protected_posts($raw = false)
Retrieves an array list of all posts that are protected. $raw specifies if you want the cached version of this request or not (which is useful for testing).
protect_post($args)
Protects a post. See wlmapi_protect_post for a list of accepted arguments.
unprotect_post($post_id)
Unprotects a post.
get_protected_pages($raw = false)
Retrieves an array list of all pages that are protected. $raw specifies if you want the cached version of this request or not (which is useful for testing).
protect_page($args)
Protects a page. See wlmapi_protect_page for a list of accepted arguments.
unprotect_page($page_id)
Un-protects a page.
get_protected_categories($raw = false)
Retrieves an array list of all categories that are protected. $raw specifies if you want the cached version of this request or not (which is useful for testing).
protect_category($args)
Protects a category. See wlmapi_protect_category for a list of accepted arguments.
unprotect_category($category_id)
Un-protects a category.
get_members($raw = false)
Retrieves an array list of all members from the database. $raw specifies if you want the cached version of this request or not (which is useful for testing).
add_member($args)
Adds a new member to the database. See wlmapi_add_member for a list of accepted arguments.
get_member($user_id, $raw = false)
Retrieves membership details for the specified member. $raw specifies if you want the cached version of this request or not (which is useful for testing).
get_member_levels($user_id, $raw = false)
Retrieves membership level details for the specified user. $raw specifies if you want the cached version of this request or not (which is useful for testing).
update_member($user_id, $args)
Updates a member's details. See wlmapi_update_member for a list of accepted arguments.
delete_member($user_id)
Deletes a member from the database.
the_levels()
Filters the get_levels array list. Use the filter “wlmapi_the_levels” to filter the array.
the_level($level_id)
Filters the get_level array list. Use the filter “wlmapi_the_level” to filter the array.
the_level_members($level_id)
Filters the get_level_members array list. Use the filter “wlmapi_the_level_members” to filter the array.
the_level_posts($level_id)
Filters the get_level_posts array list. Use the filter “wlmapi_the_level_posts” to filter the array.
the_members()
Filters the get_members array list. Use the filter “wlmapi_the_members” to filter the array.
is_user_a_member($level_id, $user_id)
Checks if the user belongs to the membership level.
manage_post($level_id, $post_ids)
Protects posts and adds them to the membership level. $post_ids accepts an array or comma-seprated list of post IDs.
unmanage_post($level_id, $post_ids)
Un-protects posts and removes them from the membership level. $post_ids accepts an array or comma-seprated list of post IDs.
Notes
This class requires the wlmapiclass.php in order to work.