将此代码添加到functions.php
要为用户添加通知,请使用subscriber
在其配置文件和仪表板管理页面上的角色。
function wpse239290_user_welcome_notice() {
// Make sure that the user is assigned to the subscriber role, specifically.
// Alternatively, capabilities can be checked with current_user_can(), but roles are not supposed to be checked this way.
$user = wp_get_current_user();
if ( ! in_array( \'subscriber\', $user->roles ) ) {
return;
}
// Make sure the profile or dashboard screens are being viewed.
$screen = get_current_screen();
if ( ! $screen || ( \'profile\' !== $screen->id && \'dashboard\' !== $screen->id ) ) {
return;
}
// Show a friendly green notice, and allow it to be dismissed (it will re-appear if the page is reloaded though).
$class = \'notice notice-success is-dismissible\';
// Customize the HTML to fit your preferences.
$message = \'<p>Looking for the <a href="http://example.com/form">Example Form</a></p>\';
printf( \'<div class="%1$s"><div class="subscriberProfile">%2$s</div></div>\', $class, $message );
}
add_action( \'admin_notices\', \'wpse239290_user_welcome_notice\' );