• 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 » Code Snippets » Building a custom login process

Building a custom login process

Chad Butler · Dec 14, 2023 ·

if ( is_user_logged_in() ) {

    // The user is logged in.
    
    /**
     * You could potentially use wpmem_is_blocked() in here to build additional 
     * logic for blocked vs unblocked content.  You could also use some of the 
     * members functions to check for membership (either if the post requires it
     * of if the user has it).
     */
    
} else {
    global $wpmem;
    
    /**
     * Currently, the most consistent way to check for a login error is as displayed
     * below checking the $wpmem->regchk value.  However, as of 3.5.0, you'll be 
     * able to check $wpmem->error using is_wp_error(): 
     *     is_wp_error( $wpmem->error );
     * Depending on your current version, that may or may not be possible with 
     * versions below 3.5.0.
     */
    if ( 'loginfailed' == $wpmem->regchk ) {
        // The login failed.  You can output the error message with the following:
        echo wpmem_get_display_message( 'loginfailed' );
        
        /**
         * Note: echoing the above is an immediate output. This is suitable where
         * this is being used in a template or elsewhere where direct output is
         * suitable.  If, however, this is within a filter such as the_content, 
         * you need to return a value for content, not echo it. In such cases,
         * you can add this to your return variable:
         * 
         * $content .= wpmem_get_display_message( 'loginfailed' );
         */
        
        // Reprint the login form.
        echo wpmem_login_form();
        
        /**
         * Same as the above - you may want to add this to a return variable
         * instead if you are doing this a filter function:
         * $content .= wpmem_login_form();
         */
        
    } else {
        
        // Login was successful.  Echo (or return) content based on login.
        
    }
}

Not sure what to do with this code?

You're not a "coder" and don't know what to do? Don't worry! Code Snippets are the basic building blocks of WordPress customization, and once you know the basics, they are simple to use.

Here are some free articles to get you started:

  • Using Code Snippets from the Site
  • Using a code snippets plugin
  • The functions.php File
  • Create a plugin file for custom functions
  • Create a child theme
  • Do not modify plugin files!

For "hands on" help, consider a plugin support subscription or the Pro Bundle.

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