php - WordPress 评论中 undefined variable

标签 php wordpress

我正在整理我的自定义主题,在 Debug模式下,我在评论部分收到一个 undefined variable 。这是我的自定义评论部分,显示的 undefined variable 是 aria_reqreqcommenter。这个自定义评论函数位于我的函数文件中。我该如何解决这个问题?

// Edit Comment Forms
function alter_comment_form_fields($fields){

    $fields['author'] = '<div class="row"><div class="col-md-4"><p class="comment-form-author">' . '<label for="author">' . __( 'Name' ) . '</label> ' . ( $req ? '<span class="required">*</span>' : '' ) .
                    '<input id="author" name="author" type="text" placeholder="Name" value="' . esc_attr( $commenter['comment_author'] ) . '"' . $aria_req . ' /></p></div>';
//Edit Email Field
$fields['email'] = '<div class="col-md-4"><p class="comment-form-author">' . '<label for="email">' . __( 'Email' ) . '</label> ' .                  ( $req ? '<span class="required">*</span>' : '' ) .
                    '<input id="email" name="email" type="text" placeholder="Email" value="' . esc_attr( $commenter['comment_author_url'] ) . '" "' . $aria_req . ' /></p></div>';
//Edit Website Field
$fields['url'] = '<div class="col-md-4"><p class="comment-form-author">' . '<label for="url">' . __( 'Website' ) . '</label> ' .                        ( $req ? '<span class="required">*</span>' : '' ) .
                    '<input id="url" name="url" type="text" placeholder="Website" value="' . esc_attr( $commenter['comment_author_url'] ) . '"' . $aria_req . ' /></p></div></div>';               

    return $fields;
}

add_filter('comment_form_default_fields','alter_comment_form_fields');

最佳答案

您可以引用http://codex.wordpress.org/Function_Reference/comment_form
可以通过以下方式在代码上方(在函数体的开头)定义变量:

$commenter = wp_get_current_commenter();
$req = get_option( 'require_name_email' );
$aria_req = ( $req ? " aria-required='true'" : '' );

关于php - WordPress 评论中 undefined variable ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20751219/

相关文章:

php - 在我的 WordPress 网站上使用 CSS 的一点帮助!

php - 通过引用或作为函数返回返回大数据?

php - 基本的sql注入(inject)

php - 拉维尔 4 : Fatal error: Class 'Patchwork\Utf8\Bootup' not found in autoload. PHP

php - Wordpress - 检查帖子是否有更新

html - 为什么这个 jpg 图像没有出现在 IE 7 和 8 中

javascript - 在 Laravel 中使用 ajax FormData() 时无法获取输入字段的值

php - 使用 ImageMagick 从 SVG 转换为 PNG 时裁剪图像

mysql - 如何在重新启动之间在 Windows 10 上保留 MySQL 容器

ajax - 如何在没有 head 标签的情况下对加载 AJAX 的页面进行 noindex?