Skip to content

Commit

Permalink
- Filter only for users who have written a comment #1220
Browse files Browse the repository at this point in the history
  • Loading branch information
olatechpro committed Sep 25, 2023
1 parent 3ede072 commit b83dc98
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 12 deletions.
37 changes: 28 additions & 9 deletions modules/editorial-comments/editorial-comments.php
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,8 @@ public function ajaxSearchPost()

public function ajaxSearchUser()
{
global $wpdb;

$ajax = Ajax::getInstance();

if (! isset($_GET['nonce']) || ! wp_verify_nonce(
Expand All @@ -370,7 +372,7 @@ public function ajaxSearchUser()
$ajax->sendJsonError(Error::ERROR_CODE_ACCESS_DENIED);
}

$queryText = isset($_GET['q']) ? sanitize_text_field($_GET['q']) : '';
$queryText = isset($_GET['search']) ? sanitize_text_field($_GET['search']) : '';

$output = [
'results' => [],
Expand All @@ -390,16 +392,33 @@ public function ajaxSearchUser()
$ajax->sendJson($output);
}

$user_args = [
'number' => 20,
'orderby' => 'display_name',
'capability' => 'edit_posts',
];
if (! empty($queryText)) {
$user_args['search'] = '*' . $queryText . '*';
// Define the custom SQL query to get users who have written comments
$commentType = self::comment_type;

$userSql = "SELECT DISTINCT u.ID, u.display_name
FROM {$wpdb->users} AS u
INNER JOIN {$wpdb->comments} AS c
ON u.ID = c.user_id
WHERE c.comment_type = %s";

if (!empty($queryText)) {
$userSql .= $wpdb->prepare(
" AND (user_login LIKE %s
OR user_url LIKE %s
OR user_email LIKE %s
OR user_nicename LIKE %s
OR display_name LIKE %s)",
'%' . $wpdb->esc_like($queryText) . '%',
'%' . $wpdb->esc_like($queryText) . '%',
'%' . $wpdb->esc_like($queryText) . '%',
'%' . $wpdb->esc_like($queryText) . '%',
'%' . $wpdb->esc_like($queryText) . '%'
);
}

$users = get_users($user_args);
$userSql .= " ORDER BY u.display_name LIMIT 20";

$users = $wpdb->get_results($wpdb->prepare($userSql, $commentType));

foreach ($users as $user) {
$results[] = [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
jQuery(function ($) {
if (ppNotif.log_url !== '' && $('body').hasClass('post-type-psppnotif_workflow') && $('.wrap .page-title-action').length > 0) {
var customButton = ' &nbsp; <a href="' + ppNotif.log_url + '" class="page-title-action">' + ppNotif.log_text + '</a>';
var customButton = ' &nbsp; <a href="' + ppNotif.log_url + '" class="page-title-action">' + ppNotif.log_text + ' (' + ppNotif.log_total + ')</a>';
$('.wrap .page-title-action').after(customButton);
}
});
16 changes: 14 additions & 2 deletions modules/improved-notifications/improved-notifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
use PublishPress\Notifications\Workflow\Step\Event_Content\Filter\Post_Type as Post_Type_Filter;
use PublishPress\Notifications\Workflow\Step\Event_Content\Post_Type;
use PublishPress\Notifications\Workflow\Step\Receiver\Site_Admin as Receiver_Site_Admin;
use PublishPress\NotificationsLog\NotificationsLogHandler;

if (! class_exists('PP_Improved_Notifications')) {
/**
Expand Down Expand Up @@ -720,13 +721,24 @@ public function add_admin_scripts($hook_suffix)
PUBLISHPRESS_VERSION,
true
);

if ($this->module_enabled('notifications_log')) {
$logHandler = new NotificationsLogHandler();
$log_url = admin_url('admin.php?page=pp-notif-log');
$log_total = number_format_i18n($logHandler->getNotificationLogEntries(null, null, null, true));
} else {
$log_url = '';
$log_total = '';

}

wp_localize_script(
'improved-notifications-js',
'ppNotif',
[
'log_url' => ($this->module_enabled('notifications_log')) ? admin_url('admin.php?page=pp-notif-log') : '',
'log_text' => esc_html__('Notifications Log', 'publishpress'),
'log_total' => $log_total,
'log_url' => $log_url,
'log_text' => esc_html__('Notifications Log', 'publishpress'),
]
);
}
Expand Down

0 comments on commit b83dc98

Please sign in to comment.