-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #51 from dartiss/develop
Version 1.7
- Loading branch information
Showing
18 changed files
with
1,050 additions
and
784 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"landingPage": "\/wp-admin\/tools.php?page=transient-options", | ||
"preferredVersions": { | ||
"php": "8.0", | ||
"wp": "latest" | ||
}, | ||
"phpExtensionBundles": [ | ||
"kitchen-sink" | ||
], | ||
"features": { | ||
"networking": true | ||
}, | ||
"steps": [ | ||
{ | ||
"step": "installPlugin", | ||
"pluginZipFile": { | ||
"resource": "url", | ||
"url": "https:\/\/downloads.wordpress.org\/plugin\/artiss-transient-cleaner.zip" | ||
}, | ||
"options": { | ||
"activate": true | ||
} | ||
}, | ||
{ | ||
"step": "login", | ||
"username": "admin", | ||
"password": "password" | ||
} | ||
] | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
<?php | ||
/** | ||
* Clean Transients | ||
* | ||
* Functions to clear down transient data | ||
* | ||
* @package artiss-transient-cleaner | ||
*/ | ||
|
||
// Exit if accessed directly. | ||
|
||
if ( ! defined( 'ABSPATH' ) ) { | ||
exit; | ||
} | ||
|
||
/** | ||
* Delete Transients | ||
* | ||
* Shared function that will clear down requested transients | ||
* | ||
* @param string $clear_all TRUE or FALSE, whether to clear all transients or not. | ||
* @return string Number of removed transients | ||
*/ | ||
function transient_cleaner_transient_delete( $clear_all ) { | ||
|
||
$cleaned = 0; | ||
|
||
global $_wp_using_ext_object_cache; | ||
|
||
if ( ! $_wp_using_ext_object_cache ) { | ||
|
||
$options = transient_cleaner_get_options(); | ||
|
||
global $wpdb; | ||
$records = 0; | ||
|
||
// Build and execute required SQL. | ||
|
||
if ( $clear_all ) { | ||
|
||
// Clean from options table. | ||
|
||
$clean = $wpdb->query( | ||
$wpdb->prepare( | ||
"DELETE FROM $wpdb->options | ||
WHERE option_name LIKE %s", | ||
$wpdb->esc_like( '_transient_' ) . '%' | ||
) | ||
); | ||
$records .= $clean; | ||
|
||
// If multisite, and the main network, also clear the sitemeta table. | ||
|
||
if ( is_multisite() && is_main_network() ) { | ||
$clean = $wpdb->query( | ||
$wpdb->prepare( | ||
"DELETE FROM $wpdb->sitemeta | ||
WHERE meta_key LIKE %s", | ||
$wpdb->esc_like( '_site_transient_' ) . '%' | ||
) | ||
); | ||
$records .= $clean; | ||
} | ||
} else { | ||
|
||
// Delete transients from options table. | ||
|
||
$clean = $wpdb->query( | ||
$wpdb->prepare( | ||
"DELETE a, b FROM {$wpdb->options} a, {$wpdb->options} b | ||
WHERE a.option_name LIKE %s | ||
AND a.option_name NOT LIKE %s | ||
AND b.option_name = CONCAT( '_transient_timeout_', SUBSTRING( a.option_name, CHAR_LENGTH('_transient_') + 1 ) ) | ||
AND b.option_value < %d", | ||
$wpdb->esc_like( '_transient_' ) . '%', | ||
$wpdb->esc_like( '_transient_timeout_' ) . '%', | ||
time() | ||
) | ||
); | ||
$records .= $clean; | ||
|
||
// Delete transients from multisite, if configured as such. | ||
|
||
if ( is_multisite() && is_main_network() ) { | ||
|
||
$clean = $wpdb->query( | ||
$wpdb->prepare( | ||
"DELETE a, b FROM {$wpdb->sitemeta} a, {$wpdb->sitemeta} b | ||
WHERE a.meta_key LIKE %s | ||
AND a.meta_key NOT LIKE %s | ||
AND b.meta_key = CONCAT( '_site_transient_timeout_', SUBSTRING( a.meta_key, CHAR_LENGTH('_site_transient_') + 1 ) ) | ||
AND b.meta_value < %d", | ||
$wpdb->esc_like( '_site_transient_' ) . '%', | ||
$wpdb->esc_like( '_site_transient_timeout_' ) . '%', | ||
time() | ||
) | ||
); | ||
$records .= $clean; | ||
} | ||
} | ||
|
||
// Save options field with number & timestamp. | ||
|
||
$results = array(); | ||
|
||
$results['timestamp'] = time() + ( get_option( 'gmt_offset' ) * 3600 ); | ||
$results['records'] = $records; | ||
|
||
$option_name = 'transient_clean_'; | ||
if ( $clear_all ) { | ||
$option_name .= 'all'; | ||
} else { | ||
$option_name .= 'expired'; | ||
} | ||
update_option( $option_name, $results ); | ||
|
||
// Optimize the table after the deletions. | ||
|
||
if ( ( ( $options['upgrade_optimize'] ) && ( $clear_all ) ) || ( ( $options['clean_optimize'] ) && ( ! $clear_all ) ) ) { | ||
$wpdb->query( "OPTIMIZE TABLE $wpdb->options" ); | ||
if ( is_multisite() && is_main_network() ) { | ||
$wpdb->query( "OPTIMIZE TABLE $wpdb->sitemeta" ); | ||
} | ||
} | ||
} | ||
|
||
return $cleaned; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
<?php | ||
/** | ||
* Scheduler | ||
* | ||
* Set up scheduler and hooks for performing the cleaning process. | ||
* | ||
* @package artiss-transient-cleaner | ||
*/ | ||
|
||
// Exit if accessed directly. | ||
|
||
if ( ! defined( 'ABSPATH' ) ) { | ||
exit; | ||
} | ||
|
||
/** | ||
* Clean Expired Transients | ||
* | ||
* Hook into scheduled deletions and clear down expired transients | ||
* | ||
* @return string Number of transients removed | ||
*/ | ||
function transient_cleaner_clean_transients() { | ||
|
||
$cleaned = 0; | ||
|
||
// Only perform clean if enabled. | ||
|
||
$options = transient_cleaner_get_options(); | ||
|
||
if ( $options['clean_enable'] ) { | ||
$cleaned = transient_cleaner_transient_delete( false ); | ||
} | ||
|
||
// Return number of cleaned transients. | ||
|
||
return $cleaned; | ||
} | ||
|
||
add_action( 'housekeep_transients', 'transient_cleaner_clean_transients' ); | ||
|
||
/** | ||
* Set cleaning schedule | ||
* | ||
* Set up scheduler for transient cleaning | ||
*/ | ||
function transient_cleaner_set_up_scheduler() { | ||
|
||
global $_wp_using_ext_object_cache; | ||
|
||
// Check for conditions under which the scheduler requires settings up. | ||
|
||
if ( ! wp_next_scheduled( 'housekeep_transients' ) && ! wp_installing() && ! $_wp_using_ext_object_cache ) { | ||
$schedule = true; | ||
} else { | ||
$schedule = false; | ||
} | ||
|
||
// Set up schedule, if required. | ||
|
||
if ( $schedule ) { | ||
$options = transient_cleaner_get_options(); | ||
transient_cleaner_set_schedule( $options['schedule'] ); | ||
} | ||
} | ||
|
||
add_action( 'init', 'transient_cleaner_set_up_scheduler' ); | ||
|
||
/** | ||
* Set scheduler | ||
* | ||
* Set up scheduler. | ||
* | ||
* @param string $hour The hour to be scheduled. | ||
* @return string The hour parameter that was used | ||
*/ | ||
function transient_cleaner_set_schedule( $hour ) { | ||
|
||
// If the hour to be set is before now, setting it will cause the schedule to run immediately | ||
// Therefore, in this case it's set to that time for tomorrow. | ||
|
||
$hour .= ':00'; | ||
if ( $hour <= gmdate( 'H' ) ) { | ||
$hour .= ' tomorrow'; | ||
} | ||
|
||
// Now create the scheduled event. | ||
|
||
wp_schedule_event( strtotime( $hour ), 'daily', 'housekeep_transients' ); | ||
|
||
return $hour; | ||
} | ||
|
||
/** | ||
* Clear All Transients | ||
* | ||
* Hook into database upgrade and clear transients | ||
* | ||
* @return string Number of transients removed | ||
*/ | ||
function transient_cleaner_clear_transients() { | ||
|
||
$cleared = 0; | ||
|
||
// Only perform clear if enabled. | ||
|
||
$options = transient_cleaner_get_options(); | ||
|
||
if ( $options['upgrade_enable'] ) { | ||
$cleared = transient_cleaner_transient_delete( true ); | ||
} | ||
|
||
// Return number of cleared transients. | ||
|
||
return $cleared; | ||
} | ||
|
||
add_action( 'after_db_upgrade', 'transient_cleaner_clear_transients' ); | ||
add_action( 'clear_all_transients', 'transient_cleaner_clear_transients' ); |
Oops, something went wrong.