| @@ -339,13 +339,9 @@ | ||
| 339 | 339 | $sanitized['autogenerate'] = sanitize_key( $config['autogenerate'] ); |
| 340 | 340 | } |
| 341 | 341 | |
| 342 | 342 | if ( isset( $config['storage'] ) ) { |
| 343 | - $storage = self::sanitize_storage_path( $config['storage'] ); | |
| 344 | - | |
| 345 | - if ( ! empty( $storage ) ) { | |
| 346 | - $sanitized['storage'] = $storage; | |
| 347 | - } | |
| 343 | + $sanitized['storage'] = sanitize_text_field( $config['storage'] ); | |
| 348 | 344 | } |
| 349 | 345 | |
| 350 | 346 | if ( isset( $config['suspend'] ) ) { |
| 351 | 347 | $sanitized['suspend'] = 'suspend'; |
| @@ -393,16 +389,10 @@ | ||
| 393 | 389 | * |
| 394 | 390 | * @return array Path and url to upload directory. |
| 395 | 391 | */ |
| 396 | 392 | private static function create_upload_dir( $storage ) { |
| 397 | - $storage = self::sanitize_storage_path( $storage ); | |
| 393 | + $storage = trim( $storage, '/' ); | |
| 398 | 394 | |
| 399 | - if ( empty( $storage ) ) { | |
| 400 | - $directory = wp_upload_dir(); | |
| 401 | - | |
| 402 | - return array( $directory['path'], $directory['url'] ); | |
| 403 | - } | |
| 404 | - | |
| 405 | 395 | /** |
| 406 | 396 | * Change permissions when creating new folders. |
| 407 | 397 | * |
| 408 | 398 | * @param int $permissions New directory access permissions. By default 0755. |
| @@ -412,41 +402,6 @@ | ||
| 412 | 402 | // We do not pay attention to the possible error. |
| 413 | 403 | wp_mkdir_p( ABSPATH . $storage, $permissions, true ); |
| 414 | 404 | |
| 415 | 405 | return array( ABSPATH . $storage, site_url( $storage ) ); |
| 416 | - } | |
| 417 | - | |
| 418 | - /** | |
| 419 | - * Sanitize custom storage path. | |
| 420 | - * | |
| 421 | - * @param string $storage Relative directory path from WordPress root. | |
| 422 | - * | |
| 423 | - * @return string Sanitized path, or empty string when invalid. | |
| 424 | - */ | |
| 425 | - private static function sanitize_storage_path( $storage ) { | |
| 426 | - if ( ! is_scalar( $storage ) ) { | |
| 427 | - return ''; | |
| 428 | - } | |
| 429 | - | |
| 430 | - $storage = sanitize_text_field( $storage ); | |
| 431 | - $storage = wp_normalize_path( $storage ); | |
| 432 | - $storage = trim( $storage, '/' ); | |
| 433 | - | |
| 434 | - if ( '' === $storage || '.' === $storage ) { | |
| 435 | - return ''; | |
| 436 | - } | |
| 437 | - | |
| 438 | - if ( false !== strpos( $storage, '://' ) || false !== strpos( $storage, ':' ) ) { | |
| 439 | - return ''; | |
| 440 | - } | |
| 441 | - | |
| 442 | - $parts = explode( '/', $storage ); | |
| 443 | - | |
| 444 | - foreach ( $parts as $part ) { | |
| 445 | - if ( '' === $part || '.' === $part || '..' === $part ) { | |
| 446 | - return ''; | |
| 447 | - } | |
| 448 | - } | |
| 449 | - | |
| 450 | - return implode( '/', $parts ); | |
| 451 | 406 | } |
| 452 | 407 | } |