Plugin Directory

Changeset 3366875


Ignore:
Timestamp:
09/24/2025 04:55:12 AM (6 months ago)
Author:
ip2location
Message:

Added ability to flush cached data.

Location:
ip2location-country-blocker/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • ip2location-country-blocker/trunk/assets/js/settings.js

    r3316128 r3366875  
    279279    });
    280280
     281    $('#btn_clear_cache').on('click', function (e) {
     282        e.preventDefault();
     283
     284        var $form = $('<form method="post">')
     285            .html('<input type="hidden" name="cache_nonce" value="' + $('#cache_nonce').val() + '">');
     286
     287        $('body').append($form);
     288        $form.submit();
     289    });
    281290});
  • ip2location-country-blocker/trunk/ip2location-country-blocker.php

    r3348463 r3366875  
    55 * Plugin URI: https://ip2location.com/resources/wordpress-ip2location-country-blocker
    66 * Description: Block visitors from accessing your website or admin area by their country.
    7  * Version: 2.39.5
     7 * Version: 2.40.0
    88 * Requires PHP: 7.4
    99 * Author: IP2Location
     
    12031203        if (!in_array($real_ip_header, array_values($real_ip_headers))) {
    12041204            $real_ip_header = '';
     1205        }
     1206
     1207        if ($this->post('cache_nonce')) {
     1208            check_admin_referer('cache', 'cache_nonce');
     1209
     1210            $this->cache_flush();
     1211
     1212            $settings_status = '
     1213            <div class="updated">
     1214                <p>' . __('All cache has been flushed.', 'ip2location-country-blocker') . '</p>
     1215            </div>';
    12051216        }
    12061217
     
    17021713                        </td>
    17031714                    </tr>
     1715                    <tr>
     1716                        <th scope="row">
     1717                            <label>' . __('Cache', 'ip2location-country-blocker') . '</label>
     1718                        </th>
     1719                        <td>
     1720                            <button id="btn_clear_cache" type="button" class="button button-danger">' . __('Clear Cache', 'ip2location-country-blocker') . ' (' . $this->display_bytes($this->cache_size()) . ')</button>
     1721                            <p class="description">
     1722                                ' . __('Clear all cached data.', 'ip2location-country-blocker') . '
     1723                            </p>
     1724                            <input type="hidden" id="cache_nonce" value="' . wp_create_nonce('cache') . '">
     1725                        </td>
     1726                    </tr>
    17041727                </table>
    17051728                <p class="submit">
     
    37703793    }
    37713794
     3795    private function cache_size()
     3796    {
     3797        $size = 0;
     3798
     3799        $files = scandir(IP2LOCATION_DIR . 'caches');
     3800
     3801        foreach ($files as $file) {
     3802            if (substr($file, -5) == '.json') {
     3803                $size += filesize(IP2LOCATION_DIR . 'caches' . \DIRECTORY_SEPARATOR . $file);
     3804            }
     3805        }
     3806
     3807        return $size;
     3808    }
     3809
    37723810    private function cache_flush()
    37733811    {
     
    39433981        return false;
    39443982    }
     3983
     3984    private function display_bytes($bytes)
     3985    {
     3986        $ext = ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
     3987
     3988        $index = 0;
     3989        for (; $bytes > 1024; ++$index) {
     3990            $bytes /= 1024;
     3991        }
     3992
     3993        return number_format((float) $bytes, 0, '.', ',') . ' ' . $ext[$index];
     3994    }
    39453995}
  • ip2location-country-blocker/trunk/readme.txt

    r3348463 r3366875  
    66Requires at least: 4.6
    77Tested up to: 6.8
    8 Stable tag: 2.39.5
     8Stable tag: 2.40.0
    99
    1010Blocks unwanted visitors from accessing your frontend (blog pages) or backend (admin area) by countries or proxy servers.
     
    9292
    9393== Changelog ==
     94* 2.40.0 Added ability to flush cached data.
    9495* 2.39.5 Fixed issue saving backend error page.
    9596* 2.39.4 Removed internal table updates.
Note: See TracChangeset for help on using the changeset viewer.