*/ public static function defaults() : array { return array( 'delete_all_data' => 'no', 'show_credit' => 'default', ); } /** * Return the active settings, merged over defaults. * * @return array */ public static function get() : array { $saved = get_option( self::OPTION_KEY, array() ); if ( !is_array( $saved ) ) { $saved = array(); } return array_merge( self::defaults(), $saved ); } /** * Whether the "Powered by SugarCalc" credit should display on the front-end. * * The credit is optional and defaults to not showing on the site's front * end (issue 00032 / WP Guideline 10); it displays only when enabled for * the installation. * * @return bool */ public static function show_credit() : bool { // Free build: explicit opt-in only, off by default. return 'yes' === (string) (self::get()['show_credit'] ?? 'default'); } /** * Sanitise and persist settings. Only the fields present in $data that * this class owns are written; every other stored key round-trips * untouched, so a settings save in one build never discards values * written by another. * * @param array $data Raw field values keyed by field name. */ public static function save( array $data ) : void { $saved = get_option( self::OPTION_KEY, array() ); if ( !is_array( $saved ) ) { $saved = array(); } update_option( self::OPTION_KEY, array_merge( $saved, self::sanitise( $data ) ) ); } /** * Sanitise the owned fields present in $data. * * @param array $data Raw input data to sanitise. * @return array */ public static function sanitise( array $data ) : array { $clean = array(); if ( array_key_exists( 'delete_all_data', $data ) ) { $clean['delete_all_data'] = ( 'yes' === $data['delete_all_data'] ? 'yes' : 'no' ); } if ( array_key_exists( 'show_credit', $data ) ) { $show_credit = (string) $data['show_credit']; $clean['show_credit'] = ( in_array( $show_credit, array('yes', 'no', 'default'), true ) ? $show_credit : 'default' ); } return $clean; } }