ngaireackerley
Forum Replies Created
-
Forum: Fixing WordPress
In reply to: how to auth_redirect to specific pageThanks, but I’m not sure that was what I was trying to explain.
I ended up pretty much sorting it out, still tightening it up, but with plenty of research from various sites this is what I came up with – thought I’d share if it is of any use to anyone or if anyone can improve on it.
Basically, if you have a private post, you click ‘Read more’ this code directs the user to the custom login page (get_permalink(9)) and then upon correct login redirects them to the full post. I’ve tweaked it for incorrect logins/errors and redirects upon logout.
For the template file:
if ( ! is_user_logged_in() ) { // Display WordPress login form: //check if the user needs to be redirected, if not keep on current page if (!isset($_GET['redirect_to'])) { $args = array( 'form_id' => 'loginform-custom', 'label_username' => __( 'Username' ), 'label_password' => __( 'Password' ), 'label_remember' => __( 'Remember Me' ), 'label_log_in' => __( 'Log In!' ), 'remember' => true ); //if do need redirecting get the past url } else { $args = array( 'redirect' => $_GET['redirect_to'], 'form_id' => 'loginform-custom', 'label_username' => __( 'Username' ), 'label_password' => __( 'Password' ), 'label_remember' => __( 'Remember Me' ), 'label_log_in' => __( 'Log In!' ), 'remember' => true ); } if(isset($_GET['login']) && $_GET['login'] == 'failed') { ?> <div id="login-error"> <p>Login failed: You have entered an incorrect username or password, please try again.</p> </div> <?php } wp_login_form( $args ); ?> <a href="<?php echo wp_lostpassword_url( get_permalink() ); ?>" title="Lost Password">Lost Password</a> <?php } else { // If logged in: wp_loginout( get_permalink() ); // Display "Log Out" link. } }
For the functions.php file:
// Subscriber Login functionality to see private posts $subRole = get_role( 'subscriber' ); $subRole->add_cap( 'read_private_posts' ); //login via custom login page function redirect_to_login() { global $wp_query,$wpdb; if (is_404()) { $private = $wpdb->get_row($wp_query->request); if( 'private' == $private->post_status ) { $url = add_query_arg('redirect_to', $_SERVER['REQUEST_URI'], site_url(get_permalink(9))); wp_redirect($url); exit; } } } add_action('template_redirect', 'redirect_to_login'); //failed login attempts function custom_login_failed( $username ) { $referrer = wp_get_referer(); if ( $referrer && ! strstr($referrer, 'wp-login') && ! strstr($referrer,'wp-admin') ) { wp_redirect( add_query_arg('login', 'failed', $referrer) ); exit; } } add_action( 'wp_login_failed', 'custom_login_failed' ); function custom_authenticate_username_password( $user, $username, $password ) { if ( is_a($user, 'WP_User') ) { return $user; } if ( empty($username) || empty($password) ) { $error = new WP_Error(); $user = new WP_Error('authentication_failed', __('<strong>ERROR</strong>: Invalid username or incorrect password.')); return $error; } } add_filter( 'authenticate', 'custom_authenticate_username_password', 30, 3); function custom_login_form_to_login_page( $content ) { if ( is_page('registerlogin') && in_the_loop() ) { $output = $message = ""; if (! empty($_GET['action']) ) { if ( 'failed' == $_GET['action'] ) $message = "There was a problem with your username or password."; elseif ( 'loggedout' == $_GET['action'] ) $message = "You are now logged out."; elseif ( 'recovered' == $_GET['action'] ) $message = "Check your e-mail for the confirmation link."; } if ( $message ) $output .= '<div class="message"><p>'. $message .'</p></div>'; $output .= wp_login_form('echo=0&redirect='. site_url()); $output .= '<a href="'. wp_lostpassword_url( add_query_arg('action', 'recovered', get_permalink()) ) .'" title="Recover Lost Password">Lost Password?</a>'; $content .= $output; } return $content; }
Forum: Fixing WordPress
In reply to: how to auth_redirect to specific pageHello,
I’m having a similar issue – not sure if there was a solution or not. It seems pretty simple to me, but I think I’m missing something obvious.
Basically I have private posts that when the user clicks ‘Read more’ I want it to check if they are logged in, if not they are sent to a custom login page, then after they login it redirects them back to the single.php that they wanted to go to.
With your current solutions above (and variations I’ve found), you get to the custom login page and can login then you are kept on that same page rather than going back to the original post.
I had been using this in my functions.php, but it keeps the user on the custom login page:
$subRole = get_role( 'subscriber' ); $subRole->add_cap( 'read_private_posts' ); function redirect_to_login() { global $wp_query,$wpdb; if (is_404()) { $private = $wpdb->get_row($wp_query->request); if( 'private' == $private->post_status ) { wp_safe_redirect(home_url(get_permalink(9))); exit; //auth_redirect(); } } } add_action('template_redirect', 'redirect_to_login');
However, auth_redirect works perfectly, but ideally I want to be using this custom login page instead of the main WordPress login.
Is this even possible or should I just been changing the main WordPress login and use the auth_redirect?
Many Thanks
Forum: Plugins
In reply to: [SN Rating] Rating Analytics replace Media button in Admin DashboardThanks for emailing me the fix! Much appreciated.
Forum: Plugins
In reply to: [Lightbox Plus Colorbox] Potential hacked css files of Lightbox Plus ColorboxSorry I may have raised the flag on that one too soon – just looked into this link and saw there is a legitimate way to use base64 – sorry!