Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/294.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php WordPress配置文件中的文本区域在更新后不显示_Php_Wordpress - Fatal编程技术网

Php WordPress配置文件中的文本区域在更新后不显示

Php WordPress配置文件中的文本区域在更新后不显示,php,wordpress,Php,Wordpress,我在WordPress配置文件中添加了一个额外的文本区域,问题是一旦保存它就不会显示。我已经看到了很多关于它的帖子,甚至把它复制粘贴到我的函数中,没有了,这里有我遗漏的东西吗 旧代码: add_action( 'show_user_profile', 'xtra_field' ); add_action( 'edit_user_profile', 'xtra_field' ); function xtra_field( $user ) { ?> <

我在WordPress配置文件中添加了一个额外的文本区域,问题是一旦保存它就不会显示。我已经看到了很多关于它的帖子,甚至把它复制粘贴到我的函数中,没有了,这里有我遗漏的东西吗

旧代码:

    add_action( 'show_user_profile', 'xtra_field' );
    add_action( 'edit_user_profile', 'xtra_field' );

    function xtra_field( $user ) { ?>

    <h3>Teacher Information</h3>

    <table class="form-table">
        <tr>
            <th><label for="teach_year">Year</label></th>
            <td>
                <input type="number" name="teach_year" id="teach_year" min="1" max="7" value="<?php echo esc_attr( get_the_author_meta( 'teach_year', $user->ID ) ); ?>" class="regular-text" /><br />
                <span style="line-height: 42px;" class="description">What year do you teach?</span>
            </td>
        </tr>

        <tr>
            <th><label for="class_intro">Class Introduction</label></th>
            <td>
                <textarea type="text" name="class_intro" id="class_intro" rows="5" cols="30" class="regular-text" value="<?php echo esc_attr( get_the_author_meta( 'class_intro', $user->ID ) ); ?>"></textarea><br/>
                <span class="description">Introduce your class.</span>
            </td>
        </tr>
    </table>

    <?php }

    add_action( 'personal_options_update', 'xtra_save_field' );
    add_action( 'edit_user_profile_update', 'xtra_save_field' );

    function xtra_save_field( $user_id ) {
        if ( !current_user_can( 'edit_user', $user_id ))
            return false;
        update_user_meta($user_id, 'teach_year', $_POST['teach_year']);
        update_user_meta($user_id, 'class_intro', $_POST['class_intro']);
    }
add_action( 'show_user_profile', 'xtra_field' );
add_action( 'edit_user_profile', 'xtra_field' );

function xtra_field( $user ) { ?>

<h3>Teacher Information</h3>

<table class="form-table">
    <tr>
        <th><label for="teach_year">Year</label></th>
        <td>
            <input type="number" name="teach_year" id="teach_year" min="1" max="7" value="<?php echo esc_attr(get_the_author_meta('teach_year', $user->ID)); ?>" class="regular-text" /><br />
            <span style="line-height: 42px;" class="description">What year do you teach?</span>
        </td>
    </tr>
    <tr>
        <th><label for="class_intro">Class Introduction</label></th>
        <td>
            <textarea type="text" name="class_intro" id="class_intro" rows="5" cols="30" class="regular-text"><?php echo esc_html(get_the_author_meta('class_intro', $user->ID) ); ?></textarea>
            <br/>
            <span class="description">Provide your class with an introduction.</span>
        </td>
    </tr>
</table>

<?php }

add_action( 'personal_options_update', 'xtra_save_field' );
add_action( 'edit_user_profile_update', 'xtra_save_field' );

function xtra_save_field( $user_id ) {
    if ( !current_user_can( 'edit_user', $user_id ))
        return false;
    update_user_meta($user_id, 'teach_year', $_POST['teach_year']);
    update_user_meta($user_id, 'class_intro', $_POST['class_intro']);
}
add_操作('show_user_profile','xtra_field');
添加操作('edit_user_profile'、'xtra_field');
函数xtra_字段($user){?>
教师信息
年

Textarea没有
value=“…”
参数。相反,它在
之间保存它的内容(即它的“值”)


文档:

这正是我做错的地方,谢谢你的参考链接。