1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/**
* Show a placeholder instead of MarketKing's display-name fallback.
*/
add_filter( 'get_user_metadata', 'custom_marketking_empty_store_name', 10, 4 );
function custom_marketking_empty_store_name( $value, $user_id, $meta_key, $single ) {
if ( 'marketking_store_name' !== $meta_key || null !== $value ) {
return $value;
}
$user_id = absint( $user_id );
$all_meta = wp_cache_get( $user_id, 'user_meta' );
if ( false === $all_meta ) {
$updated_meta = update_meta_cache( 'user', array( $user_id ) );
$all_meta = isset( $updated_meta[ $user_id ] ) ? $updated_meta[ $user_id ] : array();
}
$store_name = isset( $all_meta[ $meta_key ][0] )
? maybe_unserialize( $all_meta[ $meta_key ][0] )
: '';
$vendor_group = isset( $all_meta['marketking_group'][0] )
? maybe_unserialize( $all_meta['marketking_group'][0] )
: '';
if ( ! empty( $store_name ) || empty( $vendor_group ) || 'none' === $vendor_group ) {
return $value;
}
return array( '-' );
}
add_filter( 'sanitize_user_meta_marketking_store_name', 'custom_marketking_unsave_store_name_placeholder' );
function custom_marketking_unsave_store_name_placeholder( $store_name ) {
return '-' === $store_name ? '' : $store_name;
}
How to add this code
Any method works: a code snippets plugin, or your child theme's functions.php file.
Not sure how? We recommend the free WPCode plugin: add a new PHP snippet, paste the code, then activate and save it.
Need a hand? Reply on your ticket and we'll help.