mirror of
https://github.com/10h30/ultimatemember.git
synced 2026-07-11 18:56:10 +09:00
- added ability to use custom metakey as profile slug;
- important: use for this case required usermeta which cannot be empty
This commit is contained in:
@@ -706,7 +706,19 @@ if ( ! class_exists( 'um\core\User' ) ) {
|
||||
public function get_profile_slug( $user_id ) {
|
||||
// Permalink base
|
||||
$permalink_base = UM()->options()->get( 'permalink_base' );
|
||||
$profile_slug = get_user_meta( $user_id, "um_user_profile_url_slug_{$permalink_base}", true );
|
||||
if ( 'custom_meta' === $permalink_base ) {
|
||||
$custom_meta = UM()->options()->get( 'permalink_base_custom_meta' );
|
||||
if ( empty( $custom_meta ) ) {
|
||||
// Set default permalink base if custom meta is empty.
|
||||
$permalink_base = 'user_login';
|
||||
$meta_key = 'um_user_profile_url_slug_' . $permalink_base;
|
||||
} else {
|
||||
$meta_key = $custom_meta;
|
||||
}
|
||||
} else {
|
||||
$meta_key = 'um_user_profile_url_slug_' . $permalink_base;
|
||||
}
|
||||
$profile_slug = get_user_meta( $user_id, $meta_key, true );
|
||||
|
||||
//get default username permalink if it's empty then return false
|
||||
if ( empty( $profile_slug ) ) {
|
||||
@@ -781,6 +793,17 @@ if ( ! class_exists( 'um\core\User' ) ) {
|
||||
$user_in_url = $this->generate_user_hash( $user_id );
|
||||
}
|
||||
|
||||
if ( 'custom_meta' === $permalink_base ) {
|
||||
$custom_meta = UM()->options()->get( 'permalink_base_custom_meta' );
|
||||
if ( empty( $custom_meta ) ) {
|
||||
// Set default permalink base if custom meta is empty.
|
||||
$permalink_base = 'user_login';
|
||||
} else {
|
||||
$user_in_url = rawurlencode( get_user_meta( $user_id, $custom_meta, true ) );
|
||||
$user_in_url = apply_filters( 'um_custom_meta_permalink_base_generate_user_slug', $user_in_url, $user_id, $custom_meta );
|
||||
}
|
||||
}
|
||||
|
||||
// Username
|
||||
if ( 'user_login' === $permalink_base ) {
|
||||
|
||||
@@ -2391,6 +2414,52 @@ if ( ! class_exists( 'um\core\User' ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $slug
|
||||
*
|
||||
* @return bool|int
|
||||
*/
|
||||
public function user_exists_by_custom_meta( $slug ) {
|
||||
$permalink_base = UM()->options()->get( 'permalink_base' );
|
||||
$custom_meta = UM()->options()->get( 'permalink_base_custom_meta' );
|
||||
if ( empty( $custom_meta ) ) {
|
||||
// Set default permalink base if custom meta is empty.
|
||||
$permalink_base = 'user_login';
|
||||
$meta_key = 'um_user_profile_url_slug_' . $permalink_base;
|
||||
} else {
|
||||
$meta_key = $custom_meta;
|
||||
}
|
||||
|
||||
$raw_value = $slug;
|
||||
|
||||
// Search by Profile Slug
|
||||
$args = array(
|
||||
'fields' => array( 'ID' ),
|
||||
'meta_query' => array(
|
||||
'relation' => 'OR',
|
||||
array(
|
||||
'key' => $meta_key,
|
||||
'value' => strtolower( $raw_value ),
|
||||
'compare' => '=',
|
||||
),
|
||||
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;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method checks if a user exists or not in your site based on the user email as username
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user