Edit File by line
/home/barbar84/www/wp-admin/includes
File: file.php
$written = fwrite( $f, $content );
[500] Fix | Delete
fclose( $f );
[501] Fix | Delete
if ( false === $written ) {
[502] Fix | Delete
return new WP_Error( 'unable_to_write', __( 'Unable to write to file.' ) );
[503] Fix | Delete
}
[504] Fix | Delete
[505] Fix | Delete
wp_opcache_invalidate( $real_file, true );
[506] Fix | Delete
[507] Fix | Delete
if ( $is_active && 'php' === $extension ) {
[508] Fix | Delete
[509] Fix | Delete
$scrape_key = md5( rand() );
[510] Fix | Delete
$transient = 'scrape_key_' . $scrape_key;
[511] Fix | Delete
$scrape_nonce = (string) rand();
[512] Fix | Delete
// It shouldn't take more than 60 seconds to make the two loopback requests.
[513] Fix | Delete
set_transient( $transient, $scrape_nonce, 60 );
[514] Fix | Delete
[515] Fix | Delete
$cookies = wp_unslash( $_COOKIE );
[516] Fix | Delete
$scrape_params = array(
[517] Fix | Delete
'wp_scrape_key' => $scrape_key,
[518] Fix | Delete
'wp_scrape_nonce' => $scrape_nonce,
[519] Fix | Delete
);
[520] Fix | Delete
$headers = array(
[521] Fix | Delete
'Cache-Control' => 'no-cache',
[522] Fix | Delete
);
[523] Fix | Delete
[524] Fix | Delete
/** This filter is documented in wp-includes/class-wp-http-streams.php */
[525] Fix | Delete
$sslverify = apply_filters( 'https_local_ssl_verify', false );
[526] Fix | Delete
[527] Fix | Delete
// Include Basic auth in loopback requests.
[528] Fix | Delete
if ( isset( $_SERVER['PHP_AUTH_USER'] ) && isset( $_SERVER['PHP_AUTH_PW'] ) ) {
[529] Fix | Delete
$headers['Authorization'] = 'Basic ' . base64_encode( wp_unslash( $_SERVER['PHP_AUTH_USER'] ) . ':' . wp_unslash( $_SERVER['PHP_AUTH_PW'] ) );
[530] Fix | Delete
}
[531] Fix | Delete
[532] Fix | Delete
// Make sure PHP process doesn't die before loopback requests complete.
[533] Fix | Delete
set_time_limit( 300 );
[534] Fix | Delete
[535] Fix | Delete
// Time to wait for loopback requests to finish.
[536] Fix | Delete
$timeout = 100;
[537] Fix | Delete
[538] Fix | Delete
$needle_start = "###### wp_scraping_result_start:$scrape_key ######";
[539] Fix | Delete
$needle_end = "###### wp_scraping_result_end:$scrape_key ######";
[540] Fix | Delete
[541] Fix | Delete
// Attempt loopback request to editor to see if user just whitescreened themselves.
[542] Fix | Delete
if ( $plugin ) {
[543] Fix | Delete
$url = add_query_arg( compact( 'plugin', 'file' ), admin_url( 'plugin-editor.php' ) );
[544] Fix | Delete
} elseif ( isset( $stylesheet ) ) {
[545] Fix | Delete
$url = add_query_arg(
[546] Fix | Delete
array(
[547] Fix | Delete
'theme' => $stylesheet,
[548] Fix | Delete
'file' => $file,
[549] Fix | Delete
),
[550] Fix | Delete
admin_url( 'theme-editor.php' )
[551] Fix | Delete
);
[552] Fix | Delete
} else {
[553] Fix | Delete
$url = admin_url();
[554] Fix | Delete
}
[555] Fix | Delete
[556] Fix | Delete
if ( function_exists( 'session_status' ) && PHP_SESSION_ACTIVE === session_status() ) {
[557] Fix | Delete
// Close any active session to prevent HTTP requests from timing out
[558] Fix | Delete
// when attempting to connect back to the site.
[559] Fix | Delete
session_write_close();
[560] Fix | Delete
}
[561] Fix | Delete
[562] Fix | Delete
$url = add_query_arg( $scrape_params, $url );
[563] Fix | Delete
$r = wp_remote_get( $url, compact( 'cookies', 'headers', 'timeout', 'sslverify' ) );
[564] Fix | Delete
$body = wp_remote_retrieve_body( $r );
[565] Fix | Delete
$scrape_result_position = strpos( $body, $needle_start );
[566] Fix | Delete
[567] Fix | Delete
$loopback_request_failure = array(
[568] Fix | Delete
'code' => 'loopback_request_failed',
[569] Fix | Delete
'message' => __( 'Unable to communicate back with site to check for fatal errors, so the PHP change was reverted. You will need to upload your PHP file change by some other means, such as by using SFTP.' ),
[570] Fix | Delete
);
[571] Fix | Delete
$json_parse_failure = array(
[572] Fix | Delete
'code' => 'json_parse_error',
[573] Fix | Delete
);
[574] Fix | Delete
[575] Fix | Delete
$result = null;
[576] Fix | Delete
if ( false === $scrape_result_position ) {
[577] Fix | Delete
$result = $loopback_request_failure;
[578] Fix | Delete
} else {
[579] Fix | Delete
$error_output = substr( $body, $scrape_result_position + strlen( $needle_start ) );
[580] Fix | Delete
$error_output = substr( $error_output, 0, strpos( $error_output, $needle_end ) );
[581] Fix | Delete
$result = json_decode( trim( $error_output ), true );
[582] Fix | Delete
if ( empty( $result ) ) {
[583] Fix | Delete
$result = $json_parse_failure;
[584] Fix | Delete
}
[585] Fix | Delete
}
[586] Fix | Delete
[587] Fix | Delete
// Try making request to homepage as well to see if visitors have been whitescreened.
[588] Fix | Delete
if ( true === $result ) {
[589] Fix | Delete
$url = home_url( '/' );
[590] Fix | Delete
$url = add_query_arg( $scrape_params, $url );
[591] Fix | Delete
$r = wp_remote_get( $url, compact( 'cookies', 'headers', 'timeout', 'sslverify' ) );
[592] Fix | Delete
$body = wp_remote_retrieve_body( $r );
[593] Fix | Delete
$scrape_result_position = strpos( $body, $needle_start );
[594] Fix | Delete
[595] Fix | Delete
if ( false === $scrape_result_position ) {
[596] Fix | Delete
$result = $loopback_request_failure;
[597] Fix | Delete
} else {
[598] Fix | Delete
$error_output = substr( $body, $scrape_result_position + strlen( $needle_start ) );
[599] Fix | Delete
$error_output = substr( $error_output, 0, strpos( $error_output, $needle_end ) );
[600] Fix | Delete
$result = json_decode( trim( $error_output ), true );
[601] Fix | Delete
if ( empty( $result ) ) {
[602] Fix | Delete
$result = $json_parse_failure;
[603] Fix | Delete
}
[604] Fix | Delete
}
[605] Fix | Delete
}
[606] Fix | Delete
[607] Fix | Delete
delete_transient( $transient );
[608] Fix | Delete
[609] Fix | Delete
if ( true !== $result ) {
[610] Fix | Delete
[611] Fix | Delete
// Roll-back file change.
[612] Fix | Delete
file_put_contents( $real_file, $previous_content );
[613] Fix | Delete
wp_opcache_invalidate( $real_file, true );
[614] Fix | Delete
[615] Fix | Delete
if ( ! isset( $result['message'] ) ) {
[616] Fix | Delete
$message = __( 'Something went wrong.' );
[617] Fix | Delete
} else {
[618] Fix | Delete
$message = $result['message'];
[619] Fix | Delete
unset( $result['message'] );
[620] Fix | Delete
}
[621] Fix | Delete
return new WP_Error( 'php_error', $message, $result );
[622] Fix | Delete
}
[623] Fix | Delete
}
[624] Fix | Delete
[625] Fix | Delete
if ( $theme instanceof WP_Theme ) {
[626] Fix | Delete
$theme->cache_delete();
[627] Fix | Delete
}
[628] Fix | Delete
[629] Fix | Delete
return true;
[630] Fix | Delete
}
[631] Fix | Delete
[632] Fix | Delete
[633] Fix | Delete
/**
[634] Fix | Delete
* Returns a filename of a temporary unique file.
[635] Fix | Delete
*
[636] Fix | Delete
* Please note that the calling function must unlink() this itself.
[637] Fix | Delete
*
[638] Fix | Delete
* The filename is based off the passed parameter or defaults to the current unix timestamp,
[639] Fix | Delete
* while the directory can either be passed as well, or by leaving it blank, default to a writable
[640] Fix | Delete
* temporary directory.
[641] Fix | Delete
*
[642] Fix | Delete
* @since 2.6.0
[643] Fix | Delete
*
[644] Fix | Delete
* @param string $filename Optional. Filename to base the Unique file off. Default empty.
[645] Fix | Delete
* @param string $dir Optional. Directory to store the file in. Default empty.
[646] Fix | Delete
* @return string A writable filename.
[647] Fix | Delete
*/
[648] Fix | Delete
function wp_tempnam( $filename = '', $dir = '' ) {
[649] Fix | Delete
if ( empty( $dir ) ) {
[650] Fix | Delete
$dir = get_temp_dir();
[651] Fix | Delete
}
[652] Fix | Delete
[653] Fix | Delete
if ( empty( $filename ) || in_array( $filename, array( '.', '/', '\\' ), true ) ) {
[654] Fix | Delete
$filename = uniqid();
[655] Fix | Delete
}
[656] Fix | Delete
[657] Fix | Delete
// Use the basename of the given file without the extension as the name for the temporary directory.
[658] Fix | Delete
$temp_filename = basename( $filename );
[659] Fix | Delete
$temp_filename = preg_replace( '|\.[^.]*$|', '', $temp_filename );
[660] Fix | Delete
[661] Fix | Delete
// If the folder is falsey, use its parent directory name instead.
[662] Fix | Delete
if ( ! $temp_filename ) {
[663] Fix | Delete
return wp_tempnam( dirname( $filename ), $dir );
[664] Fix | Delete
}
[665] Fix | Delete
[666] Fix | Delete
// Suffix some random data to avoid filename conflicts.
[667] Fix | Delete
$temp_filename .= '-' . wp_generate_password( 6, false );
[668] Fix | Delete
$temp_filename .= '.tmp';
[669] Fix | Delete
$temp_filename = $dir . wp_unique_filename( $dir, $temp_filename );
[670] Fix | Delete
[671] Fix | Delete
$fp = @fopen( $temp_filename, 'x' );
[672] Fix | Delete
if ( ! $fp && is_writable( $dir ) && file_exists( $temp_filename ) ) {
[673] Fix | Delete
return wp_tempnam( $filename, $dir );
[674] Fix | Delete
}
[675] Fix | Delete
if ( $fp ) {
[676] Fix | Delete
fclose( $fp );
[677] Fix | Delete
}
[678] Fix | Delete
[679] Fix | Delete
return $temp_filename;
[680] Fix | Delete
}
[681] Fix | Delete
[682] Fix | Delete
/**
[683] Fix | Delete
* Makes sure that the file that was requested to be edited is allowed to be edited.
[684] Fix | Delete
*
[685] Fix | Delete
* Function will die if you are not allowed to edit the file.
[686] Fix | Delete
*
[687] Fix | Delete
* @since 1.5.0
[688] Fix | Delete
*
[689] Fix | Delete
* @param string $file File the user is attempting to edit.
[690] Fix | Delete
* @param string[] $allowed_files Optional. Array of allowed files to edit.
[691] Fix | Delete
* `$file` must match an entry exactly.
[692] Fix | Delete
* @return string|void Returns the file name on success, dies on failure.
[693] Fix | Delete
*/
[694] Fix | Delete
function validate_file_to_edit( $file, $allowed_files = array() ) {
[695] Fix | Delete
$code = validate_file( $file, $allowed_files );
[696] Fix | Delete
[697] Fix | Delete
if ( ! $code ) {
[698] Fix | Delete
return $file;
[699] Fix | Delete
}
[700] Fix | Delete
[701] Fix | Delete
switch ( $code ) {
[702] Fix | Delete
case 1:
[703] Fix | Delete
wp_die( __( 'Sorry, that file cannot be edited.' ) );
[704] Fix | Delete
[705] Fix | Delete
// case 2 :
[706] Fix | Delete
// wp_die( __('Sorry, can’t call files with their real path.' ));
[707] Fix | Delete
[708] Fix | Delete
case 3:
[709] Fix | Delete
wp_die( __( 'Sorry, that file cannot be edited.' ) );
[710] Fix | Delete
}
[711] Fix | Delete
}
[712] Fix | Delete
[713] Fix | Delete
/**
[714] Fix | Delete
* Handles PHP uploads in WordPress.
[715] Fix | Delete
*
[716] Fix | Delete
* Sanitizes file names, checks extensions for mime type, and moves the file
[717] Fix | Delete
* to the appropriate directory within the uploads directory.
[718] Fix | Delete
*
[719] Fix | Delete
* @access private
[720] Fix | Delete
* @since 4.0.0
[721] Fix | Delete
*
[722] Fix | Delete
* @see wp_handle_upload_error
[723] Fix | Delete
*
[724] Fix | Delete
* @param string[] $file Reference to a single element of `$_FILES`.
[725] Fix | Delete
* Call the function once for each uploaded file.
[726] Fix | Delete
* @param array|false $overrides {
[727] Fix | Delete
* An array of override parameters for this file, or boolean false if none are provided.
[728] Fix | Delete
*
[729] Fix | Delete
* @type callable $upload_error_handler Function to call when there is an error during the upload process.
[730] Fix | Delete
* @see wp_handle_upload_error().
[731] Fix | Delete
* @type callable $unique_filename_callback Function to call when determining a unique file name for the file.
[732] Fix | Delete
* @see wp_unique_filename().
[733] Fix | Delete
* @type string[] $upload_error_strings The strings that describe the error indicated in
[734] Fix | Delete
* `$_FILES[{form field}]['error']`.
[735] Fix | Delete
* @type bool $test_form Whether to test that the `$_POST['action']` parameter is as expected.
[736] Fix | Delete
* @type bool $test_size Whether to test that the file size is greater than zero bytes.
[737] Fix | Delete
* @type bool $test_type Whether to test that the mime type of the file is as expected.
[738] Fix | Delete
* @type string[] $mimes Array of allowed mime types keyed by their file extension regex.
[739] Fix | Delete
* }
[740] Fix | Delete
* @param string $time Time formatted in 'yyyy/mm'.
[741] Fix | Delete
* @param string $action Expected value for `$_POST['action']`.
[742] Fix | Delete
* @return string[] On success, returns an associative array of file attributes.
[743] Fix | Delete
* On failure, returns `$overrides['upload_error_handler']( &$file, $message )`
[744] Fix | Delete
* or `array( 'error' => $message )`.
[745] Fix | Delete
*/
[746] Fix | Delete
function _wp_handle_upload( &$file, $overrides, $time, $action ) {
[747] Fix | Delete
// The default error handler.
[748] Fix | Delete
if ( ! function_exists( 'wp_handle_upload_error' ) ) {
[749] Fix | Delete
function wp_handle_upload_error( &$file, $message ) {
[750] Fix | Delete
return array( 'error' => $message );
[751] Fix | Delete
}
[752] Fix | Delete
}
[753] Fix | Delete
[754] Fix | Delete
/**
[755] Fix | Delete
* Filters the data for a file before it is uploaded to WordPress.
[756] Fix | Delete
*
[757] Fix | Delete
* The dynamic portion of the hook name, `$action`, refers to the post action.
[758] Fix | Delete
* Possible filter names include:
[759] Fix | Delete
*
[760] Fix | Delete
* - `wp_handle_sideload_prefilter`
[761] Fix | Delete
* - `wp_handle_upload_prefilter`
[762] Fix | Delete
*
[763] Fix | Delete
* @since 2.9.0 as 'wp_handle_upload_prefilter'.
[764] Fix | Delete
* @since 4.0.0 Converted to a dynamic hook with `$action`.
[765] Fix | Delete
*
[766] Fix | Delete
* @param string[] $file An array of data for the file. Reference to a single element of `$_FILES`.
[767] Fix | Delete
*/
[768] Fix | Delete
$file = apply_filters( "{$action}_prefilter", $file );
[769] Fix | Delete
[770] Fix | Delete
/**
[771] Fix | Delete
* Filters the override parameters for a file before it is uploaded to WordPress.
[772] Fix | Delete
*
[773] Fix | Delete
* The dynamic portion of the hook name, `$action`, refers to the post action.
[774] Fix | Delete
* Possible filter names include:
[775] Fix | Delete
*
[776] Fix | Delete
* - `wp_handle_sideload_overrides`
[777] Fix | Delete
* - `wp_handle_upload_overrides`
[778] Fix | Delete
*
[779] Fix | Delete
* @since 5.7.0
[780] Fix | Delete
*
[781] Fix | Delete
* @param array|false $overrides An array of override parameters for this file. Boolean false if none are
[782] Fix | Delete
* provided. @see _wp_handle_upload().
[783] Fix | Delete
* @param string[] $file An array of data for the file. Reference to a single element of `$_FILES`.
[784] Fix | Delete
*/
[785] Fix | Delete
$overrides = apply_filters( "{$action}_overrides", $overrides, $file );
[786] Fix | Delete
[787] Fix | Delete
// You may define your own function and pass the name in $overrides['upload_error_handler'].
[788] Fix | Delete
$upload_error_handler = 'wp_handle_upload_error';
[789] Fix | Delete
if ( isset( $overrides['upload_error_handler'] ) ) {
[790] Fix | Delete
$upload_error_handler = $overrides['upload_error_handler'];
[791] Fix | Delete
}
[792] Fix | Delete
[793] Fix | Delete
// You may have had one or more 'wp_handle_upload_prefilter' functions error out the file. Handle that gracefully.
[794] Fix | Delete
if ( isset( $file['error'] ) && ! is_numeric( $file['error'] ) && $file['error'] ) {
[795] Fix | Delete
return call_user_func_array( $upload_error_handler, array( &$file, $file['error'] ) );
[796] Fix | Delete
}
[797] Fix | Delete
[798] Fix | Delete
// Install user overrides. Did we mention that this voids your warranty?
[799] Fix | Delete
[800] Fix | Delete
// You may define your own function and pass the name in $overrides['unique_filename_callback'].
[801] Fix | Delete
$unique_filename_callback = null;
[802] Fix | Delete
if ( isset( $overrides['unique_filename_callback'] ) ) {
[803] Fix | Delete
$unique_filename_callback = $overrides['unique_filename_callback'];
[804] Fix | Delete
}
[805] Fix | Delete
[806] Fix | Delete
/*
[807] Fix | Delete
* This may not have originally been intended to be overridable,
[808] Fix | Delete
* but historically has been.
[809] Fix | Delete
*/
[810] Fix | Delete
if ( isset( $overrides['upload_error_strings'] ) ) {
[811] Fix | Delete
$upload_error_strings = $overrides['upload_error_strings'];
[812] Fix | Delete
} else {
[813] Fix | Delete
// Courtesy of php.net, the strings that describe the error indicated in $_FILES[{form field}]['error'].
[814] Fix | Delete
$upload_error_strings = array(
[815] Fix | Delete
false,
[816] Fix | Delete
sprintf(
[817] Fix | Delete
/* translators: 1: upload_max_filesize, 2: php.ini */
[818] Fix | Delete
__( 'The uploaded file exceeds the %1$s directive in %2$s.' ),
[819] Fix | Delete
'upload_max_filesize',
[820] Fix | Delete
'php.ini'
[821] Fix | Delete
),
[822] Fix | Delete
sprintf(
[823] Fix | Delete
/* translators: %s: MAX_FILE_SIZE */
[824] Fix | Delete
__( 'The uploaded file exceeds the %s directive that was specified in the HTML form.' ),
[825] Fix | Delete
'MAX_FILE_SIZE'
[826] Fix | Delete
),
[827] Fix | Delete
__( 'The uploaded file was only partially uploaded.' ),
[828] Fix | Delete
__( 'No file was uploaded.' ),
[829] Fix | Delete
'',
[830] Fix | Delete
__( 'Missing a temporary folder.' ),
[831] Fix | Delete
__( 'Failed to write file to disk.' ),
[832] Fix | Delete
__( 'File upload stopped by extension.' ),
[833] Fix | Delete
);
[834] Fix | Delete
}
[835] Fix | Delete
[836] Fix | Delete
// All tests are on by default. Most can be turned off by $overrides[{test_name}] = false;
[837] Fix | Delete
$test_form = isset( $overrides['test_form'] ) ? $overrides['test_form'] : true;
[838] Fix | Delete
$test_size = isset( $overrides['test_size'] ) ? $overrides['test_size'] : true;
[839] Fix | Delete
[840] Fix | Delete
// If you override this, you must provide $ext and $type!!
[841] Fix | Delete
$test_type = isset( $overrides['test_type'] ) ? $overrides['test_type'] : true;
[842] Fix | Delete
$mimes = isset( $overrides['mimes'] ) ? $overrides['mimes'] : false;
[843] Fix | Delete
[844] Fix | Delete
// A correct form post will pass this test.
[845] Fix | Delete
if ( $test_form && ( ! isset( $_POST['action'] ) || ( $_POST['action'] != $action ) ) ) {
[846] Fix | Delete
return call_user_func_array( $upload_error_handler, array( &$file, __( 'Invalid form submission.' ) ) );
[847] Fix | Delete
}
[848] Fix | Delete
// A successful upload will pass this test. It makes no sense to override this one.
[849] Fix | Delete
if ( isset( $file['error'] ) && $file['error'] > 0 ) {
[850] Fix | Delete
return call_user_func_array( $upload_error_handler, array( &$file, $upload_error_strings[ $file['error'] ] ) );
[851] Fix | Delete
}
[852] Fix | Delete
[853] Fix | Delete
// A properly uploaded file will pass this test. There should be no reason to override this one.
[854] Fix | Delete
$test_uploaded_file = 'wp_handle_upload' === $action ? is_uploaded_file( $file['tmp_name'] ) : @is_readable( $file['tmp_name'] );
[855] Fix | Delete
if ( ! $test_uploaded_file ) {
[856] Fix | Delete
return call_user_func_array( $upload_error_handler, array( &$file, __( 'Specified file failed upload test.' ) ) );
[857] Fix | Delete
}
[858] Fix | Delete
[859] Fix | Delete
$test_file_size = 'wp_handle_upload' === $action ? $file['size'] : filesize( $file['tmp_name'] );
[860] Fix | Delete
// A non-empty file will pass this test.
[861] Fix | Delete
if ( $test_size && ! ( $test_file_size > 0 ) ) {
[862] Fix | Delete
if ( is_multisite() ) {
[863] Fix | Delete
$error_msg = __( 'File is empty. Please upload something more substantial.' );
[864] Fix | Delete
} else {
[865] Fix | Delete
$error_msg = sprintf(
[866] Fix | Delete
/* translators: 1: php.ini, 2: post_max_size, 3: upload_max_filesize */
[867] Fix | Delete
__( 'File is empty. Please upload something more substantial. This error could also be caused by uploads being disabled in your %1$s file or by %2$s being defined as smaller than %3$s in %1$s.' ),
[868] Fix | Delete
'php.ini',
[869] Fix | Delete
'post_max_size',
[870] Fix | Delete
'upload_max_filesize'
[871] Fix | Delete
);
[872] Fix | Delete
}
[873] Fix | Delete
return call_user_func_array( $upload_error_handler, array( &$file, $error_msg ) );
[874] Fix | Delete
}
[875] Fix | Delete
[876] Fix | Delete
// A correct MIME type will pass this test. Override $mimes or use the upload_mimes filter.
[877] Fix | Delete
if ( $test_type ) {
[878] Fix | Delete
$wp_filetype = wp_check_filetype_and_ext( $file['tmp_name'], $file['name'], $mimes );
[879] Fix | Delete
$ext = empty( $wp_filetype['ext'] ) ? '' : $wp_filetype['ext'];
[880] Fix | Delete
$type = empty( $wp_filetype['type'] ) ? '' : $wp_filetype['type'];
[881] Fix | Delete
$proper_filename = empty( $wp_filetype['proper_filename'] ) ? '' : $wp_filetype['proper_filename'];
[882] Fix | Delete
[883] Fix | Delete
// Check to see if wp_check_filetype_and_ext() determined the filename was incorrect.
[884] Fix | Delete
if ( $proper_filename ) {
[885] Fix | Delete
$file['name'] = $proper_filename;
[886] Fix | Delete
}
[887] Fix | Delete
if ( ( ! $type || ! $ext ) && ! current_user_can( 'unfiltered_upload' ) ) {
[888] Fix | Delete
return call_user_func_array( $upload_error_handler, array( &$file, __( 'Sorry, this file type is not permitted for security reasons.' ) ) );
[889] Fix | Delete
}
[890] Fix | Delete
if ( ! $type ) {
[891] Fix | Delete
$type = $file['type'];
[892] Fix | Delete
}
[893] Fix | Delete
} else {
[894] Fix | Delete
$type = '';
[895] Fix | Delete
}
[896] Fix | Delete
[897] Fix | Delete
/*
[898] Fix | Delete
* A writable uploads dir will pass this test. Again, there's no point
[899] Fix | Delete
* overriding this one.
[900] Fix | Delete
*/
[901] Fix | Delete
$uploads = wp_upload_dir( $time );
[902] Fix | Delete
if ( ! ( $uploads && false === $uploads['error'] ) ) {
[903] Fix | Delete
return call_user_func_array( $upload_error_handler, array( &$file, $uploads['error'] ) );
[904] Fix | Delete
}
[905] Fix | Delete
[906] Fix | Delete
$filename = wp_unique_filename( $uploads['path'], $file['name'], $unique_filename_callback );
[907] Fix | Delete
[908] Fix | Delete
// Move the file to the uploads dir.
[909] Fix | Delete
$new_file = $uploads['path'] . "/$filename";
[910] Fix | Delete
[911] Fix | Delete
/**
[912] Fix | Delete
* Filters whether to short-circuit moving the uploaded file after passing all checks.
[913] Fix | Delete
*
[914] Fix | Delete
* If a non-null value is returned from the filter, moving the file and any related
[915] Fix | Delete
* error reporting will be completely skipped.
[916] Fix | Delete
*
[917] Fix | Delete
* @since 4.9.0
[918] Fix | Delete
*
[919] Fix | Delete
* @param mixed $move_new_file If null (default) move the file after the upload.
[920] Fix | Delete
* @param string[] $file An array of data for a single file.
[921] Fix | Delete
* @param string $new_file Filename of the newly-uploaded file.
[922] Fix | Delete
* @param string $type Mime type of the newly-uploaded file.
[923] Fix | Delete
*/
[924] Fix | Delete
$move_new_file = apply_filters( 'pre_move_uploaded_file', null, $file, $new_file, $type );
[925] Fix | Delete
[926] Fix | Delete
if ( null === $move_new_file ) {
[927] Fix | Delete
if ( 'wp_handle_upload' === $action ) {
[928] Fix | Delete
$move_new_file = @move_uploaded_file( $file['tmp_name'], $new_file );
[929] Fix | Delete
} else {
[930] Fix | Delete
// Use copy and unlink because rename breaks streams.
[931] Fix | Delete
// phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
[932] Fix | Delete
$move_new_file = @copy( $file['tmp_name'], $new_file );
[933] Fix | Delete
unlink( $file['tmp_name'] );
[934] Fix | Delete
}
[935] Fix | Delete
[936] Fix | Delete
if ( false === $move_new_file ) {
[937] Fix | Delete
if ( 0 === strpos( $uploads['basedir'], ABSPATH ) ) {
[938] Fix | Delete
$error_path = str_replace( ABSPATH, '', $uploads['basedir'] ) . $uploads['subdir'];
[939] Fix | Delete
} else {
[940] Fix | Delete
$error_path = basename( $uploads['basedir'] ) . $uploads['subdir'];
[941] Fix | Delete
}
[942] Fix | Delete
return $upload_error_handler(
[943] Fix | Delete
$file,
[944] Fix | Delete
sprintf(
[945] Fix | Delete
/* translators: %s: Destination file path. */
[946] Fix | Delete
__( 'The uploaded file could not be moved to %s.' ),
[947] Fix | Delete
$error_path
[948] Fix | Delete
)
[949] Fix | Delete
);
[950] Fix | Delete
}
[951] Fix | Delete
}
[952] Fix | Delete
[953] Fix | Delete
// Set correct file permissions.
[954] Fix | Delete
$stat = stat( dirname( $new_file ) );
[955] Fix | Delete
$perms = $stat['mode'] & 0000666;
[956] Fix | Delete
chmod( $new_file, $perms );
[957] Fix | Delete
[958] Fix | Delete
// Compute the URL.
[959] Fix | Delete
$url = $uploads['url'] . "/$filename";
[960] Fix | Delete
[961] Fix | Delete
if ( is_multisite() ) {
[962] Fix | Delete
clean_dirsize_cache( $new_file );
[963] Fix | Delete
}
[964] Fix | Delete
[965] Fix | Delete
/**
[966] Fix | Delete
* Filters the data array for the uploaded file.
[967] Fix | Delete
*
[968] Fix | Delete
* @since 2.1.0
[969] Fix | Delete
*
[970] Fix | Delete
* @param array $upload {
[971] Fix | Delete
* Array of upload data.
[972] Fix | Delete
*
[973] Fix | Delete
* @type string $file Filename of the newly-uploaded file.
[974] Fix | Delete
* @type string $url URL of the newly-uploaded file.
[975] Fix | Delete
* @type string $type Mime type of the newly-uploaded file.
[976] Fix | Delete
* }
[977] Fix | Delete
* @param string $context The type of upload action. Values include 'upload' or 'sideload'.
[978] Fix | Delete
*/
[979] Fix | Delete
return apply_filters(
[980] Fix | Delete
'wp_handle_upload',
[981] Fix | Delete
array(
[982] Fix | Delete
'file' => $new_file,
[983] Fix | Delete
'url' => $url,
[984] Fix | Delete
'type' => $type,
[985] Fix | Delete
),
[986] Fix | Delete
'wp_handle_sideload' === $action ? 'sideload' : 'upload'
[987] Fix | Delete
);
[988] Fix | Delete
}
[989] Fix | Delete
[990] Fix | Delete
/**
[991] Fix | Delete
* Wrapper for _wp_handle_upload().
[992] Fix | Delete
*
[993] Fix | Delete
* Passes the {@see 'wp_handle_upload'} action.
[994] Fix | Delete
*
[995] Fix | Delete
* @since 2.0.0
[996] Fix | Delete
*
[997] Fix | Delete
* @see _wp_handle_upload()
[998] Fix | Delete
*
[999] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function