Last active
April 6, 2020 18:29
-
-
Save yratof/f26232db104fd5136a43 to your computer and use it in GitHub Desktop.
Helpful functions for wp-members wordpress plugin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Stop non-admins from accessing the dashboard. | |
Instead, they're redirected to a custom page, | |
which stops them from messing with the website. | |
This is the url. I've added an extra page to the site_url() */ | |
$goodbye = site_url() .'/video/videos'; | |
function acme_login_redirect( $redirect_to, $request, $user ) { | |
return ( is_array( $user->roles ) && in_array( 'administrator', $user->roles ) ) ? admin_url() : $goodbye; | |
} | |
add_filter( 'login_redirect', 'acme_login_redirect', 10, 3 ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Failed Login | |
------------ | |
*/ | |
add_filter( 'wpmem_login_failed', 'my_login_failed_msg' ); | |
function my_login_failed_msg( $str ) { | |
// defaults | |
$div_before = '<div class="text-center padding-4-top" id="">'; | |
$heading_before = '<h2>'; | |
$heading = __( 'Login failed', 'wp-members' ); | |
$heading_after = '</h2>'; | |
$p_before = '<p>'; | |
$message = __( 'You entered an invalid username or password.', 'wp-members' ); | |
$p_after = '</p>'; | |
$link = '<a class="button login threecol marginauto" href="' . $_SERVER['REQUEST_URI'] . '">' . __( 'Click here to continue.', 'wp-members' ) . '</a>'; | |
$div_after ='</div>'; | |
$str = $div_before | |
. $heading_before . $heading . $heading_after | |
. $p_before . $message . $p_after | |
. $p_before . $link . $p_after | |
. $div_after; | |
return $str; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Remove the stylesheet from the login form, we're going to style it ourselves. */ | |
add_action( 'wp_print_styles', 'my_styles', 99 ); | |
function my_styles() { | |
wp_deregister_style( 'wp-members' ); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Redirect to another page one successful login */ | |
add_filter( 'wpmem_login_redirect', 'my_login_redirect', 10, 2 ); | |
function my_login_redirect( $redirect_to, $user_id ) { | |
// return the url that the login should redirect to | |
return '/videos/videos'; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Rename 'Username' and 'Password'. | |
In this case, it's not a password that | |
the user needs, but a registration | |
number given to them by email. */ | |
add_filter( 'wpmem_inc_login_inputs', 'my_login_args' ); | |
function my_login_args( $array ) { | |
// Change [0] - username to 'club number' | |
$array[0]['name'] = 'Club Number'; | |
// Change [1] - password to 'Registration Number' | |
$array[1]['name'] = 'Registration Number'; | |
// Swap the Password field for a Text field. | |
$array[1]['type'] = 'text'; | |
return $array; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Strip out all that crappy <html> used in the login form */ | |
add_filter( 'wpmem_login_form_args', 'my_login_form_args', 10, 2 ); | |
function my_login_form_args( $args, $action ) { | |
$args = array( | |
// wrappers | |
'heading_before' => '<div style="display: none;">', // Easiest way to remove the heading | |
'heading_after' => '</div>', | |
'fieldset_before' => '', | |
'fieldset_after' => '', | |
'main_div_before' => '<div id="wpmem_login" class="login">', | |
'main_div_after' => '</div>', | |
'txt_before' => '', | |
'txt_after' => '', | |
'row_before' => '<div class="clearfix gutter-bottom">', | |
'row_after' => '</div>', | |
'buttons_before' => '', | |
'buttons_after' => '', | |
'link_before' => '', | |
'link_after' => '', | |
// classes & ids | |
'form_id' => '', | |
'form_class' => 'login--form', | |
'button_id' => '', | |
'button_class' => 'button compliment', | |
// other | |
'strip_breaks' => true, | |
'wrap_inputs' => false, | |
'remember_check' => false | |
); | |
return $args; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Tell someone to login. */ | |
add_filter( 'wpmem_login_form_before', 'my_function' ); | |
function my_function() { | |
$str = '<div class="text-center">Become a member and login below to see the rest of our videos</div>'; | |
return $str; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment