array( 'enumeration' => 0, 'file_editor' => 0, 'xmlrpc' => 0, 'version' => 0, 'headers' => 0, ), 'alerts_enabled' => 0, ); } /** * Saved settings merged over defaults (shape-safe). * * @return array */ public static function get() { $saved = get_option( self::OPTION, array() ); return self::sanitize( is_array( $saved ) ? $saved : array() ); } /** * Coerce any input into the exact settings shape with 0/1 values. * * @param mixed $input Raw. * @return array */ public static function sanitize( $input ) { $def = self::defaults(); $input = is_array( $input ) ? $input : array(); $out = array( 'fixes' => array() ); $in_fixes = ( isset( $input['fixes'] ) && is_array( $input['fixes'] ) ) ? $input['fixes'] : array(); foreach ( $def['fixes'] as $key => $unused ) { $out['fixes'][ $key ] = empty( $in_fixes[ $key ] ) ? 0 : 1; } $out['alerts_enabled'] = empty( $input['alerts_enabled'] ) ? 0 : 1; return $out; } /** * Whether a specific fix is enabled. * * @param string $key Fix key. * @return bool */ public static function fix_on( $key ) { $s = self::get(); return ! empty( $s['fixes'][ $key ] ); } }