Changeset 3190658
- Timestamp:
- 11/17/2024 01:58:28 PM (17 months ago)
- Location:
- camoo-cdn/trunk
- Files:
-
- 1 deleted
- 8 edited
-
camoo-cdn.php (modified) (2 diffs)
-
readme.txt (modified) (2 diffs)
-
src/Cache/Settings.php (modified) (7 diffs)
-
src/Exception (deleted)
-
src/Gateways/Option.php (modified) (1 diff)
-
src/Services/Integration.php (modified) (2 diffs)
-
src/Services/QueryCaching.php (modified) (5 diffs)
-
src/Services/SyncFiles.php (modified) (4 diffs)
-
uninstall.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
camoo-cdn/trunk/camoo-cdn.php
r3070018 r3190658 8 8 * Plugin URI: https://github.com/camoo/wp-camoo-cdn 9 9 * Description: Integrates your WordPress site with Camoo.Hosting CDN for improved loading times and performance. 10 * Version: 2.0. 210 * Version: 2.0.3 11 11 * Author: CAMOO SARL 12 12 * Author URI: https://www.camoo.hosting/ … … 16 16 * Domain Path: /languages 17 17 * Requires at least: 6.4.3 18 * Tested up to: 6. 5.218 * Tested up to: 6.7 19 19 * Requires PHP: 8.0 20 20 * -
camoo-cdn/trunk/readme.txt
r3070019 r3190658 1 1 === CAMOO CDN === 2 2 Contributors: camoo 3 Tags: Camoo.Hosting, CAMOO CDN Integration, Managed Hosting with CDN, Hébergement Web avec CDN, WordPress Caching , WP Super Cache3 Tags: Camoo.Hosting, CAMOO CDN Integration, Managed Hosting with CDN, Hébergement Web avec CDN, WordPress Caching 4 4 Requires at least: 6.4.3 5 5 Requires Plugins: wp-super-cache 6 Tested up to: 6. 5.26 Tested up to: 6.7 7 7 Requires PHP: 8.0 8 Stable tag: 2.0. 28 Stable tag: 2.0.3 9 9 License: GPLv2 or later 10 10 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 44 44 45 45 == Changelog == 46 47 = 2.0.3: 17.11, 2024 = 48 * Tweak: Tested up to 6.7 49 46 50 = 2.0.2: 13.04, 2024 = 47 51 * Tweak: Query cache added -
camoo-cdn/trunk/src/Cache/Settings.php
r3070018 r3190658 28 28 29 29 /** Method to handle actions after option updates. */ 30 public static function onOptionUpdate($option, $oldValue,$newValue): void30 public static function onOptionUpdate($option, mixed $oldValue, mixed $newValue): void 31 31 { 32 32 if ($option === 'camoo_cdn_cache_settings') { … … 75 75 'camoo_cdn' 76 76 ); 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 94 78 self::addSettingsField( 95 79 'cache_duration', … … 109 93 $options = self::getOptions(); 110 94 $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']) . "\" />"; 114 99 } 115 100 … … 119 104 $options = self::getOptions(); 120 105 $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) . "' />"; 123 109 } 124 110 … … 128 114 $options = self::getOptions(); 129 115 $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"; 132 119 } 133 120 … … 135 122 public static function settingsDescription(): void 136 123 { 137 echo '<p>' . __(124 echo '<p>' . esc_html__( 138 125 'Customize the caching behavior for your WordPress site with CAMOO CDN Query Cache settings.', 139 126 'camoo-cdn' … … 157 144 { 158 145 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; 160 148 } 161 149 -
camoo-cdn/trunk/src/Gateways/Option.php
r3058345 r3190658 21 21 * Get the whole Plugin Options 22 22 * 23 * @param string $setting_name setting name23 * @param ?string $setting_name setting name 24 24 * 25 25 * @return mixed|string 26 26 */ 27 public static function get(?string $setting_name = null) 27 public static function get(?string $setting_name = null): mixed 28 28 { 29 29 if (null === $setting_name) { -
camoo-cdn/trunk/src/Services/Integration.php
r3059295 r3190658 39 39 echo '<div class="notice notice-warning">'; 40 40 echo '<p>'; 41 _e(41 esc_html_e( 42 42 'WP Super Cache is not active. Please activate WP Super Cache for the CAMOO CDN plugin to work correctly.', 43 43 'camoo-cdn' … … 63 63 * @return array Modified cron schedules. 64 64 */ 65 public static function addCustomCronSchedule( $schedules): array65 public static function addCustomCronSchedule(mixed $schedules): array 66 66 { 67 67 $schedules['camoo_cdn_cron_every_four_days'] = [ -
camoo-cdn/trunk/src/Services/QueryCaching.php
r3070018 r3190658 4 4 5 5 namespace WP_CAMOO\CDN\Services; 6 7 use WP_CAMOO\CDN\Gateways\Option;8 use WP_Query;9 6 10 7 if (!defined('ABSPATH')) { 11 8 exit; // Exit if accessed directly 12 9 } 10 11 use WP_CAMOO\CDN\Gateways\Option; 12 use WP_Query; 13 13 14 14 final class QueryCaching … … 61 61 { 62 62 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 { 63 77 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 } 69 102 } 70 103 71 104 private static function shouldCache(): bool 72 105 { 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)) { 74 107 self::logDebug("Don't cache loggedin user or non empty Woocommerce cart"); 75 108 … … 89 122 { 90 123 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; 92 126 } 93 127 … … 104 138 private static function isExcluded(string $url): bool 105 139 { 106 $path = parse_url($url, PHP_URL_PATH) ?? '/';140 $path = wp_parse_url($url, PHP_URL_PATH) ?? '/'; 107 141 108 142 // Regular expression to match file extensions that should not be cached … … 161 195 if (defined('WP_DEBUG') && WP_DEBUG && defined('WP_DEBUG_LOG') && WP_DEBUG_LOG) { 162 196 // Define the custom log path 163 $log _path = WP_CONTENT_DIR . '/debug.log';197 $logPath = WP_CONTENT_DIR . '/debug.log'; 164 198 // 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); 167 201 } else { 168 202 error_log(current_time('mysql') . " - Failed to write to log: {$message}\n"); -
camoo-cdn/trunk/src/Services/SyncFiles.php
r3059295 r3190658 42 42 update_option('ossdl_off_cdn_url', $cdnUrl); 43 43 update_option('ossdl_off_blog_url', get_site_url()); 44 add_action( 'admin_init', 'wpsc_admin_bar_delete_cache' ); 44 45 } 45 46 … … 47 48 { 48 49 $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); 50 51 $link_text = __('Managed WordPress packages', 'camoo-cdn'); 51 52 $message_format = __('CDN is not available for your domain: %s. Check our %s out for more.', 'camoo-cdn'); … … 88 89 { 89 90 $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)); 91 92 $response = wp_remote_get($api_url); 92 93 … … 97 98 } 98 99 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); 100 101 } 101 102 -
camoo-cdn/trunk/uninstall.php
r3070018 r3190658 4 4 5 5 /** 6 * Uninstalling CAMOO-CDN, deletes tables, and options. 6 * Uninstall CAMOO-CDN Plugin 7 * 8 * Deletes plugin-related options, transients, and configurations. 7 9 * 8 10 * @version 2.0 9 11 * 10 * License:GPLv2 or later11 * License URI:http://www.gnu.org/licenses/gpl-2.0.html12 * @license GPLv2 or later 13 * @license URI http://www.gnu.org/licenses/gpl-2.0.html 12 14 * 13 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without14 * 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. 15 17 */ 18 19 // Exit if accessed directly outside the uninstallation process. 16 20 defined('WP_UNINSTALL_PLUGIN') || exit; 17 21 22 // Delete plugin-specific options from the database. 18 23 delete_option('wp_camoo_cdn_oss'); 19 24 delete_option('ossdl_off_cdn_url'); … … 22 27 delete_option('camoo_cdn_cache_settings'); 23 28 29 // Delete plugin-specific transients from the database. 24 30 global $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 29 43 $configFile = WP_CONTENT_DIR . '/wp-cache-config.php'; 30 44 if (file_exists($configFile)) {
Note: See TracChangeset
for help on using the changeset viewer.