mirror of
https://github.com/10h30/ultimatemember.git
synced 2026-07-11 18:56:10 +09:00
Merge pull request #59 from jonfalcon/master
Fix member search on homepage
This commit is contained in:
+59
-53
@@ -3,27 +3,27 @@
|
||||
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() );
|
||||
if ( isset( $parts['query'] ) ){
|
||||
parse_str($parts['query'], $query);
|
||||
return $query;
|
||||
if ( isset( $parts['query'] ) ) {
|
||||
parse_str($parts['query'], $query);
|
||||
return $query;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,26 +32,32 @@ class UM_Permalinks {
|
||||
***/
|
||||
function get_current_url( $no_query_params = false ) {
|
||||
global $post;
|
||||
|
||||
|
||||
$server_name_method = ( um_get_option('current_url_method') ) ? um_get_option('current_url_method') : 'SERVER_NAME';
|
||||
|
||||
|
||||
if ( !isset( $_SERVER['SERVER_NAME'] ) )
|
||||
return '';
|
||||
|
||||
if ( is_front_page() ) :
|
||||
if ( is_front_page() ) {
|
||||
$page_url = home_url();
|
||||
else :
|
||||
|
||||
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";
|
||||
|
||||
if ( isset( $_SERVER["HTTPS"] ) && $_SERVER["HTTPS"] == "on" ) {
|
||||
$page_url .= "s";
|
||||
}
|
||||
$page_url .= "://";
|
||||
|
||||
if ( isset( $_SERVER["SERVER_PORT"] ) && $_SERVER["SERVER_PORT"] != "80" && $_SERVER["SERVER_PORT"] != "443" )
|
||||
$page_url .= $_SERVER[ $server_name_method ].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
|
||||
else
|
||||
$page_url .= $_SERVER[ $server_name_method ].$_SERVER["REQUEST_URI"];
|
||||
endif;
|
||||
|
||||
if ( isset( $_SERVER["SERVER_PORT"] ) && $_SERVER["SERVER_PORT"] != "80" && $_SERVER["SERVER_PORT"] != "443" ) {
|
||||
$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, '?');
|
||||
@@ -59,7 +65,7 @@ class UM_Permalinks {
|
||||
|
||||
return apply_filters( 'um_get_current_page_url', $page_url );
|
||||
}
|
||||
|
||||
|
||||
/***
|
||||
*** @activates an account via email
|
||||
***/
|
||||
@@ -68,53 +74,53 @@ class UM_Permalinks {
|
||||
|
||||
if ( isset($_REQUEST['act']) && $_REQUEST['act'] == 'activate_via_email' && isset($_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 ( 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();
|
||||
$redirect = ( um_user('url_email_activate') ) ? um_user('url_email_activate') : um_get_core_page('login', 'account_active');
|
||||
|
||||
|
||||
um_reset_user();
|
||||
|
||||
|
||||
do_action('um_after_email_confirmation', $user_id );
|
||||
|
||||
exit( wp_redirect( $redirect ) );
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/***
|
||||
*** @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']) )
|
||||
if ( isset($_REQUEST['message']) )
|
||||
$ultimatemember->shortcodes->message_mode = true;
|
||||
}
|
||||
|
||||
|
||||
/***
|
||||
*** @add a query param to url
|
||||
***/
|
||||
@@ -129,7 +135,7 @@ class UM_Permalinks {
|
||||
$this->current_url = remove_query_arg( $key, $this->current_url );
|
||||
return $this->current_url;
|
||||
}
|
||||
|
||||
|
||||
/***
|
||||
*** @get profile url for set user
|
||||
***/
|
||||
@@ -138,16 +144,16 @@ class UM_Permalinks {
|
||||
|
||||
$page_id = $this->core['user'];
|
||||
$profile_url = get_permalink( $page_id );
|
||||
|
||||
|
||||
if ( function_exists('icl_get_current_language') && icl_get_current_language() != icl_get_default_language() ) {
|
||||
if ( get_the_ID() > 0 && get_post_meta( get_the_ID(), '_um_wpml_user', true ) == 1 ) {
|
||||
$profile_url = get_permalink( get_the_ID() );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ( um_get_option('permalink_base') == 'user_login' ) {
|
||||
$user_in_url = um_user('user_login');
|
||||
|
||||
|
||||
if ( is_email($user_in_url) ) {
|
||||
$user_in_url = str_replace('@','',$user_in_url);
|
||||
if( ( $pos = strrpos( $user_in_url , '.' ) ) !== false ) {
|
||||
@@ -155,35 +161,35 @@ class UM_Permalinks {
|
||||
$user_in_url = substr_replace( $user_in_url , '-' , $pos , $search_length );
|
||||
}
|
||||
} else {
|
||||
|
||||
|
||||
$user_in_url = sanitize_title( $user_in_url );
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
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 );
|
||||
|
||||
|
||||
}
|
||||
|
||||
return $profile_url;
|
||||
}
|
||||
|
||||
|
||||
/***
|
||||
*** @get action url for admin use
|
||||
***/
|
||||
@@ -195,4 +201,4 @@ class UM_Permalinks {
|
||||
return $url;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
+81
-80
@@ -3,15 +3,15 @@
|
||||
class UM_Shortcodes {
|
||||
|
||||
function __construct() {
|
||||
|
||||
|
||||
$this->message_mode = false;
|
||||
|
||||
|
||||
$this->loop = '';
|
||||
|
||||
add_shortcode('ultimatemember', array(&$this, 'ultimatemember'), 1);
|
||||
|
||||
add_filter( 'body_class', array(&$this, 'body_class'), 0 );
|
||||
|
||||
|
||||
$this->emoji[':)'] = 'https://s.w.org/images/core/emoji/72x72/1f604.png';
|
||||
$this->emoji[':smiley:'] = 'https://s.w.org/images/core/emoji/72x72/1f603.png';
|
||||
$this->emoji[':D'] = 'https://s.w.org/images/core/emoji/72x72/1f600.png';
|
||||
@@ -72,18 +72,19 @@ class UM_Shortcodes {
|
||||
$this->emoji[':expressionless:'] = 'https://s.w.org/images/core/emoji/72x72/1f611.png';
|
||||
|
||||
}
|
||||
|
||||
|
||||
/***
|
||||
*** @emoji support
|
||||
***/
|
||||
function emotize( $content ) {
|
||||
$content = stripslashes( $content );
|
||||
foreach( $this->emoji as $code => $val ) {
|
||||
$content = str_replace( $code, '<img src="'.$val.'" alt="'.$code.'" title="'.$code.'" class="emoji" />', $content );
|
||||
$regex = str_replace( array( '(', ')' ), array( "\\" . '(', "\\" . ')'), $code );
|
||||
$content = preg_replace( '/(' . $regex . ')(\s|$)/', '<img src="'.$val.'" alt="'.$code.'" title="'.$code.'" class="emoji" />$2', $content );
|
||||
}
|
||||
return $content;
|
||||
}
|
||||
|
||||
|
||||
/***
|
||||
*** @extend body classes
|
||||
***/
|
||||
@@ -92,24 +93,24 @@ class UM_Shortcodes {
|
||||
|
||||
$array = $ultimatemember->permalinks->core;
|
||||
if ( !$array ) return $classes;
|
||||
|
||||
|
||||
foreach( $array as $slug => $info ) {
|
||||
if ( um_is_core_page( $slug ) ) {
|
||||
|
||||
|
||||
$classes[] = 'um-page-' . $slug;
|
||||
|
||||
|
||||
if ( is_user_logged_in() ) {
|
||||
$classes[] = 'um-page-loggedin';
|
||||
} else {
|
||||
$classes[] = 'um-page-loggedout';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $classes;
|
||||
}
|
||||
|
||||
|
||||
/***
|
||||
*** @Retrieve core login form
|
||||
***/
|
||||
@@ -117,15 +118,15 @@ class UM_Shortcodes {
|
||||
$forms = get_posts( array( 'post_type' => 'um_form', 'posts_per_page' => 1, 'meta_key' => '_um_core', 'meta_value' => 'login' ) );
|
||||
return $forms[0]->ID;
|
||||
}
|
||||
|
||||
|
||||
/***
|
||||
*** @load a compatible template
|
||||
***/
|
||||
function load_template( $tpl ) {
|
||||
global $ultimatemember;
|
||||
|
||||
|
||||
$loop = ( $this->loop ) ? $this->loop : '';
|
||||
|
||||
|
||||
if ( isset( $this->set_args ) && is_array( $this->set_args ) ) {
|
||||
$args = $this->set_args;
|
||||
extract( $args );
|
||||
@@ -136,51 +137,51 @@ class UM_Shortcodes {
|
||||
|
||||
if ( file_exists( $theme_file ) )
|
||||
$file = $theme_file;
|
||||
|
||||
|
||||
if ( file_exists( $file ) )
|
||||
include $file;
|
||||
}
|
||||
|
||||
|
||||
/***
|
||||
*** @Add class based on shortcode
|
||||
***/
|
||||
function get_class( $mode, $args = array() ){
|
||||
|
||||
|
||||
global $ultimatemember;
|
||||
|
||||
|
||||
$classes = 'um-'.$mode;
|
||||
|
||||
|
||||
if ( is_admin() ) {
|
||||
$classes .= ' um-in-admin';
|
||||
}
|
||||
|
||||
|
||||
if ( isset( $ultimatemember->form->errors ) && $ultimatemember->form->errors ) {
|
||||
$classes .= ' um-err';
|
||||
}
|
||||
|
||||
|
||||
if ( $ultimatemember->fields->editing == true ) {
|
||||
$classes .= ' um-editing';
|
||||
}
|
||||
|
||||
|
||||
if ( $ultimatemember->fields->viewing == true ) {
|
||||
$classes .= ' um-viewing';
|
||||
}
|
||||
|
||||
|
||||
if ( isset( $args['template'] ) && $args['template'] != $args['mode'] ) {
|
||||
$classes .= ' um-' . $args['template'];
|
||||
}
|
||||
|
||||
|
||||
$classes = apply_filters('um_form_official_classes__hook', $classes);
|
||||
return $classes;
|
||||
}
|
||||
|
||||
|
||||
/***
|
||||
*** @Shortcode
|
||||
***/
|
||||
function ultimatemember( $args = array() ) {
|
||||
return $this->load( $args );
|
||||
}
|
||||
|
||||
|
||||
/***
|
||||
*** @Load a module with global function
|
||||
***/
|
||||
@@ -190,16 +191,16 @@ class UM_Shortcodes {
|
||||
|
||||
$defaults = array();
|
||||
$args = wp_parse_args( $args, $defaults );
|
||||
|
||||
|
||||
// when to not continue
|
||||
$this->form_id = (isset($args['form_id'])) ? $args['form_id'] : null;
|
||||
if (!$this->form_id) return;
|
||||
$this->form_status = get_post_status( $this->form_id );
|
||||
if ( $this->form_status != 'publish' ) return;
|
||||
|
||||
|
||||
// get data into one global array
|
||||
$post_data = $ultimatemember->query->post_data( $this->form_id );
|
||||
|
||||
|
||||
$args = apply_filters('um_pre_args_setup', $post_data );
|
||||
|
||||
if ( !isset( $args['template'] ) ) $args['template'] = '';
|
||||
@@ -207,7 +208,7 @@ class UM_Shortcodes {
|
||||
if ( !$this->template_exists( $args['template'] ) ) $args['template'] = $post_data['mode'];
|
||||
if ( !isset( $post_data['template'] ) ) $post_data['template'] = $post_data['mode'];
|
||||
$args = array_merge( $post_data, $args );
|
||||
|
||||
|
||||
if ( isset( $args['use_globals'] ) && $args['use_globals'] == 1 ) {
|
||||
$args = array_merge( $args, $this->get_css_args( $args ) );
|
||||
} else {
|
||||
@@ -220,32 +221,32 @@ class UM_Shortcodes {
|
||||
extract( $args, EXTR_SKIP );
|
||||
|
||||
// for profiles only
|
||||
if ( $mode == 'profile' && um_profile_id() && isset( $args['role'] ) && $args['role'] &&
|
||||
if ( $mode == 'profile' && um_profile_id() && isset( $args['role'] ) && $args['role'] &&
|
||||
$args['role'] != $ultimatemember->query->get_role_by_userid( um_profile_id() ) )
|
||||
return;
|
||||
|
||||
// start loading the template here
|
||||
do_action("um_pre_{$mode}_shortcode", $args);
|
||||
|
||||
|
||||
do_action("um_before_form_is_loaded", $args);
|
||||
|
||||
|
||||
do_action("um_before_{$mode}_form_is_loaded", $args);
|
||||
|
||||
$this->template_load( $template, $args );
|
||||
|
||||
|
||||
$this->dynamic_css( $args );
|
||||
|
||||
|
||||
if ( um_get_requested_user() || $mode == 'logout' ) {
|
||||
um_reset_user();
|
||||
}
|
||||
|
||||
|
||||
do_action('um_after_everything_output');
|
||||
|
||||
$output = ob_get_contents();
|
||||
ob_end_clean();
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
||||
/***
|
||||
*** @Get dynamic css args
|
||||
***/
|
||||
@@ -254,32 +255,32 @@ class UM_Shortcodes {
|
||||
$arr = array_merge( $arr, array( 'form_id' => $args['form_id'], 'mode' => $args['mode'] ) );
|
||||
return $arr;
|
||||
}
|
||||
|
||||
|
||||
/***
|
||||
*** @Load dynamic css
|
||||
***/
|
||||
function dynamic_css( $args=array() ) {
|
||||
global $ultimatemember;
|
||||
extract($args);
|
||||
|
||||
|
||||
$global = um_path . 'assets/dynamic_css/dynamic_global.php';
|
||||
|
||||
|
||||
if ( isset( $mode ) ) {
|
||||
$file = um_path . 'assets/dynamic_css/dynamic_'.$mode.'.php';
|
||||
}
|
||||
|
||||
|
||||
include $global;
|
||||
|
||||
|
||||
if ( isset( $file ) && file_exists( $file ) )
|
||||
include $file;
|
||||
|
||||
|
||||
if ( isset( $args['custom_css'] ) ) {
|
||||
$css = $args['custom_css'];
|
||||
?><!-- ULTIMATE MEMBER FORM INLINE CSS BEGIN --><style type="text/css"><?php print $ultimatemember->styles->minify( $css ); ?></style><!-- ULTIMATE MEMBER FORM INLINE CSS END --><?php
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/***
|
||||
*** @Loads a template file
|
||||
***/
|
||||
@@ -290,20 +291,20 @@ class UM_Shortcodes {
|
||||
}
|
||||
$ultimatemember->shortcodes->load_template( $template );
|
||||
}
|
||||
|
||||
|
||||
/***
|
||||
*** @Checks if a template file exists
|
||||
***/
|
||||
function template_exists( $template ) {
|
||||
|
||||
|
||||
$file = um_path . 'templates/'. $template . '.php';
|
||||
$theme_file = get_stylesheet_directory() . '/ultimate-member/templates/' . $template . '.php';
|
||||
|
||||
|
||||
if ( file_exists( $theme_file ) || file_exists( $file ) )
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/***
|
||||
*** @Get File Name without path and extension
|
||||
***/
|
||||
@@ -312,35 +313,35 @@ class UM_Shortcodes {
|
||||
$file = preg_replace('/\\.[^.\\s]{3,4}$/', '', $file);
|
||||
return $file;
|
||||
}
|
||||
|
||||
|
||||
/***
|
||||
*** @Get Templates
|
||||
***/
|
||||
function get_templates( $excluded = null ) {
|
||||
|
||||
|
||||
if ($excluded) {
|
||||
$array[$excluded] = __('Default Template','ultimatemember');
|
||||
}
|
||||
|
||||
|
||||
$paths[] = glob( um_path . 'templates/' . '*.php');
|
||||
|
||||
|
||||
if ( file_exists( get_stylesheet_directory() . '/ultimate-member/templates/' ) ) {
|
||||
$paths[] = glob( get_stylesheet_directory() . '/ultimate-member/templates/' . '*.php' );
|
||||
}
|
||||
|
||||
|
||||
foreach($paths as $k => $files){
|
||||
|
||||
|
||||
foreach( $files as $file ) {
|
||||
|
||||
|
||||
$clean_filename = $this->get_template_name($file);
|
||||
|
||||
|
||||
if (0 === strpos($clean_filename, $excluded)) {
|
||||
|
||||
|
||||
$source = file_get_contents( $file );
|
||||
$tokens = token_get_all( $source );
|
||||
$comment = array(
|
||||
T_COMMENT, // All comments since PHP5
|
||||
T_DOC_COMMENT // PHPDoc comments
|
||||
T_DOC_COMMENT // PHPDoc comments
|
||||
);
|
||||
foreach( $tokens as $token ) {
|
||||
if( in_array($token[0], $comment) && strstr( $token[1], '/* Template:' ) && $clean_filename != $excluded ) {
|
||||
@@ -350,17 +351,17 @@ class UM_Shortcodes {
|
||||
$array[ $clean_filename ] = $txt;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
return $array;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/***
|
||||
*** @Get Shortcode for given form ID
|
||||
***/
|
||||
@@ -368,14 +369,14 @@ class UM_Shortcodes {
|
||||
$shortcode = '[ultimatemember form_id='.$post_id.']';
|
||||
return $shortcode;
|
||||
}
|
||||
|
||||
|
||||
/***
|
||||
*** @convert user tags in a string
|
||||
***/
|
||||
function convert_user_tags( $str ) {
|
||||
|
||||
|
||||
$value = '';
|
||||
|
||||
|
||||
$pattern_array = array(
|
||||
'{first_name}',
|
||||
'{last_name}',
|
||||
@@ -383,38 +384,38 @@ class UM_Shortcodes {
|
||||
'{user_avatar_small}',
|
||||
'{username}',
|
||||
);
|
||||
|
||||
|
||||
$pattern_array = apply_filters('um_allowed_user_tags_patterns', $pattern_array);
|
||||
|
||||
|
||||
$matches = false;
|
||||
foreach ( $pattern_array as $pattern ) {
|
||||
|
||||
|
||||
if (preg_match($pattern, $str)) {
|
||||
|
||||
|
||||
$usermeta = str_replace('{','',$pattern);
|
||||
$usermeta = str_replace('}','',$usermeta);
|
||||
|
||||
|
||||
if ( $usermeta == 'user_avatar_small' ) {
|
||||
$value = get_avatar( um_user('ID'), 40 );
|
||||
} elseif ( um_user( $usermeta ) ){
|
||||
$value = um_user( $usermeta );
|
||||
}
|
||||
|
||||
|
||||
if ( $usermeta == 'username' ) {
|
||||
$value = um_user('user_login');
|
||||
}
|
||||
|
||||
|
||||
$value = apply_filters("um_profile_tag_hook__{$usermeta}", $value, um_user('ID') );
|
||||
|
||||
|
||||
if ( $value ) {
|
||||
$str = preg_replace('/'.$pattern.'/', $value , $str );
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user