diff --git a/includes/functions/settings/_settings_actions.php b/includes/functions/settings/_settings_actions.php index 220e0b10..ae28f41e 100644 --- a/includes/functions/settings/_settings_actions.php +++ b/includes/functions/settings/_settings_actions.php @@ -991,7 +991,7 @@ function fictioneer_tools_optimize_database() { ) "); - // Comment meta + // Delete comment meta $comment_meta_count = $wpdb->query(" DELETE FROM $wpdb->commentmeta WHERE ( diff --git a/repo/graveyard/discarded.php b/repo/graveyard/discarded.php index 9ace7c67..0a40ff5a 100644 --- a/repo/graveyard/discarded.php +++ b/repo/graveyard/discarded.php @@ -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 ); + + ?>