• Skip to primary navigation
  • Skip to main content

RocketGeek

Home of WP-Members, The Original WordPress Membership Plugin

  • WordPress Plugins
    • WP-Members
      • FAQs
      • Quick Start
      • Documentation
      • Extensions
    • Advanced Options
      • Documentation
      • Purchase the Plugin
      • Get the Pro Bundle
    • Download Protect
      • Documentation
      • Purchase the Plugin
      • Get the Pro Bundle
    • Invite Codes
      • Documentation
      • Purchase the Plugin
      • Get the Pro Bundle
    • MailChimp Integration
      • Documentation
      • Purchase the Plugin
      • Get the Pro Bundle
    • PayPal Subscriptions
      • Documentation
      • Purchase the Plugin
      • Get the Pro Bundle
    • Salesforce Web-to-Lead
    • Security
      • Documentation
      • Purchase the Plugin
      • Get the Pro Bundle
    • Text Editor
      • Purchase the Plugin
      • Get the Pro Bundle
    • User List
      • Documentation
      • Purchase the Plugin
      • Get the Pro Bundle
    • User Tracking
      • Documentation
      • Purchase the Plugin
      • Get the Pro Bundle
    • Memberships for WooCommerce
    • WordPass
  • Blog
    • Basics
    • Tips and Tricks
    • Filters
    • Actions
    • Code Snippets
    • Shortcodes
    • Design
    • Release Announcements
  • Store
    • Cart
    • Checkout
  • Contact
  • Log In
  • Show Search
Hide Search
Home » Search for "short code"

Search Results for: short code

wpmem_user_has_access()

Description

Checks if a user has access to a given membership product.

Parameters

$membership
(mixed) (required) The meta key of the membership being checked, or an array of membership meta keys.

$user_id
(integer) (optional) The user ID to check. If no user ID is passed, it will check for the currently logged in user.

Return Value

boolean (true|false) Returns true if the user has access, otherwise false.

Example

/**
 * This example checks if the currently logged in user has
 * access to the "my-membership" restriction. The 
 * result will be a true|false boolean.
 */
$has_access = wpmem_user_has_access( 'my-membership' );
 
 
/**
 * This example is similar to the above, but it checks a
 * specific user by user ID contained in $user_id.
 */
$has_access = wpmem_user_has_access( 'my-membership', $user_id ); 

Notes

If checking multiple memberships, pass an array of the membership meta keys (slugs).  If the user has current access to any of the memberships, the function will return true.

Changelog

Introduced in version 3.2.0
Version 3.2.3 reversed the order of arguments.

Source

wpmem_user_has_access() is located in /includes/api/api-users.php.

wpmem_set_user_product()

Description

Sets user access for a given product. (As of plugin version 3.4.2, use wpmem_set_user_membership() instead)

Parameters

$product
(string) (required) The meta key of the product to set access for.

$user_id
(integer) (optional) The user ID to assign access to. If no user ID is passed, it will set the product for the currently logged in user.

$date
(string|date|boolean) (optional) The user’s expiration date for the product in either MySQL date format (YYYY-MM-DD 00:00:00) or simply YYYY-MM-DD. Default value is false and the expiration will be set from the current date.

Return Value

boolean (true|false) Returns true if setting the product was successful.

Examples

// Basic usage of how the function is applied:
wpmem_set_user_product( $product_meta, $user_id, $date );


/*
 * The practical example below will set a default
 * membership for a user when they register. In this
 * example, it will set access for 'my_basic_product'.
 * In a real world application, get the slug for the
 * membership you want to set at registration from the
 * Membership > All Products table.
 *
 * The example uses the 'wpmem_post_register_data'
 * action to apply the membership at registration.
 * @see: https://rocketgeek.com/plugins/wp-members/docs/filter-hooks/wpmem_post_register_data/ 
 */
add_action( 'wpmem_post_register_data', 'my_set_basic_product' );
function my_set_basic_product( $fields ) {
    
    // Defaults.
    $product_meta = 'my_basic_product';
    $user_id = $fields['ID'];
    
    // Set product access.
    wpmem_set_user_product( $product_meta, $user_id );
}

Changelog

  • Introduced in version 3.2.3
  • Added $date argument in version 3.2.6
  • As of version 3.4.2, use wpmem_set_user_membership() instead.

Source

wpmem_set_user_product() is located in /includes/api/api-users.php.

Memberships

Membershipsgive you the ability to define access to posts, pages, and other content based on whether the user has been assigned a specific membership.

In WP-Members, “memberships” can fit a variety of applications based on your need.  In general, you can think of it as a defining tag that you can use to assign a user access to content.  If the user has a specific membership product they can access content set to require that membership product.

Defining Memberships

Memberships can be created and defined in the “Memberships” menu item.  You’ll need to have memberships enabled on the plugin’s main Options tab for this menu item to display.

Creating a new membership is much like creating a post.  Just click the “Add New” button at the top.

For a new membership, just enter a title.  The slug will be created automatically from the title.

For additional documentation and detailed information on available properties, see Membership Properties.

For documentation on how to set up “levels,” see Membership Levels.

To edit a membership, click the title in the memberships table.  Selecting a membership will bring you to the membership editor screen (see the screenshot for Add New Product – it is the same screen when editing).

Note that you cannot change the slug of a membership.

Assigning Memberships to Content

To set a post, page, or other content to require a membership to access, you can do this in the post editor.  In the upper right were the WP-Members post restriction meta box is, you will see the option to “Limit access to:” followed by a selector for memberships.  You can list a single membership or you can list multiple memberships.  In the case of multiple assigned memberships, the user will need to have a current and valid membership for one of the assigned memberships.

Managing User Access

You can manually enable or disable a user’s membership access in the user’s profile. In the Product Access section, select to “Enable” or “Disable” the desired membership and update the profile.

To automate access and/or to integrate with registration or other plugins, there are two API functions for adding or removing memberships for a user:

  • wpmem_set_user_product()
  • wpmem_remove_user_product()

WP-Members will automatically check to see if a user has access to content when that user tries to access.  However, for custom applications and integrations, the following API function can be used to check if a user has access or not:

  • wpmem_user_has_access()

Selling Memberships

Memberships are flexible. They are defined as a Custom Post Type (CPT) so you can integrate and customize how to assign access to users.

You can easily sell memberships through WooCommerce using the new WP-Members Memberships for WooCommerce extension. This extension will allow you to link a WP-Members membership in a WooCommerce product.  If a membership is linked to a WooCommerce product, when the user purchases that product, the user will have that membership assigned to them and will then be able to access content set to require that membership.

Tutorials and Code Snippets [Support Subscribers]

  • Custom shortcode to display a list of posts available for a given product
  • Allow users to choose a membership product at registration

How to bulk activate all users on an existing site

Chad Butler · Sep 25, 2018 ·

This article is provided free. Find out how you can get full access to premium content, including how-to articles and support forums, as well as priority email support and member exclusive plugin extensions..

 

A question that comes up from time to time is how to implement moderated registration on an existing site with current users.  There is no difference between an “existing” user and a “new” user – they are all simply “users,” so there isn’t a way for the plugin to know who you want to activate and who you don’t.

One particular problem, though, is that when you activate a user it will send the user a notification that they have been activated and if current settings are to send the user their initial password, their password will be set upon activation (thus changing an existing user’s password if you activate them).  

Continue Reading →

Allow users to choose membership products at registration

Chad Butler · Sep 20, 2018 ·

NOTE: This post is a tutorial for a process that is no longer necessary since the inclusion of the “membership” field type in WP-Members 3.2.6. If you’re using a recent version of WP-Members, then you already have a simple way of adding a membership selection to the WP-Members registration form by creating a custom field and selecting “membership” as the field type.

This process is for people who need to assign a membership when the user registers through the WP-Members registration form.  Since this is applied at registration, it is not recommended for users who are selling memberships, unless you are using moderated registration to approve the registration. Similarly, this is not recommended for installs integrating the selling of memberships through WooCommerce.

This is a working example of using WP-Members Membership Products. In this tutorial, we’ll add a custom field to display a multiple checkbox group in the registration form with a checkbox for each membership product.  The user can select one or several at registration.  

Continue Reading →
  • « Go to Previous Page
  • Page 1
  • Interim pages omitted …
  • Page 24
  • Page 25
  • Page 26
  • Page 27
  • Page 28
  • Interim pages omitted …
  • Page 53
  • Go to Next Page »

Ready to get started?

Join Today!

© 2025 · butlerblog.com · RocketGeek is built using WordPress, WP-Members, and the Genesis Framework

  • butlerblog.com
  • WP-Members Support Subscription
  • Terms of Service
  • Privacy Policy
  • Refund Policy