diff --git a/includes/core/class-access.php b/includes/core/class-access.php index f8de16a8..3aadeabe 100644 --- a/includes/core/class-access.php +++ b/includes/core/class-access.php @@ -225,6 +225,29 @@ if ( ! class_exists( 'Access' ) ) { return; $redirect_homepage = um_user( 'redirect_homepage' ); + /** + * UM hook + * + * @type filter + * @title um_custom_homepage_redirect_url + * @description Change custom homepage redirect + * @input_vars + * [{"var":"$url","type":"string","desc":"Redirect URL"}, + * {"var":"$id","type":"int","desc":"User ID"}] + * @change_log + * ["Since: 2.0"] + * @usage + * + * @example + * + */ + $redirect_homepage = apply_filters( 'um_custom_homepage_redirect_url', $redirect_homepage, um_user( 'ID' ) ); $redirect_to = ! empty( $redirect_homepage ) ? $redirect_homepage : um_get_core_page( 'user' ); $this->redirect_handler = $this->set_referer( esc_url( add_query_arg( 'redirect_to', urlencode_deep( $curr ), $redirect_to ) ), "custom_homepage" ); diff --git a/includes/core/class-logout.php b/includes/core/class-logout.php index 3d95e752..86f95c43 100644 --- a/includes/core/class-logout.php +++ b/includes/core/class-logout.php @@ -56,9 +56,32 @@ if ( ! class_exists( 'Logout' ) ) { session_unset(); exit( wp_redirect( home_url( $language_code ) ) ); } else { + /** + * UM hook + * + * @type filter + * @title um_logout_redirect_url + * @description Change redirect URL after logout + * @input_vars + * [{"var":"$url","type":"string","desc":"Redirect URL"}, + * {"var":"$id","type":"int","desc":"User ID"}] + * @change_log + * ["Since: 2.0"] + * @usage + * + * @example + * + */ + $redirect_url = apply_filters( 'um_logout_redirect_url', um_user( 'logout_redirect_url' ), um_user( 'ID' ) ); wp_logout(); session_unset(); - exit( wp_redirect( um_user('logout_redirect_url') ) ); + exit( wp_redirect( $redirect_url ) ); } diff --git a/includes/core/class-permalinks.php b/includes/core/class-permalinks.php index e0ac13bc..497f1140 100644 --- a/includes/core/class-permalinks.php +++ b/includes/core/class-permalinks.php @@ -5,328 +5,353 @@ namespace um\core; if ( ! defined( 'ABSPATH' ) ) exit; if ( ! class_exists( 'Permalinks' ) ) { - class Permalinks { - var $core; - var $current_url; - - function __construct() { - - add_action( 'init', array( &$this, 'set_current_url' ), 0 ); - - add_action( 'init', array( &$this, 'check_for_querystrings' ), 1 ); - - add_action( 'init', array( &$this, 'activate_account_via_email_link' ), 1 ); - - //add_action( 'um_user_after_updating_profile', array( &$this, 'profile_url' ), 1 ); - - remove_action( 'wp_head', 'rel_canonical' ); - - add_action( 'wp_head', array( &$this, 'um_rel_canonical_' ), 9 ); - } - - - /** - * Set current URL variable - */ - function set_current_url() { - $this->current_url = $this->get_current_url(); - } - /*** - *** @SEO canonical href bugfix - ***/ - function um_rel_canonical_() { - global $wp_the_query; - - if ( !is_singular() ) - return; - - /** - * UM hook - * - * @type filter - * @title um_allow_canonical__filter - * @description Allow canonical - * @input_vars - * [{"var":"$allow_canonical","type":"bool","desc":"Allow?"}] - * @change_log - * ["Since: 2.0"] - * @usage - * - * @example - * - */ - $enable_canonical = apply_filters( "um_allow_canonical__filter", true ); - - if( ! $enable_canonical ) - return; + /** + * Class Permalinks + * @package um\core + */ + class Permalinks { - if ( !$id = $wp_the_query->get_queried_object_id() ) - return; - if( UM()->config()->permalinks['user'] == $id ) { - $link = $this->get_current_url(); - echo "\n"; - return; - } + /** + * @var + */ + var $core; - $link = get_permalink( $id ); - if ( $page = get_query_var('cpage') ){ - $link = get_comments_pagenum_link( $page ); - echo "\n"; - } - } + /** + * @var + */ + var $current_url; - /*** - *** @Get query as array - ***/ - function get_query_array() { - $parts = parse_url( $this->get_current_url() ); - if ( isset( $parts['query'] ) ) { - parse_str($parts['query'], $query); - return $query; - } - } - - /*** - *** @Get current URL anywhere - ***/ - function get_current_url( $no_query_params = false ) { - $server_name_method = UM()->options()->get( 'current_url_method' ); - $server_name_method = ! empty( $server_name_method ) ? $server_name_method : 'SERVER_NAME'; - - $um_port_forwarding_url = UM()->options()->get( 'um_port_forwarding_url' ); - $um_port_forwarding_url = ! empty( $um_port_forwarding_url ) ? $um_port_forwarding_url : ''; - - if ( is_multisite() ) { - - $page_url = ''; - $blog_id = get_current_blog_id(); - $siteurl = get_site_url( $blog_id ); - - /*if ( is_front_page() ) { - $page_url = $siteurl; - - if( isset( $_SERVER['QUERY_STRING'] ) && trim( $_SERVER['QUERY_STRING'] ) ) { - $page_url .= '?' . $_SERVER['QUERY_STRING']; - } - } else {*/ - - $network_permalink_structure = UM()->options()->get( 'network_permalink_structure' ); - - if( $network_permalink_structure == "sub-directory" ){ - - $page_url = 'http'; - - if ( isset( $_SERVER["HTTPS"] ) && $_SERVER["HTTPS"] == "on" ) { - $page_url .= "s"; - } - - $page_url .= "://"; - - $page_url .= $_SERVER[ $server_name_method ]; - }else{ - $page_url .= $siteurl; - } - - if ( $um_port_forwarding_url == 1 && isset( $_SERVER["SERVER_PORT"] ) ) { - $page_url .= ":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"]; - - } else { - $page_url .= $_SERVER["REQUEST_URI"]; - } - - //} - - - }else{ - if ( !isset( $_SERVER['SERVER_NAME'] ) ) - return ''; - - /*if ( is_front_page() ) { - $page_url = home_url(); - - if( isset( $_SERVER['QUERY_STRING'] ) && trim( $_SERVER['QUERY_STRING'] ) ) { - $page_url .= '?' . $_SERVER['QUERY_STRING']; - } - } else {*/ - $page_url = 'http'; - - if ( isset( $_SERVER["HTTPS"] ) && $_SERVER["HTTPS"] == "on" ) { - $page_url .= "s"; - } - $page_url .= "://"; - - if ( $um_port_forwarding_url == 1 && isset( $_SERVER["SERVER_PORT"] ) ) { - $page_url .= $_SERVER[ $server_name_method ].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"]; - - } else { - $page_url .= $_SERVER[ $server_name_method ].$_SERVER["REQUEST_URI"]; - } - - //} - - - } - - if ( $no_query_params == true ) { - $page_url = strtok( $page_url, '?' ); - } - - /** - * UM hook - * - * @type filter - * @title um_get_current_page_url - * @description Change current page URL - * @input_vars - * [{"var":"$page_url","type":"string","desc":"Page URL"}] - * @change_log - * ["Since: 2.0"] - * @usage - * - * @example - * - */ - return apply_filters( 'um_get_current_page_url', $page_url ); - } - - /*** - *** @activates an account via email - ***/ - function activate_account_via_email_link() { - if ( isset($_REQUEST['act']) && $_REQUEST['act'] == 'activate_via_email' && isset($_REQUEST['hash']) && is_string($_REQUEST['hash']) && strlen($_REQUEST['hash']) == 40 && - isset($_REQUEST['user_id']) && is_numeric($_REQUEST['user_id']) ) { // valid token - - $user_id = absint( $_REQUEST['user_id'] ); - delete_option( "um_cache_userdata_{$user_id}" ); - - um_fetch_user( $user_id ); - - if ( strtolower($_REQUEST['hash']) !== strtolower( um_user('account_secret_hash') ) ) - wp_die( __( 'This activation link is expired or have already been used.','ultimate-member' ) ); - - UM()->user()->approve(); - $redirect = ( um_user('url_email_activate') ) ? um_user('url_email_activate') : um_get_core_page('login', 'account_active'); - $login = (bool) um_user('login_email_activate'); - - // log in automatically - if ( ! is_user_logged_in() && $login ) { - $user = get_userdata($user_id); - $user_id = $user->ID; - - // update wp user - wp_set_current_user( $user_id, $user->user_login ); - wp_set_auth_cookie( $user_id ); - - ob_start(); - do_action( 'wp_login', $user->user_login, $user ); - ob_end_clean(); - } - - um_reset_user(); - /** - * UM hook - * - * @type action - * @title um_after_email_confirmation - * @description Action on user activation - * @input_vars - * [{"var":"$user_id","type":"int","desc":"User ID"}] - * @change_log - * ["Since: 2.0"] - * @usage add_action( 'um_after_email_confirmation', 'function_name', 10, 1 ); - * @example - * - */ - do_action( 'um_after_email_confirmation', $user_id ); - - exit( wp_redirect( $redirect ) ); - - } - - } - - /*** - *** @makes an activate link for any user - ***/ - function activate_url() { - if ( !um_user('account_secret_hash') ) { - return false; - } - - /** - * UM hook - * - * @type filter - * @title um_activate_url - * @description Change activate user URL - * @input_vars - * [{"var":"$url","type":"string","desc":"Activate URL"}] - * @change_log - * ["Since: 2.0"] - * @usage - * - * @example - * - */ - $url = apply_filters( 'um_activate_url', home_url() ); - $url = add_query_arg( 'act', 'activate_via_email', $url ); - $url = add_query_arg( 'hash', um_user('account_secret_hash'), $url ); - $url = add_query_arg( 'user_id', um_user('ID'), $url ); - - return $url; - } - - /*** - *** @checks for UM query strings - ***/ - function check_for_querystrings(){ - if ( isset($_REQUEST['message']) ) - UM()->shortcodes()->message_mode = true; - } - - /*** - *** @add a query param to url - ***/ - function add_query( $key, $value ) { - $this->current_url = add_query_arg( $key, $value, $this->get_current_url() ); - return $this->current_url; - } - - - /*** - *** @remove a query param from url - ***/ - function remove_query( $key, $value ) { - $this->current_url = remove_query_arg( $key, $this->current_url ); - return $this->current_url; - } + + /** + * Permalinks constructor. + */ + function __construct() { + + add_action( 'init', array( &$this, 'set_current_url' ), 0 ); + + add_action( 'init', array( &$this, 'check_for_querystrings' ), 1 ); + + add_action( 'init', array( &$this, 'activate_account_via_email_link' ), 1 ); + + //add_action( 'um_user_after_updating_profile', array( &$this, 'profile_url' ), 1 ); + + remove_action( 'wp_head', 'rel_canonical' ); + + add_action( 'wp_head', array( &$this, 'um_rel_canonical_' ), 9 ); + } + + + /** + * Set current URL variable + */ + function set_current_url() { + $this->current_url = $this->get_current_url(); + } + + + /** + * SEO canonical href bugfix + */ + function um_rel_canonical_() { + global $wp_the_query; + + if ( ! is_singular() ) + return; + + /** + * UM hook + * + * @type filter + * @title um_allow_canonical__filter + * @description Allow canonical + * @input_vars + * [{"var":"$allow_canonical","type":"bool","desc":"Allow?"}] + * @change_log + * ["Since: 2.0"] + * @usage + * + * @example + * + */ + $enable_canonical = apply_filters( "um_allow_canonical__filter", true ); + + if( ! $enable_canonical ) + return; + + if ( !$id = $wp_the_query->get_queried_object_id() ) + return; + + if( UM()->config()->permalinks['user'] == $id ) { + $link = $this->get_current_url(); + echo "\n"; + return; + } + + $link = get_permalink( $id ); + if ( $page = get_query_var('cpage') ){ + $link = get_comments_pagenum_link( $page ); + echo "\n"; + } + + } + + + /** + * Get query as array + * + * @return array + */ + function get_query_array() { + $parts = parse_url( $this->get_current_url() ); + if ( isset( $parts['query'] ) ) { + parse_str( $parts['query'], $query ); + return $query; + } + + return array(); + } + + + /** + * Get current URL anywhere + * + * @param bool $no_query_params + * + * @return mixed|void + */ + function get_current_url( $no_query_params = false ) { + $server_name_method = UM()->options()->get( 'current_url_method' ); + $server_name_method = ! empty( $server_name_method ) ? $server_name_method : 'SERVER_NAME'; + + $um_port_forwarding_url = UM()->options()->get( 'um_port_forwarding_url' ); + $um_port_forwarding_url = ! empty( $um_port_forwarding_url ) ? $um_port_forwarding_url : ''; + + if ( is_multisite() ) { + + $page_url = ''; + $blog_id = get_current_blog_id(); + $siteurl = get_site_url( $blog_id ); + + $network_permalink_structure = UM()->options()->get( 'network_permalink_structure' ); + + if( $network_permalink_structure == "sub-directory" ){ + if ( is_ssl() ) { + $page_url = 'https'; + } else { + $page_url = 'http'; + } + $page_url .= "://"; + + $page_url .= $_SERVER[ $server_name_method ]; + }else{ + $page_url .= $siteurl; + } + + if ( $um_port_forwarding_url == 1 && isset( $_SERVER["SERVER_PORT"] ) ) { + $page_url .= ":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"]; + + } else { + $page_url .= $_SERVER["REQUEST_URI"]; + } + + } else { + if ( !isset( $_SERVER['SERVER_NAME'] ) ) + return ''; + + + if ( is_ssl() ) { + $page_url = 'https'; + } else { + $page_url = 'http'; + } + $page_url .= "://"; + + if ( $um_port_forwarding_url == 1 && isset( $_SERVER["SERVER_PORT"] ) ) { + $page_url .= $_SERVER[ $server_name_method ].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"]; + + } else { + $page_url .= $_SERVER[ $server_name_method ].$_SERVER["REQUEST_URI"]; + } + + } + + if ( $no_query_params == true ) { + $page_url = strtok( $page_url, '?' ); + } + + /** + * UM hook + * + * @type filter + * @title um_get_current_page_url + * @description Change current page URL + * @input_vars + * [{"var":"$page_url","type":"string","desc":"Page URL"}] + * @change_log + * ["Since: 2.0"] + * @usage + * + * @example + * + */ + return apply_filters( 'um_get_current_page_url', $page_url ); + } + + + /** + * Activates an account via email + */ + function activate_account_via_email_link() { + if ( isset($_REQUEST['act']) && $_REQUEST['act'] == 'activate_via_email' && isset($_REQUEST['hash']) && is_string($_REQUEST['hash']) && strlen($_REQUEST['hash']) == 40 && + isset($_REQUEST['user_id']) && is_numeric($_REQUEST['user_id']) ) { // valid token + + $user_id = absint( $_REQUEST['user_id'] ); + delete_option( "um_cache_userdata_{$user_id}" ); + + um_fetch_user( $user_id ); + + if ( strtolower($_REQUEST['hash']) !== strtolower( um_user('account_secret_hash') ) ) + wp_die( __( 'This activation link is expired or have already been used.','ultimate-member' ) ); + + UM()->user()->approve(); + $redirect = ( um_user('url_email_activate') ) ? um_user('url_email_activate') : um_get_core_page('login', 'account_active'); + $login = (bool) um_user('login_email_activate'); + + // log in automatically + if ( ! is_user_logged_in() && $login ) { + $user = get_userdata($user_id); + $user_id = $user->ID; + + // update wp user + wp_set_current_user( $user_id, $user->user_login ); + wp_set_auth_cookie( $user_id ); + + ob_start(); + do_action( 'wp_login', $user->user_login, $user ); + ob_end_clean(); + } + + um_reset_user(); + /** + * UM hook + * + * @type action + * @title um_after_email_confirmation + * @description Action on user activation + * @input_vars + * [{"var":"$user_id","type":"int","desc":"User ID"}] + * @change_log + * ["Since: 2.0"] + * @usage add_action( 'um_after_email_confirmation', 'function_name', 10, 1 ); + * @example + * + */ + do_action( 'um_after_email_confirmation', $user_id ); + + exit( wp_redirect( $redirect ) ); + + } + + } + + + /** + * Makes an activate link for any user + * + * @return bool|mixed|string|void + */ + function activate_url() { + if ( !um_user('account_secret_hash') ) { + return false; + } + + /** + * UM hook + * + * @type filter + * @title um_activate_url + * @description Change activate user URL + * @input_vars + * [{"var":"$url","type":"string","desc":"Activate URL"}] + * @change_log + * ["Since: 2.0"] + * @usage + * + * @example + * + */ + $url = apply_filters( 'um_activate_url', home_url() ); + $url = add_query_arg( 'act', 'activate_via_email', $url ); + $url = add_query_arg( 'hash', um_user('account_secret_hash'), $url ); + $url = add_query_arg( 'user_id', um_user('ID'), $url ); + + return $url; + } + + + /** + * Checks for UM query strings + */ + function check_for_querystrings() { + if ( isset( $_REQUEST['message'] ) ) { + UM()->shortcodes()->message_mode = true; + } + } + + + /** + * Add a query param to url + * + * @param $key + * @param $value + * + * @return string + */ + function add_query( $key, $value ) { + $this->current_url = add_query_arg( $key, $value, $this->get_current_url() ); + return $this->current_url; + } + + + /** + * Remove a query param from url + * + * @param $key + * @param $value + * + * @return string + */ + function remove_query( $key, $value ) { + $this->current_url = remove_query_arg( $key, $this->current_url ); + return $this->current_url; + } /** @@ -355,186 +380,192 @@ if ( ! class_exists( 'Permalinks' ) ) { return false; } - /** - * Get Profile Permalink - * - * @param string $slug - * @return string $profile_url - */ - function profile_permalink( $slug ) { - $page_id = UM()->config()->permalinks['user']; - $profile_url = get_permalink( $page_id ); + /** + * Get Profile Permalink + * + * @param string $slug + * @return string $profile_url + */ + function profile_permalink( $slug ) { - /** - * UM hook - * - * @type filter - * @title um_localize_permalink_filter - * @description Change user profile URL - * @input_vars - * [{"var":"$profile_url","type":"string","desc":"Profile URL"}, - * {"var":"$page_id","type":"int","desc":"Profile Page ID"}] - * @change_log - * ["Since: 2.0"] - * @usage - * - * @example - * - */ - $profile_url = apply_filters( 'um_localize_permalink_filter', $profile_url, $page_id ); + $page_id = UM()->config()->permalinks['user']; + $profile_url = get_permalink( $page_id ); - if ( get_option('permalink_structure') ) { + /** + * UM hook + * + * @type filter + * @title um_localize_permalink_filter + * @description Change user profile URL + * @input_vars + * [{"var":"$profile_url","type":"string","desc":"Profile URL"}, + * {"var":"$page_id","type":"int","desc":"Profile Page ID"}] + * @change_log + * ["Since: 2.0"] + * @usage + * + * @example + * + */ + $profile_url = apply_filters( 'um_localize_permalink_filter', $profile_url, $page_id ); - $profile_url = trailingslashit( untrailingslashit( $profile_url ) ); - $profile_url = $profile_url . strtolower( $slug ). '/'; + if ( get_option('permalink_structure') ) { - } else { + $profile_url = trailingslashit( untrailingslashit( $profile_url ) ); + $profile_url = $profile_url . strtolower( $slug ). '/'; - $profile_url = add_query_arg( 'um_user', $slug, $profile_url ); + } else { - } + $profile_url = add_query_arg( 'um_user', $slug, $profile_url ); - return ! empty( $profile_url ) ? strtolower( $profile_url ) : ''; + } - } - - /** - * Generate profile slug - * - * @param string $full_name - * @param string $first_name - * @param string $last_name - * @return string - */ - function profile_slug( $full_name, $first_name, $last_name ){ - - $permalink_base = UM()->options()->get( 'permalink_base' ); - - $user_in_url = ''; - - $full_name = str_replace("'", "", $full_name ); - $full_name = str_replace("&", "", $full_name ); - $full_name = str_replace("/", "", $full_name ); - - switch( $permalink_base ) - { - case 'name': // dotted - - $full_name_slug = $full_name; - $difficulties = 0; + return ! empty( $profile_url ) ? strtolower( $profile_url ) : ''; + } - if( strpos( $full_name, '.' ) > -1 ){ - $full_name = str_replace(".", "_", $full_name ); - $difficulties++; - } + /** + * Generate profile slug + * + * @param string $full_name + * @param string $first_name + * @param string $last_name + * @return string + */ + function profile_slug( $full_name, $first_name, $last_name ){ - $full_name = strtolower( str_replace( " ", ".", $full_name ) ); + $permalink_base = UM()->options()->get( 'permalink_base' ); - if( strpos( $full_name, '_.' ) > -1 ){ - $full_name = str_replace('_.', '_', $full_name ); - $difficulties++; - } + $user_in_url = ''; - $full_name_slug = str_replace( '-' , '.', $full_name_slug ); - $full_name_slug = str_replace( ' ' , '.', $full_name_slug ); - $full_name_slug = str_replace( '..' , '.', $full_name_slug ); + $full_name = str_replace("'", "", $full_name ); + $full_name = str_replace("&", "", $full_name ); + $full_name = str_replace("/", "", $full_name ); - if( strpos( $full_name, '.' ) > -1 ){ - $full_name = str_replace('.', ' ', $full_name ); - $difficulties++; - } + switch( $permalink_base ) { + case 'name': // dotted - $user_in_url = rawurlencode( $full_name_slug ); + $full_name_slug = $full_name; + $difficulties = 0; - break; - case 'name_dash': // dashed + if( strpos( $full_name, '.' ) > -1 ){ + $full_name = str_replace(".", "_", $full_name ); + $difficulties++; + } - $difficulties = 0; + $full_name = strtolower( str_replace( " ", ".", $full_name ) ); - $full_name_slug = strtolower( $full_name ); + if( strpos( $full_name, '_.' ) > -1 ){ + $full_name = str_replace('_.', '_', $full_name ); + $difficulties++; + } - // if last name has dashed replace with underscore - if( strpos( $last_name, '-') > -1 && strpos( $full_name, '-' ) > -1 ){ - $difficulties++; - $full_name = str_replace('-', '_', $full_name ); - } - // if first name has dashed replace with underscore - if( strpos( $first_name, '-') > -1 && strpos( $full_name, '-' ) > -1 ){ - $difficulties++; - $full_name = str_replace('-', '_', $full_name ); - } - // if name has space, replace with dash - $full_name_slug = str_replace( ' ' , '-', $full_name_slug ); + $full_name_slug = str_replace( '-' , '.', $full_name_slug ); + $full_name_slug = str_replace( ' ' , '.', $full_name_slug ); + $full_name_slug = str_replace( '..' , '.', $full_name_slug ); - // if name has period - if( strpos( $last_name, '.') > -1 && strpos( $full_name, '.' ) > -1 ){ - $difficulties++; - } + if( strpos( $full_name, '.' ) > -1 ){ + $full_name = str_replace('.', ' ', $full_name ); + $difficulties++; + } - $full_name_slug = str_replace( '.' , '-', $full_name_slug ); - $full_name_slug = str_replace( '--' , '-', $full_name_slug ); + $user_in_url = rawurlencode( $full_name_slug ); - $user_in_url = rawurlencode( $full_name_slug ); + break; - break; + case 'name_dash': // dashed - case 'name_plus': // plus + $difficulties = 0; - $difficulties = 0; + $full_name_slug = strtolower( $full_name ); - $full_name_slug = strtolower( $full_name ); + // if last name has dashed replace with underscore + if( strpos( $last_name, '-') > -1 && strpos( $full_name, '-' ) > -1 ){ + $difficulties++; + $full_name = str_replace('-', '_', $full_name ); + } + // if first name has dashed replace with underscore + if( strpos( $first_name, '-') > -1 && strpos( $full_name, '-' ) > -1 ){ + $difficulties++; + $full_name = str_replace('-', '_', $full_name ); + } + // if name has space, replace with dash + $full_name_slug = str_replace( ' ' , '-', $full_name_slug ); - // if last name has dashed replace with underscore - if( strpos( $last_name, '+') > -1 && strpos( $full_name, '+' ) > -1 ){ - $difficulties++; - $full_name = str_replace('-', '_', $full_name ); - } - // if first name has dashed replace with underscore - if( strpos( $first_name, '+') > -1 && strpos( $full_name, '+' ) > -1 ){ - $difficulties++; - $full_name = str_replace('-', '_', $full_name ); - } - if( strpos( $last_name, '-') > -1 || strpos( $first_name, '-') > -1 || strpos( $full_name, '-') > -1 ){ - $difficulties++; - } - // if name has space, replace with dash - $full_name_slug = str_replace( ' ' , '+', $full_name_slug ); - $full_name_slug = str_replace( '-' , '+', $full_name_slug ); + // if name has period + if( strpos( $last_name, '.') > -1 && strpos( $full_name, '.' ) > -1 ){ + $difficulties++; + } - // if name has period - if( strpos( $last_name, '.') > -1 && strpos( $full_name, '.' ) > -1 ){ - $difficulties++; - } + $full_name_slug = str_replace( '.' , '-', $full_name_slug ); + $full_name_slug = str_replace( '--' , '-', $full_name_slug ); - $full_name_slug = str_replace( '.' , '+', $full_name_slug ); - $full_name_slug = str_replace( '++' , '+', $full_name_slug ); + $user_in_url = rawurlencode( $full_name_slug ); - $user_in_url = $full_name_slug; + break; - break; - } - return $user_in_url ; + case 'name_plus': // plus - } + $difficulties = 0; - /*** - *** @get action url for admin use - ***/ - function admin_act_url( $action, $subaction ) { - $url = $this->get_current_url(); - $url = add_query_arg( 'um_adm_action', $action, $url ); - $url = add_query_arg( 'sub', $subaction, $url ); - $url = add_query_arg( 'user_id', um_user('ID'), $url ); - return $url; - } - } + $full_name_slug = strtolower( $full_name ); + + // if last name has dashed replace with underscore + if( strpos( $last_name, '+') > -1 && strpos( $full_name, '+' ) > -1 ){ + $difficulties++; + $full_name = str_replace('-', '_', $full_name ); + } + // if first name has dashed replace with underscore + if( strpos( $first_name, '+') > -1 && strpos( $full_name, '+' ) > -1 ){ + $difficulties++; + $full_name = str_replace('-', '_', $full_name ); + } + if( strpos( $last_name, '-') > -1 || strpos( $first_name, '-') > -1 || strpos( $full_name, '-') > -1 ){ + $difficulties++; + } + // if name has space, replace with dash + $full_name_slug = str_replace( ' ' , '+', $full_name_slug ); + $full_name_slug = str_replace( '-' , '+', $full_name_slug ); + + // if name has period + if( strpos( $last_name, '.') > -1 && strpos( $full_name, '.' ) > -1 ){ + $difficulties++; + } + + $full_name_slug = str_replace( '.' , '+', $full_name_slug ); + $full_name_slug = str_replace( '++' , '+', $full_name_slug ); + + $user_in_url = $full_name_slug; + + break; + } + + return $user_in_url ; + } + + + /** + * Get action url for admin use + * + * @param $action + * @param $subaction + * + * @return mixed|string|void + */ + function admin_act_url( $action, $subaction ) { + $url = $this->get_current_url(); + $url = add_query_arg( 'um_adm_action', $action, $url ); + $url = add_query_arg( 'sub', $subaction, $url ); + $url = add_query_arg( 'user_id', um_user('ID'), $url ); + return $url; + } + } } \ No newline at end of file diff --git a/includes/core/um-actions-account.php b/includes/core/um-actions-account.php index d23c24a1..fbcb2c82 100644 --- a/includes/core/um-actions-account.php +++ b/includes/core/um-actions-account.php @@ -166,7 +166,30 @@ function um_submit_account_errors_hook( $args ) { if ( um_user( 'after_delete' ) && um_user( 'after_delete' ) == 'redirect_home' ) { um_redirect_home(); } elseif ( um_user( 'delete_redirect_url' ) ) { - exit( wp_redirect( um_user( 'delete_redirect_url' ) ) ); + /** + * UM hook + * + * @type filter + * @title um_delete_account_redirect_url + * @description Change redirect URL after delete account + * @input_vars + * [{"var":"$url","type":"string","desc":"Redirect URL"}, + * {"var":"$id","type":"int","desc":"User ID"}] + * @change_log + * ["Since: 2.0"] + * @usage + * + * @example + * + */ + $redirect_url = apply_filters( 'um_delete_account_redirect_url', um_user( 'delete_redirect_url' ), um_user( 'ID' ) ); + exit( wp_redirect( $redirect_url ) ); } else { um_redirect_home(); } diff --git a/includes/core/um-actions-login.php b/includes/core/um-actions-login.php index 9f0846b0..3155ec2d 100644 --- a/includes/core/um-actions-login.php +++ b/includes/core/um-actions-login.php @@ -10,8 +10,8 @@ if ( ! defined( 'ABSPATH' ) ) exit; function um_submit_form_errors_hook_login( $args ){ $is_email = false; - $form_id = $args['form_id']; - $mode = $args['mode']; + $form_id = $args['form_id']; + $mode = $args['mode']; $user_password = $args['user_password']; @@ -218,7 +218,30 @@ if ( ! defined( 'ABSPATH' ) ) exit; break; case 'redirect_url': - exit( wp_redirect( um_user( 'login_redirect_url' ) ) ); + /** + * UM hook + * + * @type filter + * @title um_login_redirect_url + * @description Change redirect URL after successful login + * @input_vars + * [{"var":"$url","type":"string","desc":"Redirect URL"}, + * {"var":"$id","type":"int","desc":"User ID"}] + * @change_log + * ["Since: 2.0"] + * @usage + * + * @example + * + */ + $redirect_url = apply_filters( 'um_login_redirect_url', um_user( 'login_redirect_url' ), um_user( 'ID' ) ); + exit( wp_redirect( $redirect_url ) ); break; case 'refresh': @@ -240,6 +263,7 @@ if ( ! defined( 'ABSPATH' ) ) exit; ***/ add_action( 'um_submit_form_login', 'um_submit_form_login', 10 ); function um_submit_form_login( $args ) { + if ( ! isset( UM()->form()->errors ) ) { /** * UM hook diff --git a/includes/core/um-actions-register.php b/includes/core/um-actions-register.php index de55ca4f..f6fdcbf2 100644 --- a/includes/core/um-actions-register.php +++ b/includes/core/um-actions-register.php @@ -194,7 +194,32 @@ if ( ! defined( 'ABSPATH' ) ) exit; if ( $status != 'approved' ) { if ( um_user( $status . '_action' ) == 'redirect_url' && um_user( $status . '_url' ) != '' ) { - exit( wp_redirect( um_user( $status . '_url' ) ) ); + /** + * UM hook + * + * @type filter + * @title um_registration_pending_user_redirect + * @description Change redirect URL for pending user after registration + * @input_vars + * [{"var":"$url","type":"string","desc":"Redirect URL"}, + * {"var":"$status","type":"string","desc":"User status"}, + * {"var":"$user_id","type":"int","desc":"User ID"}] + * @change_log + * ["Since: 2.0"] + * @usage + * + * @example + * + */ + $redirect_url = apply_filters( 'um_registration_pending_user_redirect', um_user( $status . '_url' ), $status, um_user( 'ID' ) ); + + exit( wp_redirect( $redirect_url ) ); } if ( um_user( $status . '_action' ) == 'show_message' && um_user( $status . '_message' ) != '' ) {