Plugin Directory

Changeset 3366878


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

Added ability to flush cached data.

Location:
ip2location-redirection/trunk
Files:
3 edited

Legend:

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

    r3316642 r3366878  
    7676        },
    7777    });
     78
     79    $('#btn_clear_cache').on('click', function (e) {
     80        e.preventDefault();
     81
     82        var $form = $('<form method="post">')
     83            .html('<input type="hidden" name="cache_nonce" value="' + $('#cache_nonce').val() + '">');
     84
     85        $('body').append($form);
     86        $form.submit();
     87    });
    7888});
  • ip2location-redirection/trunk/ip2location-redirection.php

    r3335592 r3366878  
    44 * Plugin URI: https://ip2location.com/resources/wordpress-ip2location-redirection
    55 * Description: Redirect visitors by their country.
    6  * Version: 1.34.3
     6 * Version: 1.35.0
    77 * Requires PHP: 7.4
    88 * Author: IP2Location
     
    13551355        }
    13561356
     1357        if ($this->post('cache_nonce')) {
     1358            check_admin_referer('cache', 'cache_nonce');
     1359
     1360            $this->cache_flush();
     1361
     1362            $settings_status = '
     1363            <div class="updated">
     1364                <p>' . __('All cache has been flushed.', 'ip2location-redirection') . '</p>
     1365            </div>';
     1366        }
     1367
    13571368        if ($this->post('submit')) {
    13581369            check_admin_referer('save_settings');
     
    16701681                            </p>
    16711682                            <input type="hidden" id="restore_nonce" value="' . wp_create_nonce('restore') . '">
     1683                        </td>
     1684                    </tr>
     1685                    <tr>
     1686                        <th scope="row">
     1687                            <label>' . __('Cache', 'ip2location-redirection') . '</label>
     1688                        </th>
     1689                        <td>
     1690                            <button id="btn_clear_cache" type="button" class="button button-danger">' . __('Clear Cache', 'ip2location-redirection') . ' (' . $this->display_bytes($this->cache_size()) . ')</button>
     1691                            <p class="description">
     1692                                ' . __('Clear all cached data.', 'ip2location-redirection') . '
     1693                            </p>
     1694                            <input type="hidden" id="cache_nonce" value="' . wp_create_nonce('cache') . '">
    16721695                        </td>
    16731696                    </tr>
     
    29302953    }
    29312954
     2955    private function cache_size()
     2956    {
     2957        $size = 0;
     2958
     2959        $files = scandir(IP2LOCATION_DIR . 'caches');
     2960
     2961        foreach ($files as $file) {
     2962            if (substr($file, -5) == '.json') {
     2963                $size += filesize(IP2LOCATION_DIR . 'caches' . \DIRECTORY_SEPARATOR . $file);
     2964            }
     2965        }
     2966
     2967        return $size;
     2968    }
     2969
    29322970    private function cache_flush()
    29332971    {
     
    30433081        return $_SERVER['HTTP_HOST'] ?? '';
    30443082    }
     3083
     3084    private function display_bytes($bytes)
     3085    {
     3086        $ext = ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
     3087
     3088        $index = 0;
     3089        for (; $bytes > 1024; ++$index) {
     3090            $bytes /= 1024;
     3091        }
     3092
     3093        return number_format((float) $bytes, 0, '.', ',') . ' ' . $ext[$index];
     3094    }
    30453095}
  • ip2location-redirection/trunk/readme.txt

    r3335592 r3366878  
    55Requires at least: 4.6
    66Tested up to: 6.8
    7 Stable tag: 1.34.3
     7Stable tag: 1.35.0
    88
    99Redirects visitors to a blog page or a predefined URL based on their country and region geolocated using IP address.
     
    6363
    6464== Changelog ==
     65* 1.35.0 Added ability to flush cached data.
    6566* 1.34.3 Restored option to skip bots & crawlers.
    6667* 1.34.2 Fixed PHP warning when cronjobs are running.
Note: See TracChangeset for help on using the changeset viewer.