In addition to the shortcodes documented elsewhere on the site, Memberium includes a set of PHP functions located in the /includes/memberium_api.php file in your Memberium plugin directory. We also provide hooks and filters for your developer to integrate their code and extend Memberium to meet your needs. The functions documented on the site, and in the memberium_api.php file are used internally by Memberium as well, and are guaranteed to be supported and continue functioning. Always check the memberium_api.php file for the latest functions.
Directly accessing the database structures, or using undocumented API Functions is strongly discouraged. We provide documented endpoints to protect your code from internal changes. Accessing raw data directly may cause your code to crash after an update.
- PHP Functions
If you’re having trouble getting your custom code working, we’re glad to try to help. The first step is to create a simple test example. In your ticket be sure to include FTP/SFTP access, directions on how to test your code, and where we can find your simple example code in your support ticket. Please note that we cannot help debug your code over screenshare or over the phone.
Running Memberium Shortcodes
By default, you can execute Memberium Shortcodes directly in your PHP code by using WordPress’s do_shortcode function:
echo do_shortcode('My Content');
All Memberium shortcode functionality is strictly coded for compatibility with WordPress, and no extra “backdoor” functions are required. Shortcodes produce formatted output back to your script, but they often do not return simple data that is easy for the developer to work with.
You can read more about do_shortcode() in the WordPress Codex.
Conditional functions test for a certain situation, and return a true/false (boolean) result. You can use these functions to control the flow and behavior of your code based on the current page load.
memb_hasAllTags( $tags, $contact_id = false )
Useful comparing many tags at once. Returns true if the user has all of the tags passed in via the $tags parameter in an array. If any of the tags are not held by the user, then the function returns false.
memb_hasAnyTags( $tags, $contact_id = false )
Useful comparing many tags at once. Returns true if the user has even just one of any of the tags passed in via the $tags parameter in array. If none of the tags are not held by the user, then the function returns false.
Returns true if the current visitor is logged in, and has a membership level. Returns false if the user is not logged in, or is logged in without a membership level.
memb_has_MembershipLevel( $level )
Returns true if the current visitor is logged in, and has a membership with the specified membership level number or higher. Returns false if the user is not logged in, or is logged in with a membership level lower than the number level specified. This function takes a number parameter.
memb_hasPostAccess( $post_id )
Returns true if the current visitor has access to the page, post or custom post type specified by ID#. If the visitor does not have access to the post, this function returns false.
memb_overrideProhibitedAction( $action )
This function allows you to temporarily override the prohibited action for pages or posts. The actions are “Excerpt”, “Hide”, and “Redirect”. Setting this to an empty string results in pages/posts using their default action.
These functions return information from the ActiveCampaign contact records.
memb_getContactField( $fieldname = ”, $sanitize = FALSE )
Returns the named contact field for the currently logged in user. If $sanitize is true, then the results are filtered through htmlspecialchars before being returned.
Returns the ActiveCampaign Contact ID of the currently logged in user. Useful for executing other API calls directly which require the contact ID as a parameter. Returns 0 if there is no current user logged in with a corresponding contact ID.
memb_getUserIdByContactId( $contact_id )
Returns the WordPress User ID matching to the ActiveCampaign Contact ID provided. Returns false/0 if there is no matching user with the corresponding contact ID.
memb_setTags( $tags = ”, $force = FALSE )
This function can take a tag or a list of tags in several formats (integer, CSV string, array) and will apply the tags to the user. Negative tags will be removed, positive tags will be added. If the tag already exists for an add, or doesn’t exist for a removal, then no action is taken to optimize API calls. The $force parameter changes his behavior to force the API call even if it doesn’t appear to be needed.
memb_setContactField( $contact_id, array $fields )
This function will update an ActiveCampaign contact field.
Returns the ActiveCampaign Contact ID matching to the WordPress User ID provided. Returns false if there is no matching user with the corresponding user ID.
Returns the $_SESSION data of the WordPress user ID supplied.
This function returns the appname as per what you’ve configured in the Memberium settings. It does not include the “.api-us1.com” as part of the URL.
Customizing Template and Page Behavior
Memberium functions can be used to customize how your pages behave based on different criteria. This is especially useful for pages on your site that are not generated by a regular page or post type of content. Examples of these sorts of pages would be category pages, archive pages, BBPress forum listings, etc.
Direct Access to $_SESSION Variables
Memberium keeps the current user’s information in a PHP session structure in $_SESSION. The storage for the session may vary depending on your hosting environment, but the access is the same.
There is nothing to stop you from directly accessing these variables, however, the structures, key names and data formats are subject to change. To ensure your code will continue to operate reliably through updates, please use the documented API calls above.
Looking for something not listed here?
If you need access to an API function, hook or filter not listed above please contact us at support and describe to us the use case for what you are trying to accomplish. Our core functions were created based on our experience integrating Memberium and other applications, and we’re open to adding more interface points to the system where they make sense for the greater community.