【WP-Members】action and filter hooks
contens
- 1. Redirect
- 1.1. Specify the redirect destination after login : wpmem_login_redirect
- 1.2. Specify the redirect destination after logout : wpmem_logout_redirect
- 1.3. Specify the redirect destination after completing membership registration : wpmem_register_redirect
- 2. WP-Members dialogs and messages
- 2.1. Change logout URL : wpmem_logout_link
- 2.2. Change message on login page:wpmem_login_links
- 2.3. Customize the message when accessing the "Membership Registration Page" while logged in : wpmem_register_links
- 2.4. Customize login page : wpmem_login_links_args
- 2.5. Customize register page : wpmem_register_links_args
- 2.6. Customize login failed args : wpmem_login_failed
- 2.7. Customize login failed args : wpmem_login_failed_args
- 2.8. Customize product restricted messages : wpmem_product_restricted_msg
- 3. WP-Members login
- 3.1. Customize login form message : wpmem_login_form_args
- 3.2. Customize login form : wpmem_inc_login_args
- 4. WP-Members edit and reset password
- 4.1. Customize password change page : wpmem_inc_changepassword_args
- 4.2. Customize password reset page : wpmem_inc_resetpassword_args
- 4.3. Change the link destination for forgot the password : wpmem_forgot_link
- 5. WP-Members Register
- 5.1. Customize register form : wpmem_fields
- 6. Mail
- 6.1. Customize email headers : wpmem_email_headers
- 7. WP-Members action hooks
Redirect
filter hooks | use |
---|---|
wpmem_login_redirect | Specify the redirect destination after login |
wpmem_logout_redirect | Specify the redirect destination after logout |
action hooks | use |
---|---|
wpmem_register_redirect | Specify 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 hooks | use |
---|---|
wpmem_logout_link | Change the URL of the logout function default : (domain)/?a=logout |
wpmem_login_links | Customize the message when accessing the "login page" while logged in default : You are logged in as {nickname} |
wpmem_register_links | Customize the message when accessing the "Membership Registration Page" while logged in default : You are logged in as {nickname} |
wpmem_login_links_args | Customize login page |
wpmem_register_links_args | Customize register page |
wpmem_login_failed | Customize login failed messages |
wpmem_login_failed_args | Customize login failed args |
wpmem_product_restricted_msg | Customize 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; }
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; }
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; }
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; }
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; }
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; }
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 login
filter hook | use |
---|---|
wpmem_inc_login_inputs | Customize login form message |
wpmem_login_form_args | Customize 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', ), );
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
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 hooks | use |
---|---|
wpmem_inc_changepassword_args | Customize password change page |
wpmem_inc_resetpassword_args | Customize password reset page |
wpmem_forgot_link | Change 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; }
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; }
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 hooks | use |
---|---|
wpmem_fields | Customize register form |
wpmem_register_form_args | Customize register page |
wpmem_tos_link_txt | Customize terms of Service (TOS) |
wpmem_recaptcha | Customize 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
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
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, );
filter hooks | use |
---|---|
wpmem_email_filter | Customize email body |
wpmem_email_newreg | Customize 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_notify | Customized notification email for administrators when registered as a member |
wpmem_email_repass | Customize password reset email |
wpmem_notify_filter | Customize notification email |
wpmem_notify_addr | Customize the email address to which notification emails are sent |
wpmem_email_shortcodes | Email shortcode settings |
wpmem_email_headers | Customize 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 hooks | use |
---|---|
wpmem_register_redirect | Customize the redirect destination after membership registration |
wpmem_pre_register_data | Customize the registration data at the time of member registration |
wpmem_post_register_data | Customize the registration process when registering as a member |
wpmem_pre_update_data | Customize the registration data when updating member information |
wpmem_post_update_data | Customize the update process when updating member information |
wpmem_user_activated | Customize the activating membership |