【WP-Members】action and filter hooks

Redirect

filter hooksuse
wpmem_login_redirectSpecify the redirect destination after login
wpmem_logout_redirectSpecify the redirect destination after logout

action hooksuse
wpmem_register_redirectSpecify the redirect destination after completing membership registration

Specify the redirect destination after login : wpmem_login_redirect

add_filter( 'wpmem_login_redirect', 'my_login_redirect', 10, 2 );
function my_login_redirect( $redirect_to, $user_id ) {
    
    // Specify the URL of the redirect destination. It is also possible to use the wordpress method as shown below.
    return home_url( '/your-page/' );

}

Specify the redirect destination after logout : wpmem_logout_redirect

add_filter( 'wpmem_logout_redirect', 'my_logout_redirect_1' );
function my_logout_redirect_1( $redirect_to ) {
    return 'https://yourdomain.com/your-page';
}

Specify the redirect destination after completing membership registration : wpmem_register_redirect

It is an action hook only after completing the membership registration.

Since the fields parameter is also passed, you can add processing after membership registration.

add_action( 'wpmem_register_redirect', 'my_reg_redirect' );
 
function my_reg_redirect( $fields ) {
    wp_redirect( 'http://mydomain.com/my-page/' );
    exit();
}

$fields parameter contains the following information

  • ID
  • nickname
  • name
  • roles
  • date
  • IP address
  • URL

WP-Members dialogs and messages

filter hooksuse
wpmem_logout_linkChange the URL of the logout function
default : (domain)/?a=logout
wpmem_login_linksCustomize the message when accessing the "login page" while logged in
default : You are logged in as {nickname}
wpmem_register_linksCustomize the message when accessing the "Membership Registration Page" while logged in
default : You are logged in as {nickname}
wpmem_login_links_argsCustomize login page
wpmem_register_links_argsCustomize register page
wpmem_login_failedCustomize login failed messages
wpmem_login_failed_argsCustomize login failed args
wpmem_product_restricted_msgCustomize product restricted messages

Change logout URL : wpmem_logout_link

add_filter( 'wpmem_logout_link', 'my_logout_link' );

function my_logout_link( $string ) {
    $string = home_url('logout');
    return $string;
}

The URL of each logout link will change, but the URL of the logout function will not change.

Just using the above code will result in a 404 error. It is used for limited purposes such as when using the logout function of WordPress itself.

Change message on login page:wpmem_login_links

add_filter( 'wpmem_login_links', 'my_login_links' );
function my_login_links( $string )
{
    $string = "<p>I put this before the original message</p>" . $string;

    return $string;
}

WP-Members customize login form

Customize the message when accessing the "Membership Registration Page" while logged in : wpmem_register_links

add_filter( 'wpmem_register_links', 'my_register_links' );
function my_register_links( $string )
{
    $string = "<p>I put this before the original links</p>" . $string;

    return $string;
}
WP-Members register form

Customize login page : wpmem_login_links_args

add_filter( 'wpmem_login_links_args', 'my_login_links_args' );
function my_login_links_args( $args ) {

    $args['wrapper_before'] = '!!wrapper_before!!'.$args['wrapper_before'];
    $args['user_login'] = '!!user_login!!'.$args['user_login'];
    $args['welcome'] = '!!welcome!!'.$args['welcome'];
    $args['logout_text'] = '!!logout_text!!'.$args['logout_text'];
    $args['logout_link'] = '!!logout_link!!'.$args['logout_link'];
    $args['wrapper_after'] = $args['wrapper_after'].'!!wrapper_after!!';
    
    return $args;
}

WP-Members login form

Customize register page : wpmem_register_links_args

add_filter( 'wpmem_register_links_args', 'my_register_links_args' );
function my_register_links_args( $args ) {

    $args['before_wrapper'] = '!!before_wrapper!!'.$args['before_wrapper'];
    $args['wrapper_before'] = '!!wrapper_before!!'.$args['wrapper_before'];
    $args['wrapper_after'] = $args['wrapper_after'].'!!wrapper_after!!';
    $args['after_wrapper'] = $args['after_wrapper'].'!!after_wrapper!!';

    //Change link #2 2行目のリンク先を変更
    $args['rows'][1] = '<li><a href=' . home_url( 'my-page' ) . '>Enter the members area</a>';
    // Add another link. リンク先を追加
    $args['rows'][] = '<li><a href=' . home_url( 'some-page' ) . '>My Extra Link</a>';
    return $args;
}
WP-Members loggedin form

Customize login failed args : wpmem_login_failed

add_filter( 'wpmem_login_failed', 'my_login_failed_msg' );

function my_login_failed_msg( $str )
{
    $str = 'user not find.ユーザが見つかりません';
    return $str;
}
WP-Members register error form

Customize login failed args : wpmem_login_failed_args

add_filter( 'wpmem_login_failed_args', 'my_login_failed_args' );
 
function my_login_failed_args() {

    $args = array( 
        'heading_before' => '',
        'heading'        => '',
        'heading_after'  => '',
        'message'        => 'You did something wrong.',
    );
 
    return $args;
}
WP-Members customize register error

Customize product restricted messages : wpmem_product_restricted_msg

add_filter( 'wpmem_product_restricted_msg', 'my_product_restricted_msg', 10, 2 );
function my_product_restricted_msg( $msg, $post_products ) {
    global $wpmem;
    
    if ( count( $post_products ) > 1 ) {
        // Start with an empty container:
        $products = '';

        // Loop through the products to get their titles:
        foreach ( $post_products as $key => $post_product ) {

            // If this is the end of the product array, add ", or".
            // Note .= adds to the whatever is in the existing string $products
            end( $post_products );
            if ( $key === key( $post_products ) ) {
                $products .= "or " . $wpmem->membership->products[ $post_product ]['title'];
            } else {
                // Otherwise, if this is not the end, add a comma/space:
                $products .= $wpmem->membership->products[ $post_product ]['title'] . ", ";
            }
        }

    } else {
        // OR... if $post_products array is just one product:
        $products = $wpmem->membership->products[ $post_products[0] ]['title'];
    }

    $msg = "This is post is restricted.only for : ".$products;
    $msg .= "<br>";
    $msg .= $products."only membership。Resigter is <a href=\"#\">here</a>";

            return $msg;
}


WP-Members product page

WP-Members login

filter hookuse
wpmem_inc_login_inputsCustomize login form message
wpmem_login_form_argsCustomize login form

Customize login form message : wpmem_login_form_args

add_filter( 'wpmem_inc_login_inputs', 'my_login_inputs' );
function my_login_inputs( $default_inputs ) {

    $default_inputs[0]['name'] = 'Email';
    $default_inputs[1]['name'] = 'Password';

    return $default_inputs;
}

$default_inputs = array(
    array(
        'name'   => "Username or Email", // From $wpmem->get_text( 'login_username' ) 
        'type'   => 'text', 
        'tag'    => 'log',
        'class'  => 'username',
        'div'    => 'div_text',
    ),
    array( 
        'name'   => "Password",         // From $wpmem->get_text( 'login_password' ) 
        'type'   => 'password', 
        'tag'    => 'pwd', 
        'class'  => 'password',
        'div'    => 'div_text',
    ),
);
WP-Members customize loginform

Customize login form : wpmem_inc_login_args

add_filter( 'wpmem_login_form_args', function ( $args, $action ) {

    $args['row_before'] = '<div class="my-row-wrapper">';
    $args['row_after']  = '</div>';
    
    return $args;
    
}, 10, 2 );

how to use

WP-Members login form

parameter

    $defaults = array(

        // wrappers
        'heading_before'  => ' !!heading_before!!<legend>',
        'heading_after'   => '</legend>!!heading_after!! ',
        'fieldset_before' => ' !!fieldset_before<fieldset>',
        'fieldset_after'  => '</fieldset>fieldset_after!! ',
        'main_div_before' => ' !!main_div_before<div id="wpmem_login">',
        'main_div_after'  => '</div>!!main_div_after!! ',
        'txt_before'      => '!!txt_before!!',
        'txt_after'       => '!!txt_after!!',
        'row_before'      => '!!row_before!!',
        'row_after'       => '!!row_after!!',
        'buttons_before'  => ' !!buttons_before!!<div class="button_div">',
        'buttons_after'   => '</div>!!buttons_after!! ',
        'link_before'     => ' !!link_before!!<div class="link-text">',
        'link_after'      => '</div>!!link_after!! ',
        'link_span_before' => ' !!link_span_before!!<span class="link-text-%s">',
        'link_span_after'  => '</span>!!link_span_after!! ',

        // classes  ids
        'form_id'         => 'wpmem_action_form',
        'form_class'      => 'form',
        'button_id'       => '',
        'button_class'    => 'buttons',

        // other
        'strip_breaks'    => true,
        'wrap_inputs'     => true,
        'remember_check'  => true,
        'n'               => "\n",
        't'               => "\t",
        'redirect_to'     => '/test',
        'login_form_action' => true,

    );


WP-Members edit and reset password

filter hooksuse
wpmem_inc_changepassword_argsCustomize password change page
wpmem_inc_resetpassword_argsCustomize password reset page
wpmem_forgot_linkChange the link destination for forgot the password

Customize password change page : wpmem_inc_changepassword_args

add_filter( 'wpmem_inc_changepassword_args', 'my_changepassword_args' );
function my_changepassword_args( $args )
{
    $args = array( 'heading' => "Change Your Password" );

    return $args;
}
WP-Members edit password

Customize password reset page : wpmem_inc_resetpassword_args

add_filter( 'wpmem_inc_resetpassword_args', 'my_resetpassword_args' );
function my_resetpassword_args( $args )
{
    $args = array(
        'heading'      => "Request New Password",
        'button_text'  => "Reset My Password"
    );

    return $args;
}
WP-Members password reset

Change the link destination for forgot the password : wpmem_forgot_link

add_filter( 'wpmem_forgot_link', 'my_forgot_link', 10, 2 );
function my_forgot_link( $link, $tag ) {

    // Using home_url() instead makes your filter portable.
    
    return 'https://yoursite.com/your-page/';
}

WP-Members Register

filter hooksuse
wpmem_fieldsCustomize register form
wpmem_register_form_argsCustomize register page
wpmem_tos_link_txtCustomize terms of Service (TOS)
wpmem_recaptchaCustomize reCAPTCHA

Customize register form : wpmem_fields

add_filter( 'wpmem_fields', 'my_wpmem_fields_filter', 10, 2 );
function my_wpmem_fields_filter( $fields, $tag ) {


    if ( 'register' == $tag ) {
        unset( $fields['first_name'] );
        unset( $fields['last_name'] );

    }

    return $fields;
}

before

WP-Members register form before

after

WP-Members register form after

wpmem_register_form_args

add_filter( 'wpmem_register_form_args', 'my_register_form_row_wrapper', 10, 2 );
function my_register_form_row_wrapper( $args, $tag ) {
    $args = array(
        'row_before' => '<div class="my-row-wrapper">',
        'row_after'  => '</div>',
    );
 
    return $args;
}

how to use

WP-Members register

parameter

    $defaults = array(

        // Wrappers.
        'heading_before'   => '!!heading_before!!<legend>',
        'heading_after'    => '</legend>!!heading_after!!',
        'fieldset_before'  => '!!fieldset_before!!<fieldset>',
        'fieldset_after'   => '</fieldset>!!fieldset_after!!',
        'main_div_before'  => '!!main_div_before!!<div id="wpmem_reg">',
        'main_div_after'   => '</div>!!main_div_after!!',
        'txt_before'       => '!!txt_before!!',
        'txt_after'        => '!!txt_after!!',
        'row_before'       => '!!row_before!!',
        'row_after'        => '!!row_after!!',
        'buttons_before'   => '!!buttons_before!!<div class="button_div">',
        'buttons_after'    => '</div>!!buttons_after!!',

        // Classes  ids.
        'form_id'          => ( 'new' == $tag ) ? 'wpmem_register_form' : 'wpmem_profile_form',
        'form_class'       => 'form',
        'button_id'        => '',
        'button_class'     => 'buttons',

        // Required field tags and text.
        'req_mark'         => $wpmem->get_text( 'register_req_mark' ),
        'req_label'        => $wpmem->get_text( 'register_required' ),
        'req_label_before' => '<div class="req-text">',
        'req_label_after'  => '</div>',

        // Buttons.
        'show_clear_form'  => false,
        'clear_form'       => $wpmem->get_text( 'register_clear' ),
        'submit_register'  => $wpmem->get_text( 'register_submit' ),
        'submit_update'    => $wpmem->get_text( 'profile_submit' ),

        // Other.
        'post_to'          => get_permalink(),
        'strip_breaks'     => true,
        'use_nonce'        => false,
        'wrap_inputs'      => true,
        'n'                => "\n",
        't'                => "\t",
        'register_form_action' => true,
    );

Mail

filter hooksuse
wpmem_email_filterCustomize email body
wpmem_email_newregCustomize registered email
wpmem_email_newmod(When using the provisional registration setting) Customize provisional registration email
wpmem_email_appmod(When using the provisional registration setting) Customize the email when approving the provisional registration
wpmem_email_notifyCustomized notification email for administrators when registered as a member
wpmem_email_repassCustomize password reset email
wpmem_notify_filterCustomize notification email
wpmem_notify_addrCustomize the email address to which notification emails are sent
wpmem_email_shortcodesEmail shortcode settings
wpmem_email_headersCustomize email headers

Customize email headers : wpmem_email_headers

add_filter( 'wpmem_email_headers', 'my_wpmem_html_email' );
function my_wpmem_html_email() {
    return "Content-Type: text/html" . "\r\n";
}

WP-Members action hooks

action hooksuse
wpmem_register_redirectCustomize the redirect destination after membership registration
wpmem_pre_register_dataCustomize the registration data at the time of member registration
wpmem_post_register_dataCustomize the registration process when registering as a member
wpmem_pre_update_dataCustomize the registration data when updating member information
wpmem_post_update_dataCustomize the update process when updating member information
wpmem_user_activatedCustomize the activating membership

コメントを残す