我试图添加额外的用户配置文件字段。之后,我想使用短代码显示这些额外字段。我在函数中添加了以下代码。添加额外字段并将其保存到数据库的php文件:
<!-- add extra fields to user profile -->
<?php
add_action( \'show_user_profile\', \'extra_user_profile_fields\' );
add_action( \'edit_user_profile\', \'extra_user_profile_fields\' );
function extra_user_profile_fields( $user ) { ?>
<h3><?php _e("Extra profile information", "blank"); ?></h3>
<table class="form-table">
<tr>
<th><label for="school-id"><?php _e("KlickSchool ID"); ?></label></th>
<td>
<input type="text" name="school-id" id="school-id" value="<?php echo esc_attr( get_the_author_meta( \'school-id\', $user->ID ) ); ?>" class="regular-text" /><br />
<span class="description"><?php _e("Bitte geben Sie die ID für die Niederlassung an"); ?></span>
</td>
</tr>
<tr>
<th><label for="city"><?php _e("Standort"); ?></label></th>
<td>
<input type="text" name="city" id="city" value="<?php echo esc_attr( get_the_author_meta( \'city\', $user->ID ) ); ?>" class="regular-text" /><br />
<span class="description"><?php _e("Bitte geben Sie den Standort der Niederlassung ein"); ?></span>
</td>
</tr>
</table>
<?php }
add_action( \'personal_options_update\', \'save_extra_user_profile_fields\' );
add_action( \'edit_user_profile_update\', \'save_extra_user_profile_fields\' );
function save_extra_user_profile_fields( $user_id ) {
if ( !current_user_can( \'edit_user\', $user_id ) ) { return false; }
update_user_meta( $user_id, \'school-id\', $_POST[\'school-id\'] );
update_user_meta( $user_id, \'city\', $_POST[\'city\'] );
}
?>
我试图用以下代码显示一个额外字段:
<?php
( \'adress-klickschool\', \'klickschool_adress\' );
function klickschool_adress() {
?>
<div class="flex_column av_one_half flex_column_div av-zero-column-padding avia-builder-el-2 el_after_av_one_half el_before_av_codeblock adress-column">
<?php
$current_user = wp_get_current_user();
/*
* @example Safe usage: $current_user = wp_get_current_user();
* if ( ! ( $current_user instanceof WP_User ) ) {
* return;
* }
*/
echo\'<div class="image-info-box">\',\'<img src="http://intranet.klickschool.de/wp-content/uploads/2019/11/logo-sh.svg">\', \'</div>\';?>
**<?php if ( get_the_author_meta( \'school-id\' ) ) { ?>
<p class="school-id">
<p><?php the_author_meta( \'school-id\' ); ?></p>
</p>
<?php } ?>**
<?php
echo \'<div class="info-box">\' . $current_user->description . \'<br />\', \'</div>\';
?>
</div>
<?php } ?>
标有两颗星的代码应显示额外添加的字段“学校id”。但代码不显示此字段。你有什么想法吗?