/** * Changes links from "profile.php" to themed profile page * * Callback for "site_url" hook * * @see site_url() * @since 6.0 * @access public * * @param string $url The generated link * @param string $path The specified path * @param string $orig_scheme The original connection scheme * @return string The filtered link */ public function site_url($url, $path, $orig_scheme = '') { global $current_user, $pagenow; if ('profile.php' != $pagenow && strpos($url, 'profile.php') !== false) { $user_role = reset($current_user->roles); if (is_multisite() && empty($user_role)) { $user_role = 'subscriber'; } if ($user_role && !$this->get_option(array($user_role, 'theme_profile'))) { return $url; } $parsed_url = parse_url($url); $url = Theme_My_Login::get_page_link('profile'); if (isset($parsed_url['query'])) { $url = add_query_arg(array_map('rawurlencode', wp_parse_args($parsed_url['query'])), $url); } } return $url; }
/** * Returns the proper redirect URL according to action * * @since 6.0 * @access public * * @param string $action The action * @return string The redirect URL */ public function get_redirect_url($action = '') { $theme_my_login = Theme_My_Login::get_object(); if (empty($action)) { $action = $this->get_option('default_action'); } $redirect_to = isset($_REQUEST['redirect_to']) ? $_REQUEST['redirect_to'] : ''; switch ($action) { case 'lostpassword': case 'retrievepassword': $url = apply_filters('lostpassword_redirect', !empty($redirect_to) ? $redirect_to : Theme_My_Login::get_page_link('login', 'checkemail=confirm')); break; case 'register': $url = apply_filters('registration_redirect', !empty($redirect_to) ? $redirect_to : Theme_My_Login::get_page_link('login', 'checkemail=registered')); break; case 'login': default: $url = apply_filters('login_redirect', !empty($redirect_to) ? $redirect_to : admin_url(), $redirect_to, null); } return apply_filters('tml_redirect_url', $url, $action); }
function pmpro_login_head() { $login_redirect = apply_filters("pmpro_login_redirect", true); if ((pmpro_is_login_page() || is_page("login") || class_exists("Theme_My_Login") && defined('Theme_My_Login::version') && version_compare(Theme_My_Login::version, "6.3") >= 0 && (Theme_My_Login::is_tml_page("register") || Theme_My_Login::is_tml_page("login"))) && $login_redirect) { //redirect registration page to levels page if (isset($_REQUEST['action']) && $_REQUEST['action'] == "register" || isset($_REQUEST['registration']) && $_REQUEST['registration'] == "disabled" || !is_admin() && class_exists("Theme_My_Login") && defined('Theme_My_Login::version') && version_compare(Theme_My_Login::version, "6.3") >= 0 && Theme_My_Login::is_tml_page("register")) { //redirect to levels page unless filter is set. $link = apply_filters("pmpro_register_redirect", pmpro_url("levels")); if (!empty($link)) { wp_redirect($link); exit; } else { return; } //don't redirect if pmpro_register_redirect filter returns false or a blank URL } //if theme my login is installed, redirect all logins to the login page if (pmpro_is_plugin_active("theme-my-login/theme-my-login.php")) { //check for the login page id and redirect there if we're not there already global $post; if (!empty($GLOBALS['theme_my_login']) && is_array($GLOBALS['theme_my_login']->options)) { //an older version of TML stores it this way if ($GLOBALS['theme_my_login']->options['page_id'] !== $post->ID) { //redirect to the real login page $link = get_permalink($GLOBALS['theme_my_login']->options['page_id']); if ($_SERVER['QUERY_STRING']) { $link .= "?" . $_SERVER['QUERY_STRING']; } wp_redirect($link); exit; } } elseif (!empty($GLOBALS['theme_my_login']->options)) { //another older version of TML stores it this way if ($GLOBALS['theme_my_login']->options->options['page_id'] !== $post->ID) { //redirect to the real login page $link = get_permalink($GLOBALS['theme_my_login']->options->options['page_id']); if ($_SERVER['QUERY_STRING']) { $link .= "?" . $_SERVER['QUERY_STRING']; } wp_redirect($link); exit; } } elseif (class_exists("Theme_My_Login") && defined('Theme_My_Login::version') && version_compare(Theme_My_Login::version, "6.3") >= 0) { //TML > 6.3 $link = Theme_My_Login::get_page_link("login"); if (!empty($link)) { //redirect if !is_page(), i.e. we're on wp-login.php if (!Theme_My_Login::is_tml_page()) { wp_redirect($link); exit; } } } //make sure users are only getting to the profile when logged in global $current_user; if (!empty($_REQUEST['action']) && $_REQUEST['action'] == "profile" && !$current_user->ID) { $link = get_permalink($GLOBALS['theme_my_login']->options->options['page_id']); wp_redirect($link); exit; } } } }
/** * Adds ajax parameter to TML redirect URL's * * Callback for "tml_redirect_url" filter * * @since 6.3 * @access public * * @param string $url The redirect URL * @param string $action The action * @return string The redirect URL */ public function tml_redirect_url($url, $action) { if (Theme_My_Login::is_tml_page() && in_array($action, self::default_actions()) && isset($_GET['ajax'])) { switch ($action) { case 'lostpassword': case 'retrievepassword': case 'register': $url = add_query_arg('ajax', 1, $url); break; case 'login': $url = Theme_My_Login::get_page_link('login', 'ajax=1'); break; } } return $url; }
/** * Blocks "pending" users from loggin in * * Callback for "authenticate" hook in function wp_authenticate() * * @see wp_authenticate() * @since 6.0 * @access public * * @param WP_User $user WP_User object * @param string $username Username posted * @param string $password Password posted * @return WP_User|WP_Error WP_User if the user can login, WP_Error otherwise */ public function authenticate($user, $username, $password) { global $wpdb; $cap_key = $wpdb->prefix . 'capabilities'; if ($userdata = get_user_by('login', $username)) { if (array_key_exists('pending', (array) $userdata->{$cap_key})) { if ('email' == $this->get_option('type')) { return new WP_Error('pending', sprintf(__('<strong>ERROR</strong>: You have not yet confirmed your e-mail address. <a href="%s">Resend activation</a>?', 'theme-my-login'), Theme_My_Login::get_page_link('login', array('action' => 'sendactivation', 'login' => $username)))); } else { return new WP_Error('pending', __('<strong>ERROR</strong>: Your registration has not yet been approved.', 'theme-my-login')); } } } return $user; }