Answer the question
In order to leave comments, you need to log in
Why does the design with a custom field in the profile not work?
Help me please. What's wrong here?
function my_user_contactmethods($user_contactmethods){
$user_contactmethods['wmr'] = '<a name="wmr"></a> WMR кошелек';
return $user_contactmethods;
}
$user_idd = get_current_user_id();
$key1 = 'wmr';
$usermeta = get_user_meta($user_idd, $key1);
function notice_wmr() {
$class = 'updated';
$message = 'Ваш WMR кошелек не задан! Задайте его <a href="http://root1.ru/wp-admin/profile.php#wmr">здесь</a>';
echo "<div style=\"position: relative;\" class=\"$class\"> <p>$message</p> <button type=\"button\" class=\"notice-dismiss wmr\"><span class=\"screen-reader-text\">Скрыть это уведомление.</span></button></div>";
}
if ($usermeta == null)
add_action( 'admin_notices', 'notice_wmr' );
Answer the question
In order to leave comments, you need to log in
1. Do not escape double quotes with a backslash inside double quotes. Use single quotes (and double quotes inside).
2. get_user_meta(), if it does not find the key in the database, returns an empty string (if the third argument is true), or an empty array. Not Null at all. Moreover, if you do a comparison on Null, then you need to do $var === NULL
.
3. Getting $usermeta and checking this key should be stuffed into notice_wmr().
Haven't tested, but something like this:
add_action( 'admin_notices', 'notice_wmr' );
function notice_wmr() {
$user_idd = get_current_user_id();
$key1 = 'wmr';
$usermeta = get_user_meta( $user_idd, $key1, true );
if( empty( $usermeta ) ) {
$class = 'updated';
$message = 'Ваш WMR кошелек не задан! Задайте его <a href="http://root1.ru/wp-admin/profile.php#wmr">здесь</a>';
echo '<div style="position: relative;" class="' . $class . '">
<p>' . $message . '</p>
<button type="button" class="notice-dismiss wmr">
<span class="screen-reader-text">Скрыть это уведомление.</span>
</button>
</div>';
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question