mirror of
https://github.com/WenPai-org/bbpress-support-toolkit.git
synced 2025-08-18 13:11:08 +08:00
Add advanced and enhanced features to toolkit
Introduces advanced and enhanced features including admin notes, live preview, mark as read, canned replies, report content, and topic lock. Adds new CSS and JS assets for these features, updates plugin options and settings, and refactors the admin settings page to support new sections and options. Increments plugin version to 1.3.0.
This commit is contained in:
parent
b807cf08bd
commit
72f606cf07
11 changed files with 5107 additions and 1253 deletions
|
@ -1,9 +1,21 @@
|
|||
<?php
|
||||
|
||||
// Ensure WordPress is loaded and prevent direct access
|
||||
if (!defined("ABSPATH")) {
|
||||
exit();
|
||||
}
|
||||
|
||||
// bbPress activation check removed as requested
|
||||
|
||||
// Ensure we have WordPress admin functions available
|
||||
// This file should only be loaded when WordPress is fully initialized
|
||||
if (!function_exists('add_action') || !function_exists('wp_nonce_field') || !function_exists('esc_html_e')) {
|
||||
// WordPress is not fully loaded, exit gracefully
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
add_action("bbp_forum_metabox", "bbps_extend_forum_attributes_mb");
|
||||
|
||||
function bbps_extend_forum_attributes_mb($forum_id)
|
||||
|
@ -87,8 +99,12 @@ add_action("admin_init", "bbps_register_admin_settings");
|
|||
add_action("wp_ajax_bbps_save_settings", "bbps_ajax_save_settings");
|
||||
add_action("admin_enqueue_scripts", "bbps_enqueue_admin_scripts");
|
||||
|
||||
register_activation_hook(dirname(__FILE__) . '/../bbpress-support-toolkit.php', 'bbps_init_default_user_ranking');
|
||||
|
||||
function bbps_register_admin_settings()
|
||||
{
|
||||
bbps_init_default_user_ranking();
|
||||
|
||||
add_settings_section(
|
||||
"bbps-user-ranking",
|
||||
__("User Ranking", "bbpress-support-toolkit"),
|
||||
|
@ -386,6 +402,97 @@ function bbps_register_admin_settings()
|
|||
);
|
||||
register_setting("bbpress-support-toolkit", "bbps_enable_private_replies", "intval");
|
||||
|
||||
// Additional Features Section
|
||||
add_settings_section(
|
||||
"bbps-additional-features",
|
||||
__("Additional Features", "bbpress-support-toolkit"),
|
||||
"bbps_admin_setting_callback_additional_section",
|
||||
"bbpress-support-toolkit"
|
||||
);
|
||||
|
||||
add_settings_field(
|
||||
"bbps_disable_user_page",
|
||||
__("Disable User Pages", "bbpress-support-toolkit"),
|
||||
"bbps_admin_setting_callback_disable_user_page",
|
||||
"bbpress-support-toolkit",
|
||||
"bbps-additional-features"
|
||||
);
|
||||
register_setting("bbpress-support-toolkit", "bbps_disable_user_page", "intval");
|
||||
|
||||
add_settings_field(
|
||||
"bbps_remove_avatars",
|
||||
__("Remove User Avatars", "bbpress-support-toolkit"),
|
||||
"bbps_admin_setting_callback_remove_avatars",
|
||||
"bbpress-support-toolkit",
|
||||
"bbps-additional-features"
|
||||
);
|
||||
register_setting("bbpress-support-toolkit", "bbps_remove_avatars", "intval");
|
||||
|
||||
add_settings_field(
|
||||
"bbps_redirect_single_replies",
|
||||
__("Redirect Single Replies to Topics", "bbpress-support-toolkit"),
|
||||
"bbps_admin_setting_callback_redirect_single_replies",
|
||||
"bbpress-support-toolkit",
|
||||
"bbps-additional-features"
|
||||
);
|
||||
register_setting("bbpress-support-toolkit", "bbps_redirect_single_replies", "intval");
|
||||
|
||||
add_settings_field(
|
||||
"bbps_custom_notifications",
|
||||
__("Enable Custom Notifications", "bbpress-support-toolkit"),
|
||||
"bbps_admin_setting_callback_custom_notifications",
|
||||
"bbpress-support-toolkit",
|
||||
"bbps-additional-features"
|
||||
);
|
||||
register_setting("bbpress-support-toolkit", "bbps_custom_notifications", "intval");
|
||||
|
||||
// Custom Notification Settings (only show when custom notifications are enabled)
|
||||
if (get_option('bbps_custom_notifications')) {
|
||||
add_settings_section(
|
||||
"bbps-notification-settings",
|
||||
__("Notification Settings", "bbpress-support-toolkit"),
|
||||
"bbps_admin_setting_callback_notification_settings_section",
|
||||
"bbpress-support-toolkit"
|
||||
);
|
||||
|
||||
add_settings_field(
|
||||
"bbps_topic_notice_title",
|
||||
__("Topic Notification Subject", "bbpress-support-toolkit"),
|
||||
"bbps_admin_setting_callback_topic_notice_title",
|
||||
"bbpress-support-toolkit",
|
||||
"bbps-notification-settings"
|
||||
);
|
||||
register_setting("bbpress-support-toolkit", "bbps_topic_notice_title", "sanitize_text_field");
|
||||
|
||||
add_settings_field(
|
||||
"bbps_topic_notice_body",
|
||||
__("Topic Notification Body", "bbpress-support-toolkit"),
|
||||
"bbps_admin_setting_callback_topic_notice_body",
|
||||
"bbpress-support-toolkit",
|
||||
"bbps-notification-settings"
|
||||
);
|
||||
register_setting("bbpress-support-toolkit", "bbps_topic_notice_body", "sanitize_textarea_field");
|
||||
|
||||
add_settings_field(
|
||||
"bbps_reply_notice_title",
|
||||
__("Reply Notification Subject", "bbpress-support-toolkit"),
|
||||
"bbps_admin_setting_callback_reply_notice_title",
|
||||
"bbpress-support-toolkit",
|
||||
"bbps-notification-settings"
|
||||
);
|
||||
register_setting("bbpress-support-toolkit", "bbps_reply_notice_title", "sanitize_text_field");
|
||||
|
||||
add_settings_field(
|
||||
"bbps_reply_notice_body",
|
||||
__("Reply Notification Body", "bbpress-support-toolkit"),
|
||||
"bbps_admin_setting_callback_reply_notice_body",
|
||||
"bbpress-support-toolkit",
|
||||
"bbps-notification-settings"
|
||||
);
|
||||
register_setting("bbpress-support-toolkit", "bbps_reply_notice_body", "sanitize_textarea_field");
|
||||
}
|
||||
register_setting("bbpress-support-toolkit", "bbps_enable_private_replies", "intval");
|
||||
|
||||
add_settings_field(
|
||||
"bbps_private_replies_capability",
|
||||
__("Private Replies Capability", "bbpress-support-toolkit"),
|
||||
|
@ -543,11 +650,94 @@ function bbps_register_admin_settings()
|
|||
"bbps-forum-enhancements"
|
||||
);
|
||||
register_setting("bbpress-support-toolkit", "bbps_default_forum_id", "intval");
|
||||
|
||||
// Advanced Features Section
|
||||
add_settings_section(
|
||||
"bbps-advanced-features",
|
||||
__("Advanced Features", "bbpress-support-toolkit"),
|
||||
"bbps_admin_setting_callback_advanced_section",
|
||||
"bbpress-support-toolkit"
|
||||
);
|
||||
|
||||
// Admin Notes
|
||||
add_settings_field(
|
||||
"bbps_enable_admin_notes",
|
||||
__("Enable Admin Notes", "bbpress-support-toolkit"),
|
||||
"bbps_admin_setting_callback_admin_notes",
|
||||
"bbpress-support-toolkit",
|
||||
"bbps-advanced-features"
|
||||
);
|
||||
register_setting("bbpress-support-toolkit", "bbps_enable_admin_notes", "intval");
|
||||
|
||||
// Live Preview
|
||||
add_settings_field(
|
||||
"bbps_enable_live_preview",
|
||||
__("Enable Live Preview", "bbpress-support-toolkit"),
|
||||
"bbps_admin_setting_callback_live_preview",
|
||||
"bbpress-support-toolkit",
|
||||
"bbps-advanced-features"
|
||||
);
|
||||
register_setting("bbpress-support-toolkit", "bbps_enable_live_preview", "intval");
|
||||
|
||||
// Mark as Read
|
||||
add_settings_field(
|
||||
"bbps_enable_mark_as_read",
|
||||
__("Enable Mark as Read", "bbpress-support-toolkit"),
|
||||
"bbps_admin_setting_callback_mark_as_read",
|
||||
"bbpress-support-toolkit",
|
||||
"bbps-advanced-features"
|
||||
);
|
||||
register_setting("bbpress-support-toolkit", "bbps_enable_mark_as_read", "intval");
|
||||
|
||||
// Canned Replies
|
||||
add_settings_field(
|
||||
"bbps_enable_canned_replies",
|
||||
__("Enable Canned Replies", "bbpress-support-toolkit"),
|
||||
"bbps_admin_setting_callback_canned_replies",
|
||||
"bbpress-support-toolkit",
|
||||
"bbps-advanced-features"
|
||||
);
|
||||
register_setting("bbpress-support-toolkit", "bbps_enable_canned_replies", "intval");
|
||||
|
||||
// Report Content
|
||||
add_settings_field(
|
||||
"bbps_enable_report_content",
|
||||
__("Enable Report Content", "bbpress-support-toolkit"),
|
||||
"bbps_admin_setting_callback_report_content",
|
||||
"bbpress-support-toolkit",
|
||||
"bbps-advanced-features"
|
||||
);
|
||||
register_setting("bbpress-support-toolkit", "bbps_enable_report_content", "intval");
|
||||
|
||||
// Topic Lock
|
||||
add_settings_field(
|
||||
"bbps_enable_topic_lock",
|
||||
__("Enable Topic Lock", "bbpress-support-toolkit"),
|
||||
"bbps_admin_setting_callback_topic_lock",
|
||||
"bbpress-support-toolkit",
|
||||
"bbps-advanced-features"
|
||||
);
|
||||
register_setting("bbpress-support-toolkit", "bbps_enable_topic_lock", "intval");
|
||||
}
|
||||
|
||||
function bbps_admin_page()
|
||||
{
|
||||
$active_tab = isset($_GET['tab']) ? $_GET['tab'] : 'user-ranking';
|
||||
// 标签页映射:将旧标签页映射到新的分组
|
||||
$tab_mapping = array(
|
||||
'user-ranking' => 'basic-settings',
|
||||
'support-forum' => 'basic-settings',
|
||||
'topic-status' => 'topic-management',
|
||||
'topic-labels' => 'topic-management',
|
||||
'private-replies' => 'forum-features',
|
||||
'forum-enhancements' => 'forum-features',
|
||||
'search-settings' => 'search-seo',
|
||||
'seo-settings' => 'search-seo',
|
||||
'additional-features' => 'advanced-features',
|
||||
'advanced-features' => 'advanced-features'
|
||||
);
|
||||
|
||||
$requested_tab = isset($_GET['tab']) ? $_GET['tab'] : 'basic-settings';
|
||||
$active_tab = isset($tab_mapping[$requested_tab]) ? $tab_mapping[$requested_tab] : 'basic-settings';
|
||||
?>
|
||||
<div class="wrap">
|
||||
<h1><?php echo esc_html(get_admin_page_title()); ?>
|
||||
|
@ -578,29 +768,20 @@ function bbps_admin_page()
|
|||
<?php endif; ?>
|
||||
<div class="card">
|
||||
<div class="bbps-settings-tabs">
|
||||
<button type="button" class="bbps-tab <?php echo $active_tab == 'support-forum' ? 'active' : ''; ?>" data-tab="support-forum">
|
||||
<?php esc_html_e('Support Forum', 'bbpress-support-toolkit'); ?>
|
||||
<button type="button" class="bbps-tab <?php echo $active_tab == 'basic-settings' ? 'active' : ''; ?>" data-tab="basic-settings">
|
||||
<?php esc_html_e('Basic Settings', 'bbpress-support-toolkit'); ?>
|
||||
</button>
|
||||
<button type="button" class="bbps-tab <?php echo $active_tab == 'topic-status' ? 'active' : ''; ?>" data-tab="topic-status">
|
||||
<?php esc_html_e('Topic Status', 'bbpress-support-toolkit'); ?>
|
||||
<button type="button" class="bbps-tab <?php echo $active_tab == 'topic-management' ? 'active' : ''; ?>" data-tab="topic-management">
|
||||
<?php esc_html_e('Topic Management', 'bbpress-support-toolkit'); ?>
|
||||
</button>
|
||||
<button type="button" class="bbps-tab <?php echo $active_tab == 'topic-labels' ? 'active' : ''; ?>" data-tab="topic-labels">
|
||||
<?php esc_html_e('Topic Labels', 'bbpress-support-toolkit'); ?>
|
||||
<button type="button" class="bbps-tab <?php echo $active_tab == 'forum-features' ? 'active' : ''; ?>" data-tab="forum-features">
|
||||
<?php esc_html_e('Forum Features', 'bbpress-support-toolkit'); ?>
|
||||
</button>
|
||||
<button type="button" class="bbps-tab <?php echo $active_tab == 'seo-settings' ? 'active' : ''; ?>" data-tab="seo-settings">
|
||||
<?php esc_html_e('SEO Settings', 'bbpress-support-toolkit'); ?>
|
||||
<button type="button" class="bbps-tab <?php echo $active_tab == 'search-seo' ? 'active' : ''; ?>" data-tab="search-seo">
|
||||
<?php esc_html_e('Search & SEO', 'bbpress-support-toolkit'); ?>
|
||||
</button>
|
||||
<button type="button" class="bbps-tab <?php echo $active_tab == 'search-settings' ? 'active' : ''; ?>" data-tab="search-settings">
|
||||
<?php esc_html_e('Search Settings', 'bbpress-support-toolkit'); ?>
|
||||
</button>
|
||||
<button type="button" class="bbps-tab <?php echo $active_tab == 'private-replies' ? 'active' : ''; ?>" data-tab="private-replies">
|
||||
<?php esc_html_e('Private Replies', 'bbpress-support-toolkit'); ?>
|
||||
</button>
|
||||
<button type="button" class="bbps-tab <?php echo $active_tab == 'user-ranking' ? 'active' : ''; ?>" data-tab="user-ranking">
|
||||
<?php esc_html_e('User Ranking', 'bbpress-support-toolkit'); ?>
|
||||
</button>
|
||||
<button type="button" class="bbps-tab <?php echo $active_tab == 'forum-enhancements' ? 'active' : ''; ?>" data-tab="forum-enhancements">
|
||||
<?php esc_html_e('Forum Enhancements', 'bbpress-support-toolkit'); ?>
|
||||
<button type="button" class="bbps-tab <?php echo $active_tab == 'advanced-features' ? 'active' : ''; ?>" data-tab="advanced-features">
|
||||
<?php esc_html_e('Advanced Features', 'bbpress-support-toolkit'); ?>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
|
@ -608,36 +789,36 @@ function bbps_admin_page()
|
|||
<form action="options.php" method="post">
|
||||
<?php settings_fields("bbpress-support-toolkit"); ?>
|
||||
|
||||
<div id="bbps-support-forum-section" class="bbps-section" data-section="support-forum" style="<?php echo $active_tab === 'support-forum' ? '' : 'display: none;'; ?>">
|
||||
<!-- 基础设置:用户排名 + 支持论坛 -->
|
||||
<div id="bbps-basic-settings-section" class="bbps-section" data-section="basic-settings" style="<?php echo $active_tab === 'basic-settings' ? '' : 'display: none;'; ?>">
|
||||
<?php do_settings_sections_for_tab("bbpress-support-toolkit", "bbps-user-ranking"); ?>
|
||||
<?php do_settings_sections_for_tab("bbpress-support-toolkit", "bbps-support-forum"); ?>
|
||||
</div>
|
||||
|
||||
<div id="bbps-topic-status-section" class="bbps-section" data-section="topic-status" style="<?php echo $active_tab === 'topic-status' ? '' : 'display: none;'; ?>">
|
||||
<?php do_settings_sections_for_tab("bbpress-support-toolkit", "bbps-topic-status"); ?>
|
||||
</div>
|
||||
|
||||
<div id="bbps-topic-labels-section" class="bbps-section" data-section="topic-labels" style="<?php echo $active_tab === 'topic-labels' ? '' : 'display: none;'; ?>">
|
||||
<?php do_settings_sections_for_tab("bbpress-support-toolkit", "bbps-topic-labels"); ?>
|
||||
</div>
|
||||
|
||||
<div id="bbps-seo-settings-section" class="bbps-section" data-section="seo-settings" style="<?php echo $active_tab === 'seo-settings' ? '' : 'display: none;'; ?>">
|
||||
<?php do_settings_sections_for_tab("bbpress-support-toolkit", "bbps-seo-settings"); ?>
|
||||
</div>
|
||||
|
||||
<div id="bbps-search-settings-section" class="bbps-section" data-section="search-settings" style="<?php echo $active_tab === 'search-settings' ? '' : 'display: none;'; ?>">
|
||||
<?php do_settings_sections_for_tab("bbpress-support-toolkit", "bbps-search-settings"); ?>
|
||||
</div>
|
||||
|
||||
<div id="bbps-private-replies-section" class="bbps-section" data-section="private-replies" style="<?php echo $active_tab === 'private-replies' ? '' : 'display: none;'; ?>">
|
||||
<!-- 主题管理:主题状态 + 主题标签 + 私密回复 -->
|
||||
<div id="bbps-topic-management-section" class="bbps-section" data-section="topic-management" style="<?php echo $active_tab === 'topic-management' ? '' : 'display: none;'; ?>">
|
||||
<?php do_settings_sections_for_tab("bbpress-support-toolkit", "bbps-topic-status"); ?>
|
||||
<?php do_settings_sections_for_tab("bbpress-support-toolkit", "bbps-topic-labels"); ?>
|
||||
<?php do_settings_sections_for_tab("bbpress-support-toolkit", "bbps-private-replies"); ?>
|
||||
</div>
|
||||
|
||||
<div id="bbps-user-ranking-section" class="bbps-section" data-section="user-ranking" style="<?php echo $active_tab === 'user-ranking' ? '' : 'display: none;'; ?>">
|
||||
<?php do_settings_sections_for_tab("bbpress-support-toolkit", "bbps-user-ranking"); ?>
|
||||
</div>
|
||||
|
||||
<div id="bbps-forum-enhancements-section" class="bbps-section" data-section="forum-enhancements" style="<?php echo $active_tab === 'forum-enhancements' ? '' : 'display: none;'; ?>">
|
||||
|
||||
<!-- 功能增强:论坛增强 + 附加功能 -->
|
||||
<div id="bbps-forum-features-section" class="bbps-section" data-section="forum-features" style="<?php echo $active_tab === 'forum-features' ? '' : 'display: none;'; ?>">
|
||||
<?php do_settings_sections_for_tab("bbpress-support-toolkit", "bbps-forum-enhancements"); ?>
|
||||
<?php do_settings_sections_for_tab("bbpress-support-toolkit", "bbps-additional-features"); ?>
|
||||
<?php if (get_option('bbps_custom_notifications')) : ?>
|
||||
<?php do_settings_sections_for_tab("bbpress-support-toolkit", "bbps-notification-settings"); ?>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
<!-- 搜索与SEO:搜索设置 + SEO设置 -->
|
||||
<div id="bbps-search-seo-section" class="bbps-section" data-section="search-seo" style="<?php echo $active_tab === 'search-seo' ? '' : 'display: none;'; ?>">
|
||||
<?php do_settings_sections_for_tab("bbpress-support-toolkit", "bbps-search-settings"); ?>
|
||||
<?php do_settings_sections_for_tab("bbpress-support-toolkit", "bbps-seo-settings"); ?>
|
||||
</div>
|
||||
|
||||
<div id="bbps-advanced-features-section" class="bbps-section" data-section="advanced-features" style="<?php echo $active_tab === 'advanced-features' ? '' : 'display: none;'; ?>">
|
||||
<?php do_settings_sections_for_tab("bbpress-support-toolkit", "bbps-advanced-features"); ?>
|
||||
</div>
|
||||
|
||||
<div id="bbps-save-status" class="notice" style="display: none; margin-top: 10px;"></div>
|
||||
|
@ -653,6 +834,12 @@ function bbps_admin_page()
|
|||
jQuery(document).ready(function($) {
|
||||
var currentTab = '<?php echo esc_js($active_tab); ?>';
|
||||
|
||||
// 如果当前标签页不在新的标签页列表中,设置为默认标签页
|
||||
var validTabs = ['basic-settings', 'topic-management', 'forum-features', 'search-seo', 'advanced-features'];
|
||||
if (validTabs.indexOf(currentTab) === -1) {
|
||||
currentTab = 'basic-settings';
|
||||
}
|
||||
|
||||
$('.bbps-tab').on('click', function() {
|
||||
$('.bbps-tab').removeClass('active');
|
||||
$(this).addClass('active');
|
||||
|
@ -911,6 +1098,11 @@ function bbps_validate_options($input)
|
|||
$options = [];
|
||||
}
|
||||
|
||||
// 如果选项为空,设置默认参数
|
||||
if (empty($options)) {
|
||||
$options = bbps_get_default_user_ranking_options();
|
||||
}
|
||||
|
||||
if (is_array($input)) {
|
||||
$i = 1;
|
||||
foreach ($input as $array) {
|
||||
|
@ -930,6 +1122,54 @@ function bbps_validate_options($input)
|
|||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化用户等级默认参数
|
||||
*/
|
||||
function bbps_init_default_user_ranking()
|
||||
{
|
||||
$existing_options = get_option('bbps_reply_count', []);
|
||||
|
||||
// 如果选项不存在或为空,设置默认值
|
||||
if (empty($existing_options)) {
|
||||
$default_options = bbps_get_default_user_ranking_options();
|
||||
update_option('bbps_reply_count', $default_options);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户等级的默认参数
|
||||
*/
|
||||
function bbps_get_default_user_ranking_options()
|
||||
{
|
||||
return [
|
||||
1 => [
|
||||
'title' => __('新手', 'bbpress-support-toolkit'),
|
||||
'start' => '1',
|
||||
'end' => '10'
|
||||
],
|
||||
2 => [
|
||||
'title' => __('活跃用户', 'bbpress-support-toolkit'),
|
||||
'start' => '11',
|
||||
'end' => '50'
|
||||
],
|
||||
3 => [
|
||||
'title' => __('资深用户', 'bbpress-support-toolkit'),
|
||||
'start' => '51',
|
||||
'end' => '100'
|
||||
],
|
||||
4 => [
|
||||
'title' => __('专家用户', 'bbpress-support-toolkit'),
|
||||
'start' => '101',
|
||||
'end' => '200'
|
||||
],
|
||||
5 => [
|
||||
'title' => __('论坛大师', 'bbpress-support-toolkit'),
|
||||
'start' => '201',
|
||||
'end' => '999999'
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
function bbps_admin_setting_callback_ranking_section()
|
||||
{
|
||||
?>
|
||||
|
@ -1726,19 +1966,95 @@ function bbps_bulk_action_admin_notice()
|
|||
if (!empty($_REQUEST["bbps_bulk_updated"])) {
|
||||
$count = intval($_REQUEST["bbps_bulk_updated"]);
|
||||
printf(
|
||||
'<div id="message" class="updated fade"><p>' .
|
||||
_n(
|
||||
"Updated %s topic.",
|
||||
"Updated %s topics.",
|
||||
$count,
|
||||
"bbpress-support-toolkit"
|
||||
) .
|
||||
"</p></div>",
|
||||
'<div id="message" class="updated notice is-dismissible"><p>' .
|
||||
_n(
|
||||
"Updated %s topic.",
|
||||
"Updated %s topics.",
|
||||
$count,
|
||||
"bbpress-support-toolkit"
|
||||
) .
|
||||
"</p></div>",
|
||||
$count
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Additional Features Callback Functions
|
||||
function bbps_admin_setting_callback_additional_section()
|
||||
{
|
||||
echo '<p>' . __("Additional features to enhance your bbPress forums.", "bbpress-support-toolkit") . '</p>';
|
||||
}
|
||||
|
||||
function bbps_admin_setting_callback_disable_user_page()
|
||||
{
|
||||
$option = get_option("bbps_disable_user_page", 0);
|
||||
echo '<input type="checkbox" name="bbps_disable_user_page" value="1" ' . checked(1, $option, false) . ' />';
|
||||
echo '<label for="bbps_disable_user_page">' . __("Disable bbPress user profile pages", "bbpress-support-toolkit") . '</label>';
|
||||
echo '<p class="description">' . __("This will disable the bbPress user profile pages to prevent spam.", "bbpress-support-toolkit") . '</p>';
|
||||
}
|
||||
|
||||
function bbps_admin_setting_callback_remove_avatars()
|
||||
{
|
||||
$option = get_option("bbps_remove_avatars", 0);
|
||||
echo '<input type="checkbox" name="bbps_remove_avatars" value="1" ' . checked(1, $option, false) . ' />';
|
||||
echo '<label for="bbps_remove_avatars">' . __("Remove user avatars from bbPress", "bbpress-support-toolkit") . '</label>';
|
||||
echo '<p class="description">' . __("This will remove avatars from topics, replies, and user profiles.", "bbpress-support-toolkit") . '</p>';
|
||||
}
|
||||
|
||||
function bbps_admin_setting_callback_redirect_single_replies()
|
||||
{
|
||||
$option = get_option("bbps_redirect_single_replies", 0);
|
||||
echo '<input type="checkbox" name="bbps_redirect_single_replies" value="1" ' . checked(1, $option, false) . ' />';
|
||||
echo '<label for="bbps_redirect_single_replies">' . __("Redirect single reply pages to parent topics", "bbpress-support-toolkit") . '</label>';
|
||||
echo '<p class="description">' . __("This will redirect users from single reply pages to the parent topic page.", "bbpress-support-toolkit") . '</p>';
|
||||
}
|
||||
|
||||
function bbps_admin_setting_callback_custom_notifications()
|
||||
{
|
||||
$option = get_option("bbps_custom_notifications", 0);
|
||||
echo '<input type="checkbox" name="bbps_custom_notifications" value="1" ' . checked(1, $option, false) . ' />';
|
||||
echo '<label for="bbps_custom_notifications">' . __("Enable custom email notifications", "bbpress-support-toolkit") . '</label>';
|
||||
echo '<p class="description">' . __("This will allow you to customize the email notifications sent to forum subscribers.", "bbpress-support-toolkit") . '</p>';
|
||||
}
|
||||
|
||||
// Notification Settings Callback Functions
|
||||
function bbps_admin_setting_callback_notification_settings_section()
|
||||
{
|
||||
echo '<p>' . __("Customize the email notifications sent to forum and topic subscribers.", "bbpress-support-toolkit") . '</p>';
|
||||
}
|
||||
|
||||
function bbps_admin_setting_callback_topic_notice_title()
|
||||
{
|
||||
$default_title = '[' . get_option('blogname') . '] {title}';
|
||||
$value = get_option('bbps_topic_notice_title', $default_title);
|
||||
echo '<input name="bbps_topic_notice_title" type="text" id="bbps_topic_notice_title" value="' . esc_attr($value) . '" class="regular-text" />';
|
||||
echo '<p class="description">' . __("The subject of the topic notification email. Use {title} for the topic title.", "bbpress-support-toolkit") . '</p>';
|
||||
}
|
||||
|
||||
function bbps_admin_setting_callback_topic_notice_body()
|
||||
{
|
||||
$default = '{author} wrote:\n\n{content}\n\nPost Link: {url}\n\n-----------\n\nYou are receiving this email because you subscribed to the {forum_name} forum.\n\nLogin and visit the forum to unsubscribe from these emails.';
|
||||
$value = get_option('bbps_topic_notice_body', $default);
|
||||
echo '<textarea name="bbps_topic_notice_body" class="large-text" rows="15" id="bbps_topic_notice_body">' . esc_textarea($value) . '</textarea>';
|
||||
echo '<p class="description">' . __("Email message sent to forum subscribers when a new topic is posted. Available tokens: {author}, {content}, {url}, {forum_name}", "bbpress-support-toolkit") . '</p>';
|
||||
}
|
||||
|
||||
function bbps_admin_setting_callback_reply_notice_title()
|
||||
{
|
||||
$default_title = '[' . get_option('blogname') . '] {title}';
|
||||
$value = get_option('bbps_reply_notice_title', $default_title);
|
||||
echo '<input name="bbps_reply_notice_title" type="text" id="bbps_reply_notice_title" value="' . esc_attr($value) . '" class="regular-text" />';
|
||||
echo '<p class="description">' . __("The subject of the reply notification email. Use {title} for the topic title.", "bbpress-support-toolkit") . '</p>';
|
||||
}
|
||||
|
||||
function bbps_admin_setting_callback_reply_notice_body()
|
||||
{
|
||||
$default = '{author} wrote:\n\n{content}\n\nPost Link: {url}\n\n-----------\n\nYou are receiving this email because you subscribed to a forum topic.\n\nLogin and visit the topic to unsubscribe from these emails.';
|
||||
$value = get_option('bbps_reply_notice_body', $default);
|
||||
echo '<textarea name="bbps_reply_notice_body" class="large-text" rows="15" id="bbps_reply_notice_body">' . esc_textarea($value) . '</textarea>';
|
||||
echo '<p class="description">' . __("Email message sent to topic subscribers when a new reply is posted. Available tokens: {author}, {content}, {url}", "bbpress-support-toolkit") . '</p>';
|
||||
}
|
||||
|
||||
// Ajax处理函数
|
||||
function bbps_ajax_save_settings() {
|
||||
// 验证nonce
|
||||
|
@ -1779,13 +2095,18 @@ function bbps_ajax_save_settings() {
|
|||
}
|
||||
|
||||
foreach ($settings_to_save as $setting_name) {
|
||||
$value = isset($parsed_data[$setting_name]) ? $parsed_data[$setting_name] : '';
|
||||
|
||||
// 基本验证
|
||||
if (strpos($setting_name, '_count') !== false || strpos($setting_name, '_enable') !== false) {
|
||||
$value = intval($value);
|
||||
// 对于复选框类型的设置,如果没有在表单数据中,说明未选中,应该设为0
|
||||
if (strpos($setting_name, '_enable') !== false) {
|
||||
$value = isset($parsed_data[$setting_name]) ? 1 : 0;
|
||||
} else {
|
||||
$value = sanitize_text_field($value);
|
||||
$value = isset($parsed_data[$setting_name]) ? $parsed_data[$setting_name] : '';
|
||||
|
||||
// 基本验证
|
||||
if (strpos($setting_name, '_count') !== false) {
|
||||
$value = intval($value);
|
||||
} else {
|
||||
$value = sanitize_text_field($value);
|
||||
}
|
||||
}
|
||||
|
||||
update_option($setting_name, $value);
|
||||
|
@ -1812,4 +2133,58 @@ function bbps_enqueue_admin_scripts($hook) {
|
|||
'saved_text' => __('Settings saved successfully!', 'bbpress-support-toolkit'),
|
||||
'error_text' => __('Error saving settings. Please try again.', 'bbpress-support-toolkit')
|
||||
));
|
||||
}
|
||||
|
||||
// Advanced Features Callback Functions
|
||||
function bbps_admin_setting_callback_advanced_section()
|
||||
{
|
||||
echo '<p>' . __('Advanced features to enhance your bbPress forums with additional functionality.', 'bbpress-support-toolkit') . '</p>';
|
||||
}
|
||||
|
||||
function bbps_admin_setting_callback_admin_notes()
|
||||
{
|
||||
$option = get_option('bbps_enable_admin_notes', 0);
|
||||
echo '<input type="checkbox" name="bbps_enable_admin_notes" value="1" ' . checked(1, $option, false) . ' />';
|
||||
echo '<label for="bbps_enable_admin_notes">' . __('Enable admin notes for topics and replies', 'bbpress-support-toolkit') . '</label>';
|
||||
echo '<p class="description">' . __('Allows administrators to add private notes to topics and replies that are only visible to other administrators.', 'bbpress-support-toolkit') . '</p>';
|
||||
}
|
||||
|
||||
function bbps_admin_setting_callback_live_preview()
|
||||
{
|
||||
$option = get_option('bbps_enable_live_preview', 0);
|
||||
echo '<input type="checkbox" name="bbps_enable_live_preview" value="1" ' . checked(1, $option, false) . ' />';
|
||||
echo '<label for="bbps_enable_live_preview">' . __('Enable live preview for topics and replies', 'bbpress-support-toolkit') . '</label>';
|
||||
echo '<p class="description">' . __('Allows users to preview their posts in real-time before submitting.', 'bbpress-support-toolkit') . '</p>';
|
||||
}
|
||||
|
||||
function bbps_admin_setting_callback_mark_as_read()
|
||||
{
|
||||
$option = get_option('bbps_enable_mark_as_read', 0);
|
||||
echo '<input type="checkbox" name="bbps_enable_mark_as_read" value="1" ' . checked(1, $option, false) . ' />';
|
||||
echo '<label for="bbps_enable_mark_as_read">' . __('Enable mark as read functionality', 'bbpress-support-toolkit') . '</label>';
|
||||
echo '<p class="description">' . __('Allows users to mark topics as read/unread and track their reading progress.', 'bbpress-support-toolkit') . '</p>';
|
||||
}
|
||||
|
||||
function bbps_admin_setting_callback_canned_replies()
|
||||
{
|
||||
$option = get_option('bbps_enable_canned_replies', 0);
|
||||
echo '<input type="checkbox" name="bbps_enable_canned_replies" value="1" ' . checked(1, $option, false) . ' />';
|
||||
echo '<label for="bbps_enable_canned_replies">' . __('Enable canned replies', 'bbpress-support-toolkit') . '</label>';
|
||||
echo '<p class="description">' . __('Allows administrators and moderators to create and use pre-written reply templates.', 'bbpress-support-toolkit') . '</p>';
|
||||
}
|
||||
|
||||
function bbps_admin_setting_callback_report_content()
|
||||
{
|
||||
$option = get_option('bbps_enable_report_content', 0);
|
||||
echo '<input type="checkbox" name="bbps_enable_report_content" value="1" ' . checked(1, $option, false) . ' />';
|
||||
echo '<label for="bbps_enable_report_content">' . __('Enable content reporting', 'bbpress-support-toolkit') . '</label>';
|
||||
echo '<p class="description">' . __('Allows users to report inappropriate topics and replies to administrators.', 'bbpress-support-toolkit') . '</p>';
|
||||
}
|
||||
|
||||
function bbps_admin_setting_callback_topic_lock()
|
||||
{
|
||||
$option = get_option('bbps_enable_topic_lock', 0);
|
||||
echo '<input type="checkbox" name="bbps_enable_topic_lock" value="1" ' . checked(1, $option, false) . ' />';
|
||||
echo '<label for="bbps_enable_topic_lock">' . __('Enable topic lock notifications', 'bbpress-support-toolkit') . '</label>';
|
||||
echo '<p class="description">' . __('Warns moderators when another moderator is currently viewing the same topic to prevent conflicts.', 'bbpress-support-toolkit') . '</p>';
|
||||
}
|
420
includes/advanced-features.php
Normal file
420
includes/advanced-features.php
Normal file
|
@ -0,0 +1,420 @@
|
|||
<?php
|
||||
/**
|
||||
* Advanced Features for bbPress Support Toolkit
|
||||
*
|
||||
* This file contains implementations of advanced features including:
|
||||
* - Admin Notes
|
||||
* - Live Preview
|
||||
* - Mark as Read
|
||||
* - Canned Replies
|
||||
* - Report Content
|
||||
* - Topic Lock
|
||||
*/
|
||||
|
||||
// Prevent direct access
|
||||
if (!defined('ABSPATH')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Admin Notes Feature
|
||||
*/
|
||||
class BBPS_Admin_Notes {
|
||||
|
||||
public function __construct() {
|
||||
if (get_option('bbps_enable_admin_notes', 0)) {
|
||||
add_action('init', array($this, 'init'));
|
||||
}
|
||||
}
|
||||
|
||||
public function init() {
|
||||
add_action('bbp_theme_after_reply_content', array($this, 'display_admin_note'));
|
||||
add_action('bbp_theme_after_topic_content', array($this, 'display_admin_note'));
|
||||
add_action('add_meta_boxes', array($this, 'add_admin_note_metabox'));
|
||||
add_action('save_post', array($this, 'save_admin_note'));
|
||||
add_action('wp_enqueue_scripts', array($this, 'enqueue_styles'));
|
||||
}
|
||||
|
||||
public function display_admin_note() {
|
||||
if (!current_user_can('moderate_forums')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$post_id = get_the_ID();
|
||||
$admin_note = get_post_meta($post_id, '_bbps_admin_note', true);
|
||||
|
||||
if (!empty($admin_note)) {
|
||||
echo '<div class="bbps-admin-note">';
|
||||
echo '<strong>' . __('Admin Note:', 'bbpress-support-toolkit') . '</strong> ';
|
||||
echo esc_html($admin_note);
|
||||
echo '</div>';
|
||||
}
|
||||
}
|
||||
|
||||
public function add_admin_note_metabox() {
|
||||
add_meta_box(
|
||||
'bbps_admin_note',
|
||||
__('Admin Note', 'bbpress-support-toolkit'),
|
||||
array($this, 'admin_note_metabox_callback'),
|
||||
array('topic', 'reply'),
|
||||
'side',
|
||||
'high'
|
||||
);
|
||||
}
|
||||
|
||||
public function admin_note_metabox_callback($post) {
|
||||
wp_nonce_field('bbps_admin_note_nonce', 'bbps_admin_note_nonce');
|
||||
$admin_note = get_post_meta($post->ID, '_bbps_admin_note', true);
|
||||
|
||||
echo '<textarea name="bbps_admin_note" rows="4" style="width: 100%;">' . esc_textarea($admin_note) . '</textarea>';
|
||||
echo '<p class="description">' . __('This note is only visible to administrators and moderators.', 'bbpress-support-toolkit') . '</p>';
|
||||
}
|
||||
|
||||
public function save_admin_note($post_id) {
|
||||
if (!isset($_POST['bbps_admin_note_nonce']) || !wp_verify_nonce($_POST['bbps_admin_note_nonce'], 'bbps_admin_note_nonce')) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!current_user_can('moderate_forums')) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isset($_POST['bbps_admin_note'])) {
|
||||
update_post_meta($post_id, '_bbps_admin_note', sanitize_textarea_field($_POST['bbps_admin_note']));
|
||||
}
|
||||
}
|
||||
|
||||
public function enqueue_styles() {
|
||||
$is_single_topic_or_reply = false;
|
||||
if (function_exists('bbp_is_single_topic') && function_exists('bbp_is_single_reply')) {
|
||||
$is_single_topic_or_reply = bbp_is_single_topic() || bbp_is_single_reply();
|
||||
}
|
||||
if ($is_single_topic_or_reply) {
|
||||
wp_enqueue_style('bbps-advanced-features', plugin_dir_url(__FILE__) . '../assets/advanced-features.css', array(), '1.0.0');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Live Preview Feature
|
||||
*/
|
||||
class BBPS_Live_Preview {
|
||||
|
||||
public function __construct() {
|
||||
if (get_option('bbps_enable_live_preview', 0)) {
|
||||
add_action('init', array($this, 'init'));
|
||||
}
|
||||
}
|
||||
|
||||
public function init() {
|
||||
add_action('bbp_theme_after_reply_form_content', array($this, 'add_preview_button'));
|
||||
add_action('bbp_theme_after_topic_form_content', array($this, 'add_preview_button'));
|
||||
add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts'));
|
||||
add_action('wp_ajax_bbps_preview_content', array($this, 'ajax_preview_content'));
|
||||
add_action('wp_ajax_nopriv_bbps_preview_content', array($this, 'ajax_preview_content'));
|
||||
}
|
||||
|
||||
public function add_preview_button() {
|
||||
echo '<div class="bbps-preview-container">';
|
||||
echo '<button type="button" id="bbps-preview-btn" class="button">' . __('Preview', 'bbpress-support-toolkit') . '</button>';
|
||||
echo '<div id="bbps-preview-content" style="display: none; margin-top: 10px; padding: 10px; border: 1px solid #ddd; background: #f9f9f9;"></div>';
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
public function enqueue_scripts() {
|
||||
// Check if bbPress functions exist and if we're on a bbPress page
|
||||
$is_bbpress_page = false;
|
||||
if (function_exists('bbp_is_topic_edit') && function_exists('bbp_is_reply_edit')) {
|
||||
$is_bbpress_page = bbp_is_topic_edit() || bbp_is_reply_edit();
|
||||
}
|
||||
if (function_exists('bbp_is_topic_edit') && function_exists('bbp_is_reply_edit')) {
|
||||
$is_bbpress_page = $is_bbpress_page || bbp_is_topic_edit() || bbp_is_reply_edit();
|
||||
}
|
||||
|
||||
// Fallback: check if we're on any bbPress related page
|
||||
if (!$is_bbpress_page && function_exists('bbp_is_bbpress')) {
|
||||
$is_bbpress_page = bbp_is_bbpress();
|
||||
}
|
||||
|
||||
if ($is_bbpress_page) {
|
||||
wp_enqueue_script('bbps-combined', plugin_dir_url(__FILE__) . '../assets/bbps-combined.js', array('jquery'), '1.0.0', true);
|
||||
wp_localize_script('bbps-combined', 'bbps_ajax', array(
|
||||
'ajax_url' => admin_url('admin-ajax.php'),
|
||||
'nonce' => wp_create_nonce('bbps_preview_nonce')
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
public function ajax_preview_content() {
|
||||
if (!wp_verify_nonce($_POST['nonce'], 'bbps_preview_nonce')) {
|
||||
wp_die(__('Security check failed', 'bbpress-support-toolkit'));
|
||||
}
|
||||
|
||||
$content = wp_kses_post($_POST['content']);
|
||||
$preview = apply_filters('the_content', $content);
|
||||
|
||||
wp_send_json_success($preview);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark as Read Feature
|
||||
*/
|
||||
class BBPS_Mark_As_Read {
|
||||
|
||||
public function __construct() {
|
||||
if (get_option('bbps_enable_mark_as_read', 0)) {
|
||||
add_action('init', array($this, 'init'));
|
||||
}
|
||||
}
|
||||
|
||||
public function init() {
|
||||
add_action('bbp_template_after_single_topic', array($this, 'add_mark_read_link'));
|
||||
add_action('wp_ajax_bbps_mark_read', array($this, 'ajax_mark_read'));
|
||||
add_action('wp_ajax_nopriv_bbps_mark_read', array($this, 'ajax_mark_read'));
|
||||
add_filter('bbp_get_topic_class', array($this, 'add_read_status_class'), 10, 2);
|
||||
add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts'));
|
||||
}
|
||||
|
||||
public function add_mark_read_link() {
|
||||
if (!is_user_logged_in()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$topic_id = function_exists('bbp_get_topic_id') ? bbp_get_topic_id() : 0;
|
||||
$user_id = get_current_user_id();
|
||||
$is_read = $this->is_topic_read($topic_id, $user_id);
|
||||
|
||||
$text = $is_read ? __('Mark as Unread', 'bbpress-support-toolkit') : __('Mark as Read', 'bbpress-support-toolkit');
|
||||
$action = $is_read ? 'unread' : 'read';
|
||||
|
||||
echo '<div class="bbps-mark-read-container">';
|
||||
echo '<a href="#" class="bbps-mark-read" data-topic="' . $topic_id . '" data-action="' . $action . '">' . $text . '</a>';
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
public function is_topic_read($topic_id, $user_id) {
|
||||
$read_topics = get_user_meta($user_id, '_bbps_read_topics', true);
|
||||
return is_array($read_topics) && in_array($topic_id, $read_topics);
|
||||
}
|
||||
|
||||
public function ajax_mark_read() {
|
||||
if (!is_user_logged_in()) {
|
||||
wp_die(__('Please log in', 'bbpress-support-toolkit'));
|
||||
}
|
||||
|
||||
$topic_id = intval($_POST['topic_id']);
|
||||
$action = sanitize_text_field($_POST['action']);
|
||||
$user_id = get_current_user_id();
|
||||
|
||||
$read_topics = get_user_meta($user_id, '_bbps_read_topics', true);
|
||||
if (!is_array($read_topics)) {
|
||||
$read_topics = array();
|
||||
}
|
||||
|
||||
if ($action === 'read') {
|
||||
if (!in_array($topic_id, $read_topics)) {
|
||||
$read_topics[] = $topic_id;
|
||||
}
|
||||
} else {
|
||||
$read_topics = array_diff($read_topics, array($topic_id));
|
||||
}
|
||||
|
||||
update_user_meta($user_id, '_bbps_read_topics', $read_topics);
|
||||
|
||||
wp_send_json_success(array(
|
||||
'action' => $action,
|
||||
'new_text' => $action === 'read' ? __('Mark as Unread', 'bbpress-support-toolkit') : __('Mark as Read', 'bbpress-support-toolkit'),
|
||||
'new_action' => $action === 'read' ? 'unread' : 'read'
|
||||
));
|
||||
}
|
||||
|
||||
public function add_read_status_class($classes, $topic_id) {
|
||||
if (is_user_logged_in() && $this->is_topic_read($topic_id, get_current_user_id())) {
|
||||
$classes[] = 'bbps-topic-read';
|
||||
} else {
|
||||
$classes[] = 'bbps-topic-unread';
|
||||
}
|
||||
return $classes;
|
||||
}
|
||||
|
||||
public function enqueue_scripts() {
|
||||
$is_single_topic = function_exists('bbp_is_single_topic') && bbp_is_single_topic();
|
||||
if ($is_single_topic) {
|
||||
wp_enqueue_script('bbps-combined', plugin_dir_url(__FILE__) . '../assets/bbps-combined.js', array('jquery'), '1.0.0', true);
|
||||
wp_localize_script('bbps-combined', 'bbps_ajax', array(
|
||||
'ajax_url' => admin_url('admin-ajax.php'),
|
||||
'nonce' => wp_create_nonce('bbps_nonce'),
|
||||
'strings' => array(
|
||||
'mark_read' => __('Mark as Read', 'bbpress-support-toolkit'),
|
||||
'mark_unread' => __('Mark as Unread', 'bbpress-support-toolkit'),
|
||||
'error' => __('An error occurred', 'bbpress-support-toolkit')
|
||||
)
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Report Content Feature
|
||||
*/
|
||||
class BBPS_Report_Content {
|
||||
|
||||
public function __construct() {
|
||||
if (get_option('bbps_enable_report_content', 0)) {
|
||||
add_action('init', array($this, 'init'));
|
||||
}
|
||||
}
|
||||
|
||||
public function init() {
|
||||
add_action('bbp_template_after_single_topic', array($this, 'add_report_link'));
|
||||
add_action('bbp_template_after_single_reply', array($this, 'add_report_link'));
|
||||
add_action('wp_ajax_bbps_report_content', array($this, 'ajax_report_content'));
|
||||
add_action('wp_ajax_nopriv_bbps_report_content', array($this, 'ajax_report_content'));
|
||||
add_action('init', array($this, 'register_post_status'));
|
||||
}
|
||||
|
||||
public function register_post_status() {
|
||||
register_post_status('reported', array(
|
||||
'label' => __('Reported', 'bbpress-support-toolkit'),
|
||||
'public' => false,
|
||||
'exclude_from_search' => true,
|
||||
'show_in_admin_all_list' => true,
|
||||
'show_in_admin_status_list' => true,
|
||||
'label_count' => _n_noop('Reported <span class="count">(%s)</span>', 'Reported <span class="count">(%s)</span>', 'bbpress-support-toolkit')
|
||||
));
|
||||
}
|
||||
|
||||
public function add_report_link() {
|
||||
if (!is_user_logged_in()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$post_id = get_the_ID();
|
||||
echo '<div class="bbps-report-container">';
|
||||
echo '<a href="#" class="bbps-report-content" data-post="' . $post_id . '">' . __('Report', 'bbpress-support-toolkit') . '</a>';
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
public function ajax_report_content() {
|
||||
if (!is_user_logged_in()) {
|
||||
wp_die(__('Please log in', 'bbpress-support-toolkit'));
|
||||
}
|
||||
|
||||
$post_id = intval($_POST['post_id']);
|
||||
$reason = sanitize_textarea_field($_POST['reason']);
|
||||
|
||||
// Mark post as reported
|
||||
wp_update_post(array(
|
||||
'ID' => $post_id,
|
||||
'post_status' => 'reported'
|
||||
));
|
||||
|
||||
// Save report reason
|
||||
update_post_meta($post_id, '_bbps_report_reason', $reason);
|
||||
update_post_meta($post_id, '_bbps_reported_by', get_current_user_id());
|
||||
update_post_meta($post_id, '_bbps_reported_date', current_time('mysql'));
|
||||
|
||||
wp_send_json_success(__('Content reported successfully.', 'bbpress-support-toolkit'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Canned Replies Feature
|
||||
* Note: Functionality moved to enhanced-features.php to avoid duplication
|
||||
*/
|
||||
class BBPS_Canned_Replies {
|
||||
|
||||
public function __construct() {
|
||||
// Functionality moved to enhanced-features.php
|
||||
// This prevents duplicate registration
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Topic Lock Feature
|
||||
*/
|
||||
class BBPS_Topic_Lock {
|
||||
|
||||
public function __construct() {
|
||||
if (get_option('bbps_enable_topic_lock', 0)) {
|
||||
add_action('init', array($this, 'init'));
|
||||
}
|
||||
}
|
||||
|
||||
public function init() {
|
||||
add_action('bbp_template_before_single_topic', array($this, 'check_topic_lock'));
|
||||
add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts'));
|
||||
add_action('wp_ajax_bbps_topic_lock', array($this, 'ajax_topic_lock'));
|
||||
add_action('wp_ajax_nopriv_bbps_topic_lock', array($this, 'ajax_topic_lock'));
|
||||
}
|
||||
|
||||
public function check_topic_lock() {
|
||||
if (!current_user_can('moderate_forums')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$topic_id = function_exists('bbp_get_topic_id') ? bbp_get_topic_id() : 0;
|
||||
$current_user_id = get_current_user_id();
|
||||
|
||||
// Check if topic is locked by another user
|
||||
$lock_info = get_transient('bbps_topic_lock_' . $topic_id);
|
||||
|
||||
if ($lock_info && $lock_info['user_id'] != $current_user_id) {
|
||||
$user_info = get_userdata($lock_info['user_id']);
|
||||
echo '<div class="bbps-topic-lock-warning">';
|
||||
echo '<span class="dashicons dashicons-warning"></span>';
|
||||
printf(
|
||||
__('Warning: %s is currently viewing this topic (since %s)', 'bbpress-support-toolkit'),
|
||||
esc_html($user_info->display_name),
|
||||
esc_html(human_time_diff($lock_info['timestamp']))
|
||||
);
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
// Set lock for current user
|
||||
set_transient('bbps_topic_lock_' . $topic_id, array(
|
||||
'user_id' => $current_user_id,
|
||||
'timestamp' => time()
|
||||
), 300); // 5 minutes
|
||||
}
|
||||
|
||||
public function enqueue_scripts() {
|
||||
$is_single_topic = function_exists('bbp_is_single_topic') && bbp_is_single_topic();
|
||||
if ($is_single_topic && current_user_can('moderate_forums')) {
|
||||
wp_enqueue_script('bbps-combined', plugin_dir_url(__FILE__) . '../assets/bbps-combined.js', array('jquery'), '1.0.0', true);
|
||||
$topic_id = function_exists('bbp_get_topic_id') ? bbp_get_topic_id() : 0;
|
||||
wp_localize_script('bbps-combined', 'bbps_ajax', array(
|
||||
'ajax_url' => admin_url('admin-ajax.php'),
|
||||
'topic_id' => $topic_id,
|
||||
'user_id' => get_current_user_id()
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
public function ajax_topic_lock() {
|
||||
$topic_id = intval($_POST['topic_id']);
|
||||
$user_id = get_current_user_id();
|
||||
|
||||
if (!current_user_can('moderate_forums')) {
|
||||
wp_send_json_error(__('Permission denied', 'bbpress-support-toolkit'));
|
||||
}
|
||||
|
||||
// Update lock
|
||||
set_transient('bbps_topic_lock_' . $topic_id, array(
|
||||
'user_id' => $user_id,
|
||||
'timestamp' => time()
|
||||
), 300);
|
||||
|
||||
wp_send_json_success();
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize all features
|
||||
new BBPS_Admin_Notes();
|
||||
// BBPS_Live_Preview functionality moved to enhanced-features.php to avoid duplication
|
||||
// new BBPS_Live_Preview();
|
||||
new BBPS_Mark_As_Read();
|
||||
new BBPS_Report_Content();
|
||||
// BBPS_Canned_Replies functionality moved to enhanced-features.php
|
||||
new BBPS_Topic_Lock();
|
|
@ -542,13 +542,13 @@ function bbps_get_topic_status($topic_id)
|
|||
|
||||
switch ($switch) {
|
||||
case 1:
|
||||
return __("not resolved", "bbpress-support-toolkit");
|
||||
return __("Not Resolved", "bbpress-support-toolkit");
|
||||
case 2:
|
||||
return __("resolved", "bbpress-support-toolkit");
|
||||
return __("Resolved", "bbpress-support-toolkit");
|
||||
case 3:
|
||||
return __("not a support question", "bbpress-support-toolkit");
|
||||
return __("Not a Support Question", "bbpress-support-toolkit");
|
||||
default:
|
||||
return __("not resolved", "bbpress-support-toolkit");
|
||||
return __("Not Resolved", "bbpress-support-toolkit");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1255,4 +1255,160 @@ function bbps_modify_search_form($form)
|
|||
}
|
||||
</script>';
|
||||
return $form;
|
||||
}
|
||||
|
||||
// ========================================
|
||||
// Additional Features Integration
|
||||
// ========================================
|
||||
|
||||
// 1. Disable User Page Feature
|
||||
function bbps_is_disable_user_page_enabled()
|
||||
{
|
||||
return get_option('bbps_disable_user_page', 0);
|
||||
}
|
||||
|
||||
if (bbps_is_disable_user_page_enabled()) {
|
||||
add_filter('bbp_show_user_profile', '__return_false');
|
||||
}
|
||||
|
||||
// 2. Remove Avatars Feature
|
||||
function bbps_is_remove_avatars_enabled()
|
||||
{
|
||||
return get_option('bbps_remove_avatars', 0);
|
||||
}
|
||||
|
||||
if (bbps_is_remove_avatars_enabled()) {
|
||||
// Remove from replies and topics
|
||||
function bbps_return_empty(){
|
||||
return '';
|
||||
}
|
||||
add_filter('bbp_get_topic_author_avatar', 'bbps_return_empty');
|
||||
add_filter('bbp_get_reply_author_avatar', 'bbps_return_empty');
|
||||
|
||||
// Remove from a few weird places like freshness
|
||||
function bbps_remove_avatar_section($author_links, $r, $args){
|
||||
foreach ($author_links as $link) {
|
||||
if (strpos($link, 'bbp-author-avatar') !== false){
|
||||
$author_links = array_diff($author_links, array($link));
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $author_links;
|
||||
}
|
||||
add_filter('bbp_get_author_links', 'bbps_remove_avatar_section', 10 , 3);
|
||||
|
||||
function bbps_reply_padding_fix(){
|
||||
echo '<style>.bbp-reply-author { padding-top: 12px; }</style>';
|
||||
}
|
||||
add_action('bbp_template_before_replies_loop', 'bbps_reply_padding_fix');
|
||||
|
||||
// Remove from user profile page
|
||||
function bbps_return_1(){
|
||||
return 1;
|
||||
}
|
||||
add_filter('bbp_single_user_details_avatar_size', 'bbps_return_1');
|
||||
|
||||
function bbps_hide_profile_avatar(){
|
||||
echo '<style>#bbp-user-avatar { display: none; }</style>';
|
||||
}
|
||||
add_action('bbp_template_before_user_details', 'bbps_hide_profile_avatar');
|
||||
}
|
||||
|
||||
// 3. Redirect Single Replies Feature
|
||||
function bbps_is_redirect_single_replies_enabled()
|
||||
{
|
||||
return get_option('bbps_redirect_single_replies', 0);
|
||||
}
|
||||
|
||||
if (bbps_is_redirect_single_replies_enabled()) {
|
||||
class BBPS_Single_Reply_Redirect {
|
||||
public function __construct() {
|
||||
add_action( 'bbp_template_redirect', array( $this, 'template_redirect' ) );
|
||||
}
|
||||
|
||||
public function template_redirect() {
|
||||
if( bbp_is_single_reply() && ! bbp_is_reply_edit() ) {
|
||||
wp_redirect( bbp_get_reply_url() ); exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
new BBPS_Single_Reply_Redirect();
|
||||
}
|
||||
|
||||
// 4. Custom Reply Notifications Feature
|
||||
function bbps_is_custom_notifications_enabled()
|
||||
{
|
||||
return get_option('bbps_custom_notifications', 0);
|
||||
}
|
||||
|
||||
if (bbps_is_custom_notifications_enabled()) {
|
||||
class BBPS_Topic_Reply_Notifications {
|
||||
function __construct() {
|
||||
add_filter( 'bbp_forum_subscription_mail_message', array( __CLASS__, 'topic_message' ), 10, 3 );
|
||||
add_filter( 'bbp_forum_subscription_mail_title', array( __CLASS__, 'topic_title' ), 10, 3 );
|
||||
add_filter( 'bbp_subscription_mail_message', array( __CLASS__, 'reply_message' ), 10, 3 );
|
||||
add_filter( 'bbp_subscription_mail_title', array( __CLASS__, 'reply_title' ), 10, 3 );
|
||||
}
|
||||
|
||||
public static function topic_message( $message, $topic_id, $forum_id ) {
|
||||
$topic_content = strip_tags( bbp_get_topic_content( $topic_id ) );
|
||||
$topic_url = bbp_get_topic_permalink( $topic_id );
|
||||
$topic_author = bbp_get_topic_author_display_name( $topic_id );
|
||||
$forum_name = bbp_get_forum_title( $forum_id );
|
||||
|
||||
$custom_message = get_option( 'bbps_topic_notice_body' );
|
||||
$message = $custom_message ? $custom_message : $message;
|
||||
|
||||
$message = str_replace( '{author}', $topic_author, $message );
|
||||
$message = str_replace( '{content}', $topic_content, $message );
|
||||
$message = str_replace( '{url}', $topic_url, $message );
|
||||
$message = str_replace( '{forum_name}', $forum_name, $message );
|
||||
|
||||
return $message;
|
||||
}
|
||||
|
||||
public static function topic_title( $title, $topic_id, $forum_id ) {
|
||||
$subject = get_option( 'bbps_topic_notice_title' );
|
||||
|
||||
if ( ! is_string( $subject ) && strlen( $subject ) == 0 ) {
|
||||
return $title;
|
||||
}
|
||||
|
||||
$search = '{title}';
|
||||
$replace = strip_tags( bbp_get_topic_title( $topic_id ) );
|
||||
$title = str_replace( $search, $replace, $subject );
|
||||
|
||||
return $title;
|
||||
}
|
||||
|
||||
public static function reply_message( $message, $reply_id, $topic_id ) {
|
||||
$reply_content = strip_tags( bbp_get_reply_content( $reply_id ) );
|
||||
$reply_url = bbp_get_reply_url( $reply_id );
|
||||
$reply_author = bbp_get_reply_author_display_name( $reply_id );
|
||||
|
||||
$custom_message = get_option( 'bbps_reply_notice_body' );
|
||||
$message = $custom_message ? $custom_message : $message;
|
||||
|
||||
$message = str_replace( '{author}', $reply_author, $message );
|
||||
$message = str_replace( '{content}', $reply_content, $message );
|
||||
$message = str_replace( '{url}', $reply_url, $message );
|
||||
|
||||
return $message;
|
||||
}
|
||||
|
||||
public static function reply_title( $title, $reply_id, $topic_id ) {
|
||||
$subject = get_option( 'bbps_reply_notice_title' );
|
||||
|
||||
if ( ! is_string( $subject ) && strlen( $subject ) == 0 ) {
|
||||
return $title;
|
||||
}
|
||||
|
||||
$search = '{title}';
|
||||
$replace = strip_tags( bbp_get_topic_title( $topic_id ) );
|
||||
$title = str_replace( $search, $replace, $subject );
|
||||
|
||||
return $title;
|
||||
}
|
||||
}
|
||||
new BBPS_Topic_Reply_Notifications();
|
||||
}
|
601
includes/enhanced-features.php
Normal file
601
includes/enhanced-features.php
Normal file
|
@ -0,0 +1,601 @@
|
|||
<?php
|
||||
/**
|
||||
* Enhanced Features for bbPress Support Toolkit
|
||||
* Integrates functionality from admin notes, live preview, mark as read, canned replies, etc.
|
||||
*/
|
||||
|
||||
if (!defined('ABSPATH')) {
|
||||
exit();
|
||||
}
|
||||
|
||||
class BBPS_Enhanced_Features {
|
||||
|
||||
private static $instance = null;
|
||||
|
||||
public static function instance() {
|
||||
if (null === self::$instance) {
|
||||
self::$instance = new self();
|
||||
}
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
private function __construct() {
|
||||
$this->init_hooks();
|
||||
}
|
||||
|
||||
private function init_hooks() {
|
||||
// Admin Notes - only if enabled
|
||||
if (get_option('bbps_enable_admin_notes', 0)) {
|
||||
add_action('init', [$this, 'init_admin_notes']);
|
||||
add_action('bbp_theme_after_reply_content', [$this, 'display_admin_notes']);
|
||||
add_action('bbp_theme_after_topic_content', [$this, 'add_note_form']);
|
||||
add_action('bbp_theme_after_reply_content', [$this, 'add_note_form']);
|
||||
add_action('wp_ajax_bbps_save_note', [$this, 'save_admin_note']);
|
||||
add_action('wp_ajax_nopriv_bbps_save_note', [$this, 'save_admin_note']);
|
||||
}
|
||||
|
||||
// Live Preview - only if enabled
|
||||
if (get_option('bbps_enable_live_preview', 0)) {
|
||||
add_action('wp_ajax_bbps_live_preview', [$this, 'ajax_live_preview']);
|
||||
add_action('wp_ajax_nopriv_bbps_live_preview', [$this, 'ajax_live_preview']);
|
||||
add_action('bbp_theme_before_topic_form_content', [$this, 'add_preview_button']);
|
||||
add_action('bbp_theme_before_reply_form_content', [$this, 'add_preview_button']);
|
||||
}
|
||||
|
||||
// Mark as Read - only if enabled
|
||||
if (get_option('bbps_enable_mark_as_read', 0)) {
|
||||
add_action('wp_ajax_bbps_mark_read', [$this, 'ajax_mark_read']);
|
||||
add_action('wp_ajax_nopriv_bbps_mark_read', [$this, 'ajax_mark_read']);
|
||||
add_action('wp_ajax_bbps_mark_all_read', [$this, 'ajax_mark_all_read']);
|
||||
add_filter('bbp_topic_admin_links', [$this, 'add_mark_read_link'], 10, 2);
|
||||
add_filter('post_class', [$this, 'add_read_status_class']);
|
||||
add_action('wp_enqueue_scripts', [$this, 'enqueue_mark_read_scripts']);
|
||||
}
|
||||
|
||||
// Canned Replies - only if enabled
|
||||
if (get_option('bbps_enable_canned_replies', 0)) {
|
||||
add_action('init', [$this, 'register_canned_replies_post_type']);
|
||||
add_action('bbp_theme_before_reply_form_content', [$this, 'display_canned_replies']);
|
||||
add_action('admin_menu', [$this, 'add_canned_replies_menu']);
|
||||
add_action('wp_enqueue_scripts', [$this, 'enqueue_canned_replies_scripts']);
|
||||
}
|
||||
|
||||
// Topic Lock - only if enabled
|
||||
if (get_option('bbps_enable_topic_lock', 0)) {
|
||||
add_action('wp_ajax_bbps_topic_lock', [$this, 'ajax_topic_lock']);
|
||||
add_filter('bbp_topic_admin_links', [$this, 'add_topic_lock_link'], 10, 2);
|
||||
add_action('wp_enqueue_scripts', [$this, 'enqueue_topic_lock_scripts']);
|
||||
}
|
||||
|
||||
// Report Content - only if enabled
|
||||
if (get_option('bbps_enable_report_content', 0)) {
|
||||
add_action('wp_ajax_bbps_report_content', [$this, 'ajax_report_content']);
|
||||
add_action('wp_ajax_nopriv_bbps_report_content', [$this, 'ajax_report_content']);
|
||||
add_filter('bbp_reply_admin_links', [$this, 'add_report_link'], 10, 2);
|
||||
add_action('bbp_theme_after_reply_content', [$this, 'add_report_link_to_content']);
|
||||
add_action('bbp_theme_after_topic_content', [$this, 'add_report_link_to_content']);
|
||||
add_action('wp_enqueue_scripts', [$this, 'enqueue_report_content_scripts']);
|
||||
}
|
||||
}
|
||||
|
||||
// Admin Notes Functionality
|
||||
public function init_admin_notes() {
|
||||
add_post_type_support(bbp_get_topic_post_type(), 'comments');
|
||||
add_post_type_support(bbp_get_reply_post_type(), 'comments');
|
||||
}
|
||||
|
||||
public function display_admin_notes($post_id = 0) {
|
||||
if (!$post_id) {
|
||||
$post_id = get_the_ID();
|
||||
}
|
||||
|
||||
if (!current_user_can('moderate')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$notes = get_comments([
|
||||
'post_id' => $post_id,
|
||||
'meta_key' => '_bbps_admin_note',
|
||||
'meta_value' => '1',
|
||||
'status' => 'approve'
|
||||
]);
|
||||
|
||||
if (!empty($notes)) {
|
||||
echo '<div class="bbps-admin-notes">';
|
||||
echo '<h4>' . __('Admin Notes', 'bbpress-support-toolkit') . '</h4>';
|
||||
|
||||
foreach ($notes as $note) {
|
||||
echo '<div class="bbps-admin-note">';
|
||||
echo '<div class="bbps-note-meta">';
|
||||
echo '<strong>' . get_user_by('id', $note->user_id)->display_name . '</strong> - ';
|
||||
echo '<span class="bbps-note-date">' . date_i18n(get_option('date_format') . ' ' . get_option('time_format'), strtotime($note->comment_date)) . '</span>';
|
||||
echo '</div>';
|
||||
echo '<div class="bbps-note-content">' . wpautop($note->comment_content) . '</div>';
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
echo '</div>';
|
||||
}
|
||||
}
|
||||
|
||||
public function add_note_form($post_id = 0) {
|
||||
if (!$post_id) {
|
||||
$post_id = get_the_ID();
|
||||
}
|
||||
|
||||
if (!current_user_can('moderate')) {
|
||||
return;
|
||||
}
|
||||
|
||||
echo '<div class="bbps-add-note-wrapper">';
|
||||
echo '<a href="#" class="bbps-add-note-link bbps-admin-note-toggle" data-post-id="' . $post_id . '">' . __('Add Admin Note', 'bbpress-support-toolkit') . '</a>';
|
||||
echo '<form class="bbps-note-form bbps-admin-note-form" id="bbps-note-form-' . $post_id . '" style="display:none;" data-topic-id="' . $post_id . '">';
|
||||
echo '<textarea name="admin_note" placeholder="' . __('Enter admin note...', 'bbpress-support-toolkit') . '" rows="3" required></textarea>';
|
||||
echo '<input type="hidden" name="topic_id" value="' . $post_id . '">';
|
||||
echo '<button type="submit">' . __('Save Note', 'bbpress-support-toolkit') . '</button>';
|
||||
echo '</form>';
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
public function save_admin_note() {
|
||||
check_ajax_referer('bbps_nonce', 'nonce');
|
||||
|
||||
if (!current_user_can('moderate')) {
|
||||
wp_die(__('Permission denied', 'bbpress-support-toolkit'));
|
||||
}
|
||||
|
||||
$post_id = intval($_POST['topic_id']) ?: intval($_POST['post_id']);
|
||||
$content = sanitize_textarea_field($_POST['admin_note']) ?: sanitize_textarea_field($_POST['content']);
|
||||
|
||||
if (empty($content)) {
|
||||
wp_send_json_error(__('Note content is required', 'bbpress-support-toolkit'));
|
||||
}
|
||||
|
||||
$comment_data = [
|
||||
'comment_post_ID' => $post_id,
|
||||
'comment_content' => $content,
|
||||
'comment_type' => 'bbps_admin_note',
|
||||
'comment_approved' => 1,
|
||||
'user_id' => get_current_user_id()
|
||||
];
|
||||
|
||||
$comment_id = wp_insert_comment($comment_data);
|
||||
|
||||
if ($comment_id) {
|
||||
add_comment_meta($comment_id, '_bbps_admin_note', '1');
|
||||
wp_send_json_success(__('Note saved successfully', 'bbpress-support-toolkit'));
|
||||
} else {
|
||||
wp_send_json_error(__('Failed to save note', 'bbpress-support-toolkit'));
|
||||
}
|
||||
}
|
||||
|
||||
// Live Preview Functionality
|
||||
public function add_preview_button() {
|
||||
echo '<div class="bbps-preview-wrapper">';
|
||||
echo '<button type="button" id="bbps-preview-btn" class="button">' . __('Preview', 'bbpress-support-toolkit') . '</button>';
|
||||
echo '<div id="bbps-preview-content" style="display:none; margin-top:10px; padding:10px; border:1px solid #ddd; background:#f9f9f9;"></div>';
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
public function ajax_live_preview() {
|
||||
check_ajax_referer('bbps_nonce', 'nonce');
|
||||
|
||||
$content = wp_kses_post($_POST['text']);
|
||||
$type = sanitize_text_field($_POST['type']);
|
||||
|
||||
// Process content through WordPress filters
|
||||
$processed_content = apply_filters('the_content', $content);
|
||||
|
||||
wp_send_json_success($processed_content);
|
||||
}
|
||||
|
||||
// Mark as Read Functionality
|
||||
public function add_mark_read_link($links, $topic_id) {
|
||||
if (!is_user_logged_in()) {
|
||||
return $links;
|
||||
}
|
||||
|
||||
// Ensure $links is an array
|
||||
if (!is_array($links)) {
|
||||
$links = array();
|
||||
}
|
||||
|
||||
// Get the correct topic ID
|
||||
if (empty($topic_id)) {
|
||||
$topic_id = bbp_get_topic_id();
|
||||
}
|
||||
$topic_id = (int) $topic_id;
|
||||
|
||||
$user_id = get_current_user_id();
|
||||
$is_read = $this->is_topic_read($user_id, $topic_id);
|
||||
|
||||
$text = $is_read ? __('Mark as Unread', 'bbpress-support-toolkit') : __('Mark as Read', 'bbpress-support-toolkit');
|
||||
$action = $is_read ? 'unread' : 'read';
|
||||
$class = $is_read ? 'read' : 'unread';
|
||||
|
||||
$links['mark_read'] = '<a href="#" class="bbps-mark-read ' . $class . '" data-topic="' . $topic_id . '" data-action="' . $action . '">' . $text . '</a>';
|
||||
|
||||
return $links;
|
||||
}
|
||||
|
||||
public function add_read_status_class($classes) {
|
||||
if (bbp_is_topic() && is_user_logged_in()) {
|
||||
$topic_id = bbp_get_topic_id();
|
||||
$user_id = get_current_user_id();
|
||||
|
||||
if ($this->is_topic_read($user_id, $topic_id)) {
|
||||
$classes[] = 'bbps-topic-read';
|
||||
} else {
|
||||
$classes[] = 'bbps-topic-unread';
|
||||
}
|
||||
}
|
||||
|
||||
return $classes;
|
||||
}
|
||||
|
||||
public function ajax_mark_read() {
|
||||
check_ajax_referer('bbps_nonce', 'nonce');
|
||||
|
||||
if (!is_user_logged_in()) {
|
||||
wp_send_json_error(__('Please log in', 'bbpress-support-toolkit'));
|
||||
}
|
||||
|
||||
$topic_id = intval($_POST['topic_id']);
|
||||
$action = sanitize_text_field($_POST['mark_action']);
|
||||
$user_id = get_current_user_id();
|
||||
|
||||
if ($action === 'read') {
|
||||
$this->mark_topic_read($user_id, $topic_id);
|
||||
$new_text = __('Mark as Unread', 'bbpress-support-toolkit');
|
||||
$new_action = 'unread';
|
||||
} else {
|
||||
$this->mark_topic_unread($user_id, $topic_id);
|
||||
$new_text = __('Mark as Read', 'bbpress-support-toolkit');
|
||||
$new_action = 'read';
|
||||
}
|
||||
|
||||
wp_send_json_success([
|
||||
'new_text' => $new_text,
|
||||
'new_action' => $new_action
|
||||
]);
|
||||
}
|
||||
|
||||
public function ajax_mark_all_read() {
|
||||
check_ajax_referer('bbps_nonce', 'nonce');
|
||||
|
||||
if (!is_user_logged_in()) {
|
||||
wp_send_json_error(__('Please log in', 'bbpress-support-toolkit'));
|
||||
}
|
||||
|
||||
$user_id = get_current_user_id();
|
||||
|
||||
// Get all topics
|
||||
$topics = get_posts([
|
||||
'post_type' => bbp_get_topic_post_type(),
|
||||
'posts_per_page' => -1,
|
||||
'post_status' => 'publish'
|
||||
]);
|
||||
|
||||
foreach ($topics as $topic) {
|
||||
$this->mark_topic_read($user_id, $topic->ID);
|
||||
}
|
||||
|
||||
wp_send_json_success(__('All topics marked as read', 'bbpress-support-toolkit'));
|
||||
}
|
||||
|
||||
private function is_topic_read($user_id, $topic_id) {
|
||||
$read_topics = get_user_meta($user_id, '_bbps_read_topics', true);
|
||||
return is_array($read_topics) && in_array($topic_id, $read_topics);
|
||||
}
|
||||
|
||||
private function mark_topic_read($user_id, $topic_id) {
|
||||
$read_topics = get_user_meta($user_id, '_bbps_read_topics', true);
|
||||
if (!is_array($read_topics)) {
|
||||
$read_topics = [];
|
||||
}
|
||||
|
||||
if (!in_array($topic_id, $read_topics)) {
|
||||
$read_topics[] = $topic_id;
|
||||
update_user_meta($user_id, '_bbps_read_topics', $read_topics);
|
||||
}
|
||||
}
|
||||
|
||||
private function mark_topic_unread($user_id, $topic_id) {
|
||||
$read_topics = get_user_meta($user_id, '_bbps_read_topics', true);
|
||||
if (is_array($read_topics)) {
|
||||
$read_topics = array_diff($read_topics, [$topic_id]);
|
||||
update_user_meta($user_id, '_bbps_read_topics', $read_topics);
|
||||
}
|
||||
}
|
||||
|
||||
// Canned Replies Functionality
|
||||
public function register_canned_replies_post_type() {
|
||||
register_post_type('bbps_canned_reply', [
|
||||
'labels' => [
|
||||
'name' => __('Canned Replies', 'bbpress-support-toolkit'),
|
||||
'singular_name' => __('Canned Reply', 'bbpress-support-toolkit'),
|
||||
'add_new' => __('Add New Reply', 'bbpress-support-toolkit'),
|
||||
'add_new_item' => __('Add New Canned Reply', 'bbpress-support-toolkit'),
|
||||
'edit_item' => __('Edit Canned Reply', 'bbpress-support-toolkit'),
|
||||
'new_item' => __('New Canned Reply', 'bbpress-support-toolkit'),
|
||||
'view_item' => __('View Canned Reply', 'bbpress-support-toolkit'),
|
||||
'search_items' => __('Search Canned Replies', 'bbpress-support-toolkit'),
|
||||
'not_found' => __('No canned replies found', 'bbpress-support-toolkit'),
|
||||
'not_found_in_trash' => __('No canned replies found in trash', 'bbpress-support-toolkit')
|
||||
],
|
||||
'public' => false,
|
||||
'show_ui' => true,
|
||||
'show_in_menu' => 'edit.php?post_type=' . bbp_get_forum_post_type(),
|
||||
'capability_type' => 'post',
|
||||
'capabilities' => [
|
||||
'edit_post' => 'moderate',
|
||||
'edit_posts' => 'moderate',
|
||||
'edit_others_posts' => 'moderate',
|
||||
'publish_posts' => 'moderate',
|
||||
'read_post' => 'moderate',
|
||||
'read_private_posts' => 'moderate',
|
||||
'delete_post' => 'moderate'
|
||||
],
|
||||
'supports' => ['title', 'editor'],
|
||||
'menu_icon' => 'dashicons-format-chat'
|
||||
]);
|
||||
}
|
||||
|
||||
public function add_canned_replies_menu() {
|
||||
// Check if the menu already exists to avoid duplication
|
||||
global $submenu;
|
||||
$parent_slug = 'edit.php?post_type=' . bbp_get_forum_post_type();
|
||||
$menu_slug = 'edit.php?post_type=bbps_canned_reply';
|
||||
|
||||
// Check if submenu already exists
|
||||
if (isset($submenu[$parent_slug])) {
|
||||
foreach ($submenu[$parent_slug] as $item) {
|
||||
if (isset($item[2]) && $item[2] === $menu_slug) {
|
||||
return; // Menu already exists
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
add_submenu_page(
|
||||
$parent_slug,
|
||||
__('Canned Replies', 'bbpress-support-toolkit'),
|
||||
__('Canned Replies', 'bbpress-support-toolkit'),
|
||||
'moderate',
|
||||
$menu_slug
|
||||
);
|
||||
}
|
||||
|
||||
public function enqueue_canned_replies_scripts() {
|
||||
if (bbp_is_single_topic() || bbp_is_topic_edit() || bbp_is_reply_edit()) {
|
||||
wp_enqueue_script('bbps-combined', plugin_dir_url(__FILE__) . '../assets/bbps-combined.js', array('jquery'), '1.0.0', true);
|
||||
wp_enqueue_style('bbps-style', plugin_dir_url(__FILE__) . '../assets/style.css', array(), '1.0.0');
|
||||
wp_localize_script('bbps-combined', 'bbps_ajax', array(
|
||||
'ajax_url' => admin_url('admin-ajax.php'),
|
||||
'nonce' => wp_create_nonce('bbps_nonce'),
|
||||
'strings' => array(
|
||||
'loading' => __('Loading...', 'bbpress-support-toolkit'),
|
||||
'error' => __('Error occurred', 'bbpress-support-toolkit'),
|
||||
'success' => __('Success', 'bbpress-support-toolkit')
|
||||
)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
public function enqueue_topic_lock_scripts() {
|
||||
if (bbp_is_single_topic() || bbp_is_topic_edit()) {
|
||||
wp_enqueue_script('bbps-combined', plugin_dir_url(__FILE__) . '../assets/bbps-combined.js', array('jquery'), '1.0.0', true);
|
||||
wp_localize_script('bbps-combined', 'bbps_ajax', array(
|
||||
'ajax_url' => admin_url('admin-ajax.php'),
|
||||
'nonce' => wp_create_nonce('bbps_nonce'),
|
||||
'strings' => array(
|
||||
'lock_topic' => __('Lock Topic', 'bbpress-support-toolkit'),
|
||||
'unlock_topic' => __('Unlock Topic', 'bbpress-support-toolkit'),
|
||||
'topic_locked_success' => __('Topic locked successfully', 'bbpress-support-toolkit'),
|
||||
'topic_unlocked_success' => __('Topic unlocked successfully', 'bbpress-support-toolkit'),
|
||||
'error_locking_topic' => __('Error locking topic', 'bbpress-support-toolkit'),
|
||||
'error_unlocking_topic' => __('Error unlocking topic', 'bbpress-support-toolkit'),
|
||||
'topic_id_not_found' => __('Topic ID not found', 'bbpress-support-toolkit'),
|
||||
'ajax_error' => __('AJAX error occurred', 'bbpress-support-toolkit')
|
||||
)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
public function enqueue_report_content_scripts() {
|
||||
if (bbp_is_single_topic() || bbp_is_single_reply()) {
|
||||
wp_enqueue_script('bbps-combined', plugin_dir_url(__FILE__) . '../assets/bbps-combined.js', array('jquery'), '1.0.0', true);
|
||||
wp_localize_script('bbps-combined', 'bbps_ajax', array(
|
||||
'ajax_url' => admin_url('admin-ajax.php'),
|
||||
'nonce' => wp_create_nonce('bbps_nonce'),
|
||||
'strings' => array(
|
||||
'enter_report_reason' => __('Please enter the reason for reporting this content:', 'bbpress-support-toolkit'),
|
||||
'reported' => __('Reported', 'bbpress-support-toolkit'),
|
||||
'content_reported' => __('Content reported successfully', 'bbpress-support-toolkit'),
|
||||
'error_reporting' => __('Error reporting content', 'bbpress-support-toolkit'),
|
||||
'post_id_not_found' => __('Post ID not found', 'bbpress-support-toolkit'),
|
||||
'ajax_error' => __('AJAX error occurred', 'bbpress-support-toolkit')
|
||||
)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
public function enqueue_mark_read_scripts() {
|
||||
if (bbp_is_single_topic() || bbp_is_topic_archive()) {
|
||||
wp_enqueue_script('bbps-combined', plugin_dir_url(__FILE__) . '../assets/bbps-combined.js', array('jquery'), '1.0.0', true);
|
||||
wp_localize_script('bbps-combined', 'bbps_ajax', array(
|
||||
'ajax_url' => admin_url('admin-ajax.php'),
|
||||
'nonce' => wp_create_nonce('bbps_nonce'),
|
||||
'strings' => array(
|
||||
'mark_read' => __('Mark as Read', 'bbpress-support-toolkit'),
|
||||
'mark_unread' => __('Mark as Unread', 'bbpress-support-toolkit'),
|
||||
'mark_all_read_confirm' => __('Mark all topics as read?', 'bbpress-support-toolkit'),
|
||||
'error' => __('Error occurred', 'bbpress-support-toolkit')
|
||||
)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
public function display_canned_replies() {
|
||||
if (!current_user_can('moderate')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$replies = get_posts([
|
||||
'post_type' => 'bbps_canned_reply',
|
||||
'posts_per_page' => -1,
|
||||
'post_status' => 'publish'
|
||||
]);
|
||||
|
||||
if (empty($replies)) {
|
||||
return;
|
||||
}
|
||||
|
||||
echo '<div class="bbps-canned-replies-wrapper">';
|
||||
echo '<a href="#" class="bbps-toggle-canned-replies">' . __('Canned Replies', 'bbpress-support-toolkit') . '</a>';
|
||||
echo '<div class="bbps-canned-replies-list" style="display:none;">';
|
||||
|
||||
foreach ($replies as $reply) {
|
||||
echo '<div class="bbps-canned-reply-item" data-content="' . esc_attr($reply->post_content) . '">';
|
||||
echo '<strong>' . esc_html($reply->post_title) . '</strong>';
|
||||
echo '<p>' . wp_trim_words($reply->post_content, 20) . '</p>';
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
echo '</div>';
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
// Topic Lock Functionality
|
||||
public function add_topic_lock_link($links, $topic_id) {
|
||||
if (!current_user_can('moderate')) {
|
||||
return $links;
|
||||
}
|
||||
|
||||
// Ensure $links is an array
|
||||
if (!is_array($links)) {
|
||||
$links = array();
|
||||
}
|
||||
|
||||
// Get the correct topic ID
|
||||
if (empty($topic_id)) {
|
||||
$topic_id = bbp_get_topic_id();
|
||||
}
|
||||
$topic_id = (int) $topic_id;
|
||||
|
||||
$is_locked = get_post_meta($topic_id, '_bbps_topic_locked', true);
|
||||
|
||||
if ($is_locked) {
|
||||
$links['topic_lock'] = '<a href="#" class="bbps-topic-lock bbps-topic-lock-link" data-topic="' . $topic_id . '" data-topic-id="' . $topic_id . '" data-action="unlock">' . __('Unlock Topic', 'bbpress-support-toolkit') . '</a>';
|
||||
} else {
|
||||
$links['topic_lock'] = '<a href="#" class="bbps-topic-lock bbps-topic-lock-link" data-topic="' . $topic_id . '" data-topic-id="' . $topic_id . '" data-action="lock">' . __('Lock Topic', 'bbpress-support-toolkit') . '</a>';
|
||||
}
|
||||
|
||||
return $links;
|
||||
}
|
||||
|
||||
public function ajax_topic_lock() {
|
||||
check_ajax_referer('bbps_nonce', 'nonce');
|
||||
|
||||
if (!current_user_can('moderate')) {
|
||||
wp_send_json_error(__('Permission denied', 'bbpress-support-toolkit'));
|
||||
}
|
||||
|
||||
$topic_id = intval($_POST['topic_id']);
|
||||
$action = sanitize_text_field($_POST['action']) ?: sanitize_text_field($_POST['lock_action']);
|
||||
|
||||
if ($action === 'lock') {
|
||||
update_post_meta($topic_id, '_bbps_topic_locked', '1');
|
||||
// Close the topic
|
||||
bbp_close_topic($topic_id);
|
||||
$new_text = __('Unlock Topic', 'bbpress-support-toolkit');
|
||||
$is_locked = true;
|
||||
} else {
|
||||
delete_post_meta($topic_id, '_bbps_topic_locked');
|
||||
// Open the topic
|
||||
bbp_open_topic($topic_id);
|
||||
$new_text = __('Lock Topic', 'bbpress-support-toolkit');
|
||||
$is_locked = false;
|
||||
}
|
||||
|
||||
wp_send_json_success([
|
||||
'message' => __('Topic status updated', 'bbpress-support-toolkit'),
|
||||
'link_text' => $new_text,
|
||||
'is_locked' => $is_locked
|
||||
]);
|
||||
}
|
||||
|
||||
// Report Content Functionality
|
||||
public function add_report_link($links, $post_id) {
|
||||
if (!is_user_logged_in()) {
|
||||
return $links;
|
||||
}
|
||||
|
||||
// Ensure $links is an array
|
||||
if (!is_array($links)) {
|
||||
$links = array();
|
||||
}
|
||||
|
||||
// Get the correct post ID
|
||||
if (empty($post_id)) {
|
||||
$post_id = get_the_ID();
|
||||
}
|
||||
$post_id = (int) $post_id;
|
||||
|
||||
$links['report'] = '<a href="#" class="bbps-report-content bbps-report-link" data-post="' . $post_id . '" data-post-id="' . $post_id . '">' . __('Report', 'bbpress-support-toolkit') . '</a>';
|
||||
|
||||
return $links;
|
||||
}
|
||||
|
||||
public function add_report_link_to_content() {
|
||||
$post_id = get_the_ID();
|
||||
|
||||
if (!$post_id || !is_user_logged_in()) {
|
||||
return;
|
||||
}
|
||||
|
||||
echo '<div class="bbps-report-wrapper">';
|
||||
echo '<a href="#" class="bbps-report-content bbps-report-link" data-post="' . $post_id . '" data-post-id="' . $post_id . '">' . __('Report', 'bbpress-support-toolkit') . '</a>';
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
public function ajax_report_content() {
|
||||
check_ajax_referer('bbps_nonce', 'nonce');
|
||||
|
||||
if (!is_user_logged_in()) {
|
||||
wp_send_json_error(__('Please log in', 'bbpress-support-toolkit'));
|
||||
}
|
||||
|
||||
$post_id = intval($_POST['post_id']);
|
||||
$reason = sanitize_textarea_field($_POST['reason']);
|
||||
$user_id = get_current_user_id();
|
||||
|
||||
// Save report
|
||||
$report_data = [
|
||||
'post_id' => $post_id,
|
||||
'user_id' => $user_id,
|
||||
'reason' => $reason,
|
||||
'date' => current_time('mysql')
|
||||
];
|
||||
|
||||
$reports = get_option('bbps_content_reports', []);
|
||||
$reports[] = $report_data;
|
||||
update_option('bbps_content_reports', $reports);
|
||||
|
||||
// Notify administrators
|
||||
$admin_email = get_option('admin_email');
|
||||
$subject = sprintf(__('[%s] Content Reported', 'bbpress-support-toolkit'), get_bloginfo('name'));
|
||||
$message = sprintf(
|
||||
__('A user has reported content on your forum.\n\nPost ID: %d\nReported by: %s\nReason: %s\n\nPlease review this content.', 'bbpress-support-toolkit'),
|
||||
$post_id,
|
||||
get_user_by('id', $user_id)->display_name,
|
||||
$reason
|
||||
);
|
||||
|
||||
wp_mail($admin_email, $subject, $message);
|
||||
|
||||
wp_send_json_success(__('Content reported successfully', 'bbpress-support-toolkit'));
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize the enhanced features
|
||||
BBPS_Enhanced_Features::instance();
|
Loading…
Add table
Add a link
Reference in a new issue