Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93

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