- fixed user registration;

- phpDoc;
This commit is contained in:
nikitozzzzzzz
2018-03-20 13:24:38 +02:00
parent a85c8741b0
commit 2ce33098b5
54 changed files with 15292 additions and 14163 deletions
@@ -1289,6 +1289,7 @@ foreach ( $member_directories as $directory_id ) {
/**
* Transferring email templates to new logic
*/
$templates_in_theme = 0;
$emails = UM()->config()->email_notifications;
foreach ( $emails as $email_key => $value ) {
@@ -1313,11 +1314,19 @@ foreach ( $emails as $email_key => $value ) {
$fp = fopen( $theme_template_path, "w" );
$result = fputs( $fp, $setting_value );
fclose( $fp );
$templates_in_theme++;
}
}
}
}
if ( $templates_in_theme > 0 ) {
UM()->options()->update( 'email_html', true );
} else {
UM()->options()->update( 'email_html', false );
}
/**
* Transferring menu restriction data
+402 -401
View File
@@ -5,8 +5,15 @@ namespace um\core;
if ( ! defined( 'ABSPATH' ) ) exit;
if ( ! class_exists( 'Access' ) ) {
/**
* Class Access
* @package um\core
*/
class Access {
/**
* If true then we use individual restrict content options
* for post
@@ -44,9 +51,6 @@ if ( ! class_exists( 'Access' ) ) {
$this->redirect_handler = false;
$this->allow_access = false;
//there is posts (Posts/Page/CPT) filtration if site is accessible
//there also will be redirects if they need
//protect posts types
@@ -352,8 +356,8 @@ if ( ! class_exists( 'Access' ) ) {
//also skip if we currently at UM Register|Login|Reset Password pages
if ( um_is_core_post( $post, 'register' ) ||
um_is_core_post( $post, 'password-reset' ) ||
um_is_core_post( $post, 'login' ) )
um_is_core_post( $post, 'password-reset' ) ||
um_is_core_post( $post, 'login' ) )
return;
/**
@@ -466,416 +470,415 @@ if ( ! class_exists( 'Access' ) ) {
}
/**
* User can some of the roles array
* Restrict content new logic
*
* @param $user_id
* @param $roles
* @return bool
*/
function user_can( $user_id, $roles ) {
/**
* User can some of the roles array
* Restrict content new logic
*
* @param $user_id
* @param $roles
* @return bool
*/
function user_can( $user_id, $roles ) {
$user_can = false;
$user_can = false;
if ( ! empty( $roles ) ) {
foreach ( $roles as $key => $value ) {
if ( ! empty( $value ) && user_can( $user_id, $key ) ) {
$user_can = true;
}
}
}
if ( ! empty( $roles ) ) {
foreach ( $roles as $key => $value ) {
if ( ! empty( $value ) && user_can( $user_id, $key ) ) {
$user_can = true;
}
}
}
return $user_can;
}
return $user_can;
}
/**
* Get privacy settings for post
* return false if post is not private
* Restrict content new logic
*
* @param $post
* @return bool|array
*/
function get_post_privacy_settings( $post ) {
//if logged in administrator all pages are visible
if ( current_user_can( 'administrator' ) )
return false;
/**
* Get privacy settings for post
* return false if post is not private
* Restrict content new logic
*
* @param $post
* @return bool|array
*/
function get_post_privacy_settings( $post ) {
//if logged in administrator all pages are visible
if ( current_user_can( 'administrator' ) )
return false;
//exlude from privacy UM default pages (except Members list and User(Profile) page)
if ( ! empty( $post->post_type ) && $post->post_type == 'page' ) {
if ( um_is_core_post( $post, 'login' ) || um_is_core_post( $post, 'register' ) ||
um_is_core_post( $post, 'account' ) || um_is_core_post( $post, 'logout' ) ||
um_is_core_post( $post, 'password-reset' ) )
return false;
}
//exlude from privacy UM default pages (except Members list and User(Profile) page)
if ( ! empty( $post->post_type ) && $post->post_type == 'page' ) {
if ( um_is_core_post( $post, 'login' ) || um_is_core_post( $post, 'register' ) ||
um_is_core_post( $post, 'account' ) || um_is_core_post( $post, 'logout' ) ||
um_is_core_post( $post, 'password-reset' ) )
return false;
}
$restricted_posts = UM()->options()->get( 'restricted_access_post_metabox' );
$restricted_posts = UM()->options()->get( 'restricted_access_post_metabox' );
if ( ! empty( $post->post_type ) && ! empty( $restricted_posts[ $post->post_type ] ) ) {
$restriction = get_post_meta( $post->ID, 'um_content_restriction', true );
if ( ! empty( $post->post_type ) && ! empty( $restricted_posts[ $post->post_type ] ) ) {
$restriction = get_post_meta( $post->ID, 'um_content_restriction', true );
if ( ! empty( $restriction['_um_custom_access_settings'] ) ) {
if ( ! isset( $restriction['_um_accessible'] ) || '0' == $restriction['_um_accessible'] )
return false;
else
return $restriction;
}
}
if ( ! empty( $restriction['_um_custom_access_settings'] ) ) {
if ( ! isset( $restriction['_um_accessible'] ) || '0' == $restriction['_um_accessible'] )
return false;
else
return $restriction;
}
}
//post hasn't privacy settings....check all terms of this post
$restricted_taxonomies = UM()->options()->get( 'restricted_access_taxonomy_metabox' );
//post hasn't privacy settings....check all terms of this post
$restricted_taxonomies = UM()->options()->get( 'restricted_access_taxonomy_metabox' );
//get all taxonomies for current post type
$taxonomies = get_object_taxonomies( $post );
//get all taxonomies for current post type
$taxonomies = get_object_taxonomies( $post );
//get all post terms
$terms = array();
if ( ! empty( $taxonomies ) ) {
foreach ( $taxonomies as $taxonomy ) {
if ( empty( $restricted_taxonomies[$taxonomy] ) )
continue;
//get all post terms
$terms = array();
if ( ! empty( $taxonomies ) ) {
foreach ( $taxonomies as $taxonomy ) {
if ( empty( $restricted_taxonomies[$taxonomy] ) )
continue;
$terms = array_merge( $terms, wp_get_post_terms( $post->ID, $taxonomy, array( 'fields' => 'ids' ) ) );
}
}
$terms = array_merge( $terms, wp_get_post_terms( $post->ID, $taxonomy, array( 'fields' => 'ids' ) ) );
}
}
//get restriction options for first term with privacy settigns
foreach ( $terms as $term_id ) {
$restriction = get_term_meta( $term_id, 'um_content_restriction', true );
//get restriction options for first term with privacy settigns
foreach ( $terms as $term_id ) {
$restriction = get_term_meta( $term_id, 'um_content_restriction', true );
if ( ! empty( $restriction['_um_custom_access_settings'] ) ) {
if ( ! isset( $restriction['_um_accessible'] ) || '0' == $restriction['_um_accessible'] )
continue;
else
return $restriction;
}
}
if ( ! empty( $restriction['_um_custom_access_settings'] ) ) {
if ( ! isset( $restriction['_um_accessible'] ) || '0' == $restriction['_um_accessible'] )
continue;
else
return $restriction;
}
}
//post is public
return false;
}
//post is public
return false;
}
/**
* Protect Post Types in query
* Restrict content new logic
*
* @param $posts
* @param $query
* @return array
*/
function filter_protected_posts( $posts, $query ) {
$filtered_posts = array();
/**
* Protect Post Types in query
* Restrict content new logic
*
* @param $posts
* @param $query
* @return array
*/
function filter_protected_posts( $posts, $query ) {
$filtered_posts = array();
//if empty
if ( empty( $posts ) )
return $posts;
//if empty
if ( empty( $posts ) )
return $posts;
$restricted_global_message = UM()->options()->get( 'restricted_access_message' );
$restricted_global_message = UM()->options()->get( 'restricted_access_message' );
//other filter
foreach ( $posts as $post ) {
$restriction = $this->get_post_privacy_settings( $post );
//other filter
foreach ( $posts as $post ) {
$restriction = $this->get_post_privacy_settings( $post );
if ( ! $restriction ) {
$filtered_posts[] = $post;
continue;
}
//post is private
if ( '0' == $restriction['_um_accessible'] ) {
if ( ! $restriction ) {
$filtered_posts[] = $post;
continue;
} elseif ( '1' == $restriction['_um_accessible'] ) {
//if post for not logged in users and user is not logged in
if ( ! is_user_logged_in() ) {
$filtered_posts[] = $post;
continue;
} else {
}
if ( current_user_can( 'administrator' ) ) {
$filtered_posts[] = $post;
continue;
}
//post is private
if ( '0' == $restriction['_um_accessible'] ) {
$filtered_posts[] = $post;
continue;
} elseif ( '1' == $restriction['_um_accessible'] ) {
//if post for not logged in users and user is not logged in
if ( ! is_user_logged_in() ) {
$filtered_posts[] = $post;
continue;
} else {
if ( empty( $query->is_singular ) ) {
//if not single query when exclude if set _um_access_hide_from_queries
if ( empty( $restriction['_um_access_hide_from_queries'] ) ) {
if ( current_user_can( 'administrator' ) ) {
$filtered_posts[] = $post;
continue;
}
if ( ! isset( $restriction['_um_noaccess_action'] ) || '0' == $restriction['_um_noaccess_action'] ) {
if ( empty( $query->is_singular ) ) {
//if not single query when exclude if set _um_access_hide_from_queries
if ( empty( $restriction['_um_access_hide_from_queries'] ) ) {
if ( ! isset( $restriction['_um_restrict_by_custom_message'] ) || '0' == $restriction['_um_restrict_by_custom_message'] ) {
$post->post_content = stripslashes( $restricted_global_message );
} elseif ( '1' == $restriction['_um_restrict_by_custom_message'] ) {
$post->post_content = ! empty( $restriction['_um_restrict_custom_message'] ) ? stripslashes( $restriction['_um_restrict_custom_message'] ) : '';
}
if ( ! isset( $restriction['_um_noaccess_action'] ) || '0' == $restriction['_um_noaccess_action'] ) {
}
if ( ! isset( $restriction['_um_restrict_by_custom_message'] ) || '0' == $restriction['_um_restrict_by_custom_message'] ) {
$post->post_content = stripslashes( $restricted_global_message );
} elseif ( '1' == $restriction['_um_restrict_by_custom_message'] ) {
$post->post_content = ! empty( $restriction['_um_restrict_custom_message'] ) ? stripslashes( $restriction['_um_restrict_custom_message'] ) : '';
}
$filtered_posts[] = $post;
continue;
}
} else {
$this->singular_page = true;
}
//if single post query
if ( ! isset( $restriction['_um_noaccess_action'] ) || '0' == $restriction['_um_noaccess_action'] ) {
$filtered_posts[] = $post;
continue;
}
} else {
$this->singular_page = true;
if ( ! isset( $restriction['_um_restrict_by_custom_message'] ) || '0' == $restriction['_um_restrict_by_custom_message'] ) {
$post->post_content = stripslashes( $restricted_global_message );
} elseif ( '1' == $restriction['_um_restrict_by_custom_message'] ) {
$post->post_content = ! empty( $restriction['_um_restrict_custom_message'] ) ? stripslashes( $restriction['_um_restrict_custom_message'] ) : '';
}
//if single post query
if ( ! isset( $restriction['_um_noaccess_action'] ) || '0' == $restriction['_um_noaccess_action'] ) {
$this->current_single_post = $post;
add_filter( 'the_content', array( &$this, 'replace_post_content' ), 9999, 1 );
if ( ! isset( $restriction['_um_restrict_by_custom_message'] ) || '0' == $restriction['_um_restrict_by_custom_message'] ) {
$post->post_content = stripslashes( $restricted_global_message );
} elseif ( '1' == $restriction['_um_restrict_by_custom_message'] ) {
$post->post_content = ! empty( $restriction['_um_restrict_custom_message'] ) ? stripslashes( $restriction['_um_restrict_custom_message'] ) : '';
}
/**
* UM hook
*
* @type action
* @title um_access_fix_external_post_content
* @description Hook for 3-d party content filtration
* @change_log
* ["Since: 2.0"]
* @usage add_action( 'um_access_fix_external_post_content', 'function_name', 10 );
* @example
* <?php
* add_action( 'um_access_fix_external_post_content', 'my_access_fix_external_post_content', 10 );
* function my_access_fix_external_post_content() {
* // your code here
* }
* ?>
*/
do_action( 'um_access_fix_external_post_content' );
$this->current_single_post = $post;
add_filter( 'the_content', array( &$this, 'replace_post_content' ), 9999, 1 );
$filtered_posts[] = $post;
continue;
} elseif ( '1' == $restriction['_um_noaccess_action'] ) {
$curr = UM()->permalinks()->get_current_url();
/**
* UM hook
*
* @type action
* @title um_access_fix_external_post_content
* @description Hook for 3-d party content filtration
* @change_log
* ["Since: 2.0"]
* @usage add_action( 'um_access_fix_external_post_content', 'function_name', 10 );
* @example
* <?php
* add_action( 'um_access_fix_external_post_content', 'my_access_fix_external_post_content', 10 );
* function my_access_fix_external_post_content() {
* // your code here
* }
* ?>
*/
do_action( 'um_access_fix_external_post_content' );
if ( ! isset( $restriction['_um_access_redirect'] ) || '0' == $restriction['_um_access_redirect'] ) {
$filtered_posts[] = $post;
continue;
} elseif ( '1' == $restriction['_um_noaccess_action'] ) {
$curr = UM()->permalinks()->get_current_url();
exit( wp_redirect( esc_url( add_query_arg( 'redirect_to', urlencode_deep( $curr ), um_get_core_page( 'login' ) ) ) ) );
if ( ! isset( $restriction['_um_access_redirect'] ) || '0' == $restriction['_um_access_redirect'] ) {
} elseif ( '1' == $restriction['_um_access_redirect'] ) {
exit( wp_redirect( esc_url( add_query_arg( 'redirect_to', urlencode_deep( $curr ), um_get_core_page( 'login' ) ) ) ) );
if ( ! empty( $restriction['_um_access_redirect_url'] ) ) {
$redirect = $restriction['_um_access_redirect_url'];
} else {
$redirect = esc_url( add_query_arg( 'redirect_to', urlencode_deep( $curr ), um_get_core_page( 'login' ) ) );
}
} elseif ( '1' == $restriction['_um_access_redirect'] ) {
exit( wp_redirect( $redirect ) );
}
if ( ! empty( $restriction['_um_access_redirect_url'] ) ) {
$redirect = $restriction['_um_access_redirect_url'];
} else {
$redirect = esc_url( add_query_arg( 'redirect_to', urlencode_deep( $curr ), um_get_core_page( 'login' ) ) );
}
}
}
}
} elseif ( '2' == $restriction['_um_accessible'] ) {
//if post for logged in users and user is not logged in
if ( is_user_logged_in() ) {
exit( wp_redirect( $redirect ) );
}
if ( current_user_can( 'administrator' ) ) {
$filtered_posts[] = $post;
continue;
}
}
}
}
} elseif ( '2' == $restriction['_um_accessible'] ) {
//if post for logged in users and user is not logged in
if ( is_user_logged_in() ) {
$custom_restrict = $this->um_custom_restriction( $restriction );
if ( current_user_can( 'administrator' ) ) {
$filtered_posts[] = $post;
continue;
}
if ( empty( $restriction['_um_access_roles'] ) || false === array_search( '1', $restriction['_um_access_roles'] ) ) {
if ( $custom_restrict ) {
$filtered_posts[] = $post;
continue;
}
} else {
$user_can = $this->user_can( get_current_user_id(), $restriction['_um_access_roles'] );
$custom_restrict = $this->um_custom_restriction( $restriction );
if ( isset( $user_can ) && $user_can && $custom_restrict ) {
$filtered_posts[] = $post;
continue;
}
}
if ( empty( $restriction['_um_access_roles'] ) || false === array_search( '1', $restriction['_um_access_roles'] ) ) {
if ( $custom_restrict ) {
$filtered_posts[] = $post;
continue;
}
} else {
$user_can = $this->user_can( get_current_user_id(), $restriction['_um_access_roles'] );
if ( empty( $query->is_singular ) ) {
//if not single query when exclude if set _um_access_hide_from_queries
if ( empty( $restriction['_um_access_hide_from_queries'] ) ) {
if ( isset( $user_can ) && $user_can && $custom_restrict ) {
$filtered_posts[] = $post;
continue;
}
}
if ( ! isset( $restriction['_um_noaccess_action'] ) || '0' == $restriction['_um_noaccess_action'] ) {
if ( empty( $query->is_singular ) ) {
//if not single query when exclude if set _um_access_hide_from_queries
if ( empty( $restriction['_um_access_hide_from_queries'] ) ) {
if ( ! isset( $restriction['_um_restrict_by_custom_message'] ) || '0' == $restriction['_um_restrict_by_custom_message'] ) {
$post->post_content = stripslashes( $restricted_global_message );
} elseif ( '1' == $restriction['_um_restrict_by_custom_message'] ) {
$post->post_content = ! empty( $restriction['_um_restrict_custom_message'] ) ? stripslashes( $restriction['_um_restrict_custom_message'] ) : '';
}
if ( ! isset( $restriction['_um_noaccess_action'] ) || '0' == $restriction['_um_noaccess_action'] ) {
}
if ( ! isset( $restriction['_um_restrict_by_custom_message'] ) || '0' == $restriction['_um_restrict_by_custom_message'] ) {
$post->post_content = stripslashes( $restricted_global_message );
} elseif ( '1' == $restriction['_um_restrict_by_custom_message'] ) {
$post->post_content = ! empty( $restriction['_um_restrict_custom_message'] ) ? stripslashes( $restriction['_um_restrict_custom_message'] ) : '';
}
$filtered_posts[] = $post;
continue;
}
} else {
$this->singular_page = true;
}
//if single post query
if ( ! isset( $restriction['_um_noaccess_action'] ) || '0' == $restriction['_um_noaccess_action'] ) {
$filtered_posts[] = $post;
continue;
}
} else {
$this->singular_page = true;
if ( ! isset( $restriction['_um_restrict_by_custom_message'] ) || '0' == $restriction['_um_restrict_by_custom_message'] ) {
$post->post_content = stripslashes( $restricted_global_message );
//if single post query
if ( ! isset( $restriction['_um_noaccess_action'] ) || '0' == $restriction['_um_noaccess_action'] ) {
$this->current_single_post = $post;
add_filter( 'the_content', array( &$this, 'replace_post_content' ), 9999, 1 );
if ( ! isset( $restriction['_um_restrict_by_custom_message'] ) || '0' == $restriction['_um_restrict_by_custom_message'] ) {
$post->post_content = stripslashes( $restricted_global_message );
if ( 'attachment' == $post->post_type ) {
remove_filter( 'the_content', 'prepend_attachment' );
}
} elseif ( '1' == $restriction['_um_restrict_by_custom_message'] ) {
$post->post_content = ! empty( $restriction['_um_restrict_custom_message'] ) ? stripslashes( $restriction['_um_restrict_custom_message'] ) : '';
$this->current_single_post = $post;
add_filter( 'the_content', array( &$this, 'replace_post_content' ), 9999, 1 );
$this->current_single_post = $post;
add_filter( 'the_content', array( &$this, 'replace_post_content' ), 9999, 1 );
if ( 'attachment' == $post->post_type ) {
remove_filter( 'the_content', 'prepend_attachment' );
}
} elseif ( '1' == $restriction['_um_restrict_by_custom_message'] ) {
$post->post_content = ! empty( $restriction['_um_restrict_custom_message'] ) ? stripslashes( $restriction['_um_restrict_custom_message'] ) : '';
if ( 'attachment' == $post->post_type ) {
remove_filter( 'the_content', 'prepend_attachment' );
}
}
$this->current_single_post = $post;
add_filter( 'the_content', array( &$this, 'replace_post_content' ), 9999, 1 );
/**
* UM hook
*
* @type action
* @title um_access_fix_external_post_content
* @description Hook for 3-d party content filtration
* @change_log
* ["Since: 2.0"]
* @usage add_action( 'um_access_fix_external_post_content', 'function_name', 10 );
* @example
* <?php
* add_action( 'um_access_fix_external_post_content', 'my_access_fix_external_post_content', 10 );
* function my_access_fix_external_post_content() {
* // your code here
* }
* ?>
*/
do_action( 'um_access_fix_external_post_content' );
if ( 'attachment' == $post->post_type ) {
remove_filter( 'the_content', 'prepend_attachment' );
}
}
$filtered_posts[] = $post;
continue;
} elseif ( '1' == $restriction['_um_noaccess_action'] ) {
/**
* UM hook
*
* @type action
* @title um_access_fix_external_post_content
* @description Hook for 3-d party content filtration
* @change_log
* ["Since: 2.0"]
* @usage add_action( 'um_access_fix_external_post_content', 'function_name', 10 );
* @example
* <?php
* add_action( 'um_access_fix_external_post_content', 'my_access_fix_external_post_content', 10 );
* function my_access_fix_external_post_content() {
* // your code here
* }
* ?>
*/
do_action( 'um_access_fix_external_post_content' );
$curr = UM()->permalinks()->get_current_url();
$filtered_posts[] = $post;
continue;
} elseif ( '1' == $restriction['_um_noaccess_action'] ) {
if ( ! isset( $restriction['_um_access_redirect'] ) || '0' == $restriction['_um_access_redirect'] ) {
$curr = UM()->permalinks()->get_current_url();
exit( wp_redirect( esc_url( add_query_arg( 'redirect_to', urlencode_deep( $curr ), um_get_core_page( 'login' ) ) ) ) );
if ( ! isset( $restriction['_um_access_redirect'] ) || '0' == $restriction['_um_access_redirect'] ) {
} elseif ( '1' == $restriction['_um_access_redirect'] ) {
exit( wp_redirect( esc_url( add_query_arg( 'redirect_to', urlencode_deep( $curr ), um_get_core_page( 'login' ) ) ) ) );
if ( ! empty( $restriction['_um_access_redirect_url'] ) ) {
$redirect = $restriction['_um_access_redirect_url'];
} else {
$redirect = esc_url( add_query_arg( 'redirect_to', urlencode_deep( $curr ), um_get_core_page( 'login' ) ) );
}
} elseif ( '1' == $restriction['_um_access_redirect'] ) {
exit( wp_redirect( $redirect ) );
}
if ( ! empty( $restriction['_um_access_redirect_url'] ) ) {
$redirect = $restriction['_um_access_redirect_url'];
} else {
$redirect = esc_url( add_query_arg( 'redirect_to', urlencode_deep( $curr ), um_get_core_page( 'login' ) ) );
}
}
}
exit( wp_redirect( $redirect ) );
}
} else {
if ( empty( $query->is_singular ) ) {
if ( empty( $restriction['_um_access_hide_from_queries'] ) ) {
}
}
if ( ! isset( $restriction['_um_noaccess_action'] ) || '0' == $restriction['_um_noaccess_action'] ) {
} else {
if ( empty( $query->is_singular ) ) {
if ( empty( $restriction['_um_access_hide_from_queries'] ) ) {
if ( ! isset( $restriction['_um_restrict_by_custom_message'] ) || '0' == $restriction['_um_restrict_by_custom_message'] ) {
$post->post_content = stripslashes( $restricted_global_message );
} elseif ( '1' == $restriction['_um_restrict_by_custom_message'] ) {
$post->post_content = ! empty( $restriction['_um_restrict_custom_message'] ) ? stripslashes( $restriction['_um_restrict_custom_message'] ) : '';
}
if ( ! isset( $restriction['_um_noaccess_action'] ) || '0' == $restriction['_um_noaccess_action'] ) {
}
if ( ! isset( $restriction['_um_restrict_by_custom_message'] ) || '0' == $restriction['_um_restrict_by_custom_message'] ) {
$post->post_content = stripslashes( $restricted_global_message );
} elseif ( '1' == $restriction['_um_restrict_by_custom_message'] ) {
$post->post_content = ! empty( $restriction['_um_restrict_custom_message'] ) ? stripslashes( $restriction['_um_restrict_custom_message'] ) : '';
}
$filtered_posts[] = $post;
continue;
}
} else {
$this->singular_page = true;
}
//if single post query
if ( ! isset( $restriction['_um_noaccess_action'] ) || '0' == $restriction['_um_noaccess_action'] ) {
$filtered_posts[] = $post;
continue;
}
} else {
$this->singular_page = true;
if ( ! isset( $restriction['_um_restrict_by_custom_message'] ) || '0' == $restriction['_um_restrict_by_custom_message'] ) {
$post->post_content = stripslashes( $restricted_global_message );
//if single post query
if ( ! isset( $restriction['_um_noaccess_action'] ) || '0' == $restriction['_um_noaccess_action'] ) {
$this->current_single_post = $post;
add_filter( 'the_content', array( &$this, 'replace_post_content' ), 9999, 1 );
if ( ! isset( $restriction['_um_restrict_by_custom_message'] ) || '0' == $restriction['_um_restrict_by_custom_message'] ) {
$post->post_content = stripslashes( $restricted_global_message );
if ( 'attachment' == $post->post_type ) {
remove_filter( 'the_content', 'prepend_attachment' );
}
} elseif ( '1' == $restriction['_um_restrict_by_custom_message'] ) {
$post->post_content = ! empty( $restriction['_um_restrict_custom_message'] ) ? stripslashes( $restriction['_um_restrict_custom_message'] ) : '';
$this->current_single_post = $post;
add_filter( 'the_content', array( &$this, 'replace_post_content' ), 9999, 1 );
$this->current_single_post = $post;
add_filter( 'the_content', array( &$this, 'replace_post_content' ), 9999, 1 );
if ( 'attachment' == $post->post_type ) {
remove_filter( 'the_content', 'prepend_attachment' );
}
} elseif ( '1' == $restriction['_um_restrict_by_custom_message'] ) {
$post->post_content = ! empty( $restriction['_um_restrict_custom_message'] ) ? stripslashes( $restriction['_um_restrict_custom_message'] ) : '';
if ( 'attachment' == $post->post_type ) {
remove_filter( 'the_content', 'prepend_attachment' );
}
}
$this->current_single_post = $post;
add_filter( 'the_content', array( &$this, 'replace_post_content' ), 9999, 1 );
/**
* UM hook
*
* @type action
* @title um_access_fix_external_post_content
* @description Hook for 3-d party content filtration
* @change_log
* ["Since: 2.0"]
* @usage add_action( 'um_access_fix_external_post_content', 'function_name', 10 );
* @example
* <?php
* add_action( 'um_access_fix_external_post_content', 'my_access_fix_external_post_content', 10 );
* function my_access_fix_external_post_content() {
* // your code here
* }
* ?>
*/
do_action( 'um_access_fix_external_post_content' );
if ( 'attachment' == $post->post_type ) {
remove_filter( 'the_content', 'prepend_attachment' );
}
}
$filtered_posts[] = $post;
continue;
} elseif ( '1' == $restriction['_um_noaccess_action'] ) {
/**
* UM hook
*
* @type action
* @title um_access_fix_external_post_content
* @description Hook for 3-d party content filtration
* @change_log
* ["Since: 2.0"]
* @usage add_action( 'um_access_fix_external_post_content', 'function_name', 10 );
* @example
* <?php
* add_action( 'um_access_fix_external_post_content', 'my_access_fix_external_post_content', 10 );
* function my_access_fix_external_post_content() {
* // your code here
* }
* ?>
*/
do_action( 'um_access_fix_external_post_content' );
$curr = UM()->permalinks()->get_current_url();
$filtered_posts[] = $post;
continue;
} elseif ( '1' == $restriction['_um_noaccess_action'] ) {
if ( ! isset( $restriction['_um_access_redirect'] ) || '0' == $restriction['_um_access_redirect'] ) {
$curr = UM()->permalinks()->get_current_url();
exit( wp_redirect( esc_url( add_query_arg( 'redirect_to', urlencode_deep( $curr ), um_get_core_page( 'login' ) ) ) ) );
if ( ! isset( $restriction['_um_access_redirect'] ) || '0' == $restriction['_um_access_redirect'] ) {
} elseif ( '1' == $restriction['_um_access_redirect'] ) {
exit( wp_redirect( esc_url( add_query_arg( 'redirect_to', urlencode_deep( $curr ), um_get_core_page( 'login' ) ) ) ) );
if ( ! empty( $restriction['_um_access_redirect_url'] ) ) {
$redirect = $restriction['_um_access_redirect_url'];
} else {
$redirect = esc_url( add_query_arg( 'redirect_to', urlencode_deep( $curr ), um_get_core_page( 'login' ) ) );
}
} elseif ( '1' == $restriction['_um_access_redirect'] ) {
exit( wp_redirect( $redirect ) );
}
}
}
}
}
}
if ( ! empty( $restriction['_um_access_redirect_url'] ) ) {
$redirect = $restriction['_um_access_redirect_url'];
} else {
$redirect = esc_url( add_query_arg( 'redirect_to', urlencode_deep( $curr ), um_get_core_page( 'login' ) ) );
}
return $filtered_posts;
}
exit( wp_redirect( $redirect ) );
}
}
}
}
}
}
return $filtered_posts;
}
/**
@@ -885,92 +888,90 @@ if ( ! class_exists( 'Access' ) ) {
*/
function replace_post_content( $content ) {
$content = $this->current_single_post->post_content;
return $content;
}
/**
* Protect Post Types in menu query
* Restrict content new logic
* @param $menu_items
* @param $args
* @return array
*/
function filter_menu( $menu_items, $args ) {
//if empty
if ( empty( $menu_items ) )
return $menu_items;
/**
* Protect Post Types in menu query
* Restrict content new logic
* @param $menu_items
* @param $args
* @return array
*/
function filter_menu( $menu_items, $args ) {
//if empty
if ( empty( $menu_items ) )
return $menu_items;
$filtered_items = array();
$filtered_items = array();
//other filter
foreach ( $menu_items as $menu_item ) {
//other filter
foreach ( $menu_items as $menu_item ) {
if ( ! empty( $menu_item->object_id ) && ! empty( $menu_item->object ) ) {
if ( ! empty( $menu_item->object_id ) && ! empty( $menu_item->object ) ) {
$restriction = $this->get_post_privacy_settings( get_post( $menu_item->object_id ) );
if ( ! $restriction ) {
$filtered_items[] = $menu_item;
continue;
}
$restriction = $this->get_post_privacy_settings( get_post( $menu_item->object_id ) );
if ( ! $restriction ) {
$filtered_items[] = $menu_item;
continue;
}
//post is private
if ( '1' == $restriction['_um_accessible'] ) {
//if post for not logged in users and user is not logged in
if ( ! is_user_logged_in() ) {
$filtered_items[] = $menu_item;
continue;
} else {
//if not single query when exclude if set _um_access_hide_from_queries
if ( empty( $restriction['_um_access_hide_from_queries'] ) ) {
$filtered_items[] = $menu_item;
continue;
}
}
} elseif ( '2' == $restriction['_um_accessible'] ) {
//if post for logged in users and user is not logged in
if ( is_user_logged_in() ) {
//post is private
if ( '1' == $restriction['_um_accessible'] ) {
//if post for not logged in users and user is not logged in
if ( ! is_user_logged_in() ) {
$filtered_items[] = $menu_item;
continue;
} else {
//if not single query when exclude if set _um_access_hide_from_queries
if ( empty( $restriction['_um_access_hide_from_queries'] ) ) {
$filtered_items[] = $menu_item;
continue;
}
}
} elseif ( '2' == $restriction['_um_accessible'] ) {
//if post for logged in users and user is not logged in
if ( is_user_logged_in() ) {
$custom_restrict = $this->um_custom_restriction( $restriction );
$custom_restrict = $this->um_custom_restriction( $restriction );
if ( empty( $restriction['_um_access_roles'] ) || false === array_search( '1', $restriction['_um_access_roles'] ) ) {
if ( $custom_restrict ) {
$filtered_items[] = $menu_item;
continue;
}
} else {
$user_can = $this->user_can( get_current_user_id(), $restriction['_um_access_roles'] );
if ( empty( $restriction['_um_access_roles'] ) || false === array_search( '1', $restriction['_um_access_roles'] ) ) {
if ( $custom_restrict ) {
$filtered_items[] = $menu_item;
continue;
}
} else {
$user_can = $this->user_can( get_current_user_id(), $restriction['_um_access_roles'] );
if ( isset( $user_can ) && $user_can && $custom_restrict ) {
$filtered_items[] = $menu_item;
continue;
}
}
if ( isset( $user_can ) && $user_can && $custom_restrict ) {
$filtered_items[] = $menu_item;
continue;
}
}
//if not single query when exclude if set _um_access_hide_from_queries
if ( empty( $restriction['_um_access_hide_from_queries'] ) ) {
$filtered_items[] = $menu_item;
continue;
}
//if not single query when exclude if set _um_access_hide_from_queries
if ( empty( $restriction['_um_access_hide_from_queries'] ) ) {
$filtered_items[] = $menu_item;
continue;
}
} else {
if ( empty( $restriction['_um_access_hide_from_queries'] ) ) {
$filtered_items[] = $menu_item;
continue;
}
}
}
} else {
if ( empty( $restriction['_um_access_hide_from_queries'] ) ) {
$filtered_items[] = $menu_item;
continue;
}
}
}
continue;
}
continue;
}
//add all other posts
$filtered_items[] = $menu_item;
//add all other posts
$filtered_items[] = $menu_item;
}
}
return $filtered_items;
}
}
return $filtered_items;
}
}
}
File diff suppressed because it is too large Load Diff
+42 -35
View File
@@ -5,43 +5,50 @@ namespace um\core;
if ( ! defined( 'ABSPATH' ) ) exit;
if ( ! class_exists( 'AJAX_Common' ) ) {
class AJAX_Common {
/**
* AJAX_Common constructor.
*/
function __construct() {
// UM_EVENT => nopriv
$ajax_actions = array(
'router' => false
);
foreach ( $ajax_actions as $action => $nopriv ) {
add_action( 'wp_ajax_um_' . $action, array( $this, $action ) );
if ( $nopriv )
add_action( 'wp_ajax_nopriv_um_' . $action, array( $this, $action ) );
}
/**
* Fallback for ajax urls
* @uses action hooks: wp_head, admin_head
*/
//add_action( 'wp_head', array( $this, 'ultimatemember_ajax_urls' ) );
//add_action( 'admin_head', array( $this, 'ultimatemember_ajax_urls' ) );
}
/**
* Class AJAX_Common
* @package um\core
*/
class AJAX_Common {
/**
* Router method
*/
function router() {
$router = new Router();
$router->backend_requests();
}
}
/**
* AJAX_Common constructor.
*/
function __construct() {
// UM_EVENT => nopriv
$ajax_actions = array(
'router' => false
);
foreach ( $ajax_actions as $action => $nopriv ) {
add_action( 'wp_ajax_um_' . $action, array( $this, $action ) );
if ( $nopriv )
add_action( 'wp_ajax_nopriv_um_' . $action, array( $this, $action ) );
}
/**
* Fallback for ajax urls
* @uses action hooks: wp_head, admin_head
*/
//add_action( 'wp_head', array( $this, 'ultimatemember_ajax_urls' ) );
//add_action( 'admin_head', array( $this, 'ultimatemember_ajax_urls' ) );
}
/**
* Router method
*/
function router() {
$router = new Router();
$router->backend_requests();
}
}
}
File diff suppressed because it is too large Load Diff
+117 -96
View File
@@ -5,131 +5,152 @@ namespace um\core;
if ( ! defined( 'ABSPATH' ) ) exit;
if ( ! class_exists( 'Chart' ) ) {
class Chart {
function __construct() {
}
/**
* Class Chart
* @package um\core
*/
class Chart {
/***
*** @Create a new chart
***/
function create( $args=array() ){
$defaults = array(
'id' => 0,
'type' => 'LineChart',
'data' => null,
'x_label' => null,
'y_label' => null,
'vertical_max_lines' => 6,
'colors' => '#0085ba',
'backgroundcolor' => 'transparent',
'basetextcolor' => '#666',
'basebordercolor' => '#bbb',
'days' => 30
);
/**
* Chart constructor.
*/
function __construct() {
$args = wp_parse_args( $args, $defaults );
extract($args);
}
if ($type == 'LineChart'){
$this->linechart( $args );
}
}
/**
* Create a new chart
*
* @param array $args
*/
function create( $args = array() ) {
/***
*** @LineChart
***/
function linechart( $args ){
$defaults = array(
'id' => 0,
'type' => 'LineChart',
'data' => null,
'x_label' => null,
'y_label' => null,
'vertical_max_lines' => 6,
'colors' => '#0085ba',
'backgroundcolor' => 'transparent',
'basetextcolor' => '#666',
'basebordercolor' => '#bbb',
'days' => 30
);
extract($args);
$args = wp_parse_args( $args, $defaults );
?>
<script type="text/javascript">
/**
* @var $type
*/
extract( $args );
google.load("visualization", "1", {packages:["corechart"]});
if ( $type == 'LineChart' ) {
$this->linechart( $args );
}
}
function draw_linechart() {
var data = new google.visualization.DataTable();
data.addColumn('string', '<?php echo $x_label; ?>');
data.addColumn('number', '<?php echo $y_label; ?>');
/**
* LineChart
*
* @param $args
*/
function linechart( $args ) {
/**
* @var $x_label
* @var $y_label
* @var $vertical_max_lines
* @var $backgroundcolor
* @var $colors
* @var $basebordercolor
* @var $basetextcolor
* @var $data
* @var $id
*/
extract( $args ); ?>
<?php
<script type="text/javascript">
if (isset($data_y) && !empty($data_y)){
google.load( "visualization", "1", {packages:["corechart"]});
foreach($data_y as $key => $val){
function draw_linechart() {
}
var data = new google.visualization.DataTable();
data.addColumn('string', '<?php echo $x_label; ?>');
data.addColumn('number', '<?php echo $y_label; ?>');
}
<?php /*if ( ! empty( $data_y ) ) {
?>
foreach ( $data_y as $key => $val ) {
var min_data = 0;
var max_data = data.getColumnRange(1).max;
}
var vgrid_count = <?php echo $vertical_max_lines; ?>;
var hgrid_count = Math.floor( data.getNumberOfRows() / 4 );
}*/ ?>
/* Options */
var options = {
backgroundColor: '<?php echo $backgroundcolor; ?>',
colors: ['<?php echo $colors; ?>'],
curveType: 'function',
pointSize: 8,
lineWidth: 4,
vAxis:{
baselineColor: '<?php echo $basebordercolor; ?>',
gridlineColor: '<?php echo $basebordercolor; ?>',
gridlines: {color: 'transparent', count: vgrid_count},
textStyle: {color: '<?php echo $basetextcolor; ?>', fontSize: 12 },
format: '#',
viewWindow: {min: min_data, max: max_data + 10}
},
hAxis:{
textStyle: {color: '<?php echo $basetextcolor; ?>', fontSize: 12, italic: true },
showTextEvery: hgrid_count,
maxAlternation: 1,
maxTextLines: 1
},
legend: {
position: 'top',
alignment: 'start',
textStyle: {color: '<?php echo $basetextcolor; ?>', fontSize: 13}
},
tooltip: {
textStyle: {color: '<?php echo $basetextcolor; ?>', fontSize: 12}
},
chartArea: {
top:50,left:30,width: '95%', 'height' : ( vgrid_count * 50 ) - 100,
backgroundColor: {
stroke: '<?php echo $basebordercolor; ?>',
strokeWidth: 1
}
},
width: '100%',
height: ( vgrid_count * 50 )
};
var min_data = 0;
var max_data = data.getColumnRange(1).max;
var chart = new google.visualization.LineChart(document.getElementById('chart_<?php echo $data . $id; ?>'));
chart.draw(data, options);
var vgrid_count = <?php echo $vertical_max_lines; ?>;
var hgrid_count = Math.floor( data.getNumberOfRows() / 4 );
}
/* Options */
var options = {
backgroundColor: '<?php echo $backgroundcolor; ?>',
colors: ['<?php echo $colors; ?>'],
curveType: 'function',
pointSize: 8,
lineWidth: 4,
vAxis:{
baselineColor: '<?php echo $basebordercolor; ?>',
gridlineColor: '<?php echo $basebordercolor; ?>',
gridlines: {color: 'transparent', count: vgrid_count},
textStyle: {color: '<?php echo $basetextcolor; ?>', fontSize: 12 },
format: '#',
viewWindow: {min: min_data, max: max_data + 10}
},
hAxis:{
textStyle: {color: '<?php echo $basetextcolor; ?>', fontSize: 12, italic: true },
showTextEvery: hgrid_count,
maxAlternation: 1,
maxTextLines: 1
},
legend: {
position: 'top',
alignment: 'start',
textStyle: {color: '<?php echo $basetextcolor; ?>', fontSize: 13}
},
tooltip: {
textStyle: {color: '<?php echo $basetextcolor; ?>', fontSize: 12}
},
chartArea: {
top:50,left:30,width: '95%', 'height' : ( vgrid_count * 50 ) - 100,
backgroundColor: {
stroke: '<?php echo $basebordercolor; ?>',
strokeWidth: 1
}
},
width: '100%',
height: ( vgrid_count * 50 )
};
</script>
var chart = new google.visualization.LineChart( document.getElementById( 'chart_<?php echo $data . $id; ?>' ) );
chart.draw( data, options );
<div id="chart_<?php echo $data . $id; ?>">
}
</div>
</script>
<?php
<div id="chart_<?php echo $data . $id; ?>"></div>
}
<?php
}
}
}
}
+3
View File
@@ -5,12 +5,15 @@ namespace um\core;
if ( ! defined( 'ABSPATH' ) ) exit;
if ( ! class_exists( 'Cron' ) ) {
/**
* Class Cron
* @package um\core
*/
class Cron {
/**
* Cron constructor.
*/
+5 -5
View File
@@ -45,8 +45,8 @@ if ( ! class_exists( 'Enqueue' ) ) {
* ?>
*/
$priority = apply_filters( 'um_core_enqueue_priority', 100 );
add_action( 'wp_enqueue_scripts', array( &$this, 'wp_enqueue_scripts' ), $priority );
}
add_action( 'wp_enqueue_scripts', array( &$this, 'wp_enqueue_scripts' ), $priority );
}
/**
@@ -74,14 +74,14 @@ if ( ! class_exists( 'Enqueue' ) ) {
global $post;
$this->suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG || defined('UM_SCRIPT_DEBUG') ) ? '' : '.min';
$exclude = UM()->options()->get('js_css_exclude');
$exclude = UM()->options()->get( 'js_css_exclude' );
if ( is_array( $exclude ) ) {
array_filter( $exclude );
}
if ( $exclude && !is_admin() && is_array( $exclude ) ) {
$c_url = UM()->permalinks()->get_current_url( get_option('permalink_structure') );
$c_url = UM()->permalinks()->get_current_url( get_option( 'permalink_structure' ) );
foreach( $exclude as $match ) {
if ( ! empty( $c_url ) && strstr( $c_url, untrailingslashit( $match ) ) ) {
@@ -5,8 +5,15 @@ namespace um\core;
if ( ! defined( 'ABSPATH' ) ) exit;
if ( ! class_exists( 'External_Integrations' ) ) {
/**
* Class External_Integrations
* @package um\core
*/
class External_Integrations {
/**
* Access constructor.
*/
+63 -24
View File
@@ -6,17 +6,31 @@ namespace um\core;
if ( ! defined( 'ABSPATH' ) ) exit;
if ( ! class_exists( 'Fields' ) ) {
/**
* Class Fields
* @package um\core
*/
class Fields {
/**
* @var string
*/
var $set_mode = '';
function __construct() {
/**
* Fields constructor.
*/
function __construct() {
$this->editing = false;
$this->viewing = false;
$this->timestamp = current_time( 'timestamp' );
}
/**
* Standard checkbox field
*
@@ -26,16 +40,16 @@ if ( ! class_exists( 'Fields' ) ) {
function checkbox( $id, $title ) {
?>
<div class="um-field um-field-c">
<div class="um-field-area">
<label class="um-field-checkbox active">
<input type="checkbox" name="<?php echo $id; ?>" value="1" checked/><span
class="um-field-checkbox-state"><i
class="um-icon-android-checkbox-outline"></i></span>
<span class="um-field-checkbox-option"> <?php echo $title; ?></span>
</label>
</div>
</div>
<div class="um-field um-field-c">
<div class="um-field-area">
<label class="um-field-checkbox active">
<input type="checkbox" name="<?php echo $id; ?>" value="1" checked/><span
class="um-field-checkbox-state"><i
class="um-icon-android-checkbox-outline"></i></span>
<span class="um-field-checkbox-option"> <?php echo $title; ?></span>
</label>
</div>
</div>
<?php
}
@@ -45,18 +59,21 @@ if ( ! class_exists( 'Fields' ) ) {
* Shows social links
*/
function show_social_urls() {
$social = array();
$fields = UM()->builtin()->all_user_fields;
foreach ($fields as $field => $args) {
if (isset( $args['advanced'] ) && $args['advanced'] == 'social') {
$social[$field] = $args;
foreach ( $fields as $field => $args ) {
if ( isset( $args['advanced'] ) && $args['advanced'] == 'social' ) {
$social[ $field ] = $args;
}
}
foreach ($social as $k => $arr) {
if (um_profile( $k )) { ?>
<a href="<?php echo um_filtered_social_link( $k, $arr['match'] ); ?>"
style="background: <?php echo $arr['color']; ?>;" target="_blank" class="um-tip-n"
title="<?php echo $arr['title']; ?>"><i class="<?php echo $arr['icon']; ?>"></i></a>
foreach ( $social as $k => $arr ) {
if ( um_profile( $k ) ) { ?>
<a href="<?php echo um_filtered_social_link( $k, $arr['match'] ); ?>"
style="background: <?php echo $arr['color']; ?>;" target="_blank" class="um-tip-n"
title="<?php echo $arr['title']; ?>"><i class="<?php echo $arr['icon']; ?>"></i></a>
<?php
}
@@ -85,6 +102,7 @@ if ( ! class_exists( 'Fields' ) ) {
echo '</div>';
}
/**
* Get hidden field
*
@@ -94,7 +112,6 @@ if ( ! class_exists( 'Fields' ) ) {
* @return string
*/
function disabled_hidden_field( $key, $value ) {
return '<input type="hidden" name="' . $key . '" value="' . esc_attr( $value ) . '"/>';
}
@@ -186,6 +203,7 @@ if ( ! class_exists( 'Fields' ) ) {
}
}
/**
* Quickly adds a field from custom fields
*
@@ -218,6 +236,7 @@ if ( ! class_exists( 'Fields' ) ) {
}
}
/**
* Quickly adds a field from pre-defined fields
*
@@ -253,6 +272,7 @@ if ( ! class_exists( 'Fields' ) ) {
}
}
/**
* Duplicates a frield by meta key
*
@@ -290,6 +310,7 @@ if ( ! class_exists( 'Fields' ) ) {
}
/**
* Print field error
*
@@ -317,6 +338,7 @@ if ( ! class_exists( 'Fields' ) ) {
return $output;
}
/**
* Checks if field has a server-side error
*
@@ -328,6 +350,7 @@ if ( ! class_exists( 'Fields' ) ) {
return UM()->form()->has_error( $key );
}
/**
* Returns field error
*
@@ -339,12 +362,13 @@ if ( ! class_exists( 'Fields' ) ) {
return UM()->form()->errors[$key];
}
/**
* Display field label
*
* @param string $label
* @param string $key
* @param data $data
* @param array $data
*
* @return string
*/
@@ -1019,6 +1043,7 @@ if ( ! class_exists( 'Fields' ) ) {
return $value;
}
/**
* Get select options from a callback function
*
@@ -1039,6 +1064,7 @@ if ( ! class_exists( 'Fields' ) ) {
return $arr_options;
}
/**
* Get field type
*
@@ -1054,6 +1080,7 @@ if ( ! class_exists( 'Fields' ) ) {
return '';
}
/**
* Get field label
*
@@ -1089,6 +1116,7 @@ if ( ! class_exists( 'Fields' ) ) {
return __( 'Custom Field', 'ultimate-member' );
}
/**
* Get form fields
*
@@ -1465,6 +1493,11 @@ if ( ! class_exists( 'Fields' ) ) {
}
/**
* @param $option_value
*
* @return mixed|void
*/
function filter_field_non_utf8_value( $option_value ) {
/**
* UM hook
@@ -1688,8 +1721,8 @@ if ( ! class_exists( 'Fields' ) ) {
</div>';
if (!empty( $disabled )) {
$output .= $this->disabled_hidden_field( $field_name, $field_value );
if (!empty( $disabled )) {
$output .= $this->disabled_hidden_field( $field_name, $field_value );
}
if ($this->is_error( $key )) {
@@ -3189,6 +3222,7 @@ if ( ! class_exists( 'Fields' ) ) {
return ( isset ( $results ) ) ? $results : '';
}
/**
* Get fields in group
*
@@ -3375,6 +3409,7 @@ if ( ! class_exists( 'Fields' ) ) {
return $output;
}
/**
* Gets a field in `view mode`
*
@@ -3812,6 +3847,7 @@ if ( ! class_exists( 'Fields' ) ) {
return $output;
}
/**
* Get new row in form
*
@@ -3898,6 +3934,9 @@ if ( ! class_exists( 'Fields' ) ) {
}
/**
*
*/
function do_ajax_action() {
if (!is_user_logged_in() || !current_user_can( 'manage_options' )) die( __( 'Please login as administrator', 'ultimate-member' ) );
+9 -2
View File
@@ -70,6 +70,9 @@ if ( ! class_exists( 'Files' ) ) {
* Remove file by AJAX
*/
function ajax_remove_file() {
/**
* @var $src
*/
extract( $_REQUEST );
$this->delete_file( $src );
}
@@ -226,6 +229,7 @@ if ( ! class_exists( 'Files' ) ) {
}
}
/**
* Setup upload directory
*/
@@ -442,8 +446,6 @@ if ( ! class_exists( 'Files' ) ) {
$info['um_has_copied'] = $has_copied ? 'yes':'no';
}
return $info;
}
@@ -505,6 +507,7 @@ if ( ! class_exists( 'Files' ) ) {
}
/**
* Make a Folder
*
@@ -1215,6 +1218,10 @@ if ( ! class_exists( 'Files' ) ) {
exit;
}
/**
*
*/
function ajax_file_upload(){
$ret['error'] = null;
$ret = array();
+33 -23
View File
@@ -5,39 +5,49 @@ namespace um\core;
if ( ! defined( 'ABSPATH' ) ) exit;
if ( ! class_exists( 'FontIcons' ) ) {
class FontIcons {
function __construct() {
if ( ! get_option( 'um_cache_fonticons' ) ) {
/**
* Class FontIcons
* @package um\core
*/
class FontIcons {
$files['ii'] = um_path . 'assets/css/um-fonticons-ii.css';
$files['fa'] = um_path . 'assets/css/um-fonticons-fa.css';
foreach ( $files as $c => $file ) {
/**
* FontIcons constructor.
*/
function __construct() {
$css = file_get_contents( $file );
if ( ! get_option( 'um_cache_fonticons' ) ) {
if ( $c == 'fa' ) {
preg_match_all('/(um-faicon-.*?)\s?\{/', $css, $matches);
} else {
preg_match_all('/(um-icon-.*?)\s?\{/', $css, $matches);
}
$files['ii'] = um_path . 'assets/css/um-fonticons-ii.css';
$files['fa'] = um_path . 'assets/css/um-fonticons-fa.css';
unset( $matches[1][0] );
foreach ( $matches[1] as $match ) {
$icon = str_replace( ':before', '', $match );
$array[] = $icon;
}
foreach ( $files as $c => $file ) {
}
$css = file_get_contents( $file );
update_option( 'um_cache_fonticons', $array );
}
if ( $c == 'fa' ) {
preg_match_all('/(um-faicon-.*?)\s?\{/', $css, $matches);
} else {
preg_match_all('/(um-icon-.*?)\s?\{/', $css, $matches);
}
$this->all = get_option( 'um_cache_fonticons' );
unset( $matches[1][0] );
foreach ( $matches[1] as $match ) {
$icon = str_replace( ':before', '', $match );
$array[] = $icon;
}
}
}
}
update_option( 'um_cache_fonticons', $array );
}
$this->all = get_option( 'um_cache_fonticons' );
}
}
}
File diff suppressed because it is too large Load Diff
+83 -72
View File
@@ -5,93 +5,104 @@ namespace um\core;
if ( ! defined( 'ABSPATH' ) ) exit;
if ( ! class_exists( 'Logout' ) ) {
class Logout {
function __construct() {
add_action('template_redirect', array(&$this, 'logout_page'), 10000 );
/**
* Class Logout
* @package um\core
*/
class Logout {
}
/***
*** @Logout via logout page
***/
function logout_page() {
/**
* Logout constructor.
*/
function __construct() {
$language_code = '';
$current_page_ID = get_the_ID();
$logout_page_id = UM()->config()->permalinks['logout'];
$trid = 0;
add_action('template_redirect', array(&$this, 'logout_page'), 10000 );
if ( is_home() /*|| is_front_page()*/ ) {
return;
}
}
if ( UM()->external_integrations()->is_wpml_active() ) {
global $sitepress;
$default_lang = $sitepress->get_default_language();
$language_code = $sitepress->get_current_language();
if ( function_exists( 'icl_object_id' ) ) {
$trid = icl_object_id( $current_page_ID, 'page', true, $default_lang );
} else {
$trid = wpml_object_id_filter( $current_page_ID, 'page', true, $default_lang );
}
/**
* Logout via logout page
*/
function logout_page() {
if ( $language_code == $default_lang ) {
$language_code = '';
}
}
$language_code = '';
$current_page_ID = get_the_ID();
$logout_page_id = UM()->config()->permalinks['logout'];
$trid = 0;
if ( um_is_core_page( 'logout' ) || ( $trid > 0 && $trid == $logout_page_id ) ) {
if ( is_home() /*|| is_front_page()*/ ) {
return;
}
if ( is_user_logged_in() ) {
if ( UM()->external_integrations()->is_wpml_active() ) {
global $sitepress;
$default_lang = $sitepress->get_default_language();
$language_code = $sitepress->get_current_language();
if ( isset( $_REQUEST['redirect_to'] ) && $_REQUEST['redirect_to'] !== '' ) {
wp_logout();
session_unset();
exit( wp_redirect( $_REQUEST['redirect_to'] ) );
} else if ( um_user('after_logout') == 'redirect_home' ) {
wp_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
* <?php add_filter( 'um_logout_redirect_url', 'function_name', 10, 2 ); ?>
* @example
* <?php
* add_filter( 'um_logout_redirect_url', 'my_logout_redirect_url', 10, 2 );
* function my_logout_redirect_url( $url, $id ) {
* // your code here
* return $url;
* }
* ?>
*/
$redirect_url = apply_filters( 'um_logout_redirect_url', um_user( 'logout_redirect_url' ), um_user( 'ID' ) );
wp_logout();
session_unset();
exit( wp_redirect( $redirect_url ) );
if ( function_exists( 'icl_object_id' ) ) {
$trid = icl_object_id( $current_page_ID, 'page', true, $default_lang );
} else {
$trid = wpml_object_id_filter( $current_page_ID, 'page', true, $default_lang );
}
}
if ( $language_code == $default_lang ) {
$language_code = '';
}
}
} else {
exit( wp_redirect( home_url( $language_code ) ) );
}
if ( um_is_core_page( 'logout' ) || ( $trid > 0 && $trid == $logout_page_id ) ) {
}
if ( is_user_logged_in() ) {
}
if ( isset( $_REQUEST['redirect_to'] ) && $_REQUEST['redirect_to'] !== '' ) {
wp_logout();
session_unset();
exit( wp_redirect( $_REQUEST['redirect_to'] ) );
} else if ( um_user('after_logout') == 'redirect_home' ) {
wp_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
* <?php add_filter( 'um_logout_redirect_url', 'function_name', 10, 2 ); ?>
* @example
* <?php
* add_filter( 'um_logout_redirect_url', 'my_logout_redirect_url', 10, 2 );
* function my_logout_redirect_url( $url, $id ) {
* // your code here
* return $url;
* }
* ?>
*/
$redirect_url = apply_filters( 'um_logout_redirect_url', um_user( 'logout_redirect_url' ), um_user( 'ID' ) );
wp_logout();
session_unset();
exit( wp_redirect( $redirect_url ) );
}
}
} else {
exit( wp_redirect( home_url( $language_code ) ) );
}
}
}
}
}
+31 -6
View File
@@ -5,20 +5,40 @@ namespace um\core;
if ( ! defined( 'ABSPATH' ) ) exit;
if ( ! class_exists( 'Mail' ) ) {
/**
* Class Mail
* @package um\core
*/
class Mail {
/**
* @var array
*/
var $email_templates = array();
/**
* @var array
*/
var $path_by_slug = array();
function __construct() {
/**
* Mail constructor.
*/
function __construct() {
//mandrill compatibility
add_filter( 'mandrill_nl2br', array( &$this, 'mandrill_nl2br' ) );
add_action( 'plugins_loaded', array( &$this, 'init_paths' ), 99 );
}
/**
* Init paths for email notifications
*/
function init_paths() {
/**
* UM hook
@@ -53,14 +73,12 @@ if ( ! class_exists( 'Mail' ) ) {
* @return bool
*/
function mandrill_nl2br( $nl2br, $message = '' ) {
// text emails
if ( ! UM()->options()->get( 'email_html' ) ) {
$nl2br = true;
}
return $nl2br;
}
@@ -355,6 +373,11 @@ if ( ! class_exists( 'Mail' ) ) {
}
/**
* @param $template_name
*
* @return mixed|void
*/
function get_template_filename( $template_name ) {
/**
* UM hook
@@ -380,6 +403,7 @@ if ( ! class_exists( 'Mail' ) ) {
return apply_filters( 'um_change_email_template_file', $template_name );
}
/**
* Locate a template and return the path for inclusion.
*
@@ -439,13 +463,11 @@ if ( ! class_exists( 'Mail' ) ) {
* @return string
*/
function set_content_type( $content_type ) {
if ( UM()->options()->get( 'email_html' ) ) {
return 'text/html';
} else {
return 'text/plain';
}
}
@@ -488,6 +510,9 @@ if ( ! class_exists( 'Mail' ) ) {
}
/**
* Delete Email Notification Template
*/
function delete_email_template() {
$template = $_POST['email_key'];
File diff suppressed because it is too large Load Diff
+24 -15
View File
@@ -5,25 +5,34 @@ namespace um\core;
if ( ! defined( 'ABSPATH' ) ) exit;
if ( ! class_exists( 'Modal' ) ) {
class Modal {
function __construct() {
add_action('wp_footer', array(&$this, 'load_modal_content'), 9);
/**
* Class Modal
* @package um\core
*/
class Modal {
}
/***
*** @Load modal content
***/
function load_modal_content(){
if ( !is_admin() ) {
foreach( glob( um_path . 'templates/modal/*.php' ) as $modal_content) {
include_once $modal_content;
}
}
/**
* Modal constructor.
*/
function __construct() {
add_action('wp_footer', array(&$this, 'load_modal_content'), 9);
}
}
}
/**
* Load modal content
*/
function load_modal_content(){
if ( !is_admin() ) {
foreach( glob( um_path . 'templates/modal/*.php' ) as $modal_content) {
include_once $modal_content;
}
}
}
}
}
+13 -2
View File
@@ -5,12 +5,23 @@ namespace um\core;
if ( ! defined( 'ABSPATH' ) ) exit;
if ( ! class_exists( 'Options' ) ) {
/**
* Class Options
* @package um\core
*/
class Options {
var $options = array();
/**
* Access constructor.
* @var array
*/
var $options = array();
/**
* Options constructor.
*/
function __construct() {
$this->init_variables();
+332 -299
View File
@@ -5,367 +5,400 @@ namespace um\core;
if ( ! defined( 'ABSPATH' ) ) exit;
if ( ! class_exists( 'Password' ) ) {
class Password {
var $reset_request;
function __construct() {
/**
* Class Password
* @package um\core
*/
class Password {
add_shortcode('ultimatemember_password', array(&$this, 'ultimatemember_password'));
add_action('template_redirect', array(&$this, 'password_reset'), 10001 );
/**
* @var
*/
var $reset_request;
add_action('template_redirect', array(&$this, 'form_init'), 10002);
add_action('init', array(&$this, 'listen_to_password_reset_uri'), 1);
/**
* Password constructor.
*/
function __construct() {
}
add_shortcode('ultimatemember_password', array(&$this, 'ultimatemember_password'));
/***
*** @a listener to password reset uri
***/
function listen_to_password_reset_uri() {
add_action('template_redirect', array(&$this, 'password_reset'), 10001 );
if ( isset($_REQUEST['act']) && $_REQUEST['act'] == 'reset_password' && isset($_REQUEST['hash']) && strlen($_REQUEST['hash']) == 40 &&
isset($_REQUEST['user_id']) && is_numeric($_REQUEST['user_id']) ) {
add_action('template_redirect', array(&$this, 'form_init'), 10002);
$user_id = absint( $_REQUEST['user_id'] );
delete_option( "um_cache_userdata_{$user_id}" );
add_action('init', array(&$this, 'listen_to_password_reset_uri'), 1);
um_fetch_user( $user_id );
}
if ( $_REQUEST['hash'] != um_user('reset_pass_hash') ){
wp_die( __('This is not a valid hash, or it has expired.','ultimate-member') );
}
UM()->user()->profile['reset_pass_hash_token'] = current_time( 'timestamp' );
UM()->user()->update_usermeta_info('reset_pass_hash_token');
/**
* A listener to password reset uri
*/
function listen_to_password_reset_uri() {
$this->change_password = true;
if ( isset($_REQUEST['act']) && $_REQUEST['act'] == 'reset_password' && isset($_REQUEST['hash']) && strlen($_REQUEST['hash']) == 40 &&
isset($_REQUEST['user_id']) && is_numeric($_REQUEST['user_id']) ) {
um_reset_user();
$user_id = absint( $_REQUEST['user_id'] );
delete_option( "um_cache_userdata_{$user_id}" );
}
um_fetch_user( $user_id );
}
if ( $_REQUEST['hash'] != um_user('reset_pass_hash') ){
wp_die( __('This is not a valid hash, or it has expired.','ultimate-member') );
}
/***
*** @reset url
***/
function reset_url(){
if ( !um_user('reset_pass_hash') ) return false;
UM()->user()->profile['reset_pass_hash_token'] = current_time( 'timestamp' );
UM()->user()->update_usermeta_info('reset_pass_hash_token');
$user_id = um_user('ID');
$this->change_password = true;
delete_option( "um_cache_userdata_{$user_id}" );
um_reset_user();
$url = add_query_arg( 'act', 'reset_password', um_get_core_page('password-reset') );
$url = add_query_arg( 'hash', esc_attr( um_user('reset_pass_hash') ), $url );
$url = add_query_arg( 'user_id', esc_attr( um_user('ID') ), $url );
}
return $url;
}
}
/***
*** @we are on password reset page
***/
function password_reset(){
if ( um_is_core_page('password-reset') ) {
/**
* reset url
*
* @return bool|string
*/
function reset_url(){
if ( !um_user('reset_pass_hash') ) return false;
UM()->fields()->set_mode = 'password';
$user_id = um_user('ID');
}
delete_option( "um_cache_userdata_{$user_id}" );
}
$url = add_query_arg( 'act', 'reset_password', um_get_core_page('password-reset') );
$url = add_query_arg( 'hash', esc_attr( um_user('reset_pass_hash') ), $url );
$url = add_query_arg( 'user_id', esc_attr( um_user('ID') ), $url );
/**
* Password page form
*/
function form_init() {
if ( um_requesting_password_reset() ) {
return $url;
UM()->form()->post_form = $_POST;
}
/**
* UM hook
*
* @type action
* @title um_reset_password_errors_hook
* @description Action on reset password submit form
* @input_vars
* [{"var":"$post","type":"array","desc":"Form submitted"}]
* @change_log
* ["Since: 2.0"]
* @usage add_action( 'um_reset_password_errors_hook', 'function_name', 10, 1 );
* @example
* <?php
* add_action( 'um_reset_password_errors_hook', 'my_reset_password_errors', 10, 1 );
* function my_reset_password_errors( $post ) {
* // your code here
* }
* ?>
*/
do_action( 'um_reset_password_errors_hook', UM()->form()->post_form );
if ( ! isset( UM()->form()->errors ) ) {
/**
* we are on password reset page
*/
function password_reset(){
if ( um_is_core_page('password-reset') ) {
/**
* UM hook
*
* @type action
* @title um_reset_password_process_hook
* @description Action on reset password success submit form
* @input_vars
* [{"var":"$post","type":"array","desc":"Form submitted"}]
* @change_log
* ["Since: 2.0"]
* @usage add_action( 'um_reset_password_process_hook', 'function_name', 10, 1 );
* @example
* <?php
* add_action( 'um_reset_password_process_hook', 'my_reset_password_process', 10, 1 );
* function my_reset_password_process( $post ) {
* // your code here
* }
* ?>
*/
do_action( 'um_reset_password_process_hook', UM()->form()->post_form );
UM()->fields()->set_mode = 'password';
}
}
}
}
if ( um_requesting_password_change() ) {
UM()->form()->post_form = $_POST;
/**
* Password page form
*/
function form_init() {
if ( um_requesting_password_reset() ) {
/**
* UM hook
*
* @type action
* @title um_change_password_errors_hook
* @description Action on change password submit form
* @input_vars
* [{"var":"$post","type":"array","desc":"Form submitted"}]
* @change_log
* ["Since: 2.0"]
* @usage add_action( 'um_change_password_errors_hook', 'function_name', 10, 1 );
* @example
* <?php
* add_action( 'um_change_password_errors_hook', 'my_change_password_errors', 10, 1 );
* function my_change_password_errors( $post ) {
* // your code here
* }
* ?>
*/
do_action( 'um_change_password_errors_hook', UM()->form()->post_form );
UM()->form()->post_form = $_POST;
if ( ! isset( UM()->form()->errors ) ) {
/**
* UM hook
*
* @type action
* @title um_reset_password_errors_hook
* @description Action on reset password submit form
* @input_vars
* [{"var":"$post","type":"array","desc":"Form submitted"}]
* @change_log
* ["Since: 2.0"]
* @usage add_action( 'um_reset_password_errors_hook', 'function_name', 10, 1 );
* @example
* <?php
* add_action( 'um_reset_password_errors_hook', 'my_reset_password_errors', 10, 1 );
* function my_reset_password_errors( $post ) {
* // your code here
* }
* ?>
*/
do_action( 'um_reset_password_errors_hook', UM()->form()->post_form );
/**
* UM hook
*
* @type action
* @title um_change_password_process_hook
* @description Action on change password success submit form
* @input_vars
* [{"var":"$post","type":"array","desc":"Form submitted"}]
* @change_log
* ["Since: 2.0"]
* @usage add_action( 'um_change_password_process_hook', 'function_name', 10, 1 );
* @example
* <?php
* add_action( 'um_change_password_process_hook', 'my_change_password_process', 10, 1 );
* function my_change_password_process( $post ) {
* // your code here
* }
* ?>
*/
do_action( 'um_change_password_process_hook', UM()->form()->post_form );
if ( ! isset( UM()->form()->errors ) ) {
}
/**
* UM hook
*
* @type action
* @title um_reset_password_process_hook
* @description Action on reset password success submit form
* @input_vars
* [{"var":"$post","type":"array","desc":"Form submitted"}]
* @change_log
* ["Since: 2.0"]
* @usage add_action( 'um_reset_password_process_hook', 'function_name', 10, 1 );
* @example
* <?php
* add_action( 'um_reset_password_process_hook', 'my_reset_password_process', 10, 1 );
* function my_reset_password_process( $post ) {
* // your code here
* }
* ?>
*/
do_action( 'um_reset_password_process_hook', UM()->form()->post_form );
}
}
}
}
/***
*** @Add class based on shortcode
***/
function get_class( $mode ) {
if ( um_requesting_password_change() ) {
$classes = 'um-'.$mode;
UM()->form()->post_form = $_POST;
if ( is_admin() ) {
$classes .= ' um-in-admin';
}
/**
* UM hook
*
* @type action
* @title um_change_password_errors_hook
* @description Action on change password submit form
* @input_vars
* [{"var":"$post","type":"array","desc":"Form submitted"}]
* @change_log
* ["Since: 2.0"]
* @usage add_action( 'um_change_password_errors_hook', 'function_name', 10, 1 );
* @example
* <?php
* add_action( 'um_change_password_errors_hook', 'my_change_password_errors', 10, 1 );
* function my_change_password_errors( $post ) {
* // your code here
* }
* ?>
*/
do_action( 'um_change_password_errors_hook', UM()->form()->post_form );
if ( UM()->fields()->editing == true ) {
$classes .= ' um-editing';
}
if ( ! isset( UM()->form()->errors ) ) {
if ( UM()->fields()->viewing == true ) {
$classes .= ' um-viewing';
}
/**
* UM hook
*
* @type action
* @title um_change_password_process_hook
* @description Action on change password success submit form
* @input_vars
* [{"var":"$post","type":"array","desc":"Form submitted"}]
* @change_log
* ["Since: 2.0"]
* @usage add_action( 'um_change_password_process_hook', 'function_name', 10, 1 );
* @example
* <?php
* add_action( 'um_change_password_process_hook', 'my_change_password_process', 10, 1 );
* function my_change_password_process( $post ) {
* // your code here
* }
* ?>
*/
do_action( 'um_change_password_process_hook', UM()->form()->post_form );
/**
* UM hook
*
* @type filter
* @title um_form_official_classes__hook
* @description Change form additional classes
* @input_vars
* [{"var":"$classes","type":"string","desc":"Form additional classes"}]
* @change_log
* ["Since: 2.0"]
* @usage
* <?php add_filter( 'um_form_official_classes__hook', 'function_name', 10, 1 ); ?>
* @example
* <?php
* add_filter( 'um_form_official_classes__hook', 'my_form_official_classes', 10, 1 );
* function my_form_official_classes( $classes ) {
* // your code here
* return $classes;
* }
* ?>
*/
$classes = apply_filters( 'um_form_official_classes__hook', $classes );
return $classes;
}
}
/***
*** @Shortcode
***/
function ultimatemember_password( $args = array() ) {
return $this->load( $args );
}
}
/***
*** @Load a module with global function
***/
function load( $args ) {
}
ob_start();
$defaults = array(
'template' => 'password-reset',
'mode' => 'password',
'form_id' => 'um_password_id',
'max_width' => '450px',
'align' => 'center',
);
$args = wp_parse_args( $args, $defaults );
/**
* Add class based on shortcode
*
* @param $mode
*
* @return mixed|string|void
*/
function get_class( $mode ) {
if ( empty( $args['use_custom_settings'] ) ) {
$args = array_merge( $args, UM()->shortcodes()->get_css_args( $args ) );
} else {
$args = array_merge( UM()->shortcodes()->get_css_args( $args ), $args );
}
$classes = 'um-'.$mode;
/**
* UM hook
*
* @type filter
* @title um_reset_password_shortcode_args_filter
* @description Extend Reset Password Arguments
* @input_vars
* [{"var":"$args","type":"array","desc":"Shortcode arguments"}]
* @change_log
* ["Since: 2.0"]
* @usage
* <?php add_filter( 'um_reset_password_shortcode_args_filter', 'function_name', 10, 1 ); ?>
* @example
* <?php
* add_filter( 'um_reset_password_shortcode_args_filter', 'my_reset_password_shortcode_args', 10, 1 );
* function my_reset_password_shortcode_args( $args ) {
* // your code here
* return $args;
* }
* ?>
*/
$args = apply_filters( 'um_reset_password_shortcode_args_filter', $args );
if ( is_admin() ) {
$classes .= ' um-in-admin';
}
if ( isset( $this->change_password ) ) {
if ( UM()->fields()->editing == true ) {
$classes .= ' um-editing';
}
$args['user_id'] = $_REQUEST['user_id'];
$args['template'] = 'password-change';
if ( UM()->fields()->viewing == true ) {
$classes .= ' um-viewing';
}
}
/**
* UM hook
*
* @type filter
* @title um_form_official_classes__hook
* @description Change form additional classes
* @input_vars
* [{"var":"$classes","type":"string","desc":"Form additional classes"}]
* @change_log
* ["Since: 2.0"]
* @usage
* <?php add_filter( 'um_form_official_classes__hook', 'function_name', 10, 1 ); ?>
* @example
* <?php
* add_filter( 'um_form_official_classes__hook', 'my_form_official_classes', 10, 1 );
* function my_form_official_classes( $classes ) {
* // your code here
* return $classes;
* }
* ?>
*/
$classes = apply_filters( 'um_form_official_classes__hook', $classes );
return $classes;
}
extract( $args, EXTR_SKIP );
/**
* Shortcode
*
* @param array $args
*
* @return string
*/
function ultimatemember_password( $args = array() ) {
return $this->load( $args );
}
/**
* UM hook
*
* @type action
* @title um_pre_{$mode}_shortcode
* @description Action pre-load password form shortcode
* @input_vars
* [{"var":"$args","type":"array","desc":"Form shortcode pre-loading"}]
* @change_log
* ["Since: 2.0"]
* @usage add_action( 'um_pre_{$mode}_shortcode', 'function_name', 10, 1 );
* @example
* <?php
* add_action( 'um_pre_{$mode}_shortcode', 'my_pre_password_shortcode', 10, 1 );
* function my_pre_password_shortcode( $args ) {
* // your code here
* }
* ?>
*/
do_action( "um_pre_{$mode}_shortcode", $args );
/**
* UM hook
*
* @type action
* @title um_before_form_is_loaded
* @description Action pre-load password form shortcode
* @input_vars
* [{"var":"$args","type":"array","desc":"Form shortcode pre-loading"}]
* @change_log
* ["Since: 2.0"]
* @usage add_action( 'um_before_form_is_loaded', 'function_name', 10, 1 );
* @example
* <?php
* add_action( 'um_before_form_is_loaded', 'my_before_form_is_loaded', 10, 1 );
* function my_before_form_is_loaded( $args ) {
* // your code here
* }
* ?>
*/
do_action( "um_before_form_is_loaded", $args );
/**
* UM hook
*
* @type action
* @title um_before_{$mode}_form_is_loaded
* @description Action pre-load password form shortcode
* @input_vars
* [{"var":"$args","type":"array","desc":"Form shortcode pre-loading"}]
* @change_log
* ["Since: 2.0"]
* @usage add_action( 'um_before_{$mode}_form_is_loaded', 'function_name', 10, 1 );
* @example
* <?php
* add_action( 'um_before_{$mode}_form_is_loaded', 'my_before_form_is_loaded', 10, 1 );
* function my_before_form_is_loaded( $args ) {
* // your code here
* }
* ?>
*/
do_action( "um_before_{$mode}_form_is_loaded", $args );
/**
* Load a module with global function
*
* @param $args
*
* @return string
*/
function load( $args ) {
UM()->shortcodes()->template_load( $template, $args );
ob_start();
if ( ! is_admin() && ! defined( 'DOING_AJAX' ) ) {
UM()->shortcodes()->dynamic_css( $args );
}
$defaults = array(
'template' => 'password-reset',
'mode' => 'password',
'form_id' => 'um_password_id',
'max_width' => '450px',
'align' => 'center',
);
$args = wp_parse_args( $args, $defaults );
$output = ob_get_contents();
ob_end_clean();
return $output;
if ( empty( $args['use_custom_settings'] ) ) {
$args = array_merge( $args, UM()->shortcodes()->get_css_args( $args ) );
} else {
$args = array_merge( UM()->shortcodes()->get_css_args( $args ), $args );
}
}
/**
* UM hook
*
* @type filter
* @title um_reset_password_shortcode_args_filter
* @description Extend Reset Password Arguments
* @input_vars
* [{"var":"$args","type":"array","desc":"Shortcode arguments"}]
* @change_log
* ["Since: 2.0"]
* @usage
* <?php add_filter( 'um_reset_password_shortcode_args_filter', 'function_name', 10, 1 ); ?>
* @example
* <?php
* add_filter( 'um_reset_password_shortcode_args_filter', 'my_reset_password_shortcode_args', 10, 1 );
* function my_reset_password_shortcode_args( $args ) {
* // your code here
* return $args;
* }
* ?>
*/
$args = apply_filters( 'um_reset_password_shortcode_args_filter', $args );
}
if ( isset( $this->change_password ) ) {
$args['user_id'] = $_REQUEST['user_id'];
$args['template'] = 'password-change';
}
extract( $args, EXTR_SKIP );
/**
* UM hook
*
* @type action
* @title um_pre_{$mode}_shortcode
* @description Action pre-load password form shortcode
* @input_vars
* [{"var":"$args","type":"array","desc":"Form shortcode pre-loading"}]
* @change_log
* ["Since: 2.0"]
* @usage add_action( 'um_pre_{$mode}_shortcode', 'function_name', 10, 1 );
* @example
* <?php
* add_action( 'um_pre_{$mode}_shortcode', 'my_pre_password_shortcode', 10, 1 );
* function my_pre_password_shortcode( $args ) {
* // your code here
* }
* ?>
*/
do_action( "um_pre_{$mode}_shortcode", $args );
/**
* UM hook
*
* @type action
* @title um_before_form_is_loaded
* @description Action pre-load password form shortcode
* @input_vars
* [{"var":"$args","type":"array","desc":"Form shortcode pre-loading"}]
* @change_log
* ["Since: 2.0"]
* @usage add_action( 'um_before_form_is_loaded', 'function_name', 10, 1 );
* @example
* <?php
* add_action( 'um_before_form_is_loaded', 'my_before_form_is_loaded', 10, 1 );
* function my_before_form_is_loaded( $args ) {
* // your code here
* }
* ?>
*/
do_action( "um_before_form_is_loaded", $args );
/**
* UM hook
*
* @type action
* @title um_before_{$mode}_form_is_loaded
* @description Action pre-load password form shortcode
* @input_vars
* [{"var":"$args","type":"array","desc":"Form shortcode pre-loading"}]
* @change_log
* ["Since: 2.0"]
* @usage add_action( 'um_before_{$mode}_form_is_loaded', 'function_name', 10, 1 );
* @example
* <?php
* add_action( 'um_before_{$mode}_form_is_loaded', 'my_before_form_is_loaded', 10, 1 );
* function my_before_form_is_loaded( $args ) {
* // your code here
* }
* ?>
*/
do_action( "um_before_{$mode}_form_is_loaded", $args );
UM()->shortcodes()->template_load( $template, $args );
if ( ! is_admin() && ! defined( 'DOING_AJAX' ) ) {
UM()->shortcodes()->dynamic_css( $args );
}
$output = ob_get_contents();
ob_end_clean();
return $output;
}
}
}
+313 -288
View File
@@ -6,322 +6,347 @@ if ( ! defined( 'ABSPATH' ) ) exit;
if ( ! class_exists( 'Plugin_Updater' ) ) {
class Plugin_Updater {
function __construct() {
//create cron event
if ( ! wp_next_scheduled( 'um_check_extensions_licenses' ) ) {
wp_schedule_event( time() + ( 24*60*60 ), 'daily', 'um_check_extensions_licenses' );
}
register_deactivation_hook( um_plugin, array( &$this, 'um_plugin_updater_deactivation_hook' ) );
//cron request to ultimatemember.com
add_action( 'um_check_extensions_licenses', array( &$this, 'um_checklicenses' ) );
//update plugin info
add_filter( 'pre_set_site_transient_update_plugins', array( &$this, 'um_check_update' ) );
//plugin information info
add_filter( 'plugins_api', array( &$this, 'um_plugins_api_filter' ), 9999, 3 );
}
/**
* Get all paid UM extensions
*
* @return array
*/
function um_get_active_plugins() {
$paid_extensions = array(
'um-bbpress/um-bbpress.php' => array(
'key' => 'bbpress',
'title' => 'bbPress',
),
'um-followers/um-followers.php' => array(
'key' => 'followers',
'title' => 'Followers',
),
'um-friends/um-friends.php' => array(
'key' => 'friends',
'title' => 'Friends',
),
'um-groups/um-groups.php' => array(
'key' => 'groups',
'title' => 'Groups',
),
'um-instagram/um-instagram.php' => array(
'key' => 'instagram',
'title' => 'Instagram',
),
'um-invitations/um-invitations.php' => array(
'key' => 'invitations',
'title' => 'Invitations',
),
'um-mailchimp/um-mailchimp.php' => array(
'key' => 'mailchimp',
'title' => 'MailChimp',
),
'um-messaging/um-messaging.php' => array(
'key' => 'messaging',
'title' => 'Messaging',
),
'um-mycred/um-mycred.php' => array(
'key' => 'mycred',
'title' => 'myCRED',
),
'um-notices/um-notices.php' => array(
'key' => 'notices',
'title' => 'Notices',
),
'um-notifications/um-notifications.php' => array(
'key' => 'notifications',
'title' => 'Notifications',
),
'um-profile-completeness/um-profile-completeness.php' => array(
'key' => 'profile_completeness',
'title' => 'Profile Completeness',
),
'um-reviews/um-reviews.php' => array(
'key' => 'reviews',
'title' => 'Reviews',
),
'um-social-activity/um-social-activity.php' => array(
'key' => 'activity',
'title' => 'Social Activity',
),
'um-social-login/um-social-login.php' => array(
'key' => 'social_login',
'title' => 'Social Login',
),
'um-user-tags/um-user-tags.php' => array(
'key' => 'user_tags',
'title' => 'User Tags',
),
'um-verified-users/um-verified-users.php' => array(
'key' => 'verified_users',
'title' => 'Verified Users',
),
'um-woocommerce/um-woocommerce.php' => array(
'key' => 'woocommerce',
'title' => 'Woocommerce',
),
);
$the_plugs = get_option( 'active_plugins' );
$active_um_plugins = array();
foreach ( $the_plugs as $key => $value ) {
if ( in_array( $value, array_keys( $paid_extensions ) ) ) {
$license = UM()->options()->get( "um_{$paid_extensions[ $value ]['key']}_license_key" );
if ( empty( $license ) )
continue;
$active_um_plugins[ $value ] = $paid_extensions[ $value ];
$active_um_plugins[ $value ]['license'] = $license;
}
}
return $active_um_plugins;
}
/**
* Class Plugin_Updater
* @package um\core
*/
class Plugin_Updater {
function um_plugin_updater_deactivation_hook() {
wp_clear_scheduled_hook( 'um_check_extensions_licenses' );
}
/**
* Plugin_Updater constructor.
*/
function __construct() {
//create cron event
if ( ! wp_next_scheduled( 'um_check_extensions_licenses' ) ) {
wp_schedule_event( time() + ( 24*60*60 ), 'daily', 'um_check_extensions_licenses' );
}
register_deactivation_hook( um_plugin, array( &$this, 'um_plugin_updater_deactivation_hook' ) );
//cron request to ultimatemember.com
add_action( 'um_check_extensions_licenses', array( &$this, 'um_checklicenses' ) );
//update plugin info
add_filter( 'pre_set_site_transient_update_plugins', array( &$this, 'um_check_update' ) );
//plugin information info
add_filter( 'plugins_api', array( &$this, 'um_plugins_api_filter' ), 9999, 3 );
}
function um_checklicenses() {
$exts = $this->um_get_active_plugins();
/**
* Get all paid UM extensions
*
* @return array
*/
function um_get_active_plugins() {
$paid_extensions = array(
'um-bbpress/um-bbpress.php' => array(
'key' => 'bbpress',
'title' => 'bbPress',
),
'um-followers/um-followers.php' => array(
'key' => 'followers',
'title' => 'Followers',
),
'um-friends/um-friends.php' => array(
'key' => 'friends',
'title' => 'Friends',
),
'um-groups/um-groups.php' => array(
'key' => 'groups',
'title' => 'Groups',
),
'um-instagram/um-instagram.php' => array(
'key' => 'instagram',
'title' => 'Instagram',
),
'um-invitations/um-invitations.php' => array(
'key' => 'invitations',
'title' => 'Invitations',
),
'um-mailchimp/um-mailchimp.php' => array(
'key' => 'mailchimp',
'title' => 'MailChimp',
),
'um-messaging/um-messaging.php' => array(
'key' => 'messaging',
'title' => 'Messaging',
),
'um-mycred/um-mycred.php' => array(
'key' => 'mycred',
'title' => 'myCRED',
),
'um-notices/um-notices.php' => array(
'key' => 'notices',
'title' => 'Notices',
),
'um-notifications/um-notifications.php' => array(
'key' => 'notifications',
'title' => 'Notifications',
),
'um-profile-completeness/um-profile-completeness.php' => array(
'key' => 'profile_completeness',
'title' => 'Profile Completeness',
),
'um-reviews/um-reviews.php' => array(
'key' => 'reviews',
'title' => 'Reviews',
),
'um-social-activity/um-social-activity.php' => array(
'key' => 'activity',
'title' => 'Social Activity',
),
'um-social-login/um-social-login.php' => array(
'key' => 'social_login',
'title' => 'Social Login',
),
'um-user-tags/um-user-tags.php' => array(
'key' => 'user_tags',
'title' => 'User Tags',
),
'um-verified-users/um-verified-users.php' => array(
'key' => 'verified_users',
'title' => 'Verified Users',
),
'um-woocommerce/um-woocommerce.php' => array(
'key' => 'woocommerce',
'title' => 'Woocommerce',
),
);
if ( 0 == count( $exts ) )
return;
$the_plugs = get_option( 'active_plugins' );
$active_um_plugins = array();
foreach ( $the_plugs as $key => $value ) {
require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
if ( in_array( $value, array_keys( $paid_extensions ) ) ) {
$license = UM()->options()->get( "um_{$paid_extensions[ $value ]['key']}_license_key" );
$api_params = array(
'edd_action' => 'check_licenses',
'author' => 'Ultimate Member',
'url' => home_url(),
);
if ( empty( $license ) )
continue;
$api_params['active_extensions'] = array();
foreach ( $exts as $slug => $data ) {
$plugin_data = get_plugin_data( ABSPATH . "wp-content/plugins/{$slug}" );
$active_um_plugins[ $value ] = $paid_extensions[ $value ];
$active_um_plugins[ $value ]['license'] = $license;
}
}
$api_params['active_extensions'][$slug] = array(
'slug' => $slug,
'license' => $data['license'],
'item_name' => str_replace( 'Ultimate Member - ', '', $plugin_data['Name'] ),
'version' => $plugin_data['Version']
);
}
$request = wp_remote_post(
'https://ultimatemember.com/',
array(
'timeout' => 15,
'sslverify' => false,
'body' => $api_params
)
);
if ( ! is_wp_error( $request ) )
$request = json_decode( wp_remote_retrieve_body( $request ) );
$request = ( $request ) ? maybe_unserialize( $request ) : false;
if ( $request ) {
foreach ( $exts as $slug => $data ) {
if ( ! empty( $request->$slug->license_check ) )
update_option( "{$data['key']}_edd_answer", $request->$slug->license_check );
if ( ! empty( $request->$slug->get_version_check ) ) {
$request->$slug->get_version_check = json_decode( $request->$slug->get_version_check );
if ( ! empty( $request->$slug->get_version_check->package ) )
$request->$slug->get_version_check->package = $this->extend_download_url( $request->$slug->get_version_check->package, $slug, $data );
if ( ! empty( $request->$slug->get_version_check->download_link ) )
$request->$slug->get_version_check->download_link = $this->extend_download_url( $request->$slug->get_version_check->download_link, $slug, $data );
if ( isset( $request->$slug->get_version_check->sections ) ) {
$request->$slug->get_version_check->sections = maybe_unserialize( $request->$slug->get_version_check->sections );
$request->$slug->get_version_check = json_encode( $request->$slug->get_version_check );
} else {
$request->$slug->get_version_check = new \WP_Error( 'plugins_api_failed',
sprintf(
/* translators: %s: support forums URL */
__( 'An unexpected error occurred. Something may be wrong with https://ultimatemember.com/ or this server&#8217;s configuration. If you continue to have problems, please try the <a href="%s">support forums</a>.' ),
__( 'https://wordpress.org/support/' )
),
wp_remote_retrieve_body( $request->$slug->get_version_check )
);
}
update_option( "{$data['key']}_version_check_edd_answer", $request->$slug->get_version_check );
}
}
}
return;
}
return $active_um_plugins;
}
/**
* Check for Updates by request to the marketplace
* and modify the update array.
*
* @param array $_transient_data plugin update array build by WordPress.
* @return \stdClass modified plugin update array.
*/
function um_check_update( $_transient_data ) {
global $pagenow;
if ( ! is_object( $_transient_data ) )
$_transient_data = new \stdClass;
if ( 'plugins.php' == $pagenow && is_multisite() )
return $_transient_data;
$exts = $this->um_get_active_plugins();
foreach ( $exts as $slug => $data ) {
$plugin_data = get_plugin_data( ABSPATH . "wp-content/plugins/{$slug}" );
//if response for current product isn't empty check for override
if ( ! empty( $_transient_data->response ) && ! empty( $_transient_data->response[ $slug ] ) )
continue;
$version_info = get_option( "{$data['key']}_version_check_edd_answer" );
$version_info = json_decode( $version_info );
if ( false !== $version_info && is_object( $version_info ) && isset( $version_info->new_version ) ) {
//show update version block if new version > then current
if ( version_compare( $plugin_data['Version'], $version_info->new_version, '<' ) )
$_transient_data->response[ $slug ] = $version_info;
$_transient_data->last_checked = time();
$_transient_data->checked[ $slug ] = $plugin_data['Version'];
}
}
return $_transient_data;
}
/**
* Remove CRON events on deactivation hook
*/
function um_plugin_updater_deactivation_hook() {
wp_clear_scheduled_hook( 'um_check_extensions_licenses' );
}
/**
* Updates information on the "View version x.x details" popup with custom data.
*
* @param mixed $_data
* @param string $_action
* @param object $_args
* @return object $_data
*/
function um_plugins_api_filter( $_data, $_action = '', $_args = null ) {
//by default $data = false (from Wordpress)
/**
* Check license function
*/
function um_checklicenses() {
$exts = $this->um_get_active_plugins();
if ( $_action != 'plugin_information' )
return $_data;
if ( 0 == count( $exts ) )
return;
$exts = $this->um_get_active_plugins();
require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
foreach ( $exts as $slug => $data ) {
if ( isset( $_args->slug ) && $_args->slug == $slug )
$api_request_transient = get_option( "{$data['key']}_version_check_edd_answer" );
}
$api_params = array(
'edd_action' => 'check_licenses',
'author' => 'Ultimate Member',
'url' => home_url(),
);
//If we have no transient-saved value, run the API, set a fresh transient with the API value, and return that value too right now.
if ( ! empty( $api_request_transient ) ) {
$_data = json_decode( $api_request_transient );
}
$api_params['active_extensions'] = array();
foreach ( $exts as $slug => $data ) {
$plugin_data = get_plugin_data( ABSPATH . "wp-content/plugins/{$slug}" );
if ( isset( $_data->sections ) )
$_data->sections = (array)$_data->sections;
$api_params['active_extensions'][$slug] = array(
'slug' => $slug,
'license' => $data['license'],
'item_name' => str_replace( 'Ultimate Member - ', '', $plugin_data['Name'] ),
'version' => $plugin_data['Version']
);
}
return $_data;
}
$request = wp_remote_post(
'https://ultimatemember.com/',
array(
'timeout' => 15,
'sslverify' => false,
'body' => $api_params
)
);
if ( ! is_wp_error( $request ) )
$request = json_decode( wp_remote_retrieve_body( $request ) );
$request = ( $request ) ? maybe_unserialize( $request ) : false;
if ( $request ) {
foreach ( $exts as $slug => $data ) {
if ( ! empty( $request->$slug->license_check ) )
update_option( "{$data['key']}_edd_answer", $request->$slug->license_check );
if ( ! empty( $request->$slug->get_version_check ) ) {
$request->$slug->get_version_check = json_decode( $request->$slug->get_version_check );
if ( ! empty( $request->$slug->get_version_check->package ) )
$request->$slug->get_version_check->package = $this->extend_download_url( $request->$slug->get_version_check->package, $slug, $data );
if ( ! empty( $request->$slug->get_version_check->download_link ) )
$request->$slug->get_version_check->download_link = $this->extend_download_url( $request->$slug->get_version_check->download_link, $slug, $data );
if ( isset( $request->$slug->get_version_check->sections ) ) {
$request->$slug->get_version_check->sections = maybe_unserialize( $request->$slug->get_version_check->sections );
$request->$slug->get_version_check = json_encode( $request->$slug->get_version_check );
} else {
$request->$slug->get_version_check = new \WP_Error( 'plugins_api_failed',
sprintf(
/* translators: %s: support forums URL */
__( 'An unexpected error occurred. Something may be wrong with https://ultimatemember.com/ or this server&#8217;s configuration. If you continue to have problems, please try the <a href="%s">support forums</a>.' ),
__( 'https://wordpress.org/support/' )
),
wp_remote_retrieve_body( $request->$slug->get_version_check )
);
}
update_option( "{$data['key']}_version_check_edd_answer", $request->$slug->get_version_check );
}
}
}
return;
}
/**
* Disable SSL verification in order to prevent download update failures
*
* @param array $args
* @param string $url
* @return array $array
*/
function http_request_args( $args, $url ) {
// If it is an https request and we are performing a package download, disable ssl verification
if ( strpos( $url, 'https://' ) !== false && strpos( $url, 'action=package_download' ) ) {
$args['sslverify'] = false;
}
return $args;
}
/**
* Check for Updates by request to the marketplace
* and modify the update array.
*
* @param array $_transient_data plugin update array build by WordPress.
* @return \stdClass modified plugin update array.
*/
function um_check_update( $_transient_data ) {
global $pagenow;
if ( ! is_object( $_transient_data ) )
$_transient_data = new \stdClass;
if ( 'plugins.php' == $pagenow && is_multisite() )
return $_transient_data;
$exts = $this->um_get_active_plugins();
foreach ( $exts as $slug => $data ) {
$plugin_data = get_plugin_data( ABSPATH . "wp-content/plugins/{$slug}" );
//if response for current product isn't empty check for override
if ( ! empty( $_transient_data->response ) && ! empty( $_transient_data->response[ $slug ] ) )
continue;
$version_info = get_option( "{$data['key']}_version_check_edd_answer" );
$version_info = json_decode( $version_info );
if ( false !== $version_info && is_object( $version_info ) && isset( $version_info->new_version ) ) {
//show update version block if new version > then current
if ( version_compare( $plugin_data['Version'], $version_info->new_version, '<' ) )
$_transient_data->response[ $slug ] = $version_info;
$_transient_data->last_checked = time();
$_transient_data->checked[ $slug ] = $plugin_data['Version'];
}
}
return $_transient_data;
}
function extend_download_url( $download_url, $slug, $data ) {
/**
* Updates information on the "View version x.x details" popup with custom data.
*
* @param mixed $_data
* @param string $_action
* @param object $_args
* @return object $_data
*/
function um_plugins_api_filter( $_data, $_action = '', $_args = null ) {
//by default $data = false (from Wordpress)
$url = get_site_url( get_current_blog_id() );
$domain = strtolower( urlencode( rtrim( $url, '/' ) ) );
if ( $_action != 'plugin_information' )
return $_data;
$plugin_data = get_plugin_data( ABSPATH . "wp-content/plugins/{$slug}" );
$exts = $this->um_get_active_plugins();
$api_params = array(
'action' => 'get_last_version',
'license' => ! empty( $data['license'] ) ? $data['license'] : '',
'item_name' => str_replace( 'Ultimate Member - ', '', $plugin_data['Name'] ),
'blog_id' => get_current_blog_id(),
'site_url' => urlencode( $url ),
'domain' => urlencode( $domain ),
'slug' => urlencode( $slug ),
);
foreach ( $exts as $slug => $data ) {
if ( isset( $_args->slug ) && $_args->slug == $slug )
$api_request_transient = get_option( "{$data['key']}_version_check_edd_answer" );
}
$download_url = add_query_arg( $api_params, $download_url );
//If we have no transient-saved value, run the API, set a fresh transient with the API value, and return that value too right now.
if ( ! empty( $api_request_transient ) ) {
$_data = json_decode( $api_request_transient );
}
return $download_url;
}
}
if ( isset( $_data->sections ) )
$_data->sections = (array)$_data->sections;
return $_data;
}
/**
* Disable SSL verification in order to prevent download update failures
*
* @param array $args
* @param string $url
* @return array $array
*/
function http_request_args( $args, $url ) {
// If it is an https request and we are performing a package download, disable ssl verification
if ( strpos( $url, 'https://' ) !== false && strpos( $url, 'action=package_download' ) ) {
$args['sslverify'] = false;
}
return $args;
}
/**
* Download extension URL
*
* @param $download_url
* @param $slug
* @param $data
*
* @return string
*/
function extend_download_url( $download_url, $slug, $data ) {
$url = get_site_url( get_current_blog_id() );
$domain = strtolower( urlencode( rtrim( $url, '/' ) ) );
$plugin_data = get_plugin_data( ABSPATH . "wp-content/plugins/{$slug}" );
$api_params = array(
'action' => 'get_last_version',
'license' => ! empty( $data['license'] ) ? $data['license'] : '',
'item_name' => str_replace( 'Ultimate Member - ', '', $plugin_data['Name'] ),
'blog_id' => get_current_blog_id(),
'site_url' => urlencode( $url ),
'domain' => urlencode( $domain ),
'slug' => urlencode( $slug ),
);
$download_url = add_query_arg( $api_params, $download_url );
return $download_url;
}
}
}
+354 -301
View File
@@ -5,315 +5,368 @@ namespace um\core;
if ( ! defined( 'ABSPATH' ) ) exit;
if ( ! class_exists( 'Profile' ) ) {
class Profile {
public $arr_user_slugs = array();
public $arr_user_roles = array();
var $active_tab;
function __construct() {
add_action('template_redirect', array(&$this, 'active_tab'), 10002);
add_action('template_redirect', array(&$this, 'active_subnav'), 10002);
}
function ajax_delete_profile_photo() {
/**
* @var $user_id
*/
extract( $_REQUEST );
if ( ! UM()->roles()->um_current_user_can( 'edit', $user_id ) )
die( __( 'You can not edit this user' ) );
UM()->files()->delete_core_user_photo( $user_id, 'profile_photo' );
}
/**
* Class Profile
* @package um\core
*/
class Profile {
function ajax_delete_cover_photo() {
/**
* @var $user_id
*/
extract( $_REQUEST );
if ( ! UM()->roles()->um_current_user_can( 'edit', $user_id ) )
die( __( 'You can not edit this user' ) );
UM()->files()->delete_core_user_photo( $user_id, 'cover_photo' );
}
/**
* @var array
*/
public $arr_user_slugs = array();
/***
*** @all tab data
***/
function tabs() {
/**
* UM hook
*
* @type filter
* @title um_profile_tabs
* @description Extend user profile tabs
* @input_vars
* [{"var":"$tabs","type":"array","desc":"Profile tabs"}]
* @change_log
* ["Since: 2.0"]
* @usage
* <?php add_filter( 'um_profile_tabs', 'function_name', 10, 1 ); ?>
* @example
* <?php
* add_filter( 'um_profile_tabs', 'my_profile_tabs', 10, 1 );
* function my_profile_tabs( $tabs ) {
* // your code here
* return $tabs;
* }
* ?>
*/
$tabs = apply_filters( 'um_profile_tabs', array(
'main' => array(
'name' => __( 'About', 'ultimate-member' ),
'icon' => 'um-faicon-user'
),
'posts' => array(
'name' => __( 'Posts', 'ultimate-member' ),
'icon' => 'um-faicon-pencil'
),
'comments' => array(
'name' => __( 'Comments', 'ultimate-member' ),
'icon' => 'um-faicon-comment'
)
) );
// disable private tabs
if ( ! is_admin() ) {
foreach ( $tabs as $id => $tab ) {
if ( ! $this->can_view_tab( $id ) ) {
unset( $tabs[$id] );
}
}
}
return $tabs;
}
/***
*** @tabs that are active
***/
function tabs_active(){
$tabs = $this->tabs();
foreach( $tabs as $id => $info ) {
if ( ! UM()->options()->get('profile_tab_'.$id) && !isset( $info['_builtin'] ) && !isset( $info['custom'] ) )
unset( $tabs[$id] );
}
return $tabs;
}
/***
*** @primary tabs only
***/
function tabs_primary(){
$tabs = $this->tabs();
$primary = array();
foreach ( $tabs as $id => $info ) {
if ( isset( $info['name'] ) ) {
$primary[$id] = $info['name'];
}
}
return $primary;
}
/***
*** @Activated tabs in backend
***/
function tabs_enabled(){
$tabs = $this->tabs();
foreach( $tabs as $id => $info ){
if ( isset( $info['name'] ) ) {
if ( UM()->options()->get('profile_tab_'.$id) || isset( $info['_builtin'] ) ) {
$primary[$id] = $info['name'];
}
}
}
return ( isset( $primary ) ) ? $primary : '';
}
/***
*** @Privacy options
***/
function tabs_privacy() {
$privacy = array(
0 => 'Anyone',
1 => 'Guests only',
2 => 'Members only',
3 => 'Only the owner',
4 => 'Specific roles'
);
return $privacy;
}
/***
*** @Check if the user can view the current tab
***/
function can_view_tab( $tab ) {
$privacy = intval( UM()->options()->get( 'profile_tab_' . $tab . '_privacy' ) );
$can_view = false;
switch( $privacy ) {
case 1:
$can_view = is_user_logged_in() ? false : true;
break;
case 2:
$can_view = is_user_logged_in() ? true : false;
break;
case 3:
$can_view = get_current_user_id() == um_user( 'ID' ) ? true : false;
break;
case 4:
$can_view = false;
if( is_user_logged_in() ) {
$roles = UM()->options()->get( 'profile_tab_' . $tab . '_roles' );
if( is_array( $roles )
&& in_array( UM()->user()->get_role(), $roles ) ) {
$can_view = true;
}
}
break;
default:
$can_view = true;
break;
}
return $can_view;
}
/***
*** @Get active_tab
***/
function active_tab() {
$this->active_tab = UM()->options()->get('profile_menu_default_tab');
if ( get_query_var('profiletab') ) {
$this->active_tab = get_query_var('profiletab');
}
/**
* UM hook
*
* @type filter
* @title um_profile_active_tab
* @description Change active profile tab
* @input_vars
* [{"var":"$tab","type":"string","desc":"Active Profile tab"}]
* @change_log
* ["Since: 2.0"]
* @usage
* <?php add_filter( 'um_profile_active_tab', 'function_name', 10, 1 ); ?>
* @example
* <?php
* add_filter( 'um_profile_active_tab', 'my_profile_active_tab', 10, 1 );
* function my_profile_active_tab( $tab ) {
* // your code here
* return $tab;
* }
* ?>
*/
$this->active_tab = apply_filters( 'um_profile_active_tab', $this->active_tab );
return $this->active_tab;
}
/***
*** @Get active active_subnav
***/
function active_subnav() {
$this->active_subnav = null;
if ( get_query_var('subnav') ) {
$this->active_subnav = get_query_var('subnav');
}
return $this->active_subnav;
}
/**
* Show meta in profile
*
* @param array $array Meta Array
* @return string
*/
function show_meta( $array ) {
$output = '';
if ( ! empty( $array ) ) {
foreach ( $array as $key ) {
if ( $key ) {
$data = array();
if ( isset( UM()->builtin()->all_user_fields[ $key ] ) ){
$data = UM()->builtin()->all_user_fields[ $key ];
}
$data['in_profile_meta'] = true;
$value = um_filtered_value( $key, $data );
if ( ! $value )
continue;
if ( ! UM()->options()->get( 'profile_show_metaicon' ) ) {
$icon = '';
} else {
$icon = ! empty( $data['icon'] ) ? '<i class="' . $data['icon'] . '"></i>' : '';
}
$items[] = '<span>' . $icon . $value . '</span>';
$items[] = '<span class="b">&bull;</span>';
}
}
}
if ( isset( $items ) ) {
array_pop( $items );
foreach ( $items as $item ) {
$output .= $item;
}
}
return $output;
}
/**
* @var array
*/
public $arr_user_roles = array();
/**
* New menu
*
* @param string $position
* @param string $element
* @param string $trigger
* @param array $items
*/
function new_ui( $position, $element, $trigger, $items ) {
?>
/**
* @var
*/
var $active_tab;
<div class="um-dropdown" data-element="<?php echo $element; ?>" data-position="<?php echo $position; ?>" data-trigger="<?php echo $trigger; ?>">
<div class="um-dropdown-b">
<div class="um-dropdown-arr"><i class=""></i></div>
<ul>
<?php foreach ( $items as $k => $v ) { ?>
<li><?php echo $v; ?></li>
<?php } ?>
</ul>
</div>
</div>
<?php
}
}
/**
* Profile constructor.
*/
function __construct() {
add_action( 'template_redirect', array( &$this, 'active_tab' ), 10002 );
add_action( 'template_redirect', array( &$this, 'active_subnav' ), 10002 );
}
/**
* Delete profile avatar AJAX handler
*/
function ajax_delete_profile_photo() {
/**
* @var $user_id
*/
extract( $_REQUEST );
if ( ! UM()->roles()->um_current_user_can( 'edit', $user_id ) )
die( __( 'You can not edit this user' ) );
UM()->files()->delete_core_user_photo( $user_id, 'profile_photo' );
}
/**
* Delete cover photo AJAX handler
*/
function ajax_delete_cover_photo() {
/**
* @var $user_id
*/
extract( $_REQUEST );
if ( ! UM()->roles()->um_current_user_can( 'edit', $user_id ) )
die( __( 'You can not edit this user' ) );
UM()->files()->delete_core_user_photo( $user_id, 'cover_photo' );
}
/**
* All tab data
*
* @return mixed|void
*/
function tabs() {
/**
* UM hook
*
* @type filter
* @title um_profile_tabs
* @description Extend user profile tabs
* @input_vars
* [{"var":"$tabs","type":"array","desc":"Profile tabs"}]
* @change_log
* ["Since: 2.0"]
* @usage
* <?php add_filter( 'um_profile_tabs', 'function_name', 10, 1 ); ?>
* @example
* <?php
* add_filter( 'um_profile_tabs', 'my_profile_tabs', 10, 1 );
* function my_profile_tabs( $tabs ) {
* // your code here
* return $tabs;
* }
* ?>
*/
$tabs = apply_filters( 'um_profile_tabs', array(
'main' => array(
'name' => __( 'About', 'ultimate-member' ),
'icon' => 'um-faicon-user'
),
'posts' => array(
'name' => __( 'Posts', 'ultimate-member' ),
'icon' => 'um-faicon-pencil'
),
'comments' => array(
'name' => __( 'Comments', 'ultimate-member' ),
'icon' => 'um-faicon-comment'
)
) );
// disable private tabs
if ( ! is_admin() ) {
foreach ( $tabs as $id => $tab ) {
if ( ! $this->can_view_tab( $id ) ) {
unset( $tabs[$id] );
}
}
}
return $tabs;
}
/**
* Tabs that are active
*
* @return mixed|void
*/
function tabs_active() {
$tabs = $this->tabs();
foreach( $tabs as $id => $info ) {
if ( ! UM()->options()->get('profile_tab_'.$id) && !isset( $info['_builtin'] ) && !isset( $info['custom'] ) )
unset( $tabs[ $id ] );
}
return $tabs;
}
/**
* Primary tabs only
*
* @return array
*/
function tabs_primary(){
$tabs = $this->tabs();
$primary = array();
foreach ( $tabs as $id => $info ) {
if ( isset( $info['name'] ) ) {
$primary[$id] = $info['name'];
}
}
return $primary;
}
/**
* Activated tabs in backend
*
* @return string
*/
function tabs_enabled(){
$tabs = $this->tabs();
foreach( $tabs as $id => $info ){
if ( isset( $info['name'] ) ) {
if ( UM()->options()->get('profile_tab_'.$id) || isset( $info['_builtin'] ) ) {
$primary[$id] = $info['name'];
}
}
}
return ( isset( $primary ) ) ? $primary : '';
}
/**
* Privacy options
*
* @return array
*/
function tabs_privacy() {
$privacy = array(
0 => 'Anyone',
1 => 'Guests only',
2 => 'Members only',
3 => 'Only the owner',
4 => 'Specific roles'
);
return $privacy;
}
/**
* Check if the user can view the current tab
*
* @param $tab
*
* @return bool
*/
function can_view_tab( $tab ) {
$privacy = intval( UM()->options()->get( 'profile_tab_' . $tab . '_privacy' ) );
$can_view = false;
switch( $privacy ) {
case 1:
$can_view = is_user_logged_in() ? false : true;
break;
case 2:
$can_view = is_user_logged_in() ? true : false;
break;
case 3:
$can_view = get_current_user_id() == um_user( 'ID' ) ? true : false;
break;
case 4:
$can_view = false;
if( is_user_logged_in() ) {
$roles = UM()->options()->get( 'profile_tab_' . $tab . '_roles' );
if( is_array( $roles )
&& in_array( UM()->user()->get_role(), $roles ) ) {
$can_view = true;
}
}
break;
default:
$can_view = true;
break;
}
return $can_view;
}
/**
* Get active_tab
*
* @return mixed|void
*/
function active_tab() {
$this->active_tab = UM()->options()->get('profile_menu_default_tab');
if ( get_query_var('profiletab') ) {
$this->active_tab = get_query_var('profiletab');
}
/**
* UM hook
*
* @type filter
* @title um_profile_active_tab
* @description Change active profile tab
* @input_vars
* [{"var":"$tab","type":"string","desc":"Active Profile tab"}]
* @change_log
* ["Since: 2.0"]
* @usage
* <?php add_filter( 'um_profile_active_tab', 'function_name', 10, 1 ); ?>
* @example
* <?php
* add_filter( 'um_profile_active_tab', 'my_profile_active_tab', 10, 1 );
* function my_profile_active_tab( $tab ) {
* // your code here
* return $tab;
* }
* ?>
*/
$this->active_tab = apply_filters( 'um_profile_active_tab', $this->active_tab );
return $this->active_tab;
}
/**
* Get active active_subnav
*
* @return mixed|null
*/
function active_subnav() {
$this->active_subnav = null;
if ( get_query_var('subnav') ) {
$this->active_subnav = get_query_var('subnav');
}
return $this->active_subnav;
}
/**
* Show meta in profile
*
* @param array $array Meta Array
* @return string
*/
function show_meta( $array ) {
$output = '';
if ( ! empty( $array ) ) {
foreach ( $array as $key ) {
if ( $key ) {
$data = array();
if ( isset( UM()->builtin()->all_user_fields[ $key ] ) ){
$data = UM()->builtin()->all_user_fields[ $key ];
}
$data['in_profile_meta'] = true;
$value = um_filtered_value( $key, $data );
if ( ! $value )
continue;
if ( ! UM()->options()->get( 'profile_show_metaicon' ) ) {
$icon = '';
} else {
$icon = ! empty( $data['icon'] ) ? '<i class="' . $data['icon'] . '"></i>' : '';
}
$items[] = '<span>' . $icon . $value . '</span>';
$items[] = '<span class="b">&bull;</span>';
}
}
}
if ( isset( $items ) ) {
array_pop( $items );
foreach ( $items as $item ) {
$output .= $item;
}
}
return $output;
}
/**
* New menu
*
* @param string $position
* @param string $element
* @param string $trigger
* @param array $items
*/
function new_ui( $position, $element, $trigger, $items ) {
?>
<div class="um-dropdown" data-element="<?php echo $element; ?>" data-position="<?php echo $position; ?>" data-trigger="<?php echo $trigger; ?>">
<div class="um-dropdown-b">
<div class="um-dropdown-arr"><i class=""></i></div>
<ul>
<?php foreach ( $items as $k => $v ) { ?>
<li><?php echo $v; ?></li>
<?php } ?>
</ul>
</div>
</div>
<?php
}
}
}
+405 -320
View File
@@ -5,349 +5,434 @@ namespace um\core;
if ( ! defined( 'ABSPATH' ) ) exit;
if ( ! class_exists( 'Query' ) ) {
class Query {
public $wp_pages = array();
public $roles = array();
function __construct() {
}
/**
* Class Query
* @package um\core
*/
class Query {
/**
* Ajax pagination for posts
*/
function ajax_paginate() {
/**
* @var $hook
* @var $args
*/
extract( $_REQUEST );
ob_start();
/**
* UM hook
*
* @type action
* @title um_ajax_load_posts__{$hook}
* @description Action on posts loading by AJAX
* @input_vars
* [{"var":"$args","type":"array","desc":"Query arguments"}]
* @change_log
* ["Since: 2.0"]
* @usage add_action( 'um_ajax_load_posts__{$hook}', 'function_name', 10, 1 );
* @example
* <?php
* add_action( 'um_ajax_load_posts__{$hook}', 'my_ajax_load_posts', 10, 1 );
* function my_ajax_load_posts( $args ) {
* // your code here
* }
* ?>
*/
do_action( "um_ajax_load_posts__{$hook}", $args );
$output = ob_get_contents();
ob_end_clean();
die( $output );
}
/**
* @var array
*/
public $wp_pages = array();
/***
*** @get wp pages
***/
function wp_pages() {
global $wpdb;
if( isset( $this->wp_pages ) && ! empty( $this->wp_pages ) ){
return $this->wp_pages;
}
$count_pages = wp_count_posts('page');
if ( $count_pages->publish > 300 ){
return 'reached_maximum_limit';
}
/**
* @var array
*/
public $roles = array();
$pages = $wpdb->get_results('SELECT * FROM '.$wpdb->posts.' WHERE post_type = "page" AND post_status = "publish" ', OBJECT);
$array = array();
if( $wpdb->num_rows > 0 ){
foreach ($pages as $page_data) {
$array[ $page_data->ID ] = $page_data->post_title;
}
}
$this->wp_pages = $array;
return $array;
}
/***
*** @get all forms
***/
function forms() {
$args = array(
'post_type' => 'um_form',
'posts_per_page' => 200,
'post_status' => array('publish')
);
$query = new \WP_Query( $args );
foreach( $query->posts as $post ) {
setup_postdata( $post );
$results[ $post->ID ] = $post->post_title;
}
return $results;
}
/***
*** @Do custom queries
***/
function make( $args ) {
$defaults = array(
'post_type' => 'post',
'post_status' => array('publish')
);
$args = wp_parse_args( $args, $defaults );
if ( isset( $args['post__in'] ) && empty( $args['post__in'] ) )
return false;
extract( $args );
if ( $post_type == 'comment' ) { // comments
unset( $args['post_type'] );
/**
* UM hook
*
* @type filter
* @title um_excluded_comment_types
* @description Extend excluded comment types
* @input_vars
* [{"var":"$types","type":"array","desc":"Comment Types"}]
* @change_log
* ["Since: 2.0"]
* @usage
* <?php add_filter( 'um_excluded_comment_types', 'function_name', 10, 1 ); ?>
* @example
* <?php
* add_filter( 'um_excluded_comment_types', 'my_excluded_comment_types', 10, 1 );
* function my_profile_active_tab( $types ) {
* // your code here
* return $types;
* }
* ?>
*/
$args['type__not_in'] = apply_filters( 'um_excluded_comment_types', array('') );
$comments = get_comments($args);
return $comments;
} else {
$custom_posts = new \WP_Query();
$args['post_status'] = is_array( $args['post_status'] ) ? $args['post_status'] : explode( ',', $args['post_status'] );
$custom_posts->query( $args );
return $custom_posts;
}
}
/***
*** @Get last users
***/
function get_recent_users($number = 5){
$args = array( 'fields' => 'ID', 'number' => $number, 'orderby' => 'user_registered', 'order' => 'desc' );
$users = new \WP_User_Query( $args );
return $users->results;
}
/***
*** @Count users by status
***/
function count_users_by_status( $status ) {
$args = array( 'fields' => 'ID', 'number' => 0 );
if ( $status == 'unassigned' ) {
$args['meta_query'][] = array(array('key' => 'account_status','compare' => 'NOT EXISTS'));
$users = new \WP_User_Query( $args );
foreach( $users->results as $user ) {
update_user_meta( $user, 'account_status', 'approved' );
}
} else {
$args['meta_query'][] = array(array('key' => 'account_status','value' => $status,'compare' => '='));
}
$users = new \WP_User_Query( $args );
return count($users->results);
}
/***
*** @Get users by status
***/
function get_users_by_status($status, $number = 5){
global $wpdb;
$args = array( 'fields' => 'ID', 'number' => $number, 'orderby' => 'user_registered', 'order' => 'desc' );
$args['meta_query'][] = array(
array(
'key' => 'account_status',
'value' => $status,
'compare' => '='
)
);
$users = new \WP_User_Query( $args );
return $users->results;
}
/**
* Query constructor.
*/
function __construct() {
/***
*** @Count all users
***/
function count_users(){
$result = count_users();
return $result['total_users'];
}
}
/***
*** @Using wpdb instead of update_post_meta
***/
function update_attr( $key, $post_id, $new_value ){
update_post_meta( $post_id, '_um_' . $key, $new_value );
}
/**
* Ajax pagination for posts
*/
function ajax_paginate() {
/**
* @var $hook
* @var $args
*/
extract( $_REQUEST );
/***
*** @get data
***/
function get_attr( $key, $post_id ){
$meta = get_post_meta( $post_id, '_um_' . $key, true );
return $meta;
}
ob_start();
/***
*** @delete data
***/
function delete_attr( $key, $post_id ){
$meta = delete_post_meta( $post_id, '_um_' . $key );
return $meta;
}
/**
* UM hook
*
* @type action
* @title um_ajax_load_posts__{$hook}
* @description Action on posts loading by AJAX
* @input_vars
* [{"var":"$args","type":"array","desc":"Query arguments"}]
* @change_log
* ["Since: 2.0"]
* @usage add_action( 'um_ajax_load_posts__{$hook}', 'function_name', 10, 1 );
* @example
* <?php
* add_action( 'um_ajax_load_posts__{$hook}', 'my_ajax_load_posts', 10, 1 );
* function my_ajax_load_posts( $args ) {
* // your code here
* }
* ?>
*/
do_action( "um_ajax_load_posts__{$hook}", $args );
/***
*** @Checks if post has a specific meta key
***/
function has_post_meta($key, $value=null, $post_id=null ){
if (!$post_id){
global $post;
$post_id = $post->ID;
}
if ($value ){
if ( get_post_meta($post_id, $key, true) == $value )
return true;
} else {
if ( get_post_meta($post_id, $key, true) )
return true;
}
return false;
}
$output = ob_get_contents();
ob_end_clean();
/***
*** @Get posts with specific meta key/value
***/
function find_post_id($post_type, $key, $value){
$posts = get_posts( array( 'post_type' => $post_type, 'meta_key' => $key, 'meta_value' => $value ) );
if ( isset($posts[0]) && !empty($posts) )
return $posts[0]->ID;
return false;
}
die( $output );
}
/***
*** @Get post data
***/
function post_data( $post_id ) {
$array['form_id'] = $post_id;
$mode = $this->get_attr('mode', $post_id);
$meta = get_post_custom( $post_id );
foreach ($meta as $k => $v){
if ( strstr($k, '_um_'.$mode.'_' ) ) {
$k = str_replace('_um_'.$mode.'_', '', $k);
$array[$k] = $v[0];
} elseif ($k == '_um_mode'){
$k = str_replace('_um_', '', $k);
$array[$k] = $v[0];
} elseif ( strstr($k, '_um_') ) {
$k = str_replace('_um_', '', $k);
$array[$k] = $v[0];
}
/**
* Get wp pages
*
* @return array|string
*/
function wp_pages() {
global $wpdb;
}
if( isset( $this->wp_pages ) && ! empty( $this->wp_pages ) ){
return $this->wp_pages;
}
foreach( $array as $k => $v ) {
if ( strstr( $k, 'login_') || strstr( $k, 'register_' ) || strstr( $k, 'profile_' ) ){
if ( $mode != 'directory' ) {
unset($array[$k]);
}
}
}
return $array;
}
$count_pages = wp_count_posts('page');
/**
* Capture selected value
*
* @param $key
* @param null $array_key
* @param null $fallback
* @return int|mixed|null|string
*/
function get_meta_value( $key, $array_key = null, $fallback = null ) {
global $post;
$post_id = get_the_ID();
$try = get_post_meta( $post_id, $key, true );
if ( $count_pages->publish > 300 ){
return 'reached_maximum_limit';
}
//old version if ( ! empty( $try ) )
if ( false !== $try )
if ( is_array( $try ) && in_array( $array_key, $try ) ) {
return $array_key;
} else if ( is_array( $try ) ) {
return '';
} else {
return $try;
}
if ( $fallback == 'na' ) {
$fallback = 0;
$none = '';
} else {
$none = 0;
}
return ! empty( $fallback ) ? $fallback : $none;
}
$pages = $wpdb->get_results('SELECT * FROM '.$wpdb->posts.' WHERE post_type = "page" AND post_status = "publish" ', OBJECT);
/***
*** @Checks if its a core page of UM
***/
function is_core( $post_id ){
$is_core = get_post_meta($post_id, '_um_core', true);
if ( $is_core != '' ) {
return $is_core;
} else {
return false;
}
}
$array = array();
if( $wpdb->num_rows > 0 ){
foreach ($pages as $page_data) {
$array[ $page_data->ID ] = $page_data->post_title;
}
}
}
$this->wp_pages = $array;
return $array;
}
/**
* Get all forms
*
* @return mixed
*/
function forms() {
$results = array();
$args = array(
'post_type' => 'um_form',
'posts_per_page' => 200,
'post_status' => array('publish')
);
$query = new \WP_Query( $args );
foreach ( $query->posts as $post ) {
setup_postdata( $post );
$results[ $post->ID ] = $post->post_title;
}
return $results;
}
/**
* Do custom queries
*
* @param $args
*
* @return array|bool|int|\WP_Query
*/
function make( $args ) {
$defaults = array(
'post_type' => 'post',
'post_status' => array('publish')
);
$args = wp_parse_args( $args, $defaults );
if ( isset( $args['post__in'] ) && empty( $args['post__in'] ) )
return false;
extract( $args );
if ( $post_type == 'comment' ) { // comments
unset( $args['post_type'] );
/**
* UM hook
*
* @type filter
* @title um_excluded_comment_types
* @description Extend excluded comment types
* @input_vars
* [{"var":"$types","type":"array","desc":"Comment Types"}]
* @change_log
* ["Since: 2.0"]
* @usage
* <?php add_filter( 'um_excluded_comment_types', 'function_name', 10, 1 ); ?>
* @example
* <?php
* add_filter( 'um_excluded_comment_types', 'my_excluded_comment_types', 10, 1 );
* function my_profile_active_tab( $types ) {
* // your code here
* return $types;
* }
* ?>
*/
$args['type__not_in'] = apply_filters( 'um_excluded_comment_types', array('') );
$comments = get_comments($args);
return $comments;
} else {
$custom_posts = new \WP_Query();
$args['post_status'] = is_array( $args['post_status'] ) ? $args['post_status'] : explode( ',', $args['post_status'] );
$custom_posts->query( $args );
return $custom_posts;
}
}
/**
* Get last users
*
* @param int $number
*
* @return array
*/
function get_recent_users($number = 5){
$args = array( 'fields' => 'ID', 'number' => $number, 'orderby' => 'user_registered', 'order' => 'desc' );
$users = new \WP_User_Query( $args );
return $users->results;
}
/**
* Count users by status
*
* @param $status
*
* @return int
*/
function count_users_by_status( $status ) {
$args = array( 'fields' => 'ID', 'number' => 0 );
if ( $status == 'unassigned' ) {
$args['meta_query'][] = array(array('key' => 'account_status','compare' => 'NOT EXISTS'));
$users = new \WP_User_Query( $args );
foreach ( $users->results as $user ) {
update_user_meta( $user, 'account_status', 'approved' );
}
} else {
$args['meta_query'][] = array(array('key' => 'account_status','value' => $status,'compare' => '='));
}
$users = new \WP_User_Query( $args );
return count( $users->results );
}
/**
* Get users by status
*
* @param $status
* @param int $number
*
* @return array
*/
function get_users_by_status($status, $number = 5){
$args = array( 'fields' => 'ID', 'number' => $number, 'orderby' => 'user_registered', 'order' => 'desc' );
$args['meta_query'][] = array(
array(
'key' => 'account_status',
'value' => $status,
'compare' => '='
)
);
$users = new \WP_User_Query( $args );
return $users->results;
}
/**
* Count all users
*
* @return mixed
*/
function count_users() {
$result = count_users();
return $result['total_users'];
}
/**
* Using wpdb instead of update_post_meta
*
* @param $key
* @param $post_id
* @param $new_value
*/
function update_attr( $key, $post_id, $new_value ){
update_post_meta( $post_id, '_um_' . $key, $new_value );
}
/**
* Get data
*
* @param $key
* @param $post_id
*
* @return mixed
*/
function get_attr( $key, $post_id ) {
$meta = get_post_meta( $post_id, '_um_' . $key, true );
return $meta;
}
/**
* Delete data
*
* @param $key
* @param $post_id
*
* @return bool
*/
function delete_attr( $key, $post_id ) {
$meta = delete_post_meta( $post_id, '_um_' . $key );
return $meta;
}
/**
* Checks if post has a specific meta key
*
* @param $key
* @param null $value
* @param null $post_id
*
* @return bool
*/
function has_post_meta( $key, $value = null, $post_id = null ) {
if ( ! $post_id ) {
global $post;
$post_id = $post->ID;
}
if ( $value ) {
if ( get_post_meta( $post_id, $key, true ) == $value ) {
return true;
}
} else {
if ( get_post_meta( $post_id, $key, true ) ) {
return true;
}
}
return false;
}
/**
* Get posts with specific meta key/value
*
* @param $post_type
* @param $key
* @param $value
*
* @return bool
*/
function find_post_id( $post_type, $key, $value ) {
$posts = get_posts( array( 'post_type' => $post_type, 'meta_key' => $key, 'meta_value' => $value ) );
if ( isset( $posts[0] ) && ! empty( $posts ) )
return $posts[0]->ID;
return false;
}
/**
* Get post data
*
* @param $post_id
*
* @return mixed
*/
function post_data( $post_id ) {
$array['form_id'] = $post_id;
$mode = $this->get_attr('mode', $post_id);
$meta = get_post_custom( $post_id );
foreach ($meta as $k => $v){
if ( strstr($k, '_um_'.$mode.'_' ) ) {
$k = str_replace('_um_'.$mode.'_', '', $k);
$array[$k] = $v[0];
} elseif ($k == '_um_mode'){
$k = str_replace('_um_', '', $k);
$array[$k] = $v[0];
} elseif ( strstr($k, '_um_') ) {
$k = str_replace('_um_', '', $k);
$array[$k] = $v[0];
}
}
foreach( $array as $k => $v ) {
if ( strstr( $k, 'login_') || strstr( $k, 'register_' ) || strstr( $k, 'profile_' ) ){
if ( $mode != 'directory' ) {
unset($array[$k]);
}
}
}
return $array;
}
/**
* Capture selected value
*
* @param $key
* @param null $array_key
* @param null $fallback
* @return int|mixed|null|string
*/
function get_meta_value( $key, $array_key = null, $fallback = null ) {
$post_id = get_the_ID();
$try = get_post_meta( $post_id, $key, true );
//old version if ( ! empty( $try ) )
if ( false !== $try )
if ( is_array( $try ) && in_array( $array_key, $try ) ) {
return $array_key;
} else if ( is_array( $try ) ) {
return '';
} else {
return $try;
}
if ( $fallback == 'na' ) {
$fallback = 0;
$none = '';
} else {
$none = 0;
}
return ! empty( $fallback ) ? $fallback : $none;
}
/**
* Checks if its a core page of UM
*
* @param $post_id
*
* @return bool|mixed
*/
function is_core( $post_id ){
$is_core = get_post_meta($post_id, '_um_core', true);
if ( $is_core != '' ) {
return $is_core;
} else {
return false;
}
}
}
}
+61 -40
View File
@@ -5,52 +5,73 @@ namespace um\core;
if ( ! defined( 'ABSPATH' ) ) exit;
if ( ! class_exists( 'Register' ) ) {
class Register {
function __construct(){
add_action("um_after_register_fields", array( $this, 'add_nonce' ) );
add_action("um_submit_form_register", array( $this, 'verify_nonce'), 1, 1);
}
/**
* Class Register
* @package um\core
*/
class Register {
public function add_nonce(){
wp_nonce_field( 'um_register_form' );
}
public function verify_nonce( $args ){
/**
* UM hook
*
* @type filter
* @title um_register_allow_nonce_verification
* @description Enable/DIsable nonce verification of registration
* @input_vars
* [{"var":"$allow_nonce","type":"bool","desc":"Enable nonce"}]
* @change_log
* ["Since: 2.0"]
* @usage
* <?php add_filter( 'um_register_allow_nonce_verification', 'function_name', 10, 1 ); ?>
* @example
* <?php
* add_filter( 'um_register_allow_nonce_verification', 'my_register_allow_nonce_verification', 10, 1 );
* function my_register_allow_nonce_verification( $allow_nonce ) {
* // your code here
* return $allow_nonce;
* }
* ?>
*/
$allow_nonce_verification = apply_filters( "um_register_allow_nonce_verification", true );
/**
* Register constructor.
*/
function __construct() {
add_action( "um_after_register_fields", array( $this, 'add_nonce' ) );
add_action( "um_submit_form_register", array( $this, 'verify_nonce' ), 1, 1 );
}
if( ! $allow_nonce_verification ){
return $args;
}
if ( ! wp_verify_nonce( $args['_wpnonce'], 'um_register_form' ) || empty( $args['_wpnonce'] ) || ! isset( $args['_wpnonce'] ) ) {
wp_die('Invalid Nonce.');
}
/**
* Add registration form notice
*/
public function add_nonce() {
wp_nonce_field( 'um_register_form' );
}
return $args;
}
}
/**
* Verify nonce handler
*
* @param $args
*
* @return mixed
*/
public function verify_nonce( $args ) {
/**
* UM hook
*
* @type filter
* @title um_register_allow_nonce_verification
* @description Enable/DIsable nonce verification of registration
* @input_vars
* [{"var":"$allow_nonce","type":"bool","desc":"Enable nonce"}]
* @change_log
* ["Since: 2.0"]
* @usage
* <?php add_filter( 'um_register_allow_nonce_verification', 'function_name', 10, 1 ); ?>
* @example
* <?php
* add_filter( 'um_register_allow_nonce_verification', 'my_register_allow_nonce_verification', 10, 1 );
* function my_register_allow_nonce_verification( $allow_nonce ) {
* // your code here
* return $allow_nonce;
* }
* ?>
*/
$allow_nonce_verification = apply_filters( "um_register_allow_nonce_verification", true );
if( ! $allow_nonce_verification ){
return $args;
}
if ( ! wp_verify_nonce( $args['_wpnonce'], 'um_register_form' ) || empty( $args['_wpnonce'] ) || ! isset( $args['_wpnonce'] ) ) {
wp_die('Invalid Nonce.');
}
return $args;
}
}
}
File diff suppressed because it is too large Load Diff
+267 -251
View File
@@ -5,278 +5,294 @@ namespace um\core;
if ( ! defined( 'ABSPATH' ) ) exit;
if ( ! class_exists( 'Rewrite' ) ) {
class Rewrite {
function __construct() {
add_filter( 'query_vars', array(&$this, 'query_vars'), 10, 1 );
/**
* Class Rewrite
* @package um\core
*/
class Rewrite {
add_action( 'init', array( &$this, 'rewrite_rules'), 100000000 );
add_action( 'template_redirect', array( &$this, 'redirect_author_page'), 9999 );
/**
* Rewrite constructor.
*/
function __construct() {
add_filter( 'query_vars', array(&$this, 'query_vars'), 10, 1 );
add_action( 'template_redirect', array( &$this, 'locate_user_profile'), 9999 );
add_action( 'init', array( &$this, 'rewrite_rules'), 100000000 );
add_action( 'template_redirect', array( &$this, 'redirect_author_page'), 9999 );
//add rewrite rules
add_filter( 'rewrite_rules_array', array( &$this, '_add_rewrite_rules' ), 10, 1 );
add_action( 'template_redirect', array( &$this, 'locate_user_profile'), 9999 );
}
//add rewrite rules
add_filter( 'rewrite_rules_array', array( &$this, '_add_rewrite_rules' ), 10, 1 );
}
/***
*** @modify global query vars
***/
function query_vars( $public_query_vars ) {
$public_query_vars[] = 'um_user';
$public_query_vars[] = 'um_tab';
$public_query_vars[] = 'profiletab';
$public_query_vars[] = 'subnav';
$public_query_vars[] = 'um_page';
$public_query_vars[] = 'um_action';
$public_query_vars[] = 'um_resource';
$public_query_vars[] = 'um_method';
$public_query_vars[] = 'um_verify';
/**
* Modify global query vars
*
* @param $public_query_vars
*
* @return array
*/
function query_vars( $public_query_vars ) {
$public_query_vars[] = 'um_user';
$public_query_vars[] = 'um_tab';
$public_query_vars[] = 'profiletab';
$public_query_vars[] = 'subnav';
$public_query_vars[] = 'um_page';
$public_query_vars[] = 'um_action';
$public_query_vars[] = 'um_resource';
$public_query_vars[] = 'um_method';
$public_query_vars[] = 'um_verify';
return $public_query_vars;
}
/**
* Add UM rewrite rules
*
* @param $rules
*
* @return array
*/
function _add_rewrite_rules( $rules ) {
$newrules = array();
$newrules['um-api/([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$'] = 'index.php?um_page=api&um_action=$matches[1]&um_resource=$matches[2]&um_method=$matches[3]&um_verify=$matches[4]';
return $newrules + $rules;
}
/**
* Setup rewrite rules
*/
function rewrite_rules() {
if ( isset( UM()->config()->permalinks['user'] ) ) {
$user_page_id = UM()->config()->permalinks['user'];
$account_page_id = UM()->config()->permalinks['account'];
$user = get_post($user_page_id);
if ( isset( $user->post_name ) ) {
$user_slug = $user->post_name;
$account = get_post($account_page_id);
$account_slug = $account->post_name;
$add_lang_code = '';
$language_code = '';
if ( function_exists('icl_object_id') || function_exists('icl_get_current_language') ) {
if( function_exists('icl_get_current_language') ){
$language_code = icl_get_current_language();
}else if( function_exists('icl_object_id') && defined('ICL_LANGUAGE_CODE') ){
$language_code = ICL_LANGUAGE_CODE;
}
// User page translated slug
$lang_post_id = icl_object_id( $user->ID, 'post', FALSE, $language_code );
$lang_post_obj = get_post( $lang_post_id );
if( isset( $lang_post_obj->post_name ) ){
$user_slug = $lang_post_obj->post_name;
}
// Account page translated slug
$lang_post_id = icl_object_id( $account->ID, 'post', FALSE, $language_code );
$lang_post_obj = get_post( $lang_post_id );
if( isset( $lang_post_obj->post_name ) ){
$account_slug = $lang_post_obj->post_name;
}
return $public_query_vars;
}
if( $language_code != icl_get_default_language() ){
$add_lang_code = $language_code;
}
}
function _add_rewrite_rules( $rules ) {
$newrules = array();
$newrules['um-api/([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$'] = 'index.php?um_page=api&um_action=$matches[1]&um_resource=$matches[2]&um_method=$matches[3]&um_verify=$matches[4]';
return $newrules + $rules;
}
/***
*** @setup rewrite rules
***/
function rewrite_rules() {
if ( isset( UM()->config()->permalinks['user'] ) ) {
$user_page_id = UM()->config()->permalinks['user'];
$account_page_id = UM()->config()->permalinks['account'];
$user = get_post($user_page_id);
add_rewrite_rule( $user_slug.'/([^/]+)/?$',
'index.php?page_id='.$user_page_id.'&um_user=$matches[1]&lang='.$add_lang_code,
'top'
);
add_rewrite_rule( $account_slug.'/([^/]+)?$',
'index.php?page_id='.$account_page_id.'&um_tab=$matches[1]&lang='.$add_lang_code,
'top'
);
/**
* UM hook
*
* @type filter
* @title um_rewrite_flush_rewrite_rules
* @description Enable flushing rewrite rules
* @input_vars
* [{"var":"$stop_flush","type":"bool","desc":"Stop flushing rewrite rules"}]
* @change_log
* ["Since: 2.0"]
* @usage
* <?php add_filter( 'um_rewrite_flush_rewrite_rules', 'function_name', 10, 1 ); ?>
* @example
* <?php
* add_filter( 'um_rewrite_flush_rewrite_rules', 'my_rewrite_flush_rewrite_rules', 10, 1 );
* function my_rewrite_flush_rewrite_rules( $stop_flush ) {
* // your code here
* return $stop_flush;
* }
* ?>
*/
if ( ! apply_filters( 'um_rewrite_flush_rewrite_rules', UM()->options()->get( 'um_flush_stop' ) ) )
flush_rewrite_rules( true );
if ( isset( $user->post_name ) ) {
}
}
}
$user_slug = $user->post_name;
$account = get_post($account_page_id);
$account_slug = $account->post_name;
$add_lang_code = '';
$language_code = '';
if ( function_exists('icl_object_id') || function_exists('icl_get_current_language') ) {
if( function_exists('icl_get_current_language') ){
$language_code = icl_get_current_language();
}else if( function_exists('icl_object_id') && defined('ICL_LANGUAGE_CODE') ){
$language_code = ICL_LANGUAGE_CODE;
}
// User page translated slug
$lang_post_id = icl_object_id( $user->ID, 'post', FALSE, $language_code );
$lang_post_obj = get_post( $lang_post_id );
if( isset( $lang_post_obj->post_name ) ){
$user_slug = $lang_post_obj->post_name;
}
/**
* Author page to user profile redirect
*/
function redirect_author_page() {
if ( UM()->options()->get( 'author_redirect' ) && is_author() ) {
$id = get_query_var( 'author' );
um_fetch_user( $id );
exit( wp_redirect( um_user_profile_url() ) );
}
}
/**
* Locate/display a profile
*/
function locate_user_profile() {
global $post;
if ( um_queried_user() && um_is_core_page('user') ) {
if ( UM()->options()->get( 'permalink_base' ) == 'user_login' ) {
$user_id = username_exists( um_queried_user() );
// Try nice name
if ( !$user_id ) {
$slug = um_queried_user();
$slug = str_replace('.','-',$slug);
$the_user = get_user_by( 'slug', $slug );
if ( isset( $the_user->ID ) ){
$user_id = $the_user->ID;
}
if ( ! $user_id )
$user_id = UM()->user()->user_exists_by_email_as_username( um_queried_user() );
if ( ! $user_id )
$user_id = UM()->user()->user_exists_by_email_as_username( $slug );
}
}
if ( UM()->options()->get( 'permalink_base' ) == 'user_id' ) {
$user_id = UM()->user()->user_exists_by_id( um_queried_user() );
}
if ( in_array( UM()->options()->get( 'permalink_base' ), array('name','name_dash','name_dot','name_plus') ) ) {
$user_id = UM()->user()->user_exists_by_name( um_queried_user() );
}
/** USER EXISTS SET USER AND CONTINUE **/
if ( $user_id ) {
um_set_requested_user( $user_id );
/**
* UM hook
*
* @type action
* @title um_access_profile
* @description Action on user access profile
* @input_vars
* [{"var":"$user_id","type":"int","desc":"User ID"}]
* @change_log
* ["Since: 2.0"]
* @usage add_action( 'um_access_profile', 'function_name', 10, 1 );
* @example
* <?php
* add_action( 'um_access_profile', 'my_access_profile', 10, 1 );
* function my_access_profile( $user_id ) {
* // your code here
* }
* ?>
*/
do_action( 'um_access_profile', $user_id );
} else {
exit( wp_redirect( um_get_core_page( 'user' ) ) );
}
// Account page translated slug
$lang_post_id = icl_object_id( $account->ID, 'post', FALSE, $language_code );
$lang_post_obj = get_post( $lang_post_id );
if( isset( $lang_post_obj->post_name ) ){
$account_slug = $lang_post_obj->post_name;
}
} else if ( um_is_core_page( 'user' ) ) {
if( $language_code != icl_get_default_language() ){
$add_lang_code = $language_code;
}
if ( is_user_logged_in() ) { // just redirect to their profile
}
$query = UM()->permalinks()->get_query_array();
add_rewrite_rule( $user_slug.'/([^/]+)/?$',
'index.php?page_id='.$user_page_id.'&um_user=$matches[1]&lang='.$add_lang_code,
'top'
);
$url = um_user_profile_url( um_user( 'ID' ) );
add_rewrite_rule( $account_slug.'/([^/]+)?$',
'index.php?page_id='.$account_page_id.'&um_tab=$matches[1]&lang='.$add_lang_code,
'top'
);
if ( $query ) {
foreach ( $query as $key => $val ) {
$url = add_query_arg( $key, $val, $url );
}
}
exit( wp_redirect( $url ) );
} else {
/**
* UM hook
*
* @type filter
* @title um_locate_user_profile_not_loggedin__redirect
* @description Change redirect URL from user profile for not logged in user
* @input_vars
* [{"var":"$url","type":"string","desc":"Redirect URL"}]
* @change_log
* ["Since: 2.0"]
* @usage
* <?php add_filter( 'um_locate_user_profile_not_loggedin__redirect', 'function_name', 10, 1 ); ?>
* @example
* <?php
* add_filter( 'um_locate_user_profile_not_loggedin__redirect', 'my_user_profile_not_loggedin__redirect', 10, 1 );
* function my_user_profile_not_loggedin__redirect( $url ) {
* // your code here
* return $url;
* }
* ?>
*/
$redirect_to = apply_filters( 'um_locate_user_profile_not_loggedin__redirect', home_url() );
if ( ! empty( $redirect_to ) ){
exit( wp_redirect( $redirect_to ) );
}
}
/**
* UM hook
*
* @type filter
* @title um_rewrite_flush_rewrite_rules
* @description Enable flushing rewrite rules
* @input_vars
* [{"var":"$stop_flush","type":"bool","desc":"Stop flushing rewrite rules"}]
* @change_log
* ["Since: 2.0"]
* @usage
* <?php add_filter( 'um_rewrite_flush_rewrite_rules', 'function_name', 10, 1 ); ?>
* @example
* <?php
* add_filter( 'um_rewrite_flush_rewrite_rules', 'my_rewrite_flush_rewrite_rules', 10, 1 );
* function my_rewrite_flush_rewrite_rules( $stop_flush ) {
* // your code here
* return $stop_flush;
* }
* ?>
*/
if ( ! apply_filters( 'um_rewrite_flush_rewrite_rules', UM()->options()->get( 'um_flush_stop' ) ) )
flush_rewrite_rules( true );
}
}
}
/***
*** @author page to user profile redirect
***/
function redirect_author_page() {
if ( UM()->options()->get( 'author_redirect' ) && is_author() ) {
$id = get_query_var( 'author' );
um_fetch_user( $id );
exit( wp_redirect( um_user_profile_url() ) );
}
}
/***
*** @locate/display a profile
***/
function locate_user_profile() {
global $post;
if ( um_queried_user() && um_is_core_page('user') ) {
if ( UM()->options()->get( 'permalink_base' ) == 'user_login' ) {
$user_id = username_exists( um_queried_user() );
// Try nice name
if ( !$user_id ) {
$slug = um_queried_user();
$slug = str_replace('.','-',$slug);
$the_user = get_user_by( 'slug', $slug );
if ( isset( $the_user->ID ) ){
$user_id = $the_user->ID;
}
if ( ! $user_id )
$user_id = UM()->user()->user_exists_by_email_as_username( um_queried_user() );
if ( ! $user_id )
$user_id = UM()->user()->user_exists_by_email_as_username( $slug );
}
}
if ( UM()->options()->get( 'permalink_base' ) == 'user_id' ) {
$user_id = UM()->user()->user_exists_by_id( um_queried_user() );
}
if ( in_array( UM()->options()->get( 'permalink_base' ), array('name','name_dash','name_dot','name_plus') ) ) {
$user_id = UM()->user()->user_exists_by_name( um_queried_user() );
}
/** USER EXISTS SET USER AND CONTINUE **/
if ( $user_id ) {
um_set_requested_user( $user_id );
/**
* UM hook
*
* @type action
* @title um_access_profile
* @description Action on user access profile
* @input_vars
* [{"var":"$user_id","type":"int","desc":"User ID"}]
* @change_log
* ["Since: 2.0"]
* @usage add_action( 'um_access_profile', 'function_name', 10, 1 );
* @example
* <?php
* add_action( 'um_access_profile', 'my_access_profile', 10, 1 );
* function my_access_profile( $user_id ) {
* // your code here
* }
* ?>
*/
do_action( 'um_access_profile', $user_id );
} else {
exit( wp_redirect( um_get_core_page( 'user' ) ) );
}
} else if ( um_is_core_page( 'user' ) ) {
if ( is_user_logged_in() ) { // just redirect to their profile
$query = UM()->permalinks()->get_query_array();
$url = um_user_profile_url( um_user( 'ID' ) );
/*if ( empty( $url ) ) {
//if empty profile slug - generate it and re-get profile URL
UM()->user()->generate_profile_slug( um_user( 'ID' ) );
$url = um_user_profile_url();
}*/
if ( $query ) {
foreach ( $query as $key => $val ) {
$url = add_query_arg( $key, $val, $url );
}
}
exit( wp_redirect( $url ) );
} else {
/**
* UM hook
*
* @type filter
* @title um_locate_user_profile_not_loggedin__redirect
* @description Change redirect URL from user profile for not logged in user
* @input_vars
* [{"var":"$url","type":"string","desc":"Redirect URL"}]
* @change_log
* ["Since: 2.0"]
* @usage
* <?php add_filter( 'um_locate_user_profile_not_loggedin__redirect', 'function_name', 10, 1 ); ?>
* @example
* <?php
* add_filter( 'um_locate_user_profile_not_loggedin__redirect', 'my_user_profile_not_loggedin__redirect', 10, 1 );
* function my_user_profile_not_loggedin__redirect( $url ) {
* // your code here
* return $url;
* }
* ?>
*/
$redirect_to = apply_filters( 'um_locate_user_profile_not_loggedin__redirect', home_url() );
if ( ! empty( $redirect_to ) ){
exit( wp_redirect( $redirect_to ) );
}
}
}
}
}
}
}
}
}
File diff suppressed because it is too large Load Diff
+76 -64
View File
@@ -4,35 +4,42 @@ namespace um\core;
if ( ! defined( 'ABSPATH' ) ) exit;
if ( ! class_exists( 'Router' ) ) {
class Router {
/**
*
*/
function backend_requests() {
$ip = isset( $_SERVER['REMOTE_ADDR'] ) ? $_SERVER['REMOTE_ADDR'] : '';
$user_id = get_current_user_id();
if ( empty( $_REQUEST['um_action'] ) )
exit( __( 'Wrong action', 'ultimate-member' ) );
/**
* Class Router
* @package um\core
*/
class Router {
if ( empty( $_REQUEST['um_resource'] ) )
exit( __( 'Wrong resource', 'ultimate-member' ) );
if ( $_REQUEST['um_action'] == 'route' )
$verify = wp_verify_nonce( $_REQUEST['um_verify'], $ip . $user_id . $_REQUEST['um_resource'] . $_REQUEST['um_method'] );
else
$verify = wp_verify_nonce( $_REQUEST['um_verify'], $ip . $user_id . $_REQUEST['um_action'] . $_REQUEST['um_resource'] );
/**
* Run backend process
*/
function backend_requests() {
$ip = isset( $_SERVER['REMOTE_ADDR'] ) ? $_SERVER['REMOTE_ADDR'] : '';
$user_id = get_current_user_id();
if ( empty( $verify ) )
exit( __( 'Wrong nonce', 'ultimate-member' ) );
if ( empty( $_REQUEST['um_action'] ) )
exit( __( 'Wrong action', 'ultimate-member' ) );
$this->request_process( array(
'route' => $_REQUEST['um_resource'],
'method' => $_REQUEST['um_method']
) );
if ( empty( $_REQUEST['um_resource'] ) )
exit( __( 'Wrong resource', 'ultimate-member' ) );
/*if ($_REQUEST['um_action'] == 'download' || $_REQUEST['um_action'] == 'view') {
if ( $_REQUEST['um_action'] == 'route' )
$verify = wp_verify_nonce( $_REQUEST['um_verify'], $ip . $user_id . $_REQUEST['um_resource'] . $_REQUEST['um_method'] );
else
$verify = wp_verify_nonce( $_REQUEST['um_verify'], $ip . $user_id . $_REQUEST['um_action'] . $_REQUEST['um_resource'] );
if ( empty( $verify ) )
exit( __( 'Wrong nonce', 'ultimate-member' ) );
$this->request_process( array(
'route' => $_REQUEST['um_resource'],
'method' => $_REQUEST['um_method']
) );
/*if ($_REQUEST['um_action'] == 'download' || $_REQUEST['um_action'] == 'view') {
WO()->downloader()->set_type( $_REQUEST['um_action'] )->process( array(
'id' => $_REQUEST['um_id'],
'resource' => $_REQUEST['um_resource'],
@@ -44,60 +51,65 @@ if ( ! class_exists( 'Router' ) ) {
'method' => $_REQUEST['um_method']
) );
}*/
}
}
/**
* @param $params array
* @return bool
*/
function request_process( $params ) {
if ( empty( $params['route'] ) || empty( $params['method'] ) )
return false;
/**
* Request process
*
* @param $params array
* @return bool
*/
function request_process( $params ) {
if ( empty( $params['route'] ) || empty( $params['method'] ) )
return false;
$route = str_replace( array( '!', '/' ), '\\', $params['route'] );
$route = str_replace( array( '!', '/' ), '\\', $params['route'] );
if ( ! class_exists( $route ) )
return false;
if ( ! class_exists( $route ) )
return false;
if ( method_exists( $route, 'instance' ) )
$object = $route::instance();
else
$object = new $route();
if ( method_exists( $route, 'instance' ) )
$object = $route::instance();
else
$object = new $route();
if ( ! method_exists( $object, $params['method'] ) )
return false;
if ( ! method_exists( $object, $params['method'] ) )
return false;
call_user_func( array( &$object, $params['method'] ) );
return true;
}
call_user_func( array( &$object, $params['method'] ) );
return true;
}
function frontend_requests() {
$ip = isset( $_SERVER['REMOTE_ADDR'] ) ? $_SERVER['REMOTE_ADDR'] : '';
$user_id = get_current_user_id();
if ( ! get_query_var( 'um_action' ) )
exit( __( 'Wrong action', 'ultimate-member' ) );
/**
* Run frontend process
*/
function frontend_requests() {
$ip = isset( $_SERVER['REMOTE_ADDR'] ) ? $_SERVER['REMOTE_ADDR'] : '';
$user_id = get_current_user_id();
if ( ! get_query_var( 'um_action' ) )
exit( __( 'Wrong action', 'ultimate-member' ) );
if ( ! get_query_var( 'um_resource' ) )
exit( __( 'Wrong resource', 'ultimate-member' ) );
if ( ! get_query_var( 'um_resource' ) )
exit( __( 'Wrong resource', 'ultimate-member' ) );
$verify = false;
if ( get_query_var( 'um_action' ) == 'route' )
$verify = wp_verify_nonce( get_query_var( 'um_verify' ), $ip . $user_id . get_query_var( 'um_resource' ) . get_query_var( 'um_method' ) );
$verify = false;
if ( get_query_var( 'um_action' ) == 'route' )
$verify = wp_verify_nonce( get_query_var( 'um_verify' ), $ip . $user_id . get_query_var( 'um_resource' ) . get_query_var( 'um_method' ) );
if ( $verify ) {
if ( get_query_var( 'um_action' ) == 'route' ) {
$this->request_process( array(
'route' => get_query_var( 'um_resource' ),
'method' => get_query_var( 'um_method' )
) );
}
} else {
exit( __( 'Wrong nonce', 'ultimate-member' ) );
}
}
if ( $verify ) {
if ( get_query_var( 'um_action' ) == 'route' ) {
$this->request_process( array(
'route' => get_query_var( 'um_resource' ),
'method' => get_query_var( 'um_method' )
) );
}
} else {
exit( __( 'Wrong nonce', 'ultimate-member' ) );
}
}
}
}
}
+216 -203
View File
@@ -5,226 +5,239 @@ namespace um\core;
if ( ! defined( 'ABSPATH' ) ) exit;
if ( ! class_exists( 'Setup' ) ) {
class Setup {
var $setup_shortcode = array();
function __construct() {
//add_action('init', array(&$this, 'install_basics'), 9);
}
/**
* Class Setup
* @package um\core
*/
class Setup {
function run_setup() {
$this->install_basics();
$this->install_default_forms();
$this->set_default_settings();
$this->set_default_role_meta();
}
/**
* @var array
*/
var $setup_shortcode = array();
/***
*** @Basics
***/
function install_basics() {
if ( ! get_option( '__ultimatemember_sitekey' ) )
update_option( '__ultimatemember_sitekey', str_replace( array( 'http://', 'https://' ), '', sanitize_user( get_bloginfo('url') ) ) . '-' . wp_generate_password( 20, false ) );
}
/**
* Setup constructor.
*/
function __construct() {
//add_action('init', array(&$this, 'install_basics'), 9);
}
/***
*** @Default Forms
***/
function install_default_forms() {
$options = get_option( 'um_options' );
$options = empty( $options ) ? array() : $options;
if ( current_user_can( 'manage_options' ) && ! get_option( 'um_is_installed' ) ) {
update_option( 'um_is_installed', 1 );
//Install default options
foreach ( UM()->config()->settings_defaults as $key => $value ) {
$options[$key] = $value;
}
// Install Core Forms
foreach ( UM()->config()->core_forms as $id ) {
/**
If page does not exist
Create it
**/
$page_exists = UM()->query()->find_post_id( 'um_form', '_um_core', $id );
if ( ! $page_exists ) {
if ( $id == 'register' ) {
$title = 'Default Registration';
} else if ( $id == 'login' ) {
$title = 'Default Login';
} else {
$title = 'Default Profile';
}
$form = array(
'post_type' => 'um_form',
'post_title' => $title,
'post_status' => 'publish',
'post_author' => get_current_user_id(),
);
$form_id = wp_insert_post( $form );
foreach( UM()->config()->core_form_meta[$id] as $key => $value ) {
if ( $key == '_um_custom_fields' ) {
$array = unserialize( $value );
update_post_meta( $form_id, $key, $array );
} else {
update_post_meta( $form_id, $key, $value );
}
}
$this->setup_shortcode[$id] = '[ultimatemember form_id='.$form_id.']';
$core_forms[ $form_id ] = $form_id;
}
/** DONE **/
}
if ( isset( $core_forms ) )
update_option( 'um_core_forms', $core_forms );
// Install Core Directories
foreach ( UM()->config()->core_directories as $id ) {
/**
If page does not exist
Create it
**/
$page_exists = UM()->query()->find_post_id( 'um_directory', '_um_core', $id );
if ( ! $page_exists ) {
$title = 'Members';
$form = array(
'post_type' => 'um_directory',
'post_title' => $title,
'post_status' => 'publish',
'post_author' => get_current_user_id(),
);
$form_id = wp_insert_post( $form );
foreach ( UM()->config()->core_directory_meta[$id] as $key => $value ) {
if ( $key == '_um_custom_fields' ) {
$array = unserialize( $value );
update_post_meta( $form_id, $key, $array );
} else {
update_post_meta($form_id, $key, $value);
}
}
$this->setup_shortcode[$id] = '[ultimatemember form_id='.$form_id.']';
$core_directories[ $form_id ] = $form_id;
}
/** DONE **/
}
if ( isset( $core_directories ) ) update_option( 'um_core_directories', $core_directories );
/**
* Run setup
*/
function run_setup() {
$this->install_basics();
$this->install_default_forms();
$this->set_default_settings();
$this->set_default_role_meta();
}
// Install Core Pages
$core_pages = array();
foreach ( UM()->config()->core_pages as $slug => $array ) {
/**
If page does not exist
Create it
**/
$page_exists = UM()->query()->find_post_id( 'page', '_um_core', $slug );
if ( ! $page_exists ) {
if ( $slug == 'logout' ) {
$content = '';
} else if ( $slug == 'account' ) {
$content = '[ultimatemember_account]';
} else if ( $slug == 'password-reset' ) {
$content = '[ultimatemember_password]';
} else if ( $slug == 'user' ){
$content = $this->setup_shortcode['profile'];
} else {
$content = $this->setup_shortcode[$slug];
}
$user_page = array(
'post_title' => $array['title'],
'post_content' => $content,
'post_name' => $slug,
'post_type' => 'post',
'post_status' => 'publish',
'post_author' => get_current_user_id(),
'comment_status' => 'closed'
);
$post_id = wp_insert_post( $user_page );
wp_update_post( array( 'ID' => $post_id, 'post_type' => 'page' ) );
update_post_meta( $post_id, '_um_core', $slug );
$core_pages[ $slug ] = $post_id;
} else {
$core_pages[ $slug ] = $page_exists;
}
/** DONE **/
}
foreach ( $core_pages as $slug => $page_id ) {
$key = UM()->options()->get_core_page_id( $slug );
$options[ $key ] = $page_id;
}
}
update_option( 'um_options', $options );
}
/**
* Basics
*/
function install_basics() {
if ( ! get_option( '__ultimatemember_sitekey' ) )
update_option( '__ultimatemember_sitekey', str_replace( array( 'http://', 'https://' ), '', sanitize_user( get_bloginfo('url') ) ) . '-' . wp_generate_password( 20, false ) );
}
/**
* Set default UM settings
*/
function set_default_settings() {
$options = get_option( 'um_options' );
$options = empty( $options ) ? array() : $options;
/**
* Default Forms
*/
function install_default_forms() {
foreach ( UM()->config()->settings_defaults as $key => $value ) {
//set new options to default
if ( ! isset( $options[$key] ) )
$options[$key] = $value;
}
$options = get_option( 'um_options' );
$options = empty( $options ) ? array() : $options;
update_option( 'um_options', $options );
}
if ( current_user_can( 'manage_options' ) && ! get_option( 'um_is_installed' ) ) {
update_option( 'um_is_installed', 1 );
//Install default options
foreach ( UM()->config()->settings_defaults as $key => $value ) {
$options[$key] = $value;
}
// Install Core Forms
foreach ( UM()->config()->core_forms as $id ) {
/**
If page does not exist
Create it
**/
$page_exists = UM()->query()->find_post_id( 'um_form', '_um_core', $id );
if ( ! $page_exists ) {
if ( $id == 'register' ) {
$title = 'Default Registration';
} else if ( $id == 'login' ) {
$title = 'Default Login';
} else {
$title = 'Default Profile';
}
$form = array(
'post_type' => 'um_form',
'post_title' => $title,
'post_status' => 'publish',
'post_author' => get_current_user_id(),
);
$form_id = wp_insert_post( $form );
foreach( UM()->config()->core_form_meta[$id] as $key => $value ) {
if ( $key == '_um_custom_fields' ) {
$array = unserialize( $value );
update_post_meta( $form_id, $key, $array );
} else {
update_post_meta( $form_id, $key, $value );
}
}
$this->setup_shortcode[$id] = '[ultimatemember form_id='.$form_id.']';
$core_forms[ $form_id ] = $form_id;
}
/** DONE **/
}
if ( isset( $core_forms ) )
update_option( 'um_core_forms', $core_forms );
// Install Core Directories
foreach ( UM()->config()->core_directories as $id ) {
/**
If page does not exist
Create it
**/
$page_exists = UM()->query()->find_post_id( 'um_directory', '_um_core', $id );
if ( ! $page_exists ) {
$title = 'Members';
$form = array(
'post_type' => 'um_directory',
'post_title' => $title,
'post_status' => 'publish',
'post_author' => get_current_user_id(),
);
$form_id = wp_insert_post( $form );
foreach ( UM()->config()->core_directory_meta[$id] as $key => $value ) {
if ( $key == '_um_custom_fields' ) {
$array = unserialize( $value );
update_post_meta( $form_id, $key, $array );
} else {
update_post_meta($form_id, $key, $value);
}
}
$this->setup_shortcode[$id] = '[ultimatemember form_id='.$form_id.']';
$core_directories[ $form_id ] = $form_id;
}
/** DONE **/
}
if ( isset( $core_directories ) ) update_option( 'um_core_directories', $core_directories );
/**
* Set UM roles meta to Default WP roles
*/
function set_default_role_meta() {
// Install Core Pages
$core_pages = array();
foreach ( UM()->config()->core_pages as $slug => $array ) {
/**
If page does not exist
Create it
**/
$page_exists = UM()->query()->find_post_id( 'page', '_um_core', $slug );
if ( ! $page_exists ) {
if ( $slug == 'logout' ) {
$content = '';
} else if ( $slug == 'account' ) {
$content = '[ultimatemember_account]';
} else if ( $slug == 'password-reset' ) {
$content = '[ultimatemember_password]';
} else if ( $slug == 'user' ){
$content = $this->setup_shortcode['profile'];
} else {
$content = $this->setup_shortcode[$slug];
}
$user_page = array(
'post_title' => $array['title'],
'post_content' => $content,
'post_name' => $slug,
'post_type' => 'post',
'post_status' => 'publish',
'post_author' => get_current_user_id(),
'comment_status' => 'closed'
);
$post_id = wp_insert_post( $user_page );
wp_update_post( array( 'ID' => $post_id, 'post_type' => 'page' ) );
update_post_meta( $post_id, '_um_core', $slug );
$core_pages[ $slug ] = $post_id;
} else {
$core_pages[ $slug ] = $page_exists;
}
/** DONE **/
}
foreach ( $core_pages as $slug => $page_id ) {
$key = UM()->options()->get_core_page_id( $slug );
$options[ $key ] = $page_id;
}
}
update_option( 'um_options', $options );
}
/**
* Set default UM settings
*/
function set_default_settings() {
$options = get_option( 'um_options' );
$options = empty( $options ) ? array() : $options;
foreach ( UM()->config()->settings_defaults as $key => $value ) {
//set new options to default
if ( ! isset( $options[$key] ) )
$options[$key] = $value;
}
update_option( 'um_options', $options );
}
/**
* Set UM roles meta to Default WP roles
*/
function set_default_role_meta() {
//for set accounts without account status approved status
UM()->query()->count_users_by_status( 'unassigned' );
UM()->query()->count_users_by_status( 'unassigned' );
foreach ( UM()->config()->default_roles_metadata as $role => $meta ) {
update_option( "um_role_{$role}_meta", $meta );
}
}
}
foreach ( UM()->config()->default_roles_metadata as $role => $meta ) {
update_option( "um_role_{$role}_meta", $meta );
}
}
}
}
File diff suppressed because it is too large Load Diff
+170 -139
View File
@@ -5,180 +5,211 @@ namespace um\core;
if ( ! defined( 'ABSPATH' ) ) exit;
if ( ! class_exists( 'Tracking' ) ) {
class Tracking {
private $data;
public function __construct() {
$this->schedule_send();
add_action( 'admin_notices', array( $this, 'admin_notices' ), 10 );
add_action( 'um_admin_do_action__opt_into_tracking', array( $this, 'um_admin_do_action__opt_into_tracking' ) );
add_action( 'um_admin_do_action__opt_out_of_tracking', array( $this, 'um_admin_do_action__opt_out_of_tracking' ) );
}
/***
*** @Opt-in tracking
***/
function um_admin_do_action__opt_into_tracking( $action ) {
UM()->options()->update( 'um_allow_tracking', 1 );
update_option( 'um_tracking_notice', 1 );
$this->send_checkin(true);
exit( wp_redirect( remove_query_arg('um_adm_action') ) );
}
/**
* Class Tracking
* @package um\core
*/
class Tracking {
/***
*** @Opt-out of tracking
***/
function um_admin_do_action__opt_out_of_tracking( $action ) {
UM()->options()->update( 'um_allow_tracking', 0 );
update_option('um_tracking_notice', 1 );
/**
* @var
*/
private $data;
exit( wp_redirect( remove_query_arg('um_adm_action') ) );
}
/***
*** @setup info array
***/
private function setup_data() {
$data = array();
/**
* Tracking constructor.
*/
public function __construct() {
// Retrieve current theme info
if ( get_bloginfo( 'version' ) < '3.4' ) {
$theme_data = get_theme_data( get_stylesheet_directory() . '/style.css' );
$theme = $theme_data['Name'];
$theme_ver = $theme_data['Version'];
} else {
$theme_data = wp_get_theme();
$theme = $theme_data->Name;
$theme_ver = $theme_data->Version;
}
$this->schedule_send();
$data['url'] = home_url();
$data['theme'] = $theme;
$data['theme_version'] = $theme_ver;
$data['wp_version'] = get_bloginfo( 'version' );
$data['version'] = ultimatemember_version;
add_action( 'admin_notices', array( $this, 'admin_notices' ), 10 );
// Retrieve current plugin information
if( ! function_exists( 'get_plugins' ) ) {
include ABSPATH . '/wp-admin/includes/plugin.php';
}
add_action( 'um_admin_do_action__opt_into_tracking', array( $this, 'um_admin_do_action__opt_into_tracking' ) );
add_action( 'um_admin_do_action__opt_out_of_tracking', array( $this, 'um_admin_do_action__opt_out_of_tracking' ) );
}
$plugins = array_keys( get_plugins() );
$active_plugins = get_option( 'active_plugins', array() );
foreach ( $plugins as $key => $plugin ) {
if ( in_array( $plugin, $active_plugins ) ) {
// Remove active plugins from list so we can show active and inactive separately
unset( $plugins[ $key ] );
}
}
/**
* Opt-in tracking
*
* @param $action
*/
function um_admin_do_action__opt_into_tracking( $action ) {
UM()->options()->update( 'um_allow_tracking', 1 );
update_option( 'um_tracking_notice', 1 );
$data['active_plugins'] = $active_plugins;
$data['inactive_plugins'] = $plugins;
$data['language'] = get_bloginfo('language');
$data['multisite'] = ( is_multisite() ) ? 1 : 0;
$this->send_checkin(true);
UM()->setup()->install_basics();
exit( wp_redirect( remove_query_arg('um_adm_action') ) );
}
$data['email'] = get_option( 'admin_email' );
$data['unique_sitekey'] = get_option( '__ultimatemember_sitekey' );
$this->data = $data;
/**
* Opt-out of tracking
*
* @param $action
*/
function um_admin_do_action__opt_out_of_tracking( $action ) {
UM()->options()->update( 'um_allow_tracking', 0 );
update_option('um_tracking_notice', 1 );
}
exit( wp_redirect( remove_query_arg('um_adm_action') ) );
}
/***
*** @check if tracking is allowed
***/
private function tracking_allowed() {
if ( ! UM()->options()->get( 'allow_tracking' ) )
return 0;
return 1;
}
/***
*** @get last send time
***/
private function get_last_send() {
return get_option( 'um_tracking_last_send' );
}
/**
* Setup info array
*
*/
private function setup_data() {
$data = array();
/***
*** @send a report
***/
public function send_checkin( $override = false ) {
// Retrieve current theme info
if ( get_bloginfo( 'version' ) < '3.4' ) {
$theme_data = get_theme_data( get_stylesheet_directory() . '/style.css' );
$theme = $theme_data['Name'];
$theme_ver = $theme_data['Version'];
} else {
$theme_data = wp_get_theme();
$theme = $theme_data->Name;
$theme_ver = $theme_data->Version;
}
if( ! $this->tracking_allowed() && ! $override )
return;
$data['url'] = home_url();
$data['theme'] = $theme;
$data['theme_version'] = $theme_ver;
$data['wp_version'] = get_bloginfo( 'version' );
$data['version'] = ultimatemember_version;
// Send a maximum of once per period
$last_send = $this->get_last_send();
if( $last_send && $last_send > strtotime( '-1 day' ) )
return;
// Retrieve current plugin information
if( ! function_exists( 'get_plugins' ) ) {
include ABSPATH . '/wp-admin/includes/plugin.php';
}
$this->setup_data();
$plugins = array_keys( get_plugins() );
$active_plugins = get_option( 'active_plugins', array() );
if ( !get_option('__ultimatemember_coupon_sent') ) {
$this->data['send_discount'] = 1;
} else {
$this->data['send_discount'] = 0;
}
foreach ( $plugins as $key => $plugin ) {
if ( in_array( $plugin, $active_plugins ) ) {
// Remove active plugins from list so we can show active and inactive separately
unset( $plugins[ $key ] );
}
}
$request = wp_remote_post( 'https://ultimatemember.com/?um_action=checkin', array(
'method' => 'POST',
'timeout' => 20,
'redirection' => 5,
'httpversion' => '1.0',
'blocking' => true,
'body' => $this->data,
'user-agent' => 'UM/' . ultimatemember_version . '; ' . get_bloginfo( 'url' ),
) );
$data['active_plugins'] = $active_plugins;
$data['inactive_plugins'] = $plugins;
$data['language'] = get_bloginfo('language');
$data['multisite'] = ( is_multisite() ) ? 1 : 0;
update_option( 'um_tracking_last_send', time() );
update_option( '__ultimatemember_coupon_sent', 1 );
}
UM()->setup()->install_basics();
/***
*** @run a scheduled report
***/
private function schedule_send() {
add_action( 'um_daily_scheduled_events', array( $this, 'send_checkin' ) );
}
$data['email'] = get_option( 'admin_email' );
$data['unique_sitekey'] = get_option( '__ultimatemember_sitekey' );
/***
*** @show admin notices
***/
public function admin_notices() {
$this->data = $data;
if( ! current_user_can( 'manage_options' ) )
return;
}
$hide_notice = get_option('um_tracking_notice');
if ( $hide_notice )
return;
/**
* Check if tracking is allowed
*
* @return int
*/
private function tracking_allowed() {
if ( ! UM()->options()->get( 'allow_tracking' ) )
return 0;
return 1;
}
$optin_url = esc_url( add_query_arg( 'um_adm_action', 'opt_into_tracking' ) );
$optout_url = esc_url( add_query_arg( 'um_adm_action', 'opt_out_of_tracking' ) );
echo '<div class="updated um-admin-notice"><p>';
/**
* Get last send time
*
* @return mixed|void
*/
private function get_last_send() {
return get_option( 'um_tracking_last_send' );
}
printf( __( 'Thanks for installing <strong>%s</strong>! The core plugin is free but we also sell extensions which allow us to continue developing and supporting the plugin full time. If you subscribe to our mailing list (no spam) we will email you a 20%% discount code which you can use to purchase the <a href="%s" target="_blank">extensions bundle</a>.', 'ultimate-member' ), ultimatemember_plugin_name, 'https://ultimatemember.com/core-extensions-bundle/' );
echo '</p>';
/**
* Send a report
*
* @param bool $override
*/
public function send_checkin( $override = false ) {
echo '<p><a href="' . esc_url( $optin_url ) . '" class="button button-primary">' . __( 'Subscribe to mailing list', 'ultimate-member' ) . '</a>';
echo '&nbsp;<a href="' . esc_url( $optout_url ) . '" class="button-secondary">' . __( 'No thanks', 'ultimate-member' ) . '</a></p></div>';
if( ! $this->tracking_allowed() && ! $override )
return;
}
// Send a maximum of once per period
$last_send = $this->get_last_send();
if( $last_send && $last_send > strtotime( '-1 day' ) )
return;
}
$this->setup_data();
if ( !get_option('__ultimatemember_coupon_sent') ) {
$this->data['send_discount'] = 1;
} else {
$this->data['send_discount'] = 0;
}
$request = wp_remote_post( 'https://ultimatemember.com/?um_action=checkin', array(
'method' => 'POST',
'timeout' => 20,
'redirection' => 5,
'httpversion' => '1.0',
'blocking' => true,
'body' => $this->data,
'user-agent' => 'UM/' . ultimatemember_version . '; ' . get_bloginfo( 'url' ),
) );
update_option( 'um_tracking_last_send', time() );
update_option( '__ultimatemember_coupon_sent', 1 );
}
/**
* Run a scheduled report
*/
private function schedule_send() {
add_action( 'um_daily_scheduled_events', array( $this, 'send_checkin' ) );
}
/**
* Show admin notices
*/
public function admin_notices() {
if( ! current_user_can( 'manage_options' ) )
return;
$hide_notice = get_option('um_tracking_notice');
if ( $hide_notice )
return;
$optin_url = esc_url( add_query_arg( 'um_adm_action', 'opt_into_tracking' ) );
$optout_url = esc_url( add_query_arg( 'um_adm_action', 'opt_out_of_tracking' ) );
echo '<div class="updated um-admin-notice"><p>';
printf( __( 'Thanks for installing <strong>%s</strong>! The core plugin is free but we also sell extensions which allow us to continue developing and supporting the plugin full time. If you subscribe to our mailing list (no spam) we will email you a 20%% discount code which you can use to purchase the <a href="%s" target="_blank">extensions bundle</a>.', 'ultimate-member' ), ultimatemember_plugin_name, 'https://ultimatemember.com/core-extensions-bundle/' );
echo '</p>';
echo '<p><a href="' . esc_url( $optin_url ) . '" class="button button-primary">' . __( 'Subscribe to mailing list', 'ultimate-member' ) . '</a>';
echo '&nbsp;<a href="' . esc_url( $optout_url ) . '" class="button-secondary">' . __( 'No thanks', 'ultimate-member' ) . '</a></p></div>';
}
}
}
+1441 -1425
View File
File diff suppressed because it is too large Load Diff
+104 -93
View File
@@ -1,108 +1,119 @@
<?php
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) exit;
<?php if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
/**
* Processes the requests of UM actions
*/
add_action('init','um_action_request_process', 10);
function um_action_request_process(){
if ( is_admin() ) return false;
if ( ! is_user_logged_in() ) return false;
if ( ! isset( $_REQUEST['um_action'] ) ) return false;
if ( isset( $_REQUEST['uid'] ) && ! UM()->user()->user_exists_by_id( $_REQUEST['uid'] ) ) return false;
if ( isset( $_REQUEST['uid'] ) ) {
if ( is_super_admin( $_REQUEST['uid'] ) )
wp_die( __( 'Super administrators can not be modified.','ultimate-member' ) );
}
if ( isset( $_REQUEST['um_action'] ) && $_REQUEST['um_action'] != "edit" && ! current_user_can( 'edit_users' ) ) {
wp_die( __( 'You do not have enough permissions to do that.','ultimate-member') );
/**
* Processes the requests of UM actions
*
*/
function um_action_request_process() {
if ( is_admin() ) {
return;
}
if ( ! is_user_logged_in() ) {
return;
}
if ( ! isset( $_REQUEST['um_action'] ) ) {
return;
}
if ( isset( $_REQUEST['uid'] ) && ! UM()->user()->user_exists_by_id( $_REQUEST['uid'] ) ) {
return;
}
if ( isset( $_REQUEST['uid'] ) ) {
if ( is_super_admin( $_REQUEST['uid'] ) ) {
wp_die( __( 'Super administrators can not be modified.','ultimate-member' ) );
}
}
if ( isset( $_REQUEST['uid'] ) ) {
$uid = $_REQUEST['uid'];
}
if ( isset( $_REQUEST['um_action'] ) && $_REQUEST['um_action'] != "edit" && ! current_user_can( 'edit_users' ) ) {
wp_die( __( 'You do not have enough permissions to do that.','ultimate-member') );
}
if ( isset( $_REQUEST['uid'] ) ) {
$uid = $_REQUEST['uid'];
}
switch ( $_REQUEST['um_action'] ) {
switch ( $_REQUEST['um_action'] ) {
default:
$uid = isset( $_REQUEST['uid'] ) ? $_REQUEST['uid'] : 0;
/**
* UM hook
*
* @type action
* @title um_action_user_request_hook
* @description Integration for user actions
* @input_vars
* [{"var":"$action","type":"string","desc":"Action for user"},
* {"var":"$user_id","type":"int","desc":"User ID"}]
* @change_log
* ["Since: 2.0"]
* @usage add_action( 'um_action_user_request_hook', 'function_name', 10, 2 );
* @example
* <?php
* add_action( 'um_action_user_request_hook', 'my_action_user_request', 10, 2 );
* function my_action_user_request( $action, $user_id ) {
* // your code here
* }
* ?>
*/
do_action( 'um_action_user_request_hook', $_REQUEST['um_action'], $uid );
break;
default:
$uid = isset( $_REQUEST['uid'] ) ? $_REQUEST['uid'] : 0;
/**
* UM hook
*
* @type action
* @title um_action_user_request_hook
* @description Integration for user actions
* @input_vars
* [{"var":"$action","type":"string","desc":"Action for user"},
* {"var":"$user_id","type":"int","desc":"User ID"}]
* @change_log
* ["Since: 2.0"]
* @usage add_action( 'um_action_user_request_hook', 'function_name', 10, 2 );
* @example
* <?php
* add_action( 'um_action_user_request_hook', 'my_action_user_request', 10, 2 );
* function my_action_user_request( $action, $user_id ) {
* // your code here
* }
* ?>
*/
do_action( 'um_action_user_request_hook', $_REQUEST['um_action'], $uid );
break;
case 'edit':
UM()->fields()->editing = true;
if ( !um_can_edit_my_profile() ) {
$url = um_edit_my_profile_cancel_uri();
exit( wp_redirect( $url ) );
}
break;
case 'edit':
UM()->fields()->editing = true;
if ( !um_can_edit_my_profile() ) {
$url = um_edit_my_profile_cancel_uri();
exit( wp_redirect( $url ) );
}
break;
case 'um_switch_user':
if ( !current_user_can('delete_users') ) return;
UM()->user()->auto_login( $_REQUEST['uid'] );
exit( wp_redirect( UM()->permalinks()->get_current_url( true ) ) );
break;
case 'um_switch_user':
if ( !current_user_can('delete_users') ) {
return;
}
UM()->user()->auto_login( $_REQUEST['uid'] );
exit( wp_redirect( UM()->permalinks()->get_current_url( true ) ) );
break;
case 'um_reject_membership':
um_fetch_user( $uid );
UM()->user()->reject();
exit( wp_redirect( UM()->permalinks()->get_current_url( true ) ) );
break;
case 'um_reject_membership':
um_fetch_user( $uid );
UM()->user()->reject();
exit( wp_redirect( UM()->permalinks()->get_current_url( true ) ) );
break;
case 'um_approve_membership':
case 'um_reenable':
um_fetch_user( $uid );
UM()->user()->approve();
exit( wp_redirect( UM()->permalinks()->get_current_url( true ) ) );
break;
case 'um_approve_membership':
case 'um_reenable':
um_fetch_user( $uid );
UM()->user()->approve();
exit( wp_redirect( UM()->permalinks()->get_current_url( true ) ) );
break;
case 'um_put_as_pending':
um_fetch_user( $uid );
UM()->user()->pending();
exit( wp_redirect( UM()->permalinks()->get_current_url( true ) ) );
break;
case 'um_put_as_pending':
um_fetch_user( $uid );
UM()->user()->pending();
exit( wp_redirect( UM()->permalinks()->get_current_url( true ) ) );
break;
case 'um_resend_activation':
um_fetch_user( $uid );
UM()->user()->email_pending();
exit( wp_redirect( UM()->permalinks()->get_current_url( true ) ) );
break;
case 'um_resend_activation':
um_fetch_user( $uid );
UM()->user()->email_pending();
exit( wp_redirect( UM()->permalinks()->get_current_url( true ) ) );
break;
case 'um_deactivate':
um_fetch_user( $uid );
UM()->user()->deactivate();
exit( wp_redirect( UM()->permalinks()->get_current_url( true ) ) );
break;
case 'um_deactivate':
um_fetch_user( $uid );
UM()->user()->deactivate();
exit( wp_redirect( UM()->permalinks()->get_current_url( true ) ) );
break;
case 'um_delete':
if ( ! UM()->roles()->um_current_user_can( 'delete', $uid ) ) wp_die( __('You do not have permission to delete this user.','ultimate-member') );
um_fetch_user( $uid );
UM()->user()->delete();
exit( wp_redirect( UM()->permalinks()->get_current_url( true ) ) );
break;
case 'um_delete':
if ( ! UM()->roles()->um_current_user_can( 'delete', $uid ) ) wp_die( __('You do not have permission to delete this user.','ultimate-member') );
um_fetch_user( $uid );
UM()->user()->delete();
exit( wp_redirect( UM()->permalinks()->get_current_url( true ) ) );
break;
}
}
}
}
add_action( 'init', 'um_action_request_process', 10 );
File diff suppressed because it is too large Load Diff
+55 -48
View File
@@ -1,57 +1,64 @@
<?php
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) exit;
<?php if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
/***
*** @adds a form identifier to form
***/
add_action('um_after_form_fields', 'um_add_form_identifier');
function um_add_form_identifier($args){ ?>
/**
* Adds a form identifier to form
*
* @param $args
*/
function um_add_form_identifier( $args ) {
?>
<input type="hidden" name="form_id" id="form_id_<?php echo $args['form_id']; ?>" value="<?php echo $args['form_id']; ?>" />
<?php
}
add_action( 'um_after_form_fields', 'um_add_form_identifier' );
<?php
}
/***
*** @adds a spam timestamp
***/
add_action('um_after_form_fields', 'um_add_security_checks');
add_action('um_account_page_hidden_fields', 'um_add_security_checks');
function um_add_security_checks($args){
if ( is_admin() ) return;
/**
* Adds a spam timestamp
*
* @param $args
*/
function um_add_security_checks( $args ) {
if ( is_admin() ) {
return;
} ?>
echo '<input type="hidden" name="timestamp" class="um_timestamp" value="'. current_time( 'timestamp' ) .'" />';
<input type="hidden" name="timestamp" class="um_timestamp" value="<?php echo current_time( 'timestamp' ) ?>" />
?>
<p class="<?php echo UM()->honeypot; ?>_name">
<label for="<?php echo UM()->honeypot . '_' . $args['form_id']; ?>"><?php _e( 'Only fill in if you are not human' ); ?></label>
<input type="text" name="<?php echo UM()->honeypot; ?>" id="<?php echo UM()->honeypot . '_' . $args['form_id']; ?>" class="input" value="" size="25" autocomplete="off" />
</p>
<?php
}
/***
*** @makes the honeypot invisible
***/
add_action('wp_head', 'um_add_form_honeypot_css');
function um_add_form_honeypot_css() { ?>
<style type="text/css">.<?php echo UM()->honeypot; ?>_name { display: none !important; }</style>
<?php }
/***
*** @empty the honeypot value
***/
add_action('wp_footer', 'um_add_form_honeypot_js', 99999999999999999 );
function um_add_form_honeypot_js() { ?>
<script type="text/javascript">jQuery( '#<?php echo UM()->honeypot; ?>' ).val( '' );</script>
<p class="<?php echo UM()->honeypot; ?>_name">
<label for="<?php echo UM()->honeypot . '_' . $args['form_id']; ?>"><?php _e( 'Only fill in if you are not human' ); ?></label>
<input type="text" name="<?php echo UM()->honeypot; ?>" id="<?php echo UM()->honeypot . '_' . $args['form_id']; ?>" class="input" value="" size="25" autocomplete="off" />
</p>
<?php
}
}
add_action( 'um_after_form_fields', 'um_add_security_checks' );
add_action( 'um_account_page_hidden_fields', 'um_add_security_checks' );
/**
* Makes the honeypot invisible
*/
function um_add_form_honeypot_css() {
?>
<style type="text/css">
.<?php echo UM()->honeypot; ?>_name {
display: none !important;
}
</style>
<?php
}
add_action( 'wp_head', 'um_add_form_honeypot_css' );
/**
* Empty the honeypot value
*/
function um_add_form_honeypot_js() {
?>
<script type="text/javascript">
jQuery( '#<?php echo UM()->honeypot; ?>' ).val( '' );
</script>
<?php
}
add_action( 'wp_footer', 'um_add_form_honeypot_js', 99999999999999999 );
+374 -345
View File
@@ -3,104 +3,108 @@
if ( ! defined( 'ABSPATH' ) ) exit;
/**
* Error procesing hook for login
*/
add_action('um_submit_form_errors_hook_login', 'um_submit_form_errors_hook_login', 10);
function um_submit_form_errors_hook_login( $args ){
$is_email = false;
/**
* Error procesing hook for login
*
* @param $args
*/
function um_submit_form_errors_hook_login( $args ) {
$is_email = false;
$form_id = $args['form_id'];
$mode = $args['mode'];
$user_password = $args['user_password'];
$form_id = $args['form_id'];
$mode = $args['mode'];
$user_password = $args['user_password'];
if ( isset( $args['username'] ) && $args['username'] == '' ) {
UM()->form()->add_error( 'username', __('Please enter your username or email','ultimate-member') );
}
if ( isset( $args['username'] ) && $args['username'] == '' ) {
UM()->form()->add_error( 'username', __('Please enter your username or email','ultimate-member') );
}
if ( isset( $args['user_login'] ) && $args['user_login'] == '' ) {
UM()->form()->add_error( 'user_login', __('Please enter your username','ultimate-member') );
}
if ( isset( $args['user_login'] ) && $args['user_login'] == '' ) {
UM()->form()->add_error( 'user_login', __('Please enter your username','ultimate-member') );
}
if ( isset( $args['user_email'] ) && $args['user_email'] == '' ) {
UM()->form()->add_error( 'user_email', __('Please enter your email','ultimate-member') );
}
if ( isset( $args['user_email'] ) && $args['user_email'] == '' ) {
UM()->form()->add_error( 'user_email', __('Please enter your email','ultimate-member') );
}
if ( isset( $args['username'] ) ) {
$field = 'username';
if ( is_email( $args['username'] ) ) {
$is_email = true;
$data = get_user_by('email', $args['username'] );
$user_name = (isset ( $data->user_login ) ) ? $data->user_login : null;
} else {
$user_name = $args['username'];
}
} else if ( isset( $args['user_email'] ) ) {
$field = 'user_email';
$is_email = true;
$data = get_user_by('email', $args['user_email'] );
$user_name = (isset ( $data->user_login ) ) ? $data->user_login : null;
if ( isset( $args['username'] ) ) {
$field = 'username';
if ( is_email( $args['username'] ) ) {
$is_email = true;
$data = get_user_by('email', $args['username'] );
$user_name = (isset ( $data->user_login ) ) ? $data->user_login : null;
} else {
$field = 'user_login';
$user_name = $args['user_login'];
$user_name = $args['username'];
}
} else if ( isset( $args['user_email'] ) ) {
$field = 'user_email';
$is_email = true;
$data = get_user_by('email', $args['user_email'] );
$user_name = (isset ( $data->user_login ) ) ? $data->user_login : null;
} else {
$field = 'user_login';
$user_name = $args['user_login'];
}
if ( !username_exists( $user_name ) ) {
if ( $is_email ) {
UM()->form()->add_error( $field, __(' Sorry, we can\'t find an account with that email address','ultimate-member') );
} else {
UM()->form()->add_error( $field, __(' Sorry, we can\'t find an account with that username','ultimate-member') );
}
if ( !username_exists( $user_name ) ) {
if ( $is_email ) {
UM()->form()->add_error( $field, __(' Sorry, we can\'t find an account with that email address','ultimate-member') );
} else {
if ( $args['user_password'] == '' ) {
UM()->form()->add_error( 'user_password', __('Please enter your password','ultimate-member') );
}
UM()->form()->add_error( $field, __(' Sorry, we can\'t find an account with that username','ultimate-member') );
}
$user = get_user_by( 'login', $user_name );
if ( $user && wp_check_password( $args['user_password'], $user->data->user_pass, $user->ID) ) {
UM()->login()->auth_id = username_exists( $user_name );
} else {
UM()->form()->add_error( 'user_password', __('Password is incorrect. Please try again.','ultimate-member') );
}
$user = apply_filters( 'authenticate', null, $user_name, $args['user_password'] );
$authenticate_user = apply_filters( 'wp_authenticate_user', $user_name, $args['user_password'] );
// @since 4.18 replacement for 'wp_login_failed' action hook
// see WP function wp_authenticate()
$ignore_codes = array('empty_username', 'empty_password');
if ( is_wp_error( $user ) && ! in_array( $user->get_error_code(), $ignore_codes ) ) {
UM()->form()->add_error( $user->get_error_code(), __( $user->get_error_message() ,'ultimate-member') );
}
if( is_wp_error( $authenticate_user ) && ! in_array( $authenticate_user->get_error_code(), $ignore_codes ) ){
UM()->form()->add_error( $authenticate_user->get_error_code(), __( $authenticate_user->get_error_message() ,'ultimate-member') );
}
// if there is an error notify wp
if( UM()->form()->has_error( $field ) || UM()->form()->has_error( $user_password ) || UM()->form()->count_errors() > 0 ) {
do_action( 'wp_login_failed', $user_name );
} else {
if ( $args['user_password'] == '' ) {
UM()->form()->add_error( 'user_password', __('Please enter your password','ultimate-member') );
}
}
/**
* Display the login errors from other plugins
*/
add_action( 'um_before_login_fields', 'um_display_login_errors' );
function um_display_login_errors( $args ) {
$error = '';
$user = get_user_by( 'login', $user_name );
if ( $user && wp_check_password( $args['user_password'], $user->data->user_pass, $user->ID) ) {
UM()->login()->auth_id = username_exists( $user_name );
} else {
UM()->form()->add_error( 'user_password', __('Password is incorrect. Please try again.','ultimate-member') );
}
$user = apply_filters( 'authenticate', null, $user_name, $args['user_password'] );
$authenticate_user = apply_filters( 'wp_authenticate_user', $user_name, $args['user_password'] );
// @since 4.18 replacement for 'wp_login_failed' action hook
// see WP function wp_authenticate()
$ignore_codes = array('empty_username', 'empty_password');
if ( is_wp_error( $user ) && ! in_array( $user->get_error_code(), $ignore_codes ) ) {
UM()->form()->add_error( $user->get_error_code(), __( $user->get_error_message() ,'ultimate-member') );
}
if( is_wp_error( $authenticate_user ) && ! in_array( $authenticate_user->get_error_code(), $ignore_codes ) ){
UM()->form()->add_error( $authenticate_user->get_error_code(), __( $authenticate_user->get_error_message() ,'ultimate-member') );
}
// if there is an error notify wp
if( UM()->form()->has_error( $field ) || UM()->form()->has_error( $user_password ) || UM()->form()->count_errors() > 0 ) {
do_action( 'wp_login_failed', $user_name );
}
}
add_action( 'um_submit_form_errors_hook_login', 'um_submit_form_errors_hook_login', 10 );
/**
* Display the login errors from other plugins
*
* @param $args
*/
function um_display_login_errors( $args ) {
$error = '';
if( UM()->form()->count_errors() > 0 ) {
$errors = UM()->form()->errors;
// hook for other plugins to display error
$error_keys = array_keys( $errors );
if( UM()->form()->count_errors() > 0 ) {
$errors = UM()->form()->errors;
// hook for other plugins to display error
$error_keys = array_keys( $errors );
}
if( isset( $args['custom_fields'] ) ){
@@ -116,339 +120,364 @@ if ( ! defined( 'ABSPATH' ) ) exit;
}
}
}
add_action( 'um_before_login_fields', 'um_display_login_errors' );
/***
*** @login checks thru the frontend login
***/
add_action('um_submit_form_errors_hook_logincheck', 'um_submit_form_errors_hook_logincheck', 9999 );
function um_submit_form_errors_hook_logincheck($args){
// Logout if logged in
if ( is_user_logged_in() ) {
wp_logout();
}
$user_id = ( isset( UM()->login()->auth_id ) ) ? UM()->login()->auth_id : '';
um_fetch_user( $user_id );
/**
* Login checks thru the frontend login
*
* @param $args
*/
function um_submit_form_errors_hook_logincheck( $args ) {
// Logout if logged in
if ( is_user_logged_in() ) {
wp_logout();
}
$status = um_user('account_status'); // account status
switch( $status ) {
$user_id = ( isset( UM()->login()->auth_id ) ) ? UM()->login()->auth_id : '';
um_fetch_user( $user_id );
// If user can't login to site...
case 'inactive':
case 'awaiting_admin_review':
case 'awaiting_email_confirmation':
case 'rejected':
um_reset_user();
exit( wp_redirect( add_query_arg( 'err', esc_attr( $status ), UM()->permalinks()->get_current_url() ) ) );
break;
$status = um_user('account_status'); // account status
switch( $status ) {
}
if ( isset( $args['form_id'] ) && $args['form_id'] == UM()->shortcodes()->core_login_form() && UM()->form()->errors && !isset( $_POST[ UM()->honeypot ] ) ) {
exit( wp_redirect( um_get_core_page('login') ) );
}
// If user can't login to site...
case 'inactive':
case 'awaiting_admin_review':
case 'awaiting_email_confirmation':
case 'rejected':
um_reset_user();
exit( wp_redirect( add_query_arg( 'err', esc_attr( $status ), UM()->permalinks()->get_current_url() ) ) );
break;
}
/***
*** @store last login timestamp
***/
add_action('um_on_login_before_redirect', 'um_store_lastlogin_timestamp', 10, 1);
function um_store_lastlogin_timestamp( $user_id ) {
update_user_meta( $user_id, '_um_last_login', current_time( 'timestamp' ) );
if ( isset( $args['form_id'] ) && $args['form_id'] == UM()->shortcodes()->core_login_form() && UM()->form()->errors && !isset( $_POST[ UM()->honeypot ] ) ) {
exit( wp_redirect( um_get_core_page('login') ) );
}
add_action( 'wp_login', 'um_store_lastlogin_timestamp_' );
function um_store_lastlogin_timestamp_( $login ) {
$user = get_user_by('login',$login);
um_store_lastlogin_timestamp( $user->ID );
}
add_action( 'um_submit_form_errors_hook_logincheck', 'um_submit_form_errors_hook_logincheck', 9999 );
/**
* Store last login timestamp
*
* @param $user_id
*/
function um_store_lastlogin_timestamp( $user_id ) {
update_user_meta( $user_id, '_um_last_login', current_time( 'timestamp' ) );
}
add_action( 'um_on_login_before_redirect', 'um_store_lastlogin_timestamp', 10, 1 );
/**
* @param $login
*/
function um_store_lastlogin_timestamp_( $login ) {
$user = get_user_by( 'login', $login );
um_store_lastlogin_timestamp( $user->ID );
}
add_action( 'wp_login', 'um_store_lastlogin_timestamp_' );
/**
* Login user process
*
* @param array $args
*/
function um_user_login( $args ) {
extract( $args );
$rememberme = ( isset( $args['rememberme'] ) && 1 == $args['rememberme'] && isset( $_REQUEST['rememberme'] ) ) ? 1 : 0;
if ( ( UM()->options()->get('deny_admin_frontend_login') && ! isset( $_GET['provider'] ) ) && strrpos( um_user('wp_roles' ), 'administrator' ) !== false ) {
wp_die( __('This action has been prevented for security measures.','ultimate-member') );
}
UM()->user()->auto_login( um_user( 'ID' ), $rememberme );
/**
* Login user process
* UM hook
*
* @param array $args
* @type action
* @title um_on_login_before_redirect
* @description Hook that runs after successful login and before user is redirected
* @input_vars
* [{"var":"$user_id","type":"int","desc":"User ID"}]
* @change_log
* ["Since: 2.0"]
* @usage add_action( 'um_on_login_before_redirect', 'function_name', 10, 1 );
* @example
* <?php
* add_action( 'um_on_login_before_redirect', 'my_on_login_before_redirect', 10, 1 );
* function my_on_login_before_redirect( $user_id ) {
* // your code here
* }
* ?>
*/
function um_user_login( $args ) {
extract( $args );
do_action( 'um_on_login_before_redirect', um_user( 'ID' ) );
$rememberme = ( isset( $args['rememberme'] ) && 1 == $args['rememberme'] && isset( $_REQUEST['rememberme'] ) ) ? 1 : 0;
if ( ( UM()->options()->get('deny_admin_frontend_login') && ! isset( $_GET['provider'] ) ) && strrpos( um_user('wp_roles' ), 'administrator' ) !== false ) {
wp_die( __('This action has been prevented for security measures.','ultimate-member') );
}
UM()->user()->auto_login( um_user( 'ID' ), $rememberme );
/**
* UM hook
*
* @type action
* @title um_on_login_before_redirect
* @description Hook that runs after successful login and before user is redirected
* @input_vars
* [{"var":"$user_id","type":"int","desc":"User ID"}]
* @change_log
* ["Since: 2.0"]
* @usage add_action( 'um_on_login_before_redirect', 'function_name', 10, 1 );
* @example
* <?php
* add_action( 'um_on_login_before_redirect', 'my_on_login_before_redirect', 10, 1 );
* function my_on_login_before_redirect( $user_id ) {
* // your code here
* }
* ?>
*/
do_action( 'um_on_login_before_redirect', um_user( 'ID' ) );
// Priority redirect
if ( ! empty( $args['redirect_to'] ) ) {
exit( wp_redirect( $args['redirect_to'] ) );
}
// Role redirect
$after_login = um_user( 'after_login' );
if ( empty( $after_login ) )
exit( wp_redirect( um_user_profile_url() ) );
switch( $after_login ) {
case 'redirect_admin':
exit( wp_redirect( admin_url() ) );
break;
case '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
* <?php add_filter( 'um_login_redirect_url', 'function_name', 10, 2 ); ?>
* @example
* <?php
* add_filter( 'um_login_redirect_url', 'my_login_redirect_url', 10, 2 );
* function my_login_redirect_url( $url, $id ) {
* // your code here
* return $url;
* }
* ?>
*/
$redirect_url = apply_filters( 'um_login_redirect_url', um_user( 'login_redirect_url' ), um_user( 'ID' ) );
exit( wp_redirect( $redirect_url ) );
break;
case 'refresh':
exit( wp_redirect( UM()->permalinks()->get_current_url() ) );
break;
case 'redirect_profile':
default:
exit( wp_redirect( um_user_profile_url() ) );
break;
}
// Priority redirect
if ( ! empty( $args['redirect_to'] ) ) {
exit( wp_redirect( $args['redirect_to'] ) );
}
add_action( 'um_user_login', 'um_user_login', 10 );
// Role redirect
$after_login = um_user( 'after_login' );
if ( empty( $after_login ) )
exit( wp_redirect( um_user_profile_url() ) );
/***
*** @form processing
***/
add_action( 'um_submit_form_login', 'um_submit_form_login', 10 );
function um_submit_form_login( $args ) {
switch( $after_login ) {
if ( ! isset( UM()->form()->errors ) ) {
case 'redirect_admin':
exit( wp_redirect( admin_url() ) );
break;
case 'redirect_url':
/**
* UM hook
*
* @type action
* @title um_user_login
* @description Hook that runs after successful submit login form
* @type filter
* @title um_login_redirect_url
* @description Change redirect URL after successful login
* @input_vars
* [{"var":"$args","type":"array","desc":"Form data"}]
* [{"var":"$url","type":"string","desc":"Redirect URL"},
* {"var":"$id","type":"int","desc":"User ID"}]
* @change_log
* ["Since: 2.0"]
* @usage add_action( 'um_user_login', 'function_name', 10, 1 );
* @usage
* <?php add_filter( 'um_login_redirect_url', 'function_name', 10, 2 ); ?>
* @example
* <?php
* add_action( 'um_user_login', 'my_user_login', 10, 1 );
* function my_user_login( $args ) {
* add_filter( 'um_login_redirect_url', 'my_login_redirect_url', 10, 2 );
* function my_login_redirect_url( $url, $id ) {
* // your code here
* return $url;
* }
* ?>
*/
do_action( 'um_user_login', $args );
}
$redirect_url = apply_filters( 'um_login_redirect_url', um_user( 'login_redirect_url' ), um_user( 'ID' ) );
exit( wp_redirect( $redirect_url ) );
break;
case 'refresh':
exit( wp_redirect( UM()->permalinks()->get_current_url() ) );
break;
case 'redirect_profile':
default:
exit( wp_redirect( um_user_profile_url() ) );
break;
}
}
add_action( 'um_user_login', 'um_user_login', 10 );
/**
* Form processing
*
* @param $args
*/
function um_submit_form_login( $args ) {
if ( ! isset( UM()->form()->errors ) ) {
/**
* UM hook
*
* @type action
* @title um_user_login_extra_hook
* @title um_user_login
* @description Hook that runs after successful submit login form
* @input_vars
* [{"var":"$args","type":"array","desc":"Form data"}]
* @change_log
* ["Since: 2.0"]
* @usage add_action( 'um_user_login_extra_hook', 'function_name', 10, 1 );
* @usage add_action( 'um_user_login', 'function_name', 10, 1 );
* @example
* <?php
* add_action( 'um_user_login_extra_hook', 'my_user_login_extra', 10, 1 );
* function my_user_login_extra( $args ) {
* add_action( 'um_user_login', 'my_user_login', 10, 1 );
* function my_user_login( $args ) {
* // your code here
* }
* ?>
*/
do_action( 'um_user_login_extra_hook', $args );
do_action( 'um_user_login', $args );
}
/***
*** @Show the submit button
***/
add_action('um_after_login_fields', 'um_add_submit_button_to_login', 1000);
function um_add_submit_button_to_login($args){
// DO NOT add when reviewing user's details
if ( UM()->user()->preview == true && is_admin() ) return;
/**
* UM hook
*
* @type action
* @title um_user_login_extra_hook
* @description Hook that runs after successful submit login form
* @input_vars
* [{"var":"$args","type":"array","desc":"Form data"}]
* @change_log
* ["Since: 2.0"]
* @usage add_action( 'um_user_login_extra_hook', 'function_name', 10, 1 );
* @example
* <?php
* add_action( 'um_user_login_extra_hook', 'my_user_login_extra', 10, 1 );
* function my_user_login_extra( $args ) {
* // your code here
* }
* ?>
*/
do_action( 'um_user_login_extra_hook', $args );
}
add_action( 'um_submit_form_login', 'um_submit_form_login', 10 );
$primary_btn_word = $args['primary_btn_word'];
/**
* UM hook
*
* @type filter
* @title um_login_form_button_one
* @description Change Login Form Primary button
* @input_vars
* [{"var":"$primary_btn_word","type":"string","desc":"Button text"},
* {"var":"$args","type":"array","desc":"Login Form arguments"}]
* @change_log
* ["Since: 2.0"]
* @usage
* <?php add_filter( 'um_login_form_button_one', 'function_name', 10, 2 ); ?>
* @example
* <?php
* add_filter( 'um_login_form_button_one', 'my_login_form_button_one', 10, 2 );
* function my_login_form_button_one( $primary_btn_word, $args ) {
* // your code here
* return $primary_btn_word;
* }
* ?>
*/
$primary_btn_word = apply_filters('um_login_form_button_one', $primary_btn_word, $args );
$secondary_btn_word = $args['secondary_btn_word'];
/**
* UM hook
*
* @type filter
* @title um_login_form_button_two
* @description Change Login Form Secondary button
* @input_vars
* [{"var":"$secondary_btn_word","type":"string","desc":"Button text"},
* {"var":"$args","type":"array","desc":"Login Form arguments"}]
* @change_log
* ["Since: 2.0"]
* @usage
* <?php add_filter( 'um_login_form_button_two', 'function_name', 10, 2 ); ?>
* @example
* <?php
* add_filter( 'um_login_form_button_two', 'my_login_form_button_two', 10, 2 );
* function my_login_form_button_two( $secondary_btn_word, $args ) {
* // your code here
* return $secondary_btn_word;
* }
* ?>
*/
$secondary_btn_word = apply_filters('um_login_form_button_two', $secondary_btn_word, $args );
/**
* Show the submit button
*
* @param $args
*/
function um_add_submit_button_to_login( $args ) {
// DO NOT add when reviewing user's details
if ( UM()->user()->preview == true && is_admin() ) return;
$secondary_btn_url = ( isset( $args['secondary_btn_url'] ) && $args['secondary_btn_url'] ) ? $args['secondary_btn_url'] : um_get_core_page('register');
/**
* UM hook
*
* @type filter
* @title um_login_form_button_two_url
* @description Change Login Form Secondary button URL
* @input_vars
* [{"var":"$secondary_btn_url","type":"string","desc":"Button URL"},
* {"var":"$args","type":"array","desc":"Login Form arguments"}]
* @change_log
* ["Since: 2.0"]
* @usage
* <?php add_filter( 'um_login_form_button_two_url', 'function_name', 10, 2 ); ?>
* @example
* <?php
* add_filter( 'um_login_form_button_two_url', 'my_login_form_button_two_url', 10, 2 );
* function my_login_form_button_two_url( $secondary_btn_url, $args ) {
* // your code here
* return $secondary_btn_url;
* }
* ?>
*/
$secondary_btn_url = apply_filters('um_login_form_button_two_url', $secondary_btn_url, $args );
$primary_btn_word = $args['primary_btn_word'];
/**
* UM hook
*
* @type filter
* @title um_login_form_button_one
* @description Change Login Form Primary button
* @input_vars
* [{"var":"$primary_btn_word","type":"string","desc":"Button text"},
* {"var":"$args","type":"array","desc":"Login Form arguments"}]
* @change_log
* ["Since: 2.0"]
* @usage
* <?php add_filter( 'um_login_form_button_one', 'function_name', 10, 2 ); ?>
* @example
* <?php
* add_filter( 'um_login_form_button_one', 'my_login_form_button_one', 10, 2 );
* function my_login_form_button_one( $primary_btn_word, $args ) {
* // your code here
* return $primary_btn_word;
* }
* ?>
*/
$primary_btn_word = apply_filters('um_login_form_button_one', $primary_btn_word, $args );
?>
$secondary_btn_word = $args['secondary_btn_word'];
/**
* UM hook
*
* @type filter
* @title um_login_form_button_two
* @description Change Login Form Secondary button
* @input_vars
* [{"var":"$secondary_btn_word","type":"string","desc":"Button text"},
* {"var":"$args","type":"array","desc":"Login Form arguments"}]
* @change_log
* ["Since: 2.0"]
* @usage
* <?php add_filter( 'um_login_form_button_two', 'function_name', 10, 2 ); ?>
* @example
* <?php
* add_filter( 'um_login_form_button_two', 'my_login_form_button_two', 10, 2 );
* function my_login_form_button_two( $secondary_btn_word, $args ) {
* // your code here
* return $secondary_btn_word;
* }
* ?>
*/
$secondary_btn_word = apply_filters('um_login_form_button_two', $secondary_btn_word, $args );
<div class="um-col-alt">
$secondary_btn_url = ( isset( $args['secondary_btn_url'] ) && $args['secondary_btn_url'] ) ? $args['secondary_btn_url'] : um_get_core_page('register');
/**
* UM hook
*
* @type filter
* @title um_login_form_button_two_url
* @description Change Login Form Secondary button URL
* @input_vars
* [{"var":"$secondary_btn_url","type":"string","desc":"Button URL"},
* {"var":"$args","type":"array","desc":"Login Form arguments"}]
* @change_log
* ["Since: 2.0"]
* @usage
* <?php add_filter( 'um_login_form_button_two_url', 'function_name', 10, 2 ); ?>
* @example
* <?php
* add_filter( 'um_login_form_button_two_url', 'my_login_form_button_two_url', 10, 2 );
* function my_login_form_button_two_url( $secondary_btn_url, $args ) {
* // your code here
* return $secondary_btn_url;
* }
* ?>
*/
$secondary_btn_url = apply_filters('um_login_form_button_two_url', $secondary_btn_url, $args ); ?>
<?php if ( isset( $args['show_rememberme'] ) && $args['show_rememberme'] ) {
echo UM()->fields()->checkbox('rememberme', __('Keep me signed in','ultimate-member') );
echo '<div class="um-clear"></div>';
} ?>
<div class="um-col-alt">
<?php if ( isset($args['secondary_btn']) && $args['secondary_btn'] != 0 ) { ?>
<?php if ( isset( $args['show_rememberme'] ) && $args['show_rememberme'] ) {
echo UM()->fields()->checkbox('rememberme', __('Keep me signed in','ultimate-member') );
echo '<div class="um-clear"></div>';
} ?>
<?php if ( isset($args['secondary_btn']) && $args['secondary_btn'] != 0 ) { ?>
<div class="um-left um-half"><input type="submit" value="<?php echo __( $primary_btn_word,'ultimate-member'); ?>" class="um-button" id="um-submit-btn" /></div>
<div class="um-right um-half"><a href="<?php echo $secondary_btn_url; ?>" class="um-button um-alt"><?php echo __( $secondary_btn_word,'ultimate-member'); ?></a></div>
<?php } else { ?>
<?php } else { ?>
<div class="um-center"><input type="submit" value="<?php echo __( $args['primary_btn_word'],'ultimate-member'); ?>" class="um-button" id="um-submit-btn" /></div>
<?php } ?>
<?php } ?>
<div class="um-clear"></div>
<div class="um-clear"></div>
</div>
<?php
}
add_action( 'um_after_login_fields', 'um_add_submit_button_to_login', 1000 );
/**
* Display a forgot password link
*
* @param $args
*/
function um_after_login_submit( $args ) {
if ( $args['forgot_pass_link'] == 0 ) return;
?>
<div class="um-col-alt-b">
<a href="<?php echo um_get_core_page('password-reset'); ?>" class="um-link-alt"><?php _e('Forgot your password?','ultimate-member'); ?></a>
</div>
<?php
}
add_action( 'um_after_login_fields', 'um_after_login_submit', 1001 );
/***
*** @Display a forgot password link
***/
add_action('um_after_login_fields', 'um_after_login_submit', 1001);
function um_after_login_submit( $args ){
if ( $args['forgot_pass_link'] == 0 ) return;
?>
/**
* Show Fields
*
* @param $args
*/
function um_add_login_fields($args){
echo UM()->fields()->display( 'login', $args );
}
add_action('um_main_login_fields', 'um_add_login_fields', 100);
<div class="um-col-alt-b">
<a href="<?php echo um_get_core_page('password-reset'); ?>" class="um-link-alt"><?php _e('Forgot your password?','ultimate-member'); ?></a>
</div>
<?php
}
/***
*** @Show Fields
***/
add_action('um_main_login_fields', 'um_add_login_fields', 100);
function um_add_login_fields($args){
echo UM()->fields()->display( 'login', $args );
}
/**
* Remove authenticate filter
* @uses 'wp_authenticate_username_password_before'
*/
add_action('wp_authenticate_username_password_before','um_auth_username_password_before',10,3);
function um_auth_username_password_before( $user, $username, $password ){
remove_filter( 'authenticate', 'wp_authenticate_username_password', 20 );
}
/**
* Remove authenticate filter
* @uses 'wp_authenticate_username_password_before'
*
* @param $user
* @param $username
* @param $password
*/
function um_auth_username_password_before( $user, $username, $password ) {
remove_filter( 'authenticate', 'wp_authenticate_username_password', 20 );
}
add_action( 'wp_authenticate_username_password_before', 'um_auth_username_password_before', 10, 3 );
+175 -166
View File
@@ -1,150 +1,155 @@
<?php
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) exit;
<?php if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
/**
* Member Directory Search
*/
add_action('um_members_directory_search', 'um_members_directory_search');
function um_members_directory_search( $args ) {
$search_filters = array();
/**
* Member Directory Search
*
* @param $args
*/
function um_members_directory_search( $args ) {
$search_filters = array();
if ( isset($args['search_fields']) ) {
foreach( $args['search_fields'] as $k => $testfilter ){
if ($testfilter && !in_array( $testfilter, (array)$search_filters ) ) {
$search_filters[] = $testfilter;
}
if ( isset($args['search_fields']) ) {
foreach( $args['search_fields'] as $k => $testfilter ){
if ($testfilter && !in_array( $testfilter, (array)$search_filters ) ) {
$search_filters[] = $testfilter;
}
}
/**
* UM hook
*
* @type filter
* @title um_frontend_member_search_filters
* @description Extend Member Directory Search filter
* @input_vars
* [{"var":"$search_filters","type":"array","desc":"Search Filters"}]
* @change_log
* ["Since: 2.0"]
* @usage
* <?php add_filter( 'um_frontend_member_search_filters', 'function_name', 10, 1 ); ?>
* @example
* <?php
* add_filter( 'um_frontend_member_search_filters', 'my_frontend_member_search_filters', 10, 1 );
* function my_frontend_member_search_filters( $search_filters ) {
* // your code here
* return $search_filters;
* }
* ?>
*/
$search_filters = apply_filters( 'um_frontend_member_search_filters', $search_filters );
if ( $args['search'] == 1 && is_array( $search_filters ) ) { // search on
$current_user_roles = um_user( 'roles' );
if ( ! empty( $args['roles_can_search'] ) && ( empty( $current_user_roles ) || count( array_intersect( $current_user_roles, $args['roles_can_search'] ) ) <= 0 ) ) {
return;
}
$count = count( $search_filters ); ?>
<div class="um-search um-search-<?php echo $count; ?>">
<form method="get" action="" />
<?php if ( isset( $_REQUEST['page_id'] ) && get_option('permalink_structure') == 0 ) { ?>
<input type="hidden" name="page_id" id="page_id" value="<?php echo esc_attr( $_REQUEST['page_id']); ?>" />
<?php }
$i = 0;
foreach( $search_filters as $filter ) {
$i++;
if ( $i % 2 == 0 ) {
$add_class = 'um-search-filter-2';
} else {
$add_class = '';
}
echo '<div class="um-search-filter '. $add_class .'">'; UM()->members()->show_filter( $filter ); echo '</div>';
}
?>
<div class="um-clear"></div>
<div class="um-search-submit">
<input type="hidden" name="um_search" id="um_search" value="1" />
<a href="#" class="um-button um-do-search"><?php _e('Search','ultimate-member'); ?></a><a href="<?php echo UM()->permalinks()->get_current_url( true ); ?>" class="um-button um-alt"><?php _e('Reset','ultimate-member'); ?></a>
</div><div class="um-clear"></div>
</form>
</div>
<?php
}
}
/**
* Pre-display Member Directory
* UM hook
*
* @type filter
* @title um_frontend_member_search_filters
* @description Extend Member Directory Search filter
* @input_vars
* [{"var":"$search_filters","type":"array","desc":"Search Filters"}]
* @change_log
* ["Since: 2.0"]
* @usage
* <?php add_filter( 'um_frontend_member_search_filters', 'function_name', 10, 1 ); ?>
* @example
* <?php
* add_filter( 'um_frontend_member_search_filters', 'my_frontend_member_search_filters', 10, 1 );
* function my_frontend_member_search_filters( $search_filters ) {
* // your code here
* return $search_filters;
* }
* ?>
*/
add_action('um_pre_directory_shortcode', 'um_pre_directory_shortcode');
function um_pre_directory_shortcode($args) {
extract( $args );
$search_filters = apply_filters( 'um_frontend_member_search_filters', $search_filters );
UM()->members()->results = UM()->members()->get_members( $args );
if ( $args['search'] == 1 && is_array( $search_filters ) ) { // search on
}
/**
* Member Directory Header
*/
add_action('um_members_directory_head', 'um_members_directory_head');
function um_members_directory_head( $args ) {
extract( $args );
if ( isset($_REQUEST['um_search']) ) {
$is_filtering = 1;
} else if ( UM()->is_filtering == 1 ) {
$is_filtering = 1;
} else {
$is_filtering = 0;
}
if ( um_members('header') && $is_filtering && um_members('users_per_page') ) { ?>
<div class="um-members-intro">
<div class="um-members-total"><?php echo ( um_members('total_users') > 1 ) ? um_members('header') : um_members('header_single'); ?></div>
</div>
<?php }
}
/**
* Member Directory Pagination
*/
add_action('um_members_directory_footer', 'um_members_directory_pagination');
function um_members_directory_pagination( $args ) {
extract( $args );
if ( isset( $args['search'] ) && $args['search'] == 1 && isset( $args['must_search'] ) && $args['must_search'] == 1 && !isset( $_REQUEST['um_search'] ) )
$current_user_roles = um_user( 'roles' );
if ( ! empty( $args['roles_can_search'] ) && ( empty( $current_user_roles ) || count( array_intersect( $current_user_roles, $args['roles_can_search'] ) ) <= 0 ) ) {
return;
}
$count = count( $search_filters ); ?>
<div class="um-search um-search-<?php echo $count; ?>">
<form method="get" action="" />
<?php if ( isset( $_REQUEST['page_id'] ) && get_option('permalink_structure') == 0 ) { ?>
<input type="hidden" name="page_id" id="page_id" value="<?php echo esc_attr( $_REQUEST['page_id']); ?>" />
<?php }
$i = 0;
foreach( $search_filters as $filter ) {
$i++;
if ( $i % 2 == 0 ) {
$add_class = 'um-search-filter-2';
} else {
$add_class = '';
}
echo '<div class="um-search-filter '. $add_class .'">'; UM()->members()->show_filter( $filter ); echo '</div>';
}
?>
<div class="um-clear"></div>
<div class="um-search-submit">
<input type="hidden" name="um_search" id="um_search" value="1" />
<a href="#" class="um-button um-do-search"><?php _e('Search','ultimate-member'); ?></a><a href="<?php echo UM()->permalinks()->get_current_url( true ); ?>" class="um-button um-alt"><?php _e('Reset','ultimate-member'); ?></a>
</div><div class="um-clear"></div>
</form>
</div>
<?php
if ( um_members('total_pages') > 1 ) { // needs pagination
}
}
add_action( 'um_members_directory_search', 'um_members_directory_search' );
/**
* Pre-display Member Directory
*
* @param $args
*/
function um_pre_directory_shortcode( $args ) {
extract( $args );
UM()->members()->results = UM()->members()->get_members( $args );
}
add_action( 'um_pre_directory_shortcode', 'um_pre_directory_shortcode' );
/**
* Member Directory Header
*
* @param $args
*/
function um_members_directory_head( $args ) {
extract( $args );
if ( isset($_REQUEST['um_search']) ) {
$is_filtering = 1;
} else if ( UM()->is_filtering == 1 ) {
$is_filtering = 1;
} else {
$is_filtering = 0;
}
if ( um_members('header') && $is_filtering && um_members('users_per_page') ) { ?>
<div class="um-members-intro">
<div class="um-members-total"><?php echo ( um_members('total_users') > 1 ) ? um_members('header') : um_members('header_single'); ?></div>
</div>
<?php }
}
add_action( 'um_members_directory_head', 'um_members_directory_head' );
/**
* Member Directory Pagination
*
* @param $args
*/
function um_members_directory_pagination( $args ) {
extract( $args );
if ( isset( $args['search'] ) && $args['search'] == 1 && isset( $args['must_search'] ) && $args['must_search'] == 1 && !isset( $_REQUEST['um_search'] ) )
return;
if ( um_members('total_pages') > 1 ) { // needs pagination
?>
@@ -153,11 +158,11 @@ if ( ! defined( 'ABSPATH' ) ) exit;
<?php _e('Jump to page:','ultimate-member'); ?>
<?php if ( um_members('pages_to_show') && is_array( um_members('pages_to_show') ) ) { ?>
<select onChange="window.location.href=this.value" class="um-s2" style="width: 100px">
<?php foreach( um_members('pages_to_show') as $i ) { ?>
<option value="<?php echo UM()->permalinks()->add_query( 'members_page', $i ); ?>" <?php selected($i, um_members('page')); ?>><?php printf(__('%s of %d','ultimate-member'), $i, um_members('total_pages') ); ?></option>
<?php } ?>
</select>
<select onChange="window.location.href=this.value" class="um-s2" style="width: 100px">
<?php foreach( um_members('pages_to_show') as $i ) { ?>
<option value="<?php echo UM()->permalinks()->add_query( 'members_page', $i ); ?>" <?php selected($i, um_members('page')); ?>><?php printf(__('%s of %d','ultimate-member'), $i, um_members('total_pages') ); ?></option>
<?php } ?>
</select>
<?php } ?>
</div>
@@ -165,60 +170,63 @@ if ( ! defined( 'ABSPATH' ) ) exit;
<div class="um-members-pagi uimob340-hide uimob500-hide">
<?php if ( um_members('page') != 1 ) { ?>
<a href="<?php echo UM()->permalinks()->add_query( 'members_page', 1 ); ?>" class="pagi pagi-arrow um-tip-n" title="<?php _e('First Page','ultimate-member'); ?>"><i class="um-faicon-angle-double-left"></i></a>
<a href="<?php echo UM()->permalinks()->add_query( 'members_page', 1 ); ?>" class="pagi pagi-arrow um-tip-n" title="<?php _e('First Page','ultimate-member'); ?>"><i class="um-faicon-angle-double-left"></i></a>
<?php } else { ?>
<span class="pagi pagi-arrow disabled"><i class="um-faicon-angle-double-left"></i></span>
<span class="pagi pagi-arrow disabled"><i class="um-faicon-angle-double-left"></i></span>
<?php } ?>
<?php if ( um_members('page') > 1 ) { ?>
<a href="<?php echo UM()->permalinks()->add_query( 'members_page', um_members('page') - 1 ); ?>" class="pagi pagi-arrow um-tip-n" title="<?php _e('Previous','ultimate-member'); ?>"><i class="um-faicon-angle-left"></i></a>
<a href="<?php echo UM()->permalinks()->add_query( 'members_page', um_members('page') - 1 ); ?>" class="pagi pagi-arrow um-tip-n" title="<?php _e('Previous','ultimate-member'); ?>"><i class="um-faicon-angle-left"></i></a>
<?php } else { ?>
<span class="pagi pagi-arrow disabled"><i class="um-faicon-angle-left"></i></span>
<span class="pagi pagi-arrow disabled"><i class="um-faicon-angle-left"></i></span>
<?php } ?>
<?php if ( um_members('pages_to_show') && is_array( um_members('pages_to_show') ) ) { ?>
<?php foreach( um_members('pages_to_show') as $i ) { ?>
<?php foreach( um_members('pages_to_show') as $i ) { ?>
<?php if ( um_members('page') == $i ) { ?>
<span class="pagi current"><?php echo $i; ?></span>
<?php } else { ?>
<?php if ( um_members('page') == $i ) { ?>
<span class="pagi current"><?php echo $i; ?></span>
<?php } else { ?>
<a href="<?php echo UM()->permalinks()->add_query( 'members_page', $i ); ?>" class="pagi"><?php echo $i; ?></a>
<a href="<?php echo UM()->permalinks()->add_query( 'members_page', $i ); ?>" class="pagi"><?php echo $i; ?></a>
<?php } ?>
<?php } ?>
<?php } ?>
<?php } ?>
<?php if ( um_members('page') != um_members('total_pages') ) { ?>
<a href="<?php echo UM()->permalinks()->add_query( 'members_page', um_members('page') + 1 ); ?>" class="pagi pagi-arrow um-tip-n" title="<?php _e('Next','ultimate-member'); ?>"><i class="um-faicon-angle-right"></i></a>
<a href="<?php echo UM()->permalinks()->add_query( 'members_page', um_members('page') + 1 ); ?>" class="pagi pagi-arrow um-tip-n" title="<?php _e('Next','ultimate-member'); ?>"><i class="um-faicon-angle-right"></i></a>
<?php } else { ?>
<span class="pagi pagi-arrow disabled"><i class="um-faicon-angle-right"></i></span>
<span class="pagi pagi-arrow disabled"><i class="um-faicon-angle-right"></i></span>
<?php } ?>
<?php if ( um_members('page') != um_members('total_pages') ) { ?>
<a href="<?php echo UM()->permalinks()->add_query( 'members_page', um_members('total_pages') ); ?>" class="pagi pagi-arrow um-tip-n" title="<?php _e('Last Page','ultimate-member'); ?>"><i class="um-faicon-angle-double-right"></i></a>
<a href="<?php echo UM()->permalinks()->add_query( 'members_page', um_members('total_pages') ); ?>" class="pagi pagi-arrow um-tip-n" title="<?php _e('Last Page','ultimate-member'); ?>"><i class="um-faicon-angle-double-right"></i></a>
<?php } else { ?>
<span class="pagi pagi-arrow disabled"><i class="um-faicon-angle-double-right"></i></span>
<span class="pagi pagi-arrow disabled"><i class="um-faicon-angle-double-right"></i></span>
<?php } ?>
</div>
<?php
}
}
/**
* Member Directory Display
*/
add_action('um_members_directory_display', 'um_members_directory_display');
function um_members_directory_display( $args ) {
extract( $args );
}
add_action( 'um_members_directory_footer', 'um_members_directory_pagination' );
/**
* Member Directory Display
*
* @param $args
*/
function um_members_directory_display( $args ) {
extract( $args );
if ( isset( $args['search'] ) && $args['search'] == 1 && isset( $args['must_search'] ) && $args['must_search'] == 1 && !isset( $_REQUEST['um_search'] ) )
return;
if ( isset( $args['search'] ) && $args['search'] == 1 && isset( $args['must_search'] ) && $args['must_search'] == 1 && !isset( $_REQUEST['um_search'] ) )
return;
if ( um_members('no_users') ) {
@@ -241,4 +249,5 @@ if ( ! defined( 'ABSPATH' ) ) exit;
include $file;
}
}
add_action( 'um_members_directory_display', 'um_members_directory_display' );
+186 -184
View File
@@ -3,201 +3,203 @@
if ( ! defined( 'ABSPATH' ) ) exit;
/***
*** @add a force redirect to from $_get
***/
add_action('um_after_form_fields', 'um_browser_url_redirect_to');
function um_browser_url_redirect_to( $args ) {
$url = '';
/**
* Add a force redirect to from $_get
*
* @param $args
*/
function um_browser_url_redirect_to( $args ) {
$url = '';
if ( ! empty( $_REQUEST['redirect_to'] ) ) {
$url = $_REQUEST['redirect_to'];
echo '<input type="hidden" name="redirect_to" id="redirect_to" value="'.esc_url( $url ).'" />';
if ( ! empty( $_REQUEST['redirect_to'] ) ) {
$url = $_REQUEST['redirect_to'];
echo '<input type="hidden" name="redirect_to" id="redirect_to" value="'.esc_url( $url ).'" />';
} elseif ( ! empty( $args['after_login'] ) ) {
} elseif ( ! empty( $args['after_login'] ) ) {
switch ( $args['after_login'] ) {
switch ( $args['after_login'] ) {
case 'redirect_admin':
$url = admin_url();
break;
case 'redirect_admin':
$url = admin_url();
break;
case 'redirect_profile':
$url = um_user_profile_url();
break;
case 'redirect_profile':
$url = um_user_profile_url();
break;
case 'redirect_url':
$url = $args['redirect_url'];
break;
case 'redirect_url':
$url = $args['redirect_url'];
break;
case 'refresh':
case 'refresh':
$url = UM()->permalinks()->get_current_url();
$url = UM()->permalinks()->get_current_url();
break;
break;
}
}
}
/**
* UM hook
*
* @type filter
* @title um_browser_url_redirect_to__filter
* @description Add redirect to field to form and change URL for it
* @input_vars
* [{"var":"$url","type":"string","desc":"Redirect to URL"}]
* @change_log
* ["Since: 2.0"]
* @usage
* <?php add_filter( 'um_browser_url_redirect_to__filter', 'function_name', 10, 1 ); ?>
* @example
* <?php
* add_filter( 'um_browser_url_redirect_to__filter', 'my_browser_url_redirect_to', 10, 1 );
* function my_browser_url_redirect_to( $url ) {
* // your code here
* return $url;
* }
* ?>
*/
$url = apply_filters( 'um_browser_url_redirect_to__filter', $url );
if ( ! empty( $url ) ) {
echo '<input type="hidden" name="redirect_to" id="redirect_to" value="' . esc_url( $url ) . '" />';
}
}
/***
*** @add a notice to form
***/
add_action( 'um_before_form', 'um_add_update_notice', 500 );
function um_add_update_notice( $args ) {
extract($args);
$output = '';
$err = '';
$success = '';
if ( isset( $_REQUEST['updated'] ) && !empty( $_REQUEST['updated'] ) && ! UM()->form()->errors ) {
switch( $_REQUEST['updated'] ) {
default:
/**
* UM hook
*
* @type filter
* @title um_custom_success_message_handler
* @description Add custom success message
* @input_vars
* [{"var":"$success","type":"string","desc":"Message"},
* {"var":"$updated","type":"array","desc":"Updated data"}]
* @change_log
* ["Since: 2.0"]
* @usage
* <?php add_filter( 'um_custom_success_message_handler', 'function_name', 10, 2 ); ?>
* @example
* <?php
* add_filter( 'um_custom_success_message_handler', 'my_custom_success_message', 10, 2 );
* function my_custom_success_message( $success, $updated ) {
* // your code here
* return $success;
* }
* ?>
*/
$success = apply_filters( "um_custom_success_message_handler", $success, $_REQUEST['updated'] );
break;
case 'account':
$success = __('Your account was updated successfully.','ultimate-member');
break;
case 'password_changed':
$success = __('You have successfully changed your password.','ultimate-member');
break;
case 'account_active':
$success = __('Your account is now active! You can login.','ultimate-member');
break;
}
/**
* UM hook
*
* @type filter
* @title um_browser_url_redirect_to__filter
* @description Add redirect to field to form and change URL for it
* @input_vars
* [{"var":"$url","type":"string","desc":"Redirect to URL"}]
* @change_log
* ["Since: 2.0"]
* @usage
* <?php add_filter( 'um_browser_url_redirect_to__filter', 'function_name', 10, 1 ); ?>
* @example
* <?php
* add_filter( 'um_browser_url_redirect_to__filter', 'my_browser_url_redirect_to', 10, 1 );
* function my_browser_url_redirect_to( $url ) {
* // your code here
* return $url;
* }
* ?>
*/
$url = apply_filters( 'um_browser_url_redirect_to__filter', $url );
if ( ! empty( $url ) ) {
echo '<input type="hidden" name="redirect_to" id="redirect_to" value="' . esc_url( $url ) . '" />';
}
}
add_action( 'um_after_form_fields', 'um_browser_url_redirect_to' );
/**
* Add a notice to form
*
* @param $args
*/
function um_add_update_notice( $args ) {
extract( $args );
$output = '';
$err = '';
$success = '';
if ( isset( $_REQUEST['updated'] ) && !empty( $_REQUEST['updated'] ) && ! UM()->form()->errors ) {
switch ( $_REQUEST['updated'] ) {
default:
/**
* UM hook
*
* @type filter
* @title um_custom_success_message_handler
* @description Add custom success message
* @input_vars
* [{"var":"$success","type":"string","desc":"Message"},
* {"var":"$updated","type":"array","desc":"Updated data"}]
* @change_log
* ["Since: 2.0"]
* @usage
* <?php add_filter( 'um_custom_success_message_handler', 'function_name', 10, 2 ); ?>
* @example
* <?php
* add_filter( 'um_custom_success_message_handler', 'my_custom_success_message', 10, 2 );
* function my_custom_success_message( $success, $updated ) {
* // your code here
* return $success;
* }
* ?>
*/
$success = apply_filters( "um_custom_success_message_handler", $success, $_REQUEST['updated'] );
break;
case 'account':
$success = __('Your account was updated successfully.','ultimate-member');
break;
case 'password_changed':
$success = __('You have successfully changed your password.','ultimate-member');
break;
case 'account_active':
$success = __('Your account is now active! You can login.','ultimate-member');
break;
}
if ( isset( $_REQUEST['err'] ) && !empty( $_REQUEST['err'] ) && ! UM()->form()->errors ) {
switch( $_REQUEST['err'] ) {
default:
/**
* UM hook
*
* @type filter
* @title um_custom_error_message_handler
* @description Add custom error message
* @input_vars
* [{"var":"$error","type":"string","desc":"Error message"},
* {"var":"$request_error","type":"array","desc":"Error data"}]
* @change_log
* ["Since: 2.0"]
* @usage
* <?php add_filter( 'um_custom_error_message_handler', 'function_name', 10, 2 ); ?>
* @example
* <?php
* add_filter( 'um_custom_error_message_handler', 'my_custom_error_message', 10, 2 );
* function my_custom_error_message( $error, $request_error ) {
* // your code here
* return $error;
* }
* ?>
*/
$err = apply_filters( "um_custom_error_message_handler", $err, $_REQUEST['err'] );
if ( !$err )
$err = __( 'An error has been encountered', 'ultimate-member' );
break;
case 'registration_disabled':
$err = __('Registration is currently disabled','ultimate-member');
break;
case 'blocked_email':
$err = __('This email address has been blocked.','ultimate-member');
break;
case 'blocked_domain':
$err = __('We do not accept registrations from that domain.','ultimate-member');
break;
case 'blocked_ip':
$err = __('Your IP address has been blocked.','ultimate-member');
break;
case 'inactive':
$err = __('Your account has been disabled.','ultimate-member');
break;
case 'awaiting_admin_review':
$err = __('Your account has not been approved yet.','ultimate-member');
break;
case 'awaiting_email_confirmation':
$err = __('Your account is awaiting e-mail verification.','ultimate-member');
break;
case 'rejected':
$err = __('Your membership request has been rejected.','ultimate-member');
break;
}
}
if ( isset( $_REQUEST['err'] ) && !empty( $_REQUEST['err'] ) && ! UM()->form()->errors ) {
switch( $_REQUEST['err'] ) {
default:
/**
* UM hook
*
* @type filter
* @title um_custom_error_message_handler
* @description Add custom error message
* @input_vars
* [{"var":"$error","type":"string","desc":"Error message"},
* {"var":"$request_error","type":"array","desc":"Error data"}]
* @change_log
* ["Since: 2.0"]
* @usage
* <?php add_filter( 'um_custom_error_message_handler', 'function_name', 10, 2 ); ?>
* @example
* <?php
* add_filter( 'um_custom_error_message_handler', 'my_custom_error_message', 10, 2 );
* function my_custom_error_message( $error, $request_error ) {
* // your code here
* return $error;
* }
* ?>
*/
$err = apply_filters( "um_custom_error_message_handler", $err, $_REQUEST['err'] );
if ( !$err )
$err = __( 'An error has been encountered', 'ultimate-member' );
break;
case 'registration_disabled':
$err = __('Registration is currently disabled','ultimate-member');
break;
case 'blocked_email':
$err = __('This email address has been blocked.','ultimate-member');
break;
case 'blocked_domain':
$err = __('We do not accept registrations from that domain.','ultimate-member');
break;
case 'blocked_ip':
$err = __('Your IP address has been blocked.','ultimate-member');
break;
case 'inactive':
$err = __('Your account has been disabled.','ultimate-member');
break;
case 'awaiting_admin_review':
$err = __('Your account has not been approved yet.','ultimate-member');
break;
case 'awaiting_email_confirmation':
$err = __('Your account is awaiting e-mail verification.','ultimate-member');
break;
case 'rejected':
$err = __('Your membership request has been rejected.','ultimate-member');
break;
}
if ( isset( $err ) && !empty( $err ) ) {
$output .= '<p class="um-notice err"><i class="um-icon-ios-close-empty" onclick="jQuery(this).parent().fadeOut();"></i>' . $err . '</p>';
}
if ( isset( $success ) && !empty( $success ) ) {
$output .= '<p class="um-notice success"><i class="um-icon-ios-close-empty" onclick="jQuery(this).parent().fadeOut();"></i>' . $success . '</p>';
}
echo $output;
}
}
if ( isset( $err ) && !empty( $err ) ) {
$output .= '<p class="um-notice err"><i class="um-icon-ios-close-empty" onclick="jQuery(this).parent().fadeOut();"></i>' . $err . '</p>';
}
if ( isset( $success ) && !empty( $success ) ) {
$output .= '<p class="um-notice success"><i class="um-icon-ios-close-empty" onclick="jQuery(this).parent().fadeOut();"></i>' . $success . '</p>';
}
echo $output;
}
add_action( 'um_before_form', 'um_add_update_notice', 500 );
+295 -274
View File
@@ -1,340 +1,361 @@
<?php
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) exit;
<?php if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
/***
*** @process a new request
***/
add_action('um_reset_password_process_hook','um_reset_password_process_hook');
function um_reset_password_process_hook( $args ) {
$user = null;
/**
* Process a new request
*
* @param $args
*/
function um_reset_password_process_hook( $args ) {
$user = null;
foreach ( $_POST as $key => $val ) {
if( strstr( $key, "username_b") ){
$user = trim( $val );
}
}
if ( username_exists( $user ) ) {
$data = get_user_by( 'login', $user );
$user_email = $data->user_email;
} else if( email_exists( $user ) ) {
$data = get_user_by( 'email', $user );
$user_email = $user;
foreach ( $_POST as $key => $val ) {
if( strstr( $key, "username_b") ){
$user = trim( $val );
}
UM()->password()->reset_request['user_id'] = $data->ID;
UM()->password()->reset_request['user_email'] = $user_email;
um_fetch_user( $data->ID );
UM()->user()->password_reset();
um_reset_user();
}
/***
*** @process a change request
***/
add_action('um_change_password_process_hook','um_change_password_process_hook');
function um_change_password_process_hook( $args ) {
extract( $args );
wp_set_password( $args['user_password'], $args['user_id'] );
delete_user_meta( $args['user_id'], 'reset_pass_hash');
delete_user_meta( $args['user_id'], 'reset_pass_hash_token');
delete_user_meta( $args['user_id'], 'password_rst_attempts');
/**
* UM hook
*
* @type action
* @title um_after_changing_user_password
* @description Hook that runs after user change their password
* @input_vars
* [{"var":"$user_id","type":"int","desc":"User ID"}]
* @change_log
* ["Since: 2.0"]
* @usage add_action( 'um_after_changing_user_password', 'function_name', 10, 1 );
* @example
* <?php
* add_action( 'um_after_changing_user_password', 'my_after_changing_user_password', 10, 1 );
* function my_user_login_extra( $user_id ) {
* // your code here
* }
* ?>
*/
do_action( 'um_after_changing_user_password', $args['user_id'] );
if ( is_user_logged_in() ) {
wp_logout();
}
exit( wp_redirect( um_get_core_page('login', 'password_changed') ) );
if ( username_exists( $user ) ) {
$data = get_user_by( 'login', $user );
$user_email = $data->user_email;
} else if( email_exists( $user ) ) {
$data = get_user_by( 'email', $user );
$user_email = $user;
}
UM()->password()->reset_request['user_id'] = $data->ID;
UM()->password()->reset_request['user_email'] = $user_email;
um_fetch_user( $data->ID );
UM()->user()->password_reset();
um_reset_user();
}
add_action( 'um_reset_password_process_hook', 'um_reset_password_process_hook' );
/**
* Process a change request
*
* @param $args
*/
function um_change_password_process_hook( $args ) {
extract( $args );
wp_set_password( $args['user_password'], $args['user_id'] );
delete_user_meta( $args['user_id'], 'reset_pass_hash');
delete_user_meta( $args['user_id'], 'reset_pass_hash_token');
delete_user_meta( $args['user_id'], 'password_rst_attempts');
/**
* Overrides password changed notification
* UM hook
*
* @type action
* @title um_after_changing_user_password
* @description Hook that runs after user change their password
* @input_vars
* [{"var":"$user_id","type":"int","desc":"User ID"}]
* @change_log
* ["Since: 2.0"]
* @usage add_action( 'um_after_changing_user_password', 'function_name', 10, 1 );
* @example
* <?php
* add_action( 'um_after_changing_user_password', 'my_after_changing_user_password', 10, 1 );
* function my_user_login_extra( $user_id ) {
* // your code here
* }
* ?>
*/
add_action( 'send_password_change_email','um_send_password_change_email', 10, 1 );
function um_send_password_change_email( $args ) {
do_action( 'um_after_changing_user_password', $args['user_id'] );
if ( ! is_array( $args ) )
return false;
/**
* @var $user_id
*/
extract( $args );
if ( is_user_logged_in() ) {
wp_logout();
}
if ( ! isset( $user_id ) )
return false;
exit( wp_redirect( um_get_core_page('login', 'password_changed') ) );
}
add_action( 'um_change_password_process_hook','um_change_password_process_hook' );
um_fetch_user( $user_id );
UM()->user()->password_changed();
um_reset_user();
/**
* Overrides password changed notification
*
* @param $args
*
* @return bool
*/
function um_send_password_change_email( $args ) {
if ( ! is_array( $args ) )
return false;
}
/***
*** @This is executed after changing password
***/
add_action('um_after_changing_user_password','um_after_changing_user_password');
function um_after_changing_user_password( $user_id ) {
/**
* @var $user_id
*/
extract( $args );
}
if ( ! isset( $user_id ) )
return false;
/***
*** @Error handler: reset password
***/
add_action('um_reset_password_errors_hook','um_reset_password_errors_hook');
function um_reset_password_errors_hook( $args ) {
um_fetch_user( $user_id );
if ( $_POST[ UM()->honeypot ] != '' )
wp_die('Hello, spam bot!','ultimate-member');
UM()->user()->password_changed();
$form_timestamp = trim($_POST['timestamp']);
$live_timestamp = current_time( 'timestamp' );
um_reset_user();
if ( $form_timestamp == '' && UM()->options()->get( 'enable_timebot' ) == 1 )
wp_die( __('Hello, spam bot!','ultimate-member') );
return false;
}
add_action( 'send_password_change_email','um_send_password_change_email', 10, 1 );
if ( $live_timestamp - $form_timestamp < 3 && UM()->options()->get( 'enable_timebot' ) == 1 )
wp_die( __('Whoa, slow down! You\'re seeing this message because you tried to submit a form too fast and we think you might be a spam bot. If you are a real human being please wait a few seconds before submitting the form. Thanks!','ultimate-member') );
/**
* This is executed after changing password
*
* @param $user_id
*/
function um_after_changing_user_password( $user_id ) {
}
add_action( 'um_after_changing_user_password', 'um_after_changing_user_password' );
/**
* Error handler: reset password
*
* @param $args
*/
function um_reset_password_errors_hook( $args ) {
if ( $_POST[ UM()->honeypot ] != '' )
wp_die('Hello, spam bot!','ultimate-member');
$form_timestamp = trim($_POST['timestamp']);
$live_timestamp = current_time( 'timestamp' );
if ( $form_timestamp == '' && UM()->options()->get( 'enable_timebot' ) == 1 )
wp_die( __('Hello, spam bot!','ultimate-member') );
if ( $live_timestamp - $form_timestamp < 3 && UM()->options()->get( 'enable_timebot' ) == 1 )
wp_die( __('Whoa, slow down! You\'re seeing this message because you tried to submit a form too fast and we think you might be a spam bot. If you are a real human being please wait a few seconds before submitting the form. Thanks!','ultimate-member') );
$user = "";
$user = "";
foreach ( $_POST as $key => $val ) {
if( strstr( $key, "username_b") ){
$user = trim( $val );
}
}
if ( empty( $user ) ) {
UM()->form()->add_error('username_b', __('Please provide your username or email','ultimate-member') );
foreach ( $_POST as $key => $val ) {
if( strstr( $key, "username_b") ){
$user = trim( $val );
}
}
if ( ( !is_email( $user ) && !username_exists( $user ) ) || ( is_email( $user ) && !email_exists( $user ) ) ) {
UM()->form()->add_error('username_b', __('We can\'t find an account registered with that address or username','ultimate-member') );
if ( empty( $user ) ) {
UM()->form()->add_error('username_b', __('Please provide your username or email','ultimate-member') );
}
if ( ( !is_email( $user ) && !username_exists( $user ) ) || ( is_email( $user ) && !email_exists( $user ) ) ) {
UM()->form()->add_error('username_b', __('We can\'t find an account registered with that address or username','ultimate-member') );
} else {
if ( is_email( $user ) ) {
$user_id = email_exists( $user );
} else {
$user_id = username_exists( $user );
}
if ( is_email( $user ) ) {
$user_id = email_exists( $user );
$attempts = (int)get_user_meta( $user_id, 'password_rst_attempts', true );
$is_admin = user_can( intval( $user_id ),'manage_options' );
if ( UM()->options()->get( 'enable_reset_password_limit' ) ) { // if reset password limit is set
if ( UM()->options()->get( 'disable_admin_reset_password_limit' ) && $is_admin ) {
// Triggers this when a user has admin capabilities and when reset password limit is disabled for admins
} else {
$user_id = username_exists( $user );
}
$attempts = (int)get_user_meta( $user_id, 'password_rst_attempts', true );
$is_admin = user_can( intval( $user_id ),'manage_options' );
if ( UM()->options()->get( 'enable_reset_password_limit' ) ) { // if reset password limit is set
if ( UM()->options()->get( 'disable_admin_reset_password_limit' ) && $is_admin ) {
// Triggers this when a user has admin capabilities and when reset password limit is disabled for admins
$limit = UM()->options()->get( 'reset_password_limit_number' );
if ( $attempts >= $limit ) {
UM()->form()->add_error('username_b', __('You have reached the limit for requesting password change for this user already. Contact support if you cannot open the email','ultimate-member') );
} else {
$limit = UM()->options()->get( 'reset_password_limit_number' );
if ( $attempts >= $limit ) {
UM()->form()->add_error('username_b', __('You have reached the limit for requesting password change for this user already. Contact support if you cannot open the email','ultimate-member') );
} else {
update_user_meta( $user_id, 'password_rst_attempts', $attempts + 1 );
}
update_user_meta( $user_id, 'password_rst_attempts', $attempts + 1 );
}
}
}
}
/***
*** @Error handler: changing password
***/
add_action('um_change_password_errors_hook','um_change_password_errors_hook');
function um_change_password_errors_hook( $args ) {
if ( isset( $_POST[ UM()->honeypot ] ) && $_POST[ UM()->honeypot ] != '' ){
wp_die('Hello, spam bot!','ultimate-member');
}
$form_timestamp = trim($_POST['timestamp']);
$live_timestamp = current_time( 'timestamp' );
if ( $form_timestamp == '' && UM()->options()->get( 'enable_timebot' ) == 1 )
wp_die( __('Hello, spam bot!','ultimate-member') );
if ( $live_timestamp - $form_timestamp < 3 && UM()->options()->get( 'enable_timebot' ) == 1 ) {
wp_die( __('Whoa, slow down! You\'re seeing this message because you tried to submit a form too fast and we think you might be a spam bot. If you are a real human being please wait a few seconds before submitting the form. Thanks!','ultimate-member') );
}
$reset_pass_hash = '';
if( isset( $_REQUEST['act'] ) && $_REQUEST['act'] == 'reset_password' && um_is_core_page('password-reset') ){
$reset_pass_hash = get_user_meta( $args['user_id'], 'reset_pass_hash', true );
}
if( !is_user_logged_in() && isset( $args ) && ! um_is_core_page('password-reset') ||
is_user_logged_in() && isset( $args['user_id'] ) && $args['user_id'] != get_current_user_id() ||
!is_user_logged_in() && isset( $_REQUEST['hash'] ) && $reset_pass_hash != $_REQUEST['hash'] && um_is_core_page('password-reset')
){
wp_die( __( 'This is not possible for security reasons.','ultimate-member') );
}
if ( isset( $args['user_password'] ) && empty( $args['user_password'] ) ) {
UM()->form()->add_error('user_password', __('You must enter a new password','ultimate-member') );
}
if ( UM()->options()->get( 'reset_require_strongpass' ) ) {
if ( strlen( utf8_decode( $args['user_password'] ) ) < 8 ) {
UM()->form()->add_error('user_password', __('Your password must contain at least 8 characters','ultimate-member') );
}
if ( strlen( utf8_decode( $args['user_password'] ) ) > 30 ) {
UM()->form()->add_error('user_password', __('Your password must contain less than 30 characters','ultimate-member') );
}
if ( ! UM()->validation()->strong_pass( $args['user_password'] ) ) {
UM()->form()->add_error('user_password', __('Your password must contain at least one lowercase letter, one capital letter and one number','ultimate-member') );
}
}
}
if ( isset( $args['confirm_user_password'] ) && empty( $args['confirm_user_password'] ) ) {
UM()->form()->add_error('confirm_user_password', __('You must confirm your new password','ultimate-member') );
}
add_action( 'um_reset_password_errors_hook', 'um_reset_password_errors_hook' );
/**
* Error handler: changing password
*
* @param $args
*/
function um_change_password_errors_hook( $args ) {
if ( isset( $_POST[ UM()->honeypot ] ) && $_POST[ UM()->honeypot ] != '' ){
wp_die('Hello, spam bot!','ultimate-member');
}
$form_timestamp = trim($_POST['timestamp']);
$live_timestamp = current_time( 'timestamp' );
if ( $form_timestamp == '' && UM()->options()->get( 'enable_timebot' ) == 1 )
wp_die( __('Hello, spam bot!','ultimate-member') );
if ( $live_timestamp - $form_timestamp < 3 && UM()->options()->get( 'enable_timebot' ) == 1 ) {
wp_die( __('Whoa, slow down! You\'re seeing this message because you tried to submit a form too fast and we think you might be a spam bot. If you are a real human being please wait a few seconds before submitting the form. Thanks!','ultimate-member') );
}
$reset_pass_hash = '';
if( isset( $_REQUEST['act'] ) && $_REQUEST['act'] == 'reset_password' && um_is_core_page('password-reset') ){
$reset_pass_hash = get_user_meta( $args['user_id'], 'reset_pass_hash', true );
}
if( !is_user_logged_in() && isset( $args ) && ! um_is_core_page('password-reset') ||
is_user_logged_in() && isset( $args['user_id'] ) && $args['user_id'] != get_current_user_id() ||
!is_user_logged_in() && isset( $_REQUEST['hash'] ) && $reset_pass_hash != $_REQUEST['hash'] && um_is_core_page('password-reset')
){
wp_die( __( 'This is not possible for security reasons.','ultimate-member') );
}
if ( isset( $args['user_password'] ) && empty( $args['user_password'] ) ) {
UM()->form()->add_error('user_password', __('You must enter a new password','ultimate-member') );
}
if ( UM()->options()->get( 'reset_require_strongpass' ) ) {
if ( strlen( utf8_decode( $args['user_password'] ) ) < 8 ) {
UM()->form()->add_error('user_password', __('Your password must contain at least 8 characters','ultimate-member') );
}
if ( isset( $args['user_password'] ) && isset( $args['confirm_user_password'] ) && $args['user_password'] != $args['confirm_user_password'] ) {
UM()->form()->add_error('confirm_user_password', __('Your passwords do not match','ultimate-member') );
if ( strlen( utf8_decode( $args['user_password'] ) ) > 30 ) {
UM()->form()->add_error('user_password', __('Your password must contain less than 30 characters','ultimate-member') );
}
if ( ! UM()->validation()->strong_pass( $args['user_password'] ) ) {
UM()->form()->add_error('user_password', __('Your password must contain at least one lowercase letter, one capital letter and one number','ultimate-member') );
}
}
/***
*** @hidden fields
***/
add_action('um_change_password_page_hidden_fields','um_change_password_page_hidden_fields');
function um_change_password_page_hidden_fields( $args ) {
?>
<input type="hidden" name="_um_password_change" id="_um_password_change" value="1" />
<input type="hidden" name="user_id" id="user_id" value="<?php echo $args['user_id']; ?>" />
<?php
if ( isset( $args['confirm_user_password'] ) && empty( $args['confirm_user_password'] ) ) {
UM()->form()->add_error('confirm_user_password', __('You must confirm your new password','ultimate-member') );
}
/***
*** @hidden fields
***/
add_action('um_reset_password_page_hidden_fields','um_reset_password_page_hidden_fields');
function um_reset_password_page_hidden_fields( $args ) {
?>
<input type="hidden" name="_um_password_reset" id="_um_password_reset" value="1" />
<?php
if ( isset( $args['user_password'] ) && isset( $args['confirm_user_password'] ) && $args['user_password'] != $args['confirm_user_password'] ) {
UM()->form()->add_error('confirm_user_password', __('Your passwords do not match','ultimate-member') );
}
/***
*** @form content
***/
add_action('um_reset_password_form', 'um_reset_password_form');
function um_reset_password_form($args) {
}
add_action( 'um_change_password_errors_hook', 'um_change_password_errors_hook' );
$fields = UM()->builtin()->get_specific_fields('password_reset_text,username_b'); ?>
<?php $output = null;
foreach( $fields as $key => $data ) {
$output .= UM()->fields()->edit_field( $key, $data );
} echo $output; ?>
/**
* Hidden fields
*
* @param $args
*/
function um_change_password_page_hidden_fields( $args ) {
?>
<?php
/**
* UM hook
*
* @type action
* @title um_after_password_reset_fields
* @description Hook that runs after user reset their password
* @input_vars
* [{"var":"$args","type":"array","desc":"Form data"}]
* @change_log
* ["Since: 2.0"]
* @usage add_action( 'um_after_password_reset_fields', 'function_name', 10, 1 );
* @example
* <?php
* add_action( 'um_after_password_reset_fields', 'my_after_password_reset_fields', 10, 1 );
* function my_after_password_reset_fields( $args ) {
* // your code here
* }
* ?>
*/
do_action( 'um_after_password_reset_fields', $args ); ?>
<input type="hidden" name="_um_password_change" id="_um_password_change" value="1" />
<div class="um-col-alt um-col-alt-b">
<input type="hidden" name="user_id" id="user_id" value="<?php echo $args['user_id']; ?>" />
<div class="um-center"><input type="submit" value="<?php _e('Reset my password','ultimate-member'); ?>" class="um-button" id="um-submit-btn" /></div>
<?php
}
add_action( 'um_change_password_page_hidden_fields', 'um_change_password_page_hidden_fields' );
<div class="um-clear"></div>
</div>
/**
* Hidden fields
*
* @param $args
*/
function um_reset_password_page_hidden_fields( $args ) {
?>
<?php
<input type="hidden" name="_um_password_reset" id="_um_password_reset" value="1" />
}
<?php
}
add_action( 'um_reset_password_page_hidden_fields', 'um_reset_password_page_hidden_fields' );
/***
*** @change password form
***/
add_action('um_change_password_form', 'um_change_password_form');
function um_change_password_form() {
$fields = UM()->builtin()->get_specific_fields('user_password'); ?>
/**
* Form content
*
* @param $args
*/
function um_reset_password_form( $args ) {
<?php $output = null;
foreach( $fields as $key => $data ) {
$output .= UM()->fields()->edit_field( $key, $data );
}echo $output; ?>
$fields = UM()->builtin()->get_specific_fields('password_reset_text,username_b'); ?>
<div class="um-col-alt um-col-alt-b">
<?php $output = null;
foreach( $fields as $key => $data ) {
$output .= UM()->fields()->edit_field( $key, $data );
} echo $output; ?>
<div class="um-center"><input type="submit" value="<?php _e('Change my password','ultimate-member'); ?>" class="um-button" id="um-submit-btn" /></div>
<?php
/**
* UM hook
*
* @type action
* @title um_after_password_reset_fields
* @description Hook that runs after user reset their password
* @input_vars
* [{"var":"$args","type":"array","desc":"Form data"}]
* @change_log
* ["Since: 2.0"]
* @usage add_action( 'um_after_password_reset_fields', 'function_name', 10, 1 );
* @example
* <?php
* add_action( 'um_after_password_reset_fields', 'my_after_password_reset_fields', 10, 1 );
* function my_after_password_reset_fields( $args ) {
* // your code here
* }
* ?>
*/
do_action( 'um_after_password_reset_fields', $args ); ?>
<div class="um-clear"></div>
<div class="um-col-alt um-col-alt-b">
</div>
<div class="um-center"><input type="submit" value="<?php _e('Reset my password','ultimate-member'); ?>" class="um-button" id="um-submit-btn" /></div>
<?php
<div class="um-clear"></div>
}
</div>
<?php
}
add_action( 'um_reset_password_form', 'um_reset_password_form' );
/**
* Change password form
*/
function um_change_password_form() {
$fields = UM()->builtin()->get_specific_fields('user_password'); ?>
<?php $output = null;
foreach( $fields as $key => $data ) {
$output .= UM()->fields()->edit_field( $key, $data );
}echo $output; ?>
<div class="um-col-alt um-col-alt-b">
<div class="um-center"><input type="submit" value="<?php _e('Change my password','ultimate-member'); ?>" class="um-button" id="um-submit-btn" /></div>
<div class="um-clear"></div>
</div>
<?php
}
add_action( 'um_change_password_form', 'um_change_password_form' );
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+60 -61
View File
@@ -1,70 +1,69 @@
<?php
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) exit;
<?php if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
/***
*** @profile name update
***/
add_action( 'um_update_profile_full_name', 'um_update_profile_full_name', 10, 2 );
function um_update_profile_full_name( $user_id, $changes ) {
// Sync display name changes
$option = UM()->options()->get( 'display_name' );
if ( ! isset( $user_id ) || empty( $user_id ) ) {
$user = get_user_by( 'email', $changes['user_email'] );
um_fetch_user( $user->ID );
$user_id = $user->ID;
}
switch ( $option ) {
default:
break;
case 'full_name':
$update_name = get_user_meta( $user_id, 'first_name', true ) . ' ' . get_user_meta( $user_id, 'last_name', true );
break;
case 'sur_name':
$fname = get_user_meta( $user_id, 'first_name', true );
$lname = get_user_meta( $user_id, 'last_name', true );
$update_name = $lname . ' ' . $fname;
break;
case 'initial_name':
$fname = get_user_meta( $user_id, 'first_name', true );
$lname = get_user_meta( $user_id, 'last_name', true );
$update_name = $fname . ' ' . ( !empty( $lname ) ? $lname[0] : '' );
break;
case 'initial_name_f':
$fname = get_user_meta( $user_id, 'first_name', true );
$lname = get_user_meta( $user_id, 'last_name', true );
$update_name = ( !empty($fname) ? $fname[0] : '' ) . ' ' . $lname;
break;
case 'nickname':
$update_name = get_user_meta( $user_id, 'nickname', true );
break;
/**
* Profile name update
*
* @param $user_id
* @param $changes
*/
function um_update_profile_full_name( $user_id, $changes ) {
// Sync display name changes
$option = UM()->options()->get( 'display_name' );
if ( ! isset( $user_id ) || empty( $user_id ) ) {
$user = get_user_by( 'email', $changes['user_email'] );
um_fetch_user( $user->ID );
$user_id = $user->ID;
}
switch ( $option ) {
default:
break;
case 'full_name':
$update_name = get_user_meta( $user_id, 'first_name', true ) . ' ' . get_user_meta( $user_id, 'last_name', true );
break;
case 'sur_name':
$fname = get_user_meta( $user_id, 'first_name', true );
$lname = get_user_meta( $user_id, 'last_name', true );
$update_name = $lname . ' ' . $fname;
break;
case 'initial_name':
$fname = get_user_meta( $user_id, 'first_name', true );
$lname = get_user_meta( $user_id, 'last_name', true );
$update_name = $fname . ' ' . ( !empty( $lname ) ? $lname[0] : '' );
break;
case 'initial_name_f':
$fname = get_user_meta( $user_id, 'first_name', true );
$lname = get_user_meta( $user_id, 'last_name', true );
$update_name = ( !empty($fname) ? $fname[0] : '' ) . ' ' . $lname;
break;
case 'nickname':
$update_name = get_user_meta( $user_id, 'nickname', true );
break;
}
if ( isset( $update_name ) ) {
$arr_user = array( 'ID' => $user_id, 'display_name' => $update_name );
$return = wp_update_user( $arr_user );
if( is_wp_error( $return ) ) {
wp_die( '<pre>' . var_export( array( 'message' => $return->get_error_message(), 'dump' => $arr_user, 'changes' => $changes ), true ) . '</pre>' );
}
if ( isset( $update_name ) ) {
$arr_user = array( 'ID' => $user_id, 'display_name' => $update_name );
$return = wp_update_user( $arr_user );
}
if( is_wp_error( $return ) ) {
wp_die( '<pre>' . var_export( array( 'message' => $return->get_error_message(), 'dump' => $arr_user, 'changes' => $changes ), true ) . '</pre>' );
}
if ( isset( $changes['first_name'] ) && isset( $changes['last_name'] ) ) {
}
$full_name = UM()->user()->profile['display_name'];
$full_name = UM()->validation()->safe_name_in_url( $full_name );
if ( isset( $changes['first_name'] ) && isset( $changes['last_name'] ) ) {
$full_name = UM()->user()->profile['display_name'];
$full_name = UM()->validation()->safe_name_in_url( $full_name );
update_user_meta( UM()->user()->id, 'full_name', $full_name );
update_user_meta( UM()->user()->id, 'full_name', $full_name );
}
}
// regenerate slug
UM()->user()->generate_profile_slug( $user_id );
}
// regenerate slug
UM()->user()->generate_profile_slug( $user_id );
}
add_action( 'um_update_profile_full_name', 'um_update_profile_full_name', 10, 2 );
+52 -56
View File
@@ -1,66 +1,62 @@
<?php
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) exit;
<?php if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
/**
* Account secure fields
* @param array $fields
* @param string $tab_key
* @return array
* @uses um_account_secure_fields
*/
function um_account_secure_fields( $fields, $tab_key ) {
/**
* Account secure fields
* @param array $fields
* @param string $tab_key
* @return array
* @uses um_account_secure_fields
* UM hook
*
* @type filter
* @title um_account_secure_fields__enabled
* @description Active account secure fields
* @input_vars
* [{"var":"$enabled","type":"string","desc":"Enable secure account fields"}]
* @change_log
* ["Since: 2.0"]
* @usage
* <?php add_filter( 'um_account_secure_fields__enabled', 'function_name', 10, 1 ); ?>
* @example
* <?php
* add_filter( 'um_account_secure_fields__enabled', 'my_account_secure_fields', 10, 1 );
* function my_account_secure_fields( $enabled ) {
* // your code here
* return $enabled;
* }
* ?>
*/
add_filter('um_account_secure_fields','um_account_secure_fields', 10, 2);
function um_account_secure_fields( $fields, $tab_key ){
/**
* UM hook
*
* @type filter
* @title um_account_secure_fields__enabled
* @description Active account secure fields
* @input_vars
* [{"var":"$enabled","type":"string","desc":"Enable secure account fields"}]
* @change_log
* ["Since: 2.0"]
* @usage
* <?php add_filter( 'um_account_secure_fields__enabled', 'function_name', 10, 1 ); ?>
* @example
* <?php
* add_filter( 'um_account_secure_fields__enabled', 'my_account_secure_fields', 10, 1 );
* function my_account_secure_fields( $enabled ) {
* // your code here
* return $enabled;
* }
* ?>
*/
$secure = apply_filters( 'um_account_secure_fields__enabled', true );
$secure = apply_filters( 'um_account_secure_fields__enabled', true );
if( ! $secure ) return $fields;
if( ! $secure ) return $fields;
if( isset( UM()->account()->register_fields ) && ! isset( UM()->account()->register_fields[ $tab_key ] ) ){
UM()->account()->register_fields[ $tab_key ] = $fields;
}
return $fields;
if( isset( UM()->account()->register_fields ) && ! isset( UM()->account()->register_fields[ $tab_key ] ) ){
UM()->account()->register_fields[ $tab_key ] = $fields;
}
/**
* Disables first and last name fields in account page
* @param array $fields
* @return array
* @uses um_get_field__first_name, um_get_field__last_name
*/
add_filter("um_get_field__first_name","um_account_disable_name_fields", 10 ,1 );
add_filter("um_get_field__last_name","um_account_disable_name_fields", 10 ,1 );
function um_account_disable_name_fields( $fields ){
if( ! UM()->options()->get( "account_name_disable" ) ) return $fields;
return $fields;
}
add_filter( 'um_account_secure_fields', 'um_account_secure_fields', 10, 2 );
if( um_is_core_page("account") ){
$fields['disabled'] = 'disabled="disabled"';
}
return $fields;
}
/**
* Disables first and last name fields in account page
* @param array $fields
* @return array
* @uses um_get_field__first_name, um_get_field__last_name
*/
function um_account_disable_name_fields( $fields ){
if( ! UM()->options()->get( "account_name_disable" ) ) return $fields;
if ( um_is_core_page("account") ) {
$fields['disabled'] = 'disabled="disabled"';
}
return $fields;
}
add_filter( "um_get_field__first_name","um_account_disable_name_fields", 10 ,1 );
add_filter( "um_get_field__last_name","um_account_disable_name_fields", 10 ,1 );
+94 -93
View File
@@ -1,103 +1,104 @@
<?php
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) exit;
<?php if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
/***
*** @Do not apply to backend default avatars
***/
add_filter('avatar_defaults', 'um_avatar_defaults', 99999 );
function um_avatar_defaults($avatar_defaults) {
remove_filter('get_avatar', 'um_get_avatar', 99999, 5);
return $avatar_defaults;
}
/**
* Do not apply to backend default avatars
*
* @param $avatar_defaults
*
* @return mixed
*/
function um_avatar_defaults( $avatar_defaults ) {
remove_filter( 'get_avatar', 'um_get_avatar', 99999 );
return $avatar_defaults;
}
add_filter( 'avatar_defaults', 'um_avatar_defaults', 99999 );
/**
* Get user UM avatars
* @param string $avatar
* @param string $id_or_email
* @param string $size
* @param string $avatar_class
* @param string $default
* @param string $alt
* @hooks filter `get_avatar`
* @return string returns avatar in image html elements
*/
function um_get_avatar( $avatar = '', $id_or_email='', $size = '96', $avatar_class = '', $default = '', $alt = '' ) {
if ( is_numeric($id_or_email) )
$user_id = (int) $id_or_email;
elseif ( is_string( $id_or_email ) && ( $user = get_user_by( 'email', $id_or_email ) ) )
$user_id = $user->ID;
elseif ( is_object( $id_or_email ) && ! empty( $id_or_email->user_id ) )
$user_id = (int) $id_or_email->user_id;
if ( empty( $user_id ) )
return $avatar;
um_fetch_user( $user_id );
$avatar = um_user('profile_photo', $size);
/**
* Get user UM avatars
* @param string $avatar
* @param string $id_or_email
* @param string $size
* @param string $avatar_class
* @param string $default
* @param string $alt
* @hooks filter `get_avatar`
* @return string returns avatar in image html elements
* UM hook
*
* @type filter
* @title um_avatar_image_alternate_text
* @description Change avatar image alt
* @input_vars
* [{"var":"$avatar_alt","type":"string","desc":"Image alternate text. Display name by default"}]
* @change_log
* ["Since: 2.0"]
* @usage
* <?php add_filter( 'um_avatar_image_alternate_text', 'function_name', 10, 1 ); ?>
* @example
* <?php
* add_filter( 'um_avatar_image_alternate_text', 'my_avatar_image_alternate_text', 10, 1 );
* function my_avatar_image_alternate_text( $avatar_alt ) {
* // your code here
* return $avatar_alt;
* }
* ?>
*/
add_filter('get_avatar', 'um_get_avatar', 99999, 5);
function um_get_avatar($avatar = '', $id_or_email='', $size = '96', $avatar_class = '', $default = '', $alt = '') {
$image_alt = apply_filters( "um_avatar_image_alternate_text", um_user("display_name") );
if ( is_numeric($id_or_email) )
$user_id = (int) $id_or_email;
elseif ( is_string( $id_or_email ) && ( $user = get_user_by( 'email', $id_or_email ) ) )
$user_id = $user->ID;
elseif ( is_object( $id_or_email ) && ! empty( $id_or_email->user_id ) )
$user_id = (int) $id_or_email->user_id;
if ( empty( $user_id ) )
return $avatar;
if ( ! $avatar && UM()->options()->get( 'use_gravatars' ) ) {
um_fetch_user( $user_id );
$avatar = um_user('profile_photo', $size);
/**
* UM hook
*
* @type filter
* @title um_avatar_image_alternate_text
* @description Change avatar image alt
* @input_vars
* [{"var":"$avatar_alt","type":"string","desc":"Image alternate text. Display name by default"}]
* @change_log
* ["Since: 2.0"]
* @usage
* <?php add_filter( 'um_avatar_image_alternate_text', 'function_name', 10, 1 ); ?>
* @example
* <?php
* add_filter( 'um_avatar_image_alternate_text', 'my_avatar_image_alternate_text', 10, 1 );
* function my_avatar_image_alternate_text( $avatar_alt ) {
* // your code here
* return $avatar_alt;
* }
* ?>
*/
$image_alt = apply_filters( "um_avatar_image_alternate_text", um_user("display_name") );
if ( ! $avatar && UM()->options()->get( 'use_gravatars' ) ) {
$default = get_option( 'avatar_default', 'mystery' );
if ( $default == 'gravatar_default' ) {
$default = '';
}
$rating = get_option('avatar_rating');
if ( !empty( $rating ) ) {
$rating = "&amp;r={$rating}";
}
if ( UM()->options()->get('use_gravatars') && ! um_user('synced_profile_photo') && ! $has_profile_photo ){
$avatar_url = um_get_domain_protocol().'gravatar.com/avatar/'.um_user('synced_gravatar_hashed_id');
$avatar_url = add_query_arg('s',400, $avatar_url);
$gravatar_type = UM()->options()->get( 'use_um_gravatar_default_builtin_image' );
if ( $gravatar_type == 'default' ) {
if ( UM()->options()->get( 'use_um_gravatar_default_image' ) ) {
$avatar_url = add_query_arg('d', um_get_default_avatar_uri(), $avatar_url );
}
} else {
$avatar_url = add_query_arg('d', $gravatar_type, $avatar_url );
}
}
$avatar = '<img src="' .$avatar_url .'?d='. $default . '&amp;s=' . $size . $rating .'" class="func-um_get_avatar gravatar avatar avatar-'.$size.' um-avatar" width="'.$size.'" height="'.$size.'" alt="'.$image_alt.'" />';
}else if( empty( $avatar ) ){
$default_avatar_uri = um_get_default_avatar_uri();
$avatar = '<img src="' .$default_avatar_uri .'" class="gravatar avatar avatar-'.$size.' um-avatar" width="'.$size.'" height="'.$size.'" alt="'.$image_alt.'" />';
$default = get_option( 'avatar_default', 'mystery' );
if ( $default == 'gravatar_default' ) {
$default = '';
}
return $avatar;
$rating = get_option('avatar_rating');
if ( !empty( $rating ) ) {
$rating = "&amp;r={$rating}";
}
if ( UM()->options()->get('use_gravatars') && ! um_user('synced_profile_photo') && ! $has_profile_photo ){
$avatar_url = um_get_domain_protocol().'gravatar.com/avatar/'.um_user('synced_gravatar_hashed_id');
$avatar_url = add_query_arg('s',400, $avatar_url);
$gravatar_type = UM()->options()->get( 'use_um_gravatar_default_builtin_image' );
if ( $gravatar_type == 'default' ) {
if ( UM()->options()->get( 'use_um_gravatar_default_image' ) ) {
$avatar_url = add_query_arg('d', um_get_default_avatar_uri(), $avatar_url );
}
} else {
$avatar_url = add_query_arg('d', $gravatar_type, $avatar_url );
}
}
$avatar = '<img src="' .$avatar_url .'?d='. $default . '&amp;s=' . $size . $rating .'" class="func-um_get_avatar gravatar avatar avatar-'.$size.' um-avatar" width="'.$size.'" height="'.$size.'" alt="'.$image_alt.'" />';
}else if( empty( $avatar ) ){
$default_avatar_uri = um_get_default_avatar_uri();
$avatar = '<img src="' .$default_avatar_uri .'" class="gravatar avatar avatar-'.$size.' um-avatar" width="'.$size.'" height="'.$size.'" alt="'.$image_alt.'" />';
}
return $avatar;
}
add_filter( 'get_avatar', 'um_get_avatar', 99999, 5 );
+25 -22
View File
@@ -1,34 +1,37 @@
<?php
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) exit;
<?php if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
/***
*** @Control comment author display
***/
add_filter('get_comment_author_link', 'um_comment_link_to_profile', 10000, 3 );
function um_comment_link_to_profile( $return, $author, $comment_ID ) {
/**
* Control comment author display
*
* @param $return
* @param $author
* @param $comment_ID
*
* @return string
*/
function um_comment_link_to_profile( $return, $author, $comment_ID ) {
$comment = get_comment( $comment_ID );
$comment = get_comment( $comment_ID );
if( isset( $comment->user_id ) && ! empty( $comment->user_id ) ){
if ( isset( UM()->user()->cached_user[ $comment->user_id ] ) && UM()->user()->cached_user[ $comment->user_id ] ) {
if( isset( $comment->user_id ) && ! empty( $comment->user_id ) ){
if ( isset( UM()->user()->cached_user[ $comment->user_id ] ) && UM()->user()->cached_user[ $comment->user_id ] ) {
$return = '<a href="'. UM()->user()->cached_user[$comment->user_id]['url'] . '">' . UM()->user()->cached_user[$comment->user_id]['name'] . '</a>';
$return = '<a href="'. UM()->user()->cached_user[$comment->user_id]['url'] . '">' . UM()->user()->cached_user[$comment->user_id]['name'] . '</a>';
} else {
} else {
um_fetch_user( $comment->user_id );
um_fetch_user( $comment->user_id );
UM()->user()->cached_user[ $comment->user_id ] = array('url' => um_user_profile_url(), 'name' => um_user('display_name') );
$return = '<a href="'. UM()->user()->cached_user[$comment->user_id]['url'] . '">' . UM()->user()->cached_user[$comment->user_id]['name'] . '</a>';
UM()->user()->cached_user[ $comment->user_id ] = array('url' => um_user_profile_url(), 'name' => um_user('display_name') );
$return = '<a href="'. UM()->user()->cached_user[$comment->user_id]['url'] . '">' . UM()->user()->cached_user[$comment->user_id]['name'] . '</a>';
um_reset_user();
um_reset_user();
}
}
return $return;
}
}
return $return;
}
add_filter('get_comment_author_link', 'um_comment_link_to_profile', 10000, 3 );
+480 -396
View File
@@ -1,118 +1,162 @@
<?php
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) exit;
<?php if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
/***
*** @field is required?
***/
add_filter('um_edit_label_all_fields', 'um_edit_label_all_fields', 10, 2);
function um_edit_label_all_fields( $label, $data ) {
/**
* Field is required?
*
* @param $label
* @param $data
*
* @return string
*/
function um_edit_label_all_fields( $label, $data ) {
$asterisk = UM()->options()->get( 'form_asterisk' );
if ( $asterisk && isset( $data['required'] ) && $data['required'] == 1 )
$label = $label . '<span class="um-req" title="'.__('Required','ultimate-member').'">*</span>';
$asterisk = UM()->options()->get( 'form_asterisk' );
if ( $asterisk && isset( $data['required'] ) && $data['required'] == 1 )
$label = $label . '<span class="um-req" title="'.__('Required','ultimate-member').'">*</span>';
return $label;
return $label;
}
add_filter( 'um_edit_label_all_fields', 'um_edit_label_all_fields', 10, 2 );
/**
* Outputs a soundcloud track
*
* @param $value
* @param $data
*
* @return string|void
*/
function um_profile_field_filter_hook__soundcloud_track( $value, $data ) {
if ( !is_numeric( $value ) ) {
return __( 'Invalid soundcloud track ID', 'ultimate-member' );
}
/***
*** @outputs a soundcloud track
***/
add_filter('um_profile_field_filter_hook__soundcloud_track', 'um_profile_field_filter_hook__soundcloud_track', 99, 2);
function um_profile_field_filter_hook__soundcloud_track( $value, $data ) {
if ( !is_numeric( $value ) ) {
return __('Invalid soundcloud track ID','ultimate-member');
}
$value = '<div class="um-soundcloud">
$value = '<div class="um-soundcloud">
<iframe width="100%" height="166" scrolling="no" frameborder="no" src="https://w.soundcloud.com/player/?url=https%3A//api.soundcloud.com/tracks/' . $value . '&amp;color=ff6600&amp;auto_play=false&amp;show_artwork=true"></iframe>
</div>';
return $value;
}
return $value;
}
add_filter( 'um_profile_field_filter_hook__soundcloud_track', 'um_profile_field_filter_hook__soundcloud_track', 99, 2 );
/***
*** @outputs a youtube video
***/
add_filter('um_profile_field_filter_hook__youtube_video', 'um_profile_field_filter_hook__youtube_video', 99, 2);
function um_profile_field_filter_hook__youtube_video( $value, $data ) {
if( empty( $value ) ){
return '';
}
$value = ( strstr( $value, 'http') || strstr( $value, '://' ) ) ? um_youtube_id_from_url( $value ) : $value;
$value = '<div class="um-youtube">
/**
* Outputs a youtube video
*
* @param $value
* @param $data
*
* @return bool|string
*/
function um_profile_field_filter_hook__youtube_video( $value, $data ) {
if( empty( $value ) ){
return '';
}
$value = ( strstr( $value, 'http') || strstr( $value, '://' ) ) ? um_youtube_id_from_url( $value ) : $value;
$value = '<div class="um-youtube">
<iframe width="600" height="450" src="https://www.youtube.com/embed/' . $value . '" frameborder="0" allowfullscreen></iframe>
</div>';
return $value;
return $value;
}
add_filter( 'um_profile_field_filter_hook__youtube_video', 'um_profile_field_filter_hook__youtube_video', 99, 2 );
/**
* Outputs a vimeo video
*
* @param $value
* @param $data
*
* @return int|string
*/
function um_profile_field_filter_hook__vimeo_video( $value, $data ) {
if ( empty( $value ) ) {
return '';
}
/***
*** @outputs a vimeo video
***/
add_filter('um_profile_field_filter_hook__vimeo_video', 'um_profile_field_filter_hook__vimeo_video', 99, 2);
function um_profile_field_filter_hook__vimeo_video( $value, $data ) {
if( empty( $value ) ){
return '';
}
$value = ( !is_numeric( $value ) ) ? (int) substr(parse_url($value, PHP_URL_PATH), 1) : $value;
$value = '<div class="um-vimeo">
$value = ( !is_numeric( $value ) ) ? (int) substr(parse_url($value, PHP_URL_PATH), 1) : $value;
$value = '<div class="um-vimeo">
<iframe src="https://player.vimeo.com/video/'. $value . '" width="600" height="450" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
</div>';
return $value;
}
return $value;
}
add_filter( 'um_profile_field_filter_hook__vimeo_video', 'um_profile_field_filter_hook__vimeo_video', 99, 2 );
/***
*** @outputs a google map
***/
add_filter('um_profile_field_filter_hook__googlemap', 'um_profile_field_filter_hook__googlemap', 99, 2);
function um_profile_field_filter_hook__googlemap( $value, $data ) {
$value = '<div class="um-googlemap">
/**
* Outputs a google map
*
* @param $value
* @param $data
*
* @return string
*/
function um_profile_field_filter_hook__googlemap( $value, $data ) {
$value = '<div class="um-googlemap">
<iframe width="600" height="450" frameborder="0" style="border:0" src="https://maps.google.it/maps?q=' . urlencode( $value ) . '&output=embed"></iframe>
</div>';
return $value;
}
add_filter( 'um_profile_field_filter_hook__googlemap', 'um_profile_field_filter_hook__googlemap', 99, 2 );
/**
* User's registration date
*
* @param $value
* @param $data
*
* @return false|int|string
*/
function um_profile_field_filter_hook__user_registered( $value, $data ) {
$value = strtotime($value);
$value = sprintf(__('Joined %s','ultimate-member'), date_i18n('F d, Y', $value) );
return $value;
}
add_filter( 'um_profile_field_filter_hook__user_registered', 'um_profile_field_filter_hook__user_registered', 99, 2 );
/**
* Last login date
*
* @param $value
* @param $data
*
* @return string
*/
function um_profile_field_filter_hook__last_login( $value, $data ) {
$value = sprintf( __('Last login: %s','ultimate-member'), um_user_last_login( um_user('ID') ) );
return $value;
}
add_filter( 'um_profile_field_filter_hook__last_login', 'um_profile_field_filter_hook__last_login', 99, 2 );
add_filter( 'um_profile_field_filter_hook___um_last_login', 'um_profile_field_filter_hook__last_login', 99, 2 );
/**
* URLs in textarea
*
* @param $value
* @param $data
*
* @return mixed|string|void
*/
function um_profile_field_filter_hook__textarea( $value, $data ) {
if ( isset( $data ) && isset( $data['html'] ) && $data['html'] == 1 )
return $value;
}
/***
*** @user's registration date
***/
add_filter('um_profile_field_filter_hook__user_registered', 'um_profile_field_filter_hook__user_registered', 99, 2);
function um_profile_field_filter_hook__user_registered( $value, $data ) {
$value = strtotime($value);
$value = sprintf(__('Joined %s','ultimate-member'), date_i18n('F d, Y', $value) );
return $value;
}
$value = esc_textarea( $value );
$value = preg_replace('$(https?://[a-z0-9_./?=&#-]+)(?![^<>]*>)$i', ' <a href="$1" target="_blank">$1</a> ', $value." ");
$value = preg_replace('$(www\.[a-z0-9_./?=&#-]+)(?![^<>]*>)$i', '<a target="_blank" href="http://$1">$1</a> ', $value." ");
$value = wpautop($value);
/***
*** @last login date
***/
add_filter('um_profile_field_filter_hook__last_login', 'um_profile_field_filter_hook__last_login', 99, 2);
add_filter('um_profile_field_filter_hook___um_last_login', 'um_profile_field_filter_hook__last_login', 99, 2);
function um_profile_field_filter_hook__last_login( $value, $data ) {
$value = sprintf( __('Last login: %s','ultimate-member'), um_user_last_login( um_user('ID') ) );
return $value;
}
/***
*** @urls in textarea
***/
add_filter('um_profile_field_filter_hook__textarea', 'um_profile_field_filter_hook__textarea', 99, 2);
function um_profile_field_filter_hook__textarea( $value, $data ) {
if ( isset( $data ) && isset( $data['html'] ) && $data['html'] == 1 )
return $value;
$value = esc_textarea( $value );
$value = preg_replace('$(https?://[a-z0-9_./?=&#-]+)(?![^<>]*>)$i', ' <a href="$1" target="_blank">$1</a> ', $value." ");
$value = preg_replace('$(www\.[a-z0-9_./?=&#-]+)(?![^<>]*>)$i', '<a target="_blank" href="http://$1">$1</a> ', $value." ");
$value = wpautop($value);
return $value;
}
return $value;
}
add_filter( 'um_profile_field_filter_hook__textarea', 'um_profile_field_filter_hook__textarea', 99, 2 );
/***
@@ -132,44 +176,59 @@ if ( ! defined( 'ABSPATH' ) ) exit;
}*/
/***
*** @time
***/
add_filter('um_profile_field_filter_hook__time', 'um_profile_field_filter_hook__time', 99, 2);
function um_profile_field_filter_hook__time( $value, $data ) {
/**
* Time field
*
* @param $value
* @param $data
*
* @return mixed|string
*/
function um_profile_field_filter_hook__time( $value, $data ) {
$value = UM()->datetime()->format( $value, $data['format'] );
$value = str_replace('am', 'a.m.', $value );
$value = str_replace('pm', 'p.m.', $value );
return $value;
}
add_filter( 'um_profile_field_filter_hook__time', 'um_profile_field_filter_hook__time', 99, 2 );
/**
* Date field
*
* @param $value
* @param $data
*
* @return string
*/
function um_profile_field_filter_hook__date( $value, $data ) {
if ( $data['pretty_format'] == 1 ) {
$value = UM()->datetime()->get_age( $value );
} else {
$value = UM()->datetime()->format( $value, $data['format'] );
$value = str_replace('am', 'a.m.', $value );
$value = str_replace('pm', 'p.m.', $value );
return $value;
}
/***
*** @date
***/
add_filter('um_profile_field_filter_hook__date', 'um_profile_field_filter_hook__date', 99, 2);
function um_profile_field_filter_hook__date( $value, $data ) {
if ( $data['pretty_format'] == 1 ) {
$value = UM()->datetime()->get_age( $value );
} else {
$value = UM()->datetime()->format( $value, $data['format'] );
}
return $value;
}
add_filter( 'um_profile_field_filter_hook__date', 'um_profile_field_filter_hook__date', 99, 2 );
return $value;
}
/***
*** @file
***/
add_filter('um_profile_field_filter_hook__file', 'um_profile_field_filter_hook__file', 99, 2);
function um_profile_field_filter_hook__file( $value, $data ) {
$uri = um_user_uploads_uri() . $value;
$extension = pathinfo( $uri, PATHINFO_EXTENSION);
/**
* File field
* @param $value
* @param $data
*
* @return string|void
*/
function um_profile_field_filter_hook__file( $value, $data ) {
$uri = um_user_uploads_uri() . $value;
$extension = pathinfo( $uri, PATHINFO_EXTENSION);
if ( !file_exists( um_user_uploads_dir() . $value ) ) {
$value = __('This file has been removed.');
} else {
$value = '<div class="um-single-file-preview show">
if ( !file_exists( um_user_uploads_dir() . $value ) ) {
$value = __('This file has been removed.');
} else {
$value = '<div class="um-single-file-preview show">
<div class="um-single-fileinfo">
<a href="' . $uri . '" target="_blank">
<span class="icon" style="background:'. UM()->files()->get_fonticon_bg_by_ext( $extension ) . '"><i class="'. UM()->files()->get_fonticon_by_ext( $extension ) .'"></i></span>
@@ -177,289 +236,313 @@ if ( ! defined( 'ABSPATH' ) ) exit;
</a>
</div>
</div>';
}
return $value;
}
/***
*** @image
***/
add_filter('um_profile_field_filter_hook__image', 'um_profile_field_filter_hook__image', 99, 2);
function um_profile_field_filter_hook__image( $value, $data ) {
$uri = um_user_uploads_uri() . $value;
$title = ( isset( $data['title'] ) ) ? $data['title'] : __('Untitled photo');
return $value;
}
add_filter( 'um_profile_field_filter_hook__file', 'um_profile_field_filter_hook__file', 99, 2 );
/**
* Image field
*
* @param $value
* @param $data
*
* @return string
*/
function um_profile_field_filter_hook__image( $value, $data ) {
$uri = um_user_uploads_uri() . $value;
$title = ( isset( $data['title'] ) ) ? $data['title'] : __('Untitled photo');
// if value is an image tag
if( preg_match( '/\<img.*src=\"([^"]+).*/', $value, $matches ) ) {
$uri = $matches[1];
$value = '<div class="um-photo"><a href="#" class="um-photo-modal" data-src="'.$uri.'"><img src="'. $uri .'" alt="'.$title.'" title="'.$title.'" class="" /></a></div>';
} else if ( file_exists( um_user_uploads_dir() . $value ) ) {
$value = '<div class="um-photo"><a href="#" class="um-photo-modal" data-src="'.$uri.'"><img src="'. $uri .'" alt="'.$title.'" title="'.$title.'" class="" /></a></div>';
} else {
$value = '';
}
return $value;
}
add_filter( 'um_profile_field_filter_hook__image', 'um_profile_field_filter_hook__image', 99, 2 );
/**
* Global sanitize
*
* @param $value
* @param $data
* @param string $type
*
* @return string
*/
function um_profile_field_filter_hook__( $value, $data, $type = '' ) {
if ( !$value ) return '';
if ( ( isset( $data['validate'] ) && $data['validate'] != '' && strstr( $data['validate'], 'url' ) ) || ( isset( $data['type'] ) && $data['type'] == 'url' ) ) {
$alt = ( isset( $data['url_text'] ) && !empty( $data['url_text'] ) ) ? $data['url_text'] : $value;
$url_rel = ( isset( $data['url_rel'] ) && $data['url_rel'] == 'nofollow' ) ? 'rel="nofollow"' : '';
if( !strstr( $value, 'http' )
&& !strstr( $value, '://' )
&& !strstr( $value, 'www.' )
&& !strstr( $value, '.com' )
&& !strstr( $value, '.net' )
&& !strstr( $value, '.org' )
) {
if ( $data['validate'] == 'soundcloud_url' ) $value = 'https://soundcloud.com/' . $value;
if ( $data['validate'] == 'youtube_url' ) $value = 'https://youtube.com/user/' . $value;
if ( $data['validate'] == 'facebook_url' ) $value = 'https://facebook.com/' . $value;
if ( $data['validate'] == 'twitter_url' ) $value = 'https://twitter.com/' . $value;
if ( $data['validate'] == 'linkedin_url' ) $value = 'https://linkedin.com/' . $value;
if ( $data['validate'] == 'skype' ) $value = $value;
if ( $data['validate'] == 'googleplus_url' ) $value = 'https://plus.google.com/' . $value;
if ( $data['validate'] == 'instagram_url' ) $value = 'https://instagram.com/' . $value;
if ( $data['validate'] == 'vk_url' ) $value = 'https://vk.com/' . $value;
}
if ( isset( $data['validate'] ) && $data['validate'] == 'skype' ) {
$value = $value;
// if value is an image tag
if( preg_match( '/\<img.*src=\"([^"]+).*/', $value, $matches ) ) {
$uri = $matches[1];
$value = '<div class="um-photo"><a href="#" class="um-photo-modal" data-src="'.$uri.'"><img src="'. $uri .'" alt="'.$title.'" title="'.$title.'" class="" /></a></div>';
} else if ( file_exists( um_user_uploads_dir() . $value ) ) {
$value = '<div class="um-photo"><a href="#" class="um-photo-modal" data-src="'.$uri.'"><img src="'. $uri .'" alt="'.$title.'" title="'.$title.'" class="" /></a></div>';
} else {
$value = '';
if ( strpos($value, 'http://') !== 0 ) {
$value = 'http://' . $value;
}
$data['url_target'] = ( isset( $data['url_target'] ) ) ? $data['url_target'] : '_blank';
$value = '<a href="'. $value .'" title="'.$alt.'" target="'.$data['url_target'].'" ' . $url_rel . '>'.$alt.'</a>';
}
return $value;
}
/***
*** @global
***/
add_filter('um_profile_field_filter_hook__', 'um_profile_field_filter_hook__', 99, 3 );
function um_profile_field_filter_hook__( $value, $data, $type = '' ) {
if ( !$value ) return '';
if ( !is_array( $value ) ) {
if ( is_email( $value ) )
$value = '<a href="mailto:'. $value.'" title="'.$value.'">'.$value.'</a>';
} else {
$value = implode(', ', $value);
}
if ( ( isset( $data['validate'] ) && $data['validate'] != '' && strstr( $data['validate'], 'url' ) ) || ( isset( $data['type'] ) && $data['type'] == 'url' ) ) {
$alt = ( isset( $data['url_text'] ) && !empty( $data['url_text'] ) ) ? $data['url_text'] : $value;
$url_rel = ( isset( $data['url_rel'] ) && $data['url_rel'] == 'nofollow' ) ? 'rel="nofollow"' : '';
if( !strstr( $value, 'http' )
&& !strstr( $value, '://' )
&& !strstr( $value, 'www.' )
&& !strstr( $value, '.com' )
&& !strstr( $value, '.net' )
&& !strstr( $value, '.org' )
) {
if ( $data['validate'] == 'soundcloud_url' ) $value = 'https://soundcloud.com/' . $value;
if ( $data['validate'] == 'youtube_url' ) $value = 'https://youtube.com/user/' . $value;
if ( $data['validate'] == 'facebook_url' ) $value = 'https://facebook.com/' . $value;
if ( $data['validate'] == 'twitter_url' ) $value = 'https://twitter.com/' . $value;
if ( $data['validate'] == 'linkedin_url' ) $value = 'https://linkedin.com/' . $value;
if ( $data['validate'] == 'skype' ) $value = $value;
if ( $data['validate'] == 'googleplus_url' ) $value = 'https://plus.google.com/' . $value;
if ( $data['validate'] == 'instagram_url' ) $value = 'https://instagram.com/' . $value;
if ( $data['validate'] == 'vk_url' ) $value = 'https://vk.com/' . $value;
}
$value = str_replace('https://https://','https://',$value);
$value = str_replace('http://https://','https://',$value);
//$value = UM()->shortcodes()->emotize( $value );
return $value;
if ( isset( $data['validate'] ) && $data['validate'] == 'skype' ) {
}
add_filter( 'um_profile_field_filter_hook__', 'um_profile_field_filter_hook__', 99, 3 );
$value = $value;
} else {
/**
* Get form fields
*
* @param $array
*
* @return mixed|string
*/
function um_get_form_fields( $array ) {
if ( strpos($value, 'http://') !== 0 ) {
$value = 'http://' . $value;
$form_id = (isset ( UM()->fields()->set_id ) ) ? UM()->fields()->set_id : null;
$mode = (isset( UM()->fields()->set_mode ) ) ? UM()->fields()->set_mode : null;
if ( $form_id && $mode ) {
$array = UM()->query()->get_attr('custom_fields', $form_id );
} else {
$array = '';
}
return $array;
}
add_filter( 'um_get_form_fields', 'um_get_form_fields', 99 );
/**
* Validate conditional logic
*
* @param $array
* @param $fields
* @return mixed
*/
function um_get_custom_field_array( $array, $fields ) {
if ( isset( $array['conditions'] ) ) {
for ( $a = 0; $a < count( $array['conditions'] ); $a++ ) {
if ( isset( $array['conditional_value'] ) || isset( $array['conditional_value' . $a] ) ) {
foreach ( $array['conditions'] as $key => $value ) {
$condition_metakey = $fields[ $value[1] ]['metakey'];
if ( isset( $_POST[ $condition_metakey ] ) ) {
$cond_value = ( $fields[ $value[1] ]['type'] == 'radio' ) ? $_POST[ $condition_metakey ][0] : $_POST[ $condition_metakey ];
if ( isset( $array['conditional_value'] ) && $cond_value !== $array['conditional_value'] ) {
$array['required'] = 0;
} elseif ( isset( $array['conditional_value'.$a] ) && $cond_value !== $array['conditional_value'.$a] ) {
$array['required'] = 0;
}
}
}
$data['url_target'] = ( isset( $data['url_target'] ) ) ? $data['url_target'] : '_blank';
$value = '<a href="'. $value .'" title="'.$alt.'" target="'.$data['url_target'].'" ' . $url_rel . '>'.$alt.'</a>';
}
}
}
if ( !is_array( $value ) ) {
if ( is_email( $value ) )
$value = '<a href="mailto:'. $value.'" title="'.$value.'">'.$value.'</a>';
} else {
$value = implode(', ', $value);
}
return $array;
}
add_filter( 'um_get_custom_field_array', 'um_get_custom_field_array', 99, 2 );
$value = str_replace('https://https://','https://',$value);
$value = str_replace('http://https://','https://',$value);
//$value = UM()->shortcodes()->emotize( $value );
/**
* Force fields to use UTF-8 encoding
*
* @param mixed $value
* @param array $data
* @param string $type
*
* @return mixed
*/
function um_force_utf8_fields( $value, $data, $type = '' ) {
if( ! UM()->options()->get('um_force_utf8_strings') )
return $value;
}
/***
*** @get form fields
***/
add_filter('um_get_form_fields', 'um_get_form_fields', 99);
function um_get_form_fields( $array ) {
$form_id = (isset ( UM()->fields()->set_id ) ) ? UM()->fields()->set_id : null;
$mode = (isset( UM()->fields()->set_mode ) ) ? UM()->fields()->set_mode : null;
if ( $form_id && $mode ) {
$array = UM()->query()->get_attr('custom_fields', $form_id );
} else {
$array = '';
}
return $array;
}
/**
* Validate conditional logic
*
* @param $array
* @param $fields
* @return mixed
*/
function um_get_custom_field_array( $array, $fields ) {
if ( isset( $array['conditions'] ) ) {
for ( $a = 0; $a < count( $array['conditions'] ); $a++ ) {
if ( isset( $array['conditional_value'] ) || isset( $array['conditional_value' . $a] ) ) {
foreach ( $array['conditions'] as $key => $value ) {
$condition_metakey = $fields[ $value[1] ]['metakey'];
if ( isset( $_POST[ $condition_metakey ] ) ) {
$cond_value = ( $fields[ $value[1] ]['type'] == 'radio' ) ? $_POST[ $condition_metakey ][0] : $_POST[ $condition_metakey ];
if ( isset( $array['conditional_value'] ) && $cond_value !== $array['conditional_value'] ) {
$array['required'] = 0;
} elseif ( isset( $array['conditional_value'.$a] ) && $cond_value !== $array['conditional_value'.$a] ) {
$array['required'] = 0;
}
}
}
}
}
}
return $array;
}
add_filter( 'um_get_custom_field_array', 'um_get_custom_field_array', 99, 2 );
/**
* Force fields to use UTF-8 encoding
* @param mixed $value
* @param array $data
* @return mixed
* @uses hook filter: um_profile_field_filter_hook__
*/
add_filter('um_profile_field_filter_hook__','um_force_utf8_fields', 9, 3 );
function um_force_utf8_fields( $value, $data, $type = '' ) {
if( ! UM()->options()->get('um_force_utf8_strings') )
return $value;
$value = um_force_utf8_string( $value );
return $value;
}
add_filter('um_profile_field_filter_hook__','um_force_utf8_fields', 9, 3 );
/**
* Filter profile data value
* @param mixed $value
* @return mixed
* @uses hook filter: um_is_selected_filter_value
*/
add_filter('um_is_selected_filter_value','um_is_selected_filter_value',1,9);
add_filter('um_select_dropdown_dynamic_option_value','um_is_selected_filter_value',1,10);
function um_is_selected_filter_value( $value ){
if ( ! UM()->options()->get('um_force_utf8_strings') )
return $value;
$value = um_force_utf8_string( $value );
/**
* Filter profile data value
* @param mixed $value
* @return mixed
* @uses hook filter: um_is_selected_filter_value
*/
function um_is_selected_filter_value( $value ) {
if ( ! UM()->options()->get('um_force_utf8_strings') )
return $value;
}
/**
* Filter select dropdown to use UTF-8 encoding
* @param array $options
* @param array $data
* @return $options
* @uses hook filter: um_select_dropdown_dynamic_options
*/
add_filter('um_select_dropdown_dynamic_options','um_select_dropdown_dynamic_options_to_utf8',2,10);
function um_select_dropdown_dynamic_options_to_utf8( $options, $data ){
if ( ! UM()->options()->get( 'um_force_utf8_strings' ) )
return $options;
$value = um_force_utf8_string( $value );
foreach ( $options as $key => $value ) {
$options[ $key ] = um_force_utf8_string( $value );
}
return $value;
}
add_filter( 'um_is_selected_filter_value','um_is_selected_filter_value', 1, 9 );
add_filter( 'um_select_dropdown_dynamic_option_value','um_is_selected_filter_value', 1, 10 );
/**
* Filter select dropdown to use UTF-8 encoding
*
* @param array $options
* @param array $data
* @return array
* @uses hook filter: um_select_dropdown_dynamic_options
*/
function um_select_dropdown_dynamic_options_to_utf8( $options, $data ){
if ( ! UM()->options()->get( 'um_force_utf8_strings' ) )
return $options;
foreach ( $options as $key => $value ) {
$options[ $key ] = um_force_utf8_string( $value );
}
/**
* Filter non-UTF8 strings
* @param string $value
* @return string
* @uses hook filter: um_field_non_utf8_value
*/
add_filter( 'um_field_non_utf8_value', 'um_field_non_utf8_value' );
function um_field_non_utf8_value( $value ) {
return $options;
}
add_filter( 'um_select_dropdown_dynamic_options','um_select_dropdown_dynamic_options_to_utf8', 2, 10 );
if ( function_exists( 'mb_detect_encoding' ) ) {
$encoding = mb_detect_encoding( $value, 'utf-8, iso-8859-1, ascii', true );
if ( strcasecmp( $encoding, 'UTF-8' ) !== 0 ) {
$value = iconv( $encoding, 'utf-8', $value );
}
}
return $value;
}
/**
* Filter non-UTF8 strings
* @param string $value
* @return string
* @uses hook filter: um_field_non_utf8_value
*/
function um_field_non_utf8_value( $value ) {
/**
* Returns dropdown/multi-select options from a callback function
* @param $options array
* @param $data array
* @return $options array
* @uses hook filter: um_select_dropdown_dynamic_options, um_multiselect_options
*/
add_filter('um_select_dropdown_dynamic_options','um_select_dropdown_dynamic_callback_options', 10, 2);
add_filter('um_multiselect_options','um_select_dropdown_dynamic_callback_options', 10, 2);
function um_select_dropdown_dynamic_callback_options( $options, $data ){
if( isset( $data['custom_dropdown_options_source'] ) && ! empty( $data['custom_dropdown_options_source'] ) ){
if( function_exists( $data['custom_dropdown_options_source'] ) ){
$options = call_user_func( $data['custom_dropdown_options_source'] );
}
}
return $options;
}
/**
*
* Pair dropdown/multi-select options from a callback function
* @param $value string
* @param $type string
* @param $data array
* @return $value string
* @uses hook filter: um_profile_field_filter_hook__
*/
add_filter('um_profile_field_filter_hook__select','um_option_match_callback_view_field', 10, 2);
add_filter('um_profile_field_filter_hook__multiselect','um_option_match_callback_view_field', 10, 2);
add_filter('um_field_select_default_value','um_option_match_callback_view_field', 10, 2);
add_filter('um_field_multiselect_default_value','um_option_match_callback_view_field', 10, 2);
function um_option_match_callback_view_field( $value, $data ){
if( ! empty( $data['custom_dropdown_options_source'] ) ){
return UM()->fields()->get_option_value_from_callback( $value, $data, $data['type'] );
if ( function_exists( 'mb_detect_encoding' ) ) {
$encoding = mb_detect_encoding( $value, 'utf-8, iso-8859-1, ascii', true );
if ( strcasecmp( $encoding, 'UTF-8' ) !== 0 ) {
$value = iconv( $encoding, 'utf-8', $value );
}
}
return $value;
}
return $value;
}
add_filter( 'um_field_non_utf8_value', 'um_field_non_utf8_value' );
/**
* Apply textdomain in select/multi-select options
* @param $value string
* @param $type string
* @param $data array
* @return $value string
* @uses hook filters: um_profile_field_filter_hook__select, um_profile_field_filter_hook__multiselect
*/
add_filter('um_profile_field_filter_hook__select','um_profile_field__select_translate', 10, 2);
add_filter('um_profile_field_filter_hook__multiselect','um_profile_field__select_translate', 10, 2);
function um_profile_field__select_translate( $value, $data ){
if( empty( $value ) ) return $value;
/**
* Returns dropdown/multi-select options from a callback function
* @param $options array
* @param $data array
* @return array
* @uses hook filter: um_select_dropdown_dynamic_options, um_multiselect_options
*/
function um_select_dropdown_dynamic_callback_options( $options, $data ) {
$options = explode(", ", $value );
$arr_options = array();
if( is_array( $options ) ){
foreach ( $options as $item ) {
$arr_options[] = __( $item, 'ultimate-member' );
}
}
if( isset( $data['custom_dropdown_options_source'] ) && ! empty( $data['custom_dropdown_options_source'] ) ){
$value = implode(", ", $arr_options);
if( function_exists( $data['custom_dropdown_options_source'] ) ){
$options = call_user_func( $data['custom_dropdown_options_source'] );
}
}
return $value;
}
return $options;
}
add_filter( 'um_select_dropdown_dynamic_options','um_select_dropdown_dynamic_callback_options', 10, 2 );
add_filter( 'um_multiselect_options','um_select_dropdown_dynamic_callback_options', 10, 2 );
/**
* Pair dropdown/multi-select options from a callback function
*
* @param $value string
* @param $data array
* @return string
* @uses hook filter: um_profile_field_filter_hook__
*/
function um_option_match_callback_view_field( $value, $data ) {
if( ! empty( $data['custom_dropdown_options_source'] ) ){
return UM()->fields()->get_option_value_from_callback( $value, $data, $data['type'] );
}
return $value;
}
add_filter('um_profile_field_filter_hook__select','um_option_match_callback_view_field', 10, 2);
add_filter('um_profile_field_filter_hook__multiselect','um_option_match_callback_view_field', 10, 2);
add_filter('um_field_select_default_value','um_option_match_callback_view_field', 10, 2);
add_filter('um_field_multiselect_default_value','um_option_match_callback_view_field', 10, 2);
/**
* Apply textdomain in select/multi-select options
*
* @param $value string
* @param $data array
* @return string
* @uses hook filters: um_profile_field_filter_hook__select, um_profile_field_filter_hook__multiselect
*/
function um_profile_field__select_translate( $value, $data ) {
if ( empty( $value ) ) return $value;
$options = explode(", ", $value );
$arr_options = array();
if( is_array( $options ) ){
foreach ( $options as $item ) {
$arr_options[] = __( $item, 'ultimate-member' );
}
}
$value = implode(", ", $arr_options);
return $value;
}
add_filter( 'um_profile_field_filter_hook__select','um_profile_field__select_translate', 10, 2 );
add_filter( 'um_profile_field_filter_hook__multiselect','um_profile_field__select_translate', 10, 2 );
/**
@@ -488,39 +571,40 @@ function um_profile_field_filter_xss_validation( $value, $data, $type = '' ) {
}
add_filter( 'um_profile_field_filter_hook__','um_profile_field_filter_xss_validation', 10, 3 );
/**
* add role_select and role_radio to the $post_form
* It is necessary for that if on these fields the conditional logic
* @param $post_form array
* @param $mode
*
* @return $post_form
* @uses hook filters: um_submit_form_data
*/
function um_submit_form_data_role_fields( $post_form, $mode ) {
$custom_fields = unserialize( $post_form['custom_fields'] );
if ( ! empty( $post_form['role'] ) && array_key_exists( 'role_select', $custom_fields ) ) {
$post_form['role_select'] = $post_form['role'];
}
if (! empty( $post_form['role'] ) && array_key_exists( 'role_radio', $custom_fields ) ) {
$post_form['role_radio'] = $post_form['role'];
}
return $post_form;
/**
* add role_select and role_radio to the $post_form
* It is necessary for that if on these fields the conditional logic
* @param $post_form array
* @param $mode
*
* @return $post_form
* @uses hook filters: um_submit_form_data
*/
function um_submit_form_data_role_fields( $post_form, $mode ) {
$custom_fields = unserialize( $post_form['custom_fields'] );
if ( ! empty( $post_form['role'] ) && array_key_exists( 'role_select', $custom_fields ) ) {
$post_form['role_select'] = $post_form['role'];
}
add_filter( 'um_submit_form_data', 'um_submit_form_data_role_fields', 10, 2 );
/**
* Cleaning on XSS injection for url editing field
* @param $value string
* @param $key string
*
* @return string $value
* @uses hook filters: um_edit_url_field_value
*/
function um_edit_url_field_value( $value, $key ) {
$value = esc_attr( $value );
return $value;
if (! empty( $post_form['role'] ) && array_key_exists( 'role_radio', $custom_fields ) ) {
$post_form['role_radio'] = $post_form['role'];
}
add_filter( 'um_edit_url_field_value', 'um_edit_url_field_value', 10, 2 );
return $post_form;
}
add_filter( 'um_submit_form_data', 'um_submit_form_data_role_fields', 10, 2 );
/**
* Cleaning on XSS injection for url editing field
* @param $value string
* @param $key string
*
* @return string $value
* @uses hook filters: um_edit_url_field_value
*/
function um_edit_url_field_value( $value, $key ) {
$value = esc_attr( $value );
return $value;
}
add_filter( 'um_edit_url_field_value', 'um_edit_url_field_value', 10, 2 );
+11 -9
View File
@@ -1,13 +1,13 @@
<?php
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) exit;
<?php if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
/***
*** @Support multisite
***/
add_filter('um_upload_basedir_filter','um_multisite_urls_support', 99 );
add_filter('um_upload_baseurl_filter','um_multisite_urls_support', 99 );
/**
* Support multisite
*
* @param $dir
*
* @return string
*/
function um_multisite_urls_support( $dir ) {
if ( is_multisite() ) { // Need to the work
@@ -66,4 +66,6 @@ function um_multisite_urls_support( $dir ) {
}
return $dir;
}
}
add_filter( 'um_upload_basedir_filter', 'um_multisite_urls_support', 99 );
add_filter( 'um_upload_baseurl_filter', 'um_multisite_urls_support', 99 );
+139 -120
View File
@@ -1,135 +1,154 @@
<?php
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) exit;
<?php if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
/***
*** @filter to allow whitelisted IP to access the wp-admin login
***/
add_filter('um_whitelisted_wpadmin_access', 'um_whitelisted_wpadmin_access');
function um_whitelisted_wpadmin_access( $allowed ) {
$ips = UM()->options()->get( 'wpadmin_allow_ips' );
if ( !$ips )
return $allowed;
$ips = array_map("rtrim", explode("\n", $ips));
$user_ip = um_user_ip();
if ( in_array( $user_ip, $ips ) )
$allowed = 1;
/**
* Filter to allow whitelisted IP to access the wp-admin login
*
* @param $allowed
*
* @return int
*/
function um_whitelisted_wpadmin_access( $allowed ) {
$ips = UM()->options()->get( 'wpadmin_allow_ips' );
if ( !$ips )
return $allowed;
}
/***
*** @filter to customize errors
***/
add_filter('login_message', 'um_custom_wp_err_messages');
function um_custom_wp_err_messages( $message ) {
$ips = array_map("rtrim", explode("\n", $ips));
$user_ip = um_user_ip();
if ( isset( $_REQUEST['err'] ) && !empty( $_REQUEST['err'] ) ) {
switch( $_REQUEST['err'] ) {
case 'blocked_email':
$err = __('This email address has been blocked.','ultimate-member');
break;
case 'blocked_ip':
$err = __('Your IP address has been blocked.','ultimate-member');
break;
}
}
if ( in_array( $user_ip, $ips ) )
$allowed = 1;
if ( isset( $err ) ) {
$message = '<div class="login" id="login_error">'.$err.'</div>';
return $allowed;
}
add_filter( 'um_whitelisted_wpadmin_access', 'um_whitelisted_wpadmin_access' );
/**
* Filter to customize errors
*
* @param $message
*
* @return string
*/
function um_custom_wp_err_messages( $message ) {
if ( isset( $_REQUEST['err'] ) && !empty( $_REQUEST['err'] ) ) {
switch( $_REQUEST['err'] ) {
case 'blocked_email':
$err = __('This email address has been blocked.','ultimate-member');
break;
case 'blocked_ip':
$err = __('Your IP address has been blocked.','ultimate-member');
break;
}
return $message;
}
/***
*** @check for blocked ip
***/
add_filter('authenticate', 'um_wp_form_errors_hook_ip_test', 10, 3);
function um_wp_form_errors_hook_ip_test( $user, $username, $password ) {
if ( ! empty( $username ) ) {
/**
* UM hook
*
* @type action
* @title um_submit_form_errors_hook__blockedips
* @description Hook that runs after user reset their password
* @input_vars
* [{"var":"$args","type":"array","desc":"Form data"}]
* @change_log
* ["Since: 2.0"]
* @usage add_action( 'um_submit_form_errors_hook__blockedips', 'function_name', 10, 1 );
* @example
* <?php
* add_action( 'um_submit_form_errors_hook__blockedips', 'my_submit_form_errors_hook__blockedips', 10, 1 );
* function my_submit_form_errors_hook__blockedips( $args ) {
* // your code here
* }
* ?>
*/
do_action( "um_submit_form_errors_hook__blockedips", $args = array() );
/**
* UM hook
*
* @type action
* @title um_submit_form_errors_hook__blockedemails
* @description Hook that runs after user reset their password
* @input_vars
* [{"var":"$args","type":"array","desc":"Form data"}]
* @change_log
* ["Since: 2.0"]
* @usage add_action( 'um_submit_form_errors_hook__blockedemails', 'function_name', 10, 1 );
* @example
* <?php
* add_action( 'um_submit_form_errors_hook__blockedemails', 'my_submit_form_errors_hook__blockedemails', 10, 1 );
* function my_submit_form_errors_hook__blockedemails( $args ) {
* // your code here
* }
* ?>
*/
do_action( "um_submit_form_errors_hook__blockedemails", $args = array( 'username' => $username ) );
if ( isset( $err ) ) {
$message = '<div class="login" id="login_error">'.$err.'</div>';
}
return $message;
}
add_filter( 'login_message', 'um_custom_wp_err_messages' );
/**
* Check for blocked ip
*
* @param $user
* @param $username
* @param $password
*
* @return mixed
*/
function um_wp_form_errors_hook_ip_test( $user, $username, $password ) {
if ( ! empty( $username ) ) {
/**
* UM hook
*
* @type action
* @title um_submit_form_errors_hook__blockedips
* @description Hook that runs after user reset their password
* @input_vars
* [{"var":"$args","type":"array","desc":"Form data"}]
* @change_log
* ["Since: 2.0"]
* @usage add_action( 'um_submit_form_errors_hook__blockedips', 'function_name', 10, 1 );
* @example
* <?php
* add_action( 'um_submit_form_errors_hook__blockedips', 'my_submit_form_errors_hook__blockedips', 10, 1 );
* function my_submit_form_errors_hook__blockedips( $args ) {
* // your code here
* }
* ?>
*/
do_action( "um_submit_form_errors_hook__blockedips", $args = array() );
/**
* UM hook
*
* @type action
* @title um_submit_form_errors_hook__blockedemails
* @description Hook that runs after user reset their password
* @input_vars
* [{"var":"$args","type":"array","desc":"Form data"}]
* @change_log
* ["Since: 2.0"]
* @usage add_action( 'um_submit_form_errors_hook__blockedemails', 'function_name', 10, 1 );
* @example
* <?php
* add_action( 'um_submit_form_errors_hook__blockedemails', 'my_submit_form_errors_hook__blockedemails', 10, 1 );
* function my_submit_form_errors_hook__blockedemails( $args ) {
* // your code here
* }
* ?>
*/
do_action( "um_submit_form_errors_hook__blockedemails", $args = array( 'username' => $username ) );
}
return $user;
}
/***
*** @login checks thru the wordpress admin login
***/
add_filter('authenticate', 'um_wp_form_errors_hook_logincheck', 50, 3);
function um_wp_form_errors_hook_logincheck( $user, $username, $password ) {
do_action('wp_authenticate_username_password_before', $user, $username, $password );
if ( isset( $user->ID ) ) {
um_fetch_user( $user->ID );
$status = um_user('account_status');
switch( $status ) {
case 'inactive':
return new WP_Error( $status, __('Your account has been disabled.','ultimate-member') );
break;
case 'awaiting_admin_review':
return new WP_Error( $status, __('Your account has not been approved yet.','ultimate-member') );
break;
case 'awaiting_email_confirmation':
return new WP_Error( $status, __('Your account is awaiting e-mail verification.','ultimate-member') );
break;
case 'rejected':
return new WP_Error( $status, __('Your membership request has been rejected.','ultimate-member') );
break;
}
return $user;
}
add_filter( 'authenticate', 'um_wp_form_errors_hook_ip_test', 10, 3 );
/**
* Login checks thru the wordpress admin login
*
* @param $user
* @param $username
* @param $password
*
* @return WP_Error|WP_User
*/
function um_wp_form_errors_hook_logincheck( $user, $username, $password ) {
do_action( 'wp_authenticate_username_password_before', $user, $username, $password );
if ( isset( $user->ID ) ) {
um_fetch_user( $user->ID );
$status = um_user('account_status');
switch( $status ) {
case 'inactive':
return new WP_Error( $status, __('Your account has been disabled.','ultimate-member') );
break;
case 'awaiting_admin_review':
return new WP_Error( $status, __('Your account has not been approved yet.','ultimate-member') );
break;
case 'awaiting_email_confirmation':
return new WP_Error( $status, __('Your account is awaiting e-mail verification.','ultimate-member') );
break;
case 'rejected':
return new WP_Error( $status, __('Your membership request has been rejected.','ultimate-member') );
break;
}
return wp_authenticate_username_password( $user, $username, $password );
}
}
return wp_authenticate_username_password( $user, $username, $password );
}
add_filter( 'authenticate', 'um_wp_form_errors_hook_logincheck', 50, 3 );
+411 -385
View File
@@ -1,462 +1,488 @@
<?php
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) exit;
<?php if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
/***
*** @Members Filter Hooks
***/
add_filter( 'um_prepare_user_query_args', 'um_prepare_user_query_args', 10, 2 );
add_filter( 'um_prepare_user_query_args', 'um_add_search_to_query', 50, 2 );
add_filter( 'um_prepare_user_query_args', 'um_search_usernames_emails', 51, 2 );
add_filter( 'um_prepare_user_query_args', 'um_remove_special_users_from_list', 99, 2 );
/**
* WP API user search
*
* @param $query_args
* @param $args
*
* @return mixed
*/
function um_search_usernames_emails( $query_args, $args ) {
extract( $args );
/***
*** @WP API user search
***/
function um_search_usernames_emails( $query_args, $args ) {
extract( $args );
$query = UM()->permalinks()->get_query_array();
$arr_columns = array();
$query = UM()->permalinks()->get_query_array();
$arr_columns = array();
foreach ( UM()->members()->core_search_fields as $key ) {
if ( ! empty( $query[ $key ] ) ) {
$arr_columns[] = $key;
$query_args['search'] = '*' . $query[ $key ] .'*';
}
foreach ( UM()->members()->core_search_fields as $key ) {
if ( ! empty( $query[ $key ] ) ) {
$arr_columns[] = $key;
$query_args['search'] = '*' . $query[ $key ] .'*';
}
if ( ! empty( $arr_columns ) )
$query_args['search_columns'] = $arr_columns;
return $query_args;
}
/**
* Remove users we do not need to show in directory
*
* @param $query_args
* @param $args
*
* @return mixed
*/
function um_remove_special_users_from_list( $query_args, $args ) {
extract( $args );
if ( ! empty( $arr_columns ) )
$query_args['search_columns'] = $arr_columns;
$query_args['meta_query']['relation'] = 'AND';
return $query_args;
}
add_filter( 'um_prepare_user_query_args', 'um_search_usernames_emails', 51, 2 );
if ( ! UM()->roles()->um_user_can( 'can_edit_everyone' ) ) {
$query_args['meta_query'][] = array(
'key' => 'account_status',
'value' => 'approved',
'compare' => '='
);
/**
* Remove users we do not need to show in directory
*
* @param $query_args
* @param $args
*
* @return mixed
*/
function um_remove_special_users_from_list( $query_args, $args ) {
extract( $args );
}
$query_args['meta_query']['relation'] = 'AND';
if ( ! UM()->roles()->um_user_can( 'can_edit_everyone' ) || UM()->options()->get( 'account_hide_in_directory' ) ) {
$query_args['meta_query'][] = array(
"relation" => "OR",
if ( ! UM()->roles()->um_user_can( 'can_edit_everyone' ) ) {
$query_args['meta_query'][] = array(
'key' => 'account_status',
'value' => 'approved',
'compare' => '='
);
}
if ( ! UM()->roles()->um_user_can( 'can_edit_everyone' ) || UM()->options()->get( 'account_hide_in_directory' ) ) {
$query_args['meta_query'][] = array(
"relation" => "OR",
array(
'key' => 'hide_in_members',
'value' => '',
'compare' => 'NOT EXISTS'
),
array(
"relation" => "AND",
array(
'key' => 'hide_in_members',
'value' => '',
'compare' => 'NOT EXISTS'
'value' => __('Yes','ultimate-member'),
'compare' => 'NOT LIKE'
),
array(
"relation" => "AND",
array(
'key' => 'hide_in_members',
'value' => __('Yes','ultimate-member'),
'compare' => 'NOT LIKE'
),
array(
'key' => 'hide_in_members',
'value' => 'Yes',
'compare' => 'NOT LIKE'
),
'key' => 'hide_in_members',
'value' => 'Yes',
'compare' => 'NOT LIKE'
),
);
}
$roles = um_user( 'can_view_roles' );
if ( UM()->roles()->um_user_can( 'can_view_all' ) && ! empty( $roles ) ) {
$roles = maybe_unserialize( $roles );
if ( ! empty( $roles ) ) {
if ( ! empty( $query_args['role__in'] ) ) {
$query_args['role__in'] = array_intersect( $query_args['role__in'], $roles );
} else {
$query_args['role__in'] = $roles;
}
}
}
return $query_args;
),
);
}
/***
*** @adds search parameters
***/
function um_add_search_to_query( $query_args, $args ){
extract( $args );
$roles = um_user( 'can_view_roles' );
if ( UM()->roles()->um_user_can( 'can_view_all' ) && ! empty( $roles ) ) {
if ( isset( $_REQUEST['um_search'] ) ) {
$roles = maybe_unserialize( $roles );
$query = UM()->permalinks()->get_query_array();
// if searching
if ( isset( $query['search'] ) ) {
$query_args['search'] = '*' . um_filter_search( $query['search'] ) . '*';
unset( $query['search'] );
if ( ! empty( $roles ) ) {
if ( ! empty( $query_args['role__in'] ) ) {
$query_args['role__in'] = array_intersect( $query_args['role__in'], $roles );
} else {
$query_args['role__in'] = $roles;
}
}
if ( $query && is_array( $query ) ) {
foreach ( $query as $field => $value ) {
}
if ( in_array( $field, array( 'members_page' ) ) ) continue;
return $query_args;
}
add_filter( 'um_prepare_user_query_args', 'um_remove_special_users_from_list', 99, 2 );
$serialize_value = serialize( strval( $value ) );
/**
* Adds search parameters
*
* @param $query_args
* @param $args
*
* @return mixed|void
*/
function um_add_search_to_query( $query_args, $args ){
extract( $args );
if ( isset( $_REQUEST['um_search'] ) ) {
$query = UM()->permalinks()->get_query_array();
// if searching
if ( isset( $query['search'] ) ) {
$query_args['search'] = '*' . um_filter_search( $query['search'] ) . '*';
unset( $query['search'] );
}
if ( $query && is_array( $query ) ) {
foreach ( $query as $field => $value ) {
if ( in_array( $field, array( 'members_page' ) ) ) continue;
$serialize_value = serialize( strval( $value ) );
if ( $value && $field != 'um_search' && $field != 'page_id' ) {
if ( $value && $field != 'um_search' && $field != 'page_id' ) {
if ( strstr( $field, 'role_' ) )
$field = 'role';
if ( strstr( $field, 'role_' ) )
$field = 'role';
if ( ! in_array( $field, UM()->members()->core_search_fields ) ) {
if ( ! in_array( $field, UM()->members()->core_search_fields ) ) {
if ( 'role' == $field ) {
$query_args['role__in'] = trim( $value );
} else {
$field_query = array(
array(
'key' => $field,
'value' => trim( $value ),
'compare' => '=',
),
array(
'key' => $field,
'value' => trim( $value ),
'compare' => 'LIKE',
),
array(
'key' => $field,
'value' => trim( $serialize_value ),
'compare' => 'LIKE',
),
'relation' => 'OR',
);
/**
* UM hook
*
* @type filter
* @title um_query_args_{$field}__filter
* @description Change field's query for search at Members Directory
* @input_vars
* [{"var":"$field_query","type":"array","desc":"Field query"}]
* @change_log
* ["Since: 2.0"]
* @usage
* <?php add_filter( 'um_query_args_{$field}__filter', 'function_name', 10, 1 ); ?>
* @example
* <?php
* add_filter( 'um_query_args_{$field}__filter', 'my_query_args_filter', 10, 1 );
* function my_query_args_filter( $field_query ) {
* // your code here
* return $field_query;
* }
* ?>
*/
$field_query = apply_filters( "um_query_args_{$field}__filter", $field_query );
$query_args['meta_query'][] = $field_query;
}
if ( 'role' == $field ) {
$query_args['role__in'] = trim( $value );
} else {
$field_query = array(
array(
'key' => $field,
'value' => trim( $value ),
'compare' => '=',
),
array(
'key' => $field,
'value' => trim( $value ),
'compare' => 'LIKE',
),
array(
'key' => $field,
'value' => trim( $serialize_value ),
'compare' => 'LIKE',
),
'relation' => 'OR',
);
/**
* UM hook
*
* @type filter
* @title um_query_args_{$field}__filter
* @description Change field's query for search at Members Directory
* @input_vars
* [{"var":"$field_query","type":"array","desc":"Field query"}]
* @change_log
* ["Since: 2.0"]
* @usage
* <?php add_filter( 'um_query_args_{$field}__filter', 'function_name', 10, 1 ); ?>
* @example
* <?php
* add_filter( 'um_query_args_{$field}__filter', 'my_query_args_filter', 10, 1 );
* function my_query_args_filter( $field_query ) {
* // your code here
* return $field_query;
* }
* ?>
*/
$field_query = apply_filters( "um_query_args_{$field}__filter", $field_query );
$query_args['meta_query'][] = $field_query;
}
}
}
}
}
}
/**
* UM hook
*
* @type filter
* @title um_query_args_filter
* @description Change query for search at Members Directory
* @input_vars
* [{"var":"$query_args","type":"array","desc":"Query Arguments"}]
* @change_log
* ["Since: 2.0"]
* @usage
* <?php add_filter( 'um_query_args_filter', 'function_name', 10, 1 ); ?>
* @example
* <?php
* add_filter( 'um_query_args_filter', 'my_query_args_filter', 10, 1 );
* function my_query_args_filter( $query_args ) {
* // your code here
* return $query_args;
* }
* ?>
*/
$query_args = apply_filters( 'um_query_args_filter', $query_args );
if ( count( $query_args['meta_query'] ) == 1 )
unset( $query_args['meta_query'] );
return $query_args;
}
add_filter( 'um_prepare_user_query_args', 'um_add_search_to_query', 50, 2 );
/**
* Adds main parameters
*
* @param $query_args
* @param $args
*
* @return mixed
*/
function um_prepare_user_query_args( $query_args, $args ) {
extract( $args );
$query_args['fields'] = 'ID';
$query_args['number'] = 0;
$query_args['meta_query']['relation'] = 'AND';
// must have a profile photo
if ( $has_profile_photo == 1 ) {
if ( UM()->options()->get( 'use_gravatars' ) ) {
$query_args['meta_query'][] = array(
'relation' => 'OR',
array(
'key' => 'synced_profile_photo', // addons
'value' => '',
'compare' => '!='
),
array(
'key' => 'profile_photo', // from upload form
'value' => '',
'compare' => '!='
),
array(
'key' => 'synced_gravatar_hashed_id', // gravatar
'value' => '',
'compare' => '!='
)
);
} else {
$query_args['meta_query'][] = array(
'relation' => 'OR',
array(
'key' => 'synced_profile_photo', // addons
'value' => '',
'compare' => '!='
),
array(
'key' => 'profile_photo', // from upload form
'value' => '',
'compare' => '!='
)
);
}
}
// must have a cover photo
if ( $has_cover_photo == 1 ) {
$query_args['meta_query'][] = array(
'key' => 'cover_photo',
'value' => '',
'compare' => '!='
);
}
// show specific usernames
if ( isset( $show_these_users ) && $show_these_users && is_array( $show_these_users ) ) {
foreach ( $show_these_users as $username ) {
$users_array[] = username_exists( $username );
}
$query_args['include'] = $users_array;
}
// add roles to appear in directory
if ( ! empty( $roles ) ) {
//since WP4.4 use 'role__in' argument
$query_args['role__in'] = $roles;
/*$query_args['meta_query'][] = array(
'key' => 'role',
'value' => $roles,
'compare' => 'IN'
);*/
}
// sort members by
$query_args['order'] = 'ASC';
if ( isset( $sortby ) ) {
if ( $sortby == 'other' && $sortby_custom ) {
$query_args['meta_key'] = $sortby_custom;
$query_args['orderby'] = 'meta_value, display_name';
} else if ( in_array( $sortby, array( 'last_name', 'first_name' ) ) ) {
$query_args['meta_key'] = $sortby;
$query_args['orderby'] = 'meta_value';
} else {
if ( strstr( $sortby, '_desc' ) ) {
$sortby = str_replace('_desc','',$sortby);
$order = 'DESC';
}
if ( strstr( $sortby, '_asc' ) ) {
$sortby = str_replace('_asc','',$sortby);
$order = 'ASC';
}
$query_args['orderby'] = $sortby;
}
if ( isset( $order ) ) {
$query_args['order'] = $order;
}
/**
* UM hook
*
* @type filter
* @title um_query_args_filter
* @description Change query for search at Members Directory
* @title um_modify_sortby_parameter
* @description Change query sort by attributes for search at Members Directory
* @input_vars
* [{"var":"$query_args","type":"array","desc":"Query Arguments"}]
* [{"var":"$query_args","type":"array","desc":"Query Arguments"},
* {"var":"$sortby","type":"string","desc":"Sort by"}]
* @change_log
* ["Since: 2.0"]
* @usage
* <?php add_filter( 'um_query_args_filter', 'function_name', 10, 1 ); ?>
* <?php add_filter( 'um_modify_sortby_parameter', 'function_name', 10, 2 ); ?>
* @example
* <?php
* add_filter( 'um_query_args_filter', 'my_query_args_filter', 10, 1 );
* function my_query_args_filter( $query_args ) {
* add_filter( 'um_modify_sortby_parameter', 'my_modify_sortby_parameter', 10, 2 );
* function my_modify_sortby_parameter( $query_args, $sortby ) {
* // your code here
* return $query_args;
* }
* ?>
*/
$query_args = apply_filters( 'um_query_args_filter', $query_args );
if ( count( $query_args['meta_query'] ) == 1 )
unset( $query_args['meta_query'] );
return $query_args;
$query_args = apply_filters('um_modify_sortby_parameter', $query_args, $sortby);
}
/***
*** @adds main parameters
***/
function um_prepare_user_query_args( $query_args, $args ) {
extract( $args );
$query_args['fields'] = 'ID';
$query_args['number'] = 0;
$query_args['meta_query']['relation'] = 'AND';
// must have a profile photo
if ( $has_profile_photo == 1 ) {
if ( UM()->options()->get( 'use_gravatars' ) ) {
$query_args['meta_query'][] = array(
'relation' => 'OR',
array(
'key' => 'synced_profile_photo', // addons
'value' => '',
'compare' => '!='
),
array(
'key' => 'profile_photo', // from upload form
'value' => '',
'compare' => '!='
),
array(
'key' => 'synced_gravatar_hashed_id', // gravatar
'value' => '',
'compare' => '!='
)
);
} else {
$query_args['meta_query'][] = array(
'relation' => 'OR',
array(
'key' => 'synced_profile_photo', // addons
'value' => '',
'compare' => '!='
),
array(
'key' => 'profile_photo', // from upload form
'value' => '',
'compare' => '!='
)
);
}
}
// must have a cover photo
if ( $has_cover_photo == 1 ) {
$query_args['meta_query'][] = array(
'key' => 'cover_photo',
'value' => '',
'compare' => '!='
);
}
return $query_args;
}
add_filter( 'um_prepare_user_query_args', 'um_prepare_user_query_args', 10, 2 );
// show specific usernames
if ( isset( $show_these_users ) && $show_these_users && is_array( $show_these_users ) ) {
foreach ( $show_these_users as $username ) {
$users_array[] = username_exists( $username );
}
$query_args['include'] = $users_array;
}
// add roles to appear in directory
if ( ! empty( $roles ) ) {
//since WP4.4 use 'role__in' argument
$query_args['role__in'] = $roles;
/*$query_args['meta_query'][] = array(
'key' => 'role',
'value' => $roles,
'compare' => 'IN'
);*/
}
// sort members by
$query_args['order'] = 'ASC';
if ( isset( $sortby ) ) {
/**
* Sorting by last login date
*
* @param $query_args
* @param $sortby
*
* @return mixed
*/
function um_sortby_last_login( $query_args, $sortby ) {
if ( $sortby == 'last_login' ) {
$query_args['orderby'] = 'meta_value_num';
$query_args['order'] = 'desc';
$query_args['meta_key'] = '_um_last_login';
}
return $query_args;
}
add_filter( 'um_modify_sortby_parameter', 'um_sortby_last_login', 100, 2 );
if ( $sortby == 'other' && $sortby_custom ) {
$query_args['meta_key'] = $sortby_custom;
$query_args['orderby'] = 'meta_value, display_name';
} else if ( in_array( $sortby, array( 'last_name', 'first_name' ) ) ) {
$query_args['meta_key'] = $sortby;
$query_args['orderby'] = 'meta_value';
} else {
if ( strstr( $sortby, '_desc' ) ) {
$sortby = str_replace('_desc','',$sortby);
$order = 'DESC';
}
if ( strstr( $sortby, '_asc' ) ) {
$sortby = str_replace('_asc','',$sortby);
$order = 'ASC';
}
$query_args['orderby'] = $sortby;
}
if ( isset( $order ) ) {
$query_args['order'] = $order;
}
/**
* UM hook
*
* @type filter
* @title um_modify_sortby_parameter
* @description Change query sort by attributes for search at Members Directory
* @input_vars
* [{"var":"$query_args","type":"array","desc":"Query Arguments"},
* {"var":"$sortby","type":"string","desc":"Sort by"}]
* @change_log
* ["Since: 2.0"]
* @usage
* <?php add_filter( 'um_modify_sortby_parameter', 'function_name', 10, 2 ); ?>
* @example
* <?php
* add_filter( 'um_modify_sortby_parameter', 'my_modify_sortby_parameter', 10, 2 );
* function my_modify_sortby_parameter( $query_args, $sortby ) {
* // your code here
* return $query_args;
* }
* ?>
*/
$query_args = apply_filters('um_modify_sortby_parameter', $query_args, $sortby);
}
return $query_args;
/**
* Sorting random
*
* @param $query
*
* @return mixed
*/
function um_modify_sortby_randomly( $query ) {
if( um_is_session_started() === false ){
@session_start();
}
/***
*** @sorting by last login date
***/
add_filter('um_modify_sortby_parameter', 'um_sortby_last_login', 100, 2 );
function um_sortby_last_login( $query_args, $sortby ) {
if ( $sortby == 'last_login' ) {
$query_args['orderby'] = 'meta_value_num';
$query_args['order'] = 'desc';
$query_args['meta_key'] = '_um_last_login';
// Reset seed on load of initial
if( ! isset( $_REQUEST['members_page'] ) || $_REQUEST['members_page'] == 0 || $_REQUEST['members_page'] == 1 ) {
if( isset( $_SESSION['seed'] ) ) {
unset( $_SESSION['seed'] );
}
return $query_args;
}
/***
*** @sorting random
***/
add_filter('pre_user_query','um_modify_sortby_randomly');
function um_modify_sortby_randomly( $query ){
if( um_is_session_started() === false ){
@session_start();
}
// Reset seed on load of initial
if( ! isset( $_REQUEST['members_page'] ) || $_REQUEST['members_page'] == 0 || $_REQUEST['members_page'] == 1 ) {
if( isset( $_SESSION['seed'] ) ) {
unset( $_SESSION['seed'] );
}
}
// Get seed from session variable if it exists
$seed = false;
if( isset( $_SESSION['seed'] ) ) {
$seed = $_SESSION['seed'];
}
// Get seed from session variable if it exists
$seed = false;
if( isset( $_SESSION['seed'] ) ) {
$seed = $_SESSION['seed'];
}
// Set new seed if none exists
if ( ! $seed ) {
$seed = rand();
$_SESSION['seed'] = $seed;
}
if($query->query_vars["orderby"] == 'random') {
$query->query_orderby = 'ORDER by RAND('. $seed.')';
}
return $query;
// Set new seed if none exists
if ( ! $seed ) {
$seed = rand();
$_SESSION['seed'] = $seed;
}
/***
*** @hook in the member results array
***/
add_filter('um_prepare_user_results_array', 'um_prepare_user_results_array', 50, 2);
function um_prepare_user_results_array($result){
if($query->query_vars["orderby"] == 'random') {
$query->query_orderby = 'ORDER by RAND('. $seed.')';
}
if ( empty( $result['users_per_page'] ) ) {
$result['no_users'] = 1;
} else {
$result['no_users'] = 0;
}
return $query;
}
add_filter( 'pre_user_query','um_modify_sortby_randomly' );
/**
* Hook in the member results array
*
* @param $result
*
* @return mixed
*/
function um_prepare_user_results_array( $result ) {
if ( empty( $result['users_per_page'] ) ) {
$result['no_users'] = 1;
} else {
$result['no_users'] = 0;
}
return $result;
return $result;
}
add_filter( 'um_prepare_user_results_array', 'um_prepare_user_results_array', 50, 2 );
/**
* Retrieves search filter options from a callback
*
* @param $atts array
* @return array
*/
function um_search_select_fields( $atts ) {
if( isset( $atts['custom_dropdown_options_source'] ) && ! empty( $atts['custom_dropdown_options_source'] ) ){
$atts['custom'] = true;
$atts['options'] = UM()->fields()->get_options_from_callback( $atts, $atts['type'] );
}
/**
* Retrieves search filter options from a callback
* @param $atts array
* @return $atts array
*/
add_filter('um_search_select_fields','um_search_select_fields');
function um_search_select_fields( $atts ){
if( isset( $atts['custom_dropdown_options_source'] ) && ! empty( $atts['custom_dropdown_options_source'] ) ){
$atts['custom'] = true;
$atts['options'] = UM()->fields()->get_options_from_callback( $atts, $atts['type'] );
}
if( isset( $atts['label'] ) ){
$atts['label'] = strip_tags( $atts['label'] );
}
return $atts;
if( isset( $atts['label'] ) ){
$atts['label'] = strip_tags( $atts['label'] );
}
/**
* Filter gender query argument
* @param array $field_query
* @return array
*/
add_filter('um_query_args_gender__filter','um_query_args_gender__filter');
function um_query_args_gender__filter( $field_query ){
return $atts;
}
add_filter( 'um_search_select_fields', 'um_search_select_fields' );
unset( $field_query[1] );
return $field_query;
}
/**
* Filter gender query argument
*
* @param array $field_query
* @return array
*/
function um_query_args_gender__filter( $field_query ) {
unset( $field_query[1] );
return $field_query;
}
add_filter( 'um_query_args_gender__filter', 'um_query_args_gender__filter' );
+13 -11
View File
@@ -1,13 +1,15 @@
<?php
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) exit;
<?php if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
/***
*** @formats numbers nicely
***/
add_filter('um_pretty_number_formatting', 'um_pretty_number_formatting');
function um_pretty_number_formatting( $count ) {
$count = (int)$count;
return number_format( $count );
}
/**
* Formats numbers nicely
*
* @param $count
*
* @return string
*/
function um_pretty_number_formatting( $count ) {
$count = (int)$count;
return number_format( $count );
}
add_filter( 'um_pretty_number_formatting', 'um_pretty_number_formatting' );
+12 -10
View File
@@ -1,6 +1,4 @@
<?php
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) exit;
<?php if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
/**
@@ -26,12 +24,16 @@ function um_add_custom_message_to_menu( $items, $args ) {
add_filter( 'wp_nav_menu_items', 'um_add_custom_message_to_menu', 10, 2 );
/***
*** @conditional menu items
***/
if ( ! is_admin() ) {
add_filter( 'wp_get_nav_menu_items', 'um_conditional_nav_menu', 9999, 3 );
/**
* Conditional menu items
*
* @param $items
* @param $menu
* @param $args
*
* @return mixed
*/
function um_conditional_nav_menu( $items, $menu, $args ) {
$hide_children_of = array();
@@ -61,7 +63,7 @@ if ( ! is_admin() ) {
if ( empty( $current_user_roles ) ) {
return false;
}
$visible = ( count( array_intersect( $current_user_roles, (array)$roles ) ) > 0 ) ? true : false;
$visible = ( count( array_intersect( $current_user_roles, (array)$roles ) ) > 0 ) ? true : false;
} else {
$visible = is_user_logged_in() ? true : false;
}
@@ -111,5 +113,5 @@ if ( ! is_admin() ) {
return $items;
}
add_filter( 'wp_get_nav_menu_items', 'um_conditional_nav_menu', 9999, 3 );
}
+76 -65
View File
@@ -1,94 +1,105 @@
<?php
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) exit;
<?php if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
/***
*** @dynamic profile page title
***/
add_filter('wp_title', 'um_dynamic_user_profile_pagetitle', 100000, 2 );
add_filter('pre_get_document_title', 'um_dynamic_user_profile_pagetitle', 100000, 2 );
/**
* fix for plugin "The SEO Framework"
* @link https://ru.wordpress.org/plugins/autodescription/
*/
add_filter('the_seo_framework_pro_add_title', 'um_dynamic_user_profile_pagetitle', 100000, 2 );
function um_dynamic_user_profile_pagetitle( $title, $sep = '' ) {
/**
* Fix for plugin "The SEO Framework", dynamic profile page title
* @link https://ru.wordpress.org/plugins/autodescription/
*
* @param $title
* @param string $sep
*
* @return mixed|string
*/
function um_dynamic_user_profile_pagetitle( $title, $sep = '' ) {
$profile_title = UM()->options()->get( 'profile_title' );
$profile_title = UM()->options()->get( 'profile_title' );
if ( um_is_core_page('user') && um_get_requested_user() ) {
if ( um_is_core_page('user') && um_get_requested_user() ) {
um_fetch_user( um_get_requested_user() );
um_fetch_user( um_get_requested_user() );
$profile_title = um_convert_tags( $profile_title );
$profile_title = um_convert_tags( $profile_title );
$title = $profile_title;
$title = $profile_title;
um_reset_user();
um_reset_user();
}
}
return $title;
}
add_filter('the_seo_framework_pro_add_title', 'um_dynamic_user_profile_pagetitle', 100000, 2 );
add_filter('wp_title', 'um_dynamic_user_profile_pagetitle', 100000, 2 );
add_filter('pre_get_document_title', 'um_dynamic_user_profile_pagetitle', 100000, 2 );
/**
* Try and modify the page title in page
*
* @param $title
* @param string $id
*
* @return string
*/
function um_dynamic_user_profile_title( $title, $id = '' ) {
if( is_admin() ){
return $title;
}
/***
*** @try and modify the page title in page
***/
add_filter('the_title', 'um_dynamic_user_profile_title', 100000, 2 );
function um_dynamic_user_profile_title( $title, $id = '' ) {
if( is_admin() ){
return $title;
if ( $id == UM()->config()->permalinks['user'] && in_the_loop() ) {
if ( um_is_core_page('user') && um_get_requested_user() ) {
$title = um_get_display_name( um_get_requested_user() );
} else if ( um_is_core_page('user') && is_user_logged_in() ) {
$title = um_get_display_name( get_current_user_id() );
}
if ( $id == UM()->config()->permalinks['user'] && in_the_loop() ) {
if ( um_is_core_page('user') && um_get_requested_user() ) {
$title = um_get_display_name( um_get_requested_user() );
} else if ( um_is_core_page('user') && is_user_logged_in() ) {
$title = um_get_display_name( get_current_user_id() );
}
}
if( ! function_exists('utf8_decode') ){
return $title;
}
return (strlen($title)!==strlen(utf8_decode($title))) ? $title : utf8_encode($title);
}
if( ! function_exists('utf8_decode') ){
return $title;
}
/***
*** @Add cover photo label of file size limit
***/
add_filter('um_predefined_fields_hook','um_change_profile_cover_photo_label',10,1);
function um_change_profile_cover_photo_label( $args ){
$max_size = UM()->files()->format_bytes( $args['cover_photo']['max_size'] );
list( $file_size, $unit ) = explode(' ', $max_size );
return (strlen($title)!==strlen(utf8_decode($title))) ? $title : utf8_encode($title);
}
add_filter( 'the_title', 'um_dynamic_user_profile_title', 100000, 2 );
if( $file_size >= 999999999 ){
/**
* Add cover photo label of file size limit
*
* @param $args
*
* @return mixed
*/
function um_change_profile_cover_photo_label( $args ){
$max_size = UM()->files()->format_bytes( $args['cover_photo']['max_size'] );
list( $file_size, $unit ) = explode(' ', $max_size );
if( $file_size >= 999999999 ){
}else{
$args['cover_photo']['upload_text'] .= '<small class=\'um-max-filesize\'>( '.__('max','ultimate-member').': <span>'.$file_size.$unit.'</span> )</small>';
}
return $args;
}
add_filter( 'um_predefined_fields_hook', 'um_change_profile_cover_photo_label', 10, 1 );
/***
*** @Add profile photo label of file size limit
***/
add_filter('um_predefined_fields_hook','um_change_profile_photo_label',10,1);
function um_change_profile_photo_label( $args ){
$max_size = UM()->files()->format_bytes( $args['profile_photo']['max_size'] );
list( $file_size, $unit ) = explode(' ', $max_size );
/**
* Add profile photo label of file size limit
*
* @param $args
*
* @return mixed
*/
function um_change_profile_photo_label( $args ) {
$max_size = UM()->files()->format_bytes( $args['profile_photo']['max_size'] );
list( $file_size, $unit ) = explode(' ', $max_size );
if( $file_size >= 999999999 ){
}else{
$args['profile_photo']['upload_text'] .= '<small class=\'um-max-filesize\'>( '.__('max','ultimate-member').': <span>'.$file_size.$unit.'</span> )</small>';
}
return $args;
if ( $file_size < 999999999 ) {
$args['profile_photo']['upload_text'] .= '<small class=\'um-max-filesize\'>( '.__('max','ultimate-member').': <span>'.$file_size.$unit.'</span> )</small>';
}
return $args;
}
add_filter( 'um_predefined_fields_hook', 'um_change_profile_photo_label', 10, 1 );
+150 -148
View File
@@ -1,12 +1,13 @@
<?php
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) exit;
<?php if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
/***
*** @Main admin user actions
***/
add_filter('um_admin_user_actions_hook', 'um_admin_user_actions_hook', 1);
/**
* Main admin user actions
*
* @param $actions
*
* @return null
*/
function um_admin_user_actions_hook( $actions ) {
$actions = null;
@@ -54,6 +55,7 @@ function um_admin_user_actions_hook( $actions ) {
return $actions;
}
add_filter( 'um_admin_user_actions_hook', 'um_admin_user_actions_hook', 1 );
/**
@@ -62,33 +64,32 @@ function um_admin_user_actions_hook( $actions ) {
* @return string
* @hook_filter: um_clean_user_basename_filter
*/
add_filter('um_clean_user_basename_filter','um_clean_user_basename_filter',2,10);
function um_clean_user_basename_filter( $value, $raw ){
$permalink_base = UM()->options()->get( 'permalink_base' );
$user_query = new WP_User_Query(
array(
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'um_user_profile_url_slug_'.$permalink_base,
'value' => $raw,
'compare' => '='
)
),
'fields' => array('ID')
)
array(
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'um_user_profile_url_slug_'.$permalink_base,
'value' => $raw,
'compare' => '='
)
),
'fields' => array('ID')
)
);
if( $user_query->total_users > 0 ){
$result = current( $user_query->get_results() );
$slugname = '';
$result = current( $user_query->get_results() );
$slugname = '';
if( isset( $result->ID ) ){
$slugname = get_user_meta( $result->ID, 'um_user_profile_url_slug_'.$permalink_base, true );
$value = $slugname;
$slugname = get_user_meta( $result->ID, 'um_user_profile_url_slug_'.$permalink_base, true );
$value = $slugname;
}
}
@@ -117,155 +118,155 @@ function um_clean_user_basename_filter( $value, $raw ){
$raw_value = $value;
switch( $permalink_base ) {
case 'name':
case 'name':
if( ! empty( $value ) && strrpos( $value ,"_") > -1 ){
$value = str_replace( '_', '. ', $value );
}
if( ! empty( $value ) && strrpos( $value ,"_") > -1 ){
$value = str_replace( '_', '. ', $value );
}
if( ! empty( $value ) && strrpos( $value ,"_") > -1 ){
$value = str_replace( '_', '-', $value );
}
if( ! empty( $value ) && strrpos( $value ,"_") > -1 ){
$value = str_replace( '_', '-', $value );
}
if( ! empty( $value ) && strrpos( $value ,".") > -1 && strrpos( $raw_value ,"_" ) <= -1 ){
$value = str_replace( '.', ' ', $value );
}
if( ! empty( $value ) && strrpos( $value ,".") > -1 && strrpos( $raw_value ,"_" ) <= -1 ){
$value = str_replace( '.', ' ', $value );
}
/**
* UM hook
*
* @type filter
* @title um_permalink_base_after_filter_name
* @description Base permalink after if permalink is username
* @input_vars
* [{"var":"$permalink","type":"string","desc":"User Permalink"},
* {"var":"$raw_permalink","type":"string","desc":"RAW User Permalink"}]
* @change_log
* ["Since: 2.0"]
* @usage
* <?php add_filter( 'um_permalink_base_after_filter_name', 'function_name', 10, 2 ); ?>
* @example
* <?php
* add_filter( 'um_permalink_base_after_filter_name', 'my_permalink_base_after_filter_name', 10, 2 );
* function my_permalink_base_after_filter_name( $permalink, $raw_permalink ) {
* // your code here
* return $permalink;
* }
* ?>
*/
$value = apply_filters("um_permalink_base_after_filter_name", $value, $raw_value );
/**
* UM hook
*
* @type filter
* @title um_permalink_base_after_filter_name
* @description Base permalink after if permalink is username
* @input_vars
* [{"var":"$permalink","type":"string","desc":"User Permalink"},
* {"var":"$raw_permalink","type":"string","desc":"RAW User Permalink"}]
* @change_log
* ["Since: 2.0"]
* @usage
* <?php add_filter( 'um_permalink_base_after_filter_name', 'function_name', 10, 2 ); ?>
* @example
* <?php
* add_filter( 'um_permalink_base_after_filter_name', 'my_permalink_base_after_filter_name', 10, 2 );
* function my_permalink_base_after_filter_name( $permalink, $raw_permalink ) {
* // your code here
* return $permalink;
* }
* ?>
*/
$value = apply_filters("um_permalink_base_after_filter_name", $value, $raw_value );
break;
case 'name_dash':
case 'name_dash':
if( ! empty( $value ) && strrpos( $value ,"-") > -1 ){
$value = str_replace( '-', ' ', $value );
}
if( ! empty( $value ) && strrpos( $value ,"-") > -1 ){
$value = str_replace( '-', ' ', $value );
}
if( ! empty( $value ) && strrpos( $value ,"_") > -1 ){
$value = str_replace( '_', '-', $value );
}
if( ! empty( $value ) && strrpos( $value ,"_") > -1 ){
$value = str_replace( '_', '-', $value );
}
// Checks if last name has a dash
if( ! empty( $value ) && strrpos( $value ,"_") > -1 ){
$value = str_replace( '_', '-', $value );
}
// Checks if last name has a dash
if( ! empty( $value ) && strrpos( $value ,"_") > -1 ){
$value = str_replace( '_', '-', $value );
}
/**
* UM hook
*
* @type filter
* @title um_permalink_base_after_filter_name_dash
* @description Base permalink after if permalink is first name - last name
* @input_vars
* [{"var":"$permalink","type":"string","desc":"User Permalink"},
* {"var":"$raw_permalink","type":"string","desc":"RAW User Permalink"}]
* @change_log
* ["Since: 2.0"]
* @usage
* <?php add_filter( 'um_permalink_base_after_filter_name_dash', 'function_name', 10, 2 ); ?>
* @example
* <?php
* add_filter( 'um_permalink_base_after_filter_name_dash', 'my_permalink_base_after_filter_name_dash', 10, 2 );
* function my_permalink_base_after_filter_name_dash( $permalink, $raw_permalink ) {
* // your code here
* return $permalink;
* }
* ?>
*/
$value = apply_filters("um_permalink_base_after_filter_name_dash", $value, $raw_value );
/**
* UM hook
*
* @type filter
* @title um_permalink_base_after_filter_name_dash
* @description Base permalink after if permalink is first name - last name
* @input_vars
* [{"var":"$permalink","type":"string","desc":"User Permalink"},
* {"var":"$raw_permalink","type":"string","desc":"RAW User Permalink"}]
* @change_log
* ["Since: 2.0"]
* @usage
* <?php add_filter( 'um_permalink_base_after_filter_name_dash', 'function_name', 10, 2 ); ?>
* @example
* <?php
* add_filter( 'um_permalink_base_after_filter_name_dash', 'my_permalink_base_after_filter_name_dash', 10, 2 );
* function my_permalink_base_after_filter_name_dash( $permalink, $raw_permalink ) {
* // your code here
* return $permalink;
* }
* ?>
*/
$value = apply_filters("um_permalink_base_after_filter_name_dash", $value, $raw_value );
break;
case 'name_plus':
case 'name_plus':
if( ! empty( $value ) && strrpos( $value ,"+") > -1 ){
$value = str_replace( '+', ' ', $value );
}
if( ! empty( $value ) && strrpos( $value ,"+") > -1 ){
$value = str_replace( '+', ' ', $value );
}
if( ! empty( $value ) && strrpos( $value ,"_") > -1 ){
$value = str_replace( '_', '+', $value );
}
if( ! empty( $value ) && strrpos( $value ,"_") > -1 ){
$value = str_replace( '_', '+', $value );
}
/**
* UM hook
*
* @type filter
* @title um_permalink_base_after_filter_name_plus
* @description Base permalink after if permalink is first name + last name
* @input_vars
* [{"var":"$permalink","type":"string","desc":"User Permalink"},
* {"var":"$raw_permalink","type":"string","desc":"RAW User Permalink"}]
* @change_log
* ["Since: 2.0"]
* @usage
* <?php add_filter( 'um_permalink_base_after_filter_name_plus', 'function_name', 10, 2 ); ?>
* @example
* <?php
* add_filter( 'um_permalink_base_after_filter_name_plus', 'my_permalink_base_after_filter_name_plus', 10, 2 );
* function my_permalink_base_after_filter_name_plus( $permalink, $raw_permalink ) {
* // your code here
* return $permalink;
* }
* ?>
*/
$value = apply_filters("um_permalink_base_after_filter_name_plus", $value, $raw_value );
/**
* UM hook
*
* @type filter
* @title um_permalink_base_after_filter_name_plus
* @description Base permalink after if permalink is first name + last name
* @input_vars
* [{"var":"$permalink","type":"string","desc":"User Permalink"},
* {"var":"$raw_permalink","type":"string","desc":"RAW User Permalink"}]
* @change_log
* ["Since: 2.0"]
* @usage
* <?php add_filter( 'um_permalink_base_after_filter_name_plus', 'function_name', 10, 2 ); ?>
* @example
* <?php
* add_filter( 'um_permalink_base_after_filter_name_plus', 'my_permalink_base_after_filter_name_plus', 10, 2 );
* function my_permalink_base_after_filter_name_plus( $permalink, $raw_permalink ) {
* // your code here
* return $permalink;
* }
* ?>
*/
$value = apply_filters("um_permalink_base_after_filter_name_plus", $value, $raw_value );
break;
default:
default:
// Checks if last name has a dash
if( ! empty( $value ) && strrpos( $value ,"_") > -1 && substr( $value , "_") == 1 ){
$value = str_replace( '_', '-', $value );
}
// Checks if last name has a dash
if( ! empty( $value ) && strrpos( $value ,"_") > -1 && substr( $value , "_") == 1 ){
$value = str_replace( '_', '-', $value );
}
/**
* UM hook
*
* @type filter
* @title um_permalink_base_after_filter
* @description Base permalink after for default permalink
* @input_vars
* [{"var":"$permalink","type":"string","desc":"User Permalink"},
* {"var":"$raw_permalink","type":"string","desc":"RAW User Permalink"}]
* @change_log
* ["Since: 2.0"]
* @usage
* <?php add_filter( 'um_permalink_base_after_filter', 'function_name', 10, 2 ); ?>
* @example
* <?php
* add_filter( 'um_permalink_base_after_filter', 'my_permalink_base_after', 10, 2 );
* function my_permalink_base_after( $permalink, $raw_permalink ) {
* // your code here
* return $permalink;
* }
* ?>
*/
$value = apply_filters("um_permalink_base_after_filter", $value, $raw_value );
/**
* UM hook
*
* @type filter
* @title um_permalink_base_after_filter
* @description Base permalink after for default permalink
* @input_vars
* [{"var":"$permalink","type":"string","desc":"User Permalink"},
* {"var":"$raw_permalink","type":"string","desc":"RAW User Permalink"}]
* @change_log
* ["Since: 2.0"]
* @usage
* <?php add_filter( 'um_permalink_base_after_filter', 'function_name', 10, 2 ); ?>
* @example
* <?php
* add_filter( 'um_permalink_base_after_filter', 'my_permalink_base_after', 10, 2 );
* function my_permalink_base_after( $permalink, $raw_permalink ) {
* // your code here
* return $permalink;
* }
* ?>
*/
$value = apply_filters("um_permalink_base_after_filter", $value, $raw_value );
break;
}
@@ -273,6 +274,7 @@ function um_clean_user_basename_filter( $value, $raw ){
return $value;
}
add_filter( 'um_clean_user_basename_filter', 'um_clean_user_basename_filter', 2, 10 );
/**
+5
View File
@@ -3,8 +3,13 @@ if ( ! defined( 'ABSPATH' ) ) exit;
if ( ! class_exists( 'UM_Menu_Item_Custom_Fields_Editor' ) ) {
/**
* Class UM_Menu_Item_Custom_Fields_Editor
*/
class UM_Menu_Item_Custom_Fields_Editor {
/**
* @var array
*/
+32 -4
View File
@@ -4,8 +4,17 @@ namespace um\widgets;
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) exit;
/**
* Class UM_Search_Widget
* @package um\widgets
*/
class UM_Search_Widget extends \WP_Widget {
/**
* UM_Search_Widget constructor.
*/
function __construct() {
parent::__construct(
@@ -22,7 +31,13 @@ class UM_Search_Widget extends \WP_Widget {
}
// Creating widget front-end
/**
* Creating widget front-end
*
* @param array $args
* @param array $instance
*/
public function widget( $args, $instance ) {
$title = apply_filters( 'widget_title', $instance['title'] );
@@ -39,7 +54,12 @@ class UM_Search_Widget extends \WP_Widget {
echo $args['after_widget'];
}
// Widget Backend
/**
* Widget Backend
*
* @param array $instance
*/
public function form( $instance ) {
if ( isset( $instance[ 'title' ] ) ) {
$title = $instance[ 'title' ];
@@ -64,11 +84,19 @@ class UM_Search_Widget extends \WP_Widget {
<?php
}
// Updating widget replacing old instances with new
/**
* Updating widget replacing old instances with new
*
* @param array $new_instance
* @param array $old_instance
*
* @return array
*/
public function update( $new_instance, $old_instance ) {
$instance = array();
$instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
return $instance;
}
}
}