前言
子比主题用户中心的文章、评论、粉丝等默认全部人可见,但是有时不想让全部人可见就可以开启此功能
图片展示
教程开始
把以下代码添加到子比主题下,按顺序找到该文件/inc/functions/zib-author.php
,在zib-author.php
第374行把原代码删除掉粘贴下面代码。
//作者页面-评论tab
function zib_main_author_tab_content_comment()
{
global $wp_query;
$curauth = $wp_query->get_queried_object();
if (empty($curauth->ID)) {
return;
}
$author_id = $curauth->ID;
$current_user = wp_get_current_user();
$page = zib_get_the_paged();
if (isset($_POST['comment_visibility'])) {
$new_visibility = sanitize_text_field($_POST['comment_visibility']);
update_user_meta($author_id, 'comment_visibility', $new_visibility);
$comment_visibility = $new_visibility;
} else {
$comment_visibility = get_user_meta($author_id, 'comment_visibility', true);
if (!$comment_visibility) {
$comment_visibility = 'all';
}
}
$header = '';
$this_url = zib_get_current_url();
if (1 == $page || !_pz('paging_ajax_s', true)) {
$this_url = zib_url_del_paged($this_url);
$visibility_html = '';
if ($current_user->ID == $author_id) {
$visibility_options = array(
'all' => '全部人可见',
'self' => '仅自己可见',
);
$visibility_dropdown_but = '';
foreach ($visibility_options as $value => $label) {
$active_class = ($comment_visibility == $value) ? ' class="active"' : '';
$visibility_dropdown_but .= '<li' . $active_class . '><a href="javascript:;" onclick="document.getElementById(\'comment_visibility_form\').comment_visibility.value=\'' . $value . '\'; document.getElementById(\'comment_visibility_form\').submit();">' . $label . '</a></li>';
}
$current_visibility_label = $visibility_options[$comment_visibility];
$visibility_html = '<form method="post" id="comment_visibility_form" class="comment-visibility-form">';
$visibility_html .= '<input type="hidden" name="comment_visibility" value="' . $comment_visibility . '">';
$visibility_html .= '<div class="dropdown flex0 pull-right">';
$visibility_html .= '<a href="javascript:;" class="but" data-toggle="dropdown">可见性: ' . $current_visibility_label . '<i class="ml6 fa fa-caret-down opacity5" aria-hidden="true" style="margin-right:0;"></i></a>';
$visibility_html .= '<ul class="dropdown-menu">' . $visibility_dropdown_but . '</ul>';
$visibility_html .= '</div>';
$visibility_html .= '</form>';
}
$header = '<div class="ajax-item flex ac jsb mb10 px12-sm"><div class="scroll-x mini-scrollbar mr10"></div>' . $visibility_html . '</div>';
}
if ($comment_visibility == 'self' && $current_user->ID != $author_id) {
$message = zib_get_ajax_null('仅自己可见', '0', 'null-post.svg');
return $header . $message;
}
$comments_content = zib_get_author_comment($author_id);
return $header . $comments_content;
}
这里我只改了评论和粉丝页面的隐私,可以根据自己改别的页面