前言
看到了狐狸资源网的大佬的帖子,后续自己写了一下其他的隐私功能,功能有 收藏文章隐私 – 评论隐私(原文帖子) – 用户粉丝隐私,代码里面都给各位注释了,其他的如有运行报错或写法错误的话请谅解给我讲解下感谢,话不多说代码在下面。
原文
教程
首先把下面代码添加到子比主题文件里
按顺序[ /inc/functions/zib-author.php ] 找到 zib-author.php 该文件
打开文件后 Ctral + F 搜索源代码的 //XXX-XXX 后面的-源代码不需要
然后整体替换或者备份一下在替换下面的修改代码就可以的。
源代码
//作者页面-评论tab
//作者页面-评论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;
//--开头替换--
return zib_get_author_comment($author_id);
//--结尾替换--
}
//作者页面->关注|粉丝
//作者页面->关注|粉丝 源代码
function zib_main_author_tab_content_follow()
{
global $wp_query;
$curauth = $wp_query->get_queried_object();
if (empty($curauth->ID)) {
return;
}
//--源代码开头结尾--
$author_id = $curauth->ID;
//--开头替换--
return zib_get_follow_user_list($author_id);
//--结尾替换--
}
//作者页面->favorite收藏的文章
//作者页面->favorite收藏的文章 - 源代码
function zib_main_author_tab_content_favorite()
{
global $wp_query;
$curauth = $wp_query->get_queried_object();
if (empty($curauth->ID)) {
return;
}
//--源代码开头结尾--
$author_id = $curauth->ID;
//--开头替换--
$paged = isset($_GET['favorite_paged']) ? $_GET['favorite_paged'] : 1;
$orderby = !empty($_REQUEST['orderby']) ? $_REQUEST['orderby'] : 'post__in';
return zib_get_favorite_posts_lists($author_id, $paged, $orderby);
//--结尾替换--
}
修改代码
//作者页面-评论tab
//作者页面-评论tab - 修改(狐狸资源网:www.foxccs.com 作者:三夏)
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.webp');//子比目录下img添加你自己的null.webp图标
return $header . $message;
}
$comments_content = zib_get_author_comment($author_id);
//--结尾替换--
return $header . $comments_content;
}
//作者页面->关注|粉丝
//作者页面->关注|粉丝 - 修改(咸鱼绅士:xyss.asia 作者:时即)
function zib_main_author_tab_content_follow()
{
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['follow_visibility'])) {
$new_visibility = sanitize_text_field($_POST['follow_visibility']);
update_user_meta($author_id, 'follow_visibility', $new_visibility);
$follow_visibility = $new_visibility;
} else {
$follow_visibility = get_user_meta($author_id, 'follow_visibility', true);
if (!$follow_visibility) {
$follow_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 = ($follow_visibility == $value) ? ' class="active"' : '';
$visibility_dropdown_but .= '<li' . $active_class . '><a href="javascript:;" onclick="document.getElementById(\'follow_visibility_form\').follow_visibility.value=\'' . $value . '\'; document.getElementById(\'follow_visibility_form\').submit();">' . $label . '</a></li>';
}
$current_visibility_label = $visibility_options[$follow_visibility];
$visibility_html = '<form method="post" id="follow_visibility_form" class="follow-visibility-form">';
$visibility_html .= '<input type="hidden" name="follow_visibility" value="' . $follow_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 ($follow_visibility == 'self' && $current_user->ID != $author_id) {
$message = zib_get_ajax_null('无权限查看该用户粉丝列表', '0', 'null.webp');//子比目录下img添加你自己的null.webp图标
return $header . $message;
}
$follows_content = zib_get_follow_user_list($author_id);
//--结尾替换--
return $header . $follows_content;
}
//作者页面->favorite收藏的文章
//作者页面->favorite收藏的文章 - 修改(咸鱼绅士:xyss.asia 作者:时即)
function zib_main_author_tab_content_favorite()
{
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['favorite_visibility'])) {
$new_visibility = sanitize_text_field($_POST['favorite_visibility']);
update_user_meta($author_id, 'favorite_visibility', $new_visibility);
$favorite_visibility = $new_visibility;
} else {
$favorite_visibility = get_user_meta($author_id, 'favorite_visibility', true);
if (!$favorite_visibility) {
$favorite_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 = ($favorite_visibility == $value) ? ' class="active"' : '';
$visibility_dropdown_but .= '<li' . $active_class . '><a href="javascript:;" onclick="document.getElementById(\'favorite_visibility_form\').favorite_visibility.value=\'' . $value . '\'; document.getElementById(\'favorite_visibility_form\').submit();">' . $label . '</a></li>';
}
$current_visibility_label = $visibility_options[$favorite_visibility];
$visibility_html = '<form method="post" id="favorite_visibility_form" class="favorite-visibility-form">';
$visibility_html .= '<input type="hidden" name="favorite_visibility" value="' . $favorite_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 ($favorite_visibility == 'self' && $current_user->ID != $author_id) {
$message = zib_get_ajax_null('无权限查看该用户文章收藏列表', '0', 'null.webp');//子比目录下img添加你自己的null.webp图标
return $header . $message;
}
$favorites_content = zib_get_favorite_posts_lists($author_id, $paged, $orderby);
//--结尾替换--
return $header . $favorites_content;
}
效果图
© 版权声明
THE END
暂无评论内容