我尝试在所有用户配置文件页面(…/wp admin/profile.php)上显示一段文本(没有插件),例如“每日报价:一些文本”。
此文本应可从管理员配置文件管理/编辑。在管理员配置文件页面中应该有一个文本输入字段,我可以在其中更改文本并保存。
从昨天起,我就找不到任何实现这一目标的线索。我找到了很多教程来为配置文件页面创建自定义用户字段,但没有我需要的。
到目前为止,我能够创建一个文本输入字段,在该字段中,我可以将文本(输入)保存在数据库中,并仅在admins profile页面中显示,其中包括:
function add_qoute_of_the_day_backend( $user ) {
// Visible only for admins
if( current_user_can( \'administrator\' ) ) {
?>
<div class="visible-only-for-admin">
<h3>Quote of the Day Input Field</h3>
<table class="form-table" >
<tr>
<th><label for="qoute_of_the_day">Qoute of the Day</label></th>
<td><input type="text" name="qoute_of_the_day" value="<?php echo esc_attr(get_the_author_meta( \'qoute_of_the_day\', $user->ID )); ?>" class="regular-text" /></td>
</tr>
</table>
</div>
<?php } ?>
<?php }
add_action( \'show_user_profile\', \'add_qoute_of_the_day_backend\', 10 );
add_action( \'edit_user_profile\', \'add_qoute_of_the_day_backend\', 10 );
function save_qoute_of_the_day_backend( $user_id ) {
if ( !current_user_can( \'edit_user\', $user_id ) )
return false;
update_user_meta( $user_id,\'qoute_of_the_day\', sanitize_text_field ( $_POST[\'qoute_of_the_day\'] ) );
}
add_action( \'personal_options_update\', \'save_qoute_of_the_day_backend\' );
add_action( \'edit_user_profile_update\', \'save_qoute_of_the_day_backend\' );
上面的代码可以工作,但我如何在所有其他用户配置文件中以文本形式显示管理员的输入?是否有任何方法可以只为管理员角色创建一个简单的输入字段,并在所有配置文件中显示输入?Visual - what im trying to achive:
管理员配置文件页面中的输入字段:在所有其他用户配置文件中显示文本:Any help would be greatly appreciated