From 841f8d9f4824afe97c332d011a5ee72f155f6f67 Mon Sep 17 00:00:00 2001 From: Erik Golinelli Date: Mon, 22 Jan 2024 08:35:43 +0100 Subject: [PATCH] fixes the plugin update function that was removing the "enabled" flag under some conditions --- admin/CF7_AntiSpam_Admin_Core.php | 7 ++++++- engine/CF7_AntiSpam_Activator.php | 11 +++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/admin/CF7_AntiSpam_Admin_Core.php b/admin/CF7_AntiSpam_Admin_Core.php index 24b066e..1e672db 100644 --- a/admin/CF7_AntiSpam_Admin_Core.php +++ b/admin/CF7_AntiSpam_Admin_Core.php @@ -96,7 +96,12 @@ public function cf7a_admin_menu() { * @return array Modified array of plugin action links. */ public function cf7a_plugin_settings_link( array $links ) { - $settings_page_link = sprintf( '%s', admin_url( 'admin.php?page=cf7-antispam' ), esc_html__( 'Antispam Settings', 'cf7-antispam' ) ); + $options = get_option( 'cf7a_options' ); + if ( $options['cf7a_enable'] ) { + $settings_page_link = sprintf( '%s', admin_url( 'admin.php?page=cf7-antispam' ), esc_html__( 'Antispam Settings', 'cf7-antispam' ) ); + } else { + $settings_page_link = sprintf( '%s', admin_url( 'admin.php?page=wpcf7-integration' ), esc_html__( 'Activate Contact Form 7 integration', 'cf7-antispam' ) ); + } array_unshift( $links, $settings_page_link ); return $links; diff --git a/engine/CF7_AntiSpam_Activator.php b/engine/CF7_AntiSpam_Activator.php index 22f51bb..ab1e75f 100644 --- a/engine/CF7_AntiSpam_Activator.php +++ b/engine/CF7_AntiSpam_Activator.php @@ -213,8 +213,12 @@ public static function update_options( $reset_options = false ) { $options = get_option( 'cf7a_options' ); - if ( false !== $options && ! $reset_options ) { + if ( empty( $options ) || $reset_options ) { + /* if the plugin options are missing Init the plugin with the default option + the default settings */ + $new_options = array_merge( self::$default_cf7a_options, self::$default_cf7a_options_bootstrap ); + add_option( 'cf7a_options', $new_options ); + } else { /* update the plugin options but add the new options automatically */ if ( isset( $options['cf7a_version'] ) ) { unset( $options['cf7a_version'] ); @@ -226,11 +230,6 @@ public static function update_options( $reset_options = false ) { cf7a_log( 'CF7-antispam plugin options updated', 1 ); update_option( 'cf7a_options', $new_options ); - } else { - /* if the plugin options are missing Init the plugin with the default option + the default settings */ - $new_options = array_merge( self::$default_cf7a_options, self::$default_cf7a_options_bootstrap ); - - add_option( 'cf7a_options', $new_options ); } cf7a_log( $new_options, 1 );