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
/home/sportsfe.../httpdocs/wp-conte.../plugins/wp-smush.../core
File: class-upload-dir.php
<?php
[0] Fix | Delete
[1] Fix | Delete
namespace Smush\Core;
[2] Fix | Delete
[3] Fix | Delete
class Upload_Dir {
[4] Fix | Delete
private $wp_upload_dir;
[5] Fix | Delete
[6] Fix | Delete
private $root_path;
[7] Fix | Delete
[8] Fix | Delete
private $upload_path;
[9] Fix | Delete
[10] Fix | Delete
private $upload_rel_path;
[11] Fix | Delete
[12] Fix | Delete
private $upload_url;
[13] Fix | Delete
[14] Fix | Delete
/**
[15] Fix | Delete
* @return array
[16] Fix | Delete
*/
[17] Fix | Delete
private function get_wp_upload_dir() {
[18] Fix | Delete
if ( is_null( $this->wp_upload_dir ) ) {
[19] Fix | Delete
$this->wp_upload_dir = $this->prepare_wp_upload_dir();
[20] Fix | Delete
}
[21] Fix | Delete
[22] Fix | Delete
return $this->wp_upload_dir;
[23] Fix | Delete
}
[24] Fix | Delete
[25] Fix | Delete
/**
[26] Fix | Delete
* @return mixed
[27] Fix | Delete
*/
[28] Fix | Delete
private function get_root_path() {
[29] Fix | Delete
if ( is_null( $this->root_path ) ) {
[30] Fix | Delete
$this->root_path = $this->prepare_root_path();
[31] Fix | Delete
}
[32] Fix | Delete
[33] Fix | Delete
return $this->root_path;
[34] Fix | Delete
}
[35] Fix | Delete
[36] Fix | Delete
/**
[37] Fix | Delete
* @return mixed
[38] Fix | Delete
*/
[39] Fix | Delete
public function get_upload_path() {
[40] Fix | Delete
if ( is_null( $this->upload_path ) ) {
[41] Fix | Delete
$this->upload_path = $this->prepare_upload_path();
[42] Fix | Delete
}
[43] Fix | Delete
[44] Fix | Delete
return $this->upload_path;
[45] Fix | Delete
}
[46] Fix | Delete
[47] Fix | Delete
/**
[48] Fix | Delete
* @return string
[49] Fix | Delete
*/
[50] Fix | Delete
public function get_upload_rel_path() {
[51] Fix | Delete
if ( is_null( $this->upload_rel_path ) ) {
[52] Fix | Delete
$this->upload_rel_path = $this->prepare_upload_rel_path();
[53] Fix | Delete
}
[54] Fix | Delete
[55] Fix | Delete
return $this->upload_rel_path;
[56] Fix | Delete
}
[57] Fix | Delete
[58] Fix | Delete
/**
[59] Fix | Delete
* @return string
[60] Fix | Delete
*/
[61] Fix | Delete
public function get_upload_url() {
[62] Fix | Delete
if ( is_null( $this->upload_url ) ) {
[63] Fix | Delete
$this->upload_url = $this->prepare_upload_url();
[64] Fix | Delete
}
[65] Fix | Delete
[66] Fix | Delete
return $this->upload_url;
[67] Fix | Delete
}
[68] Fix | Delete
[69] Fix | Delete
private function prepare_upload_path() {
[70] Fix | Delete
$upload = $this->get_wp_upload_dir();
[71] Fix | Delete
[72] Fix | Delete
return untrailingslashit( $upload['basedir'] );
[73] Fix | Delete
}
[74] Fix | Delete
[75] Fix | Delete
private function prepare_upload_rel_path() {
[76] Fix | Delete
$root_path = $this->get_root_path();
[77] Fix | Delete
[78] Fix | Delete
return str_replace( $root_path, '', $this->get_upload_path() );
[79] Fix | Delete
}
[80] Fix | Delete
[81] Fix | Delete
private function prepare_upload_url() {
[82] Fix | Delete
$upload = $this->get_wp_upload_dir();
[83] Fix | Delete
[84] Fix | Delete
return untrailingslashit( $upload['baseurl'] );
[85] Fix | Delete
}
[86] Fix | Delete
[87] Fix | Delete
private function prepare_wp_upload_dir() {
[88] Fix | Delete
if ( ! is_multisite() || is_main_site() ) {
[89] Fix | Delete
$upload = wp_upload_dir();
[90] Fix | Delete
} else {
[91] Fix | Delete
// Use the main site's upload directory for all subsite's webp converted images.
[92] Fix | Delete
// This makes it easier to have a single rule on the server configs for serving webp in mu.
[93] Fix | Delete
$blog_id = get_main_site_id();
[94] Fix | Delete
switch_to_blog( $blog_id );
[95] Fix | Delete
$upload = wp_upload_dir();
[96] Fix | Delete
restore_current_blog();
[97] Fix | Delete
}
[98] Fix | Delete
[99] Fix | Delete
return $upload;
[100] Fix | Delete
}
[101] Fix | Delete
[102] Fix | Delete
protected function prepare_root_path() {
[103] Fix | Delete
// Is it possible that none of the following conditions are met?
[104] Fix | Delete
$root_path = '';
[105] Fix | Delete
[106] Fix | Delete
// Get the Document root path. There must be a better way to do this.
[107] Fix | Delete
// For example, /srv/www/site/public_html for /srv/www/site/public_html/wp-content/uploads.
[108] Fix | Delete
if ( 0 === strpos( $this->get_upload_path(), ABSPATH ) ) {
[109] Fix | Delete
// Environments like Flywheel have an ABSPATH that's not used in the paths.
[110] Fix | Delete
$root_path = ABSPATH;
[111] Fix | Delete
} elseif ( ! empty( $_SERVER['DOCUMENT_ROOT'] ) && 0 === strpos( $this->get_upload_path(), wp_unslash( $_SERVER['DOCUMENT_ROOT'] ) ) ) {
[112] Fix | Delete
/**
[113] Fix | Delete
* This gets called when scanning for uncompressed images.
[114] Fix | Delete
* When ran from certain contexts, $_SERVER['DOCUMENT_ROOT'] might not be set.
[115] Fix | Delete
*
[116] Fix | Delete
* We are removing this part from the path later on.
[117] Fix | Delete
*/
[118] Fix | Delete
$root_path = realpath( wp_unslash( $_SERVER['DOCUMENT_ROOT'] ) ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
[119] Fix | Delete
} elseif ( 0 === strpos( $this->get_upload_path(), dirname( WP_CONTENT_DIR ) ) ) {
[120] Fix | Delete
// We're assuming WP_CONTENT_DIR is only one level deep into the document root.
[121] Fix | Delete
// This might not be true in customized sites. A bit edgy.
[122] Fix | Delete
$root_path = dirname( WP_CONTENT_DIR );
[123] Fix | Delete
}
[124] Fix | Delete
[125] Fix | Delete
$root_path = untrailingslashit( $root_path );
[126] Fix | Delete
[127] Fix | Delete
/**
[128] Fix | Delete
* Filters the Document root path used to get relative paths for webp rules.
[129] Fix | Delete
* Hopefully of help for debugging and SLS.
[130] Fix | Delete
*
[131] Fix | Delete
* @since 3.9.0
[132] Fix | Delete
*/
[133] Fix | Delete
return apply_filters( 'smush_webp_rules_root_path_base', $root_path );
[134] Fix | Delete
}
[135] Fix | Delete
[136] Fix | Delete
public function get_human_readable_path( $full_path ) {
[137] Fix | Delete
return str_replace( WP_CONTENT_DIR, '', $full_path );
[138] Fix | Delete
}
[139] Fix | Delete
}
[140] Fix | Delete
[141] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function