*/ public static function defaults() { return array( 'asset_loading' => 'conditional', // conditional|always. 'editor_integration' => 1, 'a11y_defaults' => 1, 'reduced_motion' => 'respect', // respect|force|off. 'debug_logging' => 0, 'remove_data_uninstall'=> 0, 'telemetry_consent' => 0, // Stored only. Nothing reads this to send data. 'core_rules_default' => 'off', // off|show_hide. ); } /** * @return array */ public static function all() { $stored = get_option( Edition::OPTION_SETTINGS, array() ); if ( ! is_array( $stored ) ) { $stored = array(); } return array_merge( self::defaults(), $stored ); } /** * @param string $key Setting key. * @param mixed $default Default. * @return mixed */ public static function get( $key, $default = null ) { $all = self::all(); return array_key_exists( $key, $all ) ? $all[ $key ] : $default; } /** * @param array $input Raw input. * @return array */ public static function sanitize( array $input ) { $defaults = self::defaults(); $out = self::all(); if ( isset( $input['asset_loading'] ) ) { $v = sanitize_key( (string) $input['asset_loading'] ); $out['asset_loading'] = in_array( $v, array( 'conditional', 'always' ), true ) ? $v : $defaults['asset_loading']; } $out['editor_integration'] = empty( $input['editor_integration'] ) ? 0 : 1; $out['a11y_defaults'] = empty( $input['a11y_defaults'] ) ? 0 : 1; if ( isset( $input['reduced_motion'] ) ) { $v = sanitize_key( (string) $input['reduced_motion'] ); $out['reduced_motion'] = in_array( $v, array( 'respect', 'force', 'off' ), true ) ? $v : $defaults['reduced_motion']; } $out['debug_logging'] = empty( $input['debug_logging'] ) ? 0 : 1; $out['remove_data_uninstall'] = empty( $input['remove_data_uninstall'] ) ? 0 : 1; $out['telemetry_consent'] = empty( $input['telemetry_consent'] ) ? 0 : 1; if ( isset( $input['core_rules_default'] ) ) { $v = sanitize_key( (string) $input['core_rules_default'] ); $out['core_rules_default'] = in_array( $v, array( 'off', 'show_hide' ), true ) ? $v : $defaults['core_rules_default']; } return $out; } /** * @param array $input Raw input. * @return array */ public static function save( array $input ) { $clean = self::sanitize( $input ); update_option( Edition::OPTION_SETTINGS, $clean, false ); return $clean; } }