Plugin Directory

Changeset 3190658


Ignore:
Timestamp:
11/17/2024 01:58:28 PM (17 months ago)
Author:
camoo
Message:

Tested up to 6.7

Location:
camoo-cdn/trunk
Files:
1 deleted
8 edited

Legend:

Unmodified
Added
Removed
  • camoo-cdn/trunk/camoo-cdn.php

    r3070018 r3190658  
    88 * Plugin URI: https://github.com/camoo/wp-camoo-cdn
    99 * Description: Integrates your WordPress site with Camoo.Hosting CDN for improved loading times and performance.
    10  * Version: 2.0.2
     10 * Version: 2.0.3
    1111 * Author: CAMOO SARL
    1212 * Author URI: https://www.camoo.hosting/
     
    1616 * Domain Path: /languages
    1717 * Requires at least: 6.4.3
    18  * Tested up to: 6.5.2
     18 * Tested up to: 6.7
    1919 * Requires PHP: 8.0
    2020 *
  • camoo-cdn/trunk/readme.txt

    r3070019 r3190658  
    11=== CAMOO CDN ===
    22Contributors: camoo
    3 Tags: Camoo.Hosting, CAMOO CDN Integration, Managed Hosting with CDN, Hébergement Web avec CDN, WordPress Caching, WP Super Cache
     3Tags: Camoo.Hosting, CAMOO CDN Integration, Managed Hosting with CDN, Hébergement Web avec CDN, WordPress Caching
    44Requires at least: 6.4.3
    55Requires Plugins: wp-super-cache
    6 Tested up to: 6.5.2
     6Tested up to: 6.7
    77Requires PHP: 8.0
    8 Stable tag: 2.0.2
     8Stable tag: 2.0.3
    99License: GPLv2 or later
    1010License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    4444
    4545== Changelog ==
     46
     47= 2.0.3: 17.11, 2024 =
     48* Tweak: Tested up to 6.7
     49
    4650= 2.0.2: 13.04, 2024 =
    4751* Tweak: Query cache added
  • camoo-cdn/trunk/src/Cache/Settings.php

    r3070018 r3190658  
    2828
    2929    /** Method to handle actions after option updates. */
    30     public static function onOptionUpdate($option, $oldValue, $newValue): void
     30    public static function onOptionUpdate($option, mixed $oldValue, mixed $newValue): void
    3131    {
    3232        if ($option === 'camoo_cdn_cache_settings') {
     
    7575            'camoo_cdn'
    7676        );
    77         /*
    78                 self::addSettingsField(
    79                     'excluded_pages',
    80                     __('Pages to Exclude from Caching', 'camoo-cdn'),
    81                     [self::class, 'renderTextInput'],
    82                     '/foo-page, /bar-page'
    83                 );
    84                 self::addSettingsField(
    85                     'table_inclusion',
    86                     __('Tables to Include in Caching', 'camoo-cdn'),
    87                     [self::class, 'renderTextInput']
    88                 );
    89                 self::addSettingsField(
    90                     'table_exclusion',
    91                     __('Tables to Exclude from Caching', 'camoo-cdn'),
    92                     [self::class, 'renderTextInput']
    93                 );*/
     77
    9478        self::addSettingsField(
    9579            'cache_duration',
     
    10993        $options = self::getOptions();
    11094        $value = $options[$args['id']] ?? '';
    111         echo "<input id='camoo_cdn_{$args['id']}'
    112         name='camoo_cdn_cache_settings[{$args['id']}]' size='40' type='text' value='" .
    113             esc_attr($value) . "' placeholder='" . esc_attr($args['placeholder']) . "' />";
     95        $suffixAttribute = esc_attr($args['id']);
     96        echo "<input id=\"camoo_cdn_{$suffixAttribute}\"
     97        name=\"camoo_cdn_cache_settings[{$suffixAttribute}]\" size=\"40\" type=\"text\" value=\"" .
     98            esc_attr($value) . "\" placeholder=\"" . esc_attr($args['placeholder']) . "\" />";
    11499    }
    115100
     
    119104        $options = self::getOptions();
    120105        $value = $options[$args['id']] ?? '';
    121         echo "<input id='camoo_cdn_{$args['id']}'
    122             name='camoo_cdn_cache_settings[{$args['id']}]' size='40' type='number' value='" . esc_attr($value) . "' />";
     106        $suffixAttribute = esc_attr($args['id']);
     107        echo "<input id='camoo_cdn_{$suffixAttribute}'
     108            name='camoo_cdn_cache_settings[{$suffixAttribute}]' size='40' type='number' value='" . esc_attr($value) . "' />";
    123109    }
    124110
     
    128114        $options = self::getOptions();
    129115        $checked = !empty($options[$args['id']]) ? 'checked' : '';
    130         echo "<input id='camoo_cdn_{$args['id']}'
    131             name='camoo_cdn_cache_settings[{$args['id']}]' type='checkbox' {$checked} /> Enable";
     116        $suffixAttribute = esc_attr($args['id']);
     117        echo "<input id='camoo_cdn_{$suffixAttribute}'
     118            name='camoo_cdn_cache_settings[{$suffixAttribute}]' type='checkbox' {$checked} /> Enable";
    132119    }
    133120
     
    135122    public static function settingsDescription(): void
    136123    {
    137         echo '<p>' . __(
     124        echo '<p>' . esc_html__(
    138125            'Customize the caching behavior for your WordPress site with CAMOO CDN Query Cache settings.',
    139126            'camoo-cdn'
     
    157144    {
    158145        if (self::$options === null) {
    159             self::$options = Option::get('camoo_cdn_cache_settings') ?? [];
     146            $value = Option::get('camoo_cdn_cache_settings');
     147            self::$options = empty($value) ? ['enable_caching' => '1'] : $value;
    160148        }
    161149
  • camoo-cdn/trunk/src/Gateways/Option.php

    r3058345 r3190658  
    2121     * Get the whole Plugin Options
    2222     *
    23      * @param string $setting_name setting name
     23     * @param ?string $setting_name setting name
    2424     *
    2525     * @return mixed|string
    2626     */
    27     public static function get(?string $setting_name = null)
     27    public static function get(?string $setting_name = null): mixed
    2828    {
    2929        if (null === $setting_name) {
  • camoo-cdn/trunk/src/Services/Integration.php

    r3059295 r3190658  
    3939        echo '<div class="notice notice-warning">';
    4040        echo '<p>';
    41         _e(
     41        esc_html_e(
    4242            'WP Super Cache is not active. Please activate WP Super Cache for the CAMOO CDN plugin to work correctly.',
    4343            'camoo-cdn'
     
    6363     * @return array Modified cron schedules.
    6464     */
    65     public static function addCustomCronSchedule($schedules): array
     65    public static function addCustomCronSchedule(mixed $schedules): array
    6666    {
    6767        $schedules['camoo_cdn_cron_every_four_days'] = [
  • camoo-cdn/trunk/src/Services/QueryCaching.php

    r3070018 r3190658  
    44
    55namespace WP_CAMOO\CDN\Services;
    6 
    7 use WP_CAMOO\CDN\Gateways\Option;
    8 use WP_Query;
    96
    107if (!defined('ABSPATH')) {
    118    exit; // Exit if accessed directly
    129}
     10
     11use WP_CAMOO\CDN\Gateways\Option;
     12use WP_Query;
    1313
    1414final class QueryCaching
     
    6161    {
    6262        self::logDebug('Clear cache started...');
     63
     64        // Use WordPress functions to delete transient data
     65        self::deleteTransientsByPrefix('camoo_cdn_');
     66
     67        self::logDebug('Clear cache ended...');
     68    }
     69
     70    /**
     71     * Deletes transients with a specific prefix.
     72     *
     73     * @param string $prefix The prefix of transients to delete.
     74     */
     75    private static function deleteTransientsByPrefix(string $prefix): void
     76    {
    6377        global $wpdb;
    64         $wpdb->query("
    65            DELETE FROM {$wpdb->options}
    66            WHERE option_name LIKE '\_transient\_camoo\_cdn\_%' OR option_name LIKE '\_transient\_timeout\_camoo\_cdn\_%'
    67         ");
    68         self::logDebug('Clear cache ended...');
     78
     79        // Get all matching transients and their timeouts
     80        $options = $wpdb->get_col(
     81            $wpdb->prepare(
     82                "
     83                SELECT option_name
     84                FROM {$wpdb->options}
     85                WHERE option_name LIKE %s OR option_name LIKE %s
     86            ",
     87                $wpdb->esc_like("_transient_{$prefix}") . '%',
     88                $wpdb->esc_like("_transient_timeout_{$prefix}") . '%'
     89            )
     90        );
     91
     92        foreach ($options as $option) {
     93            if (str_contains($option, '_transient_timeout_')) {
     94                // Delete transient timeout entry
     95                delete_option($option); // Directly delete the timeout option
     96            } else {
     97                // Delete transient entry
     98                $transient_name = str_replace('_transient_', '', $option);
     99                delete_transient($transient_name);
     100            }
     101        }
    69102    }
    70103
    71104    private static function shouldCache(): bool
    72105    {
    73         if (is_user_logged_in() || WC()->cart->get_cart_contents_count() > 0) {
     106        if (is_user_logged_in() || (function_exists('WC') && WC()->cart->get_cart_contents_count() > 0)) {
    74107            self::logDebug("Don't cache loggedin user or non empty Woocommerce cart");
    75108
     
    89122    {
    90123        if (self::$options === null) {
    91             self::$options = Option::get('camoo_cdn_cache_settings') ?? [];
     124            $value = Option::get('camoo_cdn_cache_settings');
     125            self::$options = empty($value) ? ['enable_caching' => '1'] : $value;
    92126        }
    93127
     
    104138    private static function isExcluded(string $url): bool
    105139    {
    106         $path = parse_url($url, PHP_URL_PATH) ?? '/';
     140        $path = wp_parse_url($url, PHP_URL_PATH) ?? '/';
    107141
    108142        // Regular expression to match file extensions that should not be cached
     
    161195        if (defined('WP_DEBUG') && WP_DEBUG && defined('WP_DEBUG_LOG') && WP_DEBUG_LOG) {
    162196            // Define the custom log path
    163             $log_path = WP_CONTENT_DIR . '/debug.log';
     197            $logPath = WP_CONTENT_DIR . '/debug.log';
    164198            // Check if the log file is writable or if it does not exist and can be created
    165             if (is_writable($log_path) || (!file_exists($log_path) && is_writable(dirname($log_path)))) {
    166                 error_log(current_time('mysql') . " - {$message}\n", 3, $log_path);
     199            if ((file_exists($logPath) && is_writable($logPath)) || is_writable(dirname($logPath))) {
     200                error_log(current_time('mysql') . " - {$message}\n", 3, $logPath);
    167201            } else {
    168202                error_log(current_time('mysql') . " - Failed to write to log: {$message}\n");
  • camoo-cdn/trunk/src/Services/SyncFiles.php

    r3059295 r3190658  
    4242        update_option('ossdl_off_cdn_url', $cdnUrl);
    4343        update_option('ossdl_off_blog_url', get_site_url());
     44        add_action( 'admin_init', 'wpsc_admin_bar_delete_cache' );
    4445    }
    4546
     
    4748    {
    4849        $packages_url = esc_url(WP_CAMOO_CDN_SITE . '/wordpress-hosting');
    49         $domain = parse_url(home_url(), PHP_URL_HOST);
     50        $domain = wp_parse_url(home_url(), PHP_URL_HOST);
    5051        $link_text = __('Managed WordPress packages', 'camoo-cdn');
    5152        $message_format = __('CDN is not available for your domain: %s. Check our %s out for more.', 'camoo-cdn');
     
    8889    {
    8990        $api_url = WP_CAMOO_CDN_SITE . '/cpanel/managed-wordpress/can-cdn.json?dn=' .
    90             urlencode(parse_url(home_url(), PHP_URL_HOST));
     91            urlencode(wp_parse_url(home_url(), PHP_URL_HOST));
    9192        $response = wp_remote_get($api_url);
    9293
     
    9798        }
    9899
    99         return json_decode(wp_remote_retrieve_body($response), true);
     100        return json_decode(wp_remote_retrieve_body($response), true, 512, JSON_THROW_ON_ERROR);
    100101    }
    101102
  • camoo-cdn/trunk/uninstall.php

    r3070018 r3190658  
    44
    55/**
    6  * Uninstalling CAMOO-CDN, deletes tables, and options.
     6 * Uninstall CAMOO-CDN Plugin
     7 *
     8 * Deletes plugin-related options, transients, and configurations.
    79 *
    810 * @version 2.0
    911 *
    10  * License: GPLv2 or later
    11  * License URI: http://www.gnu.org/licenses/gpl-2.0.html
     12 * @license GPLv2 or later
     13 * @license URI http://www.gnu.org/licenses/gpl-2.0.html
    1214 *
    13  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
    14  * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
     15 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
     16 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    1517 */
     18
     19// Exit if accessed directly outside the uninstallation process.
    1620defined('WP_UNINSTALL_PLUGIN') || exit;
    1721
     22// Delete plugin-specific options from the database.
    1823delete_option('wp_camoo_cdn_oss');
    1924delete_option('ossdl_off_cdn_url');
     
    2227delete_option('camoo_cdn_cache_settings');
    2328
     29// Delete plugin-specific transients from the database.
    2430global $wpdb;
    25 $wpdb->query("
    26            DELETE FROM {$wpdb->options}
    27            WHERE option_name LIKE '\_transient\_camoo\_cdn\_%' OR option_name LIKE '\_transient\_timeout\_camoo\_cdn\_%'
    28         ");
     31$transient_prefix = '_transient_camoo_cdn_';
     32$timeout_prefix = '_transient_timeout_camoo_cdn_';
     33
     34// Using a direct query here for performance on transient cleanup.
     35$wpdb->query(
     36    $wpdb->prepare(
     37        "DELETE FROM {$wpdb->options} WHERE option_name LIKE %s OR option_name LIKE %s",
     38        $wpdb->esc_like($transient_prefix) . '%',
     39        $wpdb->esc_like($timeout_prefix) . '%'
     40    )
     41);
     42
    2943$configFile = WP_CONTENT_DIR . '/wp-cache-config.php';
    3044if (file_exists($configFile)) {
Note: See TracChangeset for help on using the changeset viewer.