diff --git a/includes/admin/core/packages/2.0-beta1.php b/includes/admin/core/packages/2.0-beta1.php index 200f993f..e1fc9d8d 100644 --- a/includes/admin/core/packages/2.0-beta1.php +++ b/includes/admin/core/packages/2.0-beta1.php @@ -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 diff --git a/includes/core/class-access.php b/includes/core/class-access.php index 3aadeabe..9e37ca3a 100644 --- a/includes/core/class-access.php +++ b/includes/core/class-access.php @@ -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 - * - */ - 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 + * + */ + 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 - * - */ - 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 + * + */ + 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 - * - */ - 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 + * + */ + 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; + } + } } \ No newline at end of file diff --git a/includes/core/class-account.php b/includes/core/class-account.php index 7812af33..46406ab0 100644 --- a/includes/core/class-account.php +++ b/includes/core/class-account.php @@ -5,803 +5,833 @@ namespace um\core; if ( ! defined( 'ABSPATH' ) ) exit; if ( ! class_exists( 'Account' ) ) { - class Account { - var $tabs; - var $current_tab = 'general'; - var $register_fields = array(); - var $tab_output = array(); + /** + * Class Account + * @package um\core + */ + class Account { - function __construct() { - add_shortcode( 'ultimatemember_account', array( &$this, 'ultimatemember_account' ) ); + /** + * @var + */ + var $tabs; - add_action( 'template_redirect', array( &$this, 'account_page_restrict' ), 10001 ); - add_action( 'template_redirect', array( &$this, 'account_submit' ), 10002 ); + /** + * @var string + */ + var $current_tab = 'general'; - add_filter( 'um_predefined_fields_hook', array( &$this, 'predefined_fields_hook' ), 1 ); - } + /** + * @var array + */ + var $register_fields = array(); - /** - * Init AllTabs for user account - * - * @param $args - */ - function init_tabs( $args ) { - $this->tabs = $this->get_tabs(); - - ksort( $this->tabs ); - - $tabs_structed = array(); - foreach ( $this->tabs as $k => $arr ) { - - foreach ( $arr as $id => $info ) { - - if ( ! empty( $args['tab'] ) && $id != $args['tab'] ) - continue; - - $output = $this->get_tab_fields( $id, $args ); - - if ( ! empty( $output ) ) - $tabs_structed[$id] = $info; - - } - - } - - $this->tabs = $tabs_structed; - } - - - function get_tabs() { - $tabs = array(); - $tabs[100]['general'] = array( - 'icon' => 'um-faicon-user', - 'title' => __( 'Account', 'ultimate-member' ), - 'submit_title' => __( 'Update Account', 'ultimate-member' ), - ); - - $tabs[200]['password'] = array( - 'icon' => 'um-faicon-asterisk', - 'title' => __( 'Change Password', 'ultimate-member' ), - 'submit_title' => __( 'Update Password', 'ultimate-member' ), - ); - - $tabs[300]['privacy'] = array( - 'icon' => 'um-faicon-lock', - 'title' => __( 'Privacy', 'ultimate-member' ), - 'submit_title' => __( 'Update Privacy', 'ultimate-member' ), - ); - - $tabs[400]['notifications'] = array( - 'icon' => 'um-faicon-envelope', - 'title' => __( 'Notifications', 'ultimate-member' ), - 'submit_title' => __( 'Update Notifications', 'ultimate-member' ), - ); - - //if user cannot delete profile hide delete tab - if ( um_user( 'can_delete_profile' ) || um_user( 'can_delete_everyone' ) ) { - - $tabs[99999]['delete'] = array( - 'icon' => 'um-faicon-trash-o', - 'title' => __( 'Delete Account', 'ultimate-member' ), - 'submit_title' => __( 'Delete Account', 'ultimate-member' ), - ); - - } - - /** - * UM hook - * - * @type filter - * @title um_account_page_default_tabs_hook - * @description Account Page Tabs - * @input_vars - * [{"var":"$tabs","type":"array","desc":"Account Page Tabs"}] - * @change_log - * ["Since: 2.0"] - * @usage add_filter( 'um_account_page_default_tabs_hook', 'function_name', 10, 1 ); - * @example - * - */ - return apply_filters( 'um_account_page_default_tabs_hook', $tabs ); - } - - - /** - * Account Shortcode - * - * @param array $args - * @return string - */ - function ultimatemember_account( $args = array() ) { - um_fetch_user( get_current_user_id() ); - - ob_start(); - - $defaults = array( - 'template' => 'account', - 'mode' => 'account', - 'form_id' => 'um_account_id', - ); - $args = wp_parse_args( $args, $defaults ); - - /** - * UM hook - * - * @type filter - * @title um_account_shortcode_args_filter - * @description Account Shortcode Arguments - * @input_vars - * [{"var":"$args","type":"array","desc":"Shortcode Arguments"}] - * @change_log - * ["Since: 2.0"] - * @usage add_filter( 'um_account_shortcode_args_filter', 'function_name', 10, 1 ); - * @example - * - */ - $args = apply_filters( 'um_account_shortcode_args_filter', $args ); - - if ( ! empty( $args['tab'] ) ) { - - if ( $args['tab'] == 'account' ) - $args['tab'] = 'general'; - - $this->init_tabs( $args ); - - $this->current_tab = $args['tab']; - - if ( ! empty( $this->tabs[ $args['tab'] ] ) ) { ?> -
-
- - */ - do_action( 'um_account_page_hidden_fields', $args ); - $this->render_account_tab( $args['tab'], $this->tabs[$args['tab']], $args ); ?> -
-
- init_tabs( $args ); - - /** - * UM hook - * - * @type action - * @title um_pre_{$mode}_shortcode - * @description Make some action before account tabs loading - * @input_vars - * [{"var":"$args","type":"array","desc":"Account Page Arguments"}] - * @change_log - * ["Since: 2.0"] - * @usage add_action( 'um_pre_{$mode}_shortcode', 'function_name', 10, 1 ); - * @example - * - */ - do_action( "um_pre_{$args['mode']}_shortcode", $args ); - /** - * UM hook - * - * @type action - * @title um_before_form_is_loaded - * @description Make some action before account tabs loading - * @input_vars - * [{"var":"$args","type":"array","desc":"Account Page Arguments"}] - * @change_log - * ["Since: 2.0"] - * @usage add_action( 'um_before_form_is_loaded', 'function_name', 10, 1 ); - * @example - * - */ - do_action( "um_before_form_is_loaded", $args ); - /** - * UM hook - * - * @type action - * @title um_before_{$mode}_form_is_loaded - * @description Make some action before account tabs loading - * @input_vars - * [{"var":"$args","type":"array","desc":"Account Page Arguments"}] - * @change_log - * ["Since: 2.0"] - * @usage add_action( 'um_before_{$mode}_form_is_loaded', 'function_name', 10, 1 ); - * @example - * - */ - do_action( "um_before_{$args['mode']}_form_is_loaded", $args ); - - UM()->shortcodes()->template_load( $args['template'], $args ); - - } - - if ( ! is_admin() && ! defined( 'DOING_AJAX' ) ) { - UM()->shortcodes()->dynamic_css( $args ); - } - - $output = ob_get_clean(); - - return $output; - } - - - /** - * Restrict access to Account page - */ - function account_page_restrict() { - - if ( um_is_core_page( 'account' ) ) { - - //redirect to login for not logged in users - if ( ! is_user_logged_in() ) { - $redirect_to = add_query_arg( - 'redirect_to', - urlencode_deep( um_get_core_page( 'account' ) ) , - um_get_core_page( 'login' ) - ); - - exit( wp_redirect( $redirect_to ) ); - } - - - //set data for fields - UM()->fields()->set_mode = 'account'; - UM()->fields()->editing = true; - - if ( get_query_var('um_tab') ) - $this->current_tab = get_query_var('um_tab'); - - } - } - - - /** - * Submit Account handler - */ - function account_submit() { - - if ( um_submitting_account_page() ) { - - UM()->form()->post_form = $_POST; - - /** - * UM hook - * - * @type action - * @title um_submit_account_errors_hook - * @description Validate process on account submit - * @input_vars - * [{"var":"$submitted","type":"array","desc":"Account Page Submitted data"}] - * @change_log - * ["Since: 2.0"] - * @usage add_action( 'um_submit_account_errors_hook', 'function_name', 10, 1 ); - * @example - * - */ - do_action( 'um_submit_account_errors_hook', UM()->form()->post_form ); - - if ( ! isset( UM()->form()->errors ) ) { - - if ( um_is_core_page( 'account' ) && get_query_var( 'um_tab' ) ) { - $this->current_tab = get_query_var( 'um_tab' ); - } else { - $this->current_tab = UM()->form()->post_form['_um_account_tab']; - } - - /** - * UM hook - * - * @type action - * @title um_submit_account_details - * @description On success account submit - * @input_vars - * [{"var":"$submitted","type":"array","desc":"Account Page Submitted data"}] - * @change_log - * ["Since: 2.0"] - * @usage add_action( 'um_submit_account_details', 'function_name', 10, 1 ); - * @example - * - */ - do_action( 'um_submit_account_details', UM()->form()->post_form ); - - } - - } - - } - - - /** - * Filter account fields - * @param array $predefined_fields - * @return array - */ - function predefined_fields_hook( $predefined_fields ) { - - $account_hide_in_directory = UM()->options()->get( 'account_hide_in_directory' ); - - if ( ! $account_hide_in_directory ) - unset( $predefined_fields['hide_in_members'] ); - - return $predefined_fields; - } - - - /** - * Get Tab Link - * @param integer $id - * @return string - */ - function tab_link( $id ) { - - if ( get_option('permalink_structure') ) { - - $url = trailingslashit( untrailingslashit( um_get_core_page('account') ) ); - $url = $url . $id . '/'; - - } else { - - $url = add_query_arg( 'um_tab', $id, um_get_core_page('account') ); - - } - - return $url; - } - - - /** - * @param $fields - * @param $shortcode_args - * @return mixed - */ - function filter_fields_by_attrs( $fields, $shortcode_args ) { - - foreach ( $fields as $k => $field ) { - if ( isset( $shortcode_args[ $field['metakey'] ] ) && 0 == $shortcode_args[ $field['metakey'] ] ) - unset( $fields[ $k ] ); - } - - return $fields; - - } - - - function account_secure_fields( $fields, $id ) { - /** - * UM hook - * - * @type filter - * @title um_account_secure_fields - * @description Change Account secure fields - * @input_vars - * [{"var":"$fields","type":"array","desc":"Account Fields"}, - * {"var":"$id","type":"int","desc":"User ID"}] - * @change_log - * ["Since: 2.0"] - * @usage add_filter( 'um_account_secure_fields', 'function_name', 10, 2 ); - * @example - * - */ - $fields = apply_filters( 'um_account_secure_fields', $fields, $id ); - return $fields; - } - - - /** - * * Get Tab Output - * - * @param integer $id - * @param array $shortcode_args - * @return mixed|null|string|void - */ - function get_tab_fields( $id, $shortcode_args ) { - $output = null; - - UM()->fields()->set_mode = 'account'; - UM()->fields()->editing = true; - - if ( ! empty( $this->tab_output[$id]['content'] ) && ! empty( $this->tab_output[$id]['hash'] ) && - $this->tab_output[$id]['hash'] == md5( json_encode( $shortcode_args ) ) ) - return $this->tab_output[$id]['content']; - - switch ( $id ) { - - case 'privacy': - - $args = 'profile_privacy,hide_in_members'; - /** - * UM hook - * - * @type filter - * @title um_account_tab_privacy_fields - * @description Extend Account Tab Privacy - * @input_vars - * [{"var":"$args","type":"array","desc":"Account Arguments"}, - * {"var":"$shortcode_args","type":"array","desc":"Account Shortcode Arguments"}] - * @change_log - * ["Since: 2.0"] - * @usage add_filter( 'um_account_tab_privacy_fields', 'function_name', 10, 2 ); - * @example - * - */ - $args = apply_filters( 'um_account_tab_privacy_fields', $args, $shortcode_args ); - - $fields = UM()->builtin()->get_specific_fields( $args ); - $fields = $this->account_secure_fields( $fields, $id ); - $fields = $this->filter_fields_by_attrs( $fields, $shortcode_args ); - - foreach ( $fields as $key => $data ){ - $output .= UM()->fields()->edit_field( $key, $data ); - } - - break; - - case 'delete': - - $args = 'single_user_password'; - - /** - * UM hook - * - * @type filter - * @title um_account_tab_delete_fields - * @description Extend Account Tab Delete - * @input_vars - * [{"var":"$args","type":"array","desc":"Account Arguments"}, - * {"var":"$shortcode_args","type":"array","desc":"Account Shortcode Arguments"}] - * @change_log - * ["Since: 2.0"] - * @usage add_filter( 'um_account_tab_delete_fields', 'function_name', 10, 2 ); - * @example - * - */ - $args = apply_filters( 'um_account_tab_delete_fields', $args, $shortcode_args ); - - $fields = UM()->builtin()->get_specific_fields( $args ); - $fields = $this->account_secure_fields( $fields, $id ); - $fields = $this->filter_fields_by_attrs( $fields, $shortcode_args ); - - foreach ( $fields as $key => $data ) { - $output .= UM()->fields()->edit_field( $key, $data ); - } - - break; - - case 'general': - - $args = 'user_login,first_name,last_name,user_email'; - - if ( ! UM()->options()->get( 'account_name' ) ) { - $args = 'user_login,user_email'; - } - - if ( ! UM()->options()->get( 'account_email' ) && ! um_user( 'can_edit_everyone' ) ) { - $args = str_replace(',user_email','', $args ); - } - - /** - * UM hook - * - * @type filter - * @title um_account_tab_general_fields - * @description Extend Account Tab General - * @input_vars - * [{"var":"$args","type":"array","desc":"Account Arguments"}, - * {"var":"$shortcode_args","type":"array","desc":"Account Shortcode Arguments"}] - * @change_log - * ["Since: 2.0"] - * @usage add_filter( 'um_account_tab_general_fields', 'function_name', 10, 2 ); - * @example - * - */ - $args = apply_filters( 'um_account_tab_general_fields', $args, $shortcode_args ); - - $fields = UM()->builtin()->get_specific_fields( $args ); - $fields = $this->account_secure_fields( $fields, $id ); - $fields = $this->filter_fields_by_attrs( $fields, $shortcode_args ); - - foreach ( $fields as $key => $data ) { - $output .= UM()->fields()->edit_field( $key, $data ); - } - - break; - - case 'password': - - $args = 'user_password'; - - /** - * UM hook - * - * @type filter - * @title um_account_tab_password_fields - * @description Extend Account Tab Password - * @input_vars - * [{"var":"$args","type":"array","desc":"Account Arguments"}, - * {"var":"$shortcode_args","type":"array","desc":"Account Shortcode Arguments"}] - * @change_log - * ["Since: 2.0"] - * @usage add_filter( 'um_account_tab_password_fields', 'function_name', 10, 2 ); - * @example - * - */ - $args = apply_filters( 'um_account_tab_password_fields', $args, $shortcode_args ); - - $fields = UM()->builtin()->get_specific_fields( $args ); - $fields = $this->account_secure_fields( $fields, $id ); - $fields = $this->filter_fields_by_attrs( $fields, $shortcode_args ); - - foreach ( $fields as $key => $data ) { - $output .= UM()->fields()->edit_field( $key, $data ); - } - - break; - - default : - - /** - * UM hook - * - * @type filter - * @title um_account_content_hook_{$id} - * @description Change not default Account tabs content - * @input_vars - * [{"var":"$output","type":"string","desc":"Account Tab Output"}, - * {"var":"$shortcode_args","type":"array","desc":"Account Shortcode Arguments"}] - * @change_log - * ["Since: 2.0"] - * @usage add_filter( 'um_account_content_hook_{$id}', 'function_name', 10, 2 ); - * @example - * - */ - $output = apply_filters( "um_account_content_hook_{$id}", $output, $shortcode_args ); - break; - - } - - $this->tab_output[$id] = array( 'content' => $output, 'hash' => md5( json_encode( $shortcode_args ) ) ); - return $output; - } - - - /** - * Render Account Tab HTML - * - * @param $tab_id - * @param $tab_data - * @param $args - */ - function render_account_tab( $tab_id, $tab_data, $args ) { - - $output = $this->get_tab_fields( $tab_id, $args ); - - if ( $output ) { - - if ( ! empty ( $tab_data['with_header'] ) ) { ?> - -
- - - */ - do_action( "um_before_account_{$tab_id}", $args ); - - echo $output; - - /** - * UM hook - * - * @type action - * @title um_after_account_{$tab_id} - * @description Make some action after show account tab - * @input_vars - * [{"var":"$args","type":"array","desc":"Account Page Arguments"}] - * @change_log - * ["Since: 2.0"] - * @usage add_action( 'um_after_account_{$tab_id}', 'function_name', 10, 1 ); - * @example - * - */ - do_action( "um_after_account_{$tab_id}", $args ); - - if ( ! isset( $tab_data['show_button'] ) || false !== $tab_data['show_button'] ) { ?> - -
-
- -
- - - */ - do_action( "um_after_account_{$tab_id}_button" ); ?> - -
-
- - fields()->editing == true ) { - $classes .= ' um-editing'; - } - - if ( UM()->fields()->viewing == true ) { - $classes .= ' um-viewing'; - } - - /** - * UM hook - * - * @type filter - * @title um_form_official_classes__hook - * @description Change not default Account tabs content - * @input_vars - * [{"var":"$classes","type":"string","desc":"Form Classes"}] - * @change_log - * ["Since: 2.0"] - * @usage add_filter( 'um_form_official_classes__hook', 'function_name', 10, 1 ); - * @example - * - */ - $classes = apply_filters( 'um_form_official_classes__hook', $classes ); - return $classes; - } - } + /** + * @var array + */ + var $tab_output = array(); + + + /** + * Account constructor. + */ + function __construct() { + add_shortcode( 'ultimatemember_account', array( &$this, 'ultimatemember_account' ) ); + add_action( 'template_redirect', array( &$this, 'account_page_restrict' ), 10001 ); + add_action( 'template_redirect', array( &$this, 'account_submit' ), 10002 ); + add_filter( 'um_predefined_fields_hook', array( &$this, 'predefined_fields_hook' ), 1 ); + } + + + /** + * Init AllTabs for user account + * + * @param $args + */ + function init_tabs( $args ) { + $this->tabs = $this->get_tabs(); + + ksort( $this->tabs ); + + $tabs_structed = array(); + foreach ( $this->tabs as $k => $arr ) { + + foreach ( $arr as $id => $info ) { + + if ( ! empty( $args['tab'] ) && $id != $args['tab'] ) + continue; + + $output = $this->get_tab_fields( $id, $args ); + + if ( ! empty( $output ) ) + $tabs_structed[$id] = $info; + + } + + } + + $this->tabs = $tabs_structed; + } + + + /** + * @return mixed|void + */ + function get_tabs() { + $tabs = array(); + $tabs[100]['general'] = array( + 'icon' => 'um-faicon-user', + 'title' => __( 'Account', 'ultimate-member' ), + 'submit_title' => __( 'Update Account', 'ultimate-member' ), + ); + + $tabs[200]['password'] = array( + 'icon' => 'um-faicon-asterisk', + 'title' => __( 'Change Password', 'ultimate-member' ), + 'submit_title' => __( 'Update Password', 'ultimate-member' ), + ); + + $tabs[300]['privacy'] = array( + 'icon' => 'um-faicon-lock', + 'title' => __( 'Privacy', 'ultimate-member' ), + 'submit_title' => __( 'Update Privacy', 'ultimate-member' ), + ); + + $tabs[400]['notifications'] = array( + 'icon' => 'um-faicon-envelope', + 'title' => __( 'Notifications', 'ultimate-member' ), + 'submit_title' => __( 'Update Notifications', 'ultimate-member' ), + ); + + //if user cannot delete profile hide delete tab + if ( um_user( 'can_delete_profile' ) || um_user( 'can_delete_everyone' ) ) { + + $tabs[99999]['delete'] = array( + 'icon' => 'um-faicon-trash-o', + 'title' => __( 'Delete Account', 'ultimate-member' ), + 'submit_title' => __( 'Delete Account', 'ultimate-member' ), + ); + + } + + /** + * UM hook + * + * @type filter + * @title um_account_page_default_tabs_hook + * @description Account Page Tabs + * @input_vars + * [{"var":"$tabs","type":"array","desc":"Account Page Tabs"}] + * @change_log + * ["Since: 2.0"] + * @usage add_filter( 'um_account_page_default_tabs_hook', 'function_name', 10, 1 ); + * @example + * + */ + return apply_filters( 'um_account_page_default_tabs_hook', $tabs ); + } + + + /** + * Account Shortcode + * + * @param array $args + * @return string + */ + function ultimatemember_account( $args = array() ) { + um_fetch_user( get_current_user_id() ); + + ob_start(); + + $defaults = array( + 'template' => 'account', + 'mode' => 'account', + 'form_id' => 'um_account_id', + ); + $args = wp_parse_args( $args, $defaults ); + + /** + * UM hook + * + * @type filter + * @title um_account_shortcode_args_filter + * @description Account Shortcode Arguments + * @input_vars + * [{"var":"$args","type":"array","desc":"Shortcode Arguments"}] + * @change_log + * ["Since: 2.0"] + * @usage add_filter( 'um_account_shortcode_args_filter', 'function_name', 10, 1 ); + * @example + * + */ + $args = apply_filters( 'um_account_shortcode_args_filter', $args ); + + if ( ! empty( $args['tab'] ) ) { + + if ( $args['tab'] == 'account' ) + $args['tab'] = 'general'; + + $this->init_tabs( $args ); + + $this->current_tab = $args['tab']; + + if ( ! empty( $this->tabs[ $args['tab'] ] ) ) { ?> +
+
+ + */ + do_action( 'um_account_page_hidden_fields', $args ); + $this->render_account_tab( $args['tab'], $this->tabs[$args['tab']], $args ); ?> +
+
+ init_tabs( $args ); + + /** + * UM hook + * + * @type action + * @title um_pre_{$mode}_shortcode + * @description Make some action before account tabs loading + * @input_vars + * [{"var":"$args","type":"array","desc":"Account Page Arguments"}] + * @change_log + * ["Since: 2.0"] + * @usage add_action( 'um_pre_{$mode}_shortcode', 'function_name', 10, 1 ); + * @example + * + */ + do_action( "um_pre_{$args['mode']}_shortcode", $args ); + /** + * UM hook + * + * @type action + * @title um_before_form_is_loaded + * @description Make some action before account tabs loading + * @input_vars + * [{"var":"$args","type":"array","desc":"Account Page Arguments"}] + * @change_log + * ["Since: 2.0"] + * @usage add_action( 'um_before_form_is_loaded', 'function_name', 10, 1 ); + * @example + * + */ + do_action( "um_before_form_is_loaded", $args ); + /** + * UM hook + * + * @type action + * @title um_before_{$mode}_form_is_loaded + * @description Make some action before account tabs loading + * @input_vars + * [{"var":"$args","type":"array","desc":"Account Page Arguments"}] + * @change_log + * ["Since: 2.0"] + * @usage add_action( 'um_before_{$mode}_form_is_loaded', 'function_name', 10, 1 ); + * @example + * + */ + do_action( "um_before_{$args['mode']}_form_is_loaded", $args ); + + UM()->shortcodes()->template_load( $args['template'], $args ); + + } + + if ( ! is_admin() && ! defined( 'DOING_AJAX' ) ) { + UM()->shortcodes()->dynamic_css( $args ); + } + + $output = ob_get_clean(); + + return $output; + } + + + /** + * Restrict access to Account page + */ + function account_page_restrict() { + + if ( um_is_core_page( 'account' ) ) { + + //redirect to login for not logged in users + if ( ! is_user_logged_in() ) { + $redirect_to = add_query_arg( + 'redirect_to', + urlencode_deep( um_get_core_page( 'account' ) ) , + um_get_core_page( 'login' ) + ); + + exit( wp_redirect( $redirect_to ) ); + } + + + //set data for fields + UM()->fields()->set_mode = 'account'; + UM()->fields()->editing = true; + + if ( get_query_var('um_tab') ) + $this->current_tab = get_query_var('um_tab'); + + } + } + + + /** + * Submit Account handler + */ + function account_submit() { + + if ( um_submitting_account_page() ) { + + UM()->form()->post_form = $_POST; + + /** + * UM hook + * + * @type action + * @title um_submit_account_errors_hook + * @description Validate process on account submit + * @input_vars + * [{"var":"$submitted","type":"array","desc":"Account Page Submitted data"}] + * @change_log + * ["Since: 2.0"] + * @usage add_action( 'um_submit_account_errors_hook', 'function_name', 10, 1 ); + * @example + * + */ + do_action( 'um_submit_account_errors_hook', UM()->form()->post_form ); + + if ( ! isset( UM()->form()->errors ) ) { + + if ( um_is_core_page( 'account' ) && get_query_var( 'um_tab' ) ) { + $this->current_tab = get_query_var( 'um_tab' ); + } else { + $this->current_tab = UM()->form()->post_form['_um_account_tab']; + } + + /** + * UM hook + * + * @type action + * @title um_submit_account_details + * @description On success account submit + * @input_vars + * [{"var":"$submitted","type":"array","desc":"Account Page Submitted data"}] + * @change_log + * ["Since: 2.0"] + * @usage add_action( 'um_submit_account_details', 'function_name', 10, 1 ); + * @example + * + */ + do_action( 'um_submit_account_details', UM()->form()->post_form ); + + } + + } + + } + + + /** + * Filter account fields + * @param array $predefined_fields + * @return array + */ + function predefined_fields_hook( $predefined_fields ) { + + $account_hide_in_directory = UM()->options()->get( 'account_hide_in_directory' ); + + if ( ! $account_hide_in_directory ) + unset( $predefined_fields['hide_in_members'] ); + + return $predefined_fields; + } + + + /** + * Get Tab Link + * @param integer $id + * @return string + */ + function tab_link( $id ) { + + if ( get_option('permalink_structure') ) { + + $url = trailingslashit( untrailingslashit( um_get_core_page('account') ) ); + $url = $url . $id . '/'; + + } else { + + $url = add_query_arg( 'um_tab', $id, um_get_core_page('account') ); + + } + + return $url; + } + + + /** + * @param $fields + * @param $shortcode_args + * @return mixed + */ + function filter_fields_by_attrs( $fields, $shortcode_args ) { + foreach ( $fields as $k => $field ) { + if ( isset( $shortcode_args[ $field['metakey'] ] ) && 0 == $shortcode_args[ $field['metakey'] ] ) + unset( $fields[ $k ] ); + } + + return $fields; + } + + + /** + * @param $fields + * @param $id + * + * @return mixed|void + */ + function account_secure_fields( $fields, $id ) { + /** + * UM hook + * + * @type filter + * @title um_account_secure_fields + * @description Change Account secure fields + * @input_vars + * [{"var":"$fields","type":"array","desc":"Account Fields"}, + * {"var":"$id","type":"int","desc":"User ID"}] + * @change_log + * ["Since: 2.0"] + * @usage add_filter( 'um_account_secure_fields', 'function_name', 10, 2 ); + * @example + * + */ + $fields = apply_filters( 'um_account_secure_fields', $fields, $id ); + return $fields; + } + + + /** + * * Get Tab Output + * + * @param integer $id + * @param array $shortcode_args + * @return mixed|null|string|void + */ + function get_tab_fields( $id, $shortcode_args ) { + $output = null; + + UM()->fields()->set_mode = 'account'; + UM()->fields()->editing = true; + + if ( ! empty( $this->tab_output[$id]['content'] ) && ! empty( $this->tab_output[$id]['hash'] ) && + $this->tab_output[$id]['hash'] == md5( json_encode( $shortcode_args ) ) ) + return $this->tab_output[$id]['content']; + + switch ( $id ) { + + case 'privacy': + + $args = 'profile_privacy,hide_in_members'; + /** + * UM hook + * + * @type filter + * @title um_account_tab_privacy_fields + * @description Extend Account Tab Privacy + * @input_vars + * [{"var":"$args","type":"array","desc":"Account Arguments"}, + * {"var":"$shortcode_args","type":"array","desc":"Account Shortcode Arguments"}] + * @change_log + * ["Since: 2.0"] + * @usage add_filter( 'um_account_tab_privacy_fields', 'function_name', 10, 2 ); + * @example + * + */ + $args = apply_filters( 'um_account_tab_privacy_fields', $args, $shortcode_args ); + + $fields = UM()->builtin()->get_specific_fields( $args ); + $fields = $this->account_secure_fields( $fields, $id ); + $fields = $this->filter_fields_by_attrs( $fields, $shortcode_args ); + + foreach ( $fields as $key => $data ){ + $output .= UM()->fields()->edit_field( $key, $data ); + } + + break; + + case 'delete': + + $args = 'single_user_password'; + + /** + * UM hook + * + * @type filter + * @title um_account_tab_delete_fields + * @description Extend Account Tab Delete + * @input_vars + * [{"var":"$args","type":"array","desc":"Account Arguments"}, + * {"var":"$shortcode_args","type":"array","desc":"Account Shortcode Arguments"}] + * @change_log + * ["Since: 2.0"] + * @usage add_filter( 'um_account_tab_delete_fields', 'function_name', 10, 2 ); + * @example + * + */ + $args = apply_filters( 'um_account_tab_delete_fields', $args, $shortcode_args ); + + $fields = UM()->builtin()->get_specific_fields( $args ); + $fields = $this->account_secure_fields( $fields, $id ); + $fields = $this->filter_fields_by_attrs( $fields, $shortcode_args ); + + foreach ( $fields as $key => $data ) { + $output .= UM()->fields()->edit_field( $key, $data ); + } + + break; + + case 'general': + + $args = 'user_login,first_name,last_name,user_email'; + + if ( ! UM()->options()->get( 'account_name' ) ) { + $args = 'user_login,user_email'; + } + + if ( ! UM()->options()->get( 'account_email' ) && ! um_user( 'can_edit_everyone' ) ) { + $args = str_replace(',user_email','', $args ); + } + + /** + * UM hook + * + * @type filter + * @title um_account_tab_general_fields + * @description Extend Account Tab General + * @input_vars + * [{"var":"$args","type":"array","desc":"Account Arguments"}, + * {"var":"$shortcode_args","type":"array","desc":"Account Shortcode Arguments"}] + * @change_log + * ["Since: 2.0"] + * @usage add_filter( 'um_account_tab_general_fields', 'function_name', 10, 2 ); + * @example + * + */ + $args = apply_filters( 'um_account_tab_general_fields', $args, $shortcode_args ); + + $fields = UM()->builtin()->get_specific_fields( $args ); + $fields = $this->account_secure_fields( $fields, $id ); + $fields = $this->filter_fields_by_attrs( $fields, $shortcode_args ); + + foreach ( $fields as $key => $data ) { + $output .= UM()->fields()->edit_field( $key, $data ); + } + + break; + + case 'password': + + $args = 'user_password'; + + /** + * UM hook + * + * @type filter + * @title um_account_tab_password_fields + * @description Extend Account Tab Password + * @input_vars + * [{"var":"$args","type":"array","desc":"Account Arguments"}, + * {"var":"$shortcode_args","type":"array","desc":"Account Shortcode Arguments"}] + * @change_log + * ["Since: 2.0"] + * @usage add_filter( 'um_account_tab_password_fields', 'function_name', 10, 2 ); + * @example + * + */ + $args = apply_filters( 'um_account_tab_password_fields', $args, $shortcode_args ); + + $fields = UM()->builtin()->get_specific_fields( $args ); + $fields = $this->account_secure_fields( $fields, $id ); + $fields = $this->filter_fields_by_attrs( $fields, $shortcode_args ); + + foreach ( $fields as $key => $data ) { + $output .= UM()->fields()->edit_field( $key, $data ); + } + + break; + + default : + + /** + * UM hook + * + * @type filter + * @title um_account_content_hook_{$id} + * @description Change not default Account tabs content + * @input_vars + * [{"var":"$output","type":"string","desc":"Account Tab Output"}, + * {"var":"$shortcode_args","type":"array","desc":"Account Shortcode Arguments"}] + * @change_log + * ["Since: 2.0"] + * @usage add_filter( 'um_account_content_hook_{$id}', 'function_name', 10, 2 ); + * @example + * + */ + $output = apply_filters( "um_account_content_hook_{$id}", $output, $shortcode_args ); + break; + + } + + $this->tab_output[$id] = array( 'content' => $output, 'hash' => md5( json_encode( $shortcode_args ) ) ); + return $output; + } + + + /** + * Render Account Tab HTML + * + * @param $tab_id + * @param $tab_data + * @param $args + */ + function render_account_tab( $tab_id, $tab_data, $args ) { + + $output = $this->get_tab_fields( $tab_id, $args ); + + if ( $output ) { + + if ( ! empty ( $tab_data['with_header'] ) ) { ?> + +
+ + + */ + do_action( "um_before_account_{$tab_id}", $args ); + + echo $output; + + /** + * UM hook + * + * @type action + * @title um_after_account_{$tab_id} + * @description Make some action after show account tab + * @input_vars + * [{"var":"$args","type":"array","desc":"Account Page Arguments"}] + * @change_log + * ["Since: 2.0"] + * @usage add_action( 'um_after_account_{$tab_id}', 'function_name', 10, 1 ); + * @example + * + */ + do_action( "um_after_account_{$tab_id}", $args ); + + if ( ! isset( $tab_data['show_button'] ) || false !== $tab_data['show_button'] ) { ?> + +
+
+ +
+ + + */ + do_action( "um_after_account_{$tab_id}_button" ); ?> + +
+
+ + fields()->editing == true ) { + $classes .= ' um-editing'; + } + + if ( UM()->fields()->viewing == true ) { + $classes .= ' um-viewing'; + } + + /** + * UM hook + * + * @type filter + * @title um_form_official_classes__hook + * @description Change not default Account tabs content + * @input_vars + * [{"var":"$classes","type":"string","desc":"Form Classes"}] + * @change_log + * ["Since: 2.0"] + * @usage add_filter( 'um_form_official_classes__hook', 'function_name', 10, 1 ); + * @example + * + */ + $classes = apply_filters( 'um_form_official_classes__hook', $classes ); + return $classes; + } + } } \ No newline at end of file diff --git a/includes/core/class-ajax-common.php b/includes/core/class-ajax-common.php index 76d8951a..62fa085e 100644 --- a/includes/core/class-ajax-common.php +++ b/includes/core/class-ajax-common.php @@ -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(); + } + } } \ No newline at end of file diff --git a/includes/core/class-builtin.php b/includes/core/class-builtin.php index 7c75af79..585c9eac 100644 --- a/includes/core/class-builtin.php +++ b/includes/core/class-builtin.php @@ -5,516 +5,578 @@ namespace um\core; if ( ! defined( 'ABSPATH' ) ) exit; if ( ! class_exists( 'Builtin' ) ) { - class Builtin { - public $predefined_fields = array(); - var $all_user_fields = array(); - var $core_fields = array(); - function __construct() { + /** + * Class Builtin + * @package um\core + */ + class Builtin { - add_action( 'init', array(&$this, 'set_core_fields'), 1); - add_action( 'init', array(&$this, 'set_predefined_fields'), 1); + /** + * @var array + */ + public $predefined_fields = array(); - add_action( 'init', array(&$this, 'set_custom_fields'), 1); - $this->saved_fields = get_option( 'um_fields' ); + /** + * @var array + */ + var $all_user_fields = array(); - } - /*** - *** @regular or multi-select/options - ***/ - function is_dropdown_field( $field, $attrs ) { + /** + * @var array + */ + var $core_fields = array(); - if ( isset( $attrs['options'] ) ) - return true; - $fields = $this->all_user_fields; + /** + * Builtin constructor. + */ + function __construct() { + add_action( 'init', array(&$this, 'set_core_fields'), 1); + add_action( 'init', array(&$this, 'set_predefined_fields'), 1); + add_action( 'init', array(&$this, 'set_custom_fields'), 1); + $this->saved_fields = get_option( 'um_fields' ); + } - if ( isset( $fields[$field]['options'] ) || ! empty( $fields[$field]['custom_dropdown_options_source'] ) ) - return true; - return false; - } + /** + * Regular or multi-select/options + * + * @param $field + * @param $attrs + * + * @return bool + */ + function is_dropdown_field( $field, $attrs ) { - /*** - *** @get a field - ***/ - function get_a_field( $field ) { - $fields = $this->all_user_fields; - if ( isset( $fields[$field] ) ) { - return $fields[$field]; - } - return ''; - } + if ( isset( $attrs['options'] ) ) + return true; - /*** - *** @get specific fields - ***/ - function get_specific_fields( $fields ) { - $fields = explode(',', $fields); - $array=array(); - foreach ($fields as $field ) { - if ( isset( $this->predefined_fields[$field] ) ) { - $array[$field] = $this->predefined_fields[$field]; - } - } - return $array; - } + $fields = $this->all_user_fields; - /*** - *** @get specific field - ***/ - function get_specific_field( $fields ) { - $fields = explode(',', $fields); - $array=array(); - foreach ($fields as $field ) { - if ( isset( $this->predefined_fields[$field] ) ) { - $array = $this->predefined_fields[$field]; - } else if ( isset( $this->saved_fields[$field] ) ) { - $array = $this->saved_fields[$field]; - } - } - return $array; - } + if ( isset( $fields[$field]['options'] ) || ! empty( $fields[$field]['custom_dropdown_options_source'] ) ) + return true; - /*** - *** @Checks for a unique field error - ***/ - function unique_field_err( $key ){ - if ( empty( $key ) ) return 'Please provide a meta key'; - if ( isset( $this->core_fields[ $key ] ) ) return __('Your meta key is a reserved core field and cannot be used','ultimate-member'); - if ( isset( $this->predefined_fields[ $key ] ) ) return __('Your meta key is a predefined reserved key and cannot be used','ultimate-member'); - if ( isset( $this->saved_fields[ $key ] ) ) return __('Your meta key already exists in your fields list','ultimate-member'); - if ( ! UM()->validation()->safe_string( $key ) ) return __('Your meta key contains illegal characters. Please correct it.','ultimate-member'); - return 0; - } + return false; + } - /*** - *** @check date range errors (start date) - ***/ - function date_range_start_err( $date ) { - if ( empty( $date ) ) return __('Please provide a date range beginning','ultimate-member'); - if ( ! UM()->validation()->validate_date( $date ) ) return __('Please enter a valid start date in the date range','ultimate-member'); - return 0; - } - /*** - *** @check date range errors (end date) - ***/ - function date_range_end_err( $date, $start_date ) { - if ( empty( $date ) ) return __('Please provide a date range end','ultimate-member'); - if ( ! UM()->validation()->validate_date( $date ) ) return __('Please enter a valid end date in the date range','ultimate-member'); - if ( strtotime( $date ) <= strtotime( $start_date ) ) return __('The end of date range must be greater than the start of date range','ultimate-member'); - return 0; - } + /** + * Get a field + * + * @param $field + * + * @return mixed|string + */ + function get_a_field( $field ) { + $fields = $this->all_user_fields; + if ( isset( $fields[ $field ] ) ) { + return $fields[ $field ]; + } + return ''; + } - /*** - *** @Get a core field attrs - ***/ - function get_core_field_attrs( $type ) { - return ( isset( $this->core_fields[$type] ) ) ? $this->core_fields[$type] : array(''); - } - /*** - *** @Core Fields - ***/ - function set_core_fields() { + /** + * Get specific fields + * + * @param $fields + * + * @return array + */ + function get_specific_fields( $fields ) { + $fields = explode( ',', $fields ); + $array = array(); + foreach ( $fields as $field ) { + if ( isset( $this->predefined_fields[ $field ] ) ) { + $array[ $field ] = $this->predefined_fields[ $field ]; + } + } + return $array; + } - $this->core_fields = array( - 'row' => array( - 'name' => 'Row', - 'in_fields' => false, - 'form_only' => true, - 'conditional_support' => 0, - 'icon' => 'um-faicon-pencil', - 'col1' => array('_id','_background','_text_color','_padding','_margin','_border','_borderradius','_borderstyle','_bordercolor'), - 'col2' => array('_heading','_heading_text','_heading_background_color','_heading_text_color','_icon','_icon_color','_css_class'), - ), + /** + * Get specific field + * + * @param $fields + * + * @return array|mixed + */ + function get_specific_field( $fields ) { + $fields = explode( ',', $fields ); + $array = array(); + foreach ( $fields as $field ) { + if ( isset( $this->predefined_fields[ $field ] ) ) { + $array = $this->predefined_fields[ $field ]; + } elseif ( isset( $this->saved_fields[ $field ] ) ) { + $array = $this->saved_fields[ $field ]; + } + } + return $array; + } - 'text' => array( - 'name' => 'Text Box', - 'col1' => array('_title','_metakey','_help','_default','_min_chars','_visibility'), - 'col2' => array('_label','_placeholder','_public','_roles','_validate','_custom_validate','_max_chars'), - 'col3' => array('_required','_editable','_icon'), - 'validate' => array( - '_title' => array( - 'mode' => 'required', - 'error' => __('You must provide a title','ultimate-member') - ), - '_metakey' => array( - 'mode' => 'unique', - ), - ) - ), - 'number' => array( - 'name' => __('Number','ultimate-member'), - 'col1' => array('_title','_metakey','_help','_default','_min','_visibility'), - 'col2' => array('_label','_placeholder','_public','_roles','_validate','_custom_validate','_max'), - 'col3' => array('_required','_editable','_icon'), - 'validate' => array( - '_title' => array( - 'mode' => 'required', - 'error' => __('You must provide a title','ultimate-member') - ), - '_metakey' => array( - 'mode' => 'unique', - ), - ) - ), + /** + * Checks for a unique field error + * + * @param $key + * + * @return int|string|void + */ + function unique_field_err( $key ) { + if ( empty( $key ) ) return __('Please provide a meta key','ultimate-member'); + if ( isset( $this->core_fields[ $key ] ) ) return __('Your meta key is a reserved core field and cannot be used','ultimate-member'); + if ( isset( $this->predefined_fields[ $key ] ) ) return __('Your meta key is a predefined reserved key and cannot be used','ultimate-member'); + if ( isset( $this->saved_fields[ $key ] ) ) return __('Your meta key already exists in your fields list','ultimate-member'); + if ( ! UM()->validation()->safe_string( $key ) ) return __('Your meta key contains illegal characters. Please correct it.','ultimate-member'); + return 0; + } - 'textarea' => array( - 'name' => 'Textarea', - 'col1' => array('_title','_metakey','_help','_height','_max_chars','_max_words','_visibility'), - 'col2' => array('_label','_placeholder','_public','_roles','_default','_html'), - 'col3' => array('_required','_editable','_icon'), - 'validate' => array( - '_title' => array( - 'mode' => 'required', - 'error' => __('You must provide a title','ultimate-member') - ), - '_metakey' => array( - 'mode' => 'unique', - ), - ) - ), - 'select' => array( - 'name' => 'Dropdown', - 'col1' => array('_title','_metakey','_help','_default','_options','_visibility'), - 'col2' => array('_label','_placeholder','_public','_roles','_custom_dropdown_options_source','_parent_dropdown_relationship'), - 'col3' => array('_required','_editable','_icon'), - 'validate' => array( - '_title' => array( - 'mode' => 'required', - 'error' => __('You must provide a title','ultimate-member') - ), - '_metakey' => array( - 'mode' => 'unique', - ), - '_options' => array( - 'mode' => 'required', - 'error' => __('You have not added any choices yet.','ultimate-member') - ), - ) - ), + /** + * Check date range errors (start date) + * + * @param $date + * + * @return int|string|void + */ + function date_range_start_err( $date ) { + if ( empty( $date ) ) return __('Please provide a date range beginning','ultimate-member'); + if ( ! UM()->validation()->validate_date( $date ) ) return __('Please enter a valid start date in the date range','ultimate-member'); + return 0; + } - 'multiselect' => array( - 'name' => 'Multi-Select', - 'col1' => array('_title','_metakey','_help','_default','_options','_visibility'), - 'col2' => array('_label','_placeholder','_public','_roles','_min_selections','_max_selections','_custom_dropdown_options_source'), - 'col3' => array('_required','_editable','_icon'), - 'validate' => array( - '_title' => array( - 'mode' => 'required', - 'error' => __('You must provide a title','ultimate-member') - ), - '_metakey' => array( - 'mode' => 'unique', - ), - '_options' => array( - 'mode' => 'required', - 'error' => __('You have not added any choices yet.','ultimate-member') - ), - ) - ), - 'radio' => array( - 'name' => 'Radio', - 'col1' => array('_title','_metakey','_help','_default','_options','_visibility'), - 'col2' => array('_label','_public','_roles'), - 'col3' => array('_required','_editable','_icon'), - 'validate' => array( - '_title' => array( - 'mode' => 'required', - 'error' => __('You must provide a title','ultimate-member') - ), - '_metakey' => array( - 'mode' => 'unique', - ), - '_options' => array( - 'mode' => 'required', - 'error' => __('You have not added any choices yet.','ultimate-member') - ), - ) - ), + /** + * Check date range errors (end date) + * + * @param $date + * @param $start_date + * + * @return int|string|void + */ + function date_range_end_err( $date, $start_date ) { + if ( empty( $date ) ) return __('Please provide a date range end','ultimate-member'); + if ( ! UM()->validation()->validate_date( $date ) ) return __('Please enter a valid end date in the date range','ultimate-member'); + if ( strtotime( $date ) <= strtotime( $start_date ) ) return __('The end of date range must be greater than the start of date range','ultimate-member'); + return 0; + } - 'checkbox' => array( - 'name' => 'Checkbox', - 'col1' => array('_title','_metakey','_help','_default','_options','_visibility'), - 'col2' => array('_label','_public','_roles','_max_selections'), - 'col3' => array('_required','_editable','_icon'), - 'validate' => array( - '_title' => array( - 'mode' => 'required', - 'error' => __('You must provide a title','ultimate-member') - ), - '_metakey' => array( - 'mode' => 'unique', - ), - '_options' => array( - 'mode' => 'required', - 'error' => __('You have not added any choices yet.','ultimate-member') - ), - ) - ), - 'url' => array( - 'name' => 'URL', - 'col1' => array('_title','_metakey','_help','_default','_url_text','_visibility'), - 'col2' => array('_label','_placeholder','_url_target','_url_rel','_public','_roles','_validate','_custom_validate'), - 'col3' => array('_required','_editable','_icon'), - 'validate' => array( - '_title' => array( - 'mode' => 'required', - 'error' => __('You must provide a title','ultimate-member') - ), - '_metakey' => array( - 'mode' => 'unique', - ), - ) - ), + /** + * Get a core field attrs + * + * @param $type + * + * @return array|mixed + */ + function get_core_field_attrs( $type ) { + return ( isset( $this->core_fields[ $type ] ) ) ? $this->core_fields[ $type ] : array(''); + } - 'password' => array( - 'name' => 'Password', - 'col1' => array('_title','_metakey','_help','_min_chars','_max_chars','_visibility'), - 'col2' => array('_label','_placeholder','_public','_roles','_force_good_pass','_force_confirm_pass'), - 'col3' => array('_required','_editable','_icon'), - 'validate' => array( - '_title' => array( - 'mode' => 'required', - 'error' => __('You must provide a title','ultimate-member') - ), - '_metakey' => array( - 'mode' => 'unique', - ), - ) - ), - 'image' => array( - 'name' => 'Image Upload', - 'col1' => array('_title','_metakey','_help','_allowed_types','_max_size','_crop','_visibility'), - 'col2' => array('_label','_public','_roles','_upload_text','_upload_help_text','_button_text'), - 'col3' => array('_required','_editable','_icon'), - 'validate' => array( - '_title' => array( - 'mode' => 'required', - 'error' => __('You must provide a title','ultimate-member') - ), - '_metakey' => array( - 'mode' => 'unique', - ), - '_max_size' => array( - 'mode' => 'numeric', - 'error' => __('Please enter a valid size','ultimate-member') - ), - ) - ), + /** + * Core Fields + */ + function set_core_fields() { - 'file' => array( - 'name' => 'File Upload', - 'col1' => array('_title','_metakey','_help','_allowed_types','_max_size','_visibility'), - 'col2' => array('_label','_public','_roles','_upload_text','_upload_help_text','_button_text'), - 'col3' => array('_required','_editable','_icon'), - 'validate' => array( - '_title' => array( - 'mode' => 'required', - 'error' => __('You must provide a title','ultimate-member') - ), - '_metakey' => array( - 'mode' => 'unique', - ), - '_max_size' => array( - 'mode' => 'numeric', - 'error' => __('Please enter a valid size','ultimate-member') - ), - ) - ), + $this->core_fields = array( - 'date' => array( - 'name' => 'Date Picker', - 'col1' => array('_title','_metakey','_help','_range','_years','_years_x','_range_start','_range_end','_visibility'), - 'col2' => array('_label','_placeholder','_public','_roles','_format','_pretty_format','_disabled_weekdays'), - 'col3' => array('_required','_editable','_icon'), - 'validate' => array( - '_title' => array( - 'mode' => 'required', - 'error' => __('You must provide a title','ultimate-member') - ), - '_metakey' => array( - 'mode' => 'unique', - ), - '_years' => array( - 'mode' => 'numeric', - 'error' => __('Number of years is not valid','ultimate-member') - ), - '_range_start' => array( - 'mode' => 'range-start', - ), - '_range_end' => array( - 'mode' => 'range-end', - ), - ) - ), + 'row' => array( + 'name' => 'Row', + 'in_fields' => false, + 'form_only' => true, + 'conditional_support' => 0, + 'icon' => 'um-faicon-pencil', + 'col1' => array('_id','_background','_text_color','_padding','_margin','_border','_borderradius','_borderstyle','_bordercolor'), + 'col2' => array('_heading','_heading_text','_heading_background_color','_heading_text_color','_icon','_icon_color','_css_class'), + ), - 'time' => array( - 'name' => 'Time Picker', - 'col1' => array('_title','_metakey','_help','_format','_visibility'), - 'col2' => array('_label','_placeholder','_public','_roles','_intervals'), - 'col3' => array('_required','_editable','_icon'), - 'validate' => array( - '_title' => array( - 'mode' => 'required', - 'error' => __('You must provide a title','ultimate-member') - ), - '_metakey' => array( - 'mode' => 'unique', - ), - ) - ), + 'text' => array( + 'name' => 'Text Box', + 'col1' => array('_title','_metakey','_help','_default','_min_chars','_visibility'), + 'col2' => array('_label','_placeholder','_public','_roles','_validate','_custom_validate','_max_chars'), + 'col3' => array('_required','_editable','_icon'), + 'validate' => array( + '_title' => array( + 'mode' => 'required', + 'error' => __('You must provide a title','ultimate-member') + ), + '_metakey' => array( + 'mode' => 'unique', + ), + ) + ), - 'rating' => array( - 'name' => 'Rating', - 'col1' => array('_title','_metakey','_help','_visibility'), - 'col2' => array('_label','_public','_roles','_number','_default'), - 'col3' => array('_required','_editable','_icon'), - 'validate' => array( - '_title' => array( - 'mode' => 'required', - 'error' => __('You must provide a title','ultimate-member') - ), - '_metakey' => array( - 'mode' => 'unique', - ), - ) - ), + 'number' => array( + 'name' => __('Number','ultimate-member'), + 'col1' => array('_title','_metakey','_help','_default','_min','_visibility'), + 'col2' => array('_label','_placeholder','_public','_roles','_validate','_custom_validate','_max'), + 'col3' => array('_required','_editable','_icon'), + 'validate' => array( + '_title' => array( + 'mode' => 'required', + 'error' => __('You must provide a title','ultimate-member') + ), + '_metakey' => array( + 'mode' => 'unique', + ), + ) + ), - 'block' => array( - 'name' => 'Content Block', - 'col1' => array('_title','_visibility'), - 'col2' => array('_public','_roles'), - 'col_full' => array('_content'), - 'mce_content' => true, - 'validate' => array( - '_title' => array( - 'mode' => 'required', - 'error' => __('You must provide a title','ultimate-member') - ), - ) - ), + 'textarea' => array( + 'name' => 'Textarea', + 'col1' => array('_title','_metakey','_help','_height','_max_chars','_max_words','_visibility'), + 'col2' => array('_label','_placeholder','_public','_roles','_default','_html'), + 'col3' => array('_required','_editable','_icon'), + 'validate' => array( + '_title' => array( + 'mode' => 'required', + 'error' => __('You must provide a title','ultimate-member') + ), + '_metakey' => array( + 'mode' => 'unique', + ), + ) + ), - 'shortcode' => array( - 'name' => 'Shortcode', - 'col1' => array('_title','_visibility'), - 'col2' => array('_public','_roles'), - 'col_full' => array('_content'), - 'validate' => array( - '_title' => array( - 'mode' => 'required', - 'error' => __('You must provide a title','ultimate-member') - ), - '_content' => array( - 'mode' => 'required', - 'error' => __('You must add a shortcode to the content area','ultimate-member') - ), - ) - ), + 'select' => array( + 'name' => 'Dropdown', + 'col1' => array('_title','_metakey','_help','_default','_options','_visibility'), + 'col2' => array('_label','_placeholder','_public','_roles','_custom_dropdown_options_source','_parent_dropdown_relationship'), + 'col3' => array('_required','_editable','_icon'), + 'validate' => array( + '_title' => array( + 'mode' => 'required', + 'error' => __('You must provide a title','ultimate-member') + ), + '_metakey' => array( + 'mode' => 'unique', + ), + '_options' => array( + 'mode' => 'required', + 'error' => __('You have not added any choices yet.','ultimate-member') + ), + ) + ), - 'spacing' => array( - 'name' => 'Spacing', - 'col1' => array('_title','_visibility'), - 'col2' => array('_spacing'), - 'form_only' => true, - 'validate' => array( - '_title' => array( - 'mode' => 'required', - 'error' => __('You must provide a title','ultimate-member') - ), - ) - ), + 'multiselect' => array( + 'name' => 'Multi-Select', + 'col1' => array('_title','_metakey','_help','_default','_options','_visibility'), + 'col2' => array('_label','_placeholder','_public','_roles','_min_selections','_max_selections','_custom_dropdown_options_source'), + 'col3' => array('_required','_editable','_icon'), + 'validate' => array( + '_title' => array( + 'mode' => 'required', + 'error' => __('You must provide a title','ultimate-member') + ), + '_metakey' => array( + 'mode' => 'unique', + ), + '_options' => array( + 'mode' => 'required', + 'error' => __('You have not added any choices yet.','ultimate-member') + ), + ) + ), - 'divider' => array( - 'name' => 'Divider', - 'col1' => array('_title','_width','_divider_text','_visibility'), - 'col2' => array('_style','_color'), - 'form_only' => true, - 'validate' => array( - '_title' => array( - 'mode' => 'required', - 'error' => __('You must provide a title','ultimate-member') - ), - ) - ), + 'radio' => array( + 'name' => 'Radio', + 'col1' => array('_title','_metakey','_help','_default','_options','_visibility'), + 'col2' => array('_label','_public','_roles'), + 'col3' => array('_required','_editable','_icon'), + 'validate' => array( + '_title' => array( + 'mode' => 'required', + 'error' => __('You must provide a title','ultimate-member') + ), + '_metakey' => array( + 'mode' => 'unique', + ), + '_options' => array( + 'mode' => 'required', + 'error' => __('You have not added any choices yet.','ultimate-member') + ), + ) + ), - 'googlemap' => array( - 'name' => 'Google Map', - 'col1' => array('_title','_metakey','_help','_visibility'), - 'col2' => array('_label','_placeholder','_public','_roles','_validate','_custom_validate'), - 'col3' => array('_required','_editable','_icon'), - 'validate' => array( - '_title' => array( - 'mode' => 'required', - 'error' => __('You must provide a title','ultimate-member') - ), - '_metakey' => array( - 'mode' => 'unique', - ), - ) - ), + 'checkbox' => array( + 'name' => 'Checkbox', + 'col1' => array('_title','_metakey','_help','_default','_options','_visibility'), + 'col2' => array('_label','_public','_roles','_max_selections'), + 'col3' => array('_required','_editable','_icon'), + 'validate' => array( + '_title' => array( + 'mode' => 'required', + 'error' => __('You must provide a title','ultimate-member') + ), + '_metakey' => array( + 'mode' => 'unique', + ), + '_options' => array( + 'mode' => 'required', + 'error' => __('You have not added any choices yet.','ultimate-member') + ), + ) + ), - 'youtube_video' => array( - 'name' => 'YouTube Video', - 'col1' => array('_title','_metakey','_help','_visibility'), - 'col2' => array('_label','_placeholder','_public','_roles','_validate','_custom_validate'), - 'col3' => array('_required','_editable','_icon'), - 'validate' => array( - '_title' => array( - 'mode' => 'required', - 'error' => __('You must provide a title','ultimate-member') - ), - '_metakey' => array( - 'mode' => 'unique', - ), - ) - ), + 'url' => array( + 'name' => 'URL', + 'col1' => array('_title','_metakey','_help','_default','_url_text','_visibility'), + 'col2' => array('_label','_placeholder','_url_target','_url_rel','_public','_roles','_validate','_custom_validate'), + 'col3' => array('_required','_editable','_icon'), + 'validate' => array( + '_title' => array( + 'mode' => 'required', + 'error' => __('You must provide a title','ultimate-member') + ), + '_metakey' => array( + 'mode' => 'unique', + ), + ) + ), - 'vimeo_video' => array( - 'name' => 'Vimeo Video', - 'col1' => array('_title','_metakey','_help','_visibility'), - 'col2' => array('_label','_placeholder','_public','_roles','_validate','_custom_validate'), - 'col3' => array('_required','_editable','_icon'), - 'validate' => array( - '_title' => array( - 'mode' => 'required', - 'error' => __('You must provide a title','ultimate-member') - ), - '_metakey' => array( - 'mode' => 'unique', - ), - ) - ), + 'password' => array( + 'name' => 'Password', + 'col1' => array('_title','_metakey','_help','_min_chars','_max_chars','_visibility'), + 'col2' => array('_label','_placeholder','_public','_roles','_force_good_pass','_force_confirm_pass'), + 'col3' => array('_required','_editable','_icon'), + 'validate' => array( + '_title' => array( + 'mode' => 'required', + 'error' => __('You must provide a title','ultimate-member') + ), + '_metakey' => array( + 'mode' => 'unique', + ), + ) + ), - 'soundcloud_track' => array( - 'name' => 'SoundCloud Track', - 'col1' => array('_title','_metakey','_help','_visibility'), - 'col2' => array('_label','_placeholder','_public','_roles','_validate','_custom_validate'), - 'col3' => array('_required','_editable','_icon'), - 'validate' => array( - '_title' => array( - 'mode' => 'required', - 'error' => __('You must provide a title','ultimate-member') - ), - '_metakey' => array( - 'mode' => 'unique', - ), - ) - ), + 'image' => array( + 'name' => 'Image Upload', + 'col1' => array('_title','_metakey','_help','_allowed_types','_max_size','_crop','_visibility'), + 'col2' => array('_label','_public','_roles','_upload_text','_upload_help_text','_button_text'), + 'col3' => array('_required','_editable','_icon'), + 'validate' => array( + '_title' => array( + 'mode' => 'required', + 'error' => __('You must provide a title','ultimate-member') + ), + '_metakey' => array( + 'mode' => 'unique', + ), + '_max_size' => array( + 'mode' => 'numeric', + 'error' => __('Please enter a valid size','ultimate-member') + ), + ) + ), - /*'group' => array( + 'file' => array( + 'name' => 'File Upload', + 'col1' => array('_title','_metakey','_help','_allowed_types','_max_size','_visibility'), + 'col2' => array('_label','_public','_roles','_upload_text','_upload_help_text','_button_text'), + 'col3' => array('_required','_editable','_icon'), + 'validate' => array( + '_title' => array( + 'mode' => 'required', + 'error' => __('You must provide a title','ultimate-member') + ), + '_metakey' => array( + 'mode' => 'unique', + ), + '_max_size' => array( + 'mode' => 'numeric', + 'error' => __('Please enter a valid size','ultimate-member') + ), + ) + ), + + 'date' => array( + 'name' => 'Date Picker', + 'col1' => array('_title','_metakey','_help','_range','_years','_years_x','_range_start','_range_end','_visibility'), + 'col2' => array('_label','_placeholder','_public','_roles','_format','_pretty_format','_disabled_weekdays'), + 'col3' => array('_required','_editable','_icon'), + 'validate' => array( + '_title' => array( + 'mode' => 'required', + 'error' => __('You must provide a title','ultimate-member') + ), + '_metakey' => array( + 'mode' => 'unique', + ), + '_years' => array( + 'mode' => 'numeric', + 'error' => __('Number of years is not valid','ultimate-member') + ), + '_range_start' => array( + 'mode' => 'range-start', + ), + '_range_end' => array( + 'mode' => 'range-end', + ), + ) + ), + + 'time' => array( + 'name' => 'Time Picker', + 'col1' => array('_title','_metakey','_help','_format','_visibility'), + 'col2' => array('_label','_placeholder','_public','_roles','_intervals'), + 'col3' => array('_required','_editable','_icon'), + 'validate' => array( + '_title' => array( + 'mode' => 'required', + 'error' => __('You must provide a title','ultimate-member') + ), + '_metakey' => array( + 'mode' => 'unique', + ), + ) + ), + + 'rating' => array( + 'name' => 'Rating', + 'col1' => array('_title','_metakey','_help','_visibility'), + 'col2' => array('_label','_public','_roles','_number','_default'), + 'col3' => array('_required','_editable','_icon'), + 'validate' => array( + '_title' => array( + 'mode' => 'required', + 'error' => __('You must provide a title','ultimate-member') + ), + '_metakey' => array( + 'mode' => 'unique', + ), + ) + ), + + 'block' => array( + 'name' => 'Content Block', + 'col1' => array('_title','_visibility'), + 'col2' => array('_public','_roles'), + 'col_full' => array('_content'), + 'mce_content' => true, + 'validate' => array( + '_title' => array( + 'mode' => 'required', + 'error' => __('You must provide a title','ultimate-member') + ), + ) + ), + + 'shortcode' => array( + 'name' => 'Shortcode', + 'col1' => array('_title','_visibility'), + 'col2' => array('_public','_roles'), + 'col_full' => array('_content'), + 'validate' => array( + '_title' => array( + 'mode' => 'required', + 'error' => __('You must provide a title','ultimate-member') + ), + '_content' => array( + 'mode' => 'required', + 'error' => __('You must add a shortcode to the content area','ultimate-member') + ), + ) + ), + + 'spacing' => array( + 'name' => 'Spacing', + 'col1' => array('_title','_visibility'), + 'col2' => array('_spacing'), + 'form_only' => true, + 'validate' => array( + '_title' => array( + 'mode' => 'required', + 'error' => __('You must provide a title','ultimate-member') + ), + ) + ), + + 'divider' => array( + 'name' => 'Divider', + 'col1' => array('_title','_width','_divider_text','_visibility'), + 'col2' => array('_style','_color'), + 'form_only' => true, + 'validate' => array( + '_title' => array( + 'mode' => 'required', + 'error' => __('You must provide a title','ultimate-member') + ), + ) + ), + + 'googlemap' => array( + 'name' => 'Google Map', + 'col1' => array('_title','_metakey','_help','_visibility'), + 'col2' => array('_label','_placeholder','_public','_roles','_validate','_custom_validate'), + 'col3' => array('_required','_editable','_icon'), + 'validate' => array( + '_title' => array( + 'mode' => 'required', + 'error' => __('You must provide a title','ultimate-member') + ), + '_metakey' => array( + 'mode' => 'unique', + ), + ) + ), + + 'youtube_video' => array( + 'name' => 'YouTube Video', + 'col1' => array('_title','_metakey','_help','_visibility'), + 'col2' => array('_label','_placeholder','_public','_roles','_validate','_custom_validate'), + 'col3' => array('_required','_editable','_icon'), + 'validate' => array( + '_title' => array( + 'mode' => 'required', + 'error' => __('You must provide a title','ultimate-member') + ), + '_metakey' => array( + 'mode' => 'unique', + ), + ) + ), + + 'vimeo_video' => array( + 'name' => 'Vimeo Video', + 'col1' => array('_title','_metakey','_help','_visibility'), + 'col2' => array('_label','_placeholder','_public','_roles','_validate','_custom_validate'), + 'col3' => array('_required','_editable','_icon'), + 'validate' => array( + '_title' => array( + 'mode' => 'required', + 'error' => __('You must provide a title','ultimate-member') + ), + '_metakey' => array( + 'mode' => 'unique', + ), + ) + ), + + 'soundcloud_track' => array( + 'name' => 'SoundCloud Track', + 'col1' => array('_title','_metakey','_help','_visibility'), + 'col2' => array('_label','_placeholder','_public','_roles','_validate','_custom_validate'), + 'col3' => array('_required','_editable','_icon'), + 'validate' => array( + '_title' => array( + 'mode' => 'required', + 'error' => __('You must provide a title','ultimate-member') + ), + '_metakey' => array( + 'mode' => 'unique', + ), + ) + ), + + /*'group' => array( 'name' => 'Field Group', 'col1' => array('_title','_max_entries'), 'col2' => array('_label','_public','_roles'), @@ -531,1222 +593,1238 @@ if ( ! class_exists( 'Builtin' ) ) { ) ),*/ - ); + ); - /** - * UM hook - * - * @type filter - * @title um_core_fields_hook - * @description UM Core Fields - * @input_vars - * [{"var":"$core_fields","type":"array","desc":"Core Fields"}] - * @change_log - * ["Since: 2.0"] - * @usage add_filter( 'um_core_fields_hook', 'function_name', 10, 1 ); - * @example - * - */ - $this->core_fields = apply_filters( 'um_core_fields_hook', $this->core_fields ); - } + /** + * UM hook + * + * @type filter + * @title um_core_fields_hook + * @description UM Core Fields + * @input_vars + * [{"var":"$core_fields","type":"array","desc":"Core Fields"}] + * @change_log + * ["Since: 2.0"] + * @usage add_filter( 'um_core_fields_hook', 'function_name', 10, 1 ); + * @example + * + */ + $this->core_fields = apply_filters( 'um_core_fields_hook', $this->core_fields ); + } - /*** - *** @Predefined Fields - ***/ - function set_predefined_fields() { - global $wp_roles; - $role_keys = get_option( 'um_roles' ); - if ( ! empty( $role_keys ) && is_array( $role_keys ) ) { - $role_keys = array_map( function( $item ) { - return 'um_' . $item; - }, $role_keys ); - } else { - $role_keys = array(); - } + /** + * Predefined Fields + */ + function set_predefined_fields() { + + global $wp_roles; + $role_keys = get_option( 'um_roles' ); + if ( ! empty( $role_keys ) && is_array( $role_keys ) ) { + $role_keys = array_map( function( $item ) { + return 'um_' . $item; + }, $role_keys ); + } else { + $role_keys = array(); + } $exclude_roles = array_diff( array_keys( $wp_roles->roles ), array_merge( $role_keys, array( 'subscriber' ) ) ); - $um_roles = UM()->roles()->get_roles( false, $exclude_roles ); - - /** - * UM hook - * - * @type filter - * @title um_profile_privacy_options - * @description Profile Privacy Options - * @input_vars - * [{"var":"$privacy_options","type":"array","desc":"Privacy Options"}] - * @change_log - * ["Since: 2.0"] - * @usage add_filter( 'um_profile_privacy_options', 'function_name', 10, 1 ); - * @example - * - */ - $profile_privacy = apply_filters( 'um_profile_privacy_options', array( - __( 'Everyone', 'ultimate-member' ), - __( 'Only me', 'ultimate-member' ) - ) ); - - $this->predefined_fields = array( - - 'user_login' => array( - 'title' => __('Username','ultimate-member'), - 'metakey' => 'user_login', - 'type' => 'text', - 'label' => __('Username','ultimate-member'), - 'required' => 1, - 'public' => 1, - 'editable' => 0, - 'validate' => 'unique_username', - 'min_chars' => 3, - 'max_chars' => 24 - ), - - 'username' => array( - 'title' => __('Username or E-mail','ultimate-member'), - 'metakey' => 'username', - 'type' => 'text', - 'label' => __('Username or E-mail','ultimate-member'), - 'required' => 1, - 'public' => 1, - 'editable' => 0, - 'validate' => 'unique_username_or_email', - ), - - 'user_password' => array( - 'title' => __('Password','ultimate-member'), - 'metakey' => 'user_password', - 'type' => 'password', - 'label' => __('Password','ultimate-member'), - 'required' => 1, - 'public' => 1, - 'editable' => 1, - 'min_chars' => 8, - 'max_chars' => 30, - 'force_good_pass' => 1, - 'force_confirm_pass' => 1, - ), - - 'first_name' => array( - 'title' => __('First Name','ultimate-member'), - 'metakey' => 'first_name', - 'type' => 'text', - 'label' => __('First Name','ultimate-member'), - 'required' => 0, - 'public' => 1, - 'editable' => 1, - ), - - 'last_name' => array( - 'title' => __('Last Name','ultimate-member'), - 'metakey' => 'last_name', - 'type' => 'text', - 'label' => __('Last Name','ultimate-member'), - 'required' => 0, - 'public' => 1, - 'editable' => 1, - ), - - 'nickname' => array( - 'title' => __('Nickname','ultimate-member'), - 'metakey' => 'nickname', - 'type' => 'text', - 'label' => __('Nickname','ultimate-member'), - 'required' => 0, - 'public' => 1, - 'editable' => 1, - ), - - 'user_registered' => array( - 'title' => __('Registration Date','ultimate-member'), - 'metakey' => 'user_registered', - 'type' => 'text', - 'label' => __('Registration Date','ultimate-member'), - 'required' => 0, - 'public' => 1, - 'editable' => 1, - 'edit_forbidden' => 1, - ), - - 'last_login' => array( - 'title' => __('Last Login','ultimate-member'), - 'metakey' => '_um_last_login', - 'type' => 'text', - 'label' => __('Last Login','ultimate-member'), - 'required' => 0, - 'public' => 1, - 'editable' => 1, - 'edit_forbidden' => 1, - ), - - 'user_email' => array( - 'title' => __('E-mail Address','ultimate-member'), - 'metakey' => 'user_email', - 'type' => 'text', - 'label' => __('E-mail Address','ultimate-member'), - 'required' => 0, - 'public' => 1, - 'validate' => 'unique_email', - 'autocomplete' => 'off' - ), - - 'secondary_user_email' => array( - 'title' => __('Secondary E-mail Address','ultimate-member'), - 'metakey' => 'secondary_user_email', - 'type' => 'text', - 'label' => __('Secondary E-mail Address','ultimate-member'), - 'required' => 0, - 'public' => 1, - 'editable' => 1, - 'validate' => 'unique_email', - 'autocomplete' => 'off' - ), - - 'description' => array( - 'title' => __('Biography','ultimate-member'), - 'metakey' => 'description', - 'type' => 'textarea', - 'label' => __('Biography','ultimate-member'), - 'html' => 0, - 'required' => 0, - 'public' => 1, - 'editable' => 1, - 'max_words' => 40, - 'placeholder' => __('Enter a bit about yourself...','ultimate-member'), - ), - - 'birth_date' => array( - 'title' => __('Birth Date','ultimate-member'), - 'metakey' => 'birth_date', - 'type' => 'date', - 'label' => __('Birth Date','ultimate-member'), - 'required' => 0, - 'public' => 1, - 'editable' => 1, - 'pretty_format' => 1, - 'years' => 115, - 'years_x' => 'past', - 'icon' => 'um-faicon-calendar' - ), - - 'gender' => array( - 'title' => __('Gender','ultimate-member'), - 'metakey' => 'gender', - 'type' => 'radio', - 'label' => __('Gender','ultimate-member'), - 'required' => 0, - 'public' => 1, - 'editable' => 1, - 'options' => array( __('Male','ultimate-member'), __('Female','ultimate-member') ) - ), - - 'country' => array( - 'title' => __('Country','ultimate-member'), - 'metakey' => 'country', - 'type' => 'select', - 'label' => __('Country','ultimate-member'), - 'placeholder' => __('Choose a Country','ultimate-member'), - 'required' => 0, - 'public' => 1, - 'editable' => 1, - 'options' => $this->get('countries') - ), - - 'facebook' => array( - 'title' => __('Facebook','ultimate-member'), - 'metakey' => 'facebook', - 'type' => 'url', - 'label' => __('Facebook','ultimate-member'), - 'required' => 0, - 'public' => 1, - 'editable' => 1, - 'url_target' => '_blank', - 'url_rel' => 'nofollow', - 'icon' => 'um-faicon-facebook', - 'validate' => 'facebook_url', - 'url_text' => 'Facebook', - 'advanced' => 'social', - 'color' => '#3B5999', - 'match' => 'https://facebook.com/', - ), - - 'twitter' => array( - 'title' => __('Twitter','ultimate-member'), - 'metakey' => 'twitter', - 'type' => 'url', - 'label' => __('Twitter','ultimate-member'), - 'required' => 0, - 'public' => 1, - 'editable' => 1, - 'url_target' => '_blank', - 'url_rel' => 'nofollow', - 'icon' => 'um-faicon-twitter', - 'validate' => 'twitter_url', - 'url_text' => 'Twitter', - 'advanced' => 'social', - 'color' => '#4099FF', - 'match' => 'https://twitter.com/', - ), - - 'linkedin' => array( - 'title' => __('LinkedIn','ultimate-member'), - 'metakey' => 'linkedin', - 'type' => 'url', - 'label' => __('LinkedIn','ultimate-member'), - 'required' => 0, - 'public' => 1, - 'editable' => 1, - 'url_target' => '_blank', - 'url_rel' => 'nofollow', - 'icon' => 'um-faicon-linkedin', - 'validate' => 'linkedin_url', - 'url_text' => 'LinkedIn', - 'advanced' => 'social', - 'color' => '#0976b4', - 'match' => 'https://linkedin.com/in/', - ), - - 'googleplus' => array( - 'title' => __('Google+','ultimate-member'), - 'metakey' => 'googleplus', - 'type' => 'url', - 'label' => __('Google+','ultimate-member'), - 'required' => 0, - 'public' => 1, - 'editable' => 1, - 'url_target' => '_blank', - 'url_rel' => 'nofollow', - 'icon' => 'um-faicon-google-plus', - 'validate' => 'google_url', - 'url_text' => 'Google+', - 'advanced' => 'social', - 'color' => '#dd4b39', - 'match' => 'https://google.com/+', - ), - - 'instagram' => array( - 'title' => __('Instagram','ultimate-member'), - 'metakey' => 'instagram', - 'type' => 'url', - 'label' => __('Instagram','ultimate-member'), - 'required' => 0, - 'public' => 1, - 'editable' => 1, - 'url_target' => '_blank', - 'url_rel' => 'nofollow', - 'icon' => 'um-faicon-instagram', - 'validate' => 'instagram_url', - 'url_text' => 'Instagram', - 'advanced' => 'social', - 'color' => '#3f729b', - 'match' => 'https://instagram.com/', - ), - - 'skype' => array( - 'title' => __('Skype ID','ultimate-member'), - 'metakey' => 'skype', - 'type' => 'url', - 'label' => __('Skype ID','ultimate-member'), - 'required' => 0, - 'public' => 1, - 'editable' => 1, - 'url_target' => '_blank', - 'url_rel' => 'nofollow', - 'icon' => 'um-faicon-skype', - 'validate' => 'skype', - 'url_text' => 'Skype', - ), - - 'youtube' => array( - 'title' => __('YouTube','ultimate-member'), - 'metakey' => 'youtube', - 'type' => 'url', - 'label' => __('YouTube','ultimate-member'), - 'required' => 0, - 'public' => 1, - 'editable' => 1, - 'url_target' => '_blank', - 'url_rel' => 'nofollow', - 'icon' => 'um-faicon-youtube', - 'validate' => 'youtube_url', - 'url_text' => 'YouTube', - 'advanced' => 'social', - 'color' => '#e52d27', - 'match' => 'https://youtube.com/', - ), - - 'soundcloud' => array( - 'title' => __('SoundCloud','ultimate-member'), - 'metakey' => 'soundcloud', - 'type' => 'url', - 'label' => __('SoundCloud','ultimate-member'), - 'required' => 0, - 'public' => 1, - 'editable' => 1, - 'url_target' => '_blank', - 'url_rel' => 'nofollow', - 'icon' => 'um-faicon-soundcloud', - 'validate' => 'soundcloud_url', - 'url_text' => 'SoundCloud', - 'advanced' => 'social', - 'color' => '#f50', - 'match' => 'https://soundcloud.com/', - ), - - 'vk' => array( - 'title' => __('VKontakte','ultimate-member'), - 'metakey' => 'vkontakte', - 'type' => 'url', - 'label' => __('VKontakte','ultimate-member'), - 'required' => 0, - 'public' => 1, - 'editable' => 1, - 'url_target' => '_blank', - 'url_rel' => 'nofollow', - 'icon' => 'um-faicon-vk', - 'validate' => 'vk_url', - 'url_text' => 'VKontakte', - 'advanced' => 'social', - 'color' => '#2B587A', - 'match' => 'https://vk.com/', - ), - - 'role_select' => array( - 'title' => __('Roles (Dropdown)','ultimate-member'), - 'metakey' => 'role_select', - 'type' => 'select', - 'label' => __('Account Type','ultimate-member'), - 'placeholder' => 'Choose account type', - 'required' => 0, - 'public' => 1, - 'editable' => 1, - 'options' => $um_roles, - ), - - 'role_radio' => array( - 'title' => __('Roles (Radio)','ultimate-member'), - 'metakey' => 'role_radio', - 'type' => 'radio', - 'label' => __('Account Type','ultimate-member'), - 'required' => 0, - 'public' => 1, - 'editable' => 1, - 'options' => $um_roles, - ), - - 'languages' => array( - 'title' => __('Languages','ultimate-member'), - 'metakey' => 'languages', - 'type' => 'multiselect', - 'label' => __('Languages Spoken','ultimate-member'), - 'placeholder' => __('Select languages','ultimate-member'), - 'required' => 0, - 'public' => 1, - 'editable' => 1, - 'options' => $this->get('languages'), - ), - - 'phone_number' => array( - 'title' => __('Phone Number','ultimate-member'), - 'metakey' => 'phone_number', - 'type' => 'text', - 'label' => __('Phone Number','ultimate-member'), - 'required' => 0, - 'public' => 1, - 'editable' => 1, - 'validate' => 'phone_number', - 'icon' => 'um-faicon-phone', - ), - - 'mobile_number' => array( - 'title' => __('Mobile Number','ultimate-member'), - 'metakey' => 'mobile_number', - 'type' => 'text', - 'label' => __('Mobile Number','ultimate-member'), - 'required' => 0, - 'public' => 1, - 'editable' => 1, - 'validate' => 'phone_number', - 'icon' => 'um-faicon-mobile', - ), - - // private use ( not public list ) - - 'profile_photo' => array( - 'title' => __('Profile Photo','ultimate-member'), - 'metakey' => 'profile_photo', - 'type' => 'image', - 'label' => __('Change your profile photo','ultimate-member'), - 'upload_text' => __('Upload your photo here','ultimate-member'), - 'icon' => 'um-faicon-camera', - 'crop' => 1, - 'max_size' => ( UM()->options()->get('profile_photo_max_size') ) ? UM()->options()->get('profile_photo_max_size') : 999999999, - 'min_width' => str_replace('px','',UM()->options()->get('profile_photosize')), - 'min_height' => str_replace('px','',UM()->options()->get('profile_photosize')), - 'private_use' => true, - ), - - 'cover_photo' => array( - 'title' => __('Cover Photo','ultimate-member'), - 'metakey' => 'cover_photo', - 'type' => 'image', - 'label' => __('Change your cover photo','ultimate-member'), - 'upload_text' => __('Upload profile cover here','ultimate-member'), - 'icon' => 'um-faicon-picture-o', - 'crop' => 2, - 'max_size' => ( UM()->options()->get('cover_photo_max_size') ) ? UM()->options()->get('cover_photo_max_size') : 999999999, - 'modal_size' => 'large', - 'ratio' => str_replace(':1','',UM()->options()->get('profile_cover_ratio')), - 'min_width' => UM()->options()->get('cover_min_width'), - 'private_use' => true, - ), - - 'password_reset_text' => array( - 'title' => __('Password Reset','ultimate-member'), - 'type' => 'block', - 'content' => '
' . __('To reset your password, please enter your email address or username below','ultimate-member'). '
', - 'private_use' => true, - ), - - 'username_b' => array( - 'title' => __('Username or E-mail','ultimate-member'), - 'metakey' => 'username_b', - 'type' => 'text', - 'placeholder' => __('Enter your username or email','ultimate-member'), - 'required' => 1, - 'public' => 1, - 'editable' => 0, - 'private_use' => true, - ), - - // account page use ( not public ) - - 'profile_privacy' => array( - 'title' => __('Profile Privacy','ultimate-member'), - 'metakey' => 'profile_privacy', - 'type' => 'select', - 'label' => __('Profile Privacy','ultimate-member'), - 'help' => __('Who can see your public profile?','ultimate-member'), - 'required' => 0, - 'public' => 1, - 'editable' => 1, - 'default' => __('Everyone','ultimate-member'), - 'options' => $profile_privacy, - 'allowclear' => 0, - 'account_only' => true, - 'required_perm' => 'can_make_private_profile', - ), - - 'hide_in_members' => array( - 'title' => __('Hide my profile from directory','ultimate-member'), - 'metakey' => 'hide_in_members', - 'type' => 'radio', - 'label' => __('Hide my profile from directory','ultimate-member'), - 'help' => __('Here you can hide yourself from appearing in public directory','ultimate-member'), - 'required' => 0, - 'public' => 1, - 'editable' => 1, - 'default' => 'No', - 'options' => array( 'No' => __('No','ultimate-member'), 'Yes' => __('Yes','ultimate-member') ), - 'account_only' => true, - 'required_opt' => array( 'members_page', 1 ), - ), - - 'delete_account' => array( - 'title' => __('Delete Account','ultimate-member'), - 'metakey' => 'delete_account', - 'type' => 'radio', - 'label' => __('Delete Account','ultimate-member'), - 'help' => __('If you confirm, everything related to your profile will be deleted permanently from the site','ultimate-member'), - 'required' => 0, - 'public' => 1, - 'editable' => 1, - 'default' => __('No','ultimate-member'), - 'options' => array( __('Yes','ultimate-member') , __('No','ultimate-member') ), - 'account_only' => true, - ), - - 'single_user_password' => array( - 'title' => __('Password','ultimate-member'), - 'metakey' => 'single_user_password', - 'type' => 'password', - 'label' => __('Password','ultimate-member'), - 'required' => 1, - 'public' => 1, - 'editable' => 1, - 'account_only' => true, - ), - - ); - - /** - * UM hook - * - * @type filter - * @title um_predefined_fields_hook - * @description Extend Predefined Fields - * @input_vars - * [{"var":"$predefined_fields","type":"array","desc":"Predefined Fields"}] - * @change_log - * ["Since: 2.0"] - * @usage add_filter( 'um_predefined_fields_hook', 'function_name', 10, 1 ); - * @example - * - */ - $this->predefined_fields = apply_filters( 'um_predefined_fields_hook', $this->predefined_fields ); - } - - /*** - *** @Custom Fields - ***/ - function set_custom_fields(){ - - if ( is_array( $this->saved_fields ) ) { - - $this->custom_fields = $this->saved_fields; - - } else { - - $this->custom_fields = ''; - - } - - $custom = $this->custom_fields; - $predefined = $this->predefined_fields; - - if ( is_array( $custom ) ){ - $this->all_user_fields = array_merge( $predefined, $custom ); - } else { - $this->all_user_fields = $predefined; - } - - } - - /*** - *** @may be used to show a dropdown, or source for user meta - ***/ - function all_user_fields( $exclude_types = null, $show_all = false ) { - - $fields_without_metakey = array('block','shortcode','spacing','divider','group'); - remove_filter('um_fields_without_metakey', 'um_user_tags_requires_no_metakey'); - - /** - * UM hook - * - * @type filter - * @title um_fields_without_metakey - * @description Extend Fields without metakey - * @input_vars - * [{"var":"$fields","type":"array","desc":"Fields without metakey"}] - * @change_log - * ["Since: 2.0"] - * @usage add_filter( 'um_fields_without_metakey', 'function_name', 10, 1 ); - * @example - * - */ - $fields_without_metakey = apply_filters( 'um_fields_without_metakey', $fields_without_metakey ); - - if ( !$show_all ) { - $this->fields_dropdown = array('image','file','password','rating'); - $this->fields_dropdown = array_merge( $this->fields_dropdown, $fields_without_metakey ); - } else { - $this->fields_dropdown = $fields_without_metakey; - } - - $custom = $this->custom_fields; - $predefined = $this->predefined_fields; - - if ( $exclude_types ) { - $exclude_types = explode(',', $exclude_types); - } - - $all = array( 0 => '' ); - - if ( is_array( $custom ) ){ - $all = $all + array_merge( $predefined, $custom ); - } else { - $all = $all + $predefined; - } - - foreach( $all as $k => $arr ) { - - if ( $k == 0 ) { - unset($all[$k]); - } - - if ( isset( $arr['title'] ) ){ - $all[$k]['title'] = stripslashes( $arr['title'] ); - } - - if ( $exclude_types && isset( $arr['type'] ) && in_array( $arr['type'], $exclude_types ) ) { - unset( $all[$k] ); - } - if ( isset( $arr['account_only'] ) || isset( $arr['private_use'] ) ) { - if ( !$show_all ) { - unset( $all[$k] ); - } - } - if ( isset( $arr['type'] ) && in_array( $arr['type'], $this->fields_dropdown ) ) { - unset( $all[$k] ); - } - } - - $all = UM()->fields()->array_sort_by_column( $all, 'title'); - - $all = array( 0 => '') + $all; - - return $all; - } - - /*** - *** @Possible validation types for fields - ***/ - function validation_types(){ - - $array[0] = __('None','ultimate-member'); - $array['alphabetic'] = __('Alphabetic value only','ultimate-member'); - $array['alpha_numeric'] = __('Alpha-numeric value','ultimate-member'); - $array['english'] = __('English letters only','ultimate-member'); - $array['facebook_url'] = __('Facebook URL','ultimate-member'); - $array['google_url'] = __('Google+ URL','ultimate-member'); - $array['instagram_url'] = __('Instagram URL','ultimate-member'); - $array['linkedin_url'] = __('LinkedIn URL','ultimate-member'); - $array['vk_url'] = __('VKontakte URL','ultimate-member'); - $array['lowercase'] = __('Lowercase only','ultimate-member'); - $array['numeric'] = __('Numeric value only','ultimate-member'); - $array['phone_number'] = __('Phone Number','ultimate-member'); - $array['skype'] = __('Skype ID','ultimate-member'); - $array['soundcloud'] = __('SoundCloud Profile','ultimate-member'); - $array['twitter_url'] = __('Twitter URL','ultimate-member'); - $array['unique_email'] = __('Unique E-mail','ultimate-member'); - $array['unique_value'] = __('Unique Metakey value','ultimate-member'); - $array['unique_username'] = __('Unique Username','ultimate-member'); - $array['unique_username_or_email'] = __('Unique Username/E-mail','ultimate-member'); - $array['url'] = __('Website URL','ultimate-member'); - $array['youtube_url'] = __('YouTube Profile','ultimate-member'); - $array['custom'] = __('Custom Validation','ultimate-member'); - - /** - * UM hook - * - * @type filter - * @title um_admin_field_validation_hook - * @description Extend validation types - * @input_vars - * [{"var":"$types","type":"array","desc":"Validation Types"}] - * @change_log - * ["Since: 2.0"] - * @usage add_filter( 'um_admin_field_validation_hook', 'function_name', 10, 1 ); - * @example - * - */ - $array = apply_filters( 'um_admin_field_validation_hook', $array ); - return $array; - } - - /*** - *** @Get predefined options - ***/ - function get( $data ){ - switch($data) { - - case 'languages': - $array = array( - "aa" => __("Afar",'ultimate-member'), - "ab" => __("Abkhazian",'ultimate-member'), - "ae" => __("Avestan",'ultimate-member'), - "af" => __("Afrikaans",'ultimate-member'), - "ak" => __("Akan",'ultimate-member'), - "am" => __("Amharic",'ultimate-member'), - "an" => __("Aragonese",'ultimate-member'), - "ar" => __("Arabic",'ultimate-member'), - "as" => __("Assamese",'ultimate-member'), - "av" => __("Avaric",'ultimate-member'), - "ay" => __("Aymara",'ultimate-member'), - "az" => __("Azerbaijani",'ultimate-member'), - "ba" => __("Bashkir",'ultimate-member'), - "be" => __("Belarusian",'ultimate-member'), - "bg" => __("Bulgarian",'ultimate-member'), - "bh" => __("Bihari",'ultimate-member'), - "bi" => __("Bislama",'ultimate-member'), - "bm" => __("Bambara",'ultimate-member'), - "bn" => __("Bengali",'ultimate-member'), - "bo" => __("Tibetan",'ultimate-member'), - "br" => __("Breton",'ultimate-member'), - "bs" => __("Bosnian",'ultimate-member'), - "ca" => __("Catalan",'ultimate-member'), - "ce" => __("Chechen",'ultimate-member'), - "ch" => __("Chamorro",'ultimate-member'), - "co" => __("Corsican",'ultimate-member'), - "cr" => __("Cree",'ultimate-member'), - "cs" => __("Czech",'ultimate-member'), - "cu" => __("Church Slavic",'ultimate-member'), - "cv" => __("Chuvash",'ultimate-member'), - "cy" => __("Welsh",'ultimate-member'), - "da" => __("Danish",'ultimate-member'), - "de" => __("German",'ultimate-member'), - "dv" => __("Divehi",'ultimate-member'), - "dz" => __("Dzongkha",'ultimate-member'), - "ee" => __("Ewe",'ultimate-member'), - "el" => __("Greek",'ultimate-member'), - "en" => __("English",'ultimate-member'), - "eo" => __("Esperanto",'ultimate-member'), - "es" => __("Spanish",'ultimate-member'), - "et" => __("Estonian",'ultimate-member'), - "eu" => __("Basque",'ultimate-member'), - "fa" => __("Persian",'ultimate-member'), - "ff" => __("Fulah",'ultimate-member'), - "fi" => __("Finnish",'ultimate-member'), - "fj" => __("Fijian",'ultimate-member'), - "fo" => __("Faroese",'ultimate-member'), - "fr" => __("French",'ultimate-member'), - "fy" => __("Western Frisian",'ultimate-member'), - "ga" => __("Irish",'ultimate-member'), - "gd" => __("Scottish Gaelic",'ultimate-member'), - "gl" => __("Galician",'ultimate-member'), - "gn" => __("Guarani",'ultimate-member'), - "gu" => __("Gujarati",'ultimate-member'), - "gv" => __("Manx",'ultimate-member'), - "ha" => __("Hausa",'ultimate-member'), - "he" => __("Hebrew",'ultimate-member'), - "hi" => __("Hindi",'ultimate-member'), - "ho" => __("Hiri Motu",'ultimate-member'), - "hr" => __("Croatian",'ultimate-member'), - "ht" => __("Haitian",'ultimate-member'), - "hu" => __("Hungarian",'ultimate-member'), - "hy" => __("Armenian",'ultimate-member'), - "hz" => __("Herero",'ultimate-member'), - "ia" => __("Interlingua (International Auxiliary Language Association)",'ultimate-member'), - "id" => __("Indonesian",'ultimate-member'), - "ie" => __("Interlingue",'ultimate-member'), - "ig" => __("Igbo",'ultimate-member'), - "ii" => __("Sichuan Yi",'ultimate-member'), - "ik" => __("Inupiaq",'ultimate-member'), - "io" => __("Ido",'ultimate-member'), - "is" => __("Icelandic",'ultimate-member'), - "it" => __("Italian",'ultimate-member'), - "iu" => __("Inuktitut",'ultimate-member'), - "ja" => __("Japanese",'ultimate-member'), - "jv" => __("Javanese",'ultimate-member'), - "ka" => __("Georgian",'ultimate-member'), - "kg" => __("Kongo",'ultimate-member'), - "ki" => __("Kikuyu",'ultimate-member'), - "kj" => __("Kwanyama",'ultimate-member'), - "kk" => __("Kazakh",'ultimate-member'), - "kl" => __("Kalaallisut",'ultimate-member'), - "km" => __("Khmer",'ultimate-member'), - "kn" => __("Kannada",'ultimate-member'), - "ko" => __("Korean",'ultimate-member'), - "kr" => __("Kanuri",'ultimate-member'), - "ks" => __("Kashmiri",'ultimate-member'), - "ku" => __("Kurdish",'ultimate-member'), - "kv" => __("Komi",'ultimate-member'), - "kw" => __("Cornish",'ultimate-member'), - "ky" => __("Kirghiz",'ultimate-member'), - "la" => __("Latin",'ultimate-member'), - "lb" => __("Luxembourgish",'ultimate-member'), - "lg" => __("Ganda",'ultimate-member'), - "li" => __("Limburgish",'ultimate-member'), - "ln" => __("Lingala",'ultimate-member'), - "lo" => __("Lao",'ultimate-member'), - "lt" => __("Lithuanian",'ultimate-member'), - "lu" => __("Luba-Katanga",'ultimate-member'), - "lv" => __("Latvian",'ultimate-member'), - "mg" => __("Malagasy",'ultimate-member'), - "mh" => __("Marshallese",'ultimate-member'), - "mi" => __("Maori",'ultimate-member'), - "mk" => __("Macedonian",'ultimate-member'), - "ml" => __("Malayalam",'ultimate-member'), - "mn" => __("Mongolian",'ultimate-member'), - "mr" => __("Marathi",'ultimate-member'), - "ms" => __("Malay",'ultimate-member'), - "mt" => __("Maltese",'ultimate-member'), - "my" => __("Burmese",'ultimate-member'), - "na" => __("Nauru",'ultimate-member'), - "nb" => __("Norwegian Bokmal",'ultimate-member'), - "nd" => __("North Ndebele",'ultimate-member'), - "ne" => __("Nepali",'ultimate-member'), - "ng" => __("Ndonga",'ultimate-member'), - "nl" => __("Dutch",'ultimate-member'), - "nn" => __("Norwegian Nynorsk",'ultimate-member'), - "no" => __("Norwegian",'ultimate-member'), - "nr" => __("South Ndebele",'ultimate-member'), - "nv" => __("Navajo",'ultimate-member'), - "ny" => __("Chichewa",'ultimate-member'), - "oc" => __("Occitan",'ultimate-member'), - "oj" => __("Ojibwa",'ultimate-member'), - "om" => __("Oromo",'ultimate-member'), - "or" => __("Oriya",'ultimate-member'), - "os" => __("Ossetian",'ultimate-member'), - "pa" => __("Panjabi",'ultimate-member'), - "pi" => __("Pali",'ultimate-member'), - "pl" => __("Polish",'ultimate-member'), - "ps" => __("Pashto",'ultimate-member'), - "pt" => __("Portuguese",'ultimate-member'), - "qu" => __("Quechua",'ultimate-member'), - "rm" => __("Raeto-Romance",'ultimate-member'), - "rn" => __("Kirundi",'ultimate-member'), - "ro" => __("Romanian",'ultimate-member'), - "ru" => __("Russian",'ultimate-member'), - "rw" => __("Kinyarwanda",'ultimate-member'), - "sa" => __("Sanskrit",'ultimate-member'), - "sc" => __("Sardinian",'ultimate-member'), - "sd" => __("Sindhi",'ultimate-member'), - "se" => __("Northern Sami",'ultimate-member'), - "sg" => __("Sango",'ultimate-member'), - "si" => __("Sinhala",'ultimate-member'), - "sk" => __("Slovak",'ultimate-member'), - "sl" => __("Slovenian",'ultimate-member'), - "sm" => __("Samoan",'ultimate-member'), - "sn" => __("Shona",'ultimate-member'), - "so" => __("Somali",'ultimate-member'), - "sq" => __("Albanian",'ultimate-member'), - "sr" => __("Serbian",'ultimate-member'), - "ss" => __("Swati",'ultimate-member'), - "st" => __("Southern Sotho",'ultimate-member'), - "su" => __("Sundanese",'ultimate-member'), - "sv" => __("Swedish",'ultimate-member'), - "sw" => __("Swahili",'ultimate-member'), - "ta" => __("Tamil",'ultimate-member'), - "te" => __("Telugu",'ultimate-member'), - "tg" => __("Tajik",'ultimate-member'), - "th" => __("Thai",'ultimate-member'), - "ti" => __("Tigrinya",'ultimate-member'), - "tk" => __("Turkmen",'ultimate-member'), - "tl" => __("Tagalog",'ultimate-member'), - "tn" => __("Tswana",'ultimate-member'), - "to" => __("Tonga",'ultimate-member'), - "tr" => __("Turkish",'ultimate-member'), - "ts" => __("Tsonga",'ultimate-member'), - "tt" => __("Tatar",'ultimate-member'), - "tw" => __("Twi",'ultimate-member'), - "ty" => __("Tahitian",'ultimate-member'), - "ug" => __("Uighur",'ultimate-member'), - "uk" => __("Ukrainian",'ultimate-member'), - "ur" => __("Urdu",'ultimate-member'), - "uz" => __("Uzbek",'ultimate-member'), - "ve" => __("Venda",'ultimate-member'), - "vi" => __("Vietnamese",'ultimate-member'), - "vo" => __("Volapuk",'ultimate-member'), - "wa" => __("Walloon",'ultimate-member'), - "wo" => __("Wolof",'ultimate-member'), - "xh" => __("Xhosa",'ultimate-member'), - "yi" => __("Yiddish",'ultimate-member'), - "yo" => __("Yoruba",'ultimate-member'), - "za" => __("Zhuang",'ultimate-member'), - "zh" => __("Chinese",'ultimate-member'), - "zu" => __("Zulu",'ultimate-member') - ); - break; - - case 'countries': - $array = array ( - 'AF' => __('Afghanistan','ultimate-member'), - 'AX' => __('Åland Islands','ultimate-member'), - 'AL' => __('Albania','ultimate-member'), - 'DZ' => __('Algeria','ultimate-member'), - 'AS' => __('American Samoa','ultimate-member'), - 'AD' => __('Andorra','ultimate-member'), - 'AO' => __('Angola','ultimate-member'), - 'AI' => __('Anguilla','ultimate-member'), - 'AQ' => __('Antarctica','ultimate-member'), - 'AG' => __('Antigua and Barbuda','ultimate-member'), - 'AR' => __('Argentina','ultimate-member'), - 'AM' => __('Armenia','ultimate-member'), - 'AW' => __('Aruba','ultimate-member'), - 'AU' => __('Australia','ultimate-member'), - 'AT' => __('Austria','ultimate-member'), - 'AZ' => __('Azerbaijan','ultimate-member'), - 'BS' => __('Bahamas','ultimate-member'), - 'BH' => __('Bahrain','ultimate-member'), - 'BD' => __('Bangladesh','ultimate-member'), - 'BB' => __('Barbados','ultimate-member'), - 'BY' => __('Belarus','ultimate-member'), - 'BE' => __('Belgium','ultimate-member'), - 'BZ' => __('Belize','ultimate-member'), - 'BJ' => __('Benin','ultimate-member'), - 'BM' => __('Bermuda','ultimate-member'), - 'BT' => __('Bhutan','ultimate-member'), - 'BO' => __('Bolivia, Plurinational State of','ultimate-member'), - 'BA' => __('Bosnia and Herzegovina','ultimate-member'), - 'BW' => __('Botswana','ultimate-member'), - 'BV' => __('Bouvet Island','ultimate-member'), - 'BR' => __('Brazil','ultimate-member'), - 'IO' => __('British Indian Ocean Territory','ultimate-member'), - 'BN' => __('Brunei Darussalam','ultimate-member'), - 'BG' => __('Bulgaria','ultimate-member'), - 'BF' => __('Burkina Faso','ultimate-member'), - 'BI' => __('Burundi','ultimate-member'), - 'KH' => __('Cambodia','ultimate-member'), - 'CM' => __('Cameroon','ultimate-member'), - 'CA' => __('Canada','ultimate-member'), - 'CV' => __('Cape Verde','ultimate-member'), - 'KY' => __('Cayman Islands','ultimate-member'), - 'CF' => __('Central African Republic','ultimate-member'), - 'TD' => __('Chad','ultimate-member'), - 'CL' => __('Chile','ultimate-member'), - 'CN' => __('China','ultimate-member'), - 'CX' => __('Christmas Island','ultimate-member'), - 'CC' => __('Cocos (Keeling) Islands','ultimate-member'), - 'CO' => __('Colombia','ultimate-member'), - 'KM' => __('Comoros','ultimate-member'), - 'CG' => __('Congo','ultimate-member'), - 'CD' => __('Congo, the Democratic Republic of the','ultimate-member'), - 'CK' => __('Cook Islands','ultimate-member'), - 'CR' => __('Costa Rica','ultimate-member'), - 'CI' => __("Côte d'Ivoire",'ultimate-member'), - 'HR' => __('Croatia','ultimate-member'), - 'CU' => __('Cuba','ultimate-member'), - 'CY' => __('Cyprus','ultimate-member'), - 'CZ' => __('Czech Republic','ultimate-member'), - 'DK' => __('Denmark','ultimate-member'), - 'DJ' => __('Djibouti','ultimate-member'), - 'DM' => __('Dominica','ultimate-member'), - 'DO' => __('Dominican Republic','ultimate-member'), - 'EC' => __('Ecuador','ultimate-member'), - 'EG' => __('Egypt','ultimate-member'), - 'SV' => __('El Salvador','ultimate-member'), - 'GQ' => __('Equatorial Guinea','ultimate-member'), - 'ER' => __('Eritrea','ultimate-member'), - 'EE' => __('Estonia','ultimate-member'), - 'ET' => __('Ethiopia','ultimate-member'), - 'FK' => __('Falkland Islands (Malvinas)','ultimate-member'), - 'FO' => __('Faroe Islands','ultimate-member'), - 'FJ' => __('Fiji','ultimate-member'), - 'FI' => __('Finland','ultimate-member'), - 'FR' => __('France','ultimate-member'), - 'GF' => __('French Guiana','ultimate-member'), - 'PF' => __('French Polynesia','ultimate-member'), - 'TF' => __('French Southern Territories','ultimate-member'), - 'GA' => __('Gabon','ultimate-member'), - 'GM' => __('Gambia','ultimate-member'), - 'GE' => __('Georgia','ultimate-member'), - 'DE' => __('Germany','ultimate-member'), - 'GH' => __('Ghana','ultimate-member'), - 'GI' => __('Gibraltar','ultimate-member'), - 'GR' => __('Greece','ultimate-member'), - 'GL' => __('Greenland','ultimate-member'), - 'GD' => __('Grenada','ultimate-member'), - 'GP' => __('Guadeloupe','ultimate-member'), - 'GU' => __('Guam','ultimate-member'), - 'GT' => __('Guatemala','ultimate-member'), - 'GG' => __('Guernsey','ultimate-member'), - 'GN' => __('Guinea','ultimate-member'), - 'GW' => __('Guinea-Bissau','ultimate-member'), - 'GY' => __('Guyana','ultimate-member'), - 'HT' => __('Haiti','ultimate-member'), - 'HM' => __('Heard Island and McDonald Islands','ultimate-member'), - 'VA' => __('Holy See (Vatican City State)','ultimate-member'), - 'HN' => __('Honduras','ultimate-member'), - 'HK' => __('Hong Kong','ultimate-member'), - 'HU' => __('Hungary','ultimate-member'), - 'IS' => __('Iceland','ultimate-member'), - 'IN' => __('India','ultimate-member'), - 'ID' => __('Indonesia','ultimate-member'), - 'IR' => __('Iran, Islamic Republic of','ultimate-member'), - 'IQ' => __('Iraq','ultimate-member'), - 'IE' => __('Ireland','ultimate-member'), - 'IM' => __('Isle of Man','ultimate-member'), - 'IL' => __('Israel','ultimate-member'), - 'IT' => __('Italy','ultimate-member'), - 'JM' => __('Jamaica','ultimate-member'), - 'JP' => __('Japan','ultimate-member'), - 'JE' => __('Jersey','ultimate-member'), - 'JO' => __('Jordan','ultimate-member'), - 'KZ' => __('Kazakhstan','ultimate-member'), - 'KE' => __('Kenya','ultimate-member'), - 'KI' => __('Kiribati','ultimate-member'), - 'KP' => __("Korea, Democratic People's Republic of",'ultimate-member'), - 'KR' => __('Korea, Republic of','ultimate-member'), - 'KW' => __('Kuwait','ultimate-member'), - 'KG' => __('Kyrgyzstan','ultimate-member'), - 'LA' => __("Lao People's Democratic Republic",'ultimate-member'), - 'LV' => __('Latvia','ultimate-member'), - 'LB' => __('Lebanon','ultimate-member'), - 'LS' => __('Lesotho','ultimate-member'), - 'LR' => __('Liberia','ultimate-member'), - 'LY' => __('Libyan Arab Jamahiriya','ultimate-member'), - 'LI' => __('Liechtenstein','ultimate-member'), - 'LT' => __('Lithuania','ultimate-member'), - 'LU' => __('Luxembourg','ultimate-member'), - 'MO' => __('Macao','ultimate-member'), - 'MK' => __('Macedonia, the former Yugoslav Republic of','ultimate-member'), - 'MG' => __('Madagascar','ultimate-member'), - 'MW' => __('Malawi','ultimate-member'), - 'MY' => __('Malaysia','ultimate-member'), - 'MV' => __('Maldives','ultimate-member'), - 'ML' => __('Mali','ultimate-member'), - 'MT' => __('Malta','ultimate-member'), - 'MH' => __('Marshall Islands','ultimate-member'), - 'MQ' => __('Martinique','ultimate-member'), - 'MR' => __('Mauritania','ultimate-member'), - 'MU' => __('Mauritius','ultimate-member'), - 'YT' => __('Mayotte','ultimate-member'), - 'MX' => __('Mexico','ultimate-member'), - 'FM' => __('Micronesia, Federated States of','ultimate-member'), - 'MD' => __('Moldova, Republic of','ultimate-member'), - 'MC' => __('Monaco','ultimate-member'), - 'MN' => __('Mongolia','ultimate-member'), - 'ME' => __('Montenegro','ultimate-member'), - 'MS' => __('Montserrat','ultimate-member'), - 'MA' => __('Morocco','ultimate-member'), - 'MZ' => __('Mozambique','ultimate-member'), - 'MM' => __('Myanmar','ultimate-member'), - 'NA' => __('Namibia','ultimate-member'), - 'NR' => __('Nauru','ultimate-member'), - 'NP' => __('Nepal','ultimate-member'), - 'NL' => __('Netherlands','ultimate-member'), - 'AN' => __('Netherlands Antilles','ultimate-member'), - 'NC' => __('New Caledonia','ultimate-member'), - 'NZ' => __('New Zealand','ultimate-member'), - 'NI' => __('Nicaragua','ultimate-member'), - 'NE' => __('Niger','ultimate-member'), - 'NG' => __('Nigeria','ultimate-member'), - 'NU' => __('Niue','ultimate-member'), - 'NF' => __('Norfolk Island','ultimate-member'), - 'MP' => __('Northern Mariana Islands','ultimate-member'), - 'NO' => __('Norway','ultimate-member'), - 'OM' => __('Oman','ultimate-member'), - 'PK' => __('Pakistan','ultimate-member'), - 'PW' => __('Palau','ultimate-member'), - 'PS' => __('Palestine','ultimate-member'), - 'PA' => __('Panama','ultimate-member'), - 'PG' => __('Papua New Guinea','ultimate-member'), - 'PY' => __('Paraguay','ultimate-member'), - 'PE' => __('Peru','ultimate-member'), - 'PH' => __('Philippines','ultimate-member'), - 'PN' => __('Pitcairn','ultimate-member'), - 'PL' => __('Poland','ultimate-member'), - 'PT' => __('Portugal','ultimate-member'), - 'PR' => __('Puerto Rico','ultimate-member'), - 'QA' => __('Qatar','ultimate-member'), - 'RE' => __('Réunion','ultimate-member'), - 'RO' => __('Romania','ultimate-member'), - 'RU' => __('Russian Federation','ultimate-member'), - 'RW' => __('Rwanda','ultimate-member'), - 'BL' => __('Saint Barthélemy','ultimate-member'), - 'SH' => __('Saint Helena','ultimate-member'), - 'KN' => __('Saint Kitts and Nevis','ultimate-member'), - 'LC' => __('Saint Lucia','ultimate-member'), - 'MF' => __('Saint Martin (French part)','ultimate-member'), - 'PM' => __('Saint Pierre and Miquelon','ultimate-member'), - 'VC' => __('Saint Vincent and the Grenadines','ultimate-member'), - 'WS' => __('Samoa','ultimate-member'), - 'SM' => __('San Marino','ultimate-member'), - 'ST' => __('Sao Tome and Principe','ultimate-member'), - 'SA' => __('Saudi Arabia','ultimate-member'), - 'SN' => __('Senegal','ultimate-member'), - 'RS' => __('Serbia','ultimate-member'), - 'SC' => __('Seychelles','ultimate-member'), - 'SL' => __('Sierra Leone','ultimate-member'), - 'SG' => __('Singapore','ultimate-member'), - 'SK' => __('Slovakia','ultimate-member'), - 'SI' => __('Slovenia','ultimate-member'), - 'SB' => __('Solomon Islands','ultimate-member'), - 'SO' => __('Somalia','ultimate-member'), - 'ZA' => __('South Africa','ultimate-member'), - 'GS' => __('South Georgia and the South Sandwich Islands','ultimate-member'), - 'SS' => __('South Sudan','ultimate-member'), - 'ES' => __('Spain','ultimate-member'), - 'LK' => __('Sri Lanka','ultimate-member'), - 'SD' => __('Sudan','ultimate-member'), - 'SR' => __('Suriname','ultimate-member'), - 'SJ' => __('Svalbard and Jan Mayen','ultimate-member'), - 'SZ' => __('Swaziland','ultimate-member'), - 'SE' => __('Sweden','ultimate-member'), - 'CH' => __('Switzerland','ultimate-member'), - 'SY' => __('Syrian Arab Republic','ultimate-member'), - 'TW' => __('Taiwan, Province of China','ultimate-member'), - 'TJ' => __('Tajikistan','ultimate-member'), - 'TZ' => __('Tanzania, United Republic of','ultimate-member'), - 'TH' => __('Thailand','ultimate-member'), - 'TL' => __('Timor-Leste','ultimate-member'), - 'TG' => __('Togo','ultimate-member'), - 'TK' => __('Tokelau','ultimate-member'), - 'TO' => __('Tonga','ultimate-member'), - 'TT' => __('Trinidad and Tobago','ultimate-member'), - 'TN' => __('Tunisia','ultimate-member'), - 'TR' => __('Turkey','ultimate-member'), - 'TM' => __('Turkmenistan','ultimate-member'), - 'TC' => __('Turks and Caicos Islands','ultimate-member'), - 'TV' => __('Tuvalu','ultimate-member'), - 'UG' => __('Uganda','ultimate-member'), - 'UA' => __('Ukraine','ultimate-member'), - 'AE' => __('United Arab Emirates','ultimate-member'), - 'GB' => __('United Kingdom','ultimate-member'), - 'US' => __('United States','ultimate-member'), - 'UM' => __('United States Minor Outlying Islands','ultimate-member'), - 'UY' => __('Uruguay','ultimate-member'), - 'UZ' => __('Uzbekistan','ultimate-member'), - 'VU' => __('Vanuatu','ultimate-member'), - 'VE' => __('Venezuela, Bolivarian Republic of','ultimate-member'), - 'VN' => __('Viet Nam','ultimate-member'), - 'VG' => __('Virgin Islands, British','ultimate-member'), - 'VI' => __('Virgin Islands, U.S.','ultimate-member'), - 'WF' => __('Wallis and Futuna','ultimate-member'), - 'EH' => __('Western Sahara','ultimate-member'), - 'YE' => __('Yemen','ultimate-member'), - 'ZM' => __('Zambia','ultimate-member'), - 'ZW' => __('Zimbabwe','ultimate-member'), - ); - break; - - } - - /** - * UM hook - * - * @type filter - * @title um_{$data}_predefined_field_options - * @description Extend Predefined Fields options. Where $data - field key. - * @input_vars - * [{"var":"$options","type":"array","desc":"Field's Options"}] - * @change_log - * ["Since: 2.0"] - * @usage add_filter( 'um_{$data}_predefined_field_options', 'function_name', 10, 1 ); - * @example - * - */ - $array = apply_filters( "um_{$data}_predefined_field_options", $array ); - return $array; - } - - } + $um_roles = UM()->roles()->get_roles( false, $exclude_roles ); + + /** + * UM hook + * + * @type filter + * @title um_profile_privacy_options + * @description Profile Privacy Options + * @input_vars + * [{"var":"$privacy_options","type":"array","desc":"Privacy Options"}] + * @change_log + * ["Since: 2.0"] + * @usage add_filter( 'um_profile_privacy_options', 'function_name', 10, 1 ); + * @example + * + */ + $profile_privacy = apply_filters( 'um_profile_privacy_options', array( + __( 'Everyone', 'ultimate-member' ), + __( 'Only me', 'ultimate-member' ) + ) ); + + $this->predefined_fields = array( + + 'user_login' => array( + 'title' => __('Username','ultimate-member'), + 'metakey' => 'user_login', + 'type' => 'text', + 'label' => __('Username','ultimate-member'), + 'required' => 1, + 'public' => 1, + 'editable' => 0, + 'validate' => 'unique_username', + 'min_chars' => 3, + 'max_chars' => 24 + ), + + 'username' => array( + 'title' => __('Username or E-mail','ultimate-member'), + 'metakey' => 'username', + 'type' => 'text', + 'label' => __('Username or E-mail','ultimate-member'), + 'required' => 1, + 'public' => 1, + 'editable' => 0, + 'validate' => 'unique_username_or_email', + ), + + 'user_password' => array( + 'title' => __('Password','ultimate-member'), + 'metakey' => 'user_password', + 'type' => 'password', + 'label' => __('Password','ultimate-member'), + 'required' => 1, + 'public' => 1, + 'editable' => 1, + 'min_chars' => 8, + 'max_chars' => 30, + 'force_good_pass' => 1, + 'force_confirm_pass' => 1, + ), + + 'first_name' => array( + 'title' => __('First Name','ultimate-member'), + 'metakey' => 'first_name', + 'type' => 'text', + 'label' => __('First Name','ultimate-member'), + 'required' => 0, + 'public' => 1, + 'editable' => 1, + ), + + 'last_name' => array( + 'title' => __('Last Name','ultimate-member'), + 'metakey' => 'last_name', + 'type' => 'text', + 'label' => __('Last Name','ultimate-member'), + 'required' => 0, + 'public' => 1, + 'editable' => 1, + ), + + 'nickname' => array( + 'title' => __('Nickname','ultimate-member'), + 'metakey' => 'nickname', + 'type' => 'text', + 'label' => __('Nickname','ultimate-member'), + 'required' => 0, + 'public' => 1, + 'editable' => 1, + ), + + 'user_registered' => array( + 'title' => __('Registration Date','ultimate-member'), + 'metakey' => 'user_registered', + 'type' => 'text', + 'label' => __('Registration Date','ultimate-member'), + 'required' => 0, + 'public' => 1, + 'editable' => 1, + 'edit_forbidden' => 1, + ), + + 'last_login' => array( + 'title' => __('Last Login','ultimate-member'), + 'metakey' => '_um_last_login', + 'type' => 'text', + 'label' => __('Last Login','ultimate-member'), + 'required' => 0, + 'public' => 1, + 'editable' => 1, + 'edit_forbidden' => 1, + ), + + 'user_email' => array( + 'title' => __('E-mail Address','ultimate-member'), + 'metakey' => 'user_email', + 'type' => 'text', + 'label' => __('E-mail Address','ultimate-member'), + 'required' => 0, + 'public' => 1, + 'validate' => 'unique_email', + 'autocomplete' => 'off' + ), + + 'secondary_user_email' => array( + 'title' => __('Secondary E-mail Address','ultimate-member'), + 'metakey' => 'secondary_user_email', + 'type' => 'text', + 'label' => __('Secondary E-mail Address','ultimate-member'), + 'required' => 0, + 'public' => 1, + 'editable' => 1, + 'validate' => 'unique_email', + 'autocomplete' => 'off' + ), + + 'description' => array( + 'title' => __('Biography','ultimate-member'), + 'metakey' => 'description', + 'type' => 'textarea', + 'label' => __('Biography','ultimate-member'), + 'html' => 0, + 'required' => 0, + 'public' => 1, + 'editable' => 1, + 'max_words' => 40, + 'placeholder' => __('Enter a bit about yourself...','ultimate-member'), + ), + + 'birth_date' => array( + 'title' => __('Birth Date','ultimate-member'), + 'metakey' => 'birth_date', + 'type' => 'date', + 'label' => __('Birth Date','ultimate-member'), + 'required' => 0, + 'public' => 1, + 'editable' => 1, + 'pretty_format' => 1, + 'years' => 115, + 'years_x' => 'past', + 'icon' => 'um-faicon-calendar' + ), + + 'gender' => array( + 'title' => __('Gender','ultimate-member'), + 'metakey' => 'gender', + 'type' => 'radio', + 'label' => __('Gender','ultimate-member'), + 'required' => 0, + 'public' => 1, + 'editable' => 1, + 'options' => array( __('Male','ultimate-member'), __('Female','ultimate-member') ) + ), + + 'country' => array( + 'title' => __('Country','ultimate-member'), + 'metakey' => 'country', + 'type' => 'select', + 'label' => __('Country','ultimate-member'), + 'placeholder' => __('Choose a Country','ultimate-member'), + 'required' => 0, + 'public' => 1, + 'editable' => 1, + 'options' => $this->get('countries') + ), + + 'facebook' => array( + 'title' => __('Facebook','ultimate-member'), + 'metakey' => 'facebook', + 'type' => 'url', + 'label' => __('Facebook','ultimate-member'), + 'required' => 0, + 'public' => 1, + 'editable' => 1, + 'url_target' => '_blank', + 'url_rel' => 'nofollow', + 'icon' => 'um-faicon-facebook', + 'validate' => 'facebook_url', + 'url_text' => 'Facebook', + 'advanced' => 'social', + 'color' => '#3B5999', + 'match' => 'https://facebook.com/', + ), + + 'twitter' => array( + 'title' => __('Twitter','ultimate-member'), + 'metakey' => 'twitter', + 'type' => 'url', + 'label' => __('Twitter','ultimate-member'), + 'required' => 0, + 'public' => 1, + 'editable' => 1, + 'url_target' => '_blank', + 'url_rel' => 'nofollow', + 'icon' => 'um-faicon-twitter', + 'validate' => 'twitter_url', + 'url_text' => 'Twitter', + 'advanced' => 'social', + 'color' => '#4099FF', + 'match' => 'https://twitter.com/', + ), + + 'linkedin' => array( + 'title' => __('LinkedIn','ultimate-member'), + 'metakey' => 'linkedin', + 'type' => 'url', + 'label' => __('LinkedIn','ultimate-member'), + 'required' => 0, + 'public' => 1, + 'editable' => 1, + 'url_target' => '_blank', + 'url_rel' => 'nofollow', + 'icon' => 'um-faicon-linkedin', + 'validate' => 'linkedin_url', + 'url_text' => 'LinkedIn', + 'advanced' => 'social', + 'color' => '#0976b4', + 'match' => 'https://linkedin.com/in/', + ), + + 'googleplus' => array( + 'title' => __('Google+','ultimate-member'), + 'metakey' => 'googleplus', + 'type' => 'url', + 'label' => __('Google+','ultimate-member'), + 'required' => 0, + 'public' => 1, + 'editable' => 1, + 'url_target' => '_blank', + 'url_rel' => 'nofollow', + 'icon' => 'um-faicon-google-plus', + 'validate' => 'google_url', + 'url_text' => 'Google+', + 'advanced' => 'social', + 'color' => '#dd4b39', + 'match' => 'https://google.com/+', + ), + + 'instagram' => array( + 'title' => __('Instagram','ultimate-member'), + 'metakey' => 'instagram', + 'type' => 'url', + 'label' => __('Instagram','ultimate-member'), + 'required' => 0, + 'public' => 1, + 'editable' => 1, + 'url_target' => '_blank', + 'url_rel' => 'nofollow', + 'icon' => 'um-faicon-instagram', + 'validate' => 'instagram_url', + 'url_text' => 'Instagram', + 'advanced' => 'social', + 'color' => '#3f729b', + 'match' => 'https://instagram.com/', + ), + + 'skype' => array( + 'title' => __('Skype ID','ultimate-member'), + 'metakey' => 'skype', + 'type' => 'url', + 'label' => __('Skype ID','ultimate-member'), + 'required' => 0, + 'public' => 1, + 'editable' => 1, + 'url_target' => '_blank', + 'url_rel' => 'nofollow', + 'icon' => 'um-faicon-skype', + 'validate' => 'skype', + 'url_text' => 'Skype', + ), + + 'youtube' => array( + 'title' => __('YouTube','ultimate-member'), + 'metakey' => 'youtube', + 'type' => 'url', + 'label' => __('YouTube','ultimate-member'), + 'required' => 0, + 'public' => 1, + 'editable' => 1, + 'url_target' => '_blank', + 'url_rel' => 'nofollow', + 'icon' => 'um-faicon-youtube', + 'validate' => 'youtube_url', + 'url_text' => 'YouTube', + 'advanced' => 'social', + 'color' => '#e52d27', + 'match' => 'https://youtube.com/', + ), + + 'soundcloud' => array( + 'title' => __('SoundCloud','ultimate-member'), + 'metakey' => 'soundcloud', + 'type' => 'url', + 'label' => __('SoundCloud','ultimate-member'), + 'required' => 0, + 'public' => 1, + 'editable' => 1, + 'url_target' => '_blank', + 'url_rel' => 'nofollow', + 'icon' => 'um-faicon-soundcloud', + 'validate' => 'soundcloud_url', + 'url_text' => 'SoundCloud', + 'advanced' => 'social', + 'color' => '#f50', + 'match' => 'https://soundcloud.com/', + ), + + 'vk' => array( + 'title' => __('VKontakte','ultimate-member'), + 'metakey' => 'vkontakte', + 'type' => 'url', + 'label' => __('VKontakte','ultimate-member'), + 'required' => 0, + 'public' => 1, + 'editable' => 1, + 'url_target' => '_blank', + 'url_rel' => 'nofollow', + 'icon' => 'um-faicon-vk', + 'validate' => 'vk_url', + 'url_text' => 'VKontakte', + 'advanced' => 'social', + 'color' => '#2B587A', + 'match' => 'https://vk.com/', + ), + + 'role_select' => array( + 'title' => __('Roles (Dropdown)','ultimate-member'), + 'metakey' => 'role_select', + 'type' => 'select', + 'label' => __('Account Type','ultimate-member'), + 'placeholder' => 'Choose account type', + 'required' => 0, + 'public' => 1, + 'editable' => 1, + 'options' => $um_roles, + ), + + 'role_radio' => array( + 'title' => __('Roles (Radio)','ultimate-member'), + 'metakey' => 'role_radio', + 'type' => 'radio', + 'label' => __('Account Type','ultimate-member'), + 'required' => 0, + 'public' => 1, + 'editable' => 1, + 'options' => $um_roles, + ), + + 'languages' => array( + 'title' => __('Languages','ultimate-member'), + 'metakey' => 'languages', + 'type' => 'multiselect', + 'label' => __('Languages Spoken','ultimate-member'), + 'placeholder' => __('Select languages','ultimate-member'), + 'required' => 0, + 'public' => 1, + 'editable' => 1, + 'options' => $this->get('languages'), + ), + + 'phone_number' => array( + 'title' => __('Phone Number','ultimate-member'), + 'metakey' => 'phone_number', + 'type' => 'text', + 'label' => __('Phone Number','ultimate-member'), + 'required' => 0, + 'public' => 1, + 'editable' => 1, + 'validate' => 'phone_number', + 'icon' => 'um-faicon-phone', + ), + + 'mobile_number' => array( + 'title' => __('Mobile Number','ultimate-member'), + 'metakey' => 'mobile_number', + 'type' => 'text', + 'label' => __('Mobile Number','ultimate-member'), + 'required' => 0, + 'public' => 1, + 'editable' => 1, + 'validate' => 'phone_number', + 'icon' => 'um-faicon-mobile', + ), + + // private use ( not public list ) + + 'profile_photo' => array( + 'title' => __('Profile Photo','ultimate-member'), + 'metakey' => 'profile_photo', + 'type' => 'image', + 'label' => __('Change your profile photo','ultimate-member'), + 'upload_text' => __('Upload your photo here','ultimate-member'), + 'icon' => 'um-faicon-camera', + 'crop' => 1, + 'max_size' => ( UM()->options()->get('profile_photo_max_size') ) ? UM()->options()->get('profile_photo_max_size') : 999999999, + 'min_width' => str_replace('px','',UM()->options()->get('profile_photosize')), + 'min_height' => str_replace('px','',UM()->options()->get('profile_photosize')), + 'private_use' => true, + ), + + 'cover_photo' => array( + 'title' => __('Cover Photo','ultimate-member'), + 'metakey' => 'cover_photo', + 'type' => 'image', + 'label' => __('Change your cover photo','ultimate-member'), + 'upload_text' => __('Upload profile cover here','ultimate-member'), + 'icon' => 'um-faicon-picture-o', + 'crop' => 2, + 'max_size' => ( UM()->options()->get('cover_photo_max_size') ) ? UM()->options()->get('cover_photo_max_size') : 999999999, + 'modal_size' => 'large', + 'ratio' => str_replace(':1','',UM()->options()->get('profile_cover_ratio')), + 'min_width' => UM()->options()->get('cover_min_width'), + 'private_use' => true, + ), + + 'password_reset_text' => array( + 'title' => __('Password Reset','ultimate-member'), + 'type' => 'block', + 'content' => '
' . __('To reset your password, please enter your email address or username below','ultimate-member'). '
', + 'private_use' => true, + ), + + 'username_b' => array( + 'title' => __('Username or E-mail','ultimate-member'), + 'metakey' => 'username_b', + 'type' => 'text', + 'placeholder' => __('Enter your username or email','ultimate-member'), + 'required' => 1, + 'public' => 1, + 'editable' => 0, + 'private_use' => true, + ), + + // account page use ( not public ) + + 'profile_privacy' => array( + 'title' => __('Profile Privacy','ultimate-member'), + 'metakey' => 'profile_privacy', + 'type' => 'select', + 'label' => __('Profile Privacy','ultimate-member'), + 'help' => __('Who can see your public profile?','ultimate-member'), + 'required' => 0, + 'public' => 1, + 'editable' => 1, + 'default' => __('Everyone','ultimate-member'), + 'options' => $profile_privacy, + 'allowclear' => 0, + 'account_only' => true, + 'required_perm' => 'can_make_private_profile', + ), + + 'hide_in_members' => array( + 'title' => __('Hide my profile from directory','ultimate-member'), + 'metakey' => 'hide_in_members', + 'type' => 'radio', + 'label' => __('Hide my profile from directory','ultimate-member'), + 'help' => __('Here you can hide yourself from appearing in public directory','ultimate-member'), + 'required' => 0, + 'public' => 1, + 'editable' => 1, + 'default' => 'No', + 'options' => array( 'No' => __('No','ultimate-member'), 'Yes' => __('Yes','ultimate-member') ), + 'account_only' => true, + 'required_opt' => array( 'members_page', 1 ), + ), + + 'delete_account' => array( + 'title' => __('Delete Account','ultimate-member'), + 'metakey' => 'delete_account', + 'type' => 'radio', + 'label' => __('Delete Account','ultimate-member'), + 'help' => __('If you confirm, everything related to your profile will be deleted permanently from the site','ultimate-member'), + 'required' => 0, + 'public' => 1, + 'editable' => 1, + 'default' => __('No','ultimate-member'), + 'options' => array( __('Yes','ultimate-member') , __('No','ultimate-member') ), + 'account_only' => true, + ), + + 'single_user_password' => array( + 'title' => __('Password','ultimate-member'), + 'metakey' => 'single_user_password', + 'type' => 'password', + 'label' => __('Password','ultimate-member'), + 'required' => 1, + 'public' => 1, + 'editable' => 1, + 'account_only' => true, + ), + + ); + + /** + * UM hook + * + * @type filter + * @title um_predefined_fields_hook + * @description Extend Predefined Fields + * @input_vars + * [{"var":"$predefined_fields","type":"array","desc":"Predefined Fields"}] + * @change_log + * ["Since: 2.0"] + * @usage add_filter( 'um_predefined_fields_hook', 'function_name', 10, 1 ); + * @example + * + */ + $this->predefined_fields = apply_filters( 'um_predefined_fields_hook', $this->predefined_fields ); + } + + + /** + * Custom Fields + */ + function set_custom_fields() { + + if ( is_array( $this->saved_fields ) ) { + + $this->custom_fields = $this->saved_fields; + + } else { + + $this->custom_fields = ''; + + } + + $custom = $this->custom_fields; + $predefined = $this->predefined_fields; + + if ( is_array( $custom ) ){ + $this->all_user_fields = array_merge( $predefined, $custom ); + } else { + $this->all_user_fields = $predefined; + } + + } + + + /** + * May be used to show a dropdown, or source for user meta + * + * @param null $exclude_types + * @param bool $show_all + * + * @return array + */ + function all_user_fields( $exclude_types = null, $show_all = false ) { + + $fields_without_metakey = array('block','shortcode','spacing','divider','group'); + remove_filter('um_fields_without_metakey', 'um_user_tags_requires_no_metakey'); + + /** + * UM hook + * + * @type filter + * @title um_fields_without_metakey + * @description Extend Fields without metakey + * @input_vars + * [{"var":"$fields","type":"array","desc":"Fields without metakey"}] + * @change_log + * ["Since: 2.0"] + * @usage add_filter( 'um_fields_without_metakey', 'function_name', 10, 1 ); + * @example + * + */ + $fields_without_metakey = apply_filters( 'um_fields_without_metakey', $fields_without_metakey ); + + if ( !$show_all ) { + $this->fields_dropdown = array('image','file','password','rating'); + $this->fields_dropdown = array_merge( $this->fields_dropdown, $fields_without_metakey ); + } else { + $this->fields_dropdown = $fields_without_metakey; + } + + $custom = $this->custom_fields; + $predefined = $this->predefined_fields; + + if ( $exclude_types ) { + $exclude_types = explode(',', $exclude_types); + } + + $all = array( 0 => '' ); + + if ( is_array( $custom ) ){ + $all = $all + array_merge( $predefined, $custom ); + } else { + $all = $all + $predefined; + } + + foreach( $all as $k => $arr ) { + + if ( $k == 0 ) { + unset($all[$k]); + } + + if ( isset( $arr['title'] ) ){ + $all[$k]['title'] = stripslashes( $arr['title'] ); + } + + if ( $exclude_types && isset( $arr['type'] ) && in_array( $arr['type'], $exclude_types ) ) { + unset( $all[$k] ); + } + if ( isset( $arr['account_only'] ) || isset( $arr['private_use'] ) ) { + if ( !$show_all ) { + unset( $all[$k] ); + } + } + if ( isset( $arr['type'] ) && in_array( $arr['type'], $this->fields_dropdown ) ) { + unset( $all[$k] ); + } + } + + $all = UM()->fields()->array_sort_by_column( $all, 'title'); + + $all = array( 0 => '') + $all; + + return $all; + } + + + /** + * Possible validation types for fields + * + * @return mixed + */ + function validation_types() { + + $array[0] = __('None','ultimate-member'); + $array['alphabetic'] = __('Alphabetic value only','ultimate-member'); + $array['alpha_numeric'] = __('Alpha-numeric value','ultimate-member'); + $array['english'] = __('English letters only','ultimate-member'); + $array['facebook_url'] = __('Facebook URL','ultimate-member'); + $array['google_url'] = __('Google+ URL','ultimate-member'); + $array['instagram_url'] = __('Instagram URL','ultimate-member'); + $array['linkedin_url'] = __('LinkedIn URL','ultimate-member'); + $array['vk_url'] = __('VKontakte URL','ultimate-member'); + $array['lowercase'] = __('Lowercase only','ultimate-member'); + $array['numeric'] = __('Numeric value only','ultimate-member'); + $array['phone_number'] = __('Phone Number','ultimate-member'); + $array['skype'] = __('Skype ID','ultimate-member'); + $array['soundcloud'] = __('SoundCloud Profile','ultimate-member'); + $array['twitter_url'] = __('Twitter URL','ultimate-member'); + $array['unique_email'] = __('Unique E-mail','ultimate-member'); + $array['unique_value'] = __('Unique Metakey value','ultimate-member'); + $array['unique_username'] = __('Unique Username','ultimate-member'); + $array['unique_username_or_email'] = __('Unique Username/E-mail','ultimate-member'); + $array['url'] = __('Website URL','ultimate-member'); + $array['youtube_url'] = __('YouTube Profile','ultimate-member'); + $array['custom'] = __('Custom Validation','ultimate-member'); + + /** + * UM hook + * + * @type filter + * @title um_admin_field_validation_hook + * @description Extend validation types + * @input_vars + * [{"var":"$types","type":"array","desc":"Validation Types"}] + * @change_log + * ["Since: 2.0"] + * @usage add_filter( 'um_admin_field_validation_hook', 'function_name', 10, 1 ); + * @example + * + */ + $array = apply_filters( 'um_admin_field_validation_hook', $array ); + return $array; + } + + + /** + * Get predefined options + * + * @param $data + * + * @return array|mixed|void + */ + function get( $data ) { + switch ( $data ) { + + case 'languages': + $array = array( + "aa" => __("Afar",'ultimate-member'), + "ab" => __("Abkhazian",'ultimate-member'), + "ae" => __("Avestan",'ultimate-member'), + "af" => __("Afrikaans",'ultimate-member'), + "ak" => __("Akan",'ultimate-member'), + "am" => __("Amharic",'ultimate-member'), + "an" => __("Aragonese",'ultimate-member'), + "ar" => __("Arabic",'ultimate-member'), + "as" => __("Assamese",'ultimate-member'), + "av" => __("Avaric",'ultimate-member'), + "ay" => __("Aymara",'ultimate-member'), + "az" => __("Azerbaijani",'ultimate-member'), + "ba" => __("Bashkir",'ultimate-member'), + "be" => __("Belarusian",'ultimate-member'), + "bg" => __("Bulgarian",'ultimate-member'), + "bh" => __("Bihari",'ultimate-member'), + "bi" => __("Bislama",'ultimate-member'), + "bm" => __("Bambara",'ultimate-member'), + "bn" => __("Bengali",'ultimate-member'), + "bo" => __("Tibetan",'ultimate-member'), + "br" => __("Breton",'ultimate-member'), + "bs" => __("Bosnian",'ultimate-member'), + "ca" => __("Catalan",'ultimate-member'), + "ce" => __("Chechen",'ultimate-member'), + "ch" => __("Chamorro",'ultimate-member'), + "co" => __("Corsican",'ultimate-member'), + "cr" => __("Cree",'ultimate-member'), + "cs" => __("Czech",'ultimate-member'), + "cu" => __("Church Slavic",'ultimate-member'), + "cv" => __("Chuvash",'ultimate-member'), + "cy" => __("Welsh",'ultimate-member'), + "da" => __("Danish",'ultimate-member'), + "de" => __("German",'ultimate-member'), + "dv" => __("Divehi",'ultimate-member'), + "dz" => __("Dzongkha",'ultimate-member'), + "ee" => __("Ewe",'ultimate-member'), + "el" => __("Greek",'ultimate-member'), + "en" => __("English",'ultimate-member'), + "eo" => __("Esperanto",'ultimate-member'), + "es" => __("Spanish",'ultimate-member'), + "et" => __("Estonian",'ultimate-member'), + "eu" => __("Basque",'ultimate-member'), + "fa" => __("Persian",'ultimate-member'), + "ff" => __("Fulah",'ultimate-member'), + "fi" => __("Finnish",'ultimate-member'), + "fj" => __("Fijian",'ultimate-member'), + "fo" => __("Faroese",'ultimate-member'), + "fr" => __("French",'ultimate-member'), + "fy" => __("Western Frisian",'ultimate-member'), + "ga" => __("Irish",'ultimate-member'), + "gd" => __("Scottish Gaelic",'ultimate-member'), + "gl" => __("Galician",'ultimate-member'), + "gn" => __("Guarani",'ultimate-member'), + "gu" => __("Gujarati",'ultimate-member'), + "gv" => __("Manx",'ultimate-member'), + "ha" => __("Hausa",'ultimate-member'), + "he" => __("Hebrew",'ultimate-member'), + "hi" => __("Hindi",'ultimate-member'), + "ho" => __("Hiri Motu",'ultimate-member'), + "hr" => __("Croatian",'ultimate-member'), + "ht" => __("Haitian",'ultimate-member'), + "hu" => __("Hungarian",'ultimate-member'), + "hy" => __("Armenian",'ultimate-member'), + "hz" => __("Herero",'ultimate-member'), + "ia" => __("Interlingua (International Auxiliary Language Association)",'ultimate-member'), + "id" => __("Indonesian",'ultimate-member'), + "ie" => __("Interlingue",'ultimate-member'), + "ig" => __("Igbo",'ultimate-member'), + "ii" => __("Sichuan Yi",'ultimate-member'), + "ik" => __("Inupiaq",'ultimate-member'), + "io" => __("Ido",'ultimate-member'), + "is" => __("Icelandic",'ultimate-member'), + "it" => __("Italian",'ultimate-member'), + "iu" => __("Inuktitut",'ultimate-member'), + "ja" => __("Japanese",'ultimate-member'), + "jv" => __("Javanese",'ultimate-member'), + "ka" => __("Georgian",'ultimate-member'), + "kg" => __("Kongo",'ultimate-member'), + "ki" => __("Kikuyu",'ultimate-member'), + "kj" => __("Kwanyama",'ultimate-member'), + "kk" => __("Kazakh",'ultimate-member'), + "kl" => __("Kalaallisut",'ultimate-member'), + "km" => __("Khmer",'ultimate-member'), + "kn" => __("Kannada",'ultimate-member'), + "ko" => __("Korean",'ultimate-member'), + "kr" => __("Kanuri",'ultimate-member'), + "ks" => __("Kashmiri",'ultimate-member'), + "ku" => __("Kurdish",'ultimate-member'), + "kv" => __("Komi",'ultimate-member'), + "kw" => __("Cornish",'ultimate-member'), + "ky" => __("Kirghiz",'ultimate-member'), + "la" => __("Latin",'ultimate-member'), + "lb" => __("Luxembourgish",'ultimate-member'), + "lg" => __("Ganda",'ultimate-member'), + "li" => __("Limburgish",'ultimate-member'), + "ln" => __("Lingala",'ultimate-member'), + "lo" => __("Lao",'ultimate-member'), + "lt" => __("Lithuanian",'ultimate-member'), + "lu" => __("Luba-Katanga",'ultimate-member'), + "lv" => __("Latvian",'ultimate-member'), + "mg" => __("Malagasy",'ultimate-member'), + "mh" => __("Marshallese",'ultimate-member'), + "mi" => __("Maori",'ultimate-member'), + "mk" => __("Macedonian",'ultimate-member'), + "ml" => __("Malayalam",'ultimate-member'), + "mn" => __("Mongolian",'ultimate-member'), + "mr" => __("Marathi",'ultimate-member'), + "ms" => __("Malay",'ultimate-member'), + "mt" => __("Maltese",'ultimate-member'), + "my" => __("Burmese",'ultimate-member'), + "na" => __("Nauru",'ultimate-member'), + "nb" => __("Norwegian Bokmal",'ultimate-member'), + "nd" => __("North Ndebele",'ultimate-member'), + "ne" => __("Nepali",'ultimate-member'), + "ng" => __("Ndonga",'ultimate-member'), + "nl" => __("Dutch",'ultimate-member'), + "nn" => __("Norwegian Nynorsk",'ultimate-member'), + "no" => __("Norwegian",'ultimate-member'), + "nr" => __("South Ndebele",'ultimate-member'), + "nv" => __("Navajo",'ultimate-member'), + "ny" => __("Chichewa",'ultimate-member'), + "oc" => __("Occitan",'ultimate-member'), + "oj" => __("Ojibwa",'ultimate-member'), + "om" => __("Oromo",'ultimate-member'), + "or" => __("Oriya",'ultimate-member'), + "os" => __("Ossetian",'ultimate-member'), + "pa" => __("Panjabi",'ultimate-member'), + "pi" => __("Pali",'ultimate-member'), + "pl" => __("Polish",'ultimate-member'), + "ps" => __("Pashto",'ultimate-member'), + "pt" => __("Portuguese",'ultimate-member'), + "qu" => __("Quechua",'ultimate-member'), + "rm" => __("Raeto-Romance",'ultimate-member'), + "rn" => __("Kirundi",'ultimate-member'), + "ro" => __("Romanian",'ultimate-member'), + "ru" => __("Russian",'ultimate-member'), + "rw" => __("Kinyarwanda",'ultimate-member'), + "sa" => __("Sanskrit",'ultimate-member'), + "sc" => __("Sardinian",'ultimate-member'), + "sd" => __("Sindhi",'ultimate-member'), + "se" => __("Northern Sami",'ultimate-member'), + "sg" => __("Sango",'ultimate-member'), + "si" => __("Sinhala",'ultimate-member'), + "sk" => __("Slovak",'ultimate-member'), + "sl" => __("Slovenian",'ultimate-member'), + "sm" => __("Samoan",'ultimate-member'), + "sn" => __("Shona",'ultimate-member'), + "so" => __("Somali",'ultimate-member'), + "sq" => __("Albanian",'ultimate-member'), + "sr" => __("Serbian",'ultimate-member'), + "ss" => __("Swati",'ultimate-member'), + "st" => __("Southern Sotho",'ultimate-member'), + "su" => __("Sundanese",'ultimate-member'), + "sv" => __("Swedish",'ultimate-member'), + "sw" => __("Swahili",'ultimate-member'), + "ta" => __("Tamil",'ultimate-member'), + "te" => __("Telugu",'ultimate-member'), + "tg" => __("Tajik",'ultimate-member'), + "th" => __("Thai",'ultimate-member'), + "ti" => __("Tigrinya",'ultimate-member'), + "tk" => __("Turkmen",'ultimate-member'), + "tl" => __("Tagalog",'ultimate-member'), + "tn" => __("Tswana",'ultimate-member'), + "to" => __("Tonga",'ultimate-member'), + "tr" => __("Turkish",'ultimate-member'), + "ts" => __("Tsonga",'ultimate-member'), + "tt" => __("Tatar",'ultimate-member'), + "tw" => __("Twi",'ultimate-member'), + "ty" => __("Tahitian",'ultimate-member'), + "ug" => __("Uighur",'ultimate-member'), + "uk" => __("Ukrainian",'ultimate-member'), + "ur" => __("Urdu",'ultimate-member'), + "uz" => __("Uzbek",'ultimate-member'), + "ve" => __("Venda",'ultimate-member'), + "vi" => __("Vietnamese",'ultimate-member'), + "vo" => __("Volapuk",'ultimate-member'), + "wa" => __("Walloon",'ultimate-member'), + "wo" => __("Wolof",'ultimate-member'), + "xh" => __("Xhosa",'ultimate-member'), + "yi" => __("Yiddish",'ultimate-member'), + "yo" => __("Yoruba",'ultimate-member'), + "za" => __("Zhuang",'ultimate-member'), + "zh" => __("Chinese",'ultimate-member'), + "zu" => __("Zulu",'ultimate-member') + ); + break; + + case 'countries': + $array = array ( + 'AF' => __('Afghanistan','ultimate-member'), + 'AX' => __('Åland Islands','ultimate-member'), + 'AL' => __('Albania','ultimate-member'), + 'DZ' => __('Algeria','ultimate-member'), + 'AS' => __('American Samoa','ultimate-member'), + 'AD' => __('Andorra','ultimate-member'), + 'AO' => __('Angola','ultimate-member'), + 'AI' => __('Anguilla','ultimate-member'), + 'AQ' => __('Antarctica','ultimate-member'), + 'AG' => __('Antigua and Barbuda','ultimate-member'), + 'AR' => __('Argentina','ultimate-member'), + 'AM' => __('Armenia','ultimate-member'), + 'AW' => __('Aruba','ultimate-member'), + 'AU' => __('Australia','ultimate-member'), + 'AT' => __('Austria','ultimate-member'), + 'AZ' => __('Azerbaijan','ultimate-member'), + 'BS' => __('Bahamas','ultimate-member'), + 'BH' => __('Bahrain','ultimate-member'), + 'BD' => __('Bangladesh','ultimate-member'), + 'BB' => __('Barbados','ultimate-member'), + 'BY' => __('Belarus','ultimate-member'), + 'BE' => __('Belgium','ultimate-member'), + 'BZ' => __('Belize','ultimate-member'), + 'BJ' => __('Benin','ultimate-member'), + 'BM' => __('Bermuda','ultimate-member'), + 'BT' => __('Bhutan','ultimate-member'), + 'BO' => __('Bolivia, Plurinational State of','ultimate-member'), + 'BA' => __('Bosnia and Herzegovina','ultimate-member'), + 'BW' => __('Botswana','ultimate-member'), + 'BV' => __('Bouvet Island','ultimate-member'), + 'BR' => __('Brazil','ultimate-member'), + 'IO' => __('British Indian Ocean Territory','ultimate-member'), + 'BN' => __('Brunei Darussalam','ultimate-member'), + 'BG' => __('Bulgaria','ultimate-member'), + 'BF' => __('Burkina Faso','ultimate-member'), + 'BI' => __('Burundi','ultimate-member'), + 'KH' => __('Cambodia','ultimate-member'), + 'CM' => __('Cameroon','ultimate-member'), + 'CA' => __('Canada','ultimate-member'), + 'CV' => __('Cape Verde','ultimate-member'), + 'KY' => __('Cayman Islands','ultimate-member'), + 'CF' => __('Central African Republic','ultimate-member'), + 'TD' => __('Chad','ultimate-member'), + 'CL' => __('Chile','ultimate-member'), + 'CN' => __('China','ultimate-member'), + 'CX' => __('Christmas Island','ultimate-member'), + 'CC' => __('Cocos (Keeling) Islands','ultimate-member'), + 'CO' => __('Colombia','ultimate-member'), + 'KM' => __('Comoros','ultimate-member'), + 'CG' => __('Congo','ultimate-member'), + 'CD' => __('Congo, the Democratic Republic of the','ultimate-member'), + 'CK' => __('Cook Islands','ultimate-member'), + 'CR' => __('Costa Rica','ultimate-member'), + 'CI' => __("Côte d'Ivoire",'ultimate-member'), + 'HR' => __('Croatia','ultimate-member'), + 'CU' => __('Cuba','ultimate-member'), + 'CY' => __('Cyprus','ultimate-member'), + 'CZ' => __('Czech Republic','ultimate-member'), + 'DK' => __('Denmark','ultimate-member'), + 'DJ' => __('Djibouti','ultimate-member'), + 'DM' => __('Dominica','ultimate-member'), + 'DO' => __('Dominican Republic','ultimate-member'), + 'EC' => __('Ecuador','ultimate-member'), + 'EG' => __('Egypt','ultimate-member'), + 'SV' => __('El Salvador','ultimate-member'), + 'GQ' => __('Equatorial Guinea','ultimate-member'), + 'ER' => __('Eritrea','ultimate-member'), + 'EE' => __('Estonia','ultimate-member'), + 'ET' => __('Ethiopia','ultimate-member'), + 'FK' => __('Falkland Islands (Malvinas)','ultimate-member'), + 'FO' => __('Faroe Islands','ultimate-member'), + 'FJ' => __('Fiji','ultimate-member'), + 'FI' => __('Finland','ultimate-member'), + 'FR' => __('France','ultimate-member'), + 'GF' => __('French Guiana','ultimate-member'), + 'PF' => __('French Polynesia','ultimate-member'), + 'TF' => __('French Southern Territories','ultimate-member'), + 'GA' => __('Gabon','ultimate-member'), + 'GM' => __('Gambia','ultimate-member'), + 'GE' => __('Georgia','ultimate-member'), + 'DE' => __('Germany','ultimate-member'), + 'GH' => __('Ghana','ultimate-member'), + 'GI' => __('Gibraltar','ultimate-member'), + 'GR' => __('Greece','ultimate-member'), + 'GL' => __('Greenland','ultimate-member'), + 'GD' => __('Grenada','ultimate-member'), + 'GP' => __('Guadeloupe','ultimate-member'), + 'GU' => __('Guam','ultimate-member'), + 'GT' => __('Guatemala','ultimate-member'), + 'GG' => __('Guernsey','ultimate-member'), + 'GN' => __('Guinea','ultimate-member'), + 'GW' => __('Guinea-Bissau','ultimate-member'), + 'GY' => __('Guyana','ultimate-member'), + 'HT' => __('Haiti','ultimate-member'), + 'HM' => __('Heard Island and McDonald Islands','ultimate-member'), + 'VA' => __('Holy See (Vatican City State)','ultimate-member'), + 'HN' => __('Honduras','ultimate-member'), + 'HK' => __('Hong Kong','ultimate-member'), + 'HU' => __('Hungary','ultimate-member'), + 'IS' => __('Iceland','ultimate-member'), + 'IN' => __('India','ultimate-member'), + 'ID' => __('Indonesia','ultimate-member'), + 'IR' => __('Iran, Islamic Republic of','ultimate-member'), + 'IQ' => __('Iraq','ultimate-member'), + 'IE' => __('Ireland','ultimate-member'), + 'IM' => __('Isle of Man','ultimate-member'), + 'IL' => __('Israel','ultimate-member'), + 'IT' => __('Italy','ultimate-member'), + 'JM' => __('Jamaica','ultimate-member'), + 'JP' => __('Japan','ultimate-member'), + 'JE' => __('Jersey','ultimate-member'), + 'JO' => __('Jordan','ultimate-member'), + 'KZ' => __('Kazakhstan','ultimate-member'), + 'KE' => __('Kenya','ultimate-member'), + 'KI' => __('Kiribati','ultimate-member'), + 'KP' => __("Korea, Democratic People's Republic of",'ultimate-member'), + 'KR' => __('Korea, Republic of','ultimate-member'), + 'KW' => __('Kuwait','ultimate-member'), + 'KG' => __('Kyrgyzstan','ultimate-member'), + 'LA' => __("Lao People's Democratic Republic",'ultimate-member'), + 'LV' => __('Latvia','ultimate-member'), + 'LB' => __('Lebanon','ultimate-member'), + 'LS' => __('Lesotho','ultimate-member'), + 'LR' => __('Liberia','ultimate-member'), + 'LY' => __('Libyan Arab Jamahiriya','ultimate-member'), + 'LI' => __('Liechtenstein','ultimate-member'), + 'LT' => __('Lithuania','ultimate-member'), + 'LU' => __('Luxembourg','ultimate-member'), + 'MO' => __('Macao','ultimate-member'), + 'MK' => __('Macedonia, the former Yugoslav Republic of','ultimate-member'), + 'MG' => __('Madagascar','ultimate-member'), + 'MW' => __('Malawi','ultimate-member'), + 'MY' => __('Malaysia','ultimate-member'), + 'MV' => __('Maldives','ultimate-member'), + 'ML' => __('Mali','ultimate-member'), + 'MT' => __('Malta','ultimate-member'), + 'MH' => __('Marshall Islands','ultimate-member'), + 'MQ' => __('Martinique','ultimate-member'), + 'MR' => __('Mauritania','ultimate-member'), + 'MU' => __('Mauritius','ultimate-member'), + 'YT' => __('Mayotte','ultimate-member'), + 'MX' => __('Mexico','ultimate-member'), + 'FM' => __('Micronesia, Federated States of','ultimate-member'), + 'MD' => __('Moldova, Republic of','ultimate-member'), + 'MC' => __('Monaco','ultimate-member'), + 'MN' => __('Mongolia','ultimate-member'), + 'ME' => __('Montenegro','ultimate-member'), + 'MS' => __('Montserrat','ultimate-member'), + 'MA' => __('Morocco','ultimate-member'), + 'MZ' => __('Mozambique','ultimate-member'), + 'MM' => __('Myanmar','ultimate-member'), + 'NA' => __('Namibia','ultimate-member'), + 'NR' => __('Nauru','ultimate-member'), + 'NP' => __('Nepal','ultimate-member'), + 'NL' => __('Netherlands','ultimate-member'), + 'AN' => __('Netherlands Antilles','ultimate-member'), + 'NC' => __('New Caledonia','ultimate-member'), + 'NZ' => __('New Zealand','ultimate-member'), + 'NI' => __('Nicaragua','ultimate-member'), + 'NE' => __('Niger','ultimate-member'), + 'NG' => __('Nigeria','ultimate-member'), + 'NU' => __('Niue','ultimate-member'), + 'NF' => __('Norfolk Island','ultimate-member'), + 'MP' => __('Northern Mariana Islands','ultimate-member'), + 'NO' => __('Norway','ultimate-member'), + 'OM' => __('Oman','ultimate-member'), + 'PK' => __('Pakistan','ultimate-member'), + 'PW' => __('Palau','ultimate-member'), + 'PS' => __('Palestine','ultimate-member'), + 'PA' => __('Panama','ultimate-member'), + 'PG' => __('Papua New Guinea','ultimate-member'), + 'PY' => __('Paraguay','ultimate-member'), + 'PE' => __('Peru','ultimate-member'), + 'PH' => __('Philippines','ultimate-member'), + 'PN' => __('Pitcairn','ultimate-member'), + 'PL' => __('Poland','ultimate-member'), + 'PT' => __('Portugal','ultimate-member'), + 'PR' => __('Puerto Rico','ultimate-member'), + 'QA' => __('Qatar','ultimate-member'), + 'RE' => __('Réunion','ultimate-member'), + 'RO' => __('Romania','ultimate-member'), + 'RU' => __('Russian Federation','ultimate-member'), + 'RW' => __('Rwanda','ultimate-member'), + 'BL' => __('Saint Barthélemy','ultimate-member'), + 'SH' => __('Saint Helena','ultimate-member'), + 'KN' => __('Saint Kitts and Nevis','ultimate-member'), + 'LC' => __('Saint Lucia','ultimate-member'), + 'MF' => __('Saint Martin (French part)','ultimate-member'), + 'PM' => __('Saint Pierre and Miquelon','ultimate-member'), + 'VC' => __('Saint Vincent and the Grenadines','ultimate-member'), + 'WS' => __('Samoa','ultimate-member'), + 'SM' => __('San Marino','ultimate-member'), + 'ST' => __('Sao Tome and Principe','ultimate-member'), + 'SA' => __('Saudi Arabia','ultimate-member'), + 'SN' => __('Senegal','ultimate-member'), + 'RS' => __('Serbia','ultimate-member'), + 'SC' => __('Seychelles','ultimate-member'), + 'SL' => __('Sierra Leone','ultimate-member'), + 'SG' => __('Singapore','ultimate-member'), + 'SK' => __('Slovakia','ultimate-member'), + 'SI' => __('Slovenia','ultimate-member'), + 'SB' => __('Solomon Islands','ultimate-member'), + 'SO' => __('Somalia','ultimate-member'), + 'ZA' => __('South Africa','ultimate-member'), + 'GS' => __('South Georgia and the South Sandwich Islands','ultimate-member'), + 'SS' => __('South Sudan','ultimate-member'), + 'ES' => __('Spain','ultimate-member'), + 'LK' => __('Sri Lanka','ultimate-member'), + 'SD' => __('Sudan','ultimate-member'), + 'SR' => __('Suriname','ultimate-member'), + 'SJ' => __('Svalbard and Jan Mayen','ultimate-member'), + 'SZ' => __('Swaziland','ultimate-member'), + 'SE' => __('Sweden','ultimate-member'), + 'CH' => __('Switzerland','ultimate-member'), + 'SY' => __('Syrian Arab Republic','ultimate-member'), + 'TW' => __('Taiwan, Province of China','ultimate-member'), + 'TJ' => __('Tajikistan','ultimate-member'), + 'TZ' => __('Tanzania, United Republic of','ultimate-member'), + 'TH' => __('Thailand','ultimate-member'), + 'TL' => __('Timor-Leste','ultimate-member'), + 'TG' => __('Togo','ultimate-member'), + 'TK' => __('Tokelau','ultimate-member'), + 'TO' => __('Tonga','ultimate-member'), + 'TT' => __('Trinidad and Tobago','ultimate-member'), + 'TN' => __('Tunisia','ultimate-member'), + 'TR' => __('Turkey','ultimate-member'), + 'TM' => __('Turkmenistan','ultimate-member'), + 'TC' => __('Turks and Caicos Islands','ultimate-member'), + 'TV' => __('Tuvalu','ultimate-member'), + 'UG' => __('Uganda','ultimate-member'), + 'UA' => __('Ukraine','ultimate-member'), + 'AE' => __('United Arab Emirates','ultimate-member'), + 'GB' => __('United Kingdom','ultimate-member'), + 'US' => __('United States','ultimate-member'), + 'UM' => __('United States Minor Outlying Islands','ultimate-member'), + 'UY' => __('Uruguay','ultimate-member'), + 'UZ' => __('Uzbekistan','ultimate-member'), + 'VU' => __('Vanuatu','ultimate-member'), + 'VE' => __('Venezuela, Bolivarian Republic of','ultimate-member'), + 'VN' => __('Viet Nam','ultimate-member'), + 'VG' => __('Virgin Islands, British','ultimate-member'), + 'VI' => __('Virgin Islands, U.S.','ultimate-member'), + 'WF' => __('Wallis and Futuna','ultimate-member'), + 'EH' => __('Western Sahara','ultimate-member'), + 'YE' => __('Yemen','ultimate-member'), + 'ZM' => __('Zambia','ultimate-member'), + 'ZW' => __('Zimbabwe','ultimate-member'), + ); + break; + + } + + /** + * UM hook + * + * @type filter + * @title um_{$data}_predefined_field_options + * @description Extend Predefined Fields options. Where $data - field key. + * @input_vars + * [{"var":"$options","type":"array","desc":"Field's Options"}] + * @change_log + * ["Since: 2.0"] + * @usage add_filter( 'um_{$data}_predefined_field_options', 'function_name', 10, 1 ); + * @example + * + */ + $array = apply_filters( "um_{$data}_predefined_field_options", $array ); + return $array; + } + + } } \ No newline at end of file diff --git a/includes/core/class-chart.php b/includes/core/class-chart.php index de81782a..c83e69a3 100644 --- a/includes/core/class-chart.php +++ b/includes/core/class-chart.php @@ -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 ); - ?> - + var chart = new google.visualization.LineChart( document.getElementById( 'chart_' ) ); + chart.draw( data, options ); -
+ } -
+ - "> - } + */ $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 ) ) ) { diff --git a/includes/core/class-external-integrations.php b/includes/core/class-external-integrations.php index 94382182..e20a6378 100644 --- a/includes/core/class-external-integrations.php +++ b/includes/core/class-external-integrations.php @@ -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. */ diff --git a/includes/core/class-fields.php b/includes/core/class-fields.php index 21abfaab..deedbf2e 100644 --- a/includes/core/class-fields.php +++ b/includes/core/class-fields.php @@ -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 ) { ?> -
-
- -
-
+
+
+ +
+
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 )) { ?> - + foreach ( $social as $k => $arr ) { + if ( um_profile( $k ) ) { ?> + + '; } + /** * Get hidden field * @@ -94,7 +112,6 @@ if ( ! class_exists( 'Fields' ) ) { * @return string */ function disabled_hidden_field( $key, $value ) { - return ''; } @@ -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' ) ) { '; - 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' ) ); diff --git a/includes/core/class-files.php b/includes/core/class-files.php index f4b27434..2010c401 100644 --- a/includes/core/class-files.php +++ b/includes/core/class-files.php @@ -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(); diff --git a/includes/core/class-fonticons.php b/includes/core/class-fonticons.php index 96efc8fb..dd52f5d4 100644 --- a/includes/core/class-fonticons.php +++ b/includes/core/class-fonticons.php @@ -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' ); + + } + + } } \ No newline at end of file diff --git a/includes/core/class-form.php b/includes/core/class-form.php index fd9d9d1f..792d8014 100644 --- a/includes/core/class-form.php +++ b/includes/core/class-form.php @@ -5,505 +5,531 @@ namespace um\core; if ( ! defined( 'ABSPATH' ) ) exit; if ( ! class_exists( 'Form' ) ) { - class Form { - - public $form_suffix; - var $form_id; - - function __construct() { - - $this->post_form = null; - - $this->form_suffix = null; - - $this->errors = null; - - $this->processing = null; - - add_action('template_redirect', array(&$this, 'form_init'), 2); - - add_action('init', array(&$this, 'field_declare'), 10); - - } - - - function ajax_muted_action() { - extract( $_REQUEST ); - - if ( ! UM()->roles()->um_current_user_can( 'edit', $user_id ) ) - die( __( 'You can not edit this user' ) ); - - switch( $hook ) { - default: - /** - * UM hook - * - * @type action - * @title um_run_ajax_function__{$hook} - * @description Action on AJAX muted action - * @input_vars - * [{"var":"$request","type":"int","desc":"Request"}] - * @change_log - * ["Since: 2.0"] - * @usage add_action( 'um_run_ajax_function__{$hook}', 'function_name', 10, 1 ); - * @example - * - */ - do_action( "um_run_ajax_function__{$hook}", $_REQUEST ); - break; - } - } - - - function ajax_select_options() { - - $arr_options = array(); - $arr_options['status'] = 'success'; - $arr_options['post'] = $_POST; - - UM()->fields()->set_id = intval( $_POST['form_id'] ); - UM()->fields()->set_mode = 'profile'; - $form_fields = UM()->fields()->get_fields(); - $arr_options['fields'] = $form_fields; - - /** - * UM hook - * - * @type filter - * @title um_ajax_select_options__debug_mode - * @description Activate debug mode for AJAX select options - * @input_vars - * [{"var":"$debug_mode","type":"bool","desc":"Enable Debug mode"}] - * @change_log - * ["Since: 2.0"] - * @usage - * - * @example - * - */ - $debug = apply_filters('um_ajax_select_options__debug_mode', false ); - if( $debug ){ - $arr_options['debug'] = array( - $_POST, - $form_fields, - ); - } - - if( isset( $_POST['child_callback'] ) && ! empty( $_POST['child_callback'] ) && isset( $form_fields[ $_POST['child_name'] ] ) ){ - - $ajax_source_func = $_POST['child_callback']; - - // If the requested callback function is added in the form or added in the field option, execute it with call_user_func. - if( isset( $form_fields[ $_POST['child_name'] ]['custom_dropdown_options_source'] ) && - ! empty( $form_fields[ $_POST['child_name'] ]['custom_dropdown_options_source'] ) && - $form_fields[ $_POST['child_name'] ]['custom_dropdown_options_source'] == $ajax_source_func ){ - - $arr_options['field'] = $form_fields[ $_POST['child_name'] ]; - if( function_exists( $ajax_source_func ) ){ - $arr_options['items'] = call_user_func( $ajax_source_func, $arr_options['field']['parent_dropdown_relationship'] ); - } - - }else{ - $arr_options['status'] = 'error'; - $arr_options['message'] = __( 'This is not possible for security reasons.','ultimate-member'); - } - - } - - wp_send_json( $arr_options ); - } - - - /** - * Count the form errors. - * @return integer - */ - function count_errors() { - $errors = $this->errors; - - if( $errors && is_array( $errors ) ) { - return count( $errors ); - } - - return 0; - } - - - /** - * Appends field errors - * @param string $key - * @param string $error - */ - function add_error( $key, $error ) { - if ( ! isset( $this->errors[ $key ] ) ){ - /** - * UM hook - * - * @type filter - * @title um_submit_form_error - * @description Change error text on submit form - * @input_vars - * [{"var":"$error","type":"string","desc":"Error String"}, - * {"var":"$key","type":"string","desc":"Error Key"}] - * @change_log - * ["Since: 2.0"] - * @usage - * - * @example - * - */ - $error = apply_filters( 'um_submit_form_error', $error, $key ); - $this->errors[ $key ] = $error; - } - } - - - /** - * If a form has errors - * @param string $key - * @return boolean - */ - function has_error( $key ) { - if ( isset( $this->errors[$key] ) ) - return true; - return false; - } - - - /** - * Declare all fields - */ - function field_declare(){ - if ( isset( UM()->builtin()->custom_fields ) ) { - $this->all_fields = UM()->builtin()->custom_fields; - } else { - $this->all_fields = null; - } - } - - - /** - * Validate form - */ - function form_init() { - if ( isset( $_SERVER['REQUEST_METHOD'] ) ) { - $http_post = ('POST' == $_SERVER['REQUEST_METHOD']); - } else { - $http_post = 'POST'; - } - - if ( $http_post && ! is_admin() && isset( $_POST['form_id'] ) && is_numeric( $_POST['form_id'] ) ) { - - /** - * UM hook - * - * @type action - * @title um_before_submit_form_post - * @description Before submit form - * @input_vars - * [{"var":"$post","type":"int","desc":"Post data"}] - * @change_log - * ["Since: 2.0"] - * @usage add_action( 'um_before_submit_form_post', 'function_name', 10, 1 ); - * @example - * - */ - do_action( "um_before_submit_form_post", $_POST ); - - $this->form_id = $_POST['form_id']; - $this->form_status = get_post_status( $this->form_id ); - - - if ( $this->form_status == 'publish' ) { - /* save entire form as global */ - /** - * UM hook - * - * @type filter - * @title um_submit_post_form - * @description Change submitted data on form submit - * @input_vars - * [{"var":"$data","type":"array","desc":"Submitted data"}] - * @change_log - * ["Since: 2.0"] - * @usage - * - * @example - * - */ - $this->post_form = apply_filters( 'um_submit_post_form', $_POST ); - - $this->post_form = $this->beautify( $this->post_form ); - - $this->form_data = UM()->query()->post_data( $this->form_id ); - - $this->post_form['submitted'] = $this->post_form; - - $this->post_form = array_merge( $this->form_data, $this->post_form ); - - if ( isset( $this->form_data['custom_fields'] ) && strstr( $this->form_data['custom_fields'], 'role_' ) ) { // Secure selected role - - $custom_field_roles = $this->custom_field_roles( $this->form_data['custom_fields'] ); - - if ( ! empty( $_POST['role'] ) ) { - $role = $_POST['role']; - - if( is_array( $_POST['role'] ) ){ - $role = current( $_POST['role'] ); - } - - global $wp_roles; - $role_keys = array_map( function( $item ) { - return 'um_' . $item; - }, get_option( 'um_roles' ) ); - $exclude_roles = array_diff( array_keys( $wp_roles->roles ), array_merge( $role_keys, array( 'subscriber' ) ) ); - - if ( ! empty( $role ) && - ( ! in_array( $role , $custom_field_roles ) || in_array( $role , $exclude_roles ) ) ) { - wp_die( __( 'This is not possible for security reasons.','ultimate-member') ); - } - - $this->post_form['role'] = $role; - $this->post_form['submitted']['role'] = $role; - } - - } elseif ( isset( $this->post_form['mode'] ) && $this->post_form['mode'] == 'register' ) { - $role = $this->assigned_role( $this->form_id ); - $this->post_form['role'] = $role; - //fix for social login - //$this->post_form['submitted']['role'] = $role; - } - - if ( isset( $_POST[ UM()->honeypot ] ) && $_POST[ UM()->honeypot ] != '' ){ - wp_die( 'Hello, spam bot!', 'ultimate-member' ); - } - - if ( ! in_array( $this->form_data['mode'], array( 'login' ) ) ) { - - $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 ( !current_user_can('manage_options') && $live_timestamp - $form_timestamp < 6 && 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') ); - - } - - /** - * UM hook - * - * @type filter - * @title um_submit_form_data - * @description Change submitted data on form submit - * @input_vars - * [{"var":"$data","type":"array","desc":"Submitted data"}, - * {"var":"$mode","type":"string","desc":"Form mode"}] - * @change_log - * ["Since: 2.0"] - * @usage - * - * @example - * - */ - $this->post_form = apply_filters( 'um_submit_form_data', $this->post_form, $this->post_form['mode'] ); - - /* Continue based on form mode - pre-validation */ - - /** - * UM hook - * - * @type action - * @title um_submit_form_errors_hook - * @description Action on submit form - * @input_vars - * [{"var":"$post","type":"int","desc":"Post data"}] - * @change_log - * ["Since: 2.0"] - * @usage add_action( 'um_submit_form_errors_hook', 'function_name', 10, 1 ); - * @example - * - */ - do_action( 'um_submit_form_errors_hook', $this->post_form ); - /** - * UM hook - * - * @type action - * @title um_submit_form_{$mode} - * @description Action on submit form - * @input_vars - * [{"var":"$post","type":"int","desc":"Post data"}] - * @change_log - * ["Since: 2.0"] - * @usage add_action( 'um_submit_form_{$mode}', 'function_name', 10, 1 ); - * @example - * - */ - do_action( "um_submit_form_{$this->post_form['mode']}", $this->post_form ); - - } - - } - - } - - - /** - * Beautify form data - * @param array $form - * @return array $form - */ - function beautify( $form ){ - - if (isset($form['form_id'])){ - - $this->form_suffix = '-' . $form['form_id']; - - $this->processing = $form['form_id']; - - foreach( $form as $key => $value ){ - if ( strstr( $key, $this->form_suffix ) ) { - $a_key = str_replace( $this->form_suffix, '', $key ); - $form[ $a_key ] = $value; - unset( $form[ $key ] ); - } - } - - } - - return $form; - } - - - /** - * Display form type as Title - * @param string $mode - * @param integer $post_id - * @return string $output - */ - function display_form_type( $mode, $post_id ){ - $output = null; - switch( $mode ){ - case 'login': - $output = 'Login'; - break; - case 'profile': - $output = 'Profile'; - break; - case 'register': - $output = 'Register'; - break; - } - return $output; - } - - /** - * Assigned roles to a form - * @param integer $post_id - * @return string $role - */ - function assigned_role( $post_id ) { - - $global_role = get_option( 'default_role' ); // WP Global settings - - $um_global_role = UM()->options()->get( 'register_role' ); // UM Settings Global settings - if ( ! empty( $um_global_role ) ) - $global_role = $um_global_role; // Form Global settings - - - $mode = $this->form_type( $post_id ); - $use_custom = get_post_meta( $post_id, "_um_{$mode}_use_custom_settings", true ); - if ( $use_custom ) { // Custom Form settings - $role = get_post_meta( $post_id, "_um_{$mode}_role", true ); - } - - if ( empty( $role ) ) { // custom role is default, return default role's slug - $role = $global_role; - } - - return $role; - } - - /** - * Get form type - * @param integer $post_id - * @return string - */ - function form_type( $post_id ){ - - $mode = get_post_meta( $post_id, '_um_mode', true ); - - return $mode; - } - - /** - * Get custom field roles - * @param string $custom_fields serialized - * @return bool|array roles - */ - function custom_field_roles( $custom_fields ) { - $fields = maybe_unserialize( $custom_fields ); - - if ( ! is_array( $fields ) ) - return false; - - foreach ( $fields as $field_key => $field_settings ) { - - if ( strstr( $field_key , 'role_' ) ) { - if ( is_array( $field_settings['options'] ) ) { - return array_keys( $field_settings['options'] ); - } - } - - } - - return false; - } - } + + /** + * Class Form + * @package um\core + */ + class Form { + + + /** + * @var null + */ + public $form_suffix; + + + /** + * @var + */ + var $form_id; + + + /** + * Form constructor. + */ + function __construct() { + + $this->post_form = null; + + $this->form_suffix = null; + + $this->errors = null; + + $this->processing = null; + + add_action('template_redirect', array(&$this, 'form_init'), 2); + + add_action('init', array(&$this, 'field_declare'), 10); + + } + + + /** + * + */ + function ajax_muted_action() { + extract( $_REQUEST ); + + if ( ! UM()->roles()->um_current_user_can( 'edit', $user_id ) ) + die( __( 'You can not edit this user' ) ); + + switch( $hook ) { + default: + /** + * UM hook + * + * @type action + * @title um_run_ajax_function__{$hook} + * @description Action on AJAX muted action + * @input_vars + * [{"var":"$request","type":"int","desc":"Request"}] + * @change_log + * ["Since: 2.0"] + * @usage add_action( 'um_run_ajax_function__{$hook}', 'function_name', 10, 1 ); + * @example + * + */ + do_action( "um_run_ajax_function__{$hook}", $_REQUEST ); + break; + } + } + + + /** + * + */ + function ajax_select_options() { + + $arr_options = array(); + $arr_options['status'] = 'success'; + $arr_options['post'] = $_POST; + + UM()->fields()->set_id = intval( $_POST['form_id'] ); + UM()->fields()->set_mode = 'profile'; + $form_fields = UM()->fields()->get_fields(); + $arr_options['fields'] = $form_fields; + + /** + * UM hook + * + * @type filter + * @title um_ajax_select_options__debug_mode + * @description Activate debug mode for AJAX select options + * @input_vars + * [{"var":"$debug_mode","type":"bool","desc":"Enable Debug mode"}] + * @change_log + * ["Since: 2.0"] + * @usage + * + * @example + * + */ + $debug = apply_filters('um_ajax_select_options__debug_mode', false ); + if( $debug ){ + $arr_options['debug'] = array( + $_POST, + $form_fields, + ); + } + + if( isset( $_POST['child_callback'] ) && ! empty( $_POST['child_callback'] ) && isset( $form_fields[ $_POST['child_name'] ] ) ){ + + $ajax_source_func = $_POST['child_callback']; + + // If the requested callback function is added in the form or added in the field option, execute it with call_user_func. + if( isset( $form_fields[ $_POST['child_name'] ]['custom_dropdown_options_source'] ) && + ! empty( $form_fields[ $_POST['child_name'] ]['custom_dropdown_options_source'] ) && + $form_fields[ $_POST['child_name'] ]['custom_dropdown_options_source'] == $ajax_source_func ){ + + $arr_options['field'] = $form_fields[ $_POST['child_name'] ]; + if( function_exists( $ajax_source_func ) ){ + $arr_options['items'] = call_user_func( $ajax_source_func, $arr_options['field']['parent_dropdown_relationship'] ); + } + + }else{ + $arr_options['status'] = 'error'; + $arr_options['message'] = __( 'This is not possible for security reasons.','ultimate-member'); + } + + } + + wp_send_json( $arr_options ); + } + + + /** + * Count the form errors. + * @return integer + */ + function count_errors() { + $errors = $this->errors; + + if( $errors && is_array( $errors ) ) { + return count( $errors ); + } + + return 0; + } + + + /** + * Appends field errors + * @param string $key + * @param string $error + */ + function add_error( $key, $error ) { + if ( ! isset( $this->errors[ $key ] ) ){ + /** + * UM hook + * + * @type filter + * @title um_submit_form_error + * @description Change error text on submit form + * @input_vars + * [{"var":"$error","type":"string","desc":"Error String"}, + * {"var":"$key","type":"string","desc":"Error Key"}] + * @change_log + * ["Since: 2.0"] + * @usage + * + * @example + * + */ + $error = apply_filters( 'um_submit_form_error', $error, $key ); + $this->errors[ $key ] = $error; + } + } + + + /** + * If a form has errors + * @param string $key + * @return boolean + */ + function has_error( $key ) { + if ( isset( $this->errors[$key] ) ) + return true; + return false; + } + + + /** + * Declare all fields + */ + function field_declare(){ + if ( isset( UM()->builtin()->custom_fields ) ) { + $this->all_fields = UM()->builtin()->custom_fields; + } else { + $this->all_fields = null; + } + } + + + /** + * Validate form + */ + function form_init() { + if ( isset( $_SERVER['REQUEST_METHOD'] ) ) { + $http_post = ('POST' == $_SERVER['REQUEST_METHOD']); + } else { + $http_post = 'POST'; + } + + if ( $http_post && ! is_admin() && isset( $_POST['form_id'] ) && is_numeric( $_POST['form_id'] ) ) { + + /** + * UM hook + * + * @type action + * @title um_before_submit_form_post + * @description Before submit form + * @input_vars + * [{"var":"$post","type":"int","desc":"Post data"}] + * @change_log + * ["Since: 2.0"] + * @usage add_action( 'um_before_submit_form_post', 'function_name', 10, 1 ); + * @example + * + */ + do_action( "um_before_submit_form_post", $_POST ); + + $this->form_id = $_POST['form_id']; + $this->form_status = get_post_status( $this->form_id ); + + + if ( $this->form_status == 'publish' ) { + /* save entire form as global */ + /** + * UM hook + * + * @type filter + * @title um_submit_post_form + * @description Change submitted data on form submit + * @input_vars + * [{"var":"$data","type":"array","desc":"Submitted data"}] + * @change_log + * ["Since: 2.0"] + * @usage + * + * @example + * + */ + $this->post_form = apply_filters( 'um_submit_post_form', $_POST ); + + $this->post_form = $this->beautify( $this->post_form ); + + $this->form_data = UM()->query()->post_data( $this->form_id ); + + $this->post_form['submitted'] = $this->post_form; + + $this->post_form = array_merge( $this->form_data, $this->post_form ); + + if ( isset( $this->form_data['custom_fields'] ) && strstr( $this->form_data['custom_fields'], 'role_' ) ) { // Secure selected role + + $custom_field_roles = $this->custom_field_roles( $this->form_data['custom_fields'] ); + + if ( ! empty( $_POST['role'] ) ) { + $role = $_POST['role']; + + if( is_array( $_POST['role'] ) ){ + $role = current( $_POST['role'] ); + } + + global $wp_roles; + $role_keys = array_map( function( $item ) { + return 'um_' . $item; + }, get_option( 'um_roles' ) ); + $exclude_roles = array_diff( array_keys( $wp_roles->roles ), array_merge( $role_keys, array( 'subscriber' ) ) ); + + if ( ! empty( $role ) && + ( ! in_array( $role , $custom_field_roles ) || in_array( $role , $exclude_roles ) ) ) { + wp_die( __( 'This is not possible for security reasons.','ultimate-member') ); + } + + $this->post_form['role'] = $role; + $this->post_form['submitted']['role'] = $role; + } + + } elseif ( isset( $this->post_form['mode'] ) && $this->post_form['mode'] == 'register' ) { + $role = $this->assigned_role( $this->form_id ); + $this->post_form['role'] = $role; + //fix for social login + //$this->post_form['submitted']['role'] = $role; + } + + if ( isset( $_POST[ UM()->honeypot ] ) && $_POST[ UM()->honeypot ] != '' ){ + wp_die( 'Hello, spam bot!', 'ultimate-member' ); + } + + if ( ! in_array( $this->form_data['mode'], array( 'login' ) ) ) { + + $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 ( !current_user_can('manage_options') && $live_timestamp - $form_timestamp < 6 && 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') ); + + } + + /** + * UM hook + * + * @type filter + * @title um_submit_form_data + * @description Change submitted data on form submit + * @input_vars + * [{"var":"$data","type":"array","desc":"Submitted data"}, + * {"var":"$mode","type":"string","desc":"Form mode"}] + * @change_log + * ["Since: 2.0"] + * @usage + * + * @example + * + */ + $this->post_form = apply_filters( 'um_submit_form_data', $this->post_form, $this->post_form['mode'] ); + + /* Continue based on form mode - pre-validation */ + + /** + * UM hook + * + * @type action + * @title um_submit_form_errors_hook + * @description Action on submit form + * @input_vars + * [{"var":"$post","type":"int","desc":"Post data"}] + * @change_log + * ["Since: 2.0"] + * @usage add_action( 'um_submit_form_errors_hook', 'function_name', 10, 1 ); + * @example + * + */ + do_action( 'um_submit_form_errors_hook', $this->post_form ); + /** + * UM hook + * + * @type action + * @title um_submit_form_{$mode} + * @description Action on submit form + * @input_vars + * [{"var":"$post","type":"int","desc":"Post data"}] + * @change_log + * ["Since: 2.0"] + * @usage add_action( 'um_submit_form_{$mode}', 'function_name', 10, 1 ); + * @example + * + */ + do_action( "um_submit_form_{$this->post_form['mode']}", $this->post_form ); + + } + + } + + } + + + /** + * Beautify form data + * @param array $form + * @return array $form + */ + function beautify( $form ){ + + if (isset($form['form_id'])){ + + $this->form_suffix = '-' . $form['form_id']; + + $this->processing = $form['form_id']; + + foreach( $form as $key => $value ){ + if ( strstr( $key, $this->form_suffix ) ) { + $a_key = str_replace( $this->form_suffix, '', $key ); + $form[ $a_key ] = $value; + unset( $form[ $key ] ); + } + } + + } + + return $form; + } + + + /** + * Display form type as Title + * @param string $mode + * @param integer $post_id + * @return string $output + */ + function display_form_type( $mode, $post_id ){ + $output = null; + switch( $mode ){ + case 'login': + $output = 'Login'; + break; + case 'profile': + $output = 'Profile'; + break; + case 'register': + $output = 'Register'; + break; + } + return $output; + } + + + /** + * Assigned roles to a form + * @param integer $post_id + * @return string $role + */ + function assigned_role( $post_id ) { + + $global_role = get_option( 'default_role' ); // WP Global settings + + $um_global_role = UM()->options()->get( 'register_role' ); // UM Settings Global settings + if ( ! empty( $um_global_role ) ) + $global_role = $um_global_role; // Form Global settings + + + $mode = $this->form_type( $post_id ); + $use_custom = get_post_meta( $post_id, "_um_{$mode}_use_custom_settings", true ); + if ( $use_custom ) { // Custom Form settings + $role = get_post_meta( $post_id, "_um_{$mode}_role", true ); + } + + if ( empty( $role ) ) { // custom role is default, return default role's slug + $role = $global_role; + } + + return $role; + } + + + /** + * Get form type + * @param integer $post_id + * @return string + */ + function form_type( $post_id ){ + $mode = get_post_meta( $post_id, '_um_mode', true ); + return $mode; + } + + + /** + * Get custom field roles + * @param string $custom_fields serialized + * @return bool|array roles + */ + function custom_field_roles( $custom_fields ) { + + $fields = maybe_unserialize( $custom_fields ); + + if ( ! is_array( $fields ) ) + return false; + + foreach ( $fields as $field_key => $field_settings ) { + + if ( strstr( $field_key , 'role_' ) ) { + if ( is_array( $field_settings['options'] ) ) { + return array_keys( $field_settings['options'] ); + } + } + + } + + return false; + } + } } \ No newline at end of file diff --git a/includes/core/class-logout.php b/includes/core/class-logout.php index 86f95c43..bdefde9c 100644 --- a/includes/core/class-logout.php +++ b/includes/core/class-logout.php @@ -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 - * - * @example - * - */ - $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 + * + * @example + * + */ + $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 ) ) ); + } + + } + + } + + } } \ No newline at end of file diff --git a/includes/core/class-mail.php b/includes/core/class-mail.php index 1a9c4d64..b517c302 100644 --- a/includes/core/class-mail.php +++ b/includes/core/class-mail.php @@ -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']; diff --git a/includes/core/class-members.php b/includes/core/class-members.php index acd2bba4..3d01bf09 100644 --- a/includes/core/class-members.php +++ b/includes/core/class-members.php @@ -5,561 +5,591 @@ namespace um\core; if ( ! defined( 'ABSPATH' ) ) exit; if ( ! class_exists( 'Members' ) ) { - class Members { - - var $results; - - function __construct() { - - add_filter('user_search_columns', array(&$this, 'user_search_columns'), 99 ); - - add_action('template_redirect', array(&$this, 'access_members'), 555); - - $this->core_search_fields = array( - 'user_login', - 'username', - 'display_name', - 'user_email', - ); - - add_filter( 'um_search_select_fields', array(&$this, 'um_search_select_fields'), 10, 1 ); - - } - - /*** - *** @user_search_columns - ***/ - function user_search_columns( $search_columns ){ - if ( is_admin() ) { - $search_columns[] = 'display_name'; - } - return $search_columns; - } - - /*** - *** @Members page allowed? - ***/ - function access_members() { - - if ( UM()->options()->get('members_page') == 0 && um_is_core_page( 'members' ) ) { - um_redirect_home(); - } - - } - - /*** - *** @tag conversion for member directory - ***/ - function convert_tags( $string, $array ) { - - $search = array( - '{total_users}', - ); - - $replace = array( - $array['total_users'], - ); - - $string = str_replace($search, $replace, $string); - return $string; - } - - /*** - *** @show filter - ***/ - function show_filter( $filter ) { - $fields = UM()->builtin()->all_user_fields; - - if ( isset( $fields[ $filter ] ) ) { - $attrs = $fields[ $filter ]; - } else { - /** - * UM hook - * - * @type filter - * @title um_custom_search_field_{$filter} - * @description Custom search settings by $filter - * @input_vars - * [{"var":"$settings","type":"array","desc":"Search Settings"}] - * @change_log - * ["Since: 2.0"] - * @usage - * - * @example - * - */ - $attrs = apply_filters( "um_custom_search_field_{$filter}", array() ); - } - - // additional filter for search field attributes - /** - * UM hook - * - * @type filter - * @title um_search_field_{$filter} - * @description Extend search settings by $filter - * @input_vars - * [{"var":"$settings","type":"array","desc":"Search Settings"}] - * @change_log - * ["Since: 2.0"] - * @usage - * - * @example - * - */ - $attrs = apply_filters( "um_search_field_{$filter}", $attrs ); - - $type = UM()->builtin()->is_dropdown_field( $filter, $attrs ) ? 'select' : 'text'; - - /** - * UM hook - * - * @type filter - * @title um_search_field_type - * @description Change search field type - * @input_vars - * [{"var":"$type","type":"string","desc":"Search field type"}, - * {"var":"$settings","type":"array","desc":"Search Settings"}] - * @change_log - * ["Since: 2.0"] - * @usage - * - * @example - * - */ - $type = apply_filters( 'um_search_field_type', $type, $attrs ); - - /** - * UM hook - * - * @type filter - * @title um_search_fields - * @description Filter all search fields - * @input_vars - * [{"var":"$settings","type":"array","desc":"Search Fields"}] - * @change_log - * ["Since: 2.0"] - * @usage - * - * @example - * - */ - $attrs = apply_filters( 'um_search_fields', $attrs ); - - if ( $type == 'select' ) { - /** - * UM hook - * - * @type filter - * @title um_search_select_fields - * @description Filter all search fields for select field type - * @input_vars - * [{"var":"$settings","type":"array","desc":"Search Fields"}] - * @change_log - * ["Since: 2.0"] - * @usage - * - * @example - * - */ - $attrs = apply_filters( 'um_search_select_fields', $attrs ); - } - - switch ( $type ) { - - case 'select': - - ?> - - - - - - - - shortcodes()->form_id, '_um_roles', true ); - $um_roles = UM()->roles()->get_roles( false ); - - if( ! empty( $shortcode_roles ) && is_array( $shortcode_roles ) ){ - - $attrs['options'] = array(); - - foreach ( $um_roles as $key => $value ) { - if ( in_array( $key, $shortcode_roles ) ) { - $attrs['options'][ $key ] = $value; - } - } - } - } - - return $attrs; - } - - - - - /*** - *** @Generate a loop of results - ***/ - function get_members( $args ) { - - global $wpdb, $post; - - /** - * @var $profiles_per_page - * @var $profiles_per_page_mobile - */ - extract( $args ); + /** + * Class Members + * @package um\core + */ + class Members { + + + /** + * @var + */ + var $results; + + + /** + * Members constructor. + */ + function __construct() { + + add_filter('user_search_columns', array(&$this, 'user_search_columns'), 99 ); + + add_action('template_redirect', array(&$this, 'access_members'), 555); + + $this->core_search_fields = array( + 'user_login', + 'username', + 'display_name', + 'user_email', + ); + + add_filter( 'um_search_select_fields', array(&$this, 'um_search_select_fields'), 10, 1 ); + + } + + + /** + * User_search_columns + * + * @param $search_columns + * + * @return array + */ + function user_search_columns( $search_columns ){ + if ( is_admin() ) { + $search_columns[] = 'display_name'; + } + return $search_columns; + } + + + /** + * Members page allowed? + */ + function access_members() { + if ( UM()->options()->get('members_page') == 0 && um_is_core_page( 'members' ) ) { + um_redirect_home(); + } + } + + + /** + * Tag conversion for member directory + * + * @param $string + * @param $array + * + * @return mixed + */ + function convert_tags( $string, $array ) { + + $search = array( + '{total_users}', + ); + + $replace = array( + $array['total_users'], + ); + + $string = str_replace($search, $replace, $string); + return $string; + } + + + /** + * Show filter + * + * @param $filter + */ + function show_filter( $filter ) { + $fields = UM()->builtin()->all_user_fields; + + if ( isset( $fields[ $filter ] ) ) { + $attrs = $fields[ $filter ]; + } else { + /** + * UM hook + * + * @type filter + * @title um_custom_search_field_{$filter} + * @description Custom search settings by $filter + * @input_vars + * [{"var":"$settings","type":"array","desc":"Search Settings"}] + * @change_log + * ["Since: 2.0"] + * @usage + * + * @example + * + */ + $attrs = apply_filters( "um_custom_search_field_{$filter}", array() ); + } + + // additional filter for search field attributes + /** + * UM hook + * + * @type filter + * @title um_search_field_{$filter} + * @description Extend search settings by $filter + * @input_vars + * [{"var":"$settings","type":"array","desc":"Search Settings"}] + * @change_log + * ["Since: 2.0"] + * @usage + * + * @example + * + */ + $attrs = apply_filters( "um_search_field_{$filter}", $attrs ); + + $type = UM()->builtin()->is_dropdown_field( $filter, $attrs ) ? 'select' : 'text'; + + /** + * UM hook + * + * @type filter + * @title um_search_field_type + * @description Change search field type + * @input_vars + * [{"var":"$type","type":"string","desc":"Search field type"}, + * {"var":"$settings","type":"array","desc":"Search Settings"}] + * @change_log + * ["Since: 2.0"] + * @usage + * + * @example + * + */ + $type = apply_filters( 'um_search_field_type', $type, $attrs ); + + /** + * UM hook + * + * @type filter + * @title um_search_fields + * @description Filter all search fields + * @input_vars + * [{"var":"$settings","type":"array","desc":"Search Fields"}] + * @change_log + * ["Since: 2.0"] + * @usage + * + * @example + * + */ + $attrs = apply_filters( 'um_search_fields', $attrs ); + + if ( $type == 'select' ) { + /** + * UM hook + * + * @type filter + * @title um_search_select_fields + * @description Filter all search fields for select field type + * @input_vars + * [{"var":"$settings","type":"array","desc":"Search Fields"}] + * @change_log + * ["Since: 2.0"] + * @usage + * + * @example + * + */ + $attrs = apply_filters( 'um_search_select_fields', $attrs ); + } + + switch ( $type ) { + + case 'select': + + ?> + + + + + + + + shortcodes()->form_id, '_um_roles', true ); + $um_roles = UM()->roles()->get_roles( false ); + + if( ! empty( $shortcode_roles ) && is_array( $shortcode_roles ) ){ + + $attrs['options'] = array(); + + foreach ( $um_roles as $key => $value ) { + if ( in_array( $key, $shortcode_roles ) ) { + $attrs['options'][ $key ] = $value; + } + } + + } + + } + + return $attrs; + } + + + /** + * Generate a loop of results + * + * @param $args + * + * @return mixed|void + */ + function get_members( $args ) { + + global $wpdb, $post; + + /** + * @var $profiles_per_page + * @var $profiles_per_page_mobile + */ + extract( $args ); - /** - * UM hook - * - * @type filter - * @title um_prepare_user_query_args - * @description Extend member directory query arguments - * @input_vars - * [{"var":"$query_args","type":"array","desc":"Members Query Arguments"}, - * {"var":"$directory_settings","type":"array","desc":"Member Directory Settings"}] - * @change_log - * ["Since: 2.0"] - * @usage - * - * @example - * - */ - $query_args = apply_filters( 'um_prepare_user_query_args', array(), $args ); + /** + * UM hook + * + * @type filter + * @title um_prepare_user_query_args + * @description Extend member directory query arguments + * @input_vars + * [{"var":"$query_args","type":"array","desc":"Members Query Arguments"}, + * {"var":"$directory_settings","type":"array","desc":"Member Directory Settings"}] + * @change_log + * ["Since: 2.0"] + * @usage + * + * @example + * + */ + $query_args = apply_filters( 'um_prepare_user_query_args', array(), $args ); + + // Prepare for BIG SELECT query + $wpdb->query('SET SQL_BIG_SELECTS=1'); + + // number of profiles for mobile + if ( UM()->mobile()->isMobile() && isset( $profiles_per_page_mobile ) ){ + $profiles_per_page = $profiles_per_page_mobile; + } + + $query_args['number'] = $profiles_per_page; + + if( isset( $args['number'] ) ){ + $query_args['number'] = $args['number']; + } + + if( isset( $args['page'] ) ){ + $members_page = $args['page']; + }else{ + $members_page = isset( $_REQUEST['members_page'] ) ? $_REQUEST['members_page'] : 1; + } + + $query_args['paged'] = $members_page; + + if ( ! um_user( 'can_view_all' ) && is_user_logged_in() ) { + //unset( $query_args ); + $query_args = array(); + } + + /** + * UM hook + * + * @type action + * @title um_user_before_query + * @description Action before users query on member directory + * @input_vars + * [{"var":"$query_args","type":"array","desc":"Query arguments"}] + * @change_log + * ["Since: 2.0"] + * @usage add_action( 'um_user_before_query', 'function_name', 10, 1 ); + * @example + * + */ + do_action( 'um_user_before_query', $query_args ); + + $users = new \WP_User_Query( $query_args ); + + /** + * UM hook + * + * @type action + * @title um_user_after_query + * @description Action before users query on member directory + * @input_vars + * [{"var":"$query_args","type":"array","desc":"Query arguments"}, + * {"var":"$users","type":"array","desc":"Users"}] + * @change_log + * ["Since: 2.0"] + * @usage add_action( 'um_user_after_query', 'function_name', 10, 2 ); + * @example + * + */ + do_action( 'um_user_after_query', $query_args, $users ); + + + $array['users'] = isset( $users->results ) && ! empty( $users->results ) ? array_unique( $users->results ) : array(); + + $array['total_users'] = (isset( $max_users ) && $max_users && $max_users <= $users->total_users ) ? $max_users : $users->total_users; + + $array['page'] = $members_page; + + if ( isset( $profiles_per_page ) && $profiles_per_page > 0 ) { + $array['total_pages'] = ceil( $array['total_users'] / $profiles_per_page ); + } else { + $array['total_pages'] = 1; + } + + $array['header'] = $this->convert_tags( $header, $array ); + $array['header_single'] = $this->convert_tags( $header_single, $array ); + + $array['users_per_page'] = $array['users']; + + for( $i = $array['page']; $i <= $array['page'] + 2; $i++ ) { + if ( $i <= $array['total_pages'] ) { + $pages_to_show[] = $i; + } + } + + if ( isset( $pages_to_show ) && count( $pages_to_show ) < 5 ) { + $pages_needed = 5 - count( $pages_to_show ); + + for ( $c = $array['page']; $c >= $array['page'] - 2; $c-- ) { + if ( !in_array( $c, $pages_to_show ) && $c > 0 ) { + $pages_to_add[] = $c; + } + } + } + + if ( isset( $pages_to_add ) ) { + + asort( $pages_to_add ); + $pages_to_show = array_merge( (array)$pages_to_add, $pages_to_show ); + + if ( count( $pages_to_show ) < 5 ) { + if ( max($pages_to_show) - $array['page'] >= 2 ) { + $pages_to_show[] = max($pages_to_show) + 1; + if ( count( $pages_to_show ) < 5 ) { + $pages_to_show[] = max($pages_to_show) + 1; + } + } else if ( $array['page'] - min($pages_to_show) >= 2 ) { + $pages_to_show[] = min($pages_to_show) - 1; + if ( count( $pages_to_show ) < 5 ) { + $pages_to_show[] = min($pages_to_show) - 1; + } + } + } + + asort( $pages_to_show ); + + $array['pages_to_show'] = $pages_to_show; + + } else { + + if ( isset( $pages_to_show ) && count( $pages_to_show ) < 5 ) { + if ( max($pages_to_show) - $array['page'] >= 2 ) { + $pages_to_show[] = max($pages_to_show) + 1; + if ( count( $pages_to_show ) < 5 ) { + $pages_to_show[] = max($pages_to_show) + 1; + } + } else if ( $array['page'] - min($pages_to_show) >= 2 ) { + $pages_to_show[] = min($pages_to_show) - 1; + if ( count( $pages_to_show ) < 5 ) { + $pages_to_show[] = min($pages_to_show) - 1; + } + } + } + + if ( isset( $pages_to_show ) && is_array( $pages_to_show ) ) { + + asort( $pages_to_show ); + + $array['pages_to_show'] = $pages_to_show; + + } + + } + + if ( isset( $array['pages_to_show'] ) ) { + + if ( $array['total_pages'] < count( $array['pages_to_show'] ) ) { + foreach( $array['pages_to_show'] as $k => $v ) { + if ( $v > $array['total_pages'] ) unset( $array['pages_to_show'][$k] ); + } + } - // Prepare for BIG SELECT query - $wpdb->query('SET SQL_BIG_SELECTS=1'); - - // number of profiles for mobile - if ( UM()->mobile()->isMobile() && isset( $profiles_per_page_mobile ) ){ - $profiles_per_page = $profiles_per_page_mobile; - } - - $query_args['number'] = $profiles_per_page; - - if( isset( $args['number'] ) ){ - $query_args['number'] = $args['number']; - } - - if( isset( $args['page'] ) ){ - $members_page = $args['page']; - }else{ - $members_page = isset( $_REQUEST['members_page'] ) ? $_REQUEST['members_page'] : 1; - } - - $query_args['paged'] = $members_page; - - if ( ! um_user( 'can_view_all' ) && is_user_logged_in() ) { - //unset( $query_args ); - $query_args = array(); - } - - /** - * UM hook - * - * @type action - * @title um_user_before_query - * @description Action before users query on member directory - * @input_vars - * [{"var":"$query_args","type":"array","desc":"Query arguments"}] - * @change_log - * ["Since: 2.0"] - * @usage add_action( 'um_user_before_query', 'function_name', 10, 1 ); - * @example - * - */ - do_action( 'um_user_before_query', $query_args ); - - $users = new \WP_User_Query( $query_args ); - - /** - * UM hook - * - * @type action - * @title um_user_after_query - * @description Action before users query on member directory - * @input_vars - * [{"var":"$query_args","type":"array","desc":"Query arguments"}, - * {"var":"$users","type":"array","desc":"Users"}] - * @change_log - * ["Since: 2.0"] - * @usage add_action( 'um_user_after_query', 'function_name', 10, 2 ); - * @example - * - */ - do_action( 'um_user_after_query', $query_args, $users ); - - - $array['users'] = isset( $users->results ) && ! empty( $users->results ) ? array_unique( $users->results ) : array(); - - $array['total_users'] = (isset( $max_users ) && $max_users && $max_users <= $users->total_users ) ? $max_users : $users->total_users; - - $array['page'] = $members_page; - - if ( isset( $profiles_per_page ) && $profiles_per_page > 0 ) { - $array['total_pages'] = ceil( $array['total_users'] / $profiles_per_page ); - } else { - $array['total_pages'] = 1; - } - - $array['header'] = $this->convert_tags( $header, $array ); - $array['header_single'] = $this->convert_tags( $header_single, $array ); - - $array['users_per_page'] = $array['users']; - - for( $i = $array['page']; $i <= $array['page'] + 2; $i++ ) { - if ( $i <= $array['total_pages'] ) { - $pages_to_show[] = $i; - } - } - - if ( isset( $pages_to_show ) && count( $pages_to_show ) < 5 ) { - $pages_needed = 5 - count( $pages_to_show ); - - for ( $c = $array['page']; $c >= $array['page'] - 2; $c-- ) { - if ( !in_array( $c, $pages_to_show ) && $c > 0 ) { - $pages_to_add[] = $c; - } - } - } - - if ( isset( $pages_to_add ) ) { - - asort( $pages_to_add ); - $pages_to_show = array_merge( (array)$pages_to_add, $pages_to_show ); - - if ( count( $pages_to_show ) < 5 ) { - if ( max($pages_to_show) - $array['page'] >= 2 ) { - $pages_to_show[] = max($pages_to_show) + 1; - if ( count( $pages_to_show ) < 5 ) { - $pages_to_show[] = max($pages_to_show) + 1; - } - } else if ( $array['page'] - min($pages_to_show) >= 2 ) { - $pages_to_show[] = min($pages_to_show) - 1; - if ( count( $pages_to_show ) < 5 ) { - $pages_to_show[] = min($pages_to_show) - 1; - } - } - } - - asort( $pages_to_show ); - - $array['pages_to_show'] = $pages_to_show; - - } else { - - if ( isset( $pages_to_show ) && count( $pages_to_show ) < 5 ) { - if ( max($pages_to_show) - $array['page'] >= 2 ) { - $pages_to_show[] = max($pages_to_show) + 1; - if ( count( $pages_to_show ) < 5 ) { - $pages_to_show[] = max($pages_to_show) + 1; - } - } else if ( $array['page'] - min($pages_to_show) >= 2 ) { - $pages_to_show[] = min($pages_to_show) - 1; - if ( count( $pages_to_show ) < 5 ) { - $pages_to_show[] = min($pages_to_show) - 1; - } - } - } - - if ( isset( $pages_to_show ) && is_array( $pages_to_show ) ) { - - asort( $pages_to_show ); - - $array['pages_to_show'] = $pages_to_show; - - } - - } - - if ( isset( $array['pages_to_show'] ) ) { - - if ( $array['total_pages'] < count( $array['pages_to_show'] ) ) { - foreach( $array['pages_to_show'] as $k => $v ) { - if ( $v > $array['total_pages'] ) unset( $array['pages_to_show'][$k] ); - } - } + foreach( $array['pages_to_show'] as $k => $v ) { + if ( (int)$v <= 0 ) { + unset( $array['pages_to_show'][$k] ); + } + } - foreach( $array['pages_to_show'] as $k => $v ) { - if ( (int)$v <= 0 ) { - unset( $array['pages_to_show'][$k] ); - } - } + } - } + /** + * UM hook + * + * @type filter + * @title um_prepare_user_results_array + * @description Extend member directory query result + * @input_vars + * [{"var":"$result","type":"array","desc":"Members Query Result"}] + * @change_log + * ["Since: 2.0"] + * @usage + * + * @example + * + */ + return apply_filters( 'um_prepare_user_results_array', $array ); + } - /** - * UM hook - * - * @type filter - * @title um_prepare_user_results_array - * @description Extend member directory query result - * @input_vars - * [{"var":"$result","type":"array","desc":"Members Query Result"}] - * @change_log - * ["Since: 2.0"] - * @usage - * - * @example - * - */ - return apply_filters( 'um_prepare_user_results_array', $array ); - } + /** + * Optimizes Member directory with multiple LEFT JOINs + * @param object $vars + * @return object $var + */ + public function um_optimize_member_query( $vars ) { - /** - * Optimizes Member directory with multiple LEFT JOINs - * @param object $vars - * @return object $var - */ - public function um_optimize_member_query( $vars ) { + global $wpdb; - global $wpdb; + $arr_where = explode("\n", $vars->query_where ); + $arr_left_join = explode("LEFT JOIN", $vars->query_from ); + $arr_user_photo_key = array('synced_profile_photo','profile_photo','synced_gravatar_hashed_id'); + + foreach ( $arr_where as $where ) { - $arr_where = explode("\n", $vars->query_where ); - $arr_left_join = explode("LEFT JOIN", $vars->query_from ); - $arr_user_photo_key = array('synced_profile_photo','profile_photo','synced_gravatar_hashed_id'); - - foreach ( $arr_where as $where ) { + foreach( $arr_user_photo_key as $key ){ + + if( strpos( $where , "'".$key."'" ) > -1 ){ - foreach( $arr_user_photo_key as $key ){ - - if( strpos( $where , "'".$key."'" ) > -1 ){ + // find usermeta key + preg_match("#mt[0-9]+.#", $where, $meta_key ); - // find usermeta key - preg_match("#mt[0-9]+.#", $where, $meta_key ); + // remove period from found meta_key + $meta_key = str_replace(".","", current( $meta_key ) ); - // remove period from found meta_key - $meta_key = str_replace(".","", current( $meta_key ) ); + // remove matched LEFT JOIN clause + $vars->query_from = str_replace('LEFT JOIN wp_usermeta AS '.$meta_key.' ON ( wp_users.ID = '.$meta_key.'.user_id )', '', $vars->query_from ); - // remove matched LEFT JOIN clause - $vars->query_from = str_replace('LEFT JOIN wp_usermeta AS '.$meta_key.' ON ( wp_users.ID = '.$meta_key.'.user_id )', '', $vars->query_from ); + // prepare EXISTS replacement for LEFT JOIN clauses + $where_exists = 'um_exist EXISTS( SELECT '.$wpdb->usermeta.'.umeta_id FROM '.$wpdb->usermeta.' WHERE '.$wpdb->usermeta.'.user_id = '.$wpdb->users.'.ID AND '.$wpdb->usermeta.'.meta_key IN("'.implode('","', $arr_user_photo_key ).'") AND '.$wpdb->usermeta.'.meta_value != "" )'; - // prepare EXISTS replacement for LEFT JOIN clauses - $where_exists = 'um_exist EXISTS( SELECT '.$wpdb->usermeta.'.umeta_id FROM '.$wpdb->usermeta.' WHERE '.$wpdb->usermeta.'.user_id = '.$wpdb->users.'.ID AND '.$wpdb->usermeta.'.meta_key IN("'.implode('","', $arr_user_photo_key ).'") AND '.$wpdb->usermeta.'.meta_value != "" )'; + // Replace LEFT JOIN clauses with EXISTS and remove duplicates + if( strpos( $vars->query_where, 'um_exist' ) === FALSE ){ + $vars->query_where = str_replace( $where , $where_exists, $vars->query_where ); + }else{ + $vars->query_where = str_replace( $where , '1=0', $vars->query_where ); + } + } - // Replace LEFT JOIN clauses with EXISTS and remove duplicates - if( strpos( $vars->query_where, 'um_exist' ) === FALSE ){ - $vars->query_where = str_replace( $where , $where_exists, $vars->query_where ); - }else{ - $vars->query_where = str_replace( $where , '1=0', $vars->query_where ); - } - } + } - } + } - } + $vars->query_where = str_replace("\n", "", $vars->query_where ); + $vars->query_where = str_replace("um_exist", "", $vars->query_where ); - $vars->query_where = str_replace("\n", "", $vars->query_where ); - $vars->query_where = str_replace("um_exist", "", $vars->query_where ); + return $vars; - return $vars; + } - } - - } + } } \ No newline at end of file diff --git a/includes/core/class-modal.php b/includes/core/class-modal.php index 00f4d19a..b709a58a 100644 --- a/includes/core/class-modal.php +++ b/includes/core/class-modal.php @@ -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; + } + } + + } + + } } \ No newline at end of file diff --git a/includes/core/class-options.php b/includes/core/class-options.php index 24507d4e..4ae6f089 100644 --- a/includes/core/class-options.php +++ b/includes/core/class-options.php @@ -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(); diff --git a/includes/core/class-password.php b/includes/core/class-password.php index ec6a0dd4..9d7445ce 100644 --- a/includes/core/class-password.php +++ b/includes/core/class-password.php @@ -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 - * - */ - 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 - * - */ - 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 - * - */ - 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 + * + */ + 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 - * - */ - 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 + * + */ + 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 + * + */ + 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 + * + */ + 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 - * - * @example - * - */ - $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 - * - * @example - * - */ - $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 + * + * @example + * + */ + $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 - * - */ - 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 - * - */ - 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 - * - */ - 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 + * + * @example + * + */ + $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 + * + */ + 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 + * + */ + 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 + * + */ + 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; + + } + + } } \ No newline at end of file diff --git a/includes/core/class-plugin-updater.php b/includes/core/class-plugin-updater.php index 6ba11583..dd024efa 100644 --- a/includes/core/class-plugin-updater.php +++ b/includes/core/class-plugin-updater.php @@ -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’s configuration. If you continue to have problems, please try the support forums.' ), - __( '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’s configuration. If you continue to have problems, please try the support forums.' ), + __( '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; + } + } } \ No newline at end of file diff --git a/includes/core/class-profile.php b/includes/core/class-profile.php index 38578c76..4ff5b58d 100644 --- a/includes/core/class-profile.php +++ b/includes/core/class-profile.php @@ -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 - * - * @example - * - */ - $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 - * - * @example - * - */ - $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'] ) ? '' : ''; - } - - $items[] = '' . $icon . $value . ''; - $items[] = ''; - } - } - } - - 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; -
-
-
- -
-
- 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 + * + * @example + * + */ + $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 + * + * @example + * + */ + $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'] ) ? '' : ''; + } + + $items[] = '' . $icon . $value . ''; + $items[] = ''; + } + } + } + + 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 ) { + ?> + +
+
+
+ +
+
+ + - */ - 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 - * - * @example - * - */ - $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 + * + */ + 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 + * + * @example + * + */ + $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; + } + } + + } } diff --git a/includes/core/class-register.php b/includes/core/class-register.php index 2f38492e..b0381120 100644 --- a/includes/core/class-register.php +++ b/includes/core/class-register.php @@ -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 - * - * @example - * - */ - $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 + * + * @example + * + */ + $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; + } + + } } \ No newline at end of file diff --git a/includes/core/class-rest-api.php b/includes/core/class-rest-api.php index faa8a871..35b084c1 100644 --- a/includes/core/class-rest-api.php +++ b/includes/core/class-rest-api.php @@ -5,1024 +5,1154 @@ namespace um\core; if ( ! defined( 'ABSPATH' ) ) exit; if ( ! class_exists( 'REST_API' ) ) { - class REST_API { - - const VERSION = '1.0'; - - private $pretty_print = false; - public $log_requests = true; - private $is_valid_request = false; - private $user_id = 0; - private $stats; - private $data = array(); - private $override = true; - - public function __construct() { - - add_action( 'init', array( $this, 'add_endpoint' ) ); - add_action( 'template_redirect', array( $this, 'process_query' ), -1 ); - add_filter( 'query_vars', array( $this, 'query_vars' ) ); - - add_filter( 'um_user_profile_additional_fields', array( $this, 'user_key_field' ), 3, 2 ); - - add_action( 'personal_options_update', array( $this, 'update_key' ) ); - add_action( 'edit_user_profile_update', array( $this, 'update_key' ) ); - - // Determine if JSON_PRETTY_PRINT is available - $this->pretty_print = defined( 'JSON_PRETTY_PRINT' ) ? JSON_PRETTY_PRINT : null; - - /** - * UM hook - * - * @type filter - * @title um_api_log_requests - * @description Allow API request logging to be turned off - * @input_vars - * [{"var":"$allow_log","type":"bool","desc":"Enable api logs"}] - * @change_log - * ["Since: 2.0"] - * @usage - * - * @example - * - */ - $this->log_requests = apply_filters( 'um_api_log_requests', $this->log_requests ); - } - - /** - * Registers a new rewrite endpoint for accessing the API - */ - public function add_endpoint( $rewrite_rules ) { - add_rewrite_endpoint( 'um-api', EP_ALL ); - } - - /** - * Registers query vars for API access - */ - public function query_vars( $vars ) { - - $vars[] = 'key'; - $vars[] = 'token'; - $vars[] = 'format'; - $vars[] = 'query'; - $vars[] = 'type'; - $vars[] = 'data'; - $vars[] = 'fields'; - $vars[] = 'value'; - $vars[] = 'number'; - $vars[] = 'id'; - $vars[] = 'email'; - $vars[] = 'orderby'; - $vars[] = 'order'; - $vars[] = 'include'; - $vars[] = 'exclude'; - - $this->vars = $vars; - - return $vars; - } - - /** - * Validate the API request - */ - private function validate_request() { - global $wp_query; - - $this->override = false; - - // Make sure we have both user and api key - if ( ! empty( $wp_query->query_vars['um-api'] ) ) { - - if ( empty( $wp_query->query_vars['token'] ) || empty( $wp_query->query_vars['key'] ) ) - $this->missing_auth(); - - // Retrieve the user by public API key and ensure they exist - if ( ! ( $user = $this->get_user( $wp_query->query_vars['key'] ) ) ) : - $this->invalid_key(); - else : - $token = urldecode( $wp_query->query_vars['token'] ); - $secret = get_user_meta( $user, 'um_user_secret_key', true ); - $public = urldecode( $wp_query->query_vars['key'] ); - - if ( hash_equals( md5( $secret . $public ), $token ) ) - $this->is_valid_request = true; - else - $this->invalid_auth(); - endif; - } - } - - /** - * Retrieve the user ID based on the public key provided - */ - public function get_user( $key = '' ) { - global $wpdb, $wp_query; - - if( empty( $key ) ) - $key = urldecode( $wp_query->query_vars['key'] ); - - if ( empty( $key ) ) { - return false; - } - - $user = get_transient( md5( 'um_api_user_' . $key ) ); - - if ( false === $user ) { - $user = $wpdb->get_var( $wpdb->prepare( "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = 'um_user_public_key' AND meta_value = %s LIMIT 1", $key ) ); - set_transient( md5( 'um_api_user_' . $key ) , $user, DAY_IN_SECONDS ); - } - - if ( $user != NULL ) { - $this->user_id = $user; - return $user; - } - - return false; - } - - /** - * Displays a missing authentication error if all the parameters aren't - * provided - */ - private function missing_auth() { - $error = array(); - $error['error'] = __( 'You must specify both a token and API key!', 'ultimate-member' ); - - $this->data = $error; - $this->output( 401 ); - } - - /** - * Displays an authentication failed error if the user failed to provide valid credentials - */ - private function invalid_auth() { - $error = array(); - $error['error'] = __( 'Your request could not be authenticated', 'ultimate-member' ); - - $this->data = $error; - $this->output( 401 ); - } - - /** - * Displays an invalid API key error if the API key provided couldn't be validated - */ - private function invalid_key() { - $error = array(); - $error['error'] = __( 'Invalid API key', 'ultimate-member' ); - - $this->data = $error; - $this->output( 401 ); - } - - - /** - * Listens for the API and then processes the API requests - */ - public function process_query() { - global $wp_query; - - // Check for um-api var. Get out if not present - if ( ! isset( $wp_query->query_vars['um-api'] ) ) - return; - - // Check for a valid user and set errors if necessary - $this->validate_request(); - - // Only proceed if no errors have been noted - if( ! $this->is_valid_request ) - return; - - if( ! defined( 'UM_DOING_API' ) ) { - define( 'UM_DOING_API', true ); - } - - // Determine the kind of query - $args = array(); - $query_mode = $this->get_query_mode(); - foreach( $this->vars as $k ) { - $args[ $k ] = isset( $wp_query->query_vars[ $k ] ) ? $wp_query->query_vars[ $k ] : null; - } - - $data = array(); - - switch( $query_mode ) { - - case 'get.stats': - $data = $this->get_stats( $args ); - break; - - case 'get.users': - $data = $this->get_users( $args ); - break; - - case 'get.user': - $data = $this->get_auser( $args ); - break; - - case 'update.user': - $data = $this->update_user( $args ); - break; - - case 'delete.user': - $data = $this->delete_user( $args ); - break; - - default: - /** - * UM hook - * - * @type filter - * @title um_rest_query_mode - * @description Change query attributes - * @input_vars - * [{"var":"$data","type":"array","desc":"Query Data"}, - * {"var":"$query_mode","type":"string","desc":"Query Mode"}, - * {"var":"$args","type":"array","desc":"Query Arguments"}] - * @change_log - * ["Since: 2.0"] - * @usage - * - * @example - * - */ - $data = apply_filters( 'um_rest_query_mode', $data, $query_mode, $args ); - } - - /** - * UM hook - * - * @type filter - * @title um_api_output_data - * @description Change output data for Rest API call - * @input_vars - * [{"var":"$data","type":"array","desc":"Output Data"}, - * {"var":"$query_mode","type":"string","desc":"Query Mode"}, - * {"var":"$api_class","type":"REST_API","desc":"REST_API instance"}] - * @change_log - * ["Since: 2.0"] - * @usage - * - * @example - * - */ - $this->data = apply_filters( 'um_api_output_data', $data, $query_mode, $this ); - - // Log this API request, if enabled. We log it here because we have access to errors. - $this->log_request( $this->data ); - - // Send out data to the output function - $this->output(); - } - - /** - * Get some stats - */ - public function get_stats( $args ) { - global $wpdb; - extract( $args ); - - $response = array(); - - $query = "SELECT COUNT(*) FROM {$wpdb->prefix}users"; - $count = absint( $wpdb->get_var($query) ); - $response['stats']['total_users'] = $count; - - $pending = UM()->user()->get_pending_users_count(); - $response['stats']['pending_users'] = absint( $pending ); - - /** - * UM hook - * - * @type filter - * @title um_rest_api_get_stats - * @description Change output data for Rest API get stats call - * @input_vars - * [{"var":"$response","type":"array","desc":"Output Data"}] - * @change_log - * ["Since: 2.0"] - * @usage - * - * @example - * - */ - $response = apply_filters( 'um_rest_api_get_stats', $response ); - return $response; - } - - /** - * Update user API query - */ - public function update_user( $args ) { - extract( $args ); - - $response = array(); - $error = array(); - - if ( !$id ) { - $error['error'] = __('You must provide a user ID','ultimate-member'); - return $error; - } - - if ( !$data ) { - $error['error'] = __('You need to provide data to update','ultimate-member'); - return $error; - } - - um_fetch_user( $id ); - - switch ( $data ) { - case 'status': - UM()->user()->set_status( $value ); - $response['success'] = __('User status has been changed.','ultimate-member'); - break; - case 'role': - $wp_user_object = new \WP_User( $id ); - $old_roles = $wp_user_object->roles; - $wp_user_object->set_role( $value ); - - /** - * UM hook - * - * @type action - * @title um_after_member_role_upgrade - * @description Action after user role was changed - * @input_vars - * [{"var":"$new_roles","type":"array","desc":"New User Roles"}, - * {"var":"$old_roles","type":"array","desc":"Old roles"}] - * @change_log - * ["Since: 2.0"] - * @usage add_action( 'um_after_member_role_upgrade', 'function_name', 10, 2 ); - * @example - * - */ - do_action( 'um_after_member_role_upgrade', array( $value ), $old_roles ); - - $response['success'] = __( 'User role has been changed.', 'ultimate-member' ); - break; - default: - update_user_meta( $id, $data, esc_attr( $value ) ); - $response['success'] = __('User meta has been changed.','ultimate-member'); - break; - } - - return $response; - } - - - /** - * Process Get users API Request - */ - public function get_users( $args ) { - extract( $args ); - - $response = array(); - $error = array(); - - if ( !$number ) - $number = 10; - - if ( !$orderby ) - $orderby = 'user_registered'; - - if ( !$order ) - $order = 'desc'; - - $loop_a = array('number' => $number, 'orderby' => $orderby, 'order' => $order ); - - if ( $include ) { - $include = explode(',', $include ); - $loop_a['include'] = $include; - } - - if ( $exclude ) { - $exclude = explode(',', $exclude ); - $loop_a['exclude'] = $exclude; - } - - $loop = get_users( $loop_a ); - - foreach( $loop as $user ) { - - unset( $user->data->user_status ); - unset( $user->data->user_activation_key ); - unset( $user->data->user_pass ); - - um_fetch_user( $user->ID ); - - foreach( $user as $key => $val ) { - if ( $key != 'data' ) continue; - if ( $key == 'data' ) { - $key = 'profile'; - $val->roles = $user->roles; - $val->first_name = um_user('first_name'); - $val->last_name = um_user('last_name'); - $val->account_status = um_user('account_status'); - $val->profile_pic_original = $this->getsrc( um_user('profile_photo', 'original') ); - $val->profile_pic_normal = $this->getsrc( um_user('profile_photo', 200) ); - $val->profile_pic_small = $this->getsrc( um_user('profile_photo', 40) ); - $val->cover_photo = $this->getsrc( um_user('cover_photo', 1000) ); - - /** - * UM hook - * - * @type filter - * @title um_rest_userdata - * @description Change output data for Rest API userdata call - * @input_vars - * [{"var":"$value","type":"array","desc":"Output Data"}, - * {"var":"$user_id","type":"string","desc":"User ID"}] - * @change_log - * ["Since: 2.0"] - * @usage - * - * @example - * - */ - $val = apply_filters( 'um_rest_userdata', $val, $user->ID ); - } - $response[ $user->ID ] = $val; - } - - } - - return $response; - } - - /** - * Process delete user via API - */ - public function delete_user( $args ) { - extract( $args ); - - $response = array(); - $error = array(); - - if ( !isset( $id ) ) { - $error['error'] = __('You must provide a user ID','ultimate-member'); - return $error; - } - - $user = get_userdata( $id ); - if ( !$user ) { - $error['error'] = __('Invalid user specified','ultimate-member'); - return $error; - } - - um_fetch_user( $id ); - UM()->user()->delete(); - - $response['success'] = __('User has been successfully deleted.','ultimate-member'); - - return $response; - } - - /** - * Process Get user API Request - */ - public function get_auser( $args ) { - extract( $args ); - - $response = array(); - $error = array(); - - if ( !isset( $id ) ) { - $error['error'] = __('You must provide a user ID','ultimate-member'); - return $error; - } - - $user = get_userdata( $id ); - if ( ! $user ) { - $error['error'] = __('Invalid user specified','ultimate-member'); - return $error; - } - - unset( $user->data->user_status ); - unset( $user->data->user_activation_key ); - unset( $user->data->user_pass ); - - um_fetch_user( $user->ID ); - - if ( isset( $fields ) && $fields ) { - $fields = explode(',', $fields ); - $response['ID'] = $user->ID; - $response['username'] = $user->user_login; - foreach ( $fields as $field ) { - - switch( $field ) { - - default: - $response[ $field ] = ( um_profile( $field ) ) ? um_profile( $field ) : ''; - - /** - * UM hook - * - * @type filter - * @title um_rest_get_auser - * @description Change output data for Rest API user authentification call - * @input_vars - * [{"var":"$response","type":"array","desc":"Output Data"}, - * {"var":"$field","type":"string","desc":"Field Key"}, - * {"var":"$user_id","type":"int","desc":"User ID"}] - * @change_log - * ["Since: 2.0"] - * @usage - * - * @example - * - */ - $response = apply_filters( 'um_rest_get_auser', $response, $field, $user->ID ); - break; - - case 'cover_photo': - $response['cover_photo'] = $this->getsrc( um_user('cover_photo', 1000) ); - break; - - case 'profile_pic': - $response['profile_pic_original'] = $this->getsrc( um_user('profile_photo', 'original') ); - $response['profile_pic_normal'] = $this->getsrc( um_user('profile_photo', 200) ); - $response['profile_pic_small'] = $this->getsrc( um_user('profile_photo', 40) ); - break; - - case 'status': - $response['status'] = um_user('account_status'); - break; - - case 'role': - //get priority role here - $response['role'] = um_user( 'role' ); - break; - - case 'email': - case 'user_email': - $response['email'] = um_user('user_email'); - break; - - } - - } - } else { - - foreach( $user as $key => $val ) { - if ( $key != 'data' ) continue; - if ( $key == 'data' ) { - $key = 'profile'; - $val->roles = $user->roles; - $val->first_name = um_user('first_name'); - $val->last_name = um_user('last_name'); - $val->account_status = um_user('account_status'); - $val->profile_pic_original = $this->getsrc( um_user('profile_photo', 'original') ); - $val->profile_pic_normal = $this->getsrc( um_user('profile_photo', 200) ); - $val->profile_pic_small = $this->getsrc( um_user('profile_photo', 40) ); - $val->cover_photo = $this->getsrc( um_user('cover_photo', 1000) ); - - /** - * UM hook - * - * @type filter - * @title um_rest_userdata - * @description Change output data for Rest API userdata call - * @input_vars - * [{"var":"$value","type":"array","desc":"Output Data"}, - * {"var":"$user_id","type":"string","desc":"User ID"}] - * @change_log - * ["Since: 2.0"] - * @usage - * - * @example - * - */ - $val = apply_filters( 'um_rest_userdata', $val, $user->ID ); - } - $response = $val; - } - - } - - return $response; - } - - /** - * Get source - */ - public function getsrc( $image ) { - if (preg_match('/ - * @example - * - */ - $accepted = apply_filters( 'um_api_valid_query_modes', array( - 'get.users', - 'get.user', - 'update.user', - 'delete.user', - 'get.following', - 'get.followers', - 'get.stats', - ) ); - - $query = isset( $wp_query->query_vars['um-api'] ) ? $wp_query->query_vars['um-api'] : null; - $error = array(); - // Make sure our query is valid - if ( ! in_array( $query, $accepted ) ) { - $error['error'] = __( 'Invalid query!', 'ultimate-member' ); - - $this->data = $error; - $this->output(); - } - - return $query; - } - - /** - * Get page number - */ - public function get_paged() { - global $wp_query; - - return isset( $wp_query->query_vars['page'] ) ? $wp_query->query_vars['page'] : 1; - } - - /** - * Retrieve the output format - */ - public function get_output_format() { - global $wp_query; - - $format = isset( $wp_query->query_vars['format'] ) ? $wp_query->query_vars['format'] : 'json'; - - /** - * UM hook - * - * @type filter - * @title um_api_output_format - * @description UM Rest API output format - * @input_vars - * [{"var":"$format","type":"string","desc":"Format"}] - * @change_log - * ["Since: 2.0"] - * @usage - * - * @example - * - */ - return apply_filters( 'um_api_output_format', $format ); - } - - /** - * Log each API request, if enabled - */ - private function log_request( $data = array() ) { - if ( ! $this->log_requests ) - return; - - } - - - /** - * Retrieve the output data - */ - public function get_output() { - return $this->data; - } - - /** - * Output Query in either JSON/XML. The query data is outputted as JSON - * by default - */ - public function output( $status_code = 200 ) { - global $wp_query; - - $format = $this->get_output_format(); - - status_header( $status_code ); - - /** - * UM hook - * - * @type action - * @title um_api_output_before - * @description Action before API output - * @input_vars - * [{"var":"$data","type":"array","desc":"API data"}, - * {"var":"$rest_api","type":"object","desc":"REST API class"}, - * {"var":"$format","type":"string","desc":"Format"}] - * @change_log - * ["Since: 2.0"] - * @usage add_action( 'um_api_output_before', 'function_name', 10, 3 ); - * @example - * - */ - do_action( 'um_api_output_before', $this->data, $this, $format ); - - switch ( $format ) : - - case 'xml' : - - require_once um_path . 'includes/lib/array2xml.php'; - $xml = Array2XML::createXML( 'um', $this->data ); - echo $xml->saveXML(); - - break; - - case 'json' : - case '' : - - header( 'Content-Type: application/json' ); - if ( ! empty( $this->pretty_print ) ) - echo json_encode( $this->data, $this->pretty_print ); - else - echo json_encode( $this->data ); - - break; - - - default : - - // Allow other formats to be added via extensions - /** - * UM hook - * - * @type action - * @title um_api_output_{$format} - * @description Action before API output - * @input_vars - * [{"var":"$data","type":"array","desc":"API data"}, - * {"var":"$rest_api","type":"object","desc":"REST API class"}] - * @change_log - * ["Since: 2.0"] - * @usage add_action( 'um_api_output_{$format}', 'function_name', 10, 2 ); - * @example - * - */ - do_action( 'um_api_output_' . $format, $this->data, $this ); - - break; - - endswitch; - - /** - * UM hook - * - * @type action - * @title um_api_output_after - * @description Action after API output - * @input_vars - * [{"var":"$data","type":"array","desc":"API data"}, - * {"var":"$rest_api","type":"object","desc":"REST API class"}, - * {"var":"$format","type":"string","desc":"Format"}] - * @change_log - * ["Since: 2.0"] - * @usage add_action( 'um_api_output_after', 'function_name', 10, 3 ); - * @example - * - */ - do_action( 'um_api_output_after', $this->data, $this, $format ); - - die(); - } - - /** - * Modify User Profile Page fields - * - * @param $content - * @param $user - * @return string - */ - function user_key_field( $content, $user ) { - if ( empty( $user ) ) - return $content; - - if( ! isset( $user->ID ) ) - return $content; - - if ( current_user_can( 'edit_users' ) && current_user_can( 'edit_user', $user->ID ) ) { - $user = get_userdata( $user->ID ); - - ob_start(); ?> - - - - - - - - -
- - - um_user_public_key ) ) { ?> -

-

- -

-  um_user_public_key; ?>
-  um_user_secret_key; ?>
-  get_token( $user->ID ); ?> -

-

-

- -
- um_user_public_key ) ) { - update_user_meta( $user_id, 'um_user_public_key', $this->generate_public_key( $user->user_email ) ); - update_user_meta( $user_id, 'um_user_secret_key', $this->generate_private_key( $user->ID ) ); - } elseif( $regenerate == true ) { - $this->revoke_api_key( $user->ID ); - update_user_meta( $user_id, 'um_user_public_key', $this->generate_public_key( $user->user_email ) ); - update_user_meta( $user_id, 'um_user_secret_key', $this->generate_private_key( $user->ID ) ); - } else { - return false; - } - - return true; - } - - /** - * Revoke a users API keys - */ - public function revoke_api_key( $user_id = 0 ) { - - if( empty( $user_id ) ) { - return false; - } - - $user = get_userdata( $user_id ); - - if( ! $user ) { - return false; - } - - if ( ! empty( $user->um_user_public_key ) ) { - delete_transient( md5( 'um_api_user_' . $user->um_user_public_key ) ); - delete_user_meta( $user_id, 'um_user_public_key' ); - delete_user_meta( $user_id, 'um_user_secret_key' ); - } else { - return false; - } - - return true; - } - - - /** - * Generate and Save API key - */ - public function update_key( $user_id ) { - if ( current_user_can( 'edit_user', $user_id ) && isset( $_POST['um_set_api_key'] ) ) { - - $user = get_userdata( $user_id ); - - if ( empty( $user->um_user_public_key ) ) { - update_user_meta( $user_id, 'um_user_public_key', $this->generate_public_key( $user->user_email ) ); - update_user_meta( $user_id, 'um_user_secret_key', $this->generate_private_key( $user->ID ) ); - } else { - $this->revoke_api_key( $user_id ); - } - } - } - - /** - * Generate the public key for a user - */ - private function generate_public_key( $user_email = '' ) { - $auth_key = defined( 'AUTH_KEY' ) ? AUTH_KEY : ''; - $public = hash( 'md5', $user_email . $auth_key . date( 'U' ) ); - return $public; - } - - /** - * Generate the secret key for a user - */ - private function generate_private_key( $user_id = 0 ) { - $auth_key = defined( 'AUTH_KEY' ) ? AUTH_KEY : ''; - $secret = hash( 'md5', $user_id . $auth_key . date( 'U' ) ); - return $secret; - } - - /** - * Retrieve the user's token - */ - private function get_token( $user_id = 0 ) { - $user = get_userdata( $user_id ); - return hash( 'md5', $user->um_user_secret_key . $user->um_user_public_key ); - } - - } + + + /** + * Class REST_API + * @package um\core + */ + class REST_API { + + /** + * + */ + const VERSION = '1.0'; + + + /** + * @var bool|int|null + */ + private $pretty_print = false; + + + /** + * @var bool|mixed|void + */ + public $log_requests = true; + + + /** + * @var bool + */ + private $is_valid_request = false; + + + /** + * @var int + */ + private $user_id = 0; + + + /** + * @var + */ + private $stats; + + + /** + * @var array + */ + private $data = array(); + + + /** + * @var bool + */ + private $override = true; + + + /** + * REST_API constructor. + */ + public function __construct() { + + add_action( 'init', array( $this, 'add_endpoint' ) ); + add_action( 'template_redirect', array( $this, 'process_query' ), -1 ); + add_filter( 'query_vars', array( $this, 'query_vars' ) ); + + add_filter( 'um_user_profile_additional_fields', array( $this, 'user_key_field' ), 3, 2 ); + + add_action( 'personal_options_update', array( $this, 'update_key' ) ); + add_action( 'edit_user_profile_update', array( $this, 'update_key' ) ); + + // Determine if JSON_PRETTY_PRINT is available + $this->pretty_print = defined( 'JSON_PRETTY_PRINT' ) ? JSON_PRETTY_PRINT : null; + + /** + * UM hook + * + * @type filter + * @title um_api_log_requests + * @description Allow API request logging to be turned off + * @input_vars + * [{"var":"$allow_log","type":"bool","desc":"Enable api logs"}] + * @change_log + * ["Since: 2.0"] + * @usage + * + * @example + * + */ + $this->log_requests = apply_filters( 'um_api_log_requests', $this->log_requests ); + } + + + /** + * Registers a new rewrite endpoint for accessing the API + * + * @param $rewrite_rules + */ + public function add_endpoint( $rewrite_rules ) { + add_rewrite_endpoint( 'um-api', EP_ALL ); + } + + + /** + * Registers query vars for API access + * + * @param $vars + * + * @return array + */ + public function query_vars( $vars ) { + + $vars[] = 'key'; + $vars[] = 'token'; + $vars[] = 'format'; + $vars[] = 'query'; + $vars[] = 'type'; + $vars[] = 'data'; + $vars[] = 'fields'; + $vars[] = 'value'; + $vars[] = 'number'; + $vars[] = 'id'; + $vars[] = 'email'; + $vars[] = 'orderby'; + $vars[] = 'order'; + $vars[] = 'include'; + $vars[] = 'exclude'; + + $this->vars = $vars; + + return $vars; + } + + + /** + * Validate the API request + */ + private function validate_request() { + global $wp_query; + + $this->override = false; + + // Make sure we have both user and api key + if ( ! empty( $wp_query->query_vars['um-api'] ) ) { + + if ( empty( $wp_query->query_vars['token'] ) || empty( $wp_query->query_vars['key'] ) ) + $this->missing_auth(); + + // Retrieve the user by public API key and ensure they exist + if ( ! ( $user = $this->get_user( $wp_query->query_vars['key'] ) ) ) : + $this->invalid_key(); + else : + $token = urldecode( $wp_query->query_vars['token'] ); + $secret = get_user_meta( $user, 'um_user_secret_key', true ); + $public = urldecode( $wp_query->query_vars['key'] ); + + if ( hash_equals( md5( $secret . $public ), $token ) ) + $this->is_valid_request = true; + else + $this->invalid_auth(); + endif; + } + } + + + /** + * Retrieve the user ID based on the public key provided + * + * @param string $key + * + * @return bool|mixed|null|string + */ + public function get_user( $key = '' ) { + global $wpdb, $wp_query; + + if( empty( $key ) ) + $key = urldecode( $wp_query->query_vars['key'] ); + + if ( empty( $key ) ) { + return false; + } + + $user = get_transient( md5( 'um_api_user_' . $key ) ); + + if ( false === $user ) { + $user = $wpdb->get_var( $wpdb->prepare( "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = 'um_user_public_key' AND meta_value = %s LIMIT 1", $key ) ); + set_transient( md5( 'um_api_user_' . $key ) , $user, DAY_IN_SECONDS ); + } + + if ( $user != NULL ) { + $this->user_id = $user; + return $user; + } + + return false; + } + + + /** + * Displays a missing authentication error if all the parameters aren't + * provided + */ + private function missing_auth() { + $error = array(); + $error['error'] = __( 'You must specify both a token and API key!', 'ultimate-member' ); + + $this->data = $error; + $this->output( 401 ); + } + + + /** + * Displays an authentication failed error if the user failed to provide valid credentials + */ + private function invalid_auth() { + $error = array(); + $error['error'] = __( 'Your request could not be authenticated', 'ultimate-member' ); + + $this->data = $error; + $this->output( 401 ); + } + + + /** + * Displays an invalid API key error if the API key provided couldn't be validated + */ + private function invalid_key() { + $error = array(); + $error['error'] = __( 'Invalid API key', 'ultimate-member' ); + + $this->data = $error; + $this->output( 401 ); + } + + + /** + * Listens for the API and then processes the API requests + */ + public function process_query() { + global $wp_query; + + // Check for um-api var. Get out if not present + if ( ! isset( $wp_query->query_vars['um-api'] ) ) + return; + + // Check for a valid user and set errors if necessary + $this->validate_request(); + + // Only proceed if no errors have been noted + if( ! $this->is_valid_request ) + return; + + if( ! defined( 'UM_DOING_API' ) ) { + define( 'UM_DOING_API', true ); + } + + // Determine the kind of query + $args = array(); + $query_mode = $this->get_query_mode(); + foreach( $this->vars as $k ) { + $args[ $k ] = isset( $wp_query->query_vars[ $k ] ) ? $wp_query->query_vars[ $k ] : null; + } + + $data = array(); + + switch( $query_mode ) { + + case 'get.stats': + $data = $this->get_stats( $args ); + break; + + case 'get.users': + $data = $this->get_users( $args ); + break; + + case 'get.user': + $data = $this->get_auser( $args ); + break; + + case 'update.user': + $data = $this->update_user( $args ); + break; + + case 'delete.user': + $data = $this->delete_user( $args ); + break; + + default: + /** + * UM hook + * + * @type filter + * @title um_rest_query_mode + * @description Change query attributes + * @input_vars + * [{"var":"$data","type":"array","desc":"Query Data"}, + * {"var":"$query_mode","type":"string","desc":"Query Mode"}, + * {"var":"$args","type":"array","desc":"Query Arguments"}] + * @change_log + * ["Since: 2.0"] + * @usage + * + * @example + * + */ + $data = apply_filters( 'um_rest_query_mode', $data, $query_mode, $args ); + } + + /** + * UM hook + * + * @type filter + * @title um_api_output_data + * @description Change output data for Rest API call + * @input_vars + * [{"var":"$data","type":"array","desc":"Output Data"}, + * {"var":"$query_mode","type":"string","desc":"Query Mode"}, + * {"var":"$api_class","type":"REST_API","desc":"REST_API instance"}] + * @change_log + * ["Since: 2.0"] + * @usage + * + * @example + * + */ + $this->data = apply_filters( 'um_api_output_data', $data, $query_mode, $this ); + + // Log this API request, if enabled. We log it here because we have access to errors. + $this->log_request( $this->data ); + + // Send out data to the output function + $this->output(); + } + + + /** + * Get some stats + * + * @param $args + * + * @return array|mixed|void + */ + public function get_stats( $args ) { + global $wpdb; + extract( $args ); + + $response = array(); + + $query = "SELECT COUNT(*) FROM {$wpdb->prefix}users"; + $count = absint( $wpdb->get_var($query) ); + $response['stats']['total_users'] = $count; + + $pending = UM()->user()->get_pending_users_count(); + $response['stats']['pending_users'] = absint( $pending ); + + /** + * UM hook + * + * @type filter + * @title um_rest_api_get_stats + * @description Change output data for Rest API get stats call + * @input_vars + * [{"var":"$response","type":"array","desc":"Output Data"}] + * @change_log + * ["Since: 2.0"] + * @usage + * + * @example + * + */ + $response = apply_filters( 'um_rest_api_get_stats', $response ); + return $response; + } + + + /** + * Update user API query + * + * @param $args + * + * @return array + */ + public function update_user( $args ) { + extract( $args ); + + $response = array(); + $error = array(); + + if ( !$id ) { + $error['error'] = __('You must provide a user ID','ultimate-member'); + return $error; + } + + if ( !$data ) { + $error['error'] = __('You need to provide data to update','ultimate-member'); + return $error; + } + + um_fetch_user( $id ); + + switch ( $data ) { + case 'status': + UM()->user()->set_status( $value ); + $response['success'] = __('User status has been changed.','ultimate-member'); + break; + case 'role': + $wp_user_object = new \WP_User( $id ); + $old_roles = $wp_user_object->roles; + $wp_user_object->set_role( $value ); + + /** + * UM hook + * + * @type action + * @title um_after_member_role_upgrade + * @description Action after user role was changed + * @input_vars + * [{"var":"$new_roles","type":"array","desc":"New User Roles"}, + * {"var":"$old_roles","type":"array","desc":"Old roles"}] + * @change_log + * ["Since: 2.0"] + * @usage add_action( 'um_after_member_role_upgrade', 'function_name', 10, 2 ); + * @example + * + */ + do_action( 'um_after_member_role_upgrade', array( $value ), $old_roles ); + + $response['success'] = __( 'User role has been changed.', 'ultimate-member' ); + break; + default: + update_user_meta( $id, $data, esc_attr( $value ) ); + $response['success'] = __('User meta has been changed.','ultimate-member'); + break; + } + + return $response; + } + + + /** + * Process Get users API Request + * + * @param $args + * + * @return array + */ + public function get_users( $args ) { + extract( $args ); + + $response = array(); + $error = array(); + + if ( !$number ) + $number = 10; + + if ( !$orderby ) + $orderby = 'user_registered'; + + if ( !$order ) + $order = 'desc'; + + $loop_a = array('number' => $number, 'orderby' => $orderby, 'order' => $order ); + + if ( $include ) { + $include = explode(',', $include ); + $loop_a['include'] = $include; + } + + if ( $exclude ) { + $exclude = explode(',', $exclude ); + $loop_a['exclude'] = $exclude; + } + + $loop = get_users( $loop_a ); + + foreach( $loop as $user ) { + + unset( $user->data->user_status ); + unset( $user->data->user_activation_key ); + unset( $user->data->user_pass ); + + um_fetch_user( $user->ID ); + + foreach( $user as $key => $val ) { + if ( $key != 'data' ) continue; + if ( $key == 'data' ) { + $key = 'profile'; + $val->roles = $user->roles; + $val->first_name = um_user('first_name'); + $val->last_name = um_user('last_name'); + $val->account_status = um_user('account_status'); + $val->profile_pic_original = $this->getsrc( um_user('profile_photo', 'original') ); + $val->profile_pic_normal = $this->getsrc( um_user('profile_photo', 200) ); + $val->profile_pic_small = $this->getsrc( um_user('profile_photo', 40) ); + $val->cover_photo = $this->getsrc( um_user('cover_photo', 1000) ); + + /** + * UM hook + * + * @type filter + * @title um_rest_userdata + * @description Change output data for Rest API userdata call + * @input_vars + * [{"var":"$value","type":"array","desc":"Output Data"}, + * {"var":"$user_id","type":"string","desc":"User ID"}] + * @change_log + * ["Since: 2.0"] + * @usage + * + * @example + * + */ + $val = apply_filters( 'um_rest_userdata', $val, $user->ID ); + } + $response[ $user->ID ] = $val; + } + + } + + return $response; + } + + + /** + * Process delete user via API + * + * @param $args + * + * @return array + */ + public function delete_user( $args ) { + extract( $args ); + + $response = array(); + $error = array(); + + if ( !isset( $id ) ) { + $error['error'] = __('You must provide a user ID','ultimate-member'); + return $error; + } + + $user = get_userdata( $id ); + if ( !$user ) { + $error['error'] = __('Invalid user specified','ultimate-member'); + return $error; + } + + um_fetch_user( $id ); + UM()->user()->delete(); + + $response['success'] = __('User has been successfully deleted.','ultimate-member'); + + return $response; + } + + + /** + * Process Get user API Request + * + * @param $args + * + * @return array|mixed|void + */ + public function get_auser( $args ) { + extract( $args ); + + $response = array(); + $error = array(); + + if ( !isset( $id ) ) { + $error['error'] = __('You must provide a user ID','ultimate-member'); + return $error; + } + + $user = get_userdata( $id ); + if ( ! $user ) { + $error['error'] = __('Invalid user specified','ultimate-member'); + return $error; + } + + unset( $user->data->user_status ); + unset( $user->data->user_activation_key ); + unset( $user->data->user_pass ); + + um_fetch_user( $user->ID ); + + if ( isset( $fields ) && $fields ) { + $fields = explode(',', $fields ); + $response['ID'] = $user->ID; + $response['username'] = $user->user_login; + foreach ( $fields as $field ) { + + switch( $field ) { + + default: + $response[ $field ] = ( um_profile( $field ) ) ? um_profile( $field ) : ''; + + /** + * UM hook + * + * @type filter + * @title um_rest_get_auser + * @description Change output data for Rest API user authentification call + * @input_vars + * [{"var":"$response","type":"array","desc":"Output Data"}, + * {"var":"$field","type":"string","desc":"Field Key"}, + * {"var":"$user_id","type":"int","desc":"User ID"}] + * @change_log + * ["Since: 2.0"] + * @usage + * + * @example + * + */ + $response = apply_filters( 'um_rest_get_auser', $response, $field, $user->ID ); + break; + + case 'cover_photo': + $response['cover_photo'] = $this->getsrc( um_user('cover_photo', 1000) ); + break; + + case 'profile_pic': + $response['profile_pic_original'] = $this->getsrc( um_user('profile_photo', 'original') ); + $response['profile_pic_normal'] = $this->getsrc( um_user('profile_photo', 200) ); + $response['profile_pic_small'] = $this->getsrc( um_user('profile_photo', 40) ); + break; + + case 'status': + $response['status'] = um_user('account_status'); + break; + + case 'role': + //get priority role here + $response['role'] = um_user( 'role' ); + break; + + case 'email': + case 'user_email': + $response['email'] = um_user('user_email'); + break; + + } + + } + } else { + + foreach( $user as $key => $val ) { + if ( $key != 'data' ) continue; + if ( $key == 'data' ) { + $key = 'profile'; + $val->roles = $user->roles; + $val->first_name = um_user('first_name'); + $val->last_name = um_user('last_name'); + $val->account_status = um_user('account_status'); + $val->profile_pic_original = $this->getsrc( um_user('profile_photo', 'original') ); + $val->profile_pic_normal = $this->getsrc( um_user('profile_photo', 200) ); + $val->profile_pic_small = $this->getsrc( um_user('profile_photo', 40) ); + $val->cover_photo = $this->getsrc( um_user('cover_photo', 1000) ); + + /** + * UM hook + * + * @type filter + * @title um_rest_userdata + * @description Change output data for Rest API userdata call + * @input_vars + * [{"var":"$value","type":"array","desc":"Output Data"}, + * {"var":"$user_id","type":"string","desc":"User ID"}] + * @change_log + * ["Since: 2.0"] + * @usage + * + * @example + * + */ + $val = apply_filters( 'um_rest_userdata', $val, $user->ID ); + } + $response = $val; + } + + } + + return $response; + } + + + /** + * Get source + * + * @param $image + * + * @return string + */ + public function getsrc( $image ) { + if (preg_match('/ + * @example + * + */ + $accepted = apply_filters( 'um_api_valid_query_modes', array( + 'get.users', + 'get.user', + 'update.user', + 'delete.user', + 'get.following', + 'get.followers', + 'get.stats', + ) ); + + $query = isset( $wp_query->query_vars['um-api'] ) ? $wp_query->query_vars['um-api'] : null; + $error = array(); + // Make sure our query is valid + if ( ! in_array( $query, $accepted ) ) { + $error['error'] = __( 'Invalid query!', 'ultimate-member' ); + + $this->data = $error; + $this->output(); + } + + return $query; + } + + + /** + * Get page number + */ + public function get_paged() { + global $wp_query; + + return isset( $wp_query->query_vars['page'] ) ? $wp_query->query_vars['page'] : 1; + } + + + /** + * Retrieve the output format + */ + public function get_output_format() { + global $wp_query; + + $format = isset( $wp_query->query_vars['format'] ) ? $wp_query->query_vars['format'] : 'json'; + + /** + * UM hook + * + * @type filter + * @title um_api_output_format + * @description UM Rest API output format + * @input_vars + * [{"var":"$format","type":"string","desc":"Format"}] + * @change_log + * ["Since: 2.0"] + * @usage + * + * @example + * + */ + return apply_filters( 'um_api_output_format', $format ); + } + + + /** + * Log each API request, if enabled + * + * @param array $data + */ + private function log_request( $data = array() ) { + if ( ! $this->log_requests ) + return; + } + + + /** + * Retrieve the output data + */ + public function get_output() { + return $this->data; + } + + + /** + * Output Query in either JSON/XML. The query data is outputted as JSON + * by default + */ + public function output( $status_code = 200 ) { + global $wp_query; + + $format = $this->get_output_format(); + + status_header( $status_code ); + + /** + * UM hook + * + * @type action + * @title um_api_output_before + * @description Action before API output + * @input_vars + * [{"var":"$data","type":"array","desc":"API data"}, + * {"var":"$rest_api","type":"object","desc":"REST API class"}, + * {"var":"$format","type":"string","desc":"Format"}] + * @change_log + * ["Since: 2.0"] + * @usage add_action( 'um_api_output_before', 'function_name', 10, 3 ); + * @example + * + */ + do_action( 'um_api_output_before', $this->data, $this, $format ); + + switch ( $format ) : + + case 'xml' : + + require_once um_path . 'includes/lib/array2xml.php'; + $xml = Array2XML::createXML( 'um', $this->data ); + echo $xml->saveXML(); + + break; + + case 'json' : + case '' : + + header( 'Content-Type: application/json' ); + if ( ! empty( $this->pretty_print ) ) + echo json_encode( $this->data, $this->pretty_print ); + else + echo json_encode( $this->data ); + + break; + + + default : + + // Allow other formats to be added via extensions + /** + * UM hook + * + * @type action + * @title um_api_output_{$format} + * @description Action before API output + * @input_vars + * [{"var":"$data","type":"array","desc":"API data"}, + * {"var":"$rest_api","type":"object","desc":"REST API class"}] + * @change_log + * ["Since: 2.0"] + * @usage add_action( 'um_api_output_{$format}', 'function_name', 10, 2 ); + * @example + * + */ + do_action( 'um_api_output_' . $format, $this->data, $this ); + + break; + + endswitch; + + /** + * UM hook + * + * @type action + * @title um_api_output_after + * @description Action after API output + * @input_vars + * [{"var":"$data","type":"array","desc":"API data"}, + * {"var":"$rest_api","type":"object","desc":"REST API class"}, + * {"var":"$format","type":"string","desc":"Format"}] + * @change_log + * ["Since: 2.0"] + * @usage add_action( 'um_api_output_after', 'function_name', 10, 3 ); + * @example + * + */ + do_action( 'um_api_output_after', $this->data, $this, $format ); + + die(); + } + + + /** + * Modify User Profile Page fields + * + * @param $content + * @param $user + * @return string + */ + function user_key_field( $content, $user ) { + if ( empty( $user ) ) + return $content; + + if( ! isset( $user->ID ) ) + return $content; + + if ( current_user_can( 'edit_users' ) && current_user_can( 'edit_user', $user->ID ) ) { + $user = get_userdata( $user->ID ); + + ob_start(); ?> + + + + + + + + +
+ + + um_user_public_key ) ) { ?> +

+

+ +

+  um_user_public_key; ?>
+  um_user_secret_key; ?>
+  get_token( $user->ID ); ?> +

+

+

+ +
+ um_user_public_key ) ) { + update_user_meta( $user_id, 'um_user_public_key', $this->generate_public_key( $user->user_email ) ); + update_user_meta( $user_id, 'um_user_secret_key', $this->generate_private_key( $user->ID ) ); + } elseif( $regenerate == true ) { + $this->revoke_api_key( $user->ID ); + update_user_meta( $user_id, 'um_user_public_key', $this->generate_public_key( $user->user_email ) ); + update_user_meta( $user_id, 'um_user_secret_key', $this->generate_private_key( $user->ID ) ); + } else { + return false; + } + + return true; + } + + + /** + * Revoke a users API keys + * + * @param int $user_id + * + * @return bool + */ + public function revoke_api_key( $user_id = 0 ) { + + if( empty( $user_id ) ) { + return false; + } + + $user = get_userdata( $user_id ); + + if( ! $user ) { + return false; + } + + if ( ! empty( $user->um_user_public_key ) ) { + delete_transient( md5( 'um_api_user_' . $user->um_user_public_key ) ); + delete_user_meta( $user_id, 'um_user_public_key' ); + delete_user_meta( $user_id, 'um_user_secret_key' ); + } else { + return false; + } + + return true; + } + + + /** + * Generate and Save API key + * + * @param $user_id + */ + public function update_key( $user_id ) { + if ( current_user_can( 'edit_user', $user_id ) && isset( $_POST['um_set_api_key'] ) ) { + + $user = get_userdata( $user_id ); + + if ( empty( $user->um_user_public_key ) ) { + update_user_meta( $user_id, 'um_user_public_key', $this->generate_public_key( $user->user_email ) ); + update_user_meta( $user_id, 'um_user_secret_key', $this->generate_private_key( $user->ID ) ); + } else { + $this->revoke_api_key( $user_id ); + } + } + } + + + /** + * Generate the public key for a user + * + * @param string $user_email + * + * @return string + */ + private function generate_public_key( $user_email = '' ) { + $auth_key = defined( 'AUTH_KEY' ) ? AUTH_KEY : ''; + $public = hash( 'md5', $user_email . $auth_key . date( 'U' ) ); + return $public; + } + + + /** + * Generate the secret key for a user + * + * @param int $user_id + * + * @return string + */ + private function generate_private_key( $user_id = 0 ) { + $auth_key = defined( 'AUTH_KEY' ) ? AUTH_KEY : ''; + $secret = hash( 'md5', $user_id . $auth_key . date( 'U' ) ); + return $secret; + } + + + /** + * Retrieve the user's token + * + * @param int $user_id + * + * @return string + */ + private function get_token( $user_id = 0 ) { + $user = get_userdata( $user_id ); + return hash( 'md5', $user->um_user_secret_key . $user->um_user_public_key ); + } + + } } \ No newline at end of file diff --git a/includes/core/class-rewrite.php b/includes/core/class-rewrite.php index 5c01eb1d..525e7084 100644 --- a/includes/core/class-rewrite.php +++ b/includes/core/class-rewrite.php @@ -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 + * + * @example + * + */ + 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 + * + */ + 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 + * + * @example + * + */ + $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 - * - * @example - * - */ - 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 - * - */ - 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 - * - * @example - * - */ - $redirect_to = apply_filters( 'um_locate_user_profile_not_loggedin__redirect', home_url() ); - if ( ! empty( $redirect_to ) ){ - exit( wp_redirect( $redirect_to ) ); - } - - } + } - } - - } - - - } + } + + } } \ No newline at end of file diff --git a/includes/core/class-roles-capabilities.php b/includes/core/class-roles-capabilities.php index 30c3ae5e..c3f5b03c 100644 --- a/includes/core/class-roles-capabilities.php +++ b/includes/core/class-roles-capabilities.php @@ -6,269 +6,278 @@ if ( ! defined( 'ABSPATH' ) ) exit; if ( ! class_exists( 'Roles_Capabilities' ) ) { - class Roles_Capabilities { - - function __construct() { - - add_action( 'wp_roles_init', array( &$this, 'um_roles_init' ), 99999 ); - - } - /** - * Loop through dynamic roles and add them to the $wp_roles array - * - * @param null|object $wp_roles - * @return null - */ - function um_roles_init( $wp_roles = null ) { - - //Add UM role data to WP Roles - foreach ( $wp_roles->roles as $roleID => $role_data ) { - $role_meta = get_option( "um_role_{$roleID}_meta" ); - - if ( ! empty( $role_meta ) ) - $wp_roles->roles[$roleID] = array_merge( $role_data, $role_meta ); - } + /** + * Class Roles_Capabilities + * @package um\core + */ + class Roles_Capabilities { - //Add custom UM roles - $roles = array(); - - $role_keys = get_option( 'um_roles' ); - - if ( $role_keys ) { - - foreach ( $role_keys as $role_key ) { - $role_meta = get_option( "um_role_{$role_key}_meta" ); - if ( $role_meta ) { - //$role_meta['name'] = 'UM ' . $role_meta['name']; - $roles['um_' . $role_key] = $role_meta; - } - } - - foreach ( $roles as $role_id => $details ) { - $capabilities = ! empty( $details['wp_capabilities'] ) ? array_keys( $details['wp_capabilities'] ) : array(); - $details['capabilities'] = array_fill_keys( array_values( $capabilities ), true ); - unset( $details['wp_capabilities'] ); - $wp_roles->roles[$role_id] = $details; - $wp_roles->role_objects[$role_id] = new \WP_Role( $role_id, $details['capabilities'] ); - $wp_roles->role_names[$role_id] = $details['name']; - } - - } - - // Return the modified $wp_roles array - return $wp_roles; - } + /** + * Roles_Capabilities constructor. + */ + function __construct() { + add_action( 'wp_roles_init', array( &$this, 'um_roles_init' ), 99999 ); + } - /** - * Check if role is custom - * - * @param $role - * @return bool - */ - function is_role_custom( $role ) { - // User has roles so look for a UM Role one - $role_keys = get_option( 'um_roles' ); + /** + * Loop through dynamic roles and add them to the $wp_roles array + * + * @param null|object $wp_roles + * @return null + */ + function um_roles_init( $wp_roles = null ) { - if ( empty( $role_keys ) ) - return false; + //Add UM role data to WP Roles + foreach ( $wp_roles->roles as $roleID => $role_data ) { + $role_meta = get_option( "um_role_{$roleID}_meta" ); - $role_keys = array_map( function( $item ) { - return 'um_' . $item; - }, $role_keys ); - - return in_array( $role, $role_keys ); - } + if ( ! empty( $role_meta ) ) + $wp_roles->roles[$roleID] = array_merge( $role_data, $role_meta ); + } - /** - * Return a user's main role - * - * @param int $user_id - * @param string $new_role - * @uses get_userdata() To get the user data - * @uses apply_filters() Calls 'um_set_user_role' with the role and user id - * @return string - */ - function set_role( $user_id, $new_role = '' ) { - // Validate user id - $user = get_userdata( $user_id ); + //Add custom UM roles + $roles = array(); - // User exists - if ( ! empty( $user ) ) { - // Get users old UM role - $role = UM()->roles()->get_um_user_role( $user_id ); + $role_keys = get_option( 'um_roles' ); - // User already has this role so no new role is set - if ( $new_role === $role || ( ! $this->is_role_custom( $new_role ) && user_can( $user, $new_role ) ) ) { - $new_role = false; - } else { - // Users role is different than the new role + if ( $role_keys ) { - // Remove the old UM role - if ( ! empty( $role ) && $this->is_role_custom( $role ) ) { - $user->remove_role( $role ); - } + foreach ( $role_keys as $role_key ) { + $role_meta = get_option( "um_role_{$role_key}_meta" ); + if ( $role_meta ) { + //$role_meta['name'] = 'UM ' . $role_meta['name']; + $roles['um_' . $role_key] = $role_meta; + } + } - // Add the new role - if ( ! empty( $new_role ) ) { - $user->add_role( $new_role ); - } + foreach ( $roles as $role_id => $details ) { + $capabilities = ! empty( $details['wp_capabilities'] ) ? array_keys( $details['wp_capabilities'] ) : array(); + $details['capabilities'] = array_fill_keys( array_values( $capabilities ), true ); + unset( $details['wp_capabilities'] ); + $wp_roles->roles[$role_id] = $details; + $wp_roles->role_objects[$role_id] = new \WP_Role( $role_id, $details['capabilities'] ); + $wp_roles->role_names[$role_id] = $details['name']; + } - /** - * UM hook - * - * @type action - * @title um_when_role_is_set - * @description Action before user role changed - * @input_vars - * [{"var":"$user_id","type":"int","desc":"User ID"}] - * @change_log - * ["Since: 2.0"] - * @usage add_action( 'um_when_role_is_set', 'function_name', 10, 1 ); - * @example - * - */ - do_action( 'um_when_role_is_set', $user_id ); - /** - * UM hook - * - * @type action - * @title um_before_user_role_is_changed - * @description Action before user role changed - * @change_log - * ["Since: 2.0"] - * @usage add_action( 'um_before_user_role_is_changed', 'function_name', 10 ); - * @example - * - */ - do_action( 'um_before_user_role_is_changed' ); + } - UM()->user()->profile['role'] = $new_role; + // Return the modified $wp_roles array + return $wp_roles; + } - /** - * UM hook - * - * @type action - * @title um_member_role_upgrade - * @description Action on user role changed - * @input_vars - * [{"var":"$user_id","type":"int","desc":"User ID"}, - * {"var":"$role","type":"string","desc":"User role"}] - * @change_log - * ["Since: 2.0"] - * @usage add_action( 'um_member_role_upgrade', 'function_name', 10, 2 ); - * @example - * - */ - do_action( 'um_member_role_upgrade', $role, UM()->user()->profile['role'] ); - UM()->user()->update_usermeta_info( 'role' ); - /** - * UM hook - * - * @type action - * @title um_after_user_role_is_changed - * @description Action after user role changed - * @change_log - * ["Since: 2.0"] - * @usage add_action( 'um_after_user_role_is_changed', 'function_name', 10 ); - * @example - * - */ - do_action( 'um_after_user_role_is_changed' ); - /** - * UM hook - * - * @type action - * @title um_after_user_role_is_updated - * @description Action after user role changed - * @input_vars - * [{"var":"$user_id","type":"int","desc":"User ID"}, - * {"var":"$role","type":"string","desc":"User role"}] - * @change_log - * ["Since: 2.0"] - * @usage add_action( 'um_after_user_role_is_updated', 'function_name', 10, 2 ); - * @example - * - */ - do_action( 'um_after_user_role_is_updated', $user_id, $role ); - } - } else { - // User does don exist so return false - $new_role = false; - } + /** + * Check if role is custom + * + * @param $role + * @return bool + */ + function is_role_custom( $role ) { + // User has roles so look for a UM Role one + $role_keys = get_option( 'um_roles' ); - /** - * UM hook - * - * @type filter - * @title um_set_user_role - * @description User role was changed - * @input_vars - * [{"var":"$new_role","type":"string","desc":"New role"}, - * {"var":"$user_id","type":"int","desc":"User ID"}, - * {"var":"$user","type":"array","desc":"Userdata"}] - * @change_log - * ["Since: 2.0"] - * @usage - * - * @example - * - */ - return apply_filters( 'um_set_user_role', $new_role, $user_id, $user ); - } + if ( empty( $role_keys ) ) + return false; - /** - * Remove user role - * - * @param $user_id - * @param $role - */ - function remove_role( $user_id, $role ) { - // Validate user id - $user = get_userdata( $user_id ); + $role_keys = array_map( function( $item ) { + return 'um_' . $item; + }, $role_keys ); - // User exists - if ( ! empty( $user ) ) { - // Remove role - $user->remove_role( $role ); - } - } + return in_array( $role, $role_keys ); + } + + + /** + * Return a user's main role + * + * @param int $user_id + * @param string $new_role + * @uses get_userdata() To get the user data + * @uses apply_filters() Calls 'um_set_user_role' with the role and user id + * @return string + */ + function set_role( $user_id, $new_role = '' ) { + // Validate user id + $user = get_userdata( $user_id ); + + // User exists + if ( ! empty( $user ) ) { + // Get users old UM role + $role = UM()->roles()->get_um_user_role( $user_id ); + + // User already has this role so no new role is set + if ( $new_role === $role || ( ! $this->is_role_custom( $new_role ) && user_can( $user, $new_role ) ) ) { + $new_role = false; + } else { + // Users role is different than the new role + + // Remove the old UM role + if ( ! empty( $role ) && $this->is_role_custom( $role ) ) { + $user->remove_role( $role ); + } + + // Add the new role + if ( ! empty( $new_role ) ) { + $user->add_role( $new_role ); + } + + /** + * UM hook + * + * @type action + * @title um_when_role_is_set + * @description Action before user role changed + * @input_vars + * [{"var":"$user_id","type":"int","desc":"User ID"}] + * @change_log + * ["Since: 2.0"] + * @usage add_action( 'um_when_role_is_set', 'function_name', 10, 1 ); + * @example + * + */ + do_action( 'um_when_role_is_set', $user_id ); + /** + * UM hook + * + * @type action + * @title um_before_user_role_is_changed + * @description Action before user role changed + * @change_log + * ["Since: 2.0"] + * @usage add_action( 'um_before_user_role_is_changed', 'function_name', 10 ); + * @example + * + */ + do_action( 'um_before_user_role_is_changed' ); + + UM()->user()->profile['role'] = $new_role; + + /** + * UM hook + * + * @type action + * @title um_member_role_upgrade + * @description Action on user role changed + * @input_vars + * [{"var":"$user_id","type":"int","desc":"User ID"}, + * {"var":"$role","type":"string","desc":"User role"}] + * @change_log + * ["Since: 2.0"] + * @usage add_action( 'um_member_role_upgrade', 'function_name', 10, 2 ); + * @example + * + */ + do_action( 'um_member_role_upgrade', $role, UM()->user()->profile['role'] ); + + UM()->user()->update_usermeta_info( 'role' ); + /** + * UM hook + * + * @type action + * @title um_after_user_role_is_changed + * @description Action after user role changed + * @change_log + * ["Since: 2.0"] + * @usage add_action( 'um_after_user_role_is_changed', 'function_name', 10 ); + * @example + * + */ + do_action( 'um_after_user_role_is_changed' ); + /** + * UM hook + * + * @type action + * @title um_after_user_role_is_updated + * @description Action after user role changed + * @input_vars + * [{"var":"$user_id","type":"int","desc":"User ID"}, + * {"var":"$role","type":"string","desc":"User role"}] + * @change_log + * ["Since: 2.0"] + * @usage add_action( 'um_after_user_role_is_updated', 'function_name', 10, 2 ); + * @example + * + */ + do_action( 'um_after_user_role_is_updated', $user_id, $role ); + } + } else { + // User does don exist so return false + $new_role = false; + } + + /** + * UM hook + * + * @type filter + * @title um_set_user_role + * @description User role was changed + * @input_vars + * [{"var":"$new_role","type":"string","desc":"New role"}, + * {"var":"$user_id","type":"int","desc":"User ID"}, + * {"var":"$user","type":"array","desc":"Userdata"}] + * @change_log + * ["Since: 2.0"] + * @usage + * + * @example + * + */ + return apply_filters( 'um_set_user_role', $new_role, $user_id, $user ); + } + + + /** + * Remove user role + * + * @param $user_id + * @param $role + */ + function remove_role( $user_id, $role ) { + // Validate user id + $user = get_userdata( $user_id ); + + // User exists + if ( ! empty( $user ) ) { + // Remove role + $user->remove_role( $role ); + } + } /** @@ -284,300 +293,300 @@ if ( ! class_exists( 'Roles_Capabilities' ) ) { /** - * Get user one of UM roles if it has it - * - * @deprecated since 2.0 - * @param int $user_id - * @return bool|mixed - */ + * Get user one of UM roles if it has it + * + * @deprecated since 2.0 + * @param int $user_id + * @return bool|mixed + */ function um_get_user_role( $user_id ) { return $this->get_um_user_role( $user_id ); } - /** - * @param $user_id - * - * @return array|bool - */ - function get_all_user_roles( $user_id ) { - $user = get_userdata( $user_id ); + /** + * @param $user_id + * + * @return array|bool + */ + function get_all_user_roles( $user_id ) { + $user = get_userdata( $user_id ); - if ( empty( $user->roles ) ) { - return false; - } + if ( empty( $user->roles ) ) { + return false; + } - return array_values( $user->roles ); - } - - - /** - * @param $user_id - * - * @return bool|mixed - */ - function get_priority_user_role( $user_id ) { - $user = get_userdata( $user_id ); - - if ( empty( $user->roles ) ) - return false; - - // User has roles so look for a UM Role one - $um_roles_keys = get_option( 'um_roles' ); - - if ( ! empty( $um_roles_keys ) ) { - $um_roles_keys = array_map( function( $item ) { - return 'um_' . $item; - }, $um_roles_keys ); - } - - $orders = array(); - foreach ( array_values( $user->roles ) as $userrole ) { - if ( ! empty( $um_roles_keys ) && in_array( $userrole, $um_roles_keys ) ) { - $userrole_metakey = substr( $userrole, 3 ); - } else { - $userrole_metakey = $userrole; - } - - $rolemeta = get_option( "um_role_{$userrole_metakey}_meta", false ); - - if ( ! $rolemeta ) { - $orders[ $userrole ] = 0; - continue; - } - - $orders[ $userrole ] = ! empty( $rolemeta['_um_priority'] ) ? $rolemeta['_um_priority'] : 0; - } - - arsort( $orders ); - $roles_in_priority = array_keys( $orders ); - - return array_shift( $roles_in_priority ); - } - - - /** - * @return array - */ - function get_editable_user_roles() { - // User has roles so look for a UM Role one - $um_roles_keys = get_option( 'um_roles' ); - - if ( ! empty( $um_roles_keys ) ) { - $um_roles_keys = array_map( function( $item ) { - return 'um_' . $item; - }, $um_roles_keys ); - } - - return array_merge( $um_roles_keys, array( 'subscriber' ) ); - } - - - /** - * @param $user_id - * - * @return bool|mixed - */ - function get_editable_priority_user_role( $user_id ) { - $user = get_userdata( $user_id ); - - if ( empty( $user->roles ) ) - return false; - - // User has roles so look for a UM Role one - $um_roles_keys = get_option( 'um_roles' ); - - if ( ! empty( $um_roles_keys ) ) { - $um_roles_keys = array_map( function( $item ) { - return 'um_' . $item; - }, $um_roles_keys ); - } - - $orders = array(); - foreach ( array_values( $user->roles ) as $userrole ) { - if ( ! empty( $um_roles_keys ) && in_array( $userrole, $um_roles_keys ) ) { - $userrole_metakey = substr( $userrole, 3 ); - } else { - $userrole_metakey = $userrole; - } - - $rolemeta = get_option( "um_role_{$userrole_metakey}_meta", false ); - - if ( ! $rolemeta ) { - $orders[ $userrole ] = 0; - continue; - } - - $orders[ $userrole ] = ! empty( $rolemeta['_um_priority'] ) ? $rolemeta['_um_priority'] : 0; - } - - arsort( $orders ); - $roles_in_priority = array_keys( $orders ); - $roles_in_priority = array_intersect( $roles_in_priority, $this->get_editable_user_roles() ); - - return array_shift( $roles_in_priority ); - } - - - /** - * @param $user_id - * - * @return bool|mixed - */ - function get_um_user_role( $user_id ) { - // User has roles so look for a UM Role one - $um_roles_keys = get_option( 'um_roles' ); - - if ( empty( $um_roles_keys ) ) - return false; - - $user = get_userdata( $user_id ); - - if ( empty( $user->roles ) ) - return false; - - $um_roles_keys = array_map( function( $item ) { - return 'um_' . $item; - }, $um_roles_keys ); - - $user_um_roles_array = array_intersect( $um_roles_keys, array_values( $user->roles ) ); - - if ( empty( $user_um_roles_array ) ) - return false; - - return array_shift( $user_um_roles_array ); - } - - - /** - * Get role name by roleID - * - * @param $slug - * @return bool|string - */ - function get_role_name( $slug ) { - $roledata = $this->role_data( $slug ); - - if ( empty( $roledata['name'] ) ) { - global $wp_roles; - - if ( empty( $wp_roles->roles[$slug] ) ) - return false; - else - return $wp_roles->roles[$slug]['name']; - } - - - return $roledata['name']; - } - - - /** - * Get role data - * - * @param int $roleID Role ID - * @return mixed|void - */ - function role_data( $roleID ) { - if ( strpos( $roleID, 'um_' ) === 0 ) - $roleID = substr( $roleID, 3 ); - - $role_data = get_option( "um_role_{$roleID}_meta" ); - - if ( ! $role_data ) - return array(); - - $temp = array(); - foreach ( $role_data as $key=>$value ) { - if ( strpos( $key, '_um_' ) === 0 ) - $key = str_replace( '_um_', '', $key ); - $temp[$key] = $value; - } - return $temp; - } - - - /** - * Query for UM roles - * - * @param bool $add_default - * @param null $exclude - * - * @return array - */ - function get_roles( $add_default = false, $exclude = null ){ - global $wp_roles; - - if ( empty( $wp_roles ) ) { - return array(); - } - - $roles = $wp_roles->role_names; - - if ( $add_default ) { - $roles[0] = $add_default; - } - - if ( $exclude ) { - foreach( $exclude as $role ) { - unset( $roles[$role] ); - } - } - - return $roles; - } - - - /** - * Current user can - * - * @param $cap - * @param $user_id - * - * @return bool|int - */ - function um_current_user_can( $cap, $user_id ) { - if ( ! is_user_logged_in() ) - return false; - - $return = 1; - - um_fetch_user( get_current_user_id() ); - - $current_user_roles = UM()->roles()->get_all_user_roles( $user_id ); - switch( $cap ) { - case 'edit': - if ( get_current_user_id() == $user_id && um_user( 'can_edit_profile' ) ) - $return = 1; - elseif ( ! um_user( 'can_edit_everyone' ) ) - $return = 0; - elseif ( get_current_user_id() == $user_id && ! um_user( 'can_edit_profile') ) - $return = 0; - elseif ( um_user( 'can_edit_roles' ) && ( empty( $current_user_roles ) || count( array_intersect( $current_user_roles, um_user( 'can_edit_roles' ) ) ) <= 0 ) ) - $return = 0; - break; - - case 'delete': - if ( ! um_user( 'can_delete_everyone' ) ) - $return = 0; - elseif ( um_user( 'can_delete_roles' ) && ( empty( $current_user_roles ) || count( array_intersect( $current_user_roles, um_user( 'can_delete_roles' ) ) ) <= 0 ) ) - $return = 0; - break; - - } - - um_fetch_user( $user_id ); - - return $return; - } + return array_values( $user->roles ); + } /** - * User can ( role settings ) - * - * @param $permission - * @return bool|mixed - */ + * @param $user_id + * + * @return bool|mixed + */ + function get_priority_user_role( $user_id ) { + $user = get_userdata( $user_id ); + + if ( empty( $user->roles ) ) + return false; + + // User has roles so look for a UM Role one + $um_roles_keys = get_option( 'um_roles' ); + + if ( ! empty( $um_roles_keys ) ) { + $um_roles_keys = array_map( function( $item ) { + return 'um_' . $item; + }, $um_roles_keys ); + } + + $orders = array(); + foreach ( array_values( $user->roles ) as $userrole ) { + if ( ! empty( $um_roles_keys ) && in_array( $userrole, $um_roles_keys ) ) { + $userrole_metakey = substr( $userrole, 3 ); + } else { + $userrole_metakey = $userrole; + } + + $rolemeta = get_option( "um_role_{$userrole_metakey}_meta", false ); + + if ( ! $rolemeta ) { + $orders[ $userrole ] = 0; + continue; + } + + $orders[ $userrole ] = ! empty( $rolemeta['_um_priority'] ) ? $rolemeta['_um_priority'] : 0; + } + + arsort( $orders ); + $roles_in_priority = array_keys( $orders ); + + return array_shift( $roles_in_priority ); + } + + + /** + * @return array + */ + function get_editable_user_roles() { + // User has roles so look for a UM Role one + $um_roles_keys = get_option( 'um_roles' ); + + if ( ! empty( $um_roles_keys ) ) { + $um_roles_keys = array_map( function( $item ) { + return 'um_' . $item; + }, $um_roles_keys ); + } + + return array_merge( $um_roles_keys, array( 'subscriber' ) ); + } + + + /** + * @param $user_id + * + * @return bool|mixed + */ + function get_editable_priority_user_role( $user_id ) { + $user = get_userdata( $user_id ); + + if ( empty( $user->roles ) ) + return false; + + // User has roles so look for a UM Role one + $um_roles_keys = get_option( 'um_roles' ); + + if ( ! empty( $um_roles_keys ) ) { + $um_roles_keys = array_map( function( $item ) { + return 'um_' . $item; + }, $um_roles_keys ); + } + + $orders = array(); + foreach ( array_values( $user->roles ) as $userrole ) { + if ( ! empty( $um_roles_keys ) && in_array( $userrole, $um_roles_keys ) ) { + $userrole_metakey = substr( $userrole, 3 ); + } else { + $userrole_metakey = $userrole; + } + + $rolemeta = get_option( "um_role_{$userrole_metakey}_meta", false ); + + if ( ! $rolemeta ) { + $orders[ $userrole ] = 0; + continue; + } + + $orders[ $userrole ] = ! empty( $rolemeta['_um_priority'] ) ? $rolemeta['_um_priority'] : 0; + } + + arsort( $orders ); + $roles_in_priority = array_keys( $orders ); + $roles_in_priority = array_intersect( $roles_in_priority, $this->get_editable_user_roles() ); + + return array_shift( $roles_in_priority ); + } + + + /** + * @param $user_id + * + * @return bool|mixed + */ + function get_um_user_role( $user_id ) { + // User has roles so look for a UM Role one + $um_roles_keys = get_option( 'um_roles' ); + + if ( empty( $um_roles_keys ) ) + return false; + + $user = get_userdata( $user_id ); + + if ( empty( $user->roles ) ) + return false; + + $um_roles_keys = array_map( function( $item ) { + return 'um_' . $item; + }, $um_roles_keys ); + + $user_um_roles_array = array_intersect( $um_roles_keys, array_values( $user->roles ) ); + + if ( empty( $user_um_roles_array ) ) + return false; + + return array_shift( $user_um_roles_array ); + } + + + /** + * Get role name by roleID + * + * @param $slug + * @return bool|string + */ + function get_role_name( $slug ) { + $roledata = $this->role_data( $slug ); + + if ( empty( $roledata['name'] ) ) { + global $wp_roles; + + if ( empty( $wp_roles->roles[$slug] ) ) + return false; + else + return $wp_roles->roles[$slug]['name']; + } + + + return $roledata['name']; + } + + + /** + * Get role data + * + * @param int $roleID Role ID + * @return mixed|void + */ + function role_data( $roleID ) { + if ( strpos( $roleID, 'um_' ) === 0 ) + $roleID = substr( $roleID, 3 ); + + $role_data = get_option( "um_role_{$roleID}_meta" ); + + if ( ! $role_data ) + return array(); + + $temp = array(); + foreach ( $role_data as $key=>$value ) { + if ( strpos( $key, '_um_' ) === 0 ) + $key = str_replace( '_um_', '', $key ); + $temp[$key] = $value; + } + return $temp; + } + + + /** + * Query for UM roles + * + * @param bool $add_default + * @param null $exclude + * + * @return array + */ + function get_roles( $add_default = false, $exclude = null ){ + global $wp_roles; + + if ( empty( $wp_roles ) ) { + return array(); + } + + $roles = $wp_roles->role_names; + + if ( $add_default ) { + $roles[0] = $add_default; + } + + if ( $exclude ) { + foreach( $exclude as $role ) { + unset( $roles[$role] ); + } + } + + return $roles; + } + + + /** + * Current user can + * + * @param $cap + * @param $user_id + * + * @return bool|int + */ + function um_current_user_can( $cap, $user_id ) { + if ( ! is_user_logged_in() ) + return false; + + $return = 1; + + um_fetch_user( get_current_user_id() ); + + $current_user_roles = UM()->roles()->get_all_user_roles( $user_id ); + switch( $cap ) { + case 'edit': + if ( get_current_user_id() == $user_id && um_user( 'can_edit_profile' ) ) + $return = 1; + elseif ( ! um_user( 'can_edit_everyone' ) ) + $return = 0; + elseif ( get_current_user_id() == $user_id && ! um_user( 'can_edit_profile') ) + $return = 0; + elseif ( um_user( 'can_edit_roles' ) && ( empty( $current_user_roles ) || count( array_intersect( $current_user_roles, um_user( 'can_edit_roles' ) ) ) <= 0 ) ) + $return = 0; + break; + + case 'delete': + if ( ! um_user( 'can_delete_everyone' ) ) + $return = 0; + elseif ( um_user( 'can_delete_roles' ) && ( empty( $current_user_roles ) || count( array_intersect( $current_user_roles, um_user( 'can_delete_roles' ) ) ) <= 0 ) ) + $return = 0; + break; + + } + + um_fetch_user( $user_id ); + + return $return; + } + + + /** + * User can ( role settings ) + * + * @param $permission + * @return bool|mixed + */ function um_user_can( $permission ) { if ( ! is_user_logged_in() ) return false; @@ -618,5 +627,5 @@ if ( ! class_exists( 'Roles_Capabilities' ) ) { return false; } - } + } } \ No newline at end of file diff --git a/includes/core/class-router.php b/includes/core/class-router.php index 9e068f60..0a26b5ed 100644 --- a/includes/core/class-router.php +++ b/includes/core/class-router.php @@ -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' ) ); + } + } - } + } } \ No newline at end of file diff --git a/includes/core/class-setup.php b/includes/core/class-setup.php index aca5c421..e01bb271 100644 --- a/includes/core/class-setup.php +++ b/includes/core/class-setup.php @@ -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 ); + } + } + } } \ No newline at end of file diff --git a/includes/core/class-shortcodes.php b/includes/core/class-shortcodes.php index e923095c..d5b5e29a 100644 --- a/includes/core/class-shortcodes.php +++ b/includes/core/class-shortcodes.php @@ -5,746 +5,797 @@ namespace um\core; if ( ! defined( 'ABSPATH' ) ) exit; if ( ! class_exists( 'Shortcodes' ) ) { - class Shortcodes { - function __construct() { - $this->message_mode = false; - $this->custom_message = ''; - - $this->loop = array(); - - add_shortcode( 'ultimatemember', array( &$this, 'ultimatemember' ) ); - - add_shortcode( 'um_loggedin', array( &$this, 'um_loggedin' ) ); - add_shortcode( 'um_loggedout', array( &$this, 'um_loggedout' ) ); - add_shortcode( 'um_show_content', array( &$this, 'um_shortcode_show_content_for_role' ) ); - add_shortcode( 'ultimatemember_searchform', array( &$this, 'ultimatemember_searchform' ) ); - - - add_filter( 'body_class', array( &$this, 'body_class' ), 0 ); - add_action( 'template_redirect', array( &$this, 'is_um_page' ) ); - - add_filter( 'um_shortcode_args_filter', array( &$this, 'display_logout_form' ), 99 ); - add_filter( 'um_shortcode_args_filter', array( &$this, 'parse_shortcode_args' ), 99 ); - - /** - * UM hook - * - * @type filter - * @title um_emoji_base_uri - * @description Change Emoji base URL - * @input_vars - * [{"var":"$url","type":"string","desc":"Base URL"}] - * @change_log - * ["Since: 2.0"] - * @usage - * - * @example - * - */ - $base_uri = apply_filters( 'um_emoji_base_uri', 'https://s.w.org/images/core/emoji/' ); - - $this->emoji[':)'] = $base_uri . '72x72/1f604.png'; - $this->emoji[':smiley:'] = $base_uri . '72x72/1f603.png'; - $this->emoji[':D'] = $base_uri . '72x72/1f600.png'; - $this->emoji[':$'] = $base_uri . '72x72/1f60a.png'; - $this->emoji[':relaxed:'] = $base_uri . '72x72/263a.png'; - $this->emoji[';)'] = $base_uri . '72x72/1f609.png'; - $this->emoji[':heart_eyes:'] = $base_uri . '72x72/1f60d.png'; - $this->emoji[':kissing_heart:'] = $base_uri . '72x72/1f618.png'; - $this->emoji[':kissing_closed_eyes:'] = $base_uri . '72x72/1f61a.png'; - $this->emoji[':kissing:'] = $base_uri . '72x72/1f617.png'; - $this->emoji[':kissing_smiling_eyes:'] = $base_uri . '72x72/1f619.png'; - $this->emoji[';P'] = $base_uri . '72x72/1f61c.png'; - $this->emoji[':P'] = $base_uri . '72x72/1f61b.png'; - $this->emoji[':stuck_out_tongue_closed_eyes:'] = $base_uri . '72x72/1f61d.png'; - $this->emoji[':flushed:'] = $base_uri . '72x72/1f633.png'; - $this->emoji[':grin:'] = $base_uri . '72x72/1f601.png'; - $this->emoji[':pensive:'] = $base_uri . '72x72/1f614.png'; - $this->emoji[':relieved:'] = $base_uri . '72x72/1f60c.png'; - $this->emoji[':unamused'] = $base_uri . '72x72/1f612.png'; - $this->emoji[':('] = $base_uri . '72x72/1f61e.png'; - $this->emoji[':persevere:'] = $base_uri . '72x72/1f623.png'; - $this->emoji[":'("] = $base_uri . '72x72/1f622.png'; - $this->emoji[':joy:'] = $base_uri . '72x72/1f602.png'; - $this->emoji[':sob:'] = $base_uri . '72x72/1f62d.png'; - $this->emoji[':sleepy:'] = $base_uri . '72x72/1f62a.png'; - $this->emoji[':disappointed_relieved:'] = $base_uri . '72x72/1f625.png'; - $this->emoji[':cold_sweat:'] = $base_uri . '72x72/1f630.png'; - $this->emoji[':sweat_smile:'] = $base_uri . '72x72/1f605.png'; - $this->emoji[':sweat:'] = $base_uri . '72x72/1f613.png'; - $this->emoji[':weary:'] = $base_uri . '72x72/1f629.png'; - $this->emoji[':tired_face:'] = $base_uri . '72x72/1f62b.png'; - $this->emoji[':fearful:'] = $base_uri . '72x72/1f628.png'; - $this->emoji[':scream:'] = $base_uri . '72x72/1f631.png'; - $this->emoji[':angry:'] = $base_uri . '72x72/1f620.png'; - $this->emoji[':rage:'] = $base_uri . '72x72/1f621.png'; - $this->emoji[':triumph'] = $base_uri . '72x72/1f624.png'; - $this->emoji[':confounded:'] = $base_uri . '72x72/1f616.png'; - $this->emoji[':laughing:'] = $base_uri . '72x72/1f606.png'; - $this->emoji[':yum:'] = $base_uri . '72x72/1f60b.png'; - $this->emoji[':mask:'] = $base_uri . '72x72/1f637.png'; - $this->emoji[':cool:'] = $base_uri . '72x72/1f60e.png'; - $this->emoji[':sleeping:'] = $base_uri . '72x72/1f634.png'; - $this->emoji[':dizzy_face:'] = $base_uri . '72x72/1f635.png'; - $this->emoji[':astonished:'] = $base_uri . '72x72/1f632.png'; - $this->emoji[':worried:'] = $base_uri . '72x72/1f61f.png'; - $this->emoji[':frowning:'] = $base_uri . '72x72/1f626.png'; - $this->emoji[':anguished:'] = $base_uri . '72x72/1f627.png'; - $this->emoji[':smiling_imp:'] = $base_uri . '72x72/1f608.png'; - $this->emoji[':imp:'] = $base_uri . '72x72/1f47f.png'; - $this->emoji[':open_mouth:'] = $base_uri . '72x72/1f62e.png'; - $this->emoji[':grimacing:'] = $base_uri . '72x72/1f62c.png'; - $this->emoji[':neutral_face:'] = $base_uri . '72x72/1f610.png'; - $this->emoji[':confused:'] = $base_uri . '72x72/1f615.png'; - $this->emoji[':hushed:'] = $base_uri . '72x72/1f62f.png'; - $this->emoji[':no_mouth:'] = $base_uri . '72x72/1f636.png'; - $this->emoji[':innocent:'] = $base_uri . '72x72/1f607.png'; - $this->emoji[':smirk:'] = $base_uri . '72x72/1f60f.png'; - $this->emoji[':expressionless:'] = $base_uri . '72x72/1f611.png'; - - } - - - /** - * Conditional logout form - * - * @param array $args - * - * @return array - */ - function display_logout_form( $args ) { - if ( is_user_logged_in() && isset( $args['mode'] ) && $args['mode'] == 'login' ) { - - if ( get_current_user_id() != um_user( 'ID' ) ) { - um_fetch_user( get_current_user_id() ); - } - - $args['template'] = 'logout'; - } - - return $args; - } - - - /** - * Filter shortcode args - * - * @param array $args - * - * @return array - */ - function parse_shortcode_args( $args ) { - if ( $this->message_mode == true ) { - - if ( ! empty( $_REQUEST['um_role'] ) ) { - $args['template'] = 'message'; - $roleID = esc_attr( $_REQUEST['um_role'] ); - $role = UM()->roles()->role_data( $roleID ); - - if ( ! empty( $role ) && ! empty( $role["status"] ) ) { - $message_key = $role["status"] . '_message'; - $this->custom_message = ! empty( $role[ $message_key ] ) ? $role[ $message_key ] : ''; - } - } - - } - - foreach ( $args as $k => $v ) { - $args[ $k ] = maybe_unserialize( $args[ $k ] ); - } - - return $args; - } - - - /*** - *** @emoji support - */ - function emotize($content) { - $content = stripslashes($content); - foreach ($this->emoji as $code => $val) { - $regex = str_replace(array('(', ')'), array("\\" . '(', "\\" . ')'), $code); - $content = preg_replace('/(' . $regex . ')(\s|$)/', '' . $code . '$2', $content); - } - return $content; - } - - - /** - * Remove wpautop filter for post content if it's UM core page - */ - function is_um_page() { - if ( is_ultimatemember() ) { - remove_filter( 'the_content', 'wpautop' ); - } - } - - - /*** - *** @extend body classes - */ - function body_class($classes) { - $array = UM()->config()->permalinks; - if (!$array) { - return $classes; - } - - foreach ($array as $slug => $info) { - if (um_is_core_page($slug)) { - - $classes[] = 'um-page-' . $slug; - - if (is_user_logged_in()) { - $classes[] = 'um-page-loggedin'; - } else { - $classes[] = 'um-page-loggedout'; - } - - } - } - - if( um_is_core_page('user') && um_is_user_himself() ){ - $classes[] = 'um-own-profile'; - } - - return $classes; - } - - /*** - *** @Retrieve core login form - */ - function core_login_form() { - $forms = get_posts(array('post_type' => 'um_form', 'posts_per_page' => 1, 'meta_key' => '_um_core', 'meta_value' => 'login')); - $form_id = isset( $forms[0]->ID ) ? $forms[0]->ID: 0; - - return $form_id; - } - - - /** - * Load a compatible template - * - * @param $tpl - */ - function load_template( $tpl ) { - $loop = ( $this->loop ) ? $this->loop : array(); - - if ( isset( $this->set_args ) && is_array( $this->set_args ) ) { - $args = $this->set_args; - - unset( $args['file'] ); - unset( $args['theme_file'] ); - unset( $args['tpl'] ); - - extract( $args ); - } - - $file = um_path . "templates/{$tpl}.php"; - $theme_file = get_stylesheet_directory() . "/ultimate-member/templates/{$tpl}.php"; - - - if ( file_exists( $theme_file ) ) { - $file = $theme_file; - } - - if ( file_exists( $file ) ) { - - include $file; - } - } - - - /*** - *** @Add class based on shortcode - */ - function get_class($mode, $args = array()) { - - $classes = 'um-' . $mode; - - if (is_admin()) { - $classes .= ' um-in-admin'; - } - - if (isset(UM()->form()->errors) && UM()->form()->errors) { - $classes .= ' um-err'; - } - - if (UM()->fields()->editing == true) { - $classes .= ' um-editing'; - } - - if (UM()->fields()->viewing == true) { - $classes .= ' um-viewing'; - } - - if (isset($args['template']) && $args['template'] != $args['mode']) { - $classes .= ' um-' . $args['template']; - } - - /** - * UM hook - * - * @type filter - * @title um_form_official_classes__hook - * @description Change official form classes - * @input_vars - * [{"var":"$classes","type":"string","desc":"Classes string"}] - * @change_log - * ["Since: 2.0"] - * @usage - * - * @example - * - */ - $classes = apply_filters( 'um_form_official_classes__hook', $classes ); - return $classes; - } - - /** - * Logged-in only content - * - * @param array $args - * @param string $content - * - * @return string - */ - function um_loggedin( $args = array(), $content = "" ) { - ob_start(); - - $defaults = array( - 'lock_text' => __( 'This content has been restricted to logged in users only. Please login to view this content.', 'ultimate-member' ), - 'show_lock' => 'yes', - ); - - $args = wp_parse_args( $args, $defaults ); - - $args['lock_text'] = $this->convert_locker_tags( $args['lock_text'] ); - - if ( ! is_user_logged_in() ) { - if ( $args['show_lock'] == 'no' ) { - echo ''; - } else { - $this->set_args = $args; - $this->load_template( 'login-to-view' ); - } - } else { - echo do_shortcode( $this->convert_locker_tags( wpautop( $content ) ) ); - } - - $output = ob_get_clean(); - return $output; - } - - /*** - *** @Logged-out only content - */ - function um_loggedout($args = array(), $content = "") { - ob_start(); - - // Hide for logged in users - if (is_user_logged_in()) { - echo ''; - } else { - echo do_shortcode(wpautop($content)); - } - - $output = ob_get_contents(); - ob_end_clean(); - return $output; - } - - /*** - *** @Shortcode - */ - function ultimatemember($args = array()) { - return $this->load($args); - } - - /*** - *** @Load a module with global function - */ - function load($args) { - ob_start(); - - $defaults = array(); - $args = wp_parse_args($args, $defaults); - - // when to not continue - $this->form_id = (isset($args['form_id'])) ? $args['form_id'] : null; - if (!$this->form_id) { - return; - } - - $this->form_status = get_post_status($this->form_id); - if ($this->form_status != 'publish') { - return; - } - - // get data into one global array - $post_data = UM()->query()->post_data($this->form_id); - - /** - * UM hook - * - * @type filter - * @title um_pre_args_setup - * @description Change arguments on load shortcode - * @input_vars - * [{"var":"$post_data","type":"string","desc":"$_POST data"}] - * @change_log - * ["Since: 2.0"] - * @usage - * - * @example - * - */ - $args = apply_filters( 'um_pre_args_setup', $post_data ); - - if (!isset($args['template'])) { - $args['template'] = ''; - } - - if (isset($post_data['template']) && $post_data['template'] != $args['template']) { - $args['template'] = $post_data['template']; - } - - if (!$this->template_exists($args['template'])) { - $args['template'] = $post_data['mode']; - } - - if (!isset($post_data['template'])) { - $post_data['template'] = $post_data['mode']; - } - - if( 'directory' != $args['mode'] ) { - - $args = array_merge( $post_data, $args ); - - if (empty( $args['use_custom_settings'] )) { - $args = array_merge( $args, $this->get_css_args( $args ) ); - } else { - $args = array_merge( $this->get_css_args( $args ), $args ); - } - } - // filter for arguments - - /** - * UM hook - * - * @type filter - * @title um_shortcode_args_filter - * @description Change arguments on load shortcode - * @input_vars - * [{"var":"$args","type":"string","desc":"Shortcode arguments"}] - * @change_log - * ["Since: 2.0"] - * @usage - * - * @example - * - */ - $args = apply_filters( 'um_shortcode_args_filter', $args ); - - extract($args, EXTR_SKIP); - - if ( 'register' == $mode && is_user_logged_in() ) { - return __( 'You are already registered', 'ultimate-member' ); - } - - // for profiles only - if ( $mode == 'profile' && um_profile_id() ) { - $current_user_roles = UM()->roles()->get_all_user_roles( um_profile_id() ); - if ( ! empty( $args['role'] ) && ! in_array( $args['role'], $current_user_roles ) ) { - return ''; - } - } - - /** - * UM hook - * - * @type action - * @title um_pre_{$mode}_shortcode - * @description Action pre-load 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 - * - */ - do_action( "um_pre_{$mode}_shortcode", $args ); - /** - * UM hook - * - * @type action - * @title um_before_form_is_loaded - * @description Action pre-load 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 - * - */ - do_action( "um_before_form_is_loaded", $args ); - /** - * UM hook - * - * @type action - * @title um_before_{$mode}_form_is_loaded - * @description Action pre-load 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 - * - */ - do_action( "um_before_{$mode}_form_is_loaded", $args ); - - $this->template_load( $template, $args ); - - $this->dynamic_css( $args ); - - if ( um_get_requested_user() || $mode == 'logout' ) { - um_reset_user(); - } - - /** - * UM hook - * - * @type action - * @title um_after_everything_output - * @description Action after load shortcode content - * @change_log - * ["Since: 2.0"] - * @usage add_action( 'um_after_everything_output', 'function_name', 10 ); - * @example - * - */ - do_action( 'um_after_everything_output' ); - - $output = ob_get_contents(); - ob_end_clean(); - return $output; - } - - - /** - * Get dynamic CSS args - * - * @param $args - * @return array - */ - function get_css_args( $args ) { - $arr = um_styling_defaults( $args['mode'] ); - $arr = array_merge( $arr, array( 'form_id' => $args['form_id'], 'mode' => $args['mode'] ) ); - return $arr; - } - - - /** - * Load dynamic css - * - * @param array $args - * - * @return string - */ - function dynamic_css( $args = array() ) { - /** - * UM hook - * - * @type filter - * @title um_disable_dynamic_global_css - * @description Turn on for disable global dynamic CSS for fix the issue #306 - * @input_vars - * [{"var":"$disable","type":"bool","desc":"Disable global CSS"}] - * @change_log - * ["Since: 2.0"] - * @usage - * - * @example - * - */ - $disable_css = apply_filters( 'um_disable_dynamic_global_css', false ); - if ( $disable_css ) - return ''; - - /** - * @var $mode - */ - extract( $args ); - - include_once um_path . 'assets/dynamic_css/dynamic_global.php'; - - if ( isset( $mode ) && in_array( $mode, array( 'profile', 'directory' ) ) ) { - $file = um_path . 'assets/dynamic_css/dynamic_' . $mode . '.php'; - - if ( file_exists( $file ) ) - include_once $file; - } - - return ''; - } - - - /** - * Loads a template file - * - * @param $template - * @param array $args - */ - function template_load( $template, $args = array() ) { - if ( is_array( $args ) ) { - $this->set_args = $args; - } - $this->load_template( $template ); - } - - - /*** - *** @Checks if a template file exists - */ - function template_exists($template) { - - $file = um_path . 'templates/' . $template . '.php'; - $theme_file = get_stylesheet_directory() . '/ultimate-member/templates/' . $template . '.php'; - - if (file_exists($theme_file) || file_exists($file)) { - return true; - } - - return false; - } - - /*** - *** @Get File Name without path and extension - */ - function get_template_name($file) { - $file = basename($file); - $file = preg_replace('/\\.[^.\\s]{3,4}$/', '', $file); - return $file; - } - - /*** - *** @Get Templates - */ - function get_templates($excluded = null) { - - if ($excluded) { - $array[$excluded] = __('Default Template', 'ultimate-member'); - } - - $paths[] = glob(um_path . 'templates/' . '*.php'); - - if (file_exists(get_stylesheet_directory() . '/ultimate-member/templates/')) { - $paths[] = glob(get_stylesheet_directory() . '/ultimate-member/templates/' . '*.php'); - } - - if( isset( $paths ) && ! empty( $paths ) ){ - - foreach ($paths as $k => $files) { - - if( isset( $files ) && ! empty( $files ) ){ - - foreach ($files as $file) { - - $clean_filename = $this->get_template_name( $file ); - - if ( 0 === strpos( $clean_filename, $excluded ) ) { - - $source = file_get_contents( $file ); - $tokens = token_get_all( $source ); - $comment = array( - T_COMMENT, // All comments since PHP5 - T_DOC_COMMENT, // PHPDoc comments - ); - foreach ( $tokens as $token ) { - if ( in_array( $token[0], $comment ) && strstr( $token[1], '/* Template:' ) && $clean_filename != $excluded ) { - $txt = $token[1]; - $txt = str_replace('/* Template: ', '', $txt ); - $txt = str_replace(' */', '', $txt ); - $array[ $clean_filename ] = $txt; - } - } - - } - - } - - } - - } - - } - - return $array; - - } + /** + * Class Shortcodes + * @package um\core + */ + class Shortcodes { /** - * Get Shortcode for given form ID - * - * @param $post_id - * - * @return string - */ + * Shortcodes constructor. + */ + function __construct() { + + $this->message_mode = false; + $this->custom_message = ''; + + $this->loop = array(); + + add_shortcode( 'ultimatemember', array( &$this, 'ultimatemember' ) ); + + add_shortcode( 'um_loggedin', array( &$this, 'um_loggedin' ) ); + add_shortcode( 'um_loggedout', array( &$this, 'um_loggedout' ) ); + add_shortcode( 'um_show_content', array( &$this, 'um_shortcode_show_content_for_role' ) ); + add_shortcode( 'ultimatemember_searchform', array( &$this, 'ultimatemember_searchform' ) ); + + + add_filter( 'body_class', array( &$this, 'body_class' ), 0 ); + add_action( 'template_redirect', array( &$this, 'is_um_page' ) ); + + add_filter( 'um_shortcode_args_filter', array( &$this, 'display_logout_form' ), 99 ); + add_filter( 'um_shortcode_args_filter', array( &$this, 'parse_shortcode_args' ), 99 ); + + /** + * UM hook + * + * @type filter + * @title um_emoji_base_uri + * @description Change Emoji base URL + * @input_vars + * [{"var":"$url","type":"string","desc":"Base URL"}] + * @change_log + * ["Since: 2.0"] + * @usage + * + * @example + * + */ + $base_uri = apply_filters( 'um_emoji_base_uri', 'https://s.w.org/images/core/emoji/' ); + + $this->emoji[':)'] = $base_uri . '72x72/1f604.png'; + $this->emoji[':smiley:'] = $base_uri . '72x72/1f603.png'; + $this->emoji[':D'] = $base_uri . '72x72/1f600.png'; + $this->emoji[':$'] = $base_uri . '72x72/1f60a.png'; + $this->emoji[':relaxed:'] = $base_uri . '72x72/263a.png'; + $this->emoji[';)'] = $base_uri . '72x72/1f609.png'; + $this->emoji[':heart_eyes:'] = $base_uri . '72x72/1f60d.png'; + $this->emoji[':kissing_heart:'] = $base_uri . '72x72/1f618.png'; + $this->emoji[':kissing_closed_eyes:'] = $base_uri . '72x72/1f61a.png'; + $this->emoji[':kissing:'] = $base_uri . '72x72/1f617.png'; + $this->emoji[':kissing_smiling_eyes:'] = $base_uri . '72x72/1f619.png'; + $this->emoji[';P'] = $base_uri . '72x72/1f61c.png'; + $this->emoji[':P'] = $base_uri . '72x72/1f61b.png'; + $this->emoji[':stuck_out_tongue_closed_eyes:'] = $base_uri . '72x72/1f61d.png'; + $this->emoji[':flushed:'] = $base_uri . '72x72/1f633.png'; + $this->emoji[':grin:'] = $base_uri . '72x72/1f601.png'; + $this->emoji[':pensive:'] = $base_uri . '72x72/1f614.png'; + $this->emoji[':relieved:'] = $base_uri . '72x72/1f60c.png'; + $this->emoji[':unamused'] = $base_uri . '72x72/1f612.png'; + $this->emoji[':('] = $base_uri . '72x72/1f61e.png'; + $this->emoji[':persevere:'] = $base_uri . '72x72/1f623.png'; + $this->emoji[":'("] = $base_uri . '72x72/1f622.png'; + $this->emoji[':joy:'] = $base_uri . '72x72/1f602.png'; + $this->emoji[':sob:'] = $base_uri . '72x72/1f62d.png'; + $this->emoji[':sleepy:'] = $base_uri . '72x72/1f62a.png'; + $this->emoji[':disappointed_relieved:'] = $base_uri . '72x72/1f625.png'; + $this->emoji[':cold_sweat:'] = $base_uri . '72x72/1f630.png'; + $this->emoji[':sweat_smile:'] = $base_uri . '72x72/1f605.png'; + $this->emoji[':sweat:'] = $base_uri . '72x72/1f613.png'; + $this->emoji[':weary:'] = $base_uri . '72x72/1f629.png'; + $this->emoji[':tired_face:'] = $base_uri . '72x72/1f62b.png'; + $this->emoji[':fearful:'] = $base_uri . '72x72/1f628.png'; + $this->emoji[':scream:'] = $base_uri . '72x72/1f631.png'; + $this->emoji[':angry:'] = $base_uri . '72x72/1f620.png'; + $this->emoji[':rage:'] = $base_uri . '72x72/1f621.png'; + $this->emoji[':triumph'] = $base_uri . '72x72/1f624.png'; + $this->emoji[':confounded:'] = $base_uri . '72x72/1f616.png'; + $this->emoji[':laughing:'] = $base_uri . '72x72/1f606.png'; + $this->emoji[':yum:'] = $base_uri . '72x72/1f60b.png'; + $this->emoji[':mask:'] = $base_uri . '72x72/1f637.png'; + $this->emoji[':cool:'] = $base_uri . '72x72/1f60e.png'; + $this->emoji[':sleeping:'] = $base_uri . '72x72/1f634.png'; + $this->emoji[':dizzy_face:'] = $base_uri . '72x72/1f635.png'; + $this->emoji[':astonished:'] = $base_uri . '72x72/1f632.png'; + $this->emoji[':worried:'] = $base_uri . '72x72/1f61f.png'; + $this->emoji[':frowning:'] = $base_uri . '72x72/1f626.png'; + $this->emoji[':anguished:'] = $base_uri . '72x72/1f627.png'; + $this->emoji[':smiling_imp:'] = $base_uri . '72x72/1f608.png'; + $this->emoji[':imp:'] = $base_uri . '72x72/1f47f.png'; + $this->emoji[':open_mouth:'] = $base_uri . '72x72/1f62e.png'; + $this->emoji[':grimacing:'] = $base_uri . '72x72/1f62c.png'; + $this->emoji[':neutral_face:'] = $base_uri . '72x72/1f610.png'; + $this->emoji[':confused:'] = $base_uri . '72x72/1f615.png'; + $this->emoji[':hushed:'] = $base_uri . '72x72/1f62f.png'; + $this->emoji[':no_mouth:'] = $base_uri . '72x72/1f636.png'; + $this->emoji[':innocent:'] = $base_uri . '72x72/1f607.png'; + $this->emoji[':smirk:'] = $base_uri . '72x72/1f60f.png'; + $this->emoji[':expressionless:'] = $base_uri . '72x72/1f611.png'; + + } + + + /** + * Conditional logout form + * + * @param array $args + * + * @return array + */ + function display_logout_form( $args ) { + if ( is_user_logged_in() && isset( $args['mode'] ) && $args['mode'] == 'login' ) { + + if ( get_current_user_id() != um_user( 'ID' ) ) { + um_fetch_user( get_current_user_id() ); + } + + $args['template'] = 'logout'; + } + + return $args; + } + + + /** + * Filter shortcode args + * + * @param array $args + * + * @return array + */ + function parse_shortcode_args( $args ) { + if ( $this->message_mode == true ) { + + if ( ! empty( $_REQUEST['um_role'] ) ) { + $args['template'] = 'message'; + $roleID = esc_attr( $_REQUEST['um_role'] ); + $role = UM()->roles()->role_data( $roleID ); + + if ( ! empty( $role ) && ! empty( $role["status"] ) ) { + $message_key = $role["status"] . '_message'; + $this->custom_message = ! empty( $role[ $message_key ] ) ? $role[ $message_key ] : ''; + } + } + + } + + foreach ( $args as $k => $v ) { + $args[ $k ] = maybe_unserialize( $args[ $k ] ); + } + + return $args; + } + + + /** + * Emoji support + * + * @param $content + * + * @return mixed|string + */ + function emotize( $content ) { + $content = stripslashes( $content ); + foreach ( $this->emoji as $code => $val ) { + $regex = str_replace(array('(', ')'), array("\\" . '(', "\\" . ')'), $code); + $content = preg_replace('/(' . $regex . ')(\s|$)/', '' . $code . '$2', $content); + } + return $content; + } + + + /** + * Remove wpautop filter for post content if it's UM core page + */ + function is_um_page() { + if ( is_ultimatemember() ) { + remove_filter( 'the_content', 'wpautop' ); + } + } + + + /** + * Extend body classes + * + * @param $classes + * + * @return array + */ + function body_class( $classes ) { + $array = UM()->config()->permalinks; + if ( ! $array ) { + return $classes; + } + + foreach ( $array as $slug => $info ) { + if ( um_is_core_page( $slug ) ) { + + $classes[] = 'um-page-' . $slug; + + if ( is_user_logged_in() ) { + $classes[] = 'um-page-loggedin'; + } else { + $classes[] = 'um-page-loggedout'; + } + + } + } + + if ( um_is_core_page( 'user' ) && um_is_user_himself() ) { + $classes[] = 'um-own-profile'; + } + + return $classes; + } + + + /** + * Retrieve core login form + * + * @return int + */ + function core_login_form() { + $forms = get_posts(array('post_type' => 'um_form', 'posts_per_page' => 1, 'meta_key' => '_um_core', 'meta_value' => 'login')); + $form_id = isset( $forms[0]->ID ) ? $forms[0]->ID: 0; + + return $form_id; + } + + + /** + * Load a compatible template + * + * @param $tpl + */ + function load_template( $tpl ) { + $loop = ( $this->loop ) ? $this->loop : array(); + + if ( isset( $this->set_args ) && is_array( $this->set_args ) ) { + $args = $this->set_args; + + unset( $args['file'] ); + unset( $args['theme_file'] ); + unset( $args['tpl'] ); + + extract( $args ); + } + + $file = um_path . "templates/{$tpl}.php"; + $theme_file = get_stylesheet_directory() . "/ultimate-member/templates/{$tpl}.php"; + + + if ( file_exists( $theme_file ) ) { + $file = $theme_file; + } + + if ( file_exists( $file ) ) { + + include $file; + } + } + + + /** + * Add class based on shortcode + * + * @param $mode + * @param array $args + * + * @return mixed|string|void + */ + function get_class($mode, $args = array()) { + + $classes = 'um-' . $mode; + + if (is_admin()) { + $classes .= ' um-in-admin'; + } + + if (isset(UM()->form()->errors) && UM()->form()->errors) { + $classes .= ' um-err'; + } + + if (UM()->fields()->editing == true) { + $classes .= ' um-editing'; + } + + if (UM()->fields()->viewing == true) { + $classes .= ' um-viewing'; + } + + if (isset($args['template']) && $args['template'] != $args['mode']) { + $classes .= ' um-' . $args['template']; + } + + /** + * UM hook + * + * @type filter + * @title um_form_official_classes__hook + * @description Change official form classes + * @input_vars + * [{"var":"$classes","type":"string","desc":"Classes string"}] + * @change_log + * ["Since: 2.0"] + * @usage + * + * @example + * + */ + $classes = apply_filters( 'um_form_official_classes__hook', $classes ); + return $classes; + } + + + /** + * Logged-in only content + * + * @param array $args + * @param string $content + * + * @return string + */ + function um_loggedin( $args = array(), $content = "" ) { + ob_start(); + + $defaults = array( + 'lock_text' => __( 'This content has been restricted to logged in users only. Please login to view this content.', 'ultimate-member' ), + 'show_lock' => 'yes', + ); + + $args = wp_parse_args( $args, $defaults ); + + $args['lock_text'] = $this->convert_locker_tags( $args['lock_text'] ); + + if ( ! is_user_logged_in() ) { + if ( $args['show_lock'] == 'no' ) { + echo ''; + } else { + $this->set_args = $args; + $this->load_template( 'login-to-view' ); + } + } else { + echo do_shortcode( $this->convert_locker_tags( wpautop( $content ) ) ); + } + + $output = ob_get_clean(); + return $output; + } + + /*** + *** @Logged-out only content + */ + function um_loggedout($args = array(), $content = "") { + ob_start(); + + // Hide for logged in users + if (is_user_logged_in()) { + echo ''; + } else { + echo do_shortcode(wpautop($content)); + } + + $output = ob_get_contents(); + ob_end_clean(); + return $output; + } + + + /** + * Shortcode + * + * @param array $args + * + * @return string + */ + function ultimatemember( $args = array() ) { + return $this->load( $args ); + } + + + /** + * Load a module with global function + * + * @param $args + * + * @return string + */ + function load( $args ) { + ob_start(); + + $defaults = array(); + $args = wp_parse_args($args, $defaults); + + // when to not continue + $this->form_id = (isset($args['form_id'])) ? $args['form_id'] : null; + if (!$this->form_id) { + return; + } + + $this->form_status = get_post_status($this->form_id); + if ($this->form_status != 'publish') { + return; + } + + // get data into one global array + $post_data = UM()->query()->post_data($this->form_id); + + /** + * UM hook + * + * @type filter + * @title um_pre_args_setup + * @description Change arguments on load shortcode + * @input_vars + * [{"var":"$post_data","type":"string","desc":"$_POST data"}] + * @change_log + * ["Since: 2.0"] + * @usage + * + * @example + * + */ + $args = apply_filters( 'um_pre_args_setup', $post_data ); + + if (!isset($args['template'])) { + $args['template'] = ''; + } + + if (isset($post_data['template']) && $post_data['template'] != $args['template']) { + $args['template'] = $post_data['template']; + } + + if (!$this->template_exists($args['template'])) { + $args['template'] = $post_data['mode']; + } + + if (!isset($post_data['template'])) { + $post_data['template'] = $post_data['mode']; + } + + if( 'directory' != $args['mode'] ) { + + $args = array_merge( $post_data, $args ); + + if (empty( $args['use_custom_settings'] )) { + $args = array_merge( $args, $this->get_css_args( $args ) ); + } else { + $args = array_merge( $this->get_css_args( $args ), $args ); + } + } + // filter for arguments + + /** + * UM hook + * + * @type filter + * @title um_shortcode_args_filter + * @description Change arguments on load shortcode + * @input_vars + * [{"var":"$args","type":"string","desc":"Shortcode arguments"}] + * @change_log + * ["Since: 2.0"] + * @usage + * + * @example + * + */ + $args = apply_filters( 'um_shortcode_args_filter', $args ); + + extract($args, EXTR_SKIP); + + if ( 'register' == $mode && is_user_logged_in() ) { + return __( 'You are already registered', 'ultimate-member' ); + } + + // for profiles only + if ( $mode == 'profile' && um_profile_id() ) { + $current_user_roles = UM()->roles()->get_all_user_roles( um_profile_id() ); + if ( ! empty( $args['role'] ) && ! in_array( $args['role'], $current_user_roles ) ) { + return ''; + } + } + + /** + * UM hook + * + * @type action + * @title um_pre_{$mode}_shortcode + * @description Action pre-load 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 + * + */ + do_action( "um_pre_{$mode}_shortcode", $args ); + /** + * UM hook + * + * @type action + * @title um_before_form_is_loaded + * @description Action pre-load 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 + * + */ + do_action( "um_before_form_is_loaded", $args ); + /** + * UM hook + * + * @type action + * @title um_before_{$mode}_form_is_loaded + * @description Action pre-load 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 + * + */ + do_action( "um_before_{$mode}_form_is_loaded", $args ); + + $this->template_load( $template, $args ); + + $this->dynamic_css( $args ); + + if ( um_get_requested_user() || $mode == 'logout' ) { + um_reset_user(); + } + + /** + * UM hook + * + * @type action + * @title um_after_everything_output + * @description Action after load shortcode content + * @change_log + * ["Since: 2.0"] + * @usage add_action( 'um_after_everything_output', 'function_name', 10 ); + * @example + * + */ + do_action( 'um_after_everything_output' ); + + $output = ob_get_contents(); + ob_end_clean(); + return $output; + } + + + /** + * Get dynamic CSS args + * + * @param $args + * @return array + */ + function get_css_args( $args ) { + $arr = um_styling_defaults( $args['mode'] ); + $arr = array_merge( $arr, array( 'form_id' => $args['form_id'], 'mode' => $args['mode'] ) ); + return $arr; + } + + + /** + * Load dynamic css + * + * @param array $args + * + * @return string + */ + function dynamic_css( $args = array() ) { + /** + * UM hook + * + * @type filter + * @title um_disable_dynamic_global_css + * @description Turn on for disable global dynamic CSS for fix the issue #306 + * @input_vars + * [{"var":"$disable","type":"bool","desc":"Disable global CSS"}] + * @change_log + * ["Since: 2.0"] + * @usage + * + * @example + * + */ + $disable_css = apply_filters( 'um_disable_dynamic_global_css', false ); + if ( $disable_css ) + return ''; + + /** + * @var $mode + */ + extract( $args ); + + include_once um_path . 'assets/dynamic_css/dynamic_global.php'; + + if ( isset( $mode ) && in_array( $mode, array( 'profile', 'directory' ) ) ) { + $file = um_path . 'assets/dynamic_css/dynamic_' . $mode . '.php'; + + if ( file_exists( $file ) ) + include_once $file; + } + + return ''; + } + + + /** + * Loads a template file + * + * @param $template + * @param array $args + */ + function template_load( $template, $args = array() ) { + if ( is_array( $args ) ) { + $this->set_args = $args; + } + $this->load_template( $template ); + } + + + /** + * Checks if a template file exists + * + * @param $template + * + * @return bool + */ + function template_exists($template) { + + $file = um_path . 'templates/' . $template . '.php'; + $theme_file = get_stylesheet_directory() . '/ultimate-member/templates/' . $template . '.php'; + + if (file_exists($theme_file) || file_exists($file)) { + return true; + } + + return false; + } + + + /** + * Get File Name without path and extension + * + * @param $file + * + * @return mixed|string + */ + function get_template_name($file) { + $file = basename($file); + $file = preg_replace('/\\.[^.\\s]{3,4}$/', '', $file); + return $file; + } + + + /** + * Get Templates + * + * @param null $excluded + * + * @return mixed + */ + function get_templates($excluded = null) { + + if ($excluded) { + $array[$excluded] = __('Default Template', 'ultimate-member'); + } + + $paths[] = glob(um_path . 'templates/' . '*.php'); + + if (file_exists(get_stylesheet_directory() . '/ultimate-member/templates/')) { + $paths[] = glob(get_stylesheet_directory() . '/ultimate-member/templates/' . '*.php'); + } + + if( isset( $paths ) && ! empty( $paths ) ){ + + foreach ($paths as $k => $files) { + + if( isset( $files ) && ! empty( $files ) ){ + + foreach ($files as $file) { + + $clean_filename = $this->get_template_name( $file ); + + if ( 0 === strpos( $clean_filename, $excluded ) ) { + + $source = file_get_contents( $file ); + $tokens = token_get_all( $source ); + $comment = array( + T_COMMENT, // All comments since PHP5 + T_DOC_COMMENT, // PHPDoc comments + ); + foreach ( $tokens as $token ) { + if ( in_array( $token[0], $comment ) && strstr( $token[1], '/* Template:' ) && $clean_filename != $excluded ) { + $txt = $token[1]; + $txt = str_replace('/* Template: ', '', $txt ); + $txt = str_replace(' */', '', $txt ); + $array[ $clean_filename ] = $txt; + } + } + + } + + } + + } + + } + + } + + return $array; + + } + + + /** + * Get Shortcode for given form ID + * + * @param $post_id + * + * @return string + */ function get_shortcode( $post_id ) { $shortcode = '[ultimatemember form_id=' . $post_id . ']'; return $shortcode; @@ -752,24 +803,24 @@ if ( ! class_exists( 'Shortcodes' ) ) { /** - * Convert access lock tags - * - * @param $str - * - * @return mixed|string - */ + * Convert access lock tags + * + * @param $str + * + * @return mixed|string + */ function convert_locker_tags( $str ) { return um_convert_tags( $str, array(), false ); } /** - * Convert user tags in a string - * - * @param $str - * - * @return mixed - */ + * Convert user tags in a string + * + * @param $str + * + * @return mixed + */ function convert_user_tags( $str ) { $pattern_array = array( @@ -857,85 +908,85 @@ if ( ! class_exists( 'Shortcodes' ) ) { } - /** - * Shortcode: Show custom content to specific role - * - * Show content to specific roles - * [um_show_content roles='member'] [/um_show_content] - * You can add multiple target roles, just use ',' e.g. [um_show_content roles='member,candidates,pets'] - * - * Hide content from specific roles - * [um_show_content not='contributors'] [/um_show_content] - * You can add multiple target roles, just use ',' e.g. [um_show_content roles='member,candidates,pets'] - * - * @param array $atts - * @param string $content - * @return string - */ - function um_shortcode_show_content_for_role( $atts = array() , $content = '' ) { - global $user_ID; + /** + * Shortcode: Show custom content to specific role + * + * Show content to specific roles + * [um_show_content roles='member'] [/um_show_content] + * You can add multiple target roles, just use ',' e.g. [um_show_content roles='member,candidates,pets'] + * + * Hide content from specific roles + * [um_show_content not='contributors'] [/um_show_content] + * You can add multiple target roles, just use ',' e.g. [um_show_content roles='member,candidates,pets'] + * + * @param array $atts + * @param string $content + * @return string + */ + function um_shortcode_show_content_for_role( $atts = array() , $content = '' ) { + global $user_ID; - if ( ! is_user_logged_in() ) { - return; - } + if ( ! is_user_logged_in() ) { + return; + } - $a = shortcode_atts( array( - 'roles' => '', - 'not' => '', - 'is_profile' => false, - ), $atts ); + $a = shortcode_atts( array( + 'roles' => '', + 'not' => '', + 'is_profile' => false, + ), $atts ); - if ( $a['is_profile'] ) { - um_fetch_user( um_profile_id() ); - } else { - um_fetch_user( $user_ID ); - } + if ( $a['is_profile'] ) { + um_fetch_user( um_profile_id() ); + } else { + um_fetch_user( $user_ID ); + } - $current_user_roles = um_user( 'roles' ); + $current_user_roles = um_user( 'roles' ); - if ( ! empty( $a['not'] ) && ! empty( $a['roles'] ) ) { - return do_shortcode( $this->convert_locker_tags( $content ) ); - } + if ( ! empty( $a['not'] ) && ! empty( $a['roles'] ) ) { + return do_shortcode( $this->convert_locker_tags( $content ) ); + } - if ( ! empty( $a['not'] ) ) { - $not_in_roles = explode( ",", $a['not'] ); + if ( ! empty( $a['not'] ) ) { + $not_in_roles = explode( ",", $a['not'] ); - if ( is_array( $not_in_roles ) && ( empty( $current_user_roles ) || count( array_intersect( $current_user_roles, $not_in_roles ) ) <= 0 ) ) { - return do_shortcode( $this->convert_locker_tags( $content ) ); - } - } else { - $roles = explode( ",", $a['roles'] ); + if ( is_array( $not_in_roles ) && ( empty( $current_user_roles ) || count( array_intersect( $current_user_roles, $not_in_roles ) ) <= 0 ) ) { + return do_shortcode( $this->convert_locker_tags( $content ) ); + } + } else { + $roles = explode( ",", $a['roles'] ); - if ( ! empty( $current_user_roles ) && is_array( $roles ) && count( array_intersect( $current_user_roles, $roles ) ) > 0 ) { - return do_shortcode( $this->convert_locker_tags( $content ) ); - } - } + if ( ! empty( $current_user_roles ) && is_array( $roles ) && count( array_intersect( $current_user_roles, $roles ) ) > 0 ) { + return do_shortcode( $this->convert_locker_tags( $content ) ); + } + } - return ''; - } + return ''; + } - /** - * @param array $args - * @param string $content - * - * @return string - */ - public function ultimatemember_searchform( $args = array(), $content = "" ) { - // turn off buffer - ob_start(); + /** + * @param array $args + * @param string $content + * + * @return string + */ + public function ultimatemember_searchform( $args = array(), $content = "" ) { + // turn off buffer + ob_start(); - // load template - $this->load_template( 'searchform' ); + // load template + $this->load_template( 'searchform' ); - // get the buffer - $template = ob_get_contents(); + // get the buffer + $template = ob_get_contents(); - // clear the buffer - ob_end_clean(); + // clear the buffer + ob_end_clean(); - return $template; - } + return $template; + } - } + } } \ No newline at end of file diff --git a/includes/core/class-tracking.php b/includes/core/class-tracking.php index e530561a..2dcc3aac 100644 --- a/includes/core/class-tracking.php +++ b/includes/core/class-tracking.php @@ -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 '

'; + /** + * Get last send time + * + * @return mixed|void + */ + private function get_last_send() { + return get_option( 'um_tracking_last_send' ); + } - printf( __( 'Thanks for installing %s! 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 extensions bundle.', 'ultimate-member' ), ultimatemember_plugin_name, 'https://ultimatemember.com/core-extensions-bundle/' ); - echo '

'; + /** + * Send a report + * + * @param bool $override + */ + public function send_checkin( $override = false ) { - echo '

' . __( 'Subscribe to mailing list', 'ultimate-member' ) . ''; - echo ' ' . __( 'No thanks', 'ultimate-member' ) . '

'; + 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 '

'; + + printf( __( 'Thanks for installing %s! 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 extensions bundle.', 'ultimate-member' ), ultimatemember_plugin_name, 'https://ultimatemember.com/core-extensions-bundle/' ); + + echo '

'; + + echo '

' . __( 'Subscribe to mailing list', 'ultimate-member' ) . ''; + echo ' ' . __( 'No thanks', 'ultimate-member' ) . '

'; + + } + + } } \ No newline at end of file diff --git a/includes/core/class-user.php b/includes/core/class-user.php index d9e025cf..e932e4d7 100644 --- a/includes/core/class-user.php +++ b/includes/core/class-user.php @@ -6,90 +6,103 @@ if ( ! defined( 'ABSPATH' ) ) exit; if ( ! class_exists( 'User' ) ) { - class User { - function __construct() { - $this->id = 0; - $this->usermeta = null; - $this->data = null; - $this->profile = null; - $this->cannot_edit = null; - $this->tabs = null; + /** + * Class User + * @package um\core + */ + class User { - $this->banned_keys = array( - 'metabox','postbox','meta-box', - 'dismissed_wp_pointers', 'session_tokens', - 'screen_layout', 'wp_user-', 'dismissed', - 'cap_key', 'wp_capabilities', - 'managenav', 'nav_menu','user_activation_key', - 'level_', 'wp_user_level' - ); - add_action( 'init', array( &$this, 'set' ), 1 ); + /** + * User constructor. + */ + function __construct() { - $this->preview = false; + $this->id = 0; + $this->usermeta = null; + $this->data = null; + $this->profile = null; + $this->cannot_edit = null; + $this->tabs = null; - // a list of keys that should never be in wp_usermeta - $this->update_user_keys = array( - 'user_email', - 'user_pass', - 'user_password', - 'display_name', - 'role', - ); + $this->banned_keys = array( + 'metabox','postbox','meta-box', + 'dismissed_wp_pointers', 'session_tokens', + 'screen_layout', 'wp_user-', 'dismissed', + 'cap_key', 'wp_capabilities', + 'managenav', 'nav_menu','user_activation_key', + 'level_', 'wp_user_level' + ); - $this->target_id = null; + add_action( 'init', array( &$this, 'set' ), 1 ); - // When the cache should be cleared - add_action('um_delete_user_hook', array(&$this, 'remove_cached_queue') ); - add_action('um_after_user_status_is_changed_hook', array(&$this, 'remove_cached_queue') ); + $this->preview = false; - // When user cache should be cleared - add_action('um_after_user_updated', array(&$this, 'remove_cache') ); - add_action('um_after_user_account_updated', array(&$this, 'remove_cache') ); - add_action('personal_options_update', array(&$this, 'remove_cache') ); - //add_action('edit_user_profile_update', array(&$this, 'remove_cache') ); - add_action('um_when_role_is_set', array(&$this, 'remove_cache') ); - add_action('um_when_status_is_set', array(&$this, 'remove_cache') ); + // a list of keys that should never be in wp_usermeta + $this->update_user_keys = array( + 'user_email', + 'user_pass', + 'user_password', + 'display_name', + 'role', + ); - add_action( 'show_user_profile', array( $this, 'profile_form_additional_section' ), 10 ); - add_action( 'user_new_form', array( $this, 'profile_form_additional_section' ), 10 ); - add_action( 'edit_user_profile', array( $this, 'profile_form_additional_section' ), 10 ); - add_filter( 'um_user_profile_additional_fields', array( $this, 'secondary_role_field' ), 1, 2 ); + $this->target_id = null; + + // When the cache should be cleared + add_action('um_delete_user_hook', array(&$this, 'remove_cached_queue') ); + add_action('um_after_user_status_is_changed_hook', array(&$this, 'remove_cached_queue') ); + + // When user cache should be cleared + add_action('um_after_user_updated', array(&$this, 'remove_cache') ); + add_action('um_after_user_account_updated', array(&$this, 'remove_cache') ); + add_action('personal_options_update', array(&$this, 'remove_cache') ); + //add_action('edit_user_profile_update', array(&$this, 'remove_cache') ); + add_action('um_when_role_is_set', array(&$this, 'remove_cache') ); + add_action('um_when_status_is_set', array(&$this, 'remove_cache') ); + + add_action( 'show_user_profile', array( $this, 'profile_form_additional_section' ), 10 ); + add_action( 'user_new_form', array( $this, 'profile_form_additional_section' ), 10 ); + add_action( 'edit_user_profile', array( $this, 'profile_form_additional_section' ), 10 ); + add_filter( 'um_user_profile_additional_fields', array( $this, 'secondary_role_field' ), 1, 2 ); //on every update of user profile (hook from wp_update_user) - add_action( 'profile_update', array( &$this, 'profile_update' ), 10, 2 ); // user_id and old_user_data + add_action( 'profile_update', array( &$this, 'profile_update' ), 10, 2 ); // user_id and old_user_data - //on user update profile page - //add_action( 'edit_user_profile_update', array( &$this, 'profile_update' ), 10, 1 ); + //on user update profile page + //add_action( 'edit_user_profile_update', array( &$this, 'profile_update' ), 10, 1 ); - add_action( 'user_register', array( &$this, 'user_register_via_admin' ), 10, 1 ); - add_action( 'user_register', array( &$this, 'set_gravatar' ), 11, 1 ); + add_action( 'user_register', array( &$this, 'user_register_via_admin' ), 10, 1 ); + add_action( 'user_register', array( &$this, 'set_gravatar' ), 11, 1 ); - add_action( 'added_existing_user', array( &$this, 'add_um_role_existing_user' ), 10, 2 ); - add_action( 'wpmu_activate_user', array( &$this, 'add_um_role_wpmu_new_user' ), 10, 1 ); + add_action( 'added_existing_user', array( &$this, 'add_um_role_existing_user' ), 10, 2 ); + add_action( 'wpmu_activate_user', array( &$this, 'add_um_role_wpmu_new_user' ), 10, 1 ); - add_action( 'init', array( &$this, 'check_membership' ), 10 ); - } + add_action( 'init', array( &$this, 'check_membership' ), 10 ); + } - function check_membership() { - if ( ! is_user_logged_in() ) - return; + /** + * + */ + function check_membership() { + if ( ! is_user_logged_in() ) + return; - um_fetch_user( get_current_user_id() ); - $status = um_user( 'account_status' ); + um_fetch_user( get_current_user_id() ); + $status = um_user( 'account_status' ); - if ( 'rejected' == $status ) { - wp_logout(); - session_unset(); - exit( wp_redirect( um_get_core_page( 'login' ) ) ); - } + if ( 'rejected' == $status ) { + wp_logout(); + session_unset(); + exit( wp_redirect( um_get_core_page( 'login' ) ) ); + } - um_reset_user(); - } + um_reset_user(); + } /** @@ -133,65 +146,65 @@ if ( ! class_exists( 'User' ) ) { } - /** - * Get pending users (in queue) - */ - function get_pending_users_count() { + /** + * Get pending users (in queue) + */ + function get_pending_users_count() { - $cached_users_queue = get_option( 'um_cached_users_queue' ); - if ( $cached_users_queue > 0 && ! isset( $_REQUEST['delete_count'] ) ){ - return $cached_users_queue; - } + $cached_users_queue = get_option( 'um_cached_users_queue' ); + if ( $cached_users_queue > 0 && ! isset( $_REQUEST['delete_count'] ) ){ + return $cached_users_queue; + } - $args = array( 'fields' => 'ID', 'number' => 1 ); - $args['meta_query']['relation'] = 'OR'; - $args['meta_query'][] = array( - 'key' => 'account_status', - 'value' => 'awaiting_email_confirmation', - 'compare' => '=' - ); - $args['meta_query'][] = array( - 'key' => 'account_status', - 'value' => 'awaiting_admin_review', - 'compare' => '=' - ); + $args = array( 'fields' => 'ID', 'number' => 1 ); + $args['meta_query']['relation'] = 'OR'; + $args['meta_query'][] = array( + 'key' => 'account_status', + 'value' => 'awaiting_email_confirmation', + 'compare' => '=' + ); + $args['meta_query'][] = array( + 'key' => 'account_status', + 'value' => 'awaiting_admin_review', + 'compare' => '=' + ); - /** - * UM hook - * - * @type filter - * @title um_admin_pending_queue_filter - * @description Change user query arguments when get pending users - * @input_vars - * [{"var":"$args","type":"array","desc":"WP_Users query arguments"}] - * @change_log - * ["Since: 2.0"] - * @usage - * - * @example - * - */ - $args = apply_filters( 'um_admin_pending_queue_filter', $args ); - $users = new \WP_User_Query( $args ); + /** + * UM hook + * + * @type filter + * @title um_admin_pending_queue_filter + * @description Change user query arguments when get pending users + * @input_vars + * [{"var":"$args","type":"array","desc":"WP_Users query arguments"}] + * @change_log + * ["Since: 2.0"] + * @usage + * + * @example + * + */ + $args = apply_filters( 'um_admin_pending_queue_filter', $args ); + $users = new \WP_User_Query( $args ); - delete_option( 'um_cached_users_queue' ); - add_option( 'um_cached_users_queue', $users->get_total(), '', 'no' ); + delete_option( 'um_cached_users_queue' ); + add_option( 'um_cached_users_queue', $users->get_total(), '', 'no' ); - return $users->get_total(); - } + return $users->get_total(); + } /** - * @param $user_id - * - * @return bool|mixed - */ + * @param $user_id + * + * @return bool|mixed + */ function get_profile_slug( $user_id ) { // Permalink base $permalink_base = UM()->options()->get( 'permalink_base' ); @@ -329,10 +342,10 @@ if ( ! class_exists( 'User' ) ) { /** - * Backend user creation - * - * @param $user_id - */ + * Backend user creation + * + * @param $user_id + */ function user_register_via_admin( $user_id ) { if ( empty( $user_id ) ) @@ -374,11 +387,11 @@ if ( ! class_exists( 'User' ) ) { /** - * On wp_update_user function complete - * - * @param int $user_id - * @param \WP_User $old_data - */ + * On wp_update_user function complete + * + * @param int $user_id + * @param \WP_User $old_data + */ function profile_update( $user_id, $old_data ) { // Bail if no user ID was passed if ( empty( $user_id ) ) { @@ -468,1356 +481,1359 @@ if ( ! class_exists( 'User' ) ) { } - /** - * Default interface for setting a ultimatemember role - * - * @param string $content Section HTML - * @param \WP_User $userdata User data - * @return string - */ - public function secondary_role_field( $content, $userdata ) { - $roles = array(); + /** + * Default interface for setting a ultimatemember role + * + * @param string $content Section HTML + * @param \WP_User $userdata User data + * @return string + */ + public function secondary_role_field( $content, $userdata ) { + $roles = array(); - $role_keys = get_option( 'um_roles' ); - if ( $role_keys ) { - foreach ( $role_keys as $role_key ) { - $role_meta = get_option( "um_role_{$role_key}_meta" ); + $role_keys = get_option( 'um_roles' ); + if ( $role_keys ) { + foreach ( $role_keys as $role_key ) { + $role_meta = get_option( "um_role_{$role_key}_meta" ); - if ( $role_meta ) { - //$role_meta['name'] = 'UM ' . $role_meta['name']; - $roles['um_' . $role_key] = $role_meta; - } - } - } + if ( $role_meta ) { + //$role_meta['name'] = 'UM ' . $role_meta['name']; + $roles['um_' . $role_key] = $role_meta; + } + } + } - if ( empty( $roles ) ) - return $content; + if ( empty( $roles ) ) + return $content; - global $pagenow; - if ( 'profile.php' == $pagenow ) - return $content; + global $pagenow; + if ( 'profile.php' == $pagenow ) + return $content; - $style = ''; - $user_role = false; - if ( $userdata !== 'add-new-user' && $userdata !== 'add-existing-user' ) { - // Bail if current user cannot edit users - if ( ! current_user_can( 'edit_user', $userdata->ID ) ) - return $content; + $style = ''; + $user_role = false; + if ( $userdata !== 'add-new-user' && $userdata !== 'add-existing-user' ) { + // Bail if current user cannot edit users + if ( ! current_user_can( 'edit_user', $userdata->ID ) ) + return $content; - $user_role = UM()->roles()->get_um_user_role( $userdata->ID ); - if ( $user_role && ! empty( $userdata->roles ) && count( $userdata->roles ) == 1 ) - $style = 'style="display:none;"'; + $user_role = UM()->roles()->get_um_user_role( $userdata->ID ); + if ( $user_role && ! empty( $userdata->roles ) && count( $userdata->roles ) == 1 ) + $style = 'style="display:none;"'; - } + } - $class = ( $userdata == 'add-existing-user' ) ? 'um_role_existing_selector_wrapper' : 'um_role_selector_wrapper'; + $class = ( $userdata == 'add-existing-user' ) ? 'um_role_existing_selector_wrapper' : 'um_role_selector_wrapper'; - ob_start(); ?> + ob_start(); ?> -
> - - - - - - - -
- -
-
+
> + + + + + + + +
+ +
+
$val) { - $new[$key] = $this->toArray($val); - } - } else { - $new = $obj; - } - - return $new; - } - - function get_cached_data( $user_id ) { - - $disallow_cache = UM()->options()->get( 'um_profile_object_cache_stop' ); - if( $disallow_cache ){ - return ''; - } - - if ( is_numeric( $user_id ) && $user_id > 0 ) { - $find_user = get_option("um_cache_userdata_{$user_id}"); - if ( $find_user ) { - /** - * UM hook - * - * @type filter - * @title um_user_permissions_filter - * @description Change User Permissions - * @input_vars - * [{"var":"$permissions","type":"array","desc":"User Permissions"}, - * {"var":"$user_id","type":"int","desc":"User ID"}] - * @change_log - * ["Since: 2.0"] - * @usage - * - * @example - * - */ - $find_user = apply_filters( 'um_user_permissions_filter', $find_user, $user_id ); - return $find_user; - } - } - return ''; - } - - function setup_cache( $user_id, $profile ) { - - $disallow_cache = UM()->options()->get( 'um_profile_object_cache_stop' ); - if( $disallow_cache ){ - return ''; - } - - update_option( "um_cache_userdata_{$user_id}", $profile, false ); - } - - function remove_cache( $user_id ) { - delete_option( "um_cache_userdata_{$user_id}" ); - } + /** + * Remove cached queue from Users backend + */ + function remove_cached_queue() { + delete_option( 'um_cached_users_queue' ); + } - /** - * @function set() - * - * @description This method lets you set a user. For example, to retrieve a profile or anything related to that user. - * - * @usage user->set( $user_id, $clean = false ); ?> - * - * @param $user_id (numeric) (optional) Which user to retrieve. A numeric user ID - * @param $clean (boolean) (optional) Should be true or false. Basically, if you did not provide a user ID It will set the current logged in user as a profile - * - * @returns This API method does not return anything. It sets user profile and permissions and allow you to retrieve any details for that user. - * - * @example The following example makes you set a user and retrieve their display name after that using the user API. + /** + * Converts object to array + * + * @param $obj + * + * @return array + */ + function toArray( $obj ) { + if ( is_object( $obj ) ) $obj = (array)$obj; + if ( is_array( $obj ) ) { + $new = array(); + foreach ( $obj as $key => $val ) { + $new[ $key ] = $this->toArray( $val ); + } + } else { + $new = $obj; + } - user->set( 12 ); - $display_name = $ultimatemember->user->profile['display_name']; // Should print user display name - ?> + /** + * @param $user_id + * + * @return mixed|string|void + */ + function get_cached_data( $user_id ) { - * - * - */ - function set( $user_id = null, $clean = false ) { - if ( isset( $this->profile ) ) { - unset( $this->profile ); - } + $disallow_cache = UM()->options()->get( 'um_profile_object_cache_stop' ); + if( $disallow_cache ){ + return ''; + } - if ( $user_id ) { - $this->id = $user_id; - } elseif ( is_user_logged_in() && $clean == false ) { - $this->id = get_current_user_id(); - } else { - $this->id = 0; - } + if ( is_numeric( $user_id ) && $user_id > 0 ) { + $find_user = get_option("um_cache_userdata_{$user_id}"); + if ( $find_user ) { + /** + * UM hook + * + * @type filter + * @title um_user_permissions_filter + * @description Change User Permissions + * @input_vars + * [{"var":"$permissions","type":"array","desc":"User Permissions"}, + * {"var":"$user_id","type":"int","desc":"User ID"}] + * @change_log + * ["Since: 2.0"] + * @usage + * + * @example + * + */ + $find_user = apply_filters( 'um_user_permissions_filter', $find_user, $user_id ); + return $find_user; + } + } + return ''; + } - if ( $this->get_cached_data( $this->id ) ) { - $this->profile = $this->get_cached_data( $this->id ); - } else { - if ( $user_id ) { + /** + * @param $user_id + * @param $profile + */ + function setup_cache( $user_id, $profile ) { - $this->id = $user_id; - $this->usermeta = get_user_meta( $user_id ); - $this->data = get_userdata( $this->id ); + $disallow_cache = UM()->options()->get( 'um_profile_object_cache_stop' ); + if ( $disallow_cache ) { + return; + } - } elseif ( is_user_logged_in() && $clean == false ) { + update_option( "um_cache_userdata_{$user_id}", $profile, false ); + } - $this->id = get_current_user_id(); - $this->usermeta = get_user_meta($this->id); - $this->data = get_userdata($this->id); - } else { + /** + * @param $user_id + */ + function remove_cache( $user_id ) { + delete_option( "um_cache_userdata_{$user_id}" ); + } - $this->id = 0; - $this->usermeta = null; - $this->data = null; - } + /** + * This method lets you set a user. For example, to retrieve a profile or anything related to that user. + * + * @usage user()->set( $user_id, $clean = false ); ?> + * + * @param null|int $user_id Which user to retrieve. A numeric user ID + * @param bool $clean Should be true or false. Basically, if you did not provide a user ID It will set the current logged in user as a profile + * + * @example The following example makes you set a user and retrieve their display name after that using the user API. - // we have a user, populate a profile - if ( $this->id && $this->toArray( $this->data ) ) { + data = $this->toArray( $this->data ); + UM()->user()->set( 12 ); + $display_name = UM()->user()->profile['display_name']; // Should print user display name - foreach ( $this->data as $k=>$v ) { - if ( $k == 'roles') { - $this->profile['wp_roles'] = implode(',',$v); - } else if ( is_array( $v ) ) { - foreach($v as $k2 => $v2){ - $this->profile[$k2] = $v2; - } - } else { - $this->profile[$k] = $v; - } - } + ?> + * + */ + function set( $user_id = null, $clean = false ) { + if ( isset( $this->profile ) ) { + unset( $this->profile ); + } - // add account status - if ( !isset( $this->usermeta['account_status'][0] ) ) { - $this->usermeta['account_status'][0] = 'approved'; - } + if ( $user_id ) { + $this->id = $user_id; + } elseif ( is_user_logged_in() && $clean == false ) { + $this->id = get_current_user_id(); + } else { + $this->id = 0; + } - if ( $this->usermeta['account_status'][0] == 'approved' ) { - $this->usermeta['account_status_name'][0] = __('Approved','ultimate-member'); - } + if ( $this->get_cached_data( $this->id ) ) { + $this->profile = $this->get_cached_data( $this->id ); + } else { - if ( $this->usermeta['account_status'][0] == 'awaiting_email_confirmation' ) { - $this->usermeta['account_status_name'][0] = __('Awaiting E-mail Confirmation','ultimate-member'); - } + if ( $user_id ) { - if ( $this->usermeta['account_status'][0] == 'awaiting_admin_review' ) { - $this->usermeta['account_status_name'][0] = __('Pending Review','ultimate-member'); - } + $this->id = $user_id; + $this->usermeta = get_user_meta( $user_id ); + $this->data = get_userdata( $this->id ); - if ( $this->usermeta['account_status'][0] == 'rejected' ) { - $this->usermeta['account_status_name'][0] = __('Membership Rejected','ultimate-member'); - } + } elseif ( is_user_logged_in() && $clean == false ) { - if ( $this->usermeta['account_status'][0] == 'inactive' ) { - $this->usermeta['account_status_name'][0] = __('Membership Inactive','ultimate-member'); - } + $this->id = get_current_user_id(); + $this->usermeta = get_user_meta($this->id); + $this->data = get_userdata($this->id); - // add user meta - foreach( $this->usermeta as $k=>$v ) { - if ( $k == 'display_name') continue; - $this->profile[$k] = $v[0]; - } + } else { - // add permissions - $user_role = UM()->roles()->get_priority_user_role( $this->id ); - $this->profile['role'] = $user_role; - $this->profile['roles'] = UM()->roles()->get_all_user_roles( $this->id ); + $this->id = 0; + $this->usermeta = null; + $this->data = null; - $role_meta = UM()->roles()->role_data( $user_role ); - /** - * UM hook - * - * @type filter - * @title um_user_permissions_filter - * @description Change User Permissions - * @input_vars - * [{"var":"$permissions","type":"array","desc":"User Permissions"}, - * {"var":"$user_id","type":"int","desc":"User ID"}] - * @change_log - * ["Since: 2.0"] - * @usage - * - * @example - * - */ - $role_meta = apply_filters( 'um_user_permissions_filter', $role_meta, $this->id ); + } - /*$role_meta = array_map( function( $key, $item ) { + // we have a user, populate a profile + if ( $this->id && $this->toArray( $this->data ) ) { + + // add user data + $this->data = $this->toArray( $this->data ); + + foreach ( $this->data as $k=>$v ) { + if ( $k == 'roles') { + $this->profile['wp_roles'] = implode(',',$v); + } else if ( is_array( $v ) ) { + foreach($v as $k2 => $v2){ + $this->profile[$k2] = $v2; + } + } else { + $this->profile[$k] = $v; + } + } + + // add account status + if ( !isset( $this->usermeta['account_status'][0] ) ) { + $this->usermeta['account_status'][0] = 'approved'; + } + + if ( $this->usermeta['account_status'][0] == 'approved' ) { + $this->usermeta['account_status_name'][0] = __('Approved','ultimate-member'); + } + + if ( $this->usermeta['account_status'][0] == 'awaiting_email_confirmation' ) { + $this->usermeta['account_status_name'][0] = __('Awaiting E-mail Confirmation','ultimate-member'); + } + + if ( $this->usermeta['account_status'][0] == 'awaiting_admin_review' ) { + $this->usermeta['account_status_name'][0] = __('Pending Review','ultimate-member'); + } + + if ( $this->usermeta['account_status'][0] == 'rejected' ) { + $this->usermeta['account_status_name'][0] = __('Membership Rejected','ultimate-member'); + } + + if ( $this->usermeta['account_status'][0] == 'inactive' ) { + $this->usermeta['account_status_name'][0] = __('Membership Inactive','ultimate-member'); + } + + // add user meta + foreach( $this->usermeta as $k=>$v ) { + if ( $k == 'display_name') continue; + $this->profile[$k] = $v[0]; + } + + // add permissions + $user_role = UM()->roles()->get_priority_user_role( $this->id ); + $this->profile['role'] = $user_role; + $this->profile['roles'] = UM()->roles()->get_all_user_roles( $this->id ); + + $role_meta = UM()->roles()->role_data( $user_role ); + /** + * UM hook + * + * @type filter + * @title um_user_permissions_filter + * @description Change User Permissions + * @input_vars + * [{"var":"$permissions","type":"array","desc":"User Permissions"}, + * {"var":"$user_id","type":"int","desc":"User ID"}] + * @change_log + * ["Since: 2.0"] + * @usage + * + * @example + * + */ + $role_meta = apply_filters( 'um_user_permissions_filter', $role_meta, $this->id ); + + /*$role_meta = array_map( function( $key, $item ) { if ( strpos( $key, '_um_' ) === 0 ) $key = str_replace( '_um_', '', $key ); return array( $key => $item ); }, array_keys( $role_meta ), $role_meta );*/ - $this->profile = array_merge( $this->profile, (array)$role_meta ); - - $this->profile['super_admin'] = ( is_super_admin( $this->id ) ) ? 1 : 0; - - // clean profile - $this->clean(); - - // Setup cache - $this->setup_cache( $this->id, $this->profile ); - - } - - } - - } - - /*** - *** @reset user data - ***/ - function reset( $clean = false ){ - $this->set(0, $clean); - } - - /*** - *** @Clean user profile - ***/ - function clean(){ - foreach($this->profile as $key => $value){ - foreach($this->banned_keys as $ban){ - if (strstr($key, $ban) || is_numeric($key) ) - unset($this->profile[$key]); - } - } - } - - /** - * @function auto_login() - * - * @description This method lets you auto sign-in a user to your site. - * - * @usage user->auto_login( $user_id, $rememberme = false ); ?> - * - * @param $user_id (numeric) (required) Which user ID to sign in automatically - * @param $rememberme (boolean) (optional) Should be true or false. If you want the user sign in session to use cookies, use true - * - * @returns Sign in the specified user automatically. - * - * @example The following example lets you sign in a user automatically by their ID. - - user->auto_login( 2 ); ?> - - * - * - * @example The following example lets you sign in a user automatically by their ID and makes the plugin remember their session. - - user->auto_login( 10, true ); ?> - - * - * - */ - function auto_login( $user_id, $rememberme = 0 ) { - - wp_set_current_user( $user_id ); - - wp_set_auth_cookie( $user_id, $rememberme ); - - $user = get_user_by('ID', $user_id ); - - do_action( 'wp_login', $user->user_login, $user ); - - } - - /*** - *** @Set user's registration details - ***/ - function set_registration_details( $submitted ) { - - if ( isset( $submitted['user_pass'] ) ) { - unset( $submitted['user_pass'] ); - } - - if ( isset( $submitted['user_password'] ) ) { - unset( $submitted['user_password'] ); - } - - if ( isset( $submitted['confirm_user_password'] ) ) { - unset( $submitted['confirm_user_password'] ); - } - - /** - * UM hook - * - * @type filter - * @title um_before_save_filter_submitted - * @description Change submitted data before save usermeta "submitted" on registration process - * @input_vars - * [{"var":"$submitted","type":"array","desc":"Submitted data"}] - * @change_log - * ["Since: 2.0"] - * @usage - * - * @example - * - */ - $submitted = apply_filters( 'um_before_save_filter_submitted', $submitted ); - - /** - * UM hook - * - * @type action - * @title um_before_save_registration_details - * @description Action on user registration before save details - * @input_vars - * [{"var":"$user_id","type":"int","desc":"User ID"}, - * {"var":"$submitted","type":"array","desc":"Registration form submitted"}] - * @change_log - * ["Since: 2.0"] - * @usage add_action( 'um_before_save_registration_details', 'function_name', 10, 2 ); - * @example - * - */ - do_action( 'um_before_save_registration_details', $this->id, $submitted ); - - update_user_meta( $this->id, 'submitted', $submitted ); - - $this->update_profile( $submitted ); - /** - * UM hook - * - * @type action - * @title um_after_save_registration_details - * @description Action on user registration after save details - * @input_vars - * [{"var":"$user_id","type":"int","desc":"User ID"}, - * {"var":"$submitted","type":"array","desc":"Registration form submitted"}] - * @change_log - * ["Since: 2.0"] - * @usage add_action( 'um_after_save_registration_details', 'function_name', 10, 2 ); - * @example - * - */ - do_action( 'um_after_save_registration_details', $this->id, $submitted ); - - } - - - /** - * A plain version of password - * - * @param $plain - */ - function set_plain_password( $plain ) { - update_user_meta( $this->id, '_um_cool_but_hard_to_guess_plain_pw', $plain ); - } - - - /** - * Set last login for new registered users - */ - function set_last_login() { - update_user_meta( $this->id, '_um_last_login', current_time( 'timestamp' ) ); - } - - - /** - * Set user's account status - * - * @param $status - */ - function set_status( $status ) { - - /** - * UM hook - * - * @type action - * @title um_when_status_is_set - * @description Action on user status changed - * @input_vars - * [{"var":"$user_id","type":"int","desc":"User ID"}] - * @change_log - * ["Since: 2.0"] - * @usage add_action( 'um_when_status_is_set', 'function_name', 10, 1 ); - * @example - * - */ - do_action( 'um_when_status_is_set', um_user( 'ID' ) ); - - $this->profile['account_status'] = $status; - - $this->update_usermeta_info( 'account_status' ); - - /** - * UM hook - * - * @type action - * @title um_after_user_status_is_changed_hook - * @description Action after user status changed - * @change_log - * ["Since: 2.0"] - * @usage add_action( 'um_after_user_status_is_changed_hook', 'function_name', 10 ); - * @example - * - */ - do_action( 'um_after_user_status_is_changed_hook' ); - - /** - * UM hook - * - * @type action - * @title um_after_user_status_is_changed - * @description Action after user status changed - * @input_vars - * [{"var":"$status","type":"string","desc":"User Status"}] - * @change_log - * ["Since: 2.0"] - * @usage add_action( 'um_after_user_status_is_changed', 'function_name', 10, 1 ); - * @example - * - */ - do_action( 'um_after_user_status_is_changed', $status ); - - } - - /*** - *** @Set user's hash for password reset - ***/ - function password_reset_hash(){ - $this->profile['reset_pass_hash'] = UM()->validation()->generate(); - $this->update_usermeta_info('reset_pass_hash'); - - } - - /*** - *** @Set user's hash - ***/ - function assign_secretkey() { - /** - * UM hook - * - * @type action - * @title um_before_user_hash_is_changed - * @description Action before user hash is changed - * @change_log - * ["Since: 2.0"] - * @usage add_action( 'um_before_user_hash_is_changed', 'function_name', 10 ); - * @example - * - */ - do_action( 'um_before_user_hash_is_changed' ); - - $this->profile['account_secret_hash'] = UM()->validation()->generate(); - $this->update_usermeta_info( 'account_secret_hash' ); - /** - * UM hook - * - * @type action - * @title um_after_user_hash_is_changed - * @description Action after user hash is changed - * @change_log - * ["Since: 2.0"] - * @usage add_action( 'um_after_user_hash_is_changed', 'function_name', 10 ); - * @example - * - */ - do_action( 'um_after_user_hash_is_changed' ); - - } - - /*** - *** @password reset email - ***/ - function password_reset(){ - $this->password_reset_hash(); - UM()->mail()->send( um_user('user_email'), 'resetpw_email' ); - } - - - /*** - *** @password changed email - ***/ - function password_changed(){ - UM()->mail()->send( um_user('user_email'), 'changedpw_email' ); - } - - /** - * @function approve() - * - * @description This method approves a user membership and sends them an optional welcome/approval e-mail. - * - * @usage user->approve(); ?> - * - * @returns Approves a user membership. - * - * @example Approve a pending user and allow him to sign-in to your site. - - user->approve(); - - ?> - - * - * - */ - function approve(){ - $user_id = um_user('ID'); - delete_option( "um_cache_userdata_{$user_id}" ); - - if ( um_user('account_status') == 'awaiting_admin_review' ) { - $this->password_reset_hash(); - UM()->mail()->send( um_user('user_email'), 'approved_email' ); - - } else { - $this->password_reset_hash(); - UM()->mail()->send( um_user('user_email'), 'welcome_email'); - } - - $this->set_status('approved'); - $this->delete_meta('account_secret_hash'); - $this->delete_meta('_um_cool_but_hard_to_guess_plain_pw'); - - /** - * UM hook - * - * @type action - * @title um_after_user_is_approved - * @description Action after user was approved - * @input_vars - * [{"var":"$user_id","type":"int","desc":"User ID"}] - * @change_log - * ["Since: 2.0"] - * @usage add_action( 'um_after_user_is_approved', 'function_name', 10, 1 ); - * @example - * - */ - do_action( 'um_after_user_is_approved', um_user( 'ID' ) ); - } - - /*** - *** @pending email - ***/ - function email_pending() { - $this->assign_secretkey(); - $this->set_status('awaiting_email_confirmation'); - UM()->mail()->send( um_user('user_email'), 'checkmail_email' ); - } - - /** - * @function pending() - * - * @description This method puts a user under manual review by administrator and sends them an optional e-mail. - * - * @usage user->pending(); ?> - * - * @returns Puts a user under review and sends them an email optionally. - * - * @example An example of putting a user pending manual review - - user->pending(); - - ?> - - * - * - */ - function pending() { - $this->set_status( 'awaiting_admin_review' ); - UM()->mail()->send( um_user( 'user_email' ), 'pending_email' ); - } - - /** - * @function reject() - * - * @description This method rejects a user membership and sends them an optional e-mail. - * - * @usage user->reject(); ?> - * - * @returns Rejects a user membership. - * - * @example Reject a user membership example - - user->reject(); - - ?> - - * - * - */ - function reject(){ - $this->set_status('rejected'); - UM()->mail()->send( um_user('user_email'), 'rejected_email' ); - } - - /** - * @function deactivate() - * - * @description This method deactivates a user membership and sends them an optional e-mail. - * - * @usage user->deactivate(); ?> - * - * @returns Deactivates a user membership. - * - * @example Deactivate a user membership with the following example - - user->deactivate(); - - ?> - - * - * - */ - function deactivate(){ - $this->set_status( 'inactive' ); - /** - * UM hook - * - * @type action - * @title um_after_user_is_inactive - * @description Action after user was inactive - * @input_vars - * [{"var":"$user_id","type":"int","desc":"User ID"}] - * @change_log - * ["Since: 2.0"] - * @usage add_action( 'um_after_user_is_inactive', 'function_name', 10, 1 ); - * @example - * - */ - do_action( 'um_after_user_is_inactive', um_user( 'ID' ) ); - - UM()->mail()->send( um_user( 'user_email' ), 'inactive_email' ); - } - - - /*** - *** @delete user - ***/ - function delete( $send_mail = true ) { - /** - * UM hook - * - * @type action - * @title um_delete_user_hook - * @description On delete user - * @change_log - * ["Since: 2.0"] - * @usage add_action( 'um_delete_user_hook', 'function_name', 10 ); - * @example - * - */ - do_action( 'um_delete_user_hook' ); - /** - * UM hook - * - * @type action - * @title um_delete_user - * @description On delete user - * @input_vars - * [{"var":"$user_id","type":"int","desc":"User ID"}] - * @change_log - * ["Since: 2.0"] - * @usage add_action( 'um_delete_user', 'function_name', 10, 1 ); - * @example - * - */ - do_action( 'um_delete_user', um_user( 'ID' ) ); - - // send email notifications - if ( $send_mail ) { - UM()->mail()->send( um_user('user_email'), 'deletion_email' ); - UM()->mail()->send( um_admin_email(), 'notification_deletion', array('admin' => true ) ); - } - - // remove uploads - UM()->files()->remove_dir( um_user_uploads_dir() ); - - // remove user - if ( is_multisite() ) { - - if ( !function_exists('wpmu_delete_user') ) { - require_once( ABSPATH . 'wp-admin/includes/ms.php' ); - } - - wpmu_delete_user( $this->id ); - - } else { - - if ( !function_exists('wp_delete_user') ) { - require_once( ABSPATH . 'wp-admin/includes/user.php' ); - } - - wp_delete_user( $this->id ); - - } - - } - - /** - * @function get_role() - * - * @description This method gets a user role in slug format. e.g. member - * - * @usage user->get_role(); ?> - * - * @returns The user role's slug. - * - * @example Do something if the user's role is paid-member - - user->get_role() == 'paid-member' ) { - // Show this to paid customers - } else { - // You are a free member - } - - ?> - - * - * - */ - function get_role() { - if ( ! empty( $this->profile['role'] ) ) { - return $this->profile['role']; - } else { - if ( $this->profile['wp_roles'] == 'administrator' ) { - return 'admin'; - } else { - return 'member'; - } - } - } - - - /*** - *** @Update one key in user meta - ***/ - function update_usermeta_info( $key ) { - // delete the key first just in case - delete_user_meta( $this->id, $key ); - update_user_meta( $this->id, $key, $this->profile[$key] ); - } - - /** - * @function delete_meta() - * - * @description This method can be used to delete user's meta key. - * - * @usage user->delete_meta( $key ); ?> - * - * @param $key (string) (required) The meta field key to remove from user - * - * @returns This method will not return anything. The specified meta key will be deleted from database for the specified user. - * - * @example Delete user's age field - - user->delete_meta( 'age' ); - - ?> - - * - * - */ - function delete_meta( $key ){ - delete_user_meta( $this->id, $key ); - } - - - /*** - *** @Get admin actions for individual user - ***/ - function get_admin_actions() { - $items = array(); - $actions = array(); - /** - * UM hook - * - * @type filter - * @title um_admin_user_actions_hook - * @description Extend admin actions for each user - * @input_vars - * [{"var":"$actions","type":"array","desc":"Actions for user"}] - * @change_log - * ["Since: 2.0"] - * @usage - * - * @example - * - */ - $actions = apply_filters('um_admin_user_actions_hook', $actions ); - if ( !isset( $actions ) || empty( $actions ) ) return false; - foreach($actions as $id => $arr ) { - $url = add_query_arg('um_action', $id ); - $url = add_query_arg('uid', um_profile_id(), $url ); - $items[] = '' . $arr['label'] . ''; - } - return $items; - } - - /** - * @function is_private_profile() - * - * @description This method checks if give user profile is private. - * - * @usage user->is_private_profile( $user_id ); ?> - * - * @param $user_id (numeric) (required) A user ID must be passed to check if the user profile is private - * - * @returns Returns true if user profile is private and false if user profile is public. - * - * @example This example display a specific user's name If his profile is public - - user->is_private_profile( 60 ); - if ( !$is_private ) { - echo 'User is public and his name is ' . um_user('display_name'); - } - - ?> - - * - * - */ - function is_private_profile( $user_id ) { - $privacy = get_user_meta( $user_id, 'profile_privacy', true ); - if ( $privacy == __('Only me','ultimate-member') ) { - return true; - } - return false; - } - - /** - * @function is_approved() - * - * @description This method can be used to determine If a certain user is approved or not. - * - * @usage user->is_approved( $user_id ); ?> - * - * @param $user_id (numeric) (required) The user ID to check approval status for - * - * @returns True if user is approved and false if user is not approved. - * - * @example Do something If a user's membership is approved - - user->is_approved( 55 ) { - // User account is approved - } else { - // User account is not approved - } - - ?> - - * - * - */ - function is_approved( $user_id ) { - $status = get_user_meta( $user_id, 'account_status', true ); - if ( $status == 'approved' || $status == '' ) { - return true; - } - return false; - } - - /*** - *** @Is private - ***/ - function is_private_case( $user_id, $case ) { - $privacy = get_user_meta( $user_id, 'profile_privacy', true ); - - if ( $privacy == $case ) { - /** - * UM hook - * - * @type filter - * @title um_is_private_filter_hook - * @description Change user privacy - * @input_vars - * [{"var":"$is_private","type":"bool","desc":"Is user private"}, - * {"var":"$privacy","type":"bool","desc":"Profile Privacy"}, - * {"var":"$user_id","type":"int","desc":"User ID"}] - * @change_log - * ["Since: 2.0"] - * @usage - * - * @example - * - */ - $bool = apply_filters( 'um_is_private_filter_hook', false, $privacy, $user_id ); - return $bool; - } - - return false; - } - - /*** - *** @update files - ***/ - function update_files( $changes ) { - - foreach( $changes as $key => $uri ) { - $src = um_is_temp_upload( $uri ); - UM()->files()->new_user_upload( $this->id, $src, $key ); - } - - } - - - /*** - *** @update profile - ***/ - function update_profile( $changes ) { - - $args['ID'] = $this->id; - - /** - * UM hook - * - * @type filter - * @title um_before_update_profile - * @description Change update profile changes data - * @input_vars - * [{"var":"$changes","type":"array","desc":"User Profile Changes"}, - * {"var":"$user_id","type":"int","desc":"User ID"}] - * @change_log - * ["Since: 2.0"] - * @usage - * - * @example - * - */ - $changes = apply_filters('um_before_update_profile', $changes, $this->id ); - - // save or update profile meta - foreach ( $changes as $key => $value ) { - if ( ! in_array( $key, $this->update_user_keys ) ) { - - update_user_meta( $this->id, $key, $value ); - - } else { - - $args[$key] = esc_attr( $changes[$key] ); - - } - - } - // update user - if ( count( $args ) > 1 ) { - global $wp_roles; - $um_roles = get_option( 'um_roles' ); - - if ( ! empty( $um_roles ) ) { - $role_keys = array_map( function( $item ) { - return 'um_' . $item; - }, get_option( 'um_roles' ) ); - } else { - $role_keys = array(); - } - - $exclude_roles = array_diff( array_keys( $wp_roles->roles ), array_merge( $role_keys, array( 'subscriber' ) ) ); - - if ( isset( $args['role'] ) && in_array( $args['role'], $exclude_roles ) ) { - unset( $args['role'] ); - } - - wp_update_user( $args ); - } - - } - - /*** - *** @user exists by meta key and value - ***/ - function user_has_metadata( $key, $value ) { - - $value = UM()->validation()->safe_name_in_url( $value ); - - $ids = get_users(array( 'fields' => 'ID', 'meta_key' => $key,'meta_value' => $value,'meta_compare' => '=') ); - if ( !isset( $ids ) || empty( $ids ) ) return false; - foreach( $ids as $k => $id ) { - if ( $id == um_user('ID') ){ - unset( $ids[$k] ); - } else { - $duplicates[] = $id; - } - } - if ( isset( $duplicates ) && !empty( $duplicates ) ) - return count( $duplicates ); - return false; - } - - - /*** - *** @user exists by name - ***/ - function user_exists_by_name( $value ) { - - // Permalink base - $permalink_base = UM()->options()->get( 'permalink_base' ); - - $raw_value = $value; - $value = UM()->validation()->safe_name_in_url( $value ); - $value = um_clean_user_basename( $value ); - - // Search by Profile Slug - $args = array( - "fields" => array("ID"), - 'meta_query' => array( - 'relation' => 'OR', - array( - 'key' => 'um_user_profile_url_slug_'.$permalink_base, - 'value' => strtolower( $raw_value ), - 'compare' => '=' - - ) - - ) - ); - - - $ids = new \WP_User_Query( $args ); - - if( $ids->total_users > 0 ){ - $um_user_query = current( $ids->get_results() ); - return $um_user_query->ID; - } - - // Search by Display Name or ID - $args = array( - "fields" => array("ID"), - "search" => $value, - 'search_columns' => array( 'display_name','ID' ) - ); - - $ids = new \WP_User_Query( $args ); - - if( $ids->total_users > 0 ){ - $um_user_query = current( $ids->get_results() ); - return $um_user_query->ID; - } - - - // Search By User Login - $value = str_replace(".", "_", $value ); - $value = str_replace(" ", "", $value ); - - $args = array( - "fields" => array("ID"), - "search" => $value, - 'search_columns' => array( - 'user_login', - ) - ); - - $ids = new \WP_User_Query( $args ); - - if( $ids->total_users > 0 ){ - $um_user_query = current( $ids->get_results() ); - return $um_user_query->ID; - } - - return false; - } - - - /** - * @function user_exists_by_id() - * - * @description This method checks if a user exists or not in your site based on the user ID. - * - * @usage user->user_exists_by_id( $user_id ); ?> - * - * @param $user_id (numeric) (required) A user ID must be passed to check if the user exists - * - * @returns Returns true if user exists and false if user does not exist. - * - * @example Basic Usage - - user->user_exists_by_id( 15 ); - if ( $boolean ) { - // That user exists - } - - ?> - - * - * - */ - function user_exists_by_id( $user_id ) { - $aux = get_userdata( intval( $user_id ) ); - if($aux==false){ - return false; - } else { - return $user_id; - } - } - - - /** - * @function user_exists_by_email_as_username() - * - * @description This method checks if a user exists or not in your site based on the user email as username - * - * @usage user->user_exists_by_email_as_username( $slug ); ?> - * - * @param $slug (string) (required) A user slug must be passed to check if the user exists - * - * @returns Returns true if user exists and false if user does not exist. - * - * @example Basic Usage - - user->user_exists_by_email_as_username( 'calumgmail-com' ); - if ( $boolean ) { - // That user exists - } - - ?> - - * - * - */ - function user_exists_by_email_as_username( $slug ){ - - $user_id = false; - - $ids = get_users( array( 'fields' => 'ID', 'meta_key' => 'um_email_as_username_'.$slug ) ); - if ( isset( $ids[0] ) && ! empty( $ids[0] ) ){ - $user_id = $ids[0]; - } - - return $user_id; - } - - - /** - * Set gravatar hash id - * - * @param $user_id - * @return string - */ - function set_gravatar( $user_id ) { - - um_fetch_user( $user_id ); - $email_address = um_user( 'user_email' ); - $hash_email_address = ''; - - if ( $email_address ) { - $hash_email_address = md5( $email_address ); - $this->profile['synced_gravatar_hashed_id'] = $hash_email_address; - $this->update_usermeta_info( 'synced_gravatar_hashed_id' ); - } - - return $hash_email_address; - } - - } + $this->profile = array_merge( $this->profile, (array)$role_meta ); + + $this->profile['super_admin'] = ( is_super_admin( $this->id ) ) ? 1 : 0; + + // clean profile + $this->clean(); + + // Setup cache + $this->setup_cache( $this->id, $this->profile ); + + } + + } + + } + + + /** + * Reset user data + * + * @param bool $clean + */ + function reset( $clean = false ){ + $this->set(0, $clean); + } + + + /** + * Clean user profile + */ + function clean() { + foreach($this->profile as $key => $value){ + foreach($this->banned_keys as $ban){ + if (strstr($key, $ban) || is_numeric($key) ) + unset($this->profile[$key]); + } + } + } + + + /** + * This method lets you auto sign-in a user to your site. + * + * @usage user()->auto_login( $user_id, $rememberme = false ); ?> + * + * @param int $user_id Which user ID to sign in automatically + * @param int|bool $rememberme Should be true or false. If you want the user sign in session to use cookies, use true + * + * @example The following example lets you sign in a user automatically by their ID. + + user()->auto_login( 2 ); ?> + * + * + * @example The following example lets you sign in a user automatically by their ID and makes the plugin remember their session. + + user()->auto_login( 10, true ); ?> + * + */ + function auto_login( $user_id, $rememberme = 0 ) { + + wp_set_current_user( $user_id ); + + wp_set_auth_cookie( $user_id, $rememberme ); + + $user = get_user_by('ID', $user_id ); + + do_action( 'wp_login', $user->user_login, $user ); + + } + + + /** + * Set user's registration details + * + * @param $submitted + */ + function set_registration_details( $submitted ) { + + if ( isset( $submitted['user_pass'] ) ) { + unset( $submitted['user_pass'] ); + } + + if ( isset( $submitted['user_password'] ) ) { + unset( $submitted['user_password'] ); + } + + if ( isset( $submitted['confirm_user_password'] ) ) { + unset( $submitted['confirm_user_password'] ); + } + + /** + * UM hook + * + * @type filter + * @title um_before_save_filter_submitted + * @description Change submitted data before save usermeta "submitted" on registration process + * @input_vars + * [{"var":"$submitted","type":"array","desc":"Submitted data"}] + * @change_log + * ["Since: 2.0"] + * @usage + * + * @example + * + */ + $submitted = apply_filters( 'um_before_save_filter_submitted', $submitted ); + + /** + * UM hook + * + * @type action + * @title um_before_save_registration_details + * @description Action on user registration before save details + * @input_vars + * [{"var":"$user_id","type":"int","desc":"User ID"}, + * {"var":"$submitted","type":"array","desc":"Registration form submitted"}] + * @change_log + * ["Since: 2.0"] + * @usage add_action( 'um_before_save_registration_details', 'function_name', 10, 2 ); + * @example + * + */ + do_action( 'um_before_save_registration_details', $this->id, $submitted ); + + update_user_meta( $this->id, 'submitted', $submitted ); + + $this->update_profile( $submitted ); + /** + * UM hook + * + * @type action + * @title um_after_save_registration_details + * @description Action on user registration after save details + * @input_vars + * [{"var":"$user_id","type":"int","desc":"User ID"}, + * {"var":"$submitted","type":"array","desc":"Registration form submitted"}] + * @change_log + * ["Since: 2.0"] + * @usage add_action( 'um_after_save_registration_details', 'function_name', 10, 2 ); + * @example + * + */ + do_action( 'um_after_save_registration_details', $this->id, $submitted ); + + } + + + /** + * A plain version of password + * + * @param $plain + */ + function set_plain_password( $plain ) { + update_user_meta( $this->id, '_um_cool_but_hard_to_guess_plain_pw', $plain ); + } + + + /** + * Set last login for new registered users + */ + function set_last_login() { + update_user_meta( $this->id, '_um_last_login', current_time( 'timestamp' ) ); + } + + + /** + * Set user's account status + * + * @param $status + */ + function set_status( $status ) { + + /** + * UM hook + * + * @type action + * @title um_when_status_is_set + * @description Action on user status changed + * @input_vars + * [{"var":"$user_id","type":"int","desc":"User ID"}] + * @change_log + * ["Since: 2.0"] + * @usage add_action( 'um_when_status_is_set', 'function_name', 10, 1 ); + * @example + * + */ + do_action( 'um_when_status_is_set', um_user( 'ID' ) ); + + $this->profile['account_status'] = $status; + + $this->update_usermeta_info( 'account_status' ); + + /** + * UM hook + * + * @type action + * @title um_after_user_status_is_changed_hook + * @description Action after user status changed + * @change_log + * ["Since: 2.0"] + * @usage add_action( 'um_after_user_status_is_changed_hook', 'function_name', 10 ); + * @example + * + */ + do_action( 'um_after_user_status_is_changed_hook' ); + + /** + * UM hook + * + * @type action + * @title um_after_user_status_is_changed + * @description Action after user status changed + * @input_vars + * [{"var":"$status","type":"string","desc":"User Status"}] + * @change_log + * ["Since: 2.0"] + * @usage add_action( 'um_after_user_status_is_changed', 'function_name', 10, 1 ); + * @example + * + */ + do_action( 'um_after_user_status_is_changed', $status ); + + } + + + /** + * Set user's hash for password reset + */ + function password_reset_hash() { + $this->profile['reset_pass_hash'] = UM()->validation()->generate(); + $this->update_usermeta_info('reset_pass_hash'); + } + + + /** + * Set user's hash + */ + function assign_secretkey() { + /** + * UM hook + * + * @type action + * @title um_before_user_hash_is_changed + * @description Action before user hash is changed + * @change_log + * ["Since: 2.0"] + * @usage add_action( 'um_before_user_hash_is_changed', 'function_name', 10 ); + * @example + * + */ + do_action( 'um_before_user_hash_is_changed' ); + + $this->profile['account_secret_hash'] = UM()->validation()->generate(); + $this->update_usermeta_info( 'account_secret_hash' ); + /** + * UM hook + * + * @type action + * @title um_after_user_hash_is_changed + * @description Action after user hash is changed + * @change_log + * ["Since: 2.0"] + * @usage add_action( 'um_after_user_hash_is_changed', 'function_name', 10 ); + * @example + * + */ + do_action( 'um_after_user_hash_is_changed' ); + } + + + /** + * Password reset email + */ + function password_reset() { + $this->password_reset_hash(); + UM()->mail()->send( um_user('user_email'), 'resetpw_email' ); + } + + + /** + * Password changed email + */ + function password_changed(){ + UM()->mail()->send( um_user('user_email'), 'changedpw_email' ); + } + + + /** + * This method approves a user membership and sends them an optional welcome/approval e-mail. + * + * @usage user()->approve(); ?> + * + * @example Approve a pending user and allow him to sign-in to your site. + + user()->approve(); + + ?> + * + */ + function approve() { + $user_id = um_user('ID'); + delete_option( "um_cache_userdata_{$user_id}" ); + + if ( um_user('account_status') == 'awaiting_admin_review' ) { + $this->password_reset_hash(); + UM()->mail()->send( um_user('user_email'), 'approved_email' ); + + } else { + $this->password_reset_hash(); + UM()->mail()->send( um_user('user_email'), 'welcome_email'); + } + + $this->set_status('approved'); + $this->delete_meta('account_secret_hash'); + $this->delete_meta('_um_cool_but_hard_to_guess_plain_pw'); + + /** + * UM hook + * + * @type action + * @title um_after_user_is_approved + * @description Action after user was approved + * @input_vars + * [{"var":"$user_id","type":"int","desc":"User ID"}] + * @change_log + * ["Since: 2.0"] + * @usage add_action( 'um_after_user_is_approved', 'function_name', 10, 1 ); + * @example + * + */ + do_action( 'um_after_user_is_approved', um_user( 'ID' ) ); + } + + + /** + * Pending email + */ + function email_pending() { + $this->assign_secretkey(); + $this->set_status('awaiting_email_confirmation'); + UM()->mail()->send( um_user('user_email'), 'checkmail_email' ); + } + + + /** + * This method puts a user under manual review by administrator and sends them an optional e-mail. + * + * @usage user()->pending(); ?> + * + * @example An example of putting a user pending manual review + + user()->pending(); + + ?> + * + */ + function pending() { + $this->set_status( 'awaiting_admin_review' ); + UM()->mail()->send( um_user( 'user_email' ), 'pending_email' ); + } + + + /** + * This method rejects a user membership and sends them an optional e-mail. + * + * @usage user()->reject(); ?> + * + * @example Reject a user membership example + + user()->reject(); + + ?> + + * + */ + function reject() { + $this->set_status('rejected'); + UM()->mail()->send( um_user('user_email'), 'rejected_email' ); + } + + + /** + * This method deactivates a user membership and sends them an optional e-mail. + * + * @usage user()->deactivate(); ?> + * + * @example Deactivate a user membership with the following example + + user->deactivate(); + + ?> + * + */ + function deactivate() { + $this->set_status( 'inactive' ); + /** + * UM hook + * + * @type action + * @title um_after_user_is_inactive + * @description Action after user was inactive + * @input_vars + * [{"var":"$user_id","type":"int","desc":"User ID"}] + * @change_log + * ["Since: 2.0"] + * @usage add_action( 'um_after_user_is_inactive', 'function_name', 10, 1 ); + * @example + * + */ + do_action( 'um_after_user_is_inactive', um_user( 'ID' ) ); + + UM()->mail()->send( um_user( 'user_email' ), 'inactive_email' ); + } + + + /** + * Delete user + * + * @param bool $send_mail + */ + function delete( $send_mail = true ) { + /** + * UM hook + * + * @type action + * @title um_delete_user_hook + * @description On delete user + * @change_log + * ["Since: 2.0"] + * @usage add_action( 'um_delete_user_hook', 'function_name', 10 ); + * @example + * + */ + do_action( 'um_delete_user_hook' ); + /** + * UM hook + * + * @type action + * @title um_delete_user + * @description On delete user + * @input_vars + * [{"var":"$user_id","type":"int","desc":"User ID"}] + * @change_log + * ["Since: 2.0"] + * @usage add_action( 'um_delete_user', 'function_name', 10, 1 ); + * @example + * + */ + do_action( 'um_delete_user', um_user( 'ID' ) ); + + // send email notifications + if ( $send_mail ) { + UM()->mail()->send( um_user('user_email'), 'deletion_email' ); + UM()->mail()->send( um_admin_email(), 'notification_deletion', array('admin' => true ) ); + } + + // remove uploads + UM()->files()->remove_dir( um_user_uploads_dir() ); + + // remove user + if ( is_multisite() ) { + + if ( !function_exists('wpmu_delete_user') ) { + require_once( ABSPATH . 'wp-admin/includes/ms.php' ); + } + + wpmu_delete_user( $this->id ); + + } else { + + if ( !function_exists('wp_delete_user') ) { + require_once( ABSPATH . 'wp-admin/includes/user.php' ); + } + + wp_delete_user( $this->id ); + + } + + } + + + /** + * This method gets a user role in slug format. e.g. member + * + * @usage user()->get_role(); ?> + * + * @return string + * + * @example Do something if the user's role is paid-member + + user()->get_role() == 'paid-member' ) { + // Show this to paid customers + } else { + // You are a free member + } + + ?> + * + */ + function get_role() { + if ( ! empty( $this->profile['role'] ) ) { + return $this->profile['role']; + } else { + if ( $this->profile['wp_roles'] == 'administrator' ) { + return 'admin'; + } else { + return 'member'; + } + } + } + + + /** + * Update one key in user meta + * + * @param $key + */ + function update_usermeta_info( $key ) { + // delete the key first just in case + delete_user_meta( $this->id, $key ); + update_user_meta( $this->id, $key, $this->profile[$key] ); + } + + + /** + * This method can be used to delete user's meta key. + * + * @usage user()->delete_meta( $key ); ?> + * + * @param string $key The meta field key to remove from user + * + * @example Delete user's age field + + user()->delete_meta( 'age' ); + + ?> + + * + */ + function delete_meta( $key ){ + delete_user_meta( $this->id, $key ); + } + + + /** + * Get admin actions for individual user + * + * @return array|bool + */ + function get_admin_actions() { + $items = array(); + $actions = array(); + /** + * UM hook + * + * @type filter + * @title um_admin_user_actions_hook + * @description Extend admin actions for each user + * @input_vars + * [{"var":"$actions","type":"array","desc":"Actions for user"}] + * @change_log + * ["Since: 2.0"] + * @usage + * + * @example + * + */ + $actions = apply_filters('um_admin_user_actions_hook', $actions ); + if ( !isset( $actions ) || empty( $actions ) ) return false; + foreach($actions as $id => $arr ) { + $url = add_query_arg('um_action', $id ); + $url = add_query_arg('uid', um_profile_id(), $url ); + $items[] = '' . $arr['label'] . ''; + } + return $items; + } + + + /** + * This method checks if give user profile is private. + * + * @usage user()->is_private_profile( $user_id ); ?> + * + * @param int $user_id A user ID must be passed to check if the user profile is private + * + * @return bool + * + * @example This example display a specific user's name If his profile is public + + user()->is_private_profile( 60 ); + if ( ! $is_private ) { + echo 'User is public and his name is ' . um_user('display_name'); + } + + ?> + * + */ + function is_private_profile( $user_id ) { + $privacy = get_user_meta( $user_id, 'profile_privacy', true ); + if ( $privacy == __('Only me','ultimate-member') ) { + return true; + } + return false; + } + + + /** + * This method can be used to determine If a certain user is approved or not. + * + * @usage user()->is_approved( $user_id ); ?> + * + * @param int $user_id The user ID to check approval status for + * + * @return bool + * + * @example Do something If a user's membership is approved + + user()->is_approved( 55 ) { + // User account is approved + } else { + // User account is not approved + } + + ?> + * + */ + function is_approved( $user_id ) { + $status = get_user_meta( $user_id, 'account_status', true ); + if ( $status == 'approved' || $status == '' ) { + return true; + } + return false; + } + + + /** + * Is private + * + * @param $user_id + * @param $case + * + * @return bool|mixed|void + */ + function is_private_case( $user_id, $case ) { + $privacy = get_user_meta( $user_id, 'profile_privacy', true ); + + if ( $privacy == $case ) { + /** + * UM hook + * + * @type filter + * @title um_is_private_filter_hook + * @description Change user privacy + * @input_vars + * [{"var":"$is_private","type":"bool","desc":"Is user private"}, + * {"var":"$privacy","type":"bool","desc":"Profile Privacy"}, + * {"var":"$user_id","type":"int","desc":"User ID"}] + * @change_log + * ["Since: 2.0"] + * @usage + * + * @example + * + */ + $bool = apply_filters( 'um_is_private_filter_hook', false, $privacy, $user_id ); + return $bool; + } + + return false; + } + + + /** + * Update files + * + * @param $changes + */ + function update_files( $changes ) { + + foreach ( $changes as $key => $uri ) { + $src = um_is_temp_upload( $uri ); + UM()->files()->new_user_upload( $this->id, $src, $key ); + } + + } + + + /** + * Update profile + * + * @param $changes + */ + function update_profile( $changes ) { + + $args['ID'] = $this->id; + + /** + * UM hook + * + * @type filter + * @title um_before_update_profile + * @description Change update profile changes data + * @input_vars + * [{"var":"$changes","type":"array","desc":"User Profile Changes"}, + * {"var":"$user_id","type":"int","desc":"User ID"}] + * @change_log + * ["Since: 2.0"] + * @usage + * + * @example + * + */ + $changes = apply_filters('um_before_update_profile', $changes, $this->id ); + + // save or update profile meta + foreach ( $changes as $key => $value ) { + if ( ! in_array( $key, $this->update_user_keys ) ) { + + update_user_meta( $this->id, $key, $value ); + + } else { + + $args[$key] = esc_attr( $changes[$key] ); + + } + + } + // update user + if ( count( $args ) > 1 ) { + global $wp_roles; + $um_roles = get_option( 'um_roles' ); + + if ( ! empty( $um_roles ) ) { + $role_keys = array_map( function( $item ) { + return 'um_' . $item; + }, get_option( 'um_roles' ) ); + } else { + $role_keys = array(); + } + + $exclude_roles = array_diff( array_keys( $wp_roles->roles ), array_merge( $role_keys, array( 'subscriber' ) ) ); + + if ( isset( $args['role'] ) && in_array( $args['role'], $exclude_roles ) ) { + unset( $args['role'] ); + } + + wp_update_user( $args ); + } + + } + + + /** + * User exists by meta key and value + * + * @param $key + * @param $value + * + * @return bool|int + */ + function user_has_metadata( $key, $value ) { + + $value = UM()->validation()->safe_name_in_url( $value ); + + $ids = get_users(array( 'fields' => 'ID', 'meta_key' => $key,'meta_value' => $value,'meta_compare' => '=') ); + if ( !isset( $ids ) || empty( $ids ) ) return false; + foreach( $ids as $k => $id ) { + if ( $id == um_user('ID') ){ + unset( $ids[$k] ); + } else { + $duplicates[] = $id; + } + } + if ( isset( $duplicates ) && !empty( $duplicates ) ) + return count( $duplicates ); + return false; + } + + + /** + * User exists by name + * + * @param $value + * + * @return bool + */ + function user_exists_by_name( $value ) { + + // Permalink base + $permalink_base = UM()->options()->get( 'permalink_base' ); + + $raw_value = $value; + $value = UM()->validation()->safe_name_in_url( $value ); + $value = um_clean_user_basename( $value ); + + // Search by Profile Slug + $args = array( + "fields" => array("ID"), + 'meta_query' => array( + 'relation' => 'OR', + array( + 'key' => 'um_user_profile_url_slug_'.$permalink_base, + 'value' => strtolower( $raw_value ), + 'compare' => '=' + + ) + + ) + ); + + + $ids = new \WP_User_Query( $args ); + + if( $ids->total_users > 0 ){ + $um_user_query = current( $ids->get_results() ); + return $um_user_query->ID; + } + + // Search by Display Name or ID + $args = array( + "fields" => array("ID"), + "search" => $value, + 'search_columns' => array( 'display_name','ID' ) + ); + + $ids = new \WP_User_Query( $args ); + + if( $ids->total_users > 0 ){ + $um_user_query = current( $ids->get_results() ); + return $um_user_query->ID; + } + + + // Search By User Login + $value = str_replace(".", "_", $value ); + $value = str_replace(" ", "", $value ); + + $args = array( + "fields" => array("ID"), + "search" => $value, + 'search_columns' => array( + 'user_login', + ) + ); + + $ids = new \WP_User_Query( $args ); + + if( $ids->total_users > 0 ){ + $um_user_query = current( $ids->get_results() ); + return $um_user_query->ID; + } + + return false; + } + + + /** + * This method checks if a user exists or not in your site based on the user ID. + * + * @usage user()->user_exists_by_id( $user_id ); ?> + * + * @param int $user_id A user ID must be passed to check if the user exists + * + * @return bool|int + * + * @example Basic Usage + + user()->user_exists_by_id( 15 ); + if ( $boolean ) { + // That user exists + } + + ?> + + * + */ + function user_exists_by_id( $user_id ) { + $aux = get_userdata( intval( $user_id ) ); + if( $aux == false ) { + return false; + } else { + return $user_id; + } + } + + + /** + * This method checks if a user exists or not in your site based on the user email as username + * + * @param string $slug A user slug must be passed to check if the user exists + * + * @usage user()->user_exists_by_email_as_username( $slug ); ?> + * + * @return bool + * + * @example Basic Usage + + user()->user_exists_by_email_as_username( 'calumgmail-com' ); + if ( $boolean ) { + // That user exists + } + + ?> + */ + function user_exists_by_email_as_username( $slug ) { + + $user_id = false; + + $ids = get_users( array( 'fields' => 'ID', 'meta_key' => 'um_email_as_username_'.$slug ) ); + if ( isset( $ids[0] ) && ! empty( $ids[0] ) ){ + $user_id = $ids[0]; + } + + return $user_id; + } + + + /** + * Set gravatar hash id + * + * @param $user_id + * @return string + */ + function set_gravatar( $user_id ) { + + um_fetch_user( $user_id ); + $email_address = um_user( 'user_email' ); + $hash_email_address = ''; + + if ( $email_address ) { + $hash_email_address = md5( $email_address ); + $this->profile['synced_gravatar_hashed_id'] = $hash_email_address; + $this->update_usermeta_info( 'synced_gravatar_hashed_id' ); + } + + return $hash_email_address; + } + + } } \ No newline at end of file diff --git a/includes/core/um-actions-core.php b/includes/core/um-actions-core.php index 8d83c265..2c85e9cb 100644 --- a/includes/core/um-actions-core.php +++ b/includes/core/um-actions-core.php @@ -1,108 +1,119 @@ -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 - * - */ - 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 + * + */ + 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; - } - } \ No newline at end of file + } +} +add_action( 'init', 'um_action_request_process', 10 ); \ No newline at end of file diff --git a/includes/core/um-actions-form.php b/includes/core/um-actions-form.php index 7f134cd4..8050be80 100644 --- a/includes/core/um-actions-form.php +++ b/includes/core/um-actions-form.php @@ -1,736 +1,745 @@ -options()->get('blocked_emails'); - if ( !$emails ) - return; +/** + * Error handling: blocked emails + * + * @param $args + */ +function um_submit_form_errors_hook__blockedemails( $args ) { + $emails = UM()->options()->get( 'blocked_emails' ); + if ( ! $emails ) + return; - $emails = array_map("rtrim", explode("\n", $emails)); + $emails = array_map("rtrim", explode("\n", $emails)); - if ( isset( $args['user_email'] ) && is_email( $args['user_email'] ) ) { + if ( isset( $args['user_email'] ) && is_email( $args['user_email'] ) ) { - $domain = explode('@', $args['user_email'] ); - $check_domain = str_replace($domain[0], '*', $args['user_email']); + $domain = explode('@', $args['user_email'] ); + $check_domain = str_replace($domain[0], '*', $args['user_email']); - if ( in_array( $args['user_email'], $emails ) ) - exit( wp_redirect( esc_url( add_query_arg('err', 'blocked_email') ) ) ); + if ( in_array( $args['user_email'], $emails ) ) + exit( wp_redirect( esc_url( add_query_arg('err', 'blocked_email') ) ) ); - if ( in_array( $check_domain, $emails ) ) - exit( wp_redirect( esc_url( add_query_arg('err', 'blocked_domain') ) ) ); - - } - - if ( isset( $args['username'] ) && is_email( $args['username'] ) ) { - - $domain = explode('@', $args['username'] ); - $check_domain = str_replace($domain[0], '*', $args['username']); - - if ( in_array( $args['username'], $emails ) ) - exit( wp_redirect( esc_url( add_query_arg('err', 'blocked_email') ) ) ); - - if ( in_array( $check_domain, $emails ) ) - exit( wp_redirect( esc_url( add_query_arg('err', 'blocked_domain') ) ) ); - - } + if ( in_array( $check_domain, $emails ) ) + exit( wp_redirect( esc_url( add_query_arg('err', 'blocked_domain') ) ) ); } - /*** - *** @Error handling: blocked IPs - ***/ - add_action('um_submit_form_errors_hook__blockedips', 'um_submit_form_errors_hook__blockedips', 10); - function um_submit_form_errors_hook__blockedips($args){ - $ips = UM()->options()->get('blocked_ips'); - if ( !$ips ) - return; + if ( isset( $args['username'] ) && is_email( $args['username'] ) ) { - $ips = array_map("rtrim", explode("\n", $ips)); - $user_ip = um_user_ip(); + $domain = explode('@', $args['username'] ); + $check_domain = str_replace($domain[0], '*', $args['username']); - foreach($ips as $ip) { - $ip = str_replace('*','',$ip); - if ( !empty( $ip ) && strpos($user_ip, $ip) === 0) { - exit( wp_redirect( esc_url( add_query_arg('err', 'blocked_ip') ) ) ); - } - } - } + if ( in_array( $args['username'], $emails ) ) + exit( wp_redirect( esc_url( add_query_arg('err', 'blocked_email') ) ) ); - /*** - *** @Error handling: blocked words during sign up - ***/ - add_action('um_submit_form_errors_hook__blockedwords', 'um_submit_form_errors_hook__blockedwords', 10); - function um_submit_form_errors_hook__blockedwords($args){ - $form_id = $args['form_id']; - $mode = $args['mode']; - $fields = unserialize( $args['custom_fields'] ); - - $words = UM()->options()->get('blocked_words'); - if ( $words != '' ) { - - $words = array_map("rtrim", explode("\n", $words)); - if( isset( $fields ) && ! empty( $fields ) && is_array( $fields ) ){ - foreach( $fields as $key => $array ) { - if ( isset($array['validate']) && in_array( $array['validate'], array('unique_username','unique_email','unique_username_or_email') ) ) { - if ( ! UM()->form()->has_error( $key ) && isset( $args[$key] ) && in_array( $args[$key], $words ) ) { - UM()->form()->add_error( $key, __('You are not allowed to use this word as your username.','ultimate-member') ); - } - } - } - } - - } + if ( in_array( $check_domain, $emails ) ) + exit( wp_redirect( esc_url( add_query_arg('err', 'blocked_domain') ) ) ); } +} +add_action( 'um_submit_form_errors_hook__blockedemails', 'um_submit_form_errors_hook__blockedemails', 10 ); - /*** - *** @Error handling - ***/ - add_action('um_submit_form_errors_hook', 'um_submit_form_errors_hook', 10); - function um_submit_form_errors_hook( $args ){ - $form_id = $args['form_id']; - $mode = $args['mode']; +/** + * Error handling: blocked IPs + * + * @param $args + */ +function um_submit_form_errors_hook__blockedips($args){ + $ips = UM()->options()->get('blocked_ips'); + if ( !$ips ) + return; - $fields = unserialize( $args['custom_fields'] ); - - if ( $mode == 'register' ) { - - /** - * UM hook - * - * @type action - * @title um_submit_form_errors_hook__registration - * @description Submit registration form validation - * @input_vars - * [{"var":"$args","type":"array","desc":"Form Arguments"}] - * @change_log - * ["Since: 2.0"] - * @usage add_action( 'um_submit_form_errors_hook__registration', 'function_name', 10, 1 ); - * @example - * - */ - do_action( "um_submit_form_errors_hook__registration", $args ); + $ips = array_map("rtrim", explode("\n", $ips)); + $user_ip = um_user_ip(); + foreach($ips as $ip) { + $ip = str_replace('*','',$ip); + if ( !empty( $ip ) && strpos($user_ip, $ip) === 0) { + exit( wp_redirect( esc_url( add_query_arg('err', 'blocked_ip') ) ) ); } - /** - * UM hook - * - * @type action - * @title um_submit_form_errors_hook__blockedips - * @description Submit form validation - * @input_vars - * [{"var":"$args","type":"array","desc":"Form Arguments"}] - * @change_log - * ["Since: 2.0"] - * @usage add_action( 'um_submit_form_errors_hook__blockedips', 'function_name', 10, 1 ); - * @example - * - */ - do_action( "um_submit_form_errors_hook__blockedips", $args ); - /** - * UM hook - * - * @type action - * @title um_submit_form_errors_hook__blockedemails - * @description Submit form validation - * @input_vars - * [{"var":"$args","type":"array","desc":"Form Arguments"}] - * @change_log - * ["Since: 2.0"] - * @usage add_action( 'um_submit_form_errors_hook__blockedemails', 'function_name', 10, 1 ); - * @example - * - */ - do_action( "um_submit_form_errors_hook__blockedemails", $args ); - - if ( $mode == 'login' ) { - /** - * UM hook - * - * @type action - * @title um_submit_form_errors_hook_login - * @description Submit login form validation - * @input_vars - * [{"var":"$args","type":"array","desc":"Form Arguments"}] - * @change_log - * ["Since: 2.0"] - * @usage add_action( 'um_submit_form_errors_hook_login', 'function_name', 10, 1 ); - * @example - * - */ - do_action( 'um_submit_form_errors_hook_login', $args ); - /** - * UM hook - * - * @type action - * @title um_submit_form_errors_hook_logincheck - * @description Submit login form validation - * @input_vars - * [{"var":"$args","type":"array","desc":"Form Arguments"}] - * @change_log - * ["Since: 2.0"] - * @usage add_action( 'um_submit_form_errors_hook_logincheck', 'function_name', 10, 1 ); - * @example - * - */ - do_action( 'um_submit_form_errors_hook_logincheck', $args ); - - } else { - /** - * UM hook - * - * @type action - * @title um_submit_form_errors_hook_ - * @description Submit form validation - * @input_vars - * [{"var":"$args","type":"array","desc":"Form Arguments"}] - * @change_log - * ["Since: 2.0"] - * @usage add_action( 'um_submit_form_errors_hook_', 'function_name', 10, 1 ); - * @example - * - */ - do_action( 'um_submit_form_errors_hook_', $args ); - /** - * UM hook - * - * @type action - * @title um_submit_form_errors_hook__blockedwords - * @description Submit form validation - * @input_vars - * [{"var":"$args","type":"array","desc":"Form Arguments"}] - * @change_log - * ["Since: 2.0"] - * @usage add_action( 'um_submit_form_errors_hook__blockedwords', 'function_name', 10, 1 ); - * @example - * - */ - do_action( "um_submit_form_errors_hook__blockedwords", $args ); - - } - } +} +add_action( 'um_submit_form_errors_hook__blockedips', 'um_submit_form_errors_hook__blockedips', 10 ); - /*** - *** @Error processing hook : standard - ***/ - add_action('um_submit_form_errors_hook_', 'um_submit_form_errors_hook_', 10); - function um_submit_form_errors_hook_( $args ){ - $form_id = $args['form_id']; - $mode = $args['mode']; - $fields = unserialize( $args['custom_fields'] ); - $um_profile_photo = um_profile('profile_photo'); - if ( get_post_meta( $form_id, '_um_profile_photo_required', true ) && ( empty( $args['profile_photo'] ) && empty( $um_profile_photo ) ) ) { - UM()->form()->add_error('profile_photo', sprintf(__('%s is required.','ultimate-member'), 'Profile Photo' ) ); - } +/** + * Error handling: blocked words during sign up + * + * @param $args + */ +function um_submit_form_errors_hook__blockedwords( $args ) { + $form_id = $args['form_id']; + $mode = $args['mode']; + $fields = unserialize( $args['custom_fields'] ); - - if ( ! empty( $fields ) ) { + $words = UM()->options()->get('blocked_words'); + if ( $words != '' ) { + + $words = array_map("rtrim", explode("\n", $words)); + if ( ! empty( $fields ) && is_array( $fields ) ) { foreach ( $fields as $key => $array ) { + if ( isset($array['validate']) && in_array( $array['validate'], array('unique_username','unique_email','unique_username_or_email') ) ) { + if ( ! UM()->form()->has_error( $key ) && isset( $args[$key] ) && in_array( $args[$key], $words ) ) { + UM()->form()->add_error( $key, __('You are not allowed to use this word as your username.','ultimate-member') ); + } + } + } + } - if ( isset( $array['public'] ) && -2 == $array['public'] && ! empty( $array['roles'] ) && is_user_logged_in() ) { - $current_user_roles = um_user( 'roles' ); - if ( empty( $current_user_roles ) || count( array_intersect( $current_user_roles, $array['roles'] ) ) <= 0 ) { - continue; - } - } + } +} +add_action( 'um_submit_form_errors_hook__blockedwords', 'um_submit_form_errors_hook__blockedwords', 10 ); - /** - * UM hook - * - * @type filter - * @title um_get_custom_field_array - * @description Extend custom field data on submit form error - * @input_vars - * [{"var":"$array","type":"array","desc":"Field data"}, - * {"var":"$fields","type":"array","desc":"All fields"}] - * @change_log - * ["Since: 2.0"] - * @usage - * - * @example - * - */ - $array = apply_filters( 'um_get_custom_field_array', $array, $fields ); - if ( ! empty( $array['conditions'] ) ) { - foreach ( $array['conditions'] as $condition ) { - list( $visibility, $parent_key, $op, $parent_value ) = $condition; +/** + * Error handling + * + * @param $args + */ +function um_submit_form_errors_hook( $args ) { + $form_id = $args['form_id']; - if ( ! isset( $args[ $parent_key ] ) ) - continue; + $mode = $args['mode']; - $cond_value = ( $fields[ $parent_key ]['type'] == 'radio' ) ? $args[ $parent_key ][0] : $args[ $parent_key ]; + $fields = unserialize( $args['custom_fields'] ); - if ( $visibility == 'hide' ) { - if ( $op == 'empty' ) { - if ( empty( $cond_value ) ) { - continue 2; - } - } elseif ( $op == 'not empty' ) { - if ( ! empty( $cond_value ) ) { - continue 2; - } - } elseif ( $op == 'equals to' ) { - if ( $cond_value == $parent_value ) { - continue 2; - } - } elseif ( $op == 'not equals' ) { - if ( $cond_value != $parent_value ) { - continue 2; - } - } elseif ( $op == 'greater than' ) { - if ( $cond_value > $op ) { - continue 2; - } - } elseif ( $op == 'less than' ) { - if ( $cond_value < $op ) { - continue 2; - } - } elseif ( $op == 'contains' ) { - if ( strstr( $cond_value, $parent_value ) ) { - continue 2; - } - } - } elseif ( $visibility == 'show' ) { - if ( $op == 'empty' ) { - if ( ! empty( $cond_value ) ) { - continue 2; - } - } elseif ( $op == 'not empty' ) { - if ( empty( $cond_value ) ) { - continue 2; - } - } elseif ( $op == 'equals to' ) { - if ( $cond_value != $parent_value ) { - continue 2; - } - } elseif ( $op == 'not equals' ) { - if ( $cond_value == $parent_value ) { - continue 2; - } - } elseif ( $op == 'greater than' ) { - if ( $cond_value <= $op ) { - continue 2; - } - } elseif ( $op == 'less than' ) { - if ( $cond_value >= $op ) { - continue 2; - } - } elseif ( $op == 'contains' ) { - if ( ! strstr( $cond_value, $parent_value ) ) { - continue 2; - } - } + if ( $mode == 'register' ) { + + /** + * UM hook + * + * @type action + * @title um_submit_form_errors_hook__registration + * @description Submit registration form validation + * @input_vars + * [{"var":"$args","type":"array","desc":"Form Arguments"}] + * @change_log + * ["Since: 2.0"] + * @usage add_action( 'um_submit_form_errors_hook__registration', 'function_name', 10, 1 ); + * @example + * + */ + do_action( "um_submit_form_errors_hook__registration", $args ); + + } + /** + * UM hook + * + * @type action + * @title um_submit_form_errors_hook__blockedips + * @description Submit form validation + * @input_vars + * [{"var":"$args","type":"array","desc":"Form Arguments"}] + * @change_log + * ["Since: 2.0"] + * @usage add_action( 'um_submit_form_errors_hook__blockedips', 'function_name', 10, 1 ); + * @example + * + */ + do_action( "um_submit_form_errors_hook__blockedips", $args ); + /** + * UM hook + * + * @type action + * @title um_submit_form_errors_hook__blockedemails + * @description Submit form validation + * @input_vars + * [{"var":"$args","type":"array","desc":"Form Arguments"}] + * @change_log + * ["Since: 2.0"] + * @usage add_action( 'um_submit_form_errors_hook__blockedemails', 'function_name', 10, 1 ); + * @example + * + */ + do_action( "um_submit_form_errors_hook__blockedemails", $args ); + + if ( $mode == 'login' ) { + /** + * UM hook + * + * @type action + * @title um_submit_form_errors_hook_login + * @description Submit login form validation + * @input_vars + * [{"var":"$args","type":"array","desc":"Form Arguments"}] + * @change_log + * ["Since: 2.0"] + * @usage add_action( 'um_submit_form_errors_hook_login', 'function_name', 10, 1 ); + * @example + * + */ + do_action( 'um_submit_form_errors_hook_login', $args ); + /** + * UM hook + * + * @type action + * @title um_submit_form_errors_hook_logincheck + * @description Submit login form validation + * @input_vars + * [{"var":"$args","type":"array","desc":"Form Arguments"}] + * @change_log + * ["Since: 2.0"] + * @usage add_action( 'um_submit_form_errors_hook_logincheck', 'function_name', 10, 1 ); + * @example + * + */ + do_action( 'um_submit_form_errors_hook_logincheck', $args ); + + } else { + /** + * UM hook + * + * @type action + * @title um_submit_form_errors_hook_ + * @description Submit form validation + * @input_vars + * [{"var":"$args","type":"array","desc":"Form Arguments"}] + * @change_log + * ["Since: 2.0"] + * @usage add_action( 'um_submit_form_errors_hook_', 'function_name', 10, 1 ); + * @example + * + */ + do_action( 'um_submit_form_errors_hook_', $args ); + /** + * UM hook + * + * @type action + * @title um_submit_form_errors_hook__blockedwords + * @description Submit form validation + * @input_vars + * [{"var":"$args","type":"array","desc":"Form Arguments"}] + * @change_log + * ["Since: 2.0"] + * @usage add_action( 'um_submit_form_errors_hook__blockedwords', 'function_name', 10, 1 ); + * @example + * + */ + do_action( "um_submit_form_errors_hook__blockedwords", $args ); + + } + +} +add_action( 'um_submit_form_errors_hook', 'um_submit_form_errors_hook', 10 ); + + +/** + * Error processing hook : standard + * + * @param $args + */ +function um_submit_form_errors_hook_( $args ) { + $form_id = $args['form_id']; + $mode = $args['mode']; + $fields = unserialize( $args['custom_fields'] ); + $um_profile_photo = um_profile('profile_photo'); + + if ( get_post_meta( $form_id, '_um_profile_photo_required', true ) && ( empty( $args['profile_photo'] ) && empty( $um_profile_photo ) ) ) { + UM()->form()->add_error('profile_photo', sprintf(__('%s is required.','ultimate-member'), 'Profile Photo' ) ); + } + + if ( ! empty( $fields ) ) { + foreach ( $fields as $key => $array ) { + + if ( isset( $array['public'] ) && -2 == $array['public'] && ! empty( $array['roles'] ) && is_user_logged_in() ) { + $current_user_roles = um_user( 'roles' ); + if ( empty( $current_user_roles ) || count( array_intersect( $current_user_roles, $array['roles'] ) ) <= 0 ) { + continue; + } + } + + /** + * UM hook + * + * @type filter + * @title um_get_custom_field_array + * @description Extend custom field data on submit form error + * @input_vars + * [{"var":"$array","type":"array","desc":"Field data"}, + * {"var":"$fields","type":"array","desc":"All fields"}] + * @change_log + * ["Since: 2.0"] + * @usage + * + * @example + * + */ + $array = apply_filters( 'um_get_custom_field_array', $array, $fields ); + + if ( ! empty( $array['conditions'] ) ) { + foreach ( $array['conditions'] as $condition ) { + list( $visibility, $parent_key, $op, $parent_value ) = $condition; + + if ( ! isset( $args[ $parent_key ] ) ) + continue; + + $cond_value = ( $fields[ $parent_key ]['type'] == 'radio' ) ? $args[ $parent_key ][0] : $args[ $parent_key ]; + + if ( $visibility == 'hide' ) { + if ( $op == 'empty' ) { + if ( empty( $cond_value ) ) { + continue 2; + } + } elseif ( $op == 'not empty' ) { + if ( ! empty( $cond_value ) ) { + continue 2; + } + } elseif ( $op == 'equals to' ) { + if ( $cond_value == $parent_value ) { + continue 2; + } + } elseif ( $op == 'not equals' ) { + if ( $cond_value != $parent_value ) { + continue 2; + } + } elseif ( $op == 'greater than' ) { + if ( $cond_value > $op ) { + continue 2; + } + } elseif ( $op == 'less than' ) { + if ( $cond_value < $op ) { + continue 2; + } + } elseif ( $op == 'contains' ) { + if ( strstr( $cond_value, $parent_value ) ) { + continue 2; + } } - } - } - - if ( isset( $array['type'] ) && $array['type'] == 'checkbox' && isset( $array['required'] ) && $array['required'] == 1 && !isset( $args[$key] ) ) { - UM()->form()->add_error($key, sprintf(__('%s is required.','ultimate-member'), $array['title'] ) ); - } - - if ( isset( $array['type'] ) && $array['type'] == 'radio' && isset( $array['required'] ) && $array['required'] == 1 && !isset( $args[$key] ) && !in_array($key, array('role_radio','role_select') ) ) { - UM()->form()->add_error($key, sprintf(__('%s is required.','ultimate-member'), $array['title'] ) ); - } - - if ( isset( $array['type'] ) && $array['type'] == 'multiselect' && isset( $array['required'] ) && $array['required'] == 1 && !isset( $args[$key] ) && !in_array($key, array('role_radio','role_select') ) ) { - UM()->form()->add_error($key, sprintf(__('%s is required.','ultimate-member'), $array['title'] ) ); - } - - if ( $key == 'role_select' || $key == 'role_radio' ) { - if ( isset( $array['required'] ) && $array['required'] == 1 && ( !isset( $args['role'] ) || empty( $args['role'] ) ) ) { - UM()->form()->add_error('role', __('Please specify account type.','ultimate-member') ); - } - } - - /** - * UM hook - * - * @type action - * @title um_add_error_on_form_submit_validation - * @description Submit form validation - * @input_vars - * [{"var":"$field","type":"array","desc":"Field Data"}, - * {"var":"$key","type":"string","desc":"Field Key"}, - * {"var":"$args","type":"array","desc":"Form Arguments"}] - * @change_log - * ["Since: 2.0"] - * @usage add_action( 'um_add_error_on_form_submit_validation', 'function_name', 10, 3 ); - * @example - * - */ - do_action( 'um_add_error_on_form_submit_validation', $array, $key, $args ); - - if ( isset( $args[$key] ) ) { - - if ( isset( $array['required'] ) && $array['required'] == 1 ) { - if ( ! isset( $args[$key] ) || $args[$key] == '' || $args[$key] == 'empty_file') { - if( empty( $array['label'] ) ) { - UM()->form()->add_error($key, __('This field is required','ultimate-member') ); - } else { - UM()->form()->add_error($key, sprintf( __('%s is required','ultimate-member'), $array['label'] ) ); + } elseif ( $visibility == 'show' ) { + if ( $op == 'empty' ) { + if ( ! empty( $cond_value ) ) { + continue 2; + } + } elseif ( $op == 'not empty' ) { + if ( empty( $cond_value ) ) { + continue 2; + } + } elseif ( $op == 'equals to' ) { + if ( $cond_value != $parent_value ) { + continue 2; + } + } elseif ( $op == 'not equals' ) { + if ( $cond_value == $parent_value ) { + continue 2; + } + } elseif ( $op == 'greater than' ) { + if ( $cond_value <= $op ) { + continue 2; + } + } elseif ( $op == 'less than' ) { + if ( $cond_value >= $op ) { + continue 2; + } + } elseif ( $op == 'contains' ) { + if ( ! strstr( $cond_value, $parent_value ) ) { + continue 2; } } } + } + } - if ( isset( $array['max_words'] ) && $array['max_words'] > 0 ) { - if ( str_word_count( $args[$key] ) > $array['max_words'] ) { + if ( isset( $array['type'] ) && $array['type'] == 'checkbox' && isset( $array['required'] ) && $array['required'] == 1 && !isset( $args[$key] ) ) { + UM()->form()->add_error($key, sprintf(__('%s is required.','ultimate-member'), $array['title'] ) ); + } + + if ( isset( $array['type'] ) && $array['type'] == 'radio' && isset( $array['required'] ) && $array['required'] == 1 && !isset( $args[$key] ) && !in_array($key, array('role_radio','role_select') ) ) { + UM()->form()->add_error($key, sprintf(__('%s is required.','ultimate-member'), $array['title'] ) ); + } + + if ( isset( $array['type'] ) && $array['type'] == 'multiselect' && isset( $array['required'] ) && $array['required'] == 1 && !isset( $args[$key] ) && !in_array($key, array('role_radio','role_select') ) ) { + UM()->form()->add_error($key, sprintf(__('%s is required.','ultimate-member'), $array['title'] ) ); + } + + if ( $key == 'role_select' || $key == 'role_radio' ) { + if ( isset( $array['required'] ) && $array['required'] == 1 && ( !isset( $args['role'] ) || empty( $args['role'] ) ) ) { + UM()->form()->add_error('role', __('Please specify account type.','ultimate-member') ); + } + } + + /** + * UM hook + * + * @type action + * @title um_add_error_on_form_submit_validation + * @description Submit form validation + * @input_vars + * [{"var":"$field","type":"array","desc":"Field Data"}, + * {"var":"$key","type":"string","desc":"Field Key"}, + * {"var":"$args","type":"array","desc":"Form Arguments"}] + * @change_log + * ["Since: 2.0"] + * @usage add_action( 'um_add_error_on_form_submit_validation', 'function_name', 10, 3 ); + * @example + * + */ + do_action( 'um_add_error_on_form_submit_validation', $array, $key, $args ); + + if ( isset( $args[$key] ) ) { + + if ( isset( $array['required'] ) && $array['required'] == 1 ) { + if ( ! isset( $args[$key] ) || $args[$key] == '' || $args[$key] == 'empty_file') { + if( empty( $array['label'] ) ) { + UM()->form()->add_error($key, __('This field is required','ultimate-member') ); + } else { + UM()->form()->add_error($key, sprintf( __('%s is required','ultimate-member'), $array['label'] ) ); + } + } + } + + if ( isset( $array['max_words'] ) && $array['max_words'] > 0 ) { + if ( str_word_count( $args[$key] ) > $array['max_words'] ) { UM()->form()->add_error($key, sprintf(__('You are only allowed to enter a maximum of %s words','ultimate-member'), $array['max_words']) ); - } } + } - if ( isset( $array['min_chars'] ) && $array['min_chars'] > 0 ) { - if ( $args[$key] && strlen( utf8_decode( $args[$key] ) ) < $array['min_chars'] ) { + if ( isset( $array['min_chars'] ) && $array['min_chars'] > 0 ) { + if ( $args[$key] && strlen( utf8_decode( $args[$key] ) ) < $array['min_chars'] ) { UM()->form()->add_error($key, sprintf(__('Your %s must contain at least %s characters','ultimate-member'), $array['label'], $array['min_chars']) ); - } } + } - if ( isset( $array['max_chars'] ) && $array['max_chars'] > 0 ) { - if ( $args[$key] && strlen( utf8_decode( $args[$key] ) ) > $array['max_chars'] ) { + if ( isset( $array['max_chars'] ) && $array['max_chars'] > 0 ) { + if ( $args[$key] && strlen( utf8_decode( $args[$key] ) ) > $array['max_chars'] ) { UM()->form()->add_error($key, sprintf(__('Your %s must contain less than %s characters','ultimate-member'), $array['label'], $array['max_chars']) ); - } } + } - $profile_show_html_bio = UM()->options()->get('profile_show_html_bio'); + $profile_show_html_bio = UM()->options()->get('profile_show_html_bio'); - if( $profile_show_html_bio == 1 && $key !== "description" ){ - if ( isset( $array['html'] ) && $array['html'] == 0 ) { - if ( wp_strip_all_tags( $args[$key] ) != trim( $args[$key] ) ) { - UM()->form()->add_error($key, __('You can not use HTML tags here','ultimate-member') ); - } + if( $profile_show_html_bio == 1 && $key !== "description" ){ + if ( isset( $array['html'] ) && $array['html'] == 0 ) { + if ( wp_strip_all_tags( $args[$key] ) != trim( $args[$key] ) ) { + UM()->form()->add_error($key, __('You can not use HTML tags here','ultimate-member') ); } } + } - if ( isset( $array['force_good_pass'] ) && $array['force_good_pass'] == 1 ) { - if ( ! UM()->validation()->strong_pass( $args[$key] ) ) { + if ( isset( $array['force_good_pass'] ) && $array['force_good_pass'] == 1 ) { + if ( ! UM()->validation()->strong_pass( $args[$key] ) ) { UM()->form()->add_error($key, __('Your password must contain at least one lowercase letter, one capital letter and one number','ultimate-member') ); - } } + } - if ( isset( $array['force_confirm_pass'] ) && $array['force_confirm_pass'] == 1 ) { - if ( $args[ 'confirm_' . $key] == '' && ! UM()->form()->has_error($key) ) { + if ( isset( $array['force_confirm_pass'] ) && $array['force_confirm_pass'] == 1 ) { + if ( $args[ 'confirm_' . $key] == '' && ! UM()->form()->has_error($key) ) { UM()->form()->add_error( 'confirm_' . $key , __('Please confirm your password','ultimate-member') ); - } - if ( $args[ 'confirm_' . $key] != $args[$key] && !UM()->form()->has_error($key) ) { + } + if ( $args[ 'confirm_' . $key] != $args[$key] && !UM()->form()->has_error($key) ) { UM()->form()->add_error( 'confirm_' . $key , __('Your passwords do not match','ultimate-member') ); - } } + } - if ( isset( $array['min_selections'] ) && $array['min_selections'] > 0 ) { - if ( ( !isset($args[$key]) ) || ( isset( $args[$key] ) && is_array($args[$key]) && count( $args[$key] ) < $array['min_selections'] ) ) { + if ( isset( $array['min_selections'] ) && $array['min_selections'] > 0 ) { + if ( ( !isset($args[$key]) ) || ( isset( $args[$key] ) && is_array($args[$key]) && count( $args[$key] ) < $array['min_selections'] ) ) { UM()->form()->add_error($key, sprintf(__('Please select at least %s choices','ultimate-member'), $array['min_selections'] ) ); - } } + } - if ( isset( $array['max_selections'] ) && $array['max_selections'] > 0 ) { - if ( isset( $args[$key] ) && is_array($args[$key]) && count( $args[$key] ) > $array['max_selections'] ) { + if ( isset( $array['max_selections'] ) && $array['max_selections'] > 0 ) { + if ( isset( $args[$key] ) && is_array($args[$key]) && count( $args[$key] ) > $array['max_selections'] ) { UM()->form()->add_error($key, sprintf(__('You can only select up to %s choices','ultimate-member'), $array['max_selections'] ) ); - } } + } - if ( isset( $array['min'] ) && is_numeric( $args[ $key ] ) ) { - if ( isset( $args[ $key ] ) && $args[ $key ] < $array['min'] ) { - UM()->form()->add_error( $key, sprintf(__('Minimum number limit is %s','ultimate-member'), $array['min'] ) ); - } - } + if ( isset( $array['min'] ) && is_numeric( $args[ $key ] ) ) { + if ( isset( $args[ $key ] ) && $args[ $key ] < $array['min'] ) { + UM()->form()->add_error( $key, sprintf(__('Minimum number limit is %s','ultimate-member'), $array['min'] ) ); + } + } - if ( isset( $array['max'] ) && is_numeric( $args[ $key ] ) ) { - if ( isset( $args[ $key ] ) && $args[ $key ] > $array['max'] ) { - UM()->form()->add_error( $key, sprintf(__('Maximum number limit is %s','ultimate-member'), $array['max'] ) ); - } - } + if ( isset( $array['max'] ) && is_numeric( $args[ $key ] ) ) { + if ( isset( $args[ $key ] ) && $args[ $key ] > $array['max'] ) { + UM()->form()->add_error( $key, sprintf(__('Maximum number limit is %s','ultimate-member'), $array['max'] ) ); + } + } - if ( isset( $array['validate'] ) && !empty( $array['validate'] ) ) { + if ( isset( $array['validate'] ) && !empty( $array['validate'] ) ) { - switch( $array['validate'] ) { + switch( $array['validate'] ) { - case 'custom': - $custom = $array['custom_validate']; - /** - * UM hook - * - * @type action - * @title um_custom_field_validation_{$custom} - * @description Submit form validation for custom field - * @input_vars - * [{"var":"$key","type":"string","desc":"Field Key"}, - * {"var":"$field","type":"array","desc":"Field Data"}, - * {"var":"$args","type":"array","desc":"Form Arguments"}] - * @change_log - * ["Since: 2.0"] - * @usage add_action( 'um_custom_field_validation_{$custom}', 'function_name', 10, 3 ); - * @example - * - */ - do_action( "um_custom_field_validation_{$custom}", $key, $array, $args ); - break; + case 'custom': + $custom = $array['custom_validate']; + /** + * UM hook + * + * @type action + * @title um_custom_field_validation_{$custom} + * @description Submit form validation for custom field + * @input_vars + * [{"var":"$key","type":"string","desc":"Field Key"}, + * {"var":"$field","type":"array","desc":"Field Data"}, + * {"var":"$args","type":"array","desc":"Form Arguments"}] + * @change_log + * ["Since: 2.0"] + * @usage add_action( 'um_custom_field_validation_{$custom}', 'function_name', 10, 3 ); + * @example + * + */ + do_action( "um_custom_field_validation_{$custom}", $key, $array, $args ); + break; - case 'numeric': - if ( $args[$key] && !is_numeric( $args[$key] ) ) { - UM()->form()->add_error($key, __('Please enter numbers only in this field','ultimate-member') ); - } - break; + case 'numeric': + if ( $args[$key] && !is_numeric( $args[$key] ) ) { + UM()->form()->add_error($key, __('Please enter numbers only in this field','ultimate-member') ); + } + break; - case 'phone_number': - if ( ! UM()->validation()->is_phone_number( $args[$key] ) ) { - UM()->form()->add_error($key, __('Please enter a valid phone number','ultimate-member') ); - } - break; + case 'phone_number': + if ( ! UM()->validation()->is_phone_number( $args[$key] ) ) { + UM()->form()->add_error($key, __('Please enter a valid phone number','ultimate-member') ); + } + break; - case 'youtube_url': - if ( ! UM()->validation()->is_url( $args[$key], 'youtube.com' ) ) { - UM()->form()->add_error($key, sprintf(__('Please enter a valid %s username or profile URL','ultimate-member'), $array['label'] ) ); - } - break; + case 'youtube_url': + if ( ! UM()->validation()->is_url( $args[$key], 'youtube.com' ) ) { + UM()->form()->add_error($key, sprintf(__('Please enter a valid %s username or profile URL','ultimate-member'), $array['label'] ) ); + } + break; - case 'soundcloud_url': - if ( ! UM()->validation()->is_url( $args[$key], 'soundcloud.com' ) ) { - UM()->form()->add_error($key, sprintf(__('Please enter a valid %s username or profile URL','ultimate-member'), $array['label'] ) ); - } - break; + case 'soundcloud_url': + if ( ! UM()->validation()->is_url( $args[$key], 'soundcloud.com' ) ) { + UM()->form()->add_error($key, sprintf(__('Please enter a valid %s username or profile URL','ultimate-member'), $array['label'] ) ); + } + break; - case 'facebook_url': - if ( ! UM()->validation()->is_url( $args[$key], 'facebook.com' ) ) { - UM()->form()->add_error($key, sprintf(__('Please enter a valid %s username or profile URL','ultimate-member'), $array['label'] ) ); - } - break; + case 'facebook_url': + if ( ! UM()->validation()->is_url( $args[$key], 'facebook.com' ) ) { + UM()->form()->add_error($key, sprintf(__('Please enter a valid %s username or profile URL','ultimate-member'), $array['label'] ) ); + } + break; - case 'twitter_url': - if ( ! UM()->validation()->is_url( $args[$key], 'twitter.com' ) ) { - UM()->form()->add_error($key, sprintf(__('Please enter a valid %s username or profile URL','ultimate-member'), $array['label'] ) ); - } - break; + case 'twitter_url': + if ( ! UM()->validation()->is_url( $args[$key], 'twitter.com' ) ) { + UM()->form()->add_error($key, sprintf(__('Please enter a valid %s username or profile URL','ultimate-member'), $array['label'] ) ); + } + break; - case 'instagram_url': - if ( ! UM()->validation()->is_url( $args[$key], 'instagram.com' ) ) { - UM()->form()->add_error($key, sprintf(__('Please enter a valid %s username or profile URL','ultimate-member'), $array['label'] ) ); - } - break; + case 'instagram_url': + if ( ! UM()->validation()->is_url( $args[$key], 'instagram.com' ) ) { + UM()->form()->add_error($key, sprintf(__('Please enter a valid %s username or profile URL','ultimate-member'), $array['label'] ) ); + } + break; - case 'google_url': - if ( ! UM()->validation()->is_url( $args[$key], 'plus.google.com' ) ) { - UM()->form()->add_error($key, sprintf(__('Please enter a valid %s username or profile URL','ultimate-member'), $array['label'] ) ); - } - break; + case 'google_url': + if ( ! UM()->validation()->is_url( $args[$key], 'plus.google.com' ) ) { + UM()->form()->add_error($key, sprintf(__('Please enter a valid %s username or profile URL','ultimate-member'), $array['label'] ) ); + } + break; - case 'linkedin_url': - if ( ! UM()->validation()->is_url( $args[$key], 'linkedin.com' ) ) { - UM()->form()->add_error($key, sprintf(__('Please enter a valid %s username or profile URL','ultimate-member'), $array['label'] ) ); - } - break; + case 'linkedin_url': + if ( ! UM()->validation()->is_url( $args[$key], 'linkedin.com' ) ) { + UM()->form()->add_error($key, sprintf(__('Please enter a valid %s username or profile URL','ultimate-member'), $array['label'] ) ); + } + break; - case 'vk_url': - if ( ! UM()->validation()->is_url( $args[$key], 'vk.com' ) ) { - UM()->form()->add_error($key, sprintf(__('Please enter a valid %s username or profile URL','ultimate-member'), $array['label'] ) ); - } - break; + case 'vk_url': + if ( ! UM()->validation()->is_url( $args[$key], 'vk.com' ) ) { + UM()->form()->add_error($key, sprintf(__('Please enter a valid %s username or profile URL','ultimate-member'), $array['label'] ) ); + } + break; - case 'url': - if ( ! UM()->validation()->is_url( $args[$key] ) ) { - UM()->form()->add_error($key, __('Please enter a valid URL','ultimate-member') ); - } - break; + case 'url': + if ( ! UM()->validation()->is_url( $args[$key] ) ) { + UM()->form()->add_error($key, __('Please enter a valid URL','ultimate-member') ); + } + break; - case 'skype': - if ( ! UM()->validation()->is_url( $args[$key], 'skype.com' ) ) { - UM()->form()->add_error($key, sprintf(__('Please enter a valid %s username or profile URL','ultimate-member'), $array['label'] ) ); - } - break; + case 'skype': + if ( ! UM()->validation()->is_url( $args[$key], 'skype.com' ) ) { + UM()->form()->add_error($key, sprintf(__('Please enter a valid %s username or profile URL','ultimate-member'), $array['label'] ) ); + } + break; - case 'unique_username': + case 'unique_username': - if ( $args[$key] == '' ) { - UM()->form()->add_error($key, __('You must provide a username','ultimate-member') ); - } else if ( $mode == 'register' && username_exists( sanitize_user( $args[$key] ) ) ) { - UM()->form()->add_error($key, __('Your username is already taken','ultimate-member') ); - } else if ( is_email( $args[$key] ) ) { - UM()->form()->add_error($key, __('Username cannot be an email','ultimate-member') ); - } else if ( ! UM()->validation()->safe_username( $args[$key] ) ) { - UM()->form()->add_error($key, __('Your username contains invalid characters','ultimate-member') ); + if ( $args[$key] == '' ) { + UM()->form()->add_error($key, __('You must provide a username','ultimate-member') ); + } else if ( $mode == 'register' && username_exists( sanitize_user( $args[$key] ) ) ) { + UM()->form()->add_error($key, __('Your username is already taken','ultimate-member') ); + } else if ( is_email( $args[$key] ) ) { + UM()->form()->add_error($key, __('Username cannot be an email','ultimate-member') ); + } else if ( ! UM()->validation()->safe_username( $args[$key] ) ) { + UM()->form()->add_error($key, __('Your username contains invalid characters','ultimate-member') ); + } + + break; + + case 'unique_username_or_email': + + if ( $args[$key] == '' ) { + UM()->form()->add_error($key, __('You must provide a username','ultimate-member') ); + } else if ( $mode == 'register' && username_exists( sanitize_user( $args[$key] ) ) ) { + UM()->form()->add_error($key, __('Your username is already taken','ultimate-member') ); + } else if ( $mode == 'register' && email_exists( $args[$key] ) ) { + UM()->form()->add_error($key, __('This email is already linked to an existing account','ultimate-member') ); + } else if ( ! UM()->validation()->safe_username( $args[$key] ) ) { + UM()->form()->add_error($key, __('Your username contains invalid characters','ultimate-member') ); + } + + break; + + case 'unique_email': + + $args[ $key ] = trim( $args[ $key ] ); + + if ( in_array( $key, array('user_email') ) ) { + + if( ! isset( $args['user_id'] ) ){ + $args['user_id'] = um_get_requested_user(); } - break; + $email_exists = email_exists( $args[ $key ] ); - case 'unique_username_or_email': - - if ( $args[$key] == '' ) { - UM()->form()->add_error($key, __('You must provide a username','ultimate-member') ); - } else if ( $mode == 'register' && username_exists( sanitize_user( $args[$key] ) ) ) { - UM()->form()->add_error($key, __('Your username is already taken','ultimate-member') ); - } else if ( $mode == 'register' && email_exists( $args[$key] ) ) { - UM()->form()->add_error($key, __('This email is already linked to an existing account','ultimate-member') ); - } else if ( ! UM()->validation()->safe_username( $args[$key] ) ) { - UM()->form()->add_error($key, __('Your username contains invalid characters','ultimate-member') ); + if ( $args[ $key ] == '' && in_array( $key, array('user_email') ) ) { + UM()->form()->add_error( $key, __('You must provide your email','ultimate-member') ); + } else if ( in_array( $mode, array('register') ) && $email_exists ) { + UM()->form()->add_error($key, __('This email is already linked to an existing account','ultimate-member') ); + } else if ( in_array( $mode, array('profile') ) && $email_exists && $email_exists != $args['user_id'] ) { + UM()->form()->add_error( $key, __('This email is already linked to an existing account','ultimate-member') ); + } else if ( !is_email( $args[ $key ] ) ) { + UM()->form()->add_error( $key, __('This is not a valid email','ultimate-member') ); + } else if ( ! UM()->validation()->safe_username( $args[ $key ] ) ) { + UM()->form()->add_error( $key, __('Your email contains invalid characters','ultimate-member') ); } - break; + } else { - case 'unique_email': - - $args[ $key ] = trim( $args[ $key ] ); - - if ( in_array( $key, array('user_email') ) ) { - - if( ! isset( $args['user_id'] ) ){ - $args['user_id'] = um_get_requested_user(); - } - - $email_exists = email_exists( $args[ $key ] ); - - if ( $args[ $key ] == '' && in_array( $key, array('user_email') ) ) { - UM()->form()->add_error( $key, __('You must provide your email','ultimate-member') ); - } else if ( in_array( $mode, array('register') ) && $email_exists ) { - UM()->form()->add_error($key, __('This email is already linked to an existing account','ultimate-member') ); - } else if ( in_array( $mode, array('profile') ) && $email_exists && $email_exists != $args['user_id'] ) { - UM()->form()->add_error( $key, __('This email is already linked to an existing account','ultimate-member') ); - } else if ( !is_email( $args[ $key ] ) ) { - UM()->form()->add_error( $key, __('This is not a valid email','ultimate-member') ); - } else if ( ! UM()->validation()->safe_username( $args[ $key ] ) ) { - UM()->form()->add_error( $key, __('Your email contains invalid characters','ultimate-member') ); - } - - } else { - - if ( $args[ $key ] != '' && !is_email( $args[ $key ] ) ) { - UM()->form()->add_error( $key, __('This is not a valid email','ultimate-member') ); - } else if ( $args[ $key ] != '' && email_exists( $args[ $key ] ) ) { - UM()->form()->add_error($key, __('This email is already linked to an existing account','ultimate-member') ); - } else if ( $args[ $key ] != '' ) { + if ( $args[ $key ] != '' && !is_email( $args[ $key ] ) ) { + UM()->form()->add_error( $key, __('This is not a valid email','ultimate-member') ); + } else if ( $args[ $key ] != '' && email_exists( $args[ $key ] ) ) { + UM()->form()->add_error($key, __('This email is already linked to an existing account','ultimate-member') ); + } else if ( $args[ $key ] != '' ) { - $users = get_users('meta_value='.$args[ $key ]); + $users = get_users('meta_value='.$args[ $key ]); - foreach ( $users as $user ) { - if( $user->ID != $args['user_id'] ){ - UM()->form()->add_error( $key, __('This email is already linked to an existing account','ultimate-member') ); - } + foreach ( $users as $user ) { + if( $user->ID != $args['user_id'] ){ + UM()->form()->add_error( $key, __('This email is already linked to an existing account','ultimate-member') ); } + } - } - } - break; + } - case 'unique_value': + break; - if ( $args[$key] != '' ) { + case 'unique_value': - $args_unique_meta = array( - 'meta_key' => $key, - 'meta_value' => $args[ $key ], - 'compare' => '=', - 'exclude' => array( $args['user_id'] ), - ); + if ( $args[$key] != '' ) { - $meta_key_exists = get_users( $args_unique_meta ); + $args_unique_meta = array( + 'meta_key' => $key, + 'meta_value' => $args[ $key ], + 'compare' => '=', + 'exclude' => array( $args['user_id'] ), + ); - if ( $meta_key_exists ) { - UM()->form()->add_error( $key , __('You must provide a unique value','ultimate-member') ); - } + $meta_key_exists = get_users( $args_unique_meta ); + + if ( $meta_key_exists ) { + UM()->form()->add_error( $key , __('You must provide a unique value','ultimate-member') ); } + } break; - case 'alphabetic': + case 'alphabetic': - if ( $args[$key] != '' ) { + if ( $args[$key] != '' ) { - if( ! ctype_alpha( str_replace(' ', '', $args[$key] ) ) ){ - UM()->form()->add_error( $key , __('You must provide alphabetic letters','ultimate-member') ); - } + if( ! ctype_alpha( str_replace(' ', '', $args[$key] ) ) ){ + UM()->form()->add_error( $key , __('You must provide alphabetic letters','ultimate-member') ); } + } break; - case 'lowercase': + case 'lowercase': - if ( $args[$key] != '' ) { + if ( $args[$key] != '' ) { - if( ! ctype_lower( str_replace(' ', '',$args[$key] ) ) ){ - UM()->form()->add_error( $key , __('You must provide lowercase letters.','ultimate-member') ); - } + if( ! ctype_lower( str_replace(' ', '',$args[$key] ) ) ){ + UM()->form()->add_error( $key , __('You must provide lowercase letters.','ultimate-member') ); } + } break; - } - } } - if ( isset( $args['description'] ) ) { + } + + if ( isset( $args['description'] ) ) { - $max_chars = UM()->options()->get('profile_bio_maxchars'); - $profile_show_bio = UM()->options()->get('profile_show_bio'); + $max_chars = UM()->options()->get('profile_bio_maxchars'); + $profile_show_bio = UM()->options()->get('profile_show_bio'); - if( $profile_show_bio ){ - if ( strlen( utf8_decode( $args['description'] ) ) > $max_chars && $max_chars ) { - UM()->form()->add_error('description', sprintf(__('Your user description must contain less than %s characters','ultimate-member'), $max_chars ) ); - } + if( $profile_show_bio ){ + if ( strlen( utf8_decode( $args['description'] ) ) > $max_chars && $max_chars ) { + UM()->form()->add_error('description', sprintf(__('Your user description must contain less than %s characters','ultimate-member'), $max_chars ) ); } - } - } // end if ( isset in args array ) - } - } \ No newline at end of file + } + + } // end if ( isset in args array ) + } +} +add_action( 'um_submit_form_errors_hook_', 'um_submit_form_errors_hook_', 10 ); \ No newline at end of file diff --git a/includes/core/um-actions-global.php b/includes/core/um-actions-global.php index 542a186b..5bfc9b05 100644 --- a/includes/core/um-actions-global.php +++ b/includes/core/um-actions-global.php @@ -1,57 +1,64 @@ - - +/** + * Adds a form identifier to form + * + * @param $args + */ +function um_add_form_identifier( $args ) { + ?> + - echo ''; + - ?> - -

- - -

- - - - - - - - +

+ + +

+ + + + 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 + * */ - 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 - * - */ - 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 - * - * @example - * - */ - $redirect_url = apply_filters( 'um_login_redirect_url', um_user( 'login_redirect_url' ), um_user( 'ID' ) ); - exit( wp_redirect( $redirect_url ) ); - break; - - case 'refresh': - 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 + * * @example * */ - 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 * */ - 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 + * + */ + 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 - * - * @example - * - */ - $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 - * - * @example - * - */ - $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 - * - * @example - * - */ - $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 + * + * @example + * + */ + $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 + * + * @example + * + */ + $secondary_btn_word = apply_filters('um_login_form_button_two', $secondary_btn_word, $args ); -
+ $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 + * + * @example + * + */ + $secondary_btn_url = apply_filters('um_login_form_button_two_url', $secondary_btn_url, $args ); ?> - fields()->checkbox('rememberme', __('Keep me signed in','ultimate-member') ); - echo '
'; - } ?> +
- + fields()->checkbox('rememberme', __('Keep me signed in','ultimate-member') ); + echo '
'; + } ?> + +
- +
- + -
+
+
+ + + +
+
+/** + * 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); -
- -
- - 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 ); \ No newline at end of file diff --git a/includes/core/um-actions-members.php b/includes/core/um-actions-members.php index d58a3765..7c451fa4 100644 --- a/includes/core/um-actions-members.php +++ b/includes/core/um-actions-members.php @@ -1,150 +1,155 @@ - $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 - * - * @example - * - */ - $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 ); ?> - - '; - - } - - ?> - -
- -
- - - - - -
- - - -
- - + * @example + * */ - 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') ) { ?> - -
- -
1 ) ? um_members('header') : um_members('header_single'); ?>
- -
- - + + '; + + } + + ?> + +
+ +
+ + + + + +
+ + + + + + 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') ) { ?> + +
+ +
1 ) ? um_members('header') : um_members('header_single'); ?>
+ +
+ + 1 ) { // needs pagination ?> @@ -153,11 +158,11 @@ if ( ! defined( 'ABSPATH' ) ) exit; - + @@ -165,60 +170,63 @@ if ( ! defined( 'ABSPATH' ) ) exit;
- + - + 1 ) { ?> - + - + - + - - - + + + - + + + - - - + - + - + - +
'; + if ( ! empty( $_REQUEST['redirect_to'] ) ) { + $url = $_REQUEST['redirect_to']; + echo ''; - } 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 - * - * @example - * - */ - $url = apply_filters( 'um_browser_url_redirect_to__filter', $url ); - if ( ! empty( $url ) ) { - echo ''; - } - } - - /*** - *** @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 - * - * @example - * - */ - $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 + * + * @example + * + */ + $url = apply_filters( 'um_browser_url_redirect_to__filter', $url ); + if ( ! empty( $url ) ) { + echo ''; + } + +} +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 + * + * @example + * + */ + $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 - * - * @example - * - */ - $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 + * + * @example + * + */ + $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 .= '

' . $err . '

'; - } - - if ( isset( $success ) && !empty( $success ) ) { - $output .= '

' . $success . '

'; - } - - echo $output; - - } \ No newline at end of file + } + + if ( isset( $err ) && !empty( $err ) ) { + $output .= '

' . $err . '

'; + } + + if ( isset( $success ) && !empty( $success ) ) { + $output .= '

' . $success . '

'; + } + + echo $output; +} +add_action( 'um_before_form', 'um_add_update_notice', 500 ); \ No newline at end of file diff --git a/includes/core/um-actions-password.php b/includes/core/um-actions-password.php index a6c76914..876ca53c 100644 --- a/includes/core/um-actions-password.php +++ b/includes/core/um-actions-password.php @@ -1,340 +1,361 @@ - $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 - * - */ - 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 + * */ - 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 ) { - - ?> - - - - - - 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 ) { - - ?> - - - - 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'); ?> - $data ) { - $output .= UM()->fields()->edit_field( $key, $data ); - } echo $output; ?> +/** + * Hidden fields + * + * @param $args + */ +function um_change_password_page_hidden_fields( $args ) { + ?> - - */ - do_action( 'um_after_password_reset_fields', $args ); ?> + -
+ -
+
- +/** + * Hidden fields + * + * @param $args + */ +function um_reset_password_page_hidden_fields( $args ) { + ?> - - } + builtin()->get_specific_fields('user_password'); ?> +/** + * Form content + * + * @param $args + */ +function um_reset_password_form( $args ) { - $data ) { - $output .= UM()->fields()->edit_field( $key, $data ); - }echo $output; ?> + $fields = UM()->builtin()->get_specific_fields('password_reset_text,username_b'); ?> -
+ $data ) { + $output .= UM()->fields()->edit_field( $key, $data ); + } echo $output; ?> -
+ + */ + do_action( 'um_after_password_reset_fields', $args ); ?> -
+
-
+
-
- } + + + builtin()->get_specific_fields('user_password'); ?> + + $data ) { + $output .= UM()->fields()->edit_field( $key, $data ); + }echo $output; ?> + +
+ +
+ +
+ +
+ + fields()->editing == 1 && UM()->fields()->set_mode == 'profile' && UM()->user()->target_id) { ?> +/** + * If editing another user + * + * @param $args + */ +function um_editing_user_id_input( $args ) { + if ( UM()->fields()->editing == 1 && UM()->fields()->set_mode == 'profile' && UM()->user()->target_id ) { ?> - + - options()->get( 'profile_desc' ) ); + $user_id = um_user( 'ID' ); + $url = um_user_profile_url(); + + if (um_profile( 'profile_photo' )) { + $avatar = um_user_uploads_uri() . um_profile( 'profile_photo' ); + } else { + $avatar = um_get_default_avatar_uri(); } + + um_reset_user(); ?> + + + + + + + + + + options()->get( 'profile_desc' ) ); - $user_id = um_user( 'ID' ); - $url = um_user_profile_url(); + $default_cover = UM()->options()->get( 'default_cover' ); - if (um_profile( 'profile_photo' )) { - $avatar = um_user_uploads_uri() . um_profile( 'profile_photo' ); - } else { - $avatar = um_get_default_avatar_uri(); - } - - um_reset_user(); ?> - - - - - - - - - - options()->get( 'default_cover' ); - - $overlay = ' + $overlay = ' @@ -558,123 +559,129 @@ add_action( 'um_after_user_updated', 'um_restore_default_roles', 10, 3 ); '; - ?> + ?> -
- - - */ - do_action( 'um_cover_area_content', um_profile_id() ); - if ( UM()->fields()->editing ) { - - $items = array( - '' . __( 'Change cover photo', 'ultimate-member' ) . '', - '' . __( 'Remove', 'ultimate-member' ) . '', - '' . __( 'Cancel', 'ultimate-member' ) . '', - ); - - echo UM()->profile()->new_ui( 'bc', 'div.um-cover', 'click', $items ); - - } - - UM()->fields()->add_hidden_field( 'cover_photo' ); - - echo $overlay; ?> - -
- - - - mobile()->isMobile()) { - if (UM()->mobile()->isTablet()) { - echo um_user( 'cover_photo', 1000 ); - } else { - echo um_user( 'cover_photo', 300 ); - } - } else { - echo um_user( 'cover_photo', 1000 ); - } - - ?> - - '; - - } else { - - if (!isset( UM()->user()->cannot_edit )) { ?> - - - - - -
- -
+
+ */ + do_action( 'um_cover_area_content', um_profile_id() ); + if ( UM()->fields()->editing ) { - } + $items = array( + '' . __( 'Change cover photo', 'ultimate-member' ) . '', + '' . __( 'Remove', 'ultimate-member' ) . '', + '' . __( 'Cancel', 'ultimate-member' ) . '', + ); + + echo UM()->profile()->new_ui( 'bc', 'div.um-cover', 'click', $items ); + + } + + UM()->fields()->add_hidden_field( 'cover_photo' ); + + echo $overlay; ?> + +
+ + + + mobile()->isMobile()) { + if (UM()->mobile()->isTablet()) { + echo um_user( 'cover_photo', 1000 ); + } else { + echo um_user( 'cover_photo', 300 ); + } + } else { + echo um_user( 'cover_photo', 1000 ); + } + + ?> + + '; + + } else { + + if (!isset( UM()->user()->cannot_edit )) { ?> + + + + + +
+ +
+ + '; - UM()->fields()->show_social_urls(); - echo ''; - } +/** + * Show social links as icons below profile name + * + * @param $args + */ +function um_social_links_icons( $args ) { + if ( ! empty( $args['show_social_links'] ) ) { + + echo '
'; + UM()->fields()->show_social_urls(); + echo '
'; + + } +} +add_action( 'um_after_profile_header_name_args', 'um_social_links_icons', 50 ); + + +/** + * Profile header + * + * @param $args + */ +function um_profile_header( $args ) { + $classes = null; + + if (!$args['cover_enabled']) { + $classes .= ' no-cover'; } - /*** - *** @profile header - ***/ - add_action( 'um_profile_header', 'um_profile_header', 9 ); - function um_profile_header( $args ) { - $classes = null; + $default_size = str_replace( 'px', '', $args['photosize'] ); - if (!$args['cover_enabled']) { - $classes .= ' no-cover'; - } - - $default_size = str_replace( 'px', '', $args['photosize'] ); - - $overlay = ' + $overlay = ' @@ -682,538 +689,560 @@ add_action( 'um_after_user_updated', 'um_restore_default_roles', 10, 3 ); '; - ?> + ?> -
+
+ + + */ + do_action( 'um_pre_header_editprofile', $args ); ?> + +
+ + - */ - do_action( 'um_pre_header_editprofile', $args ); ?> -
+ if (!isset( UM()->user()->cannot_edit )) { - + UM()->fields()->add_hidden_field( 'profile_photo' ); - user()->cannot_edit )) { + $items = array( + '' . __( 'Upload photo', 'ultimate-member' ) . '', + '' . __( 'Cancel', 'ultimate-member' ) . '', + ); - UM()->fields()->add_hidden_field( 'profile_photo' ); - - if (!um_profile( 'profile_photo' )) { // has profile photo - - $items = array( - '' . __( 'Upload photo', 'ultimate-member' ) . '', - '' . __( 'Cancel', 'ultimate-member' ) . '', - ); - - /** - * UM hook - * - * @type filter - * @title um_user_photo_menu_view - * @description Change user photo on menu view - * @input_vars - * [{"var":"$items","type":"array","desc":"User Photos"}] - * @change_log - * ["Since: 2.0"] - * @usage - * - * @example - * - */ - $items = apply_filters( 'um_user_photo_menu_view', $items ); - - echo UM()->profile()->new_ui( 'bc', 'div.um-profile-photo', 'click', $items ); - - } else if (UM()->fields()->editing == true) { - - $items = array( - '' . __( 'Change photo', 'ultimate-member' ) . '', - '' . __( 'Remove photo', 'ultimate-member' ) . '', - '' . __( 'Cancel', 'ultimate-member' ) . '', - ); - - /** - * UM hook - * - * @type filter - * @title um_user_photo_menu_edit - * @description Change user photo on menu edit - * @input_vars - * [{"var":"$items","type":"array","desc":"User Photos"}] - * @change_log - * ["Since: 2.0"] - * @usage - * - * @example - * - */ - $items = apply_filters( 'um_user_photo_menu_edit', $items ); - - echo UM()->profile()->new_ui( 'bc', 'div.um-profile-photo', 'click', $items ); - - } - - } - - ?> - -
- -
- -
- - -
- - - - - */ - do_action( 'um_after_profile_name_inline', $args ); ?> - -
- - -
- - * @example * */ - do_action( 'um_after_profile_header_name_args', $args ); + $items = apply_filters( 'um_user_photo_menu_view', $items ); + + echo UM()->profile()->new_ui( 'bc', 'div.um-profile-photo', 'click', $items ); + + } else if (UM()->fields()->editing == true) { + + $items = array( + '' . __( 'Change photo', 'ultimate-member' ) . '', + '' . __( 'Remove photo', 'ultimate-member' ) . '', + '' . __( 'Cancel', 'ultimate-member' ) . '', + ); + /** * UM hook * - * @type action - * @title um_after_profile_name_inline - * @description Insert after profile name some content + * @type filter + * @title um_user_photo_menu_edit + * @description Change user photo on menu edit + * @input_vars + * [{"var":"$items","type":"array","desc":"User Photos"}] * @change_log * ["Since: 2.0"] - * @usage add_action( 'um_after_profile_name_inline', 'function_name', 10 ); + * @usage + * * @example * */ - do_action( 'um_after_profile_header_name' ); ?> + $items = apply_filters( 'um_user_photo_menu_edit', $items ); -
+ echo UM()->profile()->new_ui( 'bc', 'div.um-profile-photo', 'click', $items ); - -
+ } - profile()->show_meta( $args['metafields'] ); ?> + } -
+ ?> + +
+ +
+ +
+ + +
+ + + + + */ + do_action( 'um_after_profile_name_inline', $args ); ?> + +
- fields()->viewing == true && um_user( 'description' ) && $args['show_bio']) { ?> - -
- options()->get( 'profile_show_html_bio' ) ) : ?> - - - - -
- - fields()->editing == true && $args['show_bio']) { ?> - -
- - options()->get( 'profile_bio_maxchars' ); ?> - fields()->is_error( 'description' )) { - echo UM()->fields()->field_error( UM()->fields()->show_error( 'description' ), true ); - } - ?> - -
- - - -
- -
+
*/ - do_action( 'um_after_header_meta', um_user( 'ID' ), $args ); ?> + do_action( 'um_after_profile_header_name_args', $args ); + /** + * UM hook + * + * @type action + * @title um_after_profile_name_inline + * @description Insert after profile name some content + * @change_log + * ["Since: 2.0"] + * @usage add_action( 'um_after_profile_name_inline', 'function_name', 10 ); + * @example + * + */ + do_action( 'um_after_profile_header_name' ); ?> -
-
+
- fields()->is_error( 'profile_photo' ) ) { - echo UM()->fields()->field_error( UM()->fields()->show_error( 'profile_photo' ), 'force_show' ); - } + +
+ profile()->show_meta( $args['metafields'] ); ?> + +
+ + + fields()->viewing == true && um_user( 'description' ) && $args['show_bio']) { ?> + +
+ options()->get( 'profile_show_html_bio' ) ) : ?> + + + + +
+ + fields()->editing == true && $args['show_bio']) { ?> + +
+ + options()->get( 'profile_bio_maxchars' ); ?> + fields()->is_error( 'description' )) { + echo UM()->fields()->field_error( UM()->fields()->show_error( 'description' ), true ); + } + ?> + +
+ + + +
+ +
+ + */ - do_action( 'um_after_header_info', um_user( 'ID' ), $args ); ?> + do_action( 'um_after_header_meta', um_user( 'ID' ), $args ); ?> -
+
+
- fields()->editing == false) { - UM()->fields()->viewing = 1; - - if ( um_get_requested_user() ) { - if ( ! um_can_view_profile( um_get_requested_user() ) && ! um_is_myprofile() ) - um_redirect_home(); - - if ( ! UM()->roles()->um_current_user_can( 'edit', um_get_requested_user() ) ) - UM()->user()->cannot_edit = 1; - - um_fetch_user( um_get_requested_user() ); - } else { - if ( ! is_user_logged_in() ) - um_redirect_home(); - - if ( ! um_user( 'can_edit_profile' ) ) - UM()->user()->cannot_edit = 1; - } + fields()->is_error( 'profile_photo' ) ) { + echo UM()->fields()->field_error( UM()->fields()->show_error( 'profile_photo' ), 'force_show' ); } - if ($mode == 'profile' && UM()->fields()->editing == true) { - UM()->fields()->editing = 1; - - if (um_get_requested_user()) { - if (!UM()->roles()->um_current_user_can( 'edit', um_get_requested_user() )) um_redirect_home(); - um_fetch_user( um_get_requested_user() ); - } - - } - - } - - /*** - *** @display the edit profile icon - ***/ - add_action( 'um_pre_header_editprofile', 'um_add_edit_icon' ); - function um_add_edit_icon( $args ) { - $output = ''; - - if (!is_user_logged_in()) return; // not allowed for guests - - if (isset( UM()->user()->cannot_edit ) && UM()->user()->cannot_edit == 1) return; // do not proceed if user cannot edit - - if (UM()->fields()->editing == true) { - - ?> - -
- - - -
- - - -
- - - - '' . __( 'Edit Profile', 'ultimate-member' ) . '', - 'myaccount' => '' . __( 'My Account', 'ultimate-member' ) . '', - 'logout' => '' . __( 'Logout', 'ultimate-member' ) . '', - 'cancel' => '' . __( 'Cancel', 'ultimate-member' ) . '', - ); - - $cancel = $items['cancel']; - - if (!um_is_myprofile()) { - - $actions = UM()->user()->get_admin_actions(); - - unset( $items['myaccount'] ); - unset( $items['logout'] ); - unset( $items['cancel'] ); - - if (is_array( $actions )) { - $items = array_merge( $items, $actions ); - } - - /** - * UM hook - * - * @type filter - * @title um_profile_edit_menu_items - * @description Edit menu items on profile page - * @input_vars - * [{"var":"$items","type":"array","desc":"User Menu"}, - * {"var":"$user_id","type":"int","desc":"Profile ID"}] - * @change_log - * ["Since: 2.0"] - * @usage - * - * @example - * - */ - $items = apply_filters( 'um_profile_edit_menu_items', $items, um_profile_id() ); - - $items['cancel'] = $cancel; - - } else { - - /** - * UM hook - * - * @type filter - * @title um_myprofile_edit_menu_items - * @description Edit menu items on my profile page - * @input_vars - * [{"var":"$items","type":"array","desc":"User Menu"}] - * @change_log - * ["Since: 2.0"] - * @usage - * - * @example - * - */ - $items = apply_filters( 'um_myprofile_edit_menu_items', $items ); - - } - - UM()->profile()->new_ui( $args['header_menu'], 'div.um-profile-edit', 'click', $items ); - - ?> - -
- - fields()->editing == true) { - - echo UM()->fields()->display( 'profile', $args ); - - } else { - - UM()->fields()->viewing = true; - - echo UM()->fields()->display_view( 'profile', $args ); - - } - - } - - /*** - *** @form processing - ***/ - add_action( 'um_submit_form_profile', 'um_submit_form_profile', 10 ); - function um_submit_form_profile( $args ) { - if ( isset( UM()->form()->errors ) ) - return false; - /** * UM hook * * @type action - * @title um_user_edit_profile - * @description Run on successful submit profile form + * @title um_after_header_info + * @description Insert after header info some content * @input_vars - * [{"var":"$args","type":"array","desc":"Form Arguments"}] + * [{"var":"$user_id","type":"int","desc":"User ID"}, + * {"var":"$args","type":"array","desc":"Form Arguments"}] * @change_log * ["Since: 2.0"] - * @usage add_action( 'um_user_edit_profile', 'function_name', 10, 1 ); + * @usage add_action( 'um_after_header_info', 'function_name', 10, 2 ); * @example * */ - do_action( 'um_user_edit_profile', $args ); + do_action( 'um_after_header_info', um_user( 'ID' ), $args ); ?> + +
+ + fields()->editing == false ) { + UM()->fields()->viewing = 1; + + if ( um_get_requested_user() ) { + if ( ! um_can_view_profile( um_get_requested_user() ) && ! um_is_myprofile() ) + um_redirect_home(); + + if ( ! UM()->roles()->um_current_user_can( 'edit', um_get_requested_user() ) ) + UM()->user()->cannot_edit = 1; + + um_fetch_user( um_get_requested_user() ); + } else { + if ( ! is_user_logged_in() ) + um_redirect_home(); + + if ( ! um_user( 'can_edit_profile' ) ) + UM()->user()->cannot_edit = 1; + } } - /*** - *** @Show the submit button (highest priority) - ***/ - add_action( 'um_after_profile_fields', 'um_add_submit_button_to_profile', 1000 ); - function um_add_submit_button_to_profile( $args ) { - // DO NOT add when reviewing user's details - if (UM()->user()->preview == true && is_admin()) return; + if ( $mode == 'profile' && UM()->fields()->editing == true ) { + UM()->fields()->editing = 1; - // only when editing - if (UM()->fields()->editing == false) return; + if ( um_get_requested_user() ) { + if ( ! UM()->roles()->um_current_user_can( 'edit', um_get_requested_user() ) ) { + um_redirect_home(); + } + um_fetch_user( um_get_requested_user() ); + } + + } + +} +add_action( 'um_pre_profile_shortcode', 'um_pre_profile_shortcode' ); + + +/** + * Display the edit profile icon + * + * @param $args + */ +function um_add_edit_icon( $args ) { + $output = ''; + + if (!is_user_logged_in()) return; // not allowed for guests + + if (isset( UM()->user()->cannot_edit ) && UM()->user()->cannot_edit == 1) return; // do not proceed if user cannot edit + + if (UM()->fields()->editing == true) { ?> -
+
- + -
-
-
+
- + -
+
- + -
+ + $items = array( + 'editprofile' => '' . __( 'Edit Profile', 'ultimate-member' ) . '', + 'myaccount' => '' . __( 'My Account', 'ultimate-member' ) . '', + 'logout' => '' . __( 'Logout', 'ultimate-member' ) . '', + 'cancel' => '' . __( 'Cancel', 'ultimate-member' ) . '', + ); + + $cancel = $items['cancel']; + + if (!um_is_myprofile()) { + + $actions = UM()->user()->get_admin_actions(); + + unset( $items['myaccount'] ); + unset( $items['logout'] ); + unset( $items['cancel'] ); + + if (is_array( $actions )) { + $items = array_merge( $items, $actions ); + } + + /** + * UM hook + * + * @type filter + * @title um_profile_edit_menu_items + * @description Edit menu items on profile page + * @input_vars + * [{"var":"$items","type":"array","desc":"User Menu"}, + * {"var":"$user_id","type":"int","desc":"Profile ID"}] + * @change_log + * ["Since: 2.0"] + * @usage + * + * @example + * + */ + $items = apply_filters( 'um_profile_edit_menu_items', $items, um_profile_id() ); + + $items['cancel'] = $cancel; + + } else { + + /** + * UM hook + * + * @type filter + * @title um_myprofile_edit_menu_items + * @description Edit menu items on my profile page + * @input_vars + * [{"var":"$items","type":"array","desc":"User Menu"}] + * @change_log + * ["Since: 2.0"] + * @usage + * + * @example + * + */ + $items = apply_filters( 'um_myprofile_edit_menu_items', $items ); + + } + + UM()->profile()->new_ui( $args['header_menu'], 'div.um-profile-edit', 'click', $items ); + + ?> + +
fields()->editing == true ) { + + echo UM()->fields()->display( 'profile', $args ); + + } else { + + UM()->fields()->viewing = true; + + echo UM()->fields()->display_view( 'profile', $args ); + + } + +} +add_action( 'um_main_profile_fields', 'um_add_profile_fields', 100 ); + + +/** + * Form processing + * + * @param $args + */ +function um_submit_form_profile( $args ) { + if ( isset( UM()->form()->errors ) ) { + return; + } + + /** + * UM hook + * + * @type action + * @title um_user_edit_profile + * @description Run on successful submit profile form + * @input_vars + * [{"var":"$args","type":"array","desc":"Form Arguments"}] + * @change_log + * ["Since: 2.0"] + * @usage add_action( 'um_user_edit_profile', 'function_name', 10, 1 ); + * @example + * + */ + do_action( 'um_user_edit_profile', $args ); +} +add_action( 'um_submit_form_profile', 'um_submit_form_profile', 10 ); + + +/** + * Show the submit button (highest priority) + * + * @param $args + */ +function um_add_submit_button_to_profile( $args ) { + // DO NOT add when reviewing user's details + if (UM()->user()->preview == true && is_admin()) return; + + // only when editing + if (UM()->fields()->editing == false) return; + + ?> + +
+ + + +
+
+
+ + + +
+ + + +
+ +
+ + -
+
$tab ) { @@ -1402,8 +1431,8 @@ function um_before_user_upload( $user_id, $arr_files ) { $old_filename = um_user( $key ); if ( basename( $filename ) != basename( um_user( $key ) ) || - in_array( $old_filename, array( basename( um_user( $key ) ), basename( $filename ) ) ) || - $filename == 'empty_file' ) { + in_array( $old_filename, array( basename( um_user( $key ) ), basename( $filename ) ) ) || + $filename == 'empty_file' ) { $path = UM()->files()->upload_basedir; delete_user_meta( $user_id, $old_filename ); diff --git a/includes/core/um-actions-register.php b/includes/core/um-actions-register.php index f6fdcbf2..14be2d80 100644 --- a/includes/core/um-actions-register.php +++ b/includes/core/um-actions-register.php @@ -1,710 +1,723 @@ -user()->approve(); +} +add_action( 'um_post_registration_approved_hook', 'um_post_registration_approved_hook', 10, 2 ); + + +/** + * Account needs email validation + * + * @param $user_id + * @param $args + */ +function um_post_registration_checkmail_hook( $user_id, $args ) { + um_fetch_user( $user_id ); + + UM()->user()->email_pending(); +} +add_action( 'um_post_registration_checkmail_hook', 'um_post_registration_checkmail_hook', 10, 2 ); + + +/** + * Account needs admin review + * + * @param $user_id + * @param $args + */ +function um_post_registration_pending_hook( $user_id, $args ) { + um_fetch_user( $user_id ); + + UM()->user()->pending(); +} +add_action('um_post_registration_pending_hook', 'um_post_registration_pending_hook', 10, 2); + + +/** + * After insert a new user + * run at frontend and backend + * + * @param $user_id + * @param $args + */ +function um_after_insert_user( $user_id, $args ) { + //clear Users cached queue + UM()->user()->remove_cached_queue(); + + if ( ! empty( $args['submitted'] ) ) { um_fetch_user( $user_id ); - - UM()->user()->approve(); + UM()->user()->set_registration_details( $args['submitted'] ); } /** - * Account needs email validation - */ - add_action('um_post_registration_checkmail_hook', 'um_post_registration_checkmail_hook', 10, 2); - function um_post_registration_checkmail_hook($user_id, $args){ - um_fetch_user( $user_id ); - - UM()->user()->email_pending(); - } - - /** - * Account needs admin review - */ - add_action('um_post_registration_pending_hook', 'um_post_registration_pending_hook', 10, 2); - function um_post_registration_pending_hook($user_id, $args){ - um_fetch_user( $user_id ); - - UM()->user()->pending(); - } - - - /** - * After insert a new user - * run at frontend and backend + * UM hook * - * @param $user_id - * @param $args + * @type action + * @title um_registration_set_extra_data + * @description Hook that runs after insert user to DB and there you can set any extra details + * @input_vars + * [{"var":"$user_id","type":"int","desc":"User ID"}, + * {"var":"$args","type":"array","desc":"Form data"}] + * @change_log + * ["Since: 2.0"] + * @usage add_action( 'um_registration_set_extra_data', 'function_name', 10, 2 ); + * @example + * */ - function um_after_insert_user( $user_id, $args ) { - //clear Users cached queue - UM()->user()->remove_cached_queue(); - - if ( ! empty( $args['submitted'] ) ) { - um_fetch_user( $user_id ); - UM()->user()->set_registration_details( $args['submitted'] ); - } - - /** - * UM hook - * - * @type action - * @title um_registration_set_extra_data - * @description Hook that runs after insert user to DB and there you can set any extra details - * @input_vars - * [{"var":"$user_id","type":"int","desc":"User ID"}, - * {"var":"$args","type":"array","desc":"Form data"}] - * @change_log - * ["Since: 2.0"] - * @usage add_action( 'um_registration_set_extra_data', 'function_name', 10, 2 ); - * @example - * - */ - do_action( 'um_registration_set_extra_data', $user_id, $args ); - - /** - * UM hook - * - * @type action - * @title um_registration_complete - * @description After complete UM user registration. Redirects handlers at 100 priority, you can add some info before redirects - * @input_vars - * [{"var":"$user_id","type":"int","desc":"User ID"}, - * {"var":"$args","type":"array","desc":"Form data"}] - * @change_log - * ["Since: 2.0"] - * @usage add_action( 'um_registration_complete', 'function_name', 10, 2 ); - * @example - * - */ - do_action( 'um_registration_complete', $user_id, $args ); - } - add_action( 'um_user_register', 'um_after_insert_user', 10, 2 ); - - - /** - * Send notification about registration - * - * @param $user_id - * @param $args - */ - function um_send_registration_notification( $user_id, $args ) { - um_fetch_user( $user_id ); - - if ( um_user( 'status' ) != 'pending' ) { - UM()->mail()->send( um_admin_email(), 'notification_new_user', array( 'admin' => true ) ); - } else { - UM()->mail()->send( um_admin_email(), 'notification_review', array( 'admin' => true ) ); - } - } - add_action( 'um_registration_complete', 'um_send_registration_notification', 10, 2 ); - - - /** - * Check user status and redirect it after registration - * - * @param $user_id - * @param $args - */ - function um_check_user_status( $user_id, $args ) { - $status = um_user( 'status' ); - - /** - * UM hook - * - * @type action - * @title um_post_registration_{$status}_hook - * @description After complete UM user registration. - * @input_vars - * [{"var":"$user_id","type":"int","desc":"User ID"}, - * {"var":"$args","type":"array","desc":"Form data"}] - * @change_log - * ["Since: 2.0"] - * @usage add_action( 'um_post_registration_{$status}_hook', 'function_name', 10, 2 ); - * @example - * - */ - do_action( "um_post_registration_{$status}_hook", $user_id, $args ); - - if ( ! is_admin() ) { - - do_action( "track_{$status}_user_registration" ); - - // Priority redirect - if ( isset( $args['redirect_to'] ) ) { - exit( wp_redirect( urldecode( $args['redirect_to'] ) ) ); - } - - if ( $status == 'approved' ) { - - UM()->user()->auto_login( $user_id ); - UM()->user()->generate_profile_slug( $user_id ); - - /** - * UM hook - * - * @type action - * @title um_registration_after_auto_login - * @description After complete UM user registration and autologin. - * @input_vars - * [{"var":"$user_id","type":"int","desc":"User ID"}] - * @change_log - * ["Since: 2.0"] - * @usage add_action( 'um_registration_after_auto_login', 'function_name', 10, 1 ); - * @example - * - */ - do_action( 'um_registration_after_auto_login', $user_id ); - - if ( um_user( 'auto_approve_act' ) == 'redirect_url' && um_user( 'auto_approve_url' ) !== '' ) { - exit( wp_redirect( um_user( 'auto_approve_url' ) ) ); - } - - if ( um_user( 'auto_approve_act' ) == 'redirect_profile' ) { - exit( wp_redirect( um_user_profile_url() ) ); - } - - } - - if ( $status != 'approved' ) { - - if ( um_user( $status . '_action' ) == 'redirect_url' && um_user( $status . '_url' ) != '' ) { - /** - * UM hook - * - * @type filter - * @title um_registration_pending_user_redirect - * @description Change redirect URL for pending user after registration - * @input_vars - * [{"var":"$url","type":"string","desc":"Redirect URL"}, - * {"var":"$status","type":"string","desc":"User status"}, - * {"var":"$user_id","type":"int","desc":"User ID"}] - * @change_log - * ["Since: 2.0"] - * @usage - * - * @example - * - */ - $redirect_url = apply_filters( 'um_registration_pending_user_redirect', um_user( $status . '_url' ), $status, um_user( 'ID' ) ); - - exit( wp_redirect( $redirect_url ) ); - } - - if ( um_user( $status . '_action' ) == 'show_message' && um_user( $status . '_message' ) != '' ) { - - $url = UM()->permalinks()->get_current_url(); - $url = add_query_arg( 'message', esc_attr( $status ), $url ); - //add only priority role to URL - $url = add_query_arg( 'um_role', esc_attr( um_user( 'role' ) ), $url ); - $url = add_query_arg( 'um_form_id', esc_attr( $args['form_id'] ), $url ); - - exit( wp_redirect( $url ) ); - } - - } - - } - - } - add_action( 'um_registration_complete', 'um_check_user_status', 100, 2 ); - + do_action( 'um_registration_set_extra_data', $user_id, $args ); /** - * Registration form submit handler + * UM hook * - * @param $args - * @return bool|int|WP_Error + * @type action + * @title um_registration_complete + * @description After complete UM user registration. Redirects handlers at 100 priority, you can add some info before redirects + * @input_vars + * [{"var":"$user_id","type":"int","desc":"User ID"}, + * {"var":"$args","type":"array","desc":"Form data"}] + * @change_log + * ["Since: 2.0"] + * @usage add_action( 'um_registration_complete', 'function_name', 10, 2 ); + * @example + * */ - function um_submit_form_register( $args ) { - if ( isset( UM()->form()->errors ) ) - return false; + do_action( 'um_registration_complete', $user_id, $args ); +} +add_action( 'um_user_register', 'um_after_insert_user', 10, 2 ); - /** - * UM hook - * - * @type filter - * @title um_add_user_frontend_submitted - * @description Extend user data on registration form submit - * @input_vars - * [{"var":"$submitted","type":"array","desc":"Registration data"}] - * @change_log - * ["Since: 2.0"] - * @usage - * - * @example - * - */ - $args = apply_filters( 'um_add_user_frontend_submitted', $args ); - extract( $args ); +/** + * Send notification about registration + * + * @param $user_id + * @param $args + */ +function um_send_registration_notification( $user_id, $args ) { + um_fetch_user( $user_id ); - if ( isset( $username ) && ! isset( $user_login ) ) { - $user_login = $username; + if ( um_user( 'status' ) != 'pending' ) { + UM()->mail()->send( um_admin_email(), 'notification_new_user', array( 'admin' => true ) ); + } else { + UM()->mail()->send( um_admin_email(), 'notification_review', array( 'admin' => true ) ); + } +} +add_action( 'um_registration_complete', 'um_send_registration_notification', 10, 2 ); + + +/** + * Check user status and redirect it after registration + * + * @param $user_id + * @param $args + */ +function um_check_user_status( $user_id, $args ) { + $status = um_user( 'status' ); + + /** + * UM hook + * + * @type action + * @title um_post_registration_{$status}_hook + * @description After complete UM user registration. + * @input_vars + * [{"var":"$user_id","type":"int","desc":"User ID"}, + * {"var":"$args","type":"array","desc":"Form data"}] + * @change_log + * ["Since: 2.0"] + * @usage add_action( 'um_post_registration_{$status}_hook', 'function_name', 10, 2 ); + * @example + * + */ + do_action( "um_post_registration_{$status}_hook", $user_id, $args ); + + if ( ! is_admin() ) { + + do_action( "track_{$status}_user_registration" ); + + // Priority redirect + if ( isset( $args['redirect_to'] ) ) { + exit( wp_redirect( urldecode( $args['redirect_to'] ) ) ); } - if ( ! empty( $first_name ) && ! empty( $last_name ) && ! isset( $user_login ) ) { + if ( $status == 'approved' ) { - if ( UM()->options()->get( 'permalink_base' ) == 'name' ) { - $user_login = rawurlencode( strtolower( str_replace( " ", ".", $first_name . " " . $last_name ) ) ); - } elseif ( UM()->options()->get( 'permalink_base' ) == 'name_dash' ) { - $user_login = rawurlencode( strtolower( str_replace( " ", "-", $first_name . " " . $last_name ) ) ); - } elseif ( UM()->options()->get( 'permalink_base' ) == 'name_plus' ) { - $user_login = strtolower( str_replace( " ", "+", $first_name . " " . $last_name ) ); - } else { - $user_login = strtolower( str_replace( " ", "", $first_name . " " . $last_name ) ); - } + UM()->user()->auto_login( $user_id ); + UM()->user()->generate_profile_slug( $user_id ); - // if full name exists - $count = 1; - while ( username_exists( $user_login ) ) { - $user_login .= $count; - $count++; - } - } - - if ( ! isset( $user_login ) && isset( $user_email ) && $user_email ) { - $user_login = $user_email; - } - - $unique_userID = UM()->query()->count_users() + 1; - - if ( ! isset( $user_login ) || strlen( $user_login ) > 30 && ! is_email( $user_login ) ) { - $user_login = 'user' . $unique_userID; - } - - if ( isset( $username ) && is_email( $username ) ) { - $user_email = $username; - } - - if ( ! isset( $user_password ) ) { - $user_password = UM()->validation()->generate( 8 ); - } - - if ( ! isset( $user_email ) ) { - $site_url = @$_SERVER['SERVER_NAME']; - $user_email = 'nobody' . $unique_userID . '@' . $site_url; /** * UM hook * - * @type filter - * @title um_user_register_submitted__email - * @description Change user default email if it's empty on registration + * @type action + * @title um_registration_after_auto_login + * @description After complete UM user registration and autologin. * @input_vars - * [{"var":"$user_email","type":"string","desc":"Default email"}] + * [{"var":"$user_id","type":"int","desc":"User ID"}] * @change_log * ["Since: 2.0"] - * @usage - * + * @usage add_action( 'um_registration_after_auto_login', 'function_name', 10, 1 ); * @example * */ - $user_email = apply_filters( 'um_user_register_submitted__email', $user_email ); + do_action( 'um_registration_after_auto_login', $user_id ); + + if ( um_user( 'auto_approve_act' ) == 'redirect_url' && um_user( 'auto_approve_url' ) !== '' ) { + exit( wp_redirect( um_user( 'auto_approve_url' ) ) ); + } + + if ( um_user( 'auto_approve_act' ) == 'redirect_profile' ) { + exit( wp_redirect( um_user_profile_url() ) ); + } + } - $credentials = array( - 'user_login' => $user_login, - 'user_password' => $user_password, - 'user_email' => trim( $user_email ), - ); + if ( $status != 'approved' ) { - $args['submitted'] = array_merge( $args['submitted'], $credentials ); - $args = array_merge( $args, $credentials ); + if ( um_user( $status . '_action' ) == 'redirect_url' && um_user( $status . '_url' ) != '' ) { + /** + * UM hook + * + * @type filter + * @title um_registration_pending_user_redirect + * @description Change redirect URL for pending user after registration + * @input_vars + * [{"var":"$url","type":"string","desc":"Redirect URL"}, + * {"var":"$status","type":"string","desc":"User status"}, + * {"var":"$user_id","type":"int","desc":"User ID"}] + * @change_log + * ["Since: 2.0"] + * @usage + * + * @example + * + */ + $redirect_url = apply_filters( 'um_registration_pending_user_redirect', um_user( $status . '_url' ), $status, um_user( 'ID' ) ); - /** - * UM hook - * - * @type filter - * @title um_registration_user_role - * @description Change user role on registration process - * @input_vars - * [{"var":"$role","type":"string","desc":"User role"}, - * {"var":"$submitted","type":"array","desc":"Registration data"}] - * @change_log - * ["Since: 2.0"] - * @usage - * - * @example - * - */ - $user_role = apply_filters( 'um_registration_user_role', UM()->form()->assigned_role( UM()->form()->form_id ), $args ); + exit( wp_redirect( $redirect_url ) ); + } - $userdata = array( - 'user_login' => $user_login, - 'user_pass' => $user_password, - 'user_email' => $user_email, - 'role' => $user_role, - ); - $user_id = wp_insert_user( $userdata ); + if ( um_user( $status . '_action' ) == 'show_message' && um_user( $status . '_message' ) != '' ) { - /** - * UM hook - * - * @type action - * @title um_user_register - * @description After complete UM user registration. - * @input_vars - * [{"var":"$user_id","type":"int","desc":"User ID"}, - * {"var":"$args","type":"array","desc":"Form data"}] - * @change_log - * ["Since: 2.0"] - * @usage add_action( 'um_user_register', 'function_name', 10, 2 ); - * @example - * - */ - do_action( 'um_user_register', $user_id, $args ); + $url = UM()->permalinks()->get_current_url(); + $url = add_query_arg( 'message', esc_attr( $status ), $url ); + //add only priority role to URL + $url = add_query_arg( 'um_role', esc_attr( um_user( 'role' ) ), $url ); + $url = add_query_arg( 'um_form_id', esc_attr( $args['form_id'] ), $url ); - return $user_id; - } - add_action( 'um_submit_form_register', 'um_submit_form_register', 10 ); + exit( wp_redirect( $url ) ); + } - - /** - * Register user with predefined role in options - */ - add_action( 'um_after_register_fields', 'um_add_user_role' ); - function um_add_user_role( $args ) { - - if ( isset( $args['custom_fields']['role_select'] ) || isset( $args['custom_fields']['role_radio'] ) ) return; - - $use_custom_settings = get_post_meta( $args['form_id'], '_um_register_use_custom_settings', true ); - - if ( ! empty( $args['role'] ) && $use_custom_settings ) { - $role = $args['role']; - } else if( ! $use_custom_settings ) { - $role = get_option( 'default_role' ); - } - - if( empty( $role ) ) return; - - /** - * UM hook - * - * @type filter - * @title um_register_hidden_role_field - * @description Display hidden role field - * @input_vars - * [{"var":"$role","type":"string","desc":"Hidden user role"}] - * @change_log - * ["Since: 2.0"] - * @usage - * - * @example - * - */ - $role = apply_filters('um_register_hidden_role_field', $role ); - if( $role ){ - echo ''; } } +} +add_action( 'um_registration_complete', 'um_check_user_status', 100, 2 ); + + +/** + * Registration form submit handler + * + * @param $args + * @return bool|int|WP_Error + */ +function um_submit_form_register( $args ) { + if ( isset( UM()->form()->errors ) ) + return false; + /** - * Show the submit button + * UM hook + * + * @type filter + * @title um_add_user_frontend_submitted + * @description Extend user data on registration form submit + * @input_vars + * [{"var":"$submitted","type":"array","desc":"Registration data"}] + * @change_log + * ["Since: 2.0"] + * @usage + * + * @example + * */ - add_action('um_after_register_fields', 'um_add_submit_button_to_register', 1000); - function um_add_submit_button_to_register($args){ - // DO NOT add when reviewing user's details - if ( isset( UM()->user()->preview ) && UM()->user()->preview == true && is_admin() ) return; + $args = apply_filters( 'um_add_user_frontend_submitted', $args ); - $primary_btn_word = $args['primary_btn_word']; + extract( $args ); + + if ( isset( $username ) && ! isset( $user_login ) ) { + $user_login = $username; + } + + if ( ! empty( $first_name ) && ! empty( $last_name ) && ! isset( $user_login ) ) { + + if ( UM()->options()->get( 'permalink_base' ) == 'name' ) { + $user_login = rawurlencode( strtolower( str_replace( " ", ".", $first_name . " " . $last_name ) ) ); + } elseif ( UM()->options()->get( 'permalink_base' ) == 'name_dash' ) { + $user_login = rawurlencode( strtolower( str_replace( " ", "-", $first_name . " " . $last_name ) ) ); + } elseif ( UM()->options()->get( 'permalink_base' ) == 'name_plus' ) { + $user_login = strtolower( str_replace( " ", "+", $first_name . " " . $last_name ) ); + } else { + $user_login = strtolower( str_replace( " ", "", $first_name . " " . $last_name ) ); + } + + // if full name exists + $count = 1; + while ( username_exists( $user_login ) ) { + $user_login .= $count; + $count++; + } + } + + if ( ! isset( $user_login ) && isset( $user_email ) && $user_email ) { + $user_login = $user_email; + } + + $unique_userID = UM()->query()->count_users() + 1; + + if ( ! isset( $user_login ) || strlen( $user_login ) > 30 && ! is_email( $user_login ) ) { + $user_login = 'user' . $unique_userID; + } + + if ( isset( $username ) && is_email( $username ) ) { + $user_email = $username; + } + + if ( ! isset( $user_password ) ) { + $user_password = UM()->validation()->generate( 8 ); + } + + if ( ! isset( $user_email ) ) { + $site_url = @$_SERVER['SERVER_NAME']; + $user_email = 'nobody' . $unique_userID . '@' . $site_url; /** * UM hook * * @type filter - * @title um_register_form_button_one - * @description Change Register Form Primary button + * @title um_user_register_submitted__email + * @description Change user default email if it's empty on registration * @input_vars - * [{"var":"$primary_btn_word","type":"string","desc":"Button text"}, - * {"var":"$args","type":"array","desc":"Registration Form arguments"}] + * [{"var":"$user_email","type":"string","desc":"Default email"}] * @change_log * ["Since: 2.0"] * @usage - * + * * @example * */ - $primary_btn_word = apply_filters('um_register_form_button_one', $primary_btn_word, $args ); + $user_email = apply_filters( 'um_user_register_submitted__email', $user_email ); + } - $secondary_btn_word = $args['secondary_btn_word']; - /** - * UM hook - * - * @type filter - * @title um_register_form_button_two - * @description Change Registration Form Secondary button - * @input_vars - * [{"var":"$secondary_btn_word","type":"string","desc":"Button text"}, - * {"var":"$args","type":"array","desc":"Registration Form arguments"}] - * @change_log - * ["Since: 2.0"] - * @usage - * - * @example - * - */ - $secondary_btn_word = apply_filters('um_register_form_button_two', $secondary_btn_word, $args ); + $credentials = array( + 'user_login' => $user_login, + 'user_password' => $user_password, + 'user_email' => trim( $user_email ), + ); - $secondary_btn_url = ( isset( $args['secondary_btn_url'] ) && $args['secondary_btn_url'] ) ? $args['secondary_btn_url'] : um_get_core_page('login'); - /** - * UM hook - * - * @type filter - * @title um_register_form_button_two_url - * @description Change Registration Form Secondary button URL - * @input_vars - * [{"var":"$secondary_btn_url","type":"string","desc":"Button URL"}, - * {"var":"$args","type":"array","desc":"Registration Form arguments"}] - * @change_log - * ["Since: 2.0"] - * @usage - * - * @example - * - */ - $secondary_btn_url = apply_filters('um_register_form_button_two_url', $secondary_btn_url, $args ); + $args['submitted'] = array_merge( $args['submitted'], $credentials ); + $args = array_merge( $args, $credentials ); - ?> + /** + * UM hook + * + * @type filter + * @title um_registration_user_role + * @description Change user role on registration process + * @input_vars + * [{"var":"$role","type":"string","desc":"User role"}, + * {"var":"$submitted","type":"array","desc":"Registration data"}] + * @change_log + * ["Since: 2.0"] + * @usage + * + * @example + * + */ + $user_role = apply_filters( 'um_registration_user_role', UM()->form()->assigned_role( UM()->form()->form_id ), $args ); -
+ $userdata = array( + 'user_login' => $user_login, + 'user_pass' => $user_password, + 'user_email' => $user_email, + 'role' => $user_role, + ); + $user_id = wp_insert_user( $userdata ); - + /** + * UM hook + * + * @type action + * @title um_user_register + * @description After complete UM user registration. + * @input_vars + * [{"var":"$user_id","type":"int","desc":"User ID"}, + * {"var":"$args","type":"array","desc":"Form data"}] + * @change_log + * ["Since: 2.0"] + * @usage add_action( 'um_user_register', 'function_name', 10, 2 ); + * @example + * + */ + do_action( 'um_user_register', $user_id, $args ); + + return $user_id; +} +add_action( 'um_submit_form_register', 'um_submit_form_register', 10 ); + + +/** + * Register user with predefined role in options + * + * @param $args + */ +function um_add_user_role( $args ) { + + if ( isset( $args['custom_fields']['role_select'] ) || isset( $args['custom_fields']['role_radio'] ) ) return; + + $use_custom_settings = get_post_meta( $args['form_id'], '_um_register_use_custom_settings', true ); + + $role = apply_filters( 'um_registration_user_role', UM()->form()->assigned_role( UM()->form()->form_id ), $args ); + + if ( empty( $role ) ) return; + + /** + * UM hook + * + * @type filter + * @title um_register_hidden_role_field + * @description Display hidden role field + * @input_vars + * [{"var":"$role","type":"string","desc":"Hidden user role"}] + * @change_log + * ["Since: 2.0"] + * @usage + * + * @example + * + */ + $role = apply_filters( 'um_register_hidden_role_field', $role ); + if ( $role ) { + echo ''; + } + +} +add_action( 'um_after_register_fields', 'um_add_user_role', 10, 1 ); + + +/** + * Show the submit button + * + * @param $args + */ +function um_add_submit_button_to_register( $args ) { + // DO NOT add when reviewing user's details + if ( isset( UM()->user()->preview ) && UM()->user()->preview == true && is_admin() ) return; + + $primary_btn_word = $args['primary_btn_word']; + /** + * UM hook + * + * @type filter + * @title um_register_form_button_one + * @description Change Register Form Primary button + * @input_vars + * [{"var":"$primary_btn_word","type":"string","desc":"Button text"}, + * {"var":"$args","type":"array","desc":"Registration Form arguments"}] + * @change_log + * ["Since: 2.0"] + * @usage + * + * @example + * + */ + $primary_btn_word = apply_filters('um_register_form_button_one', $primary_btn_word, $args ); + + $secondary_btn_word = $args['secondary_btn_word']; + /** + * UM hook + * + * @type filter + * @title um_register_form_button_two + * @description Change Registration Form Secondary button + * @input_vars + * [{"var":"$secondary_btn_word","type":"string","desc":"Button text"}, + * {"var":"$args","type":"array","desc":"Registration Form arguments"}] + * @change_log + * ["Since: 2.0"] + * @usage + * + * @example + * + */ + $secondary_btn_word = apply_filters('um_register_form_button_two', $secondary_btn_word, $args ); + + $secondary_btn_url = ( isset( $args['secondary_btn_url'] ) && $args['secondary_btn_url'] ) ? $args['secondary_btn_url'] : um_get_core_page('login'); + /** + * UM hook + * + * @type filter + * @title um_register_form_button_two_url + * @description Change Registration Form Secondary button URL + * @input_vars + * [{"var":"$secondary_btn_url","type":"string","desc":"Button URL"}, + * {"var":"$args","type":"array","desc":"Registration Form arguments"}] + * @change_log + * ["Since: 2.0"] + * @usage + * + * @example + * + */ + $secondary_btn_url = apply_filters('um_register_form_button_two_url', $secondary_btn_url, $args ); ?> + +
+ +
- +
- + -
+
-
+
- fields()->display( 'register', $args ); - } - - - /** - * Saving files to register a new user, if there are fields with files - */ - add_action( 'um_registration_set_extra_data', 'um_registration_save_files', 10, 2 ); - function um_registration_save_files( $user_id, $args ) { +/** + * Show Fields + * + * @param $args + */ +function um_add_register_fields( $args ){ + echo UM()->fields()->display( 'register', $args ); +} +add_action( 'um_main_register_fields', 'um_add_register_fields', 100 ); - if ( empty( $args['custom_fields'] ) ) - return; - $files = array(); +/** + * Saving files to register a new user, if there are fields with files + * + * @param $user_id + * @param $args + */ +function um_registration_save_files( $user_id, $args ) { - $fields = unserialize( $args['custom_fields'] ); + if ( empty( $args['custom_fields'] ) ) + return; - // loop through fields - if ( isset( $fields ) && is_array( $fields ) ) { + $files = array(); - foreach ( $fields as $key => $array ) { + $fields = unserialize( $args['custom_fields'] ); - if ( isset( $args['submitted'][$key] ) ) { + // loop through fields + if ( isset( $fields ) && is_array( $fields ) ) { - if ( isset( $fields[$key]['type'] ) && in_array( $fields[$key]['type'], array( 'image', 'file' ) ) && - ( um_is_temp_upload( $args['submitted'][$key] ) || $args['submitted'][$key] == 'empty_file' ) - ) { + foreach ( $fields as $key => $array ) { - $files[$key] = $args['submitted'][$key]; + if ( isset( $args['submitted'][$key] ) ) { + + if ( isset( $fields[$key]['type'] ) && in_array( $fields[$key]['type'], array( 'image', 'file' ) ) && + ( um_is_temp_upload( $args['submitted'][$key] ) || $args['submitted'][$key] == 'empty_file' ) + ) { + + $files[$key] = $args['submitted'][$key]; - } } } } - - /** - * UM hook - * - * @type filter - * @title um_user_pre_updating_files_array - * @description Change submitted files before register new user - * @input_vars - * [{"var":"$files","type":"array","desc":"Profile data files"}] - * @change_log - * ["Since: 2.0"] - * @usage - * - * @example - * - */ - $files = apply_filters( 'um_user_pre_updating_files_array', $files ); - - if ( !empty( $files ) ) { - /** - * UM hook - * - * @type action - * @title um_before_user_upload - * @description Before file uploaded on complete UM user registration. - * @input_vars - * [{"var":"$user_id","type":"int","desc":"User ID"}, - * {"var":"$files","type":"array","desc":"Files data"}] - * @change_log - * ["Since: 2.0"] - * @usage add_action( 'um_before_user_upload', 'function_name', 10, 2 ); - * @example - * - */ - do_action( 'um_before_user_upload', $user_id, $files ); - UM()->user()->update_files( $files ); - /** - * UM hook - * - * @type action - * @title um_after_user_upload - * @description After complete UM user registration and file uploaded. - * @input_vars - * [{"var":"$user_id","type":"int","desc":"User ID"}, - * {"var":"$files","type":"array","desc":"Files data"}] - * @change_log - * ["Since: 2.0"] - * @usage add_action( 'um_after_user_upload', 'function_name', 10, 2 ); - * @example - * - */ - do_action( 'um_after_user_upload', $user_id, $files ); - } } /** - * Update user Full Name + * UM hook * - * @profile name update - * - * @param $user_id - * @param $args + * @type filter + * @title um_user_pre_updating_files_array + * @description Change submitted files before register new user + * @input_vars + * [{"var":"$files","type":"array","desc":"Profile data files"}] + * @change_log + * ["Since: 2.0"] + * @usage + * + * @example + * */ - function um_registration_set_profile_full_name( $user_id, $args ) { + $files = apply_filters( 'um_user_pre_updating_files_array', $files ); + + if ( !empty( $files ) ) { /** * UM hook * * @type action - * @title um_update_profile_full_name - * @description On update user profile change full name + * @title um_before_user_upload + * @description Before file uploaded on complete UM user registration. * @input_vars * [{"var":"$user_id","type":"int","desc":"User ID"}, - * {"var":"$args","type":"array","desc":"Form data"}] + * {"var":"$files","type":"array","desc":"Files data"}] * @change_log * ["Since: 2.0"] - * @usage add_action( 'um_update_profile_full_name', 'function_name', 10, 2 ); + * @usage add_action( 'um_before_user_upload', 'function_name', 10, 2 ); * @example * */ - do_action( 'um_update_profile_full_name', $user_id, $args ); + do_action( 'um_before_user_upload', $user_id, $files ); + UM()->user()->update_files( $files ); + /** + * UM hook + * + * @type action + * @title um_after_user_upload + * @description After complete UM user registration and file uploaded. + * @input_vars + * [{"var":"$user_id","type":"int","desc":"User ID"}, + * {"var":"$files","type":"array","desc":"Files data"}] + * @change_log + * ["Since: 2.0"] + * @usage add_action( 'um_after_user_upload', 'function_name', 10, 2 ); + * @example + * + */ + do_action( 'um_after_user_upload', $user_id, $files ); } +} +add_action( 'um_registration_set_extra_data', 'um_registration_save_files', 10, 2 ); - add_action( 'um_registration_set_extra_data', 'um_registration_set_profile_full_name', 10, 2 ); \ No newline at end of file + +/** + * Update user Full Name + * + * @profile name update + * + * @param $user_id + * @param $args + */ +function um_registration_set_profile_full_name( $user_id, $args ) { + /** + * UM hook + * + * @type action + * @title um_update_profile_full_name + * @description On update user profile change full name + * @input_vars + * [{"var":"$user_id","type":"int","desc":"User ID"}, + * {"var":"$args","type":"array","desc":"Form data"}] + * @change_log + * ["Since: 2.0"] + * @usage add_action( 'um_update_profile_full_name', 'function_name', 10, 2 ); + * @example + * + */ + do_action( 'um_update_profile_full_name', $user_id, $args ); +} +add_action( 'um_registration_set_extra_data', 'um_registration_set_profile_full_name', 10, 2 ); \ No newline at end of file diff --git a/includes/core/um-actions-save-profile.php b/includes/core/um-actions-save-profile.php index c59f8923..e479d3df 100644 --- a/includes/core/um-actions-save-profile.php +++ b/includes/core/um-actions-save-profile.php @@ -1,70 +1,69 @@ -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( '
' . var_export( array( 'message' => $return->get_error_message(), 'dump' => $arr_user, 'changes' => $changes ), true ) . '
' ); } - 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( '
' . var_export( array( 'message' => $return->get_error_message(), 'dump' => $arr_user, 'changes' => $changes ), true ) . '
' ); - } - + 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 ); - } \ No newline at end of file + // regenerate slug + UM()->user()->generate_profile_slug( $user_id ); +} +add_action( 'um_update_profile_full_name', 'um_update_profile_full_name', 10, 2 ); \ No newline at end of file diff --git a/includes/core/um-filters-account.php b/includes/core/um-filters-account.php index 2a2ed8ec..f1087fbd 100644 --- a/includes/core/um-filters-account.php +++ b/includes/core/um-filters-account.php @@ -1,66 +1,62 @@ - + * @example + * */ - 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 - * - * @example - * - */ - $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; - } \ No newline at end of file +/** + * 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 ); \ No newline at end of file diff --git a/includes/core/um-filters-avatars.php b/includes/core/um-filters-avatars.php index 77e22db1..715e8aec 100644 --- a/includes/core/um-filters-avatars.php +++ b/includes/core/um-filters-avatars.php @@ -1,103 +1,104 @@ -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 + * + * @example + * */ - 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 - * - * @example - * - */ - $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 = "&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 = ''.$image_alt.''; - - }else if( empty( $avatar ) ){ - $default_avatar_uri = um_get_default_avatar_uri(); - - $avatar = ''.$image_alt.''; + $default = get_option( 'avatar_default', 'mystery' ); + if ( $default == 'gravatar_default' ) { + $default = ''; } - return $avatar; - + $rating = get_option('avatar_rating'); + if ( !empty( $rating ) ) { + $rating = "&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 = ''.$image_alt.''; + + }else if( empty( $avatar ) ){ + $default_avatar_uri = um_get_default_avatar_uri(); + + $avatar = ''.$image_alt.''; } + return $avatar; +} +add_filter( 'get_avatar', 'um_get_avatar', 99999, 5 ); \ No newline at end of file diff --git a/includes/core/um-filters-commenting.php b/includes/core/um-filters-commenting.php index 17a21078..acadc17f 100644 --- a/includes/core/um-filters-commenting.php +++ b/includes/core/um-filters-commenting.php @@ -1,34 +1,37 @@ -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 = '' . UM()->user()->cached_user[$comment->user_id]['name'] . ''; + $return = '' . UM()->user()->cached_user[$comment->user_id]['name'] . ''; - } 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 = '' . UM()->user()->cached_user[$comment->user_id]['name'] . ''; + UM()->user()->cached_user[ $comment->user_id ] = array('url' => um_user_profile_url(), 'name' => um_user('display_name') ); + $return = '' . UM()->user()->cached_user[$comment->user_id]['name'] . ''; - um_reset_user(); + um_reset_user(); - } - } - - return $return; + } } - \ No newline at end of file + return $return; +} + +add_filter('get_comment_author_link', 'um_comment_link_to_profile', 10000, 3 ); \ No newline at end of file diff --git a/includes/core/um-filters-fields.php b/includes/core/um-filters-fields.php index af8d0e7f..e68498ce 100644 --- a/includes/core/um-filters-fields.php +++ b/includes/core/um-filters-fields.php @@ -1,118 +1,162 @@ -options()->get( 'form_asterisk' ); - if ( $asterisk && isset( $data['required'] ) && $data['required'] == 1 ) - $label = $label . '*'; + $asterisk = UM()->options()->get( 'form_asterisk' ); + if ( $asterisk && isset( $data['required'] ) && $data['required'] == 1 ) + $label = $label . '*'; - 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 = '
+ $value = '
'; - 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 = '
+ +/** + * 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 = '
'; - 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 = '
+ $value = ( !is_numeric( $value ) ) ? (int) substr(parse_url($value, PHP_URL_PATH), 1) : $value; + $value = '
'; - 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 = '
+ +/** + * Outputs a google map + * + * @param $value + * @param $data + * + * @return string + */ +function um_profile_field_filter_hook__googlemap( $value, $data ) { + $value = '
'; + 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', ' $1 ', $value." "); + $value = preg_replace('$(www\.[a-z0-9_./?=&#-]+)(?![^<>]*>)$i', '$1 ', $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', ' $1 ', $value." "); - $value = preg_replace('$(www\.[a-z0-9_./?=&#-]+)(?![^<>]*>)$i', '$1 ', $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 = '
+ if ( !file_exists( um_user_uploads_dir() . $value ) ) { + $value = __('This file has been removed.'); + } else { + $value = ''; - } - - 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( '/\'.$title.'
'; + } else if ( file_exists( um_user_uploads_dir() . $value ) ) { + $value = '
'.$title.'
'; + } 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( '/\'.$title.'
'; - } else if ( file_exists( um_user_uploads_dir() . $value ) ) { - $value = '
'.$title.'
'; } else { - $value = ''; + + if ( strpos($value, 'http://') !== 0 ) { + $value = 'http://' . $value; + } + $data['url_target'] = ( isset( $data['url_target'] ) ) ? $data['url_target'] : '_blank'; + $value = ''.$alt.''; + } - 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 = ''.$value.''; + } 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 = ''.$alt.''; - } - } + } - if ( !is_array( $value ) ) { - if ( is_email( $value ) ) - $value = ''.$value.''; - } 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 ); \ No newline at end of file + + 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 ); \ No newline at end of file diff --git a/includes/core/um-filters-files.php b/includes/core/um-filters-files.php index 166846e8..7b431016 100644 --- a/includes/core/um-filters-files.php +++ b/includes/core/um-filters-files.php @@ -1,13 +1,13 @@ -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 = ''; + 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 - * - */ - 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 - * - */ - do_action( "um_submit_form_errors_hook__blockedemails", $args = array( 'username' => $username ) ); + + if ( isset( $err ) ) { + $message = ''; + } + + 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 + * + */ + 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 + * + */ + 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 ); + } - } \ No newline at end of file + return wp_authenticate_username_password( $user, $username, $password ); + +} +add_filter( 'authenticate', 'um_wp_form_errors_hook_logincheck', 50, 3 ); \ No newline at end of file diff --git a/includes/core/um-filters-members.php b/includes/core/um-filters-members.php index cd10449e..3f780466 100644 --- a/includes/core/um-filters-members.php +++ b/includes/core/um-filters-members.php @@ -1,462 +1,488 @@ -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 - * - * @example - * - */ - $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 + * + * @example + * + */ + $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 + * + * @example + * + */ + $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 - * + * * @example * */ - $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 - * - * @example - * - */ - $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' ); \ No newline at end of file diff --git a/includes/core/um-filters-misc.php b/includes/core/um-filters-misc.php index bb9a8041..5154a89f 100644 --- a/includes/core/um-filters-misc.php +++ b/includes/core/um-filters-misc.php @@ -1,13 +1,15 @@ - 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 ); } \ No newline at end of file diff --git a/includes/core/um-filters-profile.php b/includes/core/um-filters-profile.php index 11686697..6a94e1c9 100644 --- a/includes/core/um-filters-profile.php +++ b/includes/core/um-filters-profile.php @@ -1,94 +1,105 @@ -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'] .= '( '.__('max','ultimate-member').': '.$file_size.$unit.' )'; } 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'] .= '( '.__('max','ultimate-member').': '.$file_size.$unit.' )'; - } - return $args; + if ( $file_size < 999999999 ) { + $args['profile_photo']['upload_text'] .= '( '.__('max','ultimate-member').': '.$file_size.$unit.' )'; } + return $args; +} +add_filter( 'um_predefined_fields_hook', 'um_change_profile_photo_label', 10, 1 ); \ No newline at end of file diff --git a/includes/core/um-filters-user.php b/includes/core/um-filters-user.php index 6c038a0d..6fef1987 100644 --- a/includes/core/um-filters-user.php +++ b/includes/core/um-filters-user.php @@ -1,12 +1,13 @@ -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 - * - * @example - * - */ - $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 + * + * @example + * + */ + $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 - * - * @example - * - */ - $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 + * + * @example + * + */ + $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 - * - * @example - * - */ - $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 + * + * @example + * + */ + $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 - * - * @example - * - */ - $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 + * + * @example + * + */ + $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 ); /** diff --git a/includes/core/um-navmenu.php b/includes/core/um-navmenu.php index c23861c4..0840406e 100644 --- a/includes/core/um-navmenu.php +++ b/includes/core/um-navmenu.php @@ -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 */ diff --git a/includes/widgets/class-um-search-widget.php b/includes/widgets/class-um-search-widget.php index 7e0cb26a..bae8cbce 100644 --- a/includes/widgets/class-um-search-widget.php +++ b/includes/widgets/class-um-search-widget.php @@ -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 {