+ protected static function organizeFilesByOption( $files, $option, $default ) {
+ $organizedFiles = array();
+ foreach ( (array) $files as $key => $value ) {
+ if ( is_int( $key ) ) {
+ // File name as the value
+ if ( !isset( $organizedFiles[$default] ) ) {
+ $organizedFiles[$default] = array();
+ }
+ $organizedFiles[$default][] = $value;
+ } else if ( is_array( $value ) ) {
+ // File name as the key, options array as the value
+ $media = isset( $value[$option] ) ? $value[$option] : $default;
+ if ( !isset( $organizedFiles[$media] ) ) {
+ $organizedFiles[$media] = array();
+ }
+ $organizedFiles[$media][] = $key;
+ }
+ }
+ return $organizedFiles;
+ }
+