Test and discard cleanup function for options

This commit is contained in:
Tetrakern 2023-11-08 00:04:00 +01:00
parent e0e2935d72
commit 72b3789125
2 changed files with 32 additions and 1 deletions

View File

@ -991,7 +991,7 @@ function fictioneer_tools_optimize_database() {
)
");
// Comment meta
// Delete comment meta
$comment_meta_count = $wpdb->query("
DELETE FROM $wpdb->commentmeta
WHERE (

View File

@ -666,4 +666,35 @@ if ( ! function_exists( 'fictioneer_has_role' ) ) {
}
}
// =============================================================================
// CLEANUP
// =============================================================================
/**
* When a fictioneer option is updated as empty, the option is deleted
*
* @since Fictioneer 5.7.5
*
* @param string $option The option name.
* @param mixed $old_value The previous value.
* @param mixed $value The new value.
*/
function fictioneer_delete_null_option( $option, $old_value, $value ) {
// Theme option?
if (
! array_key_exists( $option, FICTIONEER_OPTIONS['booleans'] ) &&
! array_key_exists( $option, FICTIONEER_OPTIONS['strings'] )
) {
return;
}
// Delete empty options
if ( empty( $value ) ) {
delete_option( $option );
}
}
add_action( 'updated_option', 'fictioneer_delete_null_option', 20, 3 );
?>