- updated search users form shortcode for integrate with new member directories;

This commit is contained in:
nikitasinelnikov
2019-10-18 13:01:40 +03:00
parent 6e7eee89bf
commit 3122e79e37
13 changed files with 232 additions and 142 deletions
+11 -50
View File
@@ -119,6 +119,17 @@ if ( ! class_exists( 'um\core\Member_Directory' ) ) {
}
/**
* @param $id
*
* @return bool|string
*/
function get_directory_hash( $id ) {
$hash = substr( md5( $id ), 10, 5 );
return $hash;
}
/**
* Get view Type template
* @param string $type
@@ -245,55 +256,6 @@ if ( ! class_exists( 'um\core\Member_Directory' ) ) {
asort( $this->default_sorting );
// <!-- <option value="description">Biography</option> to Search-->
//<!-- <option value="user_email">E-mail Address</option> to Search-->
//<!-- <option value="first_name">First Name</option> to Search-->
//<!-- <option value="last_name">Last Name</option> to Search-->
//<!-- <option value="mobile_number">Mobile Number</option> to Search-->
//<!-- <option value="nickname">Nickname</option> to Search-->
//<!-- <option value="phone_number">Phone Number</option> to Search-->
//<!-- <option value="secondary_user_email">Secondary E-mail Address</option> to Search-->
//<!-- <option value="user_login">Username</option> to Search-->
//<!-- <option value="username">Username or E-mail</option> - username to Search-->
//<!-- <option value="gm">gm</option> - google maps field to Search-->
//<!-- <option value="numberr">number</option> - number field to Search-->
//<!-- <option value="scm">scm</option> - Soundcloud field to Search-->
//<!-- <option value="test">test</option> - text box field to Search-->
//<!-- <option value="textareaa">textareaa</option> - textarea field to Search-->
//<!-- <option value="vimeov">vimeov</option> - Vimeo field to Search-->
//<!-- <option value="youtubev">youtubev</option> - Youtube field to Search-->
//<!-- URL fields to Search-->
//<!-- Password skip-->
//<!-- File, Image Upload maybe search by file,image name-->
//<!---->
//<!---->
//<!-- DatePicker, TimePicker to Filter-->
//<!-- Rating field to Filter-->
//<!-- needs to be added 'birth_date' - Age to Filter-->
//<!-- <option value="checkboxx">checkbox</option> - checkbox field to Filter-->
//<!-- <option value="drop">drop</option> - select field to Filter-->
//<!-- <option value="radi">radi</option> - radio field to Filter-->
//<!-- <option value="multidrop">multidrop</option> - multiselect field to Filter-->
//<!-- <option value="role_radio">Roles (Radio)</option> - roles merge to Filter-->
//<!-- <option value="user_registered">Registration Date</option> - to Filter-->
//<!-- <option value="gender">Gender</option> to Filter-->
//<!-- <option value="languages">Languages</option> to Filter-->
//<!-- <option value="_um_last_login">Last Login</option> to Filter-->
//<!-- <option value="country">Country</option> to Filter-->
//<!---->
//<!-- So there are next filters:-->
//<!---->
//<!-- Predefined Fields:-->
//<!-- Country, Gender, Age(Birth Date field), Last Login, User Registered-->
//<!-- Languages, Roles (merge dropdown+radio)-->
//<!---->
//<!-- Custom Fields:-->
//<!-- all TimePicker, Datepicker,-->
//<!-- Rating field(by stars), Checkbox, Radio, Select, Multi-select custom fields-->
// Filters
$this->filter_fields = array(
'country' => __( 'Country', 'ultimate-member' ),
@@ -659,7 +621,6 @@ if ( ! class_exists( 'um\core\Member_Directory' ) ) {
}
/**
* @param $filter
*
+48 -6
View File
@@ -1158,14 +1158,56 @@ if ( ! class_exists( 'um\core\Shortcodes' ) ) {
* @return string
*/
public function ultimatemember_searchform( $args = array(), $content = "" ) {
// turn off buffer
ob_start();
if ( ! UM()->options()->get( 'members_page' ) ) {
return '';
}
// load template
$this->load_template( 'searchform' );
$member_directory_ids = array();
// get the buffer
$template = ob_get_clean();
$page_id = UM()->config()->permalinks['members'];
if ( ! empty( $page_id ) ) {
$members_page = get_post( $page_id );
if ( ! empty( $members_page ) && ! is_wp_error( $members_page ) ) {
if ( ! empty( $members_page->post_content ) ) {
preg_match_all( '/\[ultimatemember[^\]]*?form_id\=[\'"]*?(\d+)[\'"]*?/i', $members_page->post_content, $matches );
if ( ! empty( $matches[1] ) && is_array( $matches[1] ) ) {
$member_directory_ids = array_map( 'absint', $matches[1] );
}
}
}
}
if ( empty( $member_directory_ids ) ) {
return '';
}
//current user priority role
$priority_user_role = false;
if ( is_user_logged_in() ) {
$priority_user_role = UM()->roles()->get_priority_user_role( get_current_user_id() );
}
$query = array();
foreach ( $member_directory_ids as $directory_id ) {
$directory_data = UM()->query()->post_data( $directory_id );
$show_search = empty( $directory_data['roles_can_search'] ) || ( ! empty( $priority_user_role ) && in_array( $priority_user_role, $directory_data['roles_can_search'] ) );
if ( empty( $directory_data['search'] ) || ! $show_search ) {
continue;
}
$hash = UM()->member_directory()->get_directory_hash( $directory_id );
$query[ 'search_' . $hash ] = ! empty( $_GET[ 'search_' . $hash ] ) ? $_GET[ 'search_' . $hash ] : '';
}
if ( empty( $query ) ) {
return '';
}
$search_value = array_values( $query );
$template = UM()->get_template( 'searchform.php', '', array( 'query' => $query, 'search_value' => $search_value[0], 'members_page' => um_get_core_page( 'members' ) ) );
return $template;
}
+58
View File
@@ -438,4 +438,62 @@ function um_members( $argument ) {
$result = UM()->members()->results[ $argument ];
}
return $result;
}
/**
* Returns the ultimate member search form
*
* @deprecated 2.1.0
*
* @return string
*/
function um_get_search_form() {
//um_deprecated_function( 'um_get_search_form', '2.1.0', 'do_shortcode( \'[ultimatemember_searchform]\' )' );
return do_shortcode( '[ultimatemember_searchform]' );
}
/**
* Display the search form.
*
* @deprecated 2.1.0
*/
function um_search_form() {
//um_deprecated_function( 'um_search_form', '2.1.0', 'echo do_shortcode( \'[ultimatemember_searchform]\' )' );
echo um_get_search_form();
}
/**
* Filters the search query.
*
* @deprecated 2.1.0
*
* @param string $search
*
* @return string
*/
function um_filter_search( $search ) {
$search = trim( strip_tags( $search ) );
$search = preg_replace( '/[^a-z \.\@\_\-]+/i', '', $search );
return $search;
}
/**
* Returns the user search query
*
* @deprecated 2.1.0
*
* @return string
*/
function um_get_search_query() {
$query = UM()->permalinks()->get_query_array();
$search = isset( $query['search'] ) ? $query['search'] : '';
return um_filter_search( $search );
}
-47
View File
@@ -2547,53 +2547,6 @@ function um_force_utf8_string( $value ) {
}
/**
* Filters the search query.
*
* @param string $search
*
* @return string
*/
function um_filter_search( $search ) {
$search = trim( strip_tags( $search ) );
$search = preg_replace( '/[^a-z \.\@\_\-]+/i', '', $search );
return $search;
}
/**
* Returns the user search query
*
* @return string
*/
function um_get_search_query() {
$query = UM()->permalinks()->get_query_array();
$search = isset( $query['search'] ) ? $query['search'] : '';
return um_filter_search( $search );
}
/**
* Returns the ultimate member search form
*
* @return string
*/
function um_get_search_form() {
return do_shortcode( '[ultimatemember_searchform]' );
}
/**
* Display the search form.
*
*/
function um_search_form() {
echo um_get_search_form();
}
/**
* Get user host
*
+1 -1
View File
@@ -50,7 +50,7 @@ class UM_Search_Widget extends \WP_Widget {
}
// display the search form
um_search_form();
echo do_shortcode( '[ultimatemember_searchform /]' );
echo $args['after_widget'];
}