v1.7 — 登录态 + 评论优化
- 隐藏 WP admin bar - 导航栏右侧登录用户头像+姓名下拉菜单 - 笺文评论:只显示输入框+按钮,未登录点提交提示登录 - 评论无需审核直接显示
This commit is contained in:
+33
-10
@@ -40,16 +40,39 @@ if (post_password_required()) return;
|
|||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
comment_form(array(
|
if (is_user_logged_in()) :
|
||||||
'title_reply' => '笺下留言',
|
// 登录后:只显示留言框 + 按钮,隐藏 "Logged in as XXX"
|
||||||
'title_reply_before' => '<h3 class="comment-reply-title">',
|
comment_form(array(
|
||||||
'title_reply_after' => '</h3>',
|
'title_reply' => '笺下留言',
|
||||||
'comment_notes_before' => '',
|
'title_reply_before' => '<h3 class="comment-reply-title">',
|
||||||
'comment_field' => '<textarea id="comment" name="comment" rows="4" placeholder="写点什么..." required></textarea>',
|
'title_reply_after' => '</h3>',
|
||||||
'submit_button' => '<button type="submit" class="submit">落笔留痕</button>',
|
'comment_notes_before' => '',
|
||||||
'submit_field' => '<div class="form-submit">%1$s %2$s</div>',
|
'comment_notes_after' => '',
|
||||||
'label_submit' => '落笔留痕',
|
'logged_in_as' => '',
|
||||||
));
|
'fields' => array(),
|
||||||
|
'comment_field' => '<textarea id="comment" name="comment" rows="4" placeholder="写点什么..." required></textarea>',
|
||||||
|
'submit_button' => '<button type="submit" class="submit">落笔留痕</button>',
|
||||||
|
'submit_field' => '<div class="form-submit">%1$s %2$s</div>',
|
||||||
|
'label_submit' => '落笔留痕',
|
||||||
|
));
|
||||||
|
else :
|
||||||
|
// 未登录:只显示输入框 + 按钮,提交时提示登录
|
||||||
?>
|
?>
|
||||||
|
<h3 class="comment-reply-title">笺下留言</h3>
|
||||||
|
<form id="commentform-guest" class="comment-form" novalidate>
|
||||||
|
<textarea id="comment" name="comment" rows="4" placeholder="写点什么..." required></textarea>
|
||||||
|
<div class="form-submit">
|
||||||
|
<button type="submit" class="submit">落笔留痕</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
<script>
|
||||||
|
document.getElementById('commentform-guest').addEventListener('submit', function(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
if (confirm('请先登录')) {
|
||||||
|
window.location.href = '/wp-login.php';
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -122,6 +122,9 @@ remove_action('admin_print_styles', 'print_emoji_styles');
|
|||||||
|
|
||||||
add_filter('emoji_svg_url', '__return_false');
|
add_filter('emoji_svg_url', '__return_false');
|
||||||
|
|
||||||
|
// 隐藏顶部 admin bar
|
||||||
|
add_filter('show_admin_bar', '__return_false');
|
||||||
|
|
||||||
// 评论表单中文化
|
// 评论表单中文化
|
||||||
add_filter('comment_form_default_fields', function($fields) {
|
add_filter('comment_form_default_fields', function($fields) {
|
||||||
$fields['author'] = '<p class="comment-form-author"><label for="author">显示名称</label><input id="author" name="author" type="text" size="30" /></p>';
|
$fields['author'] = '<p class="comment-form-author"><label for="author">显示名称</label><input id="author" name="author" type="text" size="30" /></p>';
|
||||||
@@ -131,6 +134,9 @@ add_filter('comment_form_default_fields', function($fields) {
|
|||||||
return $fields;
|
return $fields;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 评论无需审核直接发布
|
||||||
|
add_filter('pre_comment_approved', function() { return 1; });
|
||||||
|
|
||||||
add_action('template_include', function($template) {
|
add_action('template_include', function($template) {
|
||||||
if (get_query_var('post_type') === 'post' && !is_home() && !is_singular()) {
|
if (get_query_var('post_type') === 'post' && !is_home() && !is_singular()) {
|
||||||
$t = locate_template('archive.php');
|
$t = locate_template('archive.php');
|
||||||
|
|||||||
+51
-18
@@ -15,24 +15,57 @@
|
|||||||
<a href="/" class="logo-area">
|
<a href="/" class="logo-area">
|
||||||
<span class="logo"><?php bloginfo('name'); ?></span>
|
<span class="logo"><?php bloginfo('name'); ?></span>
|
||||||
</a>
|
</a>
|
||||||
<nav>
|
<div class="top-bar-right">
|
||||||
<?php
|
<nav>
|
||||||
if (has_nav_menu('primary')) {
|
<?php
|
||||||
wp_nav_menu(array(
|
if (has_nav_menu('primary')) {
|
||||||
'theme_location' => 'primary',
|
wp_nav_menu(array(
|
||||||
'container' => false,
|
'theme_location' => 'primary',
|
||||||
'menu_class' => 'nav-links',
|
'container' => false,
|
||||||
'depth' => 1,
|
'menu_class' => 'nav-links',
|
||||||
));
|
'depth' => 1,
|
||||||
} else {
|
));
|
||||||
echo '<ul class="nav-links">';
|
} else {
|
||||||
echo '<li><a href="/">首页</a></li>';
|
echo '<ul class="nav-links">';
|
||||||
echo '<li><a href="/articles/">笺文</a></li>';
|
echo '<li><a href="/">首页</a></li>';
|
||||||
echo '<li><a href="/tucao/">微言</a></li>';
|
echo '<li><a href="/articles/">笺文</a></li>';
|
||||||
echo '<li><a href="/photos/">拾影</a></li>';
|
echo '<li><a href="/tucao/">微言</a></li>';
|
||||||
echo '</ul>';
|
echo '<li><a href="/photos/">拾影</a></li>';
|
||||||
}
|
echo '</ul>';
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</nav>
|
||||||
|
<?php if (is_user_logged_in()) :
|
||||||
|
$current_user = wp_get_current_user();
|
||||||
?>
|
?>
|
||||||
</nav>
|
<div class="user-menu">
|
||||||
|
<button class="user-menu-trigger" type="button" aria-haspopup="true">
|
||||||
|
<?php echo get_avatar($current_user->ID, 28); ?>
|
||||||
|
<span class="user-menu-name"><?php echo esc_html($current_user->display_name); ?></span>
|
||||||
|
<span class="user-menu-arrow">▾</span>
|
||||||
|
</button>
|
||||||
|
<div class="user-menu-dropdown">
|
||||||
|
<a href="/author/<?php echo esc_attr($current_user->user_nicename); ?>/" rel="nofollow">个人资料</a>
|
||||||
|
<a href="/wp-admin/" rel="nofollow">系统后台</a>
|
||||||
|
<a href="/wp-login.php?action=logout" rel="nofollow">退出</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php endif; ?>
|
||||||
|
</div>
|
||||||
</header>
|
</header>
|
||||||
|
<script>
|
||||||
|
(function(){
|
||||||
|
var trigger = document.querySelector('.user-menu-trigger');
|
||||||
|
var menu = document.querySelector('.user-menu');
|
||||||
|
if (trigger && menu) {
|
||||||
|
trigger.addEventListener('click', function(e) {
|
||||||
|
e.stopPropagation();
|
||||||
|
menu.classList.toggle('open');
|
||||||
|
});
|
||||||
|
document.addEventListener('click', function() {
|
||||||
|
menu.classList.remove('open');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
</script>
|
||||||
<div class="main-content">
|
<div class="main-content">
|
||||||
|
|||||||
Reference in New Issue
Block a user