Restore to commit 74e578279624c6045ca440a3459ebfa1f8d54191

This commit is contained in:
southseact-3d
2026-02-07 20:32:41 +00:00
commit ed67b7741b
252 changed files with 99814 additions and 0 deletions

View File

@@ -0,0 +1,255 @@
<?php
class PC_Community_Suggestions_Admin {
public function __construct() {
add_action('admin_menu', array($this, 'add_admin_menu'));
add_action('admin_init', array($this, 'register_settings'));
add_action('admin_post_pc_delete_suggestion', array($this, 'handle_suggestion_deletion'));
}
public function add_admin_menu() {
add_menu_page(
__('Community Suggestions', 'pc-community-suggestions-7d3f'),
__('Suggestions', 'pc-community-suggestions-7d3f'),
'manage_options',
'pc_community_suggestions',
array($this, 'render_admin_page'),
'dashicons-lightbulb',
30
);
add_submenu_page(
'pc_community_suggestions',
__('All Suggestions', 'pc-community-suggestions-7d3f'),
__('All Suggestions', 'pc-community-suggestions-7d3f'),
'manage_options',
'pc_community_suggestions',
array($this, 'render_admin_page')
);
add_submenu_page(
'pc_community_suggestions',
__('Settings', 'pc-community-suggestions-7d3f'),
__('Settings', 'pc-community-suggestions-7d3f'),
'manage_options',
'pc_community_suggestions_settings',
array($this, 'render_settings_page')
);
}
public function register_settings() {
register_setting('pc_community_suggestions_settings', 'pc_community_suggestions_default_sort');
add_settings_section(
'pc_community_suggestions_general',
__('General Settings', 'pc-community-suggestions-7d3f'),
array($this, 'render_settings_section'),
'pc_community_suggestions_settings'
);
add_settings_field(
'pc_community_suggestions_default_sort',
__('Default Sort Order', 'pc-community-suggestions-7d3f'),
array($this, 'render_sort_field'),
'pc_community_suggestions_settings',
'pc_community_suggestions_general'
);
}
public function render_settings_section() {
echo '<p>' . __('Configure how community suggestions work on your site.', 'pc-community-suggestions-7d3f') . '</p>';
}
public function render_sort_field() {
$default_sort = get_option('pc_community_suggestions_default_sort', 'popular');
?>
<select name="pc_community_suggestions_default_sort">
<option value="popular" <?php selected($default_sort, 'popular'); ?>><?php esc_html_e('Most Upvoted', 'pc-community-suggestions-7d3f'); ?></option>
<option value="newest" <?php selected($default_sort, 'newest'); ?>><?php esc_html_e('Newest', 'pc-community-suggestions-7d3f'); ?></option>
</select>
<p class="description">
<?php esc_html_e('Default sorting method for the suggestions page.', 'pc-community-suggestions-7d3f'); ?>
</p>
<?php
}
public function render_admin_page() {
$current_tab = $_GET['tab'] ?? 'all';
$sort = isset($_GET['sort']) && in_array($_GET['sort'], ['popular', 'newest']) ? $_GET['sort'] : 'newest';
?>
<div class="wrap">
<h1><?php esc_html_e('Community Suggestions', 'pc-community-suggestions-7d3f'); ?></h1>
<div class="pc-admin-controls">
<div class="pc-sort-dropdown">
<label for="pc-admin-sort"><?php esc_html_e('Sort by:', 'pc-community-suggestions-7d3f'); ?></label>
<select id="pc-admin-sort" onchange="window.location.href='?page=pc_community_suggestions&sort=' + this.value">
<option value="newest" <?php selected($sort, 'newest'); ?>><?php esc_html_e('Newest', 'pc-community-suggestions-7d3f'); ?></option>
<option value="popular" <?php selected($sort, 'popular'); ?>><?php esc_html_e('Most Upvoted', 'pc-community-suggestions-7d3f'); ?></option>
</select>
</div>
</div>
<div class="pc-admin-content">
<?php $this->render_suggestions_table($sort); ?>
</div>
</div>
<?php
}
public function render_settings_page() {
?>
<div class="wrap">
<h1><?php esc_html_e('Community Suggestions Settings', 'pc-community-suggestions-7d3f'); ?></h1>
<form method="post" action="options.php">
<?php
settings_fields('pc_community_suggestions_settings');
do_settings_sections('pc_community_suggestions_settings');
submit_button();
?>
</form>
<div class="pc-settings-stats">
<h2><?php esc_html_e('Statistics', 'pc-community-suggestions-7d3f'); ?></h2>
<div class="pc-stats-grid">
<div class="pc-stat-card">
<h3><?php echo esc_html(PC_Community_Suggestions_Database::get_suggestion_count()); ?></h3>
<p><?php esc_html_e('Total Suggestions', 'pc-community-suggestions-7d3f'); ?></p>
</div>
</div>
</div>
</div>
<?php
}
private function render_suggestions_table($sort = 'newest') {
global $wpdb;
$table_name = $wpdb->prefix . 'pc_community_suggestions';
$order_by = $sort === 'newest' ? 'created_at DESC' : 'upvotes DESC, created_at DESC';
$suggestions = $wpdb->get_results(
"SELECT s.*, u.user_login, u.display_name
FROM $table_name s
LEFT JOIN {$wpdb->users} u ON s.user_id = u.ID
ORDER BY $order_by"
);
?>
<table class="wp-list-table widefat fixed striped">
<thead>
<tr>
<th><?php esc_html_e('Title', 'pc-community-suggestions-7d3f'); ?></th>
<th><?php esc_html_e('Author', 'pc-community-suggestions-7d3f'); ?></th>
<th><?php esc_html_e('Upvotes', 'pc-community-suggestions-7d3f'); ?></th>
<th><?php esc_html_e('Date', 'pc-community-suggestions-7d3f'); ?></th>
<th><?php esc_html_e('Actions', 'pc-community-suggestions-7d3f'); ?></th>
</tr>
</thead>
<tbody>
<?php if (empty($suggestions)) : ?>
<tr>
<td colspan="5"><?php esc_html_e('No suggestions found.', 'pc-community-suggestions-7d3f'); ?></td>
</tr>
<?php else : ?>
<?php foreach ($suggestions as $suggestion) : ?>
<tr>
<td>
<strong><?php echo esc_html($suggestion->title); ?></strong>
<div class="row-actions">
<span class="view">
<a href="#" onclick="pcPreviewSuggestion(<?php echo esc_attr($suggestion->id); ?>)">
<?php esc_html_e('View Details', 'pc-community-suggestions-7d3f'); ?>
</a> |
</span>
<span class="comment">
<a href="#" onclick="pcAddComment(<?php echo esc_attr($suggestion->id); ?>)">
<?php esc_html_e('Add Comment', 'pc-community-suggestions-7d3f'); ?>
</a>
</span>
</div>
</td>
<td><?php echo esc_html($suggestion->display_name ?: $suggestion->user_login); ?></td>
<td><?php echo esc_html($suggestion->upvotes); ?></td>
<td><?php echo date_i18n(get_option('date_format'), strtotime($suggestion->created_at)); ?></td>
<td>
<a href="<?php echo wp_nonce_url(admin_url('admin-post.php?action=pc_delete_suggestion&id=' . $suggestion->id), 'pc_delete_suggestion_' . $suggestion->id); ?>"
class="button button-small button-link-delete"
onclick="return confirm('<?php esc_attr_e('Are you sure you want to delete this suggestion?', 'pc-community-suggestions-7d3f'); ?>')">
<?php esc_html_e('Delete', 'pc-community-suggestions-7d3f'); ?>
</a>
</td>
</tr>
<tr id="pc-comments-<?php echo esc_attr($suggestion->id); ?>" class="pc-comments-row" style="display: none;">
<td colspan="5" class="pc-comments-cell">
<div class="pc-comments-container">
<h4><?php esc_html_e('Admin Comments', 'pc-community-suggestions-7d3f'); ?></h4>
<div class="pc-comments-list" id="pc-comments-list-<?php echo esc_attr($suggestion->id); ?>">
<?php
$comments = PC_Community_Suggestions_Database::get_comments($suggestion->id);
if (empty($comments)) {
echo '<p class="pc-no-comments">' . esc_html__('No comments yet.', 'pc-community-suggestions-7d3f') . '</p>';
} else {
foreach ($comments as $comment) {
echo '<div class="pc-comment-item" data-comment-id="' . esc_attr($comment->id) . '">';
echo '<div class="pc-comment-header">';
echo '<strong>' . esc_html($comment->display_name ?: $comment->user_login) . '</strong>';
echo '<span class="pc-comment-date">' . esc_html(date_i18n(get_option('date_format'), strtotime($comment->created_at))) . '</span>';
echo '</div>';
echo '<div class="pc-comment-content">' . wp_kses_post(wpautop($comment->comment)) . '</div>';
echo '<div class="pc-comment-actions">';
echo '<button class="button button-small button-link-delete" onclick="pcDeleteComment(' . esc_attr($comment->id) . ')">' . esc_html__('Delete', 'pc-community-suggestions-7d3f') . '</button>';
echo '</div>';
echo '</div>';
}
}
?>
</div>
<div class="pc-add-comment">
<h5><?php esc_html_e('Add Comment', 'pc-community-suggestions-7d3f'); ?></h5>
<textarea id="pc-comment-<?php echo esc_attr($suggestion->id); ?>" rows="3" placeholder="<?php esc_attr_e('Enter your comment...', 'pc-community-suggestions-7d3f'); ?>"></textarea>
<button type="button" class="button button-small" onclick="pcSubmitComment(<?php echo esc_attr($suggestion->id); ?>)">
<?php esc_html_e('Add Comment', 'pc-community-suggestions-7d3f'); ?>
</button>
</div>
</div>
</td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</tbody>
</table>
<?php
}
public function handle_suggestion_deletion() {
if (!current_user_can('manage_options')) {
wp_die(__('You do not have permission to perform this action.', 'pc-community-suggestions-7d3f'));
}
$suggestion_id = intval($_GET['id'] ?? 0);
check_admin_referer('pc_delete_suggestion_' . $suggestion_id);
if ($suggestion_id > 0) {
PC_Community_Suggestions_Database::delete_suggestion($suggestion_id);
wp_redirect(admin_url('admin.php?page=pc_community_suggestions&deleted=1'));
exit;
}
wp_redirect(admin_url('admin.php?page=pc_community_suggestions&error=1'));
exit;
}
}

View File

@@ -0,0 +1,552 @@
/* Community Suggestions Admin Styles */
.pc-admin-content {
/* Admin-scoped palette to keep admin UI consistent */
--pc-admin-primary: #2271b1;
--pc-admin-primary-strong: #135e96;
--pc-admin-muted: #646970;
--pc-admin-bg: #fff;
margin-top: 20px;
padding: 18px 0;
}
/* Admin button enforcement */
.pc-admin-content .pc-button {
border-radius: 6px;
}
.pc-admin-content .pc-button-primary {
background: var(--pc-admin-primary) !important;
border-color: var(--pc-admin-primary) !important;
color: #fff !important;
}
.wp-list-table .row-actions .view,
.wp-list-table .row-actions .comment {
color: var(--pc-admin-primary);
}
.pc-admin-controls {
display: flex;
justify-content: flex-end;
align-items: center;
margin-bottom: 15px;
gap: 15px;
}
.pc-sort-dropdown {
display: flex;
align-items: center;
gap: 8px;
}
.pc-sort-dropdown label {
font-weight: 600;
color: #1d2327;
font-size: 13px;
}
.pc-sort-dropdown select {
padding: 6px 12px;
border: 1px solid #8c8f94;
border-radius: 4px;
background: #fff;
font-size: 13px;
}
.pc-sort-dropdown select:focus {
outline: none;
border-color: #2271b1;
box-shadow: 0 0 0 1px #2271b1;
}
.pc-comment-item {
background: #2c3338;
border-color: #3c434a;
border-left-color: #2271b1;
}
.pc-add-comment textarea {
background: #1d2327;
border-color: #3c434a;
color: #dcdcde;
}
.pc-add-comment textarea:focus {
border-color: #2271b1;
box-shadow: 0 0 0 2px rgba(34, 113, 177, 0.2);
}
.pc-no-comments {
background: #2c3338;
border-color: #3c434a;
color: #9ca1a7;
}
.pc-settings-stats {
margin-top: 30px;
border-top: 1px solid #ccd0d4;
padding-top: 30px;
}
.pc-stats-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 20px;
margin-top: 20px;
}
.pc-stat-card {
background: #fff;
border: 1px solid #ccd0d4;
border-radius: 4px;
padding: 20px;
text-align: center;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}
.pc-stat-card h3 {
font-size: 2em;
font-weight: bold;
color: #2271b1;
margin: 0 0 10px 0;
}
.pc-stat-card p {
color: #646970;
margin: 0;
font-size: 14px;
}
/* Status badges */
.pc-status {
display: inline-block;
padding: 4px 8px;
border-radius: 12px;
font-size: 11px;
font-weight: 600;
text-transform: uppercase;
line-height: 1;
}
.pc-status-pending {
background: #fff0c2;
color: #946c00;
border: 1px solid #ffd54f;
}
.pc-status-approved {
background: #e7f5e7;
color: #2a6b2a;
border: 1px solid #8bc34a;
}
.pc-status-rejected {
background: #fbe7e7;
color: #b32d2e;
border: 1px solid #f44336;
}
/* Table improvements */
.wp-list-table .pc-status {
margin-right: 8px;
}
.wp-list-table .row-actions {
margin-top: 4px;
}
.wp-list-table .row-actions .view,
.wp-list-table .row-actions .comment {
color: #2271b1;
}
.wp-list-table .row-actions .comment {
margin-left: 8px;
}
/* Comments styles */
.pc-comments-row {
background: #f9f9f9 !important;
}
.pc-comments-cell {
padding: 0 !important;
}
.pc-comments-container {
padding: 20px;
}
.pc-comments-container h4 {
margin: 0 0 15px 0;
font-size: 14px;
font-weight: 600;
color: #111;
}
.pc-comments-list {
margin-bottom: 20px;
}
.pc-comment-item {
background: #fff;
border: 1px solid #dcdcde;
border-radius: 6px;
padding: 15px;
margin-bottom: 15px;
border-left: 3px solid #2271b1;
}
/* Remove purple accents from admin comments: override public styles that use purple */
.pc-comments-container .pc-comment-card,
.pc-comments-container .pc-comment-item,
.pc-comments-container .pc-comments-section {
border-left-color: var(--pc-admin-primary) !important; /* use admin blue */
border-color: #dcdcde !important;
background: #fff !important;
color: #111 !important;
box-shadow: 0 1px 3px rgba(0,0,0,0.06) !important;
}
/* Make comment headers readable */
.pc-comments-container .pc-comment-header strong,
.pc-comments-container .pc-comment-content {
color: #111 !important;
}
.pc-comment-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 10px;
}
.pc-comment-header strong {
font-weight: 600;
color: #dcdcde;
font-size: 13px;
}
.pc-sort-dropdown label {
color: #dcdcde;
}
.pc-comment-date {
color: #646970;
font-size: 12px;
font-style: italic;
}
.pc-comment-content {
line-height: 1.5;
color: #c3c4c7;
font-size: 13px;
margin-bottom: 10px;
}
.pc-comment-actions {
text-align: right;
}
.pc-no-comments {
text-align: center;
color: #646970;
font-style: italic;
padding: 15px;
background: #fff;
border: 1px dashed #dcdcde;
border-radius: 6px;
}
.pc-add-comment {
border-top: 1px solid #e0e0e0;
padding-top: 15px;
}
.pc-add-comment h5 {
margin: 0 0 10px 0;
font-size: 13px;
font-weight: 600;
color: #dcdcde;
}
.pc-add-comment textarea {
width: 100%;
min-height: 80px;
padding: 10px;
border: 1px solid #dcdcde;
border-radius: 6px;
font-size: 13px;
font-family: inherit;
resize: vertical;
margin-bottom: 10px;
}
.pc-add-comment textarea:focus {
outline: none;
border-color: #2271b1;
box-shadow: 0 0 0 2px rgba(34, 113, 177, 0.1);
}
/* Form styles */
.pc-form-group {
margin-bottom: 20px;
}
.pc-form-group label {
display: block;
font-weight: 600;
margin-bottom: 5px;
color: #1d2327;
}
.pc-form-group input[type="text"],
.pc-form-group textarea {
width: 100%;
max-width: 400px;
padding: 8px 12px;
border: 1px solid #8c8f94;
border-radius: 4px;
font-size: 14px;
line-height: 1.4;
}
.pc-form-group input[type="text"]:focus,
.pc-form-group textarea:focus {
border-color: #2271b1;
box-shadow: 0 0 0 1px #2271b1;
outline: none;
}
.pc-form-actions {
display: flex;
gap: 10px;
margin-top: 20px;
}
/* Button styles */
.pc-button {
display: inline-block;
padding: 8px 16px;
border: 1px solid #2271b1;
border-radius: 4px;
background: #2271b1;
color: #fff;
text-decoration: none;
font-size: 13px;
font-weight: 400;
line-height: 1.4;
cursor: pointer;
transition: all 0.15s ease-in-out;
}
.pc-button:hover {
background: #135e96;
border-color: #135e96;
color: #fff;
}
.pc-button:active {
background: #0a4b78;
border-color: #0a4b78;
}
.pc-button-primary {
background: #2271b1;
border-color: #2271b1;
}
.pc-button-primary:hover {
background: #135e96;
border-color: #135e96;
}
.pc-button-secondary {
background: #f6f7f7;
border-color: #dcdcde;
color: #2c3338;
}
.pc-button-secondary:hover {
background: #dcdcde;
border-color: #c3c4c7;
}
/* Card styles */
.pc-card {
background: #fff;
border: 1px solid #ccd0d4;
border-radius: 4px;
padding: 20px;
margin-bottom: 20px;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}
.pc-card h3 {
margin: 0 0 15px 0;
color: #1d2327;
font-size: 16px;
font-weight: 600;
}
/* Responsive design */
@media screen and (max-width: 782px) {
.pc-stats-grid {
grid-template-columns: 1fr;
gap: 15px;
}
.pc-stat-card {
padding: 15px;
}
.pc-stat-card h3 {
font-size: 1.5em;
}
.pc-form-group input[type="text"],
.pc-form-group textarea {
max-width: 100%;
}
.pc-form-actions {
flex-direction: column;
gap: 10px;
}
.wp-list-table {
font-size: 14px;
}
.wp-list-table th,
.wp-list-table td {
padding: 8px 10px;
}
}
/* Dark mode support */
@media (prefers-color-scheme: dark) {
.pc-stat-card,
.pc-card {
background: #2c3338;
border-color: #3c434a;
}
.pc-stat-card p,
.pc-form-group label {
color: #dcdcde;
}
.pc-form-group input[type="text"],
.pc-form-group textarea {
background: #1d2327;
border-color: #3c434a;
color: #dcdcde;
}
.pc-form-group input[type="text"]:focus,
.pc-form-group textarea:focus {
border-color: #2271b1;
box-shadow: 0 0 0 1px #2271b1;
}
.pc-button-secondary {
background: #3c434a;
border-color: #4f5660;
color: #dcdcde;
}
.pc-button-secondary:hover {
background: #4f5660;
border-color: #646970;
}
}
/* Print styles */
@media print {
.pc-stats-grid {
grid-template-columns: repeat(3, 1fr);
gap: 15px;
}
.pc-stat-card {
border: 1px solid #000;
background: #fff !important;
color: #000 !important;
}
.pc-stat-card h3 {
color: #000 !important;
}
.pc-button {
display: none;
}
}
/* Animation for status changes */
@keyframes pc-fade-in {
from {
opacity: 0;
transform: translateY(-10px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
.pc-stat-card,
.pc-card {
animation: pc-fade-in 0.3s ease-in-out;
}
/* Loading states */
.pc-loading {
opacity: 0.6;
pointer-events: none;
}
.pc-loading::after {
content: '';
display: inline-block;
width: 16px;
height: 16px;
border: 2px solid #f3f3f3;
border-top: 2px solid #2271b1;
border-radius: 50%;
animation: pc-spin 1s linear infinite;
margin-left: 8px;
vertical-align: middle;
}
@keyframes pc-spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
/* Success/error messages */
.pc-notice {
padding: 12px;
border-radius: 4px;
margin-bottom: 20px;
border-left: 4px solid;
}
.pc-notice-success {
background: #edfaef;
border-color: #00a32a;
color: #2a6b2a;
}
.pc-notice-error {
background: #fcf0f1;
border-color: #d63638;
color: #b32d2e;
}
.pc-notice-info {
background: #f0f6ff;
border-color: #2271b1;
color: #135e96;
}

View File

@@ -0,0 +1,369 @@
jQuery(document).ready(function($) {
// View suggestion details modal
window.pcPreviewSuggestion = function(suggestionId) {
$.ajax({
url: pcCommunitySuggestionsAdmin.ajax_url,
type: 'POST',
data: {
action: 'pc_get_suggestion',
suggestion_id: suggestionId,
nonce: pcCommunitySuggestionsAdmin.nonce
},
success: function(response) {
if (response.success) {
pcShowSuggestionModal(response.data);
} else {
alert(pcCommunitySuggestionsAdmin.i18n.action_failed + ': ' + response.data.message);
}
},
error: function() {
alert(pcCommunitySuggestionsAdmin.i18n.action_failed);
}
});
};
function pcShowSuggestionModal(suggestion) {
const modalHtml = `
<div class="pc-modal" style="display: none;">
<div class="pc-modal-overlay"></div>
<div class="pc-modal-content">
<div class="pc-modal-header">
<h3>${suggestion.title}</h3>
<button class="pc-modal-close" onclick="pcCloseModal()">&times;</button>
</div>
<div class="pc-modal-body">
<div class="pc-suggestion-content">
${suggestion.content}
</div>
<div class="pc-suggestion-meta">
<p><strong>Author:</strong> ${suggestion.author}</p>
<p><strong>Submitted:</strong> ${suggestion.date}</p>
<p><strong>Upvotes:</strong> ${suggestion.upvotes}</p>
</div>
</div>
<div class="pc-modal-footer">
<button class="button button-primary" onclick="pcCloseModal()">Close</button>
</div>
</div>
</div>
`;
$('body').append(modalHtml);
$('.pc-modal').fadeIn(200);
// Prevent background scrolling
$('body').css('overflow', 'hidden');
}
window.pcCloseModal = function() {
$('.pc-modal').fadeOut(200, function() {
$(this).remove();
});
$('body').css('overflow', '');
};
// Add comment functionality
window.pcAddComment = function(suggestionId) {
var $commentsRow = $('#pc-comments-' + suggestionId);
$commentsRow.slideToggle();
};
window.pcSubmitComment = function(suggestionId) {
var $textarea = $('#pc-comment-' + suggestionId);
var comment = $textarea.val().trim();
if (!comment) {
alert('Please enter a comment.');
return;
}
var $button = $textarea.siblings('button');
var originalText = $button.text();
$button.prop('disabled', true).text('Adding...');
$.ajax({
url: pcCommunitySuggestionsAdmin.ajax_url,
type: 'POST',
data: {
action: 'pc_add_comment',
suggestion_id: suggestionId,
comment: comment,
nonce: pcCommunitySuggestionsAdmin.nonce
},
success: function(response) {
if (response.success) {
var commentHtml = '<div class="pc-comment-item" data-comment-id="' + response.data.comment.id + '">' +
'<div class="pc-comment-header">' +
'<strong>' + response.data.comment.author + '</strong> ' +
'<span class="pc-comment-date">' + response.data.comment.date + '</span>' +
'</div>' +
'<div class="pc-comment-content">' + response.data.comment.content + '</div>' +
'<div class="pc-comment-actions">' +
'<button class="button button-small button-link-delete" onclick="pcDeleteComment(' + response.data.comment.id + ')">Delete</button>' +
'</div>' +
'</div>';
var $commentsList = $('#pc-comments-list-' + suggestionId);
$commentsList.find('.pc-no-comments').remove();
$commentsList.append(commentHtml);
$textarea.val('');
alert(response.data.message);
} else {
alert(response.data.message || pcCommunitySuggestionsAdmin.i18n.action_failed);
}
},
error: function() {
alert(pcCommunitySuggestionsAdmin.i18n.action_failed);
},
complete: function() {
$button.prop('disabled', false).text(originalText);
}
});
};
window.pcDeleteComment = function(commentId) {
if (!confirm('Are you sure you want to delete this comment?')) {
return;
}
$.ajax({
url: pcCommunitySuggestionsAdmin.ajax_url,
type: 'POST',
data: {
action: 'pc_delete_comment',
comment_id: commentId,
nonce: pcCommunitySuggestionsAdmin.nonce
},
success: function(response) {
if (response.success) {
$('.pc-comment-item[data-comment-id="' + commentId + '"]').fadeOut(300, function() {
$(this).remove();
});
alert(response.data.message);
} else {
alert(response.data.message || pcCommunitySuggestionsAdmin.i18n.action_failed);
}
},
error: function() {
alert(pcCommunitySuggestionsAdmin.i18n.action_failed);
}
});
};
// Close modal on overlay click
$(document).on('click', '.pc-modal-overlay', function(e) {
if (e.target === this) {
pcCloseModal();
}
});
// Close modal on ESC key
$(document).on('keydown', function(e) {
if (e.key === 'Escape' && $('.pc-modal').is(':visible')) {
pcCloseModal();
}
});
// Add modal styles
$('<style>')
.text(`
.pc-modal {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 99999;
display: flex;
align-items: center;
justify-content: center;
}
.pc-modal-overlay {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.5);
}
.pc-modal-content {
background: #fff;
border-radius: 8px;
box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
max-width: 600px;
width: 90%;
max-height: 80vh;
overflow: hidden;
display: flex;
flex-direction: column;
z-index: 100000;
position: relative;
}
.pc-modal-header {
padding: 20px 25px;
border-bottom: 1px solid #dcdcde;
display: flex;
align-items: center;
justify-content: space-between;
}
.pc-modal-header h3 {
margin: 0;
font-size: 1.3em;
color: #1d2327;
flex: 1;
margin-right: 20px;
}
.pc-modal-close {
background: none;
border: none;
font-size: 24px;
cursor: pointer;
padding: 0;
width: 30px;
height: 30px;
line-height: 1;
color: #646970;
}
.pc-modal-close:hover {
color: #2271b1;
}
.pc-modal-body {
padding: 25px;
flex: 1;
overflow-y: auto;
}
.pc-suggestion-content {
margin-bottom: 20px;
line-height: 1.6;
color: #2c3338;
}
.pc-suggestion-content p {
margin: 0 0 15px 0;
}
.pc-suggestion-content p:last-child {
margin-bottom: 0;
}
.pc-suggestion-meta {
border-top: 1px solid #dcdcde;
padding-top: 20px;
font-size: 14px;
}
.pc-suggestion-meta p {
margin: 0 0 8px 0;
}
.pc-suggestion-meta p:last-child {
margin-bottom: 0;
}
.pc-modal-footer {
padding: 20px 25px;
border-top: 1px solid #dcdcde;
text-align: right;
}
@media screen and (max-width: 782px) {
.pc-modal-content {
width: 95%;
margin: 20px;
}
.pc-modal-header {
padding: 15px 20px;
}
.pc-modal-body {
padding: 20px;
}
.pc-modal-footer {
padding: 15px 20px;
}
}
/* Dark mode support */
@media (prefers-color-scheme: dark) {
.pc-modal-content {
background: #2c3338;
border: 1px solid #3c434a;
}
.pc-modal-header,
.pc-modal-footer {
border-color: #3c434a;
}
.pc-modal-header h3 {
color: #dcdcde;
}
.pc-modal-close {
color: #9ca1a7;
}
.pc-modal-close:hover {
color: #2271b1;
}
.pc-suggestion-content {
color: #c3c4c7;
}
.pc-suggestion-meta {
border-color: #3c434a;
}
}
`)
.appendTo('head');
// Handle bulk actions
$('.pc-bulk-action').on('change', function() {
const action = $(this).val();
if (action) {
const checked = $('.pc-bulk-checkbox:checked');
if (checked.length === 0) {
alert(pcCommunitySuggestionsAdmin.i18n.no_items_selected);
$(this).val('');
return;
}
const suggestionIds = checked.map(function() {
return $(this).val();
}).get();
if (confirm(pcCommunitySuggestionsAdmin.i18n.confirm_bulk_action.replace('{count}', checked.length).replace('{action}', action))) {
$.ajax({
url: pcCommunitySuggestionsAdmin.ajax_url,
type: 'POST',
data: {
action: 'pc_get_stats',
nonce: pcCommunitySuggestionsAdmin.nonce
},
success: function(response) {
if (response.success) {
$('#pc-stat-total').text(response.data.total);
}
}
});
}
// Update stats every 30 seconds if on stats page
if ($('.pc-settings-stats').length) {
setInterval(pcUpdateStats, 30000);
}
});