In addition to the Shortcodes documented elsewhere on the site, Memberium includes a set of PHP functions located in the
file in your Memberium plugin directory. We also providehooks 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 interface.php file are used internally by Memberium as well, and are guaranteed to be supported and continue functioning. Always check the interface.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
- Action Hooks
- Filter Hooks
Looking for something not listed here?
If you need access to an API function, hook or filter not listed above please contact the developer, David Bullock in 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.
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. 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.
Returns true if the user is logged in. Returns false if the user is not logged in.
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_hasMembership( $level )
Returns true if the current visitor is logged in, and has the specified membership. Returns false if the user is not logged in, or is logged in and does not have the membership specified. The function takes the name of the membership as the parameter, and is not case-sensitive.
memb_hasMembershipLevel( $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.
This is a synonym for memb_getLoggedIn(), and functions identically.
Custom User Field Functions
Memberium provides the capability to store additional custom field and counter data in the user’s WordPress record. The advantage of using this information is that it is consistently available between logins, but does not require any additional API calls to read or write the data. Custom User Fields are created and destroyed dynamically and do not have to be predefined or setup.
Do not try to use these functions to read Infusionsoft contact fields. Use the contact functions further below instead.
memb_getUserField( $field_name, $user_id = FALSE )
Returns the value of the named field. If $user_id is not supplied, the the currently logged in user is assumed.
memb_setUserField( $field_name, $value, $user_id = FALSE )
Set the value of the named field. If $user_id is not supplied, then the currently logged in user is assumed.
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 Infusionsoft contact and affiliate records.
memb_getAffiliateField( $fieldname = ”, $sanitize = FALSE )
Returns the named affiliate field for the currently logged in user. If $sanitize is true, then the results are filtered through htmlspecialchars before being returned.
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 Infusionsoft 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 Infusionsoft Contact ID provided. Returns false/0 if there is no matching user with the corresponding contact ID.
memb_syncContact( $contact_id = 0, $cascade = FALSE )
Syncs the contact from Infusionsoft to Memberium, updating the local cache, and making the data available immediately on the next page load. The Cascade parameter indicates whether ONLY the contact record will be updated (default), or whether affiliate, tags and other records will be resynchronized as well. Additional datasets being synchronized consumes more API calls and requires additional time since API calls are relatively slow.
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( $fieldname = ”, $fieldvalue = ” )
This function will update an Infusionsoft contact field.
This function returns the appname you registered in the i2SDK plugin when your Memberium account was connected to your Infusionsoft API. It does not include the “.infusionsoft.com” part of the URL.memb_do_shortcode()
Some themes, most notably the drag and drop themes ( Divi, Visual Composer, Thrive, etc. ) sometimes benefit from being able to do two pass shortcode processing where the standard WordPress shortcodes are processed first, and then Memberium shortcodes are automatically processed afterwards. If you are running one of these themes and wish to process Memberium shortcodes in your PHP code, you can turn on the “Two Pass Shortcodes” in Memberium Advanced options, and use this function call.
Hooks are provided by WordPress and Memberium to allow your code to ‘hook into’ the rest of Memberium; that is, to call functions in your code at specific times, and thereby set your code in motion. Actions are triggered by specific events that take place in Memberium. An Action is a custom PHP function defined in your code. You can read more about Actions in the WordPress Plugin API in the WordPress Codex.
If you need access to an Action Hook that is not documented here, please contact Support and describe what your desired end result is, so that we can help you out.
Called after Memberium is loaded and initialized after the WordPress init action is called. You can hook this action if you wish to run code immediately only after Memberium is fully initialized. No parameters are passed.
Called after contact data is loaded. The contact Id is passed.
Called when a tag is added. Two parameters are passed; the contact Id, and the Tag ID.
Called when a tag is removed. Two parameters are passed; the contact Id, and the Tag ID.
Filters are provided by WordPress and Memberium to allow your code to ‘hook into’ the rest of Memberium, and to modify Memberium’s system data from your code. Filters are triggered by specific events that take place in Memberium. A filter is a custom PHP function defined in your code. You can read more about Filters in the WordPress Plugin API in the WordPress Codex.
When creating a filter for use with Memberium, it is critical that you return the data sent to your filter when it is called. You can return modified data, but returning no data may cause problems.
If you need access to a Filter Hook that is not documented here, please contact Support and describe your use case.
Passes an array of contact fields and values. Requires that the entire array be passed back.
Passes an array of Countries Requires that the entire array be passed back.
Passes the current login URL.
Passes the name, and an array of contact fields and values. Requires that the new nice name be passed back. You can see more examples here
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.