Skip to content

Instantly share code, notes, and snippets.

@AngeliMae
AngeliMae / add comment's count in the Comments tab
Created July 25, 2022 15:12
add comment's count in the Comments tab
add_filter("um_profile_tabs", "um_072522_add_comment_count", 10 );
function um_072522_add_comment_count( $tabs ){
if( isset( $tabs['comments'] ) ){
$args = array(
'user_id' => um_profile_id(), // Use user_id.
'count' => true // Return only the count.
);
$comments_count = get_comments( $args );
$tabs['comments']['notifier'] = $comments_count;
@AngeliMae
AngeliMae / Redirect to previous page after registration
Created July 25, 2022 14:23
Redirect to previous page after registration
add_action( 'um_registration_complete', 'um_072522_redirect_to_previous_after_register', 10, 2 );
function um_072522_redirect_to_previous_after_register( $user_id, $args ){
if( 5 == $args['form_id'] ){
$previous_page_url = $_COOKIE['um_previous_page'];
if( ! empty( $previous_page_url ) ){
setcookie('um_previous_page', null, strtotime('-1 day'));
wp_redirect( $previous_page_url ); exit;
}
}
@AngeliMae
AngeliMae / Add email on the menu short tag
Created July 4, 2022 12:11
Add email on the menu short tag
add_filter( 'um_allowed_user_tags_patterns', function( $pattern_array ){
$pattern_array[] = '{email}';
return $pattern_array;
});
add_filter( "um_profile_tag_hook__email", function( $value, $user_id ){
$value = um_user( 'user_email' );
return $value;
},10,2);
@AngeliMae
AngeliMae / limit the ‘search’ in member directory to first_name meta value only
Last active July 11, 2022 13:40
limit the ‘search’ in member directory to first_name meta value only
add_action("um_pre_users_query","um_061522_pre_users_query", 10, 3 );
function um_061522_pre_users_query( $obj, $directory_data, $sortby ){
if( $obj->is_search == true && ! empty( $_POST['search'] ) ){
if( ! empty( $obj->where_clauses ) ){
foreach( $obj->where_clauses as $k => $w ){
if( strpos( $w, 'umm_search' ) > -1 ){
$w = explode(" OR ", $w );
$obj->where_clauses[ $k ] = str_replace("( umm_search.um_value = ", "( umm_search.um_key = 'first_name' AND umm_search.um_value LIKE ", $w[0] . '%' ) . ')';
@AngeliMae
AngeliMae / Custom UM Action under Users
Created June 14, 2022 14:26
Custom UM Action under Users
add_filter( 'um_admin_bulk_user_actions_hook', function( $actions ){
$actions['custom_action_key'] = array( 'label' => 'Custom Action Name' );
return $actions;
});
add_action( "um_admin_custom_hook_custom_action_key", function( $user_id){
um_fetch_user( $user_id );
@AngeliMae
AngeliMae / Customize Age display with “Days”, “Weeks” , “Months” and “Years” ago
Created June 14, 2022 13:23
Customize Age display with “Days”, “Weeks” , “Months” and “Years” ago
add_filter( 'um_profile_field_filter_hook__date', 'um_061421_profile_field_filter_hook__date', 80, 2 );
function um_061421_profile_field_filter_hook__date( $value, $data ) {
if ( ! $value ) {
return '';
}
if( $data['metakey'] !== 'birth_date' ){
return $value;
}
@AngeliMae
AngeliMae / Restriction & Redirect Login Page
Last active June 17, 2022 12:54
Restriction & Redirect Login Page
add_action('template_redirect',function(){
global $post;
if ( um_is_core_page( 'login' ) && is_user_logged_in() ) {
$restriction = get_post_meta( $post->ID, 'um_content_restriction', true );
if( $restriction ){
$access = $restriction['_um_custom_access_settings'];
$accessable = $restriction['_um_accessible'];
$is_redirect = $restriction['_um_access_redirect'];
$url = $restriction['_um_access_redirect_url'];
@AngeliMae
AngeliMae / Disable the "Remove" & "Change Cover Photo" Setting Options
Created May 27, 2022 13:04
Disable the "Remove" & "Change Cover Photo" Setting Options
add_filter( 'um_cover_area_content_dropdown_items',function( $items, $profile_id ){
unset( $items[1] );
unset( $items[2] );
return $items;
},11,2 );
@AngeliMae
AngeliMae / Disable the "Remove" & "Change Cover Photo" Setting Options
Created May 26, 2022 14:33
Disable the "Remove" & "Change Cover Photo" Setting Options
add_filter( 'um_cover_area_content_dropdown_items',function( $items, $profile_id ){
unset( $items[0] );
unset( $items[1] );
return $items;
},11,2 );
@AngeliMae
AngeliMae / Enable account status sorting in Member Directories
Created May 25, 2022 15:23
Enable account status sorting in Member Directories
add_action("um_user_before_query","um_052422_orderby_profile_photo", 999999999, 2 );
function um_052422_orderby_profile_photo( $query_args, $obj ) {
$obj->query_args['meta_query'][ ] = array(
'relation' => 'OR',
'wxo_featured_clause' => array(
'key' => 'account_status',
'compare' => 'awaiting_admin_review'
),
array(