• Resolved Wendihihihi

    (@wendihihihi)


    If you press Save on the Settings page you get this error:

    Warning: Undefined array key “scan-hour-am” in /home2/mxxxx/public_html/kxxxx/wp-content/plugins/website-file-changes-monitor/classes/admin/class-admin-manager.php on line 487

    Fatal error: Uncaught TypeError: strtoupper(): Argument #1 ($string) must be of type string, null given in /home2/mxxxx/public_html/kxxxx/wp-content/plugins/website-file-changes-monitor/classes/admin/class-admin-manager.php:487 Stack trace: #0 /home2/mxxxx/public_html/kxxxx/wp-content/plugins/website-file-changes-monitor/classes/admin/class-admin-manager.php(487): strtoupper() #1 /home2/mxxxx/public_html/kxxxx/wp-includes/class-wp-hook.php(324): MFM\Admin\Admin_Manager::save_options() #2 /home2/mxxxx/public_html/kxxxx/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters() #3 /home2/mxxxx/public_html/kxxxx/wp-includes/plugin.php(517): WP_Hook->do_action() #4 /home2/mxxxx/public_html/kxxxx/wp-admin/admin.php(238): do_action() #5 {main} thrown in /home2/mxxxx/public_html/kxxxx/wp-content/plugins/website-file-changes-monitor/classes/admin/class-admin-manager.php on line 487

    The patch on the website, which I don’t want to use because it’s not checked by WordPress, is also not there anymore.

    Please update the plugin

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter Wendihihihi

    (@wendihihihi)

    This works for me

    /**

    • Save plugin settings.
      *
    • @return void
      *
    • @since 2.0.0
      */
      public static function save_options() {
      $nonce = isset( $_POST[‘mfm-settings-save-nonce’] ) ? sanitize_key( wp_unslash( $_POST[‘mfm-settings-save-nonce’] ) ) : ”;
      if ( ! current_user_can( ‘manage_options’ ) || ! wp_verify_nonce( $nonce, ‘mfm-settings-save’ ) || ! isset( $_POST[‘mfm-settings’] ) ) {
      return;
      } $expected = Settings_Helper::get_mfm_settings();
      $posted_raw = wp_unslash( $_POST[‘mfm-settings’] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
      $posted = is_array( $posted_raw ) ? $posted_raw : array(); $sanitize_value = static function( $value ) {
      if ( is_array( $value ) ) {
      return array_map( static function( $v ) {
      return is_scalar( $v ) ? sanitize_text_field( (string) $v ) : ”;
      }, $value );
      }
      return is_scalar( $value ) ? sanitize_text_field( (string) $value ) : ”;
      }; if ( isset( $posted[‘scan-hour’] ) ) {
      $posted_hour = sprintf(
      ‘%02d’,
      is_numeric( $posted[‘scan-hour’] ) ? (int) $posted[‘scan-hour’] : (int) Settings_Helper::get_settings_default_value( ‘scan-hour’ )
      ); $posted_am_pm_raw = isset( $posted['scan-hour-am'] ) ? (string) $posted['scan-hour-am'] : (string) Settings_Helper::get_settings_default_value( 'scan-hour-am' ); $posted_am_pm = strtoupper( $posted_am_pm_raw ); $posted_scan_time = $posted_hour . ':00' . ' ' . $posted_am_pm; // phpcs:ignore Generic.Strings.UnnecessaryStringConcat.Found $current_hour = sprintf( '%02d', (int) get_site_option( MFM_PREFIX . 'scan-hour', Settings_Helper::get_settings_default_value( 'scan-hour' ) ) ); $current_am_pm = strtoupper( (string) get_site_option( MFM_PREFIX . 'scan-hour-am', Settings_Helper::get_settings_default_value( 'scan-hour-am' ) ) ); $current_scan_time = $current_hour . ':00' . ' ' . $current_am_pm; // phpcs:ignore Generic.Strings.UnnecessaryStringConcat.Found $posted_freq = isset( $posted['scan-frequency'] ) ? (string) $posted['scan-frequency'] : (string) Settings_Helper::get_settings_default_value( 'scan-frequency' ); if ( 'weekly' === $posted_freq ) { $posted_day_raw = isset( $posted['scan-day'] ) ? $posted['scan-day'] : Settings_Helper::get_settings_default_value( 'scan-day' ); $current_day_raw = get_site_option( MFM_PREFIX . 'scan-day', Settings_Helper::get_settings_default_value( 'scan-day' ) );$posted_scan_time .= ' ' . Settings_Helper::convert_to_day_string( $posted_day_raw ); $current_scan_time .= ' ' . Settings_Helper::convert_to_day_string( $current_day_raw );} if ( $posted_scan_time !== $current_scan_time ) { do_action( MFM_PREFIX . 'scan_time_updated', $current_scan_time, $posted_scan_time ); Settings_Helper::clear_scan_schedule(); } } foreach ( array_keys( $expected ) as $expected_key ) {
      if ( array_key_exists( $expected_key, $posted ) ) {
      $value = $sanitize_value( $posted[ $expected_key ] );
      if ( ! Settings_Helper::save_setting( $expected_key, $value ) ) {
      self::$settings_validation_errors[] = $expected_key;
      add_action( ‘admin_notices’, array( CLASS, ‘settings_cannot_save_notice’ ) );
      return;
      }
      } else {
      if ( ! Settings_Helper::save_setting( $expected_key, ‘no’ ) ) {
      self::$settings_validation_errors[] = $expected_key;
      add_action( ‘admin_notices’, array( CLASS, ‘settings_cannot_save_notice’ ) );
      return;
      }
      }
      } add_action( ‘admin_notices’, array( CLASS, ‘settings_saved_notice’ ) );
      }
    Plugin Support Lucian Padureanu

    (@lucianwpwhite)

    Hello @wendihihihi,

    I’m very sorry to hear about your experience, and also for the delay in getting back to you. It seems this ticket slipped off our radar, and I truly apologize for that.

    Could you please reach out to us directly at [email protected] so we can exchange a bit more information about this error? We’ll be glad to take a closer look and help resolve it as soon as possible.

    Many thanks!

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Error when saving settings’ is closed to new replies.