Plugin Directory

Changeset 3841198


Ignore:
Timestamp:
12/02/2026 09:53:05 PM (less than one hour ago)
Author:
sherpadigital
Message:

Update to version 0.3.3 from GitHub

Location:
sherpa-form-log
Files:
9 edited
1 copied

Legend:

Unmodified
Added
Removed
  • sherpa-form-log/tags/0.3.3/assets/admin.css

    r3841170 r3841198  
    1414    overflow-wrap: anywhere;
    1515}
     16
     17.sherpa-form-log-filters,
     18.sherpa-form-log-filter-actions {
     19    display: flex;
     20    flex-wrap: wrap;
     21    align-items: center;
     22    gap: 8px 6px;
     23}
     24
     25.sherpa-form-log-filters {
     26    margin: 1em 0;
     27}
     28
     29.sherpa-form-log-filters label {
     30    display: inline-flex;
     31    align-items: center;
     32    gap: 4px;
     33    max-width: 100%;
     34}
     35
     36.sherpa-form-log-filters label :is(input, select) {
     37    min-width: 0;
     38}
  • sherpa-form-log/tags/0.3.3/assets/admin.js

    r3841170 r3841198  
    88        });
    99    }
     10    const bulk = document.querySelector('.sherpa-form-log-bulk');
     11    const selectAll = bulk?.querySelector('.sherpa-form-log-select-all');
     12    if (!selectAll) {
     13        return;
     14    }
     15
     16    const entries = [...bulk.querySelectorAll('input[name="entries[]"]')];
     17    const action = bulk.querySelector('[name="bulk_action"]');
     18    const status = bulk.querySelector('[role="status"]');
     19    const selectedCount = () => entries.filter(entry => entry.checked).length;
     20    const syncSelection = () => {
     21        const count = selectedCount();
     22        selectAll.checked = count === entries.length;
     23        selectAll.indeterminate = count > 0 && count < entries.length;
     24        status.textContent = '';
     25    };
     26
     27    selectAll.disabled = false;
     28    action.querySelector('[value="delete"]').disabled = false;
     29    selectAll.addEventListener('change', () => {
     30        entries.forEach(entry => { entry.checked = selectAll.checked; });
     31        syncSelection();
     32    });
     33    entries.forEach(entry => entry.addEventListener('change', syncSelection));
     34    syncSelection();
     35    bulk.addEventListener('submit', event => {
     36        const count = selectedCount();
     37        if (count === 0) {
     38            event.preventDefault();
     39            status.textContent = bulk.dataset.selectEntry;
     40            selectAll.focus();
     41            return;
     42        }
     43        if (action.value === 'delete') {
     44            const message = count === 1
     45                ? bulk.dataset.confirmOne
     46                : bulk.dataset.confirmMany.replace('%d', count);
     47            if (!window.confirm(message)) {
     48                event.preventDefault();
     49            }
     50        }
     51    });
    1052})();
  • sherpa-form-log/tags/0.3.3/readme.txt

    r3841170 r3841198  
    55Tested up to: 7.1
    66Requires PHP: 7.4
    7 Stable tag: 0.3.2
     7Stable tag: 0.3.3
    88License: GPL-2.0-or-later
    99License URI: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
    … …  
    4747== Screenshots ==
    4848
    49 1. Form submissions with filters, read status and CSV export. Email and source addresses are redacted.
     491. Form submissions with filters, bulk actions, read status and CSV export. Email and source addresses are redacted.
    5050
    5151== Changelog ==
     52
     53= 0.3.3 =
     54* Mark selected entries as read or permanently delete them from the submissions list.
     55* Improve spacing when the filter controls wrap.
    5256
    5357= 0.3.2 =
  • sherpa-form-log/tags/0.3.3/sherpa-form-log.php

    r3841170 r3841198  
    44 * Plugin URI: https://sherpadigital.com.au/sherpa-form-log/
    55 * Description: Save submissions from Elementor Pro, Divi, Gravity Forms and Contact Form 7.
    6  * Version: 0.3.2
     6 * Version: 0.3.3
    77 * Requires at least: 6.2
    88 * Requires PHP: 7.4
    … …  
    1919
    2020final class Plugin {
    21     private const VERSION = '0.3.2';
     21    private const VERSION = '0.3.3';
    2222    private const PAGE = 'sherpa-form-log';
    2323    private const SCHEMA = '2';
    … …  
    3939        add_action('admin_menu', [self::class, 'menu'], 100);
    4040        add_action('admin_post_sherpa_form_log_delete', [self::class, 'delete_entry']);
     41        add_action('admin_post_sherpa_form_log_bulk', [self::class, 'bulk_entries']);
    4142        add_action('admin_post_sherpa_form_log_export', [self::class, 'export']);
    4243    }
    … …  
    420421        }
    421422
     423        $bulk_result = self::input('bulk_result');
     424        if (in_array($bulk_result, ['read', 'delete'], true)) {
     425            $count = absint(self::input('affected'));
     426            $message = $bulk_result === 'read'
     427                ? _n('%s entry marked as read.', '%s entries marked as read.', $count, 'sherpa-form-log')
     428                : _n('%s entry deleted.', '%s entries deleted.', $count, 'sherpa-form-log');
     429            echo '<div class="notice notice-success is-dismissible"><p>' . esc_html(sprintf($message, number_format_i18n($count))) . '</p></div>';
     430        }
     431
    422432        $where = self::where($filters, $args);
    423433        $total = (int) $wpdb->get_var($wpdb->prepare(
    … …  
    439449        <form method="get" action="<?php echo esc_url(strtok($base, '?')); ?>">
    440450            <input type="hidden" name="page" value="<?php echo esc_attr(self::PAGE); ?>">
    441             <p>
     451            <div class="sherpa-form-log-filters">
    442452                <label>Search <input type="search" name="q" value="<?php echo esc_attr($filters['q']); ?>"></label>
    443453                <label>Form <select name="form">
    … …  
    454464                <label>From <input type="date" name="from" value="<?php echo esc_attr($filters['from']); ?>"></label>
    455465                <label>To <input type="date" name="to" value="<?php echo esc_attr($filters['to']); ?>"></label>
    456                 <?php submit_button('Filter', 'secondary', 'filter', false); ?>
    457                 <a class="button" href="<?php echo esc_url($base); ?>">Reset</a>
    458                 <a class="button" href="<?php echo esc_url($export); ?>">Export filtered CSV</a>
     466                <div class="sherpa-form-log-filter-actions">
     467                    <?php submit_button('Filter', 'secondary', 'filter', false); ?>
     468                    <a class="button" href="<?php echo esc_url($base); ?>">Reset</a>
     469                    <a class="button" href="<?php echo esc_url($export); ?>">Export filtered CSV</a>
     470                </div>
     471            </div>
     472        </form>
     473        <form method="post" class="sherpa-form-log-bulk" action="<?php echo esc_url(admin_url('admin-post.php')); ?>"
     474              data-select-entry="<?php echo esc_attr__('Select at least one entry.', 'sherpa-form-log'); ?>"
     475              data-confirm-one="<?php echo esc_attr__('Permanently delete 1 selected entry?', 'sherpa-form-log'); ?>"
     476              data-confirm-many="<?php echo esc_attr__('Permanently delete %d selected entries?', 'sherpa-form-log'); ?>">
     477        <?php wp_nonce_field('sherpa_form_log_bulk', '_wpnonce', false); ?>
     478        <input type="hidden" name="action" value="sherpa_form_log_bulk">
     479        <input type="hidden" name="log_page" value="<?php echo esc_attr($page); ?>">
     480        <?php foreach ($filters as $name => $value) : ?>
     481            <input type="hidden" name="<?php echo esc_attr($name); ?>" value="<?php echo esc_attr($value); ?>">
     482        <?php endforeach; ?>
     483        <?php if ($rows) : ?>
     484            <p>
     485                <label for="sherpa-form-log-bulk-action" class="screen-reader-text"><?php esc_html_e('Bulk actions', 'sherpa-form-log'); ?></label>
     486                <select id="sherpa-form-log-bulk-action" name="bulk_action" required>
     487                    <option value=""><?php esc_html_e('Bulk actions', 'sherpa-form-log'); ?></option>
     488                    <option value="read"><?php esc_html_e('Mark as read', 'sherpa-form-log'); ?></option>
     489                    <option value="delete" disabled><?php esc_html_e('Delete permanently', 'sherpa-form-log'); ?></option>
     490                </select>
     491                <button type="submit" class="button action"><?php esc_html_e('Apply', 'sherpa-form-log'); ?></button>
     492                <span role="status"></span>
    459493            </p>
    460         </form>
     494        <?php endif; ?>
    461495        <table class="widefat striped sherpa-form-log-entries">
    462             <thead><tr><th scope="col">Entry ID</th><th scope="col">Submitted</th><th scope="col">Submitter email</th><th scope="col">Form</th><th scope="col">Builder</th><th scope="col">Status</th><th scope="col">Source page</th></tr></thead>
     496            <thead><tr><td class="check-column"><?php if ($rows) : ?><input type="checkbox" class="sherpa-form-log-select-all" aria-label="<?php esc_attr_e('Select all entries on this page', 'sherpa-form-log'); ?>" disabled><?php endif; ?></td><th scope="col">Entry ID</th><th scope="col">Submitted</th><th scope="col">Submitter email</th><th scope="col">Form</th><th scope="col">Builder</th><th scope="col">Status</th><th scope="col">Source page</th></tr></thead>
    463497            <tbody>
    464498            <?php if (!$rows) : ?>
    465                 <tr><td colspan="7">No matching submissions.</td></tr>
     499                <tr><td colspan="8">No matching submissions.</td></tr>
    466500            <?php endif; ?>
    467501            <?php foreach ($rows as $row) :
    … …  
    473507                ?>
    474508                <tr<?php if ($unread) : ?> class="is-unread"<?php endif; ?>>
     509                    <th scope="row" class="check-column"><input type="checkbox" name="entries[]" value="<?php echo esc_attr($row->id); ?>" aria-label="<?php echo esc_attr(sprintf(__('Select entry %s', 'sherpa-form-log'), $row->id)); ?>"></th>
    475510                    <td><a href="<?php echo esc_url($entry_url); ?>"><?php echo esc_html($row->id); ?></a></td>
    476511                    <td><a href="<?php echo esc_url($entry_url); ?>"><?php echo esc_html(self::display_date($row->submitted_at)); ?></a></td>
    … …  
    484519            </tbody>
    485520        </table>
     521        </form>
    486522        <p><?php echo esc_html(number_format_i18n($total)); ?> matching submissions</p>
    487523        <?php if ($page > 1) : ?>
    … …  
    559595    }
    560596
     597    public static function bulk_entries() {
     598        global $wpdb;
     599        self::require_admin();
     600        if (($_SERVER['REQUEST_METHOD'] ?? '') !== 'POST') {
     601            wp_die('Invalid bulk action request.', '', ['response' => 400]);
     602        }
     603        check_admin_referer('sherpa_form_log_bulk');
     604
     605        $action = isset($_POST['bulk_action']) && is_string($_POST['bulk_action'])
     606            ? sanitize_key(wp_unslash($_POST['bulk_action']))
     607            : '';
     608        $entries = isset($_POST['entries']) && is_array($_POST['entries'])
     609            ? wp_unslash($_POST['entries'])
     610            : [];
     611        if (!in_array($action, ['read', 'delete'], true) || !$entries || count($entries) > 25) {
     612            wp_die('Choose a bulk action and select up to 25 entries.', '', ['response' => 400]);
     613        }
     614        $ids = [];
     615        foreach ($entries as $entry) {
     616            $id = is_string($entry) && preg_match('/^[0-9]+$/D', $entry)
     617                ? filter_var($entry, FILTER_VALIDATE_INT, ['options' => ['min_range' => 1]])
     618                : false;
     619            if (!$id) {
     620                wp_die('Invalid entry ID.', '', ['response' => 400]);
     621            }
     622            $ids[$id] = $id;
     623        }
     624
     625        if (!self::ensure_table()) {
     626            wp_die('Could not update the selected entries.', '', ['response' => 500]);
     627        }
     628        $table = self::table();
     629        $placeholders = implode(', ', array_fill(0, count($ids), '%d'));
     630        if ($action === 'read') {
     631            $affected = $wpdb->query($wpdb->prepare(
     632                "UPDATE %i SET read_at = %s, read_by = %d WHERE read_at IS NULL AND id IN ($placeholders)",
     633                array_merge([$table, gmdate('Y-m-d H:i:s'), get_current_user_id()], array_values($ids))
     634            ));
     635        } else {
     636            $affected = $wpdb->query($wpdb->prepare(
     637                "DELETE FROM %i WHERE id IN ($placeholders)",
     638                array_merge([$table], array_values($ids))
     639            ));
     640        }
     641        if ($affected === false) {
     642            wp_die('Could not update the selected entries.', '', ['response' => 500]);
     643        }
     644
     645        $redirect = ['bulk_result' => $action, 'affected' => $affected, 'log_page' => max(1, self::post_id('log_page'))];
     646        foreach (['q', 'form', 'status', 'from', 'to'] as $key) {
     647            if (isset($_POST[$key]) && is_string($_POST[$key])) {
     648                $redirect[$key] = rawurlencode(sanitize_text_field(wp_unslash($_POST[$key])));
     649            }
     650        }
     651        wp_safe_redirect(add_query_arg($redirect, self::base_url()));
     652        exit;
     653    }
     654
    561655    private static function csv_row($cells) {
    562656        foreach ($cells as &$cell) {
  • sherpa-form-log/trunk/assets/admin.css

    r3841170 r3841198  
    1414    overflow-wrap: anywhere;
    1515}
     16
     17.sherpa-form-log-filters,
     18.sherpa-form-log-filter-actions {
     19    display: flex;
     20    flex-wrap: wrap;
     21    align-items: center;
     22    gap: 8px 6px;
     23}
     24
     25.sherpa-form-log-filters {
     26    margin: 1em 0;
     27}
     28
     29.sherpa-form-log-filters label {
     30    display: inline-flex;
     31    align-items: center;
     32    gap: 4px;
     33    max-width: 100%;
     34}
     35
     36.sherpa-form-log-filters label :is(input, select) {
     37    min-width: 0;
     38}
  • sherpa-form-log/trunk/assets/admin.js

    r3841170 r3841198  
    88        });
    99    }
     10    const bulk = document.querySelector('.sherpa-form-log-bulk');
     11    const selectAll = bulk?.querySelector('.sherpa-form-log-select-all');
     12    if (!selectAll) {
     13        return;
     14    }
     15
     16    const entries = [...bulk.querySelectorAll('input[name="entries[]"]')];
     17    const action = bulk.querySelector('[name="bulk_action"]');
     18    const status = bulk.querySelector('[role="status"]');
     19    const selectedCount = () => entries.filter(entry => entry.checked).length;
     20    const syncSelection = () => {
     21        const count = selectedCount();
     22        selectAll.checked = count === entries.length;
     23        selectAll.indeterminate = count > 0 && count < entries.length;
     24        status.textContent = '';
     25    };
     26
     27    selectAll.disabled = false;
     28    action.querySelector('[value="delete"]').disabled = false;
     29    selectAll.addEventListener('change', () => {
     30        entries.forEach(entry => { entry.checked = selectAll.checked; });
     31        syncSelection();
     32    });
     33    entries.forEach(entry => entry.addEventListener('change', syncSelection));
     34    syncSelection();
     35    bulk.addEventListener('submit', event => {
     36        const count = selectedCount();
     37        if (count === 0) {
     38            event.preventDefault();
     39            status.textContent = bulk.dataset.selectEntry;
     40            selectAll.focus();
     41            return;
     42        }
     43        if (action.value === 'delete') {
     44            const message = count === 1
     45                ? bulk.dataset.confirmOne
     46                : bulk.dataset.confirmMany.replace('%d', count);
     47            if (!window.confirm(message)) {
     48                event.preventDefault();
     49            }
     50        }
     51    });
    1052})();
  • sherpa-form-log/trunk/readme.txt

    r3841170 r3841198  
    55Tested up to: 7.1
    66Requires PHP: 7.4
    7 Stable tag: 0.3.2
     7Stable tag: 0.3.3
    88License: GPL-2.0-or-later
    99License URI: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
    … …  
    4747== Screenshots ==
    4848
    49 1. Form submissions with filters, read status and CSV export. Email and source addresses are redacted.
     491. Form submissions with filters, bulk actions, read status and CSV export. Email and source addresses are redacted.
    5050
    5151== Changelog ==
     52
     53= 0.3.3 =
     54* Mark selected entries as read or permanently delete them from the submissions list.
     55* Improve spacing when the filter controls wrap.
    5256
    5357= 0.3.2 =
  • sherpa-form-log/trunk/sherpa-form-log.php

    r3841170 r3841198  
    44 * Plugin URI: https://sherpadigital.com.au/sherpa-form-log/
    55 * Description: Save submissions from Elementor Pro, Divi, Gravity Forms and Contact Form 7.
    6  * Version: 0.3.2
     6 * Version: 0.3.3
    77 * Requires at least: 6.2
    88 * Requires PHP: 7.4
    … …  
    1919
    2020final class Plugin {
    21     private const VERSION = '0.3.2';
     21    private const VERSION = '0.3.3';
    2222    private const PAGE = 'sherpa-form-log';
    2323    private const SCHEMA = '2';
    … …  
    3939        add_action('admin_menu', [self::class, 'menu'], 100);
    4040        add_action('admin_post_sherpa_form_log_delete', [self::class, 'delete_entry']);
     41        add_action('admin_post_sherpa_form_log_bulk', [self::class, 'bulk_entries']);
    4142        add_action('admin_post_sherpa_form_log_export', [self::class, 'export']);
    4243    }
    … …  
    420421        }
    421422
     423        $bulk_result = self::input('bulk_result');
     424        if (in_array($bulk_result, ['read', 'delete'], true)) {
     425            $count = absint(self::input('affected'));
     426            $message = $bulk_result === 'read'
     427                ? _n('%s entry marked as read.', '%s entries marked as read.', $count, 'sherpa-form-log')
     428                : _n('%s entry deleted.', '%s entries deleted.', $count, 'sherpa-form-log');
     429            echo '<div class="notice notice-success is-dismissible"><p>' . esc_html(sprintf($message, number_format_i18n($count))) . '</p></div>';
     430        }
     431
    422432        $where = self::where($filters, $args);
    423433        $total = (int) $wpdb->get_var($wpdb->prepare(
    … …  
    439449        <form method="get" action="<?php echo esc_url(strtok($base, '?')); ?>">
    440450            <input type="hidden" name="page" value="<?php echo esc_attr(self::PAGE); ?>">
    441             <p>
     451            <div class="sherpa-form-log-filters">
    442452                <label>Search <input type="search" name="q" value="<?php echo esc_attr($filters['q']); ?>"></label>
    443453                <label>Form <select name="form">
    … …  
    454464                <label>From <input type="date" name="from" value="<?php echo esc_attr($filters['from']); ?>"></label>
    455465                <label>To <input type="date" name="to" value="<?php echo esc_attr($filters['to']); ?>"></label>
    456                 <?php submit_button('Filter', 'secondary', 'filter', false); ?>
    457                 <a class="button" href="<?php echo esc_url($base); ?>">Reset</a>
    458                 <a class="button" href="<?php echo esc_url($export); ?>">Export filtered CSV</a>
     466                <div class="sherpa-form-log-filter-actions">
     467                    <?php submit_button('Filter', 'secondary', 'filter', false); ?>
     468                    <a class="button" href="<?php echo esc_url($base); ?>">Reset</a>
     469                    <a class="button" href="<?php echo esc_url($export); ?>">Export filtered CSV</a>
     470                </div>
     471            </div>
     472        </form>
     473        <form method="post" class="sherpa-form-log-bulk" action="<?php echo esc_url(admin_url('admin-post.php')); ?>"
     474              data-select-entry="<?php echo esc_attr__('Select at least one entry.', 'sherpa-form-log'); ?>"
     475              data-confirm-one="<?php echo esc_attr__('Permanently delete 1 selected entry?', 'sherpa-form-log'); ?>"
     476              data-confirm-many="<?php echo esc_attr__('Permanently delete %d selected entries?', 'sherpa-form-log'); ?>">
     477        <?php wp_nonce_field('sherpa_form_log_bulk', '_wpnonce', false); ?>
     478        <input type="hidden" name="action" value="sherpa_form_log_bulk">
     479        <input type="hidden" name="log_page" value="<?php echo esc_attr($page); ?>">
     480        <?php foreach ($filters as $name => $value) : ?>
     481            <input type="hidden" name="<?php echo esc_attr($name); ?>" value="<?php echo esc_attr($value); ?>">
     482        <?php endforeach; ?>
     483        <?php if ($rows) : ?>
     484            <p>
     485                <label for="sherpa-form-log-bulk-action" class="screen-reader-text"><?php esc_html_e('Bulk actions', 'sherpa-form-log'); ?></label>
     486                <select id="sherpa-form-log-bulk-action" name="bulk_action" required>
     487                    <option value=""><?php esc_html_e('Bulk actions', 'sherpa-form-log'); ?></option>
     488                    <option value="read"><?php esc_html_e('Mark as read', 'sherpa-form-log'); ?></option>
     489                    <option value="delete" disabled><?php esc_html_e('Delete permanently', 'sherpa-form-log'); ?></option>
     490                </select>
     491                <button type="submit" class="button action"><?php esc_html_e('Apply', 'sherpa-form-log'); ?></button>
     492                <span role="status"></span>
    459493            </p>
    460         </form>
     494        <?php endif; ?>
    461495        <table class="widefat striped sherpa-form-log-entries">
    462             <thead><tr><th scope="col">Entry ID</th><th scope="col">Submitted</th><th scope="col">Submitter email</th><th scope="col">Form</th><th scope="col">Builder</th><th scope="col">Status</th><th scope="col">Source page</th></tr></thead>
     496            <thead><tr><td class="check-column"><?php if ($rows) : ?><input type="checkbox" class="sherpa-form-log-select-all" aria-label="<?php esc_attr_e('Select all entries on this page', 'sherpa-form-log'); ?>" disabled><?php endif; ?></td><th scope="col">Entry ID</th><th scope="col">Submitted</th><th scope="col">Submitter email</th><th scope="col">Form</th><th scope="col">Builder</th><th scope="col">Status</th><th scope="col">Source page</th></tr></thead>
    463497            <tbody>
    464498            <?php if (!$rows) : ?>
    465                 <tr><td colspan="7">No matching submissions.</td></tr>
     499                <tr><td colspan="8">No matching submissions.</td></tr>
    466500            <?php endif; ?>
    467501            <?php foreach ($rows as $row) :
    … …  
    473507                ?>
    474508                <tr<?php if ($unread) : ?> class="is-unread"<?php endif; ?>>
     509                    <th scope="row" class="check-column"><input type="checkbox" name="entries[]" value="<?php echo esc_attr($row->id); ?>" aria-label="<?php echo esc_attr(sprintf(__('Select entry %s', 'sherpa-form-log'), $row->id)); ?>"></th>
    475510                    <td><a href="<?php echo esc_url($entry_url); ?>"><?php echo esc_html($row->id); ?></a></td>
    476511                    <td><a href="<?php echo esc_url($entry_url); ?>"><?php echo esc_html(self::display_date($row->submitted_at)); ?></a></td>
    … …  
    484519            </tbody>
    485520        </table>
     521        </form>
    486522        <p><?php echo esc_html(number_format_i18n($total)); ?> matching submissions</p>
    487523        <?php if ($page > 1) : ?>
    … …  
    559595    }
    560596
     597    public static function bulk_entries() {
     598        global $wpdb;
     599        self::require_admin();
     600        if (($_SERVER['REQUEST_METHOD'] ?? '') !== 'POST') {
     601            wp_die('Invalid bulk action request.', '', ['response' => 400]);
     602        }
     603        check_admin_referer('sherpa_form_log_bulk');
     604
     605        $action = isset($_POST['bulk_action']) && is_string($_POST['bulk_action'])
     606            ? sanitize_key(wp_unslash($_POST['bulk_action']))
     607            : '';
     608        $entries = isset($_POST['entries']) && is_array($_POST['entries'])
     609            ? wp_unslash($_POST['entries'])
     610            : [];
     611        if (!in_array($action, ['read', 'delete'], true) || !$entries || count($entries) > 25) {
     612            wp_die('Choose a bulk action and select up to 25 entries.', '', ['response' => 400]);
     613        }
     614        $ids = [];
     615        foreach ($entries as $entry) {
     616            $id = is_string($entry) && preg_match('/^[0-9]+$/D', $entry)
     617                ? filter_var($entry, FILTER_VALIDATE_INT, ['options' => ['min_range' => 1]])
     618                : false;
     619            if (!$id) {
     620                wp_die('Invalid entry ID.', '', ['response' => 400]);
     621            }
     622            $ids[$id] = $id;
     623        }
     624
     625        if (!self::ensure_table()) {
     626            wp_die('Could not update the selected entries.', '', ['response' => 500]);
     627        }
     628        $table = self::table();
     629        $placeholders = implode(', ', array_fill(0, count($ids), '%d'));
     630        if ($action === 'read') {
     631            $affected = $wpdb->query($wpdb->prepare(
     632                "UPDATE %i SET read_at = %s, read_by = %d WHERE read_at IS NULL AND id IN ($placeholders)",
     633                array_merge([$table, gmdate('Y-m-d H:i:s'), get_current_user_id()], array_values($ids))
     634            ));
     635        } else {
     636            $affected = $wpdb->query($wpdb->prepare(
     637                "DELETE FROM %i WHERE id IN ($placeholders)",
     638                array_merge([$table], array_values($ids))
     639            ));
     640        }
     641        if ($affected === false) {
     642            wp_die('Could not update the selected entries.', '', ['response' => 500]);
     643        }
     644
     645        $redirect = ['bulk_result' => $action, 'affected' => $affected, 'log_page' => max(1, self::post_id('log_page'))];
     646        foreach (['q', 'form', 'status', 'from', 'to'] as $key) {
     647            if (isset($_POST[$key]) && is_string($_POST[$key])) {
     648                $redirect[$key] = rawurlencode(sanitize_text_field(wp_unslash($_POST[$key])));
     649            }
     650        }
     651        wp_safe_redirect(add_query_arg($redirect, self::base_url()));
     652        exit;
     653    }
     654
    561655    private static function csv_row($cells) {
    562656        foreach ($cells as &$cell) {
Note: See TracChangeset for help on using the changeset viewer.