Files
ultimatemember/core/um-permalinks.php
T

186 lines
4.7 KiB
PHP
Raw Normal View History

2014-12-15 22:38:07 +02:00
<?php
class UM_Permalinks {
function __construct() {
global $wp;
$this->core = get_option('um_core_pages');
add_action('init', array(&$this, 'check_for_querystrings'), 1);
add_action('init', array(&$this, 'activate_account_via_email_link'), 1);
$this->current_url = $this->get_current_url();
}
/***
*** @Get query as array
***/
function get_query_array() {
$parts = parse_url( $this->get_current_url() );
2015-01-23 19:03:29 +02:00
if ( isset( $parts['query'] ) ){
2014-12-15 22:38:07 +02:00
parse_str($parts['query'], $query);
return $query;
2015-01-23 19:03:29 +02:00
}
2014-12-15 22:38:07 +02:00
}
/***
*** @Get current URL anywhere
***/
function get_current_url( $no_query_params = false ) {
global $post;
if ( is_front_page() ) :
2015-02-18 00:45:09 +02:00
$page_url = home_url() . $_SERVER["REQUEST_URI"];
2014-12-15 22:38:07 +02:00
else :
$page_url = 'http';
if ( isset( $_SERVER["HTTPS"] ) && $_SERVER["HTTPS"] == "on" )
$page_url .= "s";
$page_url .= "://";
if ( isset( $_SERVER["SERVER_PORT"] ) && $_SERVER["SERVER_PORT"] != "80" )
$page_url .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
else
$page_url .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
endif;
if ( $no_query_params == true ) {
$page_url = strtok($page_url, '?');
}
return apply_filters( 'um_get_current_page_url', $page_url );
}
/***
*** @activates an account via email
***/
function activate_account_via_email_link(){
global $ultimatemember;
2015-04-07 20:10:23 +02:00
2015-03-07 13:07:49 +02:00
if ( isset($_REQUEST['act']) && $_REQUEST['act'] == 'activate_via_email' && isset($_REQUEST['hash']) && strlen($_REQUEST['hash']) == 40 &&
2014-12-15 22:38:07 +02:00
isset($_REQUEST['user_id']) && is_numeric($_REQUEST['user_id']) ) { // valid token
um_fetch_user( $_REQUEST['user_id'] );
2015-04-07 20:10:23 +02:00
2014-12-15 22:38:07 +02:00
if ( um_user('account_status') != 'awaiting_email_confirmation' ) wp_die('The activation link you used is invalid or has expired.');
if ( $_REQUEST['hash'] != um_user('account_secret_hash') ) wp_die('The secret key provided does not match this one for the user.');
$ultimatemember->user->approve();
2015-04-07 20:10:23 +02:00
$redirect = ( um_user('url_email_activate') ) ? um_user('url_email_activate') : um_get_core_page('login', 'account_active');
2014-12-15 22:38:07 +02:00
um_reset_user();
2015-04-07 20:10:23 +02:00
exit( wp_redirect( $redirect ) );
2015-02-01 01:30:04 +02:00
2014-12-15 22:38:07 +02:00
}
}
/***
*** @makes an activate link for any user
***/
function activate_url(){
global $ultimatemember;
if ( !um_user('account_secret_hash') ) return false;
$url = add_query_arg( 'act', 'activate_via_email', home_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(){
global $ultimatemember;
if ( isset($_REQUEST['message']) )
$ultimatemember->shortcodes->message_mode = true;
if ( isset($_REQUEST['message']) && isset($_REQUEST['uid']) )
um_fetch_user( $_REQUEST['uid'] );
}
/***
*** @add a query param to url
***/
function add_query( $key, $value ) {
$this->current_url = add_query_arg( $key, $value, $this->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;
}
/***
*** @get profile url for set user
***/
function profile_url() {
global $ultimatemember;
2015-04-07 20:10:23 +02:00
2014-12-15 22:38:07 +02:00
$profile_url = $this->core['user'];
$profile_url = get_permalink($profile_url);
if ( um_get_option('permalink_base') == 'user_login' ) {
2015-01-24 23:39:43 +02:00
$user_in_url = um_user('user_login');
2015-01-25 19:59:18 +02:00
if ( is_email($user_in_url) ) {
$user_in_url = str_replace('@','',$user_in_url);
if( ( $pos = strrpos( $user_in_url , '.' ) ) !== false ) {
$search_length = strlen( '.' );
$user_in_url = substr_replace( $user_in_url , '-' , $pos , $search_length );
}
2015-02-04 20:31:39 +02:00
} else {
$user_in_url = sanitize_title( $user_in_url );
2015-01-25 19:59:18 +02:00
}
2014-12-15 22:38:07 +02:00
}
if ( um_get_option('permalink_base') == 'user_id' ) {
$user_in_url = um_user('ID');
}
if ( um_get_option('permalink_base') == 'name' ) {
$user_in_url = rawurlencode( strtolower( um_user('full_name') ) );
}
if ( get_option('permalink_structure') ) {
$profile_url = trailingslashit( untrailingslashit( $profile_url ) );
$profile_url = $profile_url . $user_in_url . '/';
} else {
$profile_url = add_query_arg( 'um_user', $user_in_url, $profile_url );
}
2015-01-25 19:59:18 +02:00
2014-12-15 22:38:07 +02:00
return $profile_url;
}
2015-01-03 15:31:15 +02:00
/***
*** @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;
}
2014-12-15 22:38:07 +02:00
}