Edit File by line
/home/barbar84/www/wp-admin/includes
File: file.php
* Filters the filesystem method to use.
[2000] Fix | Delete
*
[2001] Fix | Delete
* @since 2.6.0
[2002] Fix | Delete
*
[2003] Fix | Delete
* @param string $method Filesystem method to return.
[2004] Fix | Delete
* @param array $args An array of connection details for the method.
[2005] Fix | Delete
* @param string $context Full path to the directory that is tested for being writable.
[2006] Fix | Delete
* @param bool $allow_relaxed_file_ownership Whether to allow Group/World writable.
[2007] Fix | Delete
*/
[2008] Fix | Delete
return apply_filters( 'filesystem_method', $method, $args, $context, $allow_relaxed_file_ownership );
[2009] Fix | Delete
}
[2010] Fix | Delete
[2011] Fix | Delete
/**
[2012] Fix | Delete
* Displays a form to the user to request for their FTP/SSH details in order
[2013] Fix | Delete
* to connect to the filesystem.
[2014] Fix | Delete
*
[2015] Fix | Delete
* All chosen/entered details are saved, excluding the password.
[2016] Fix | Delete
*
[2017] Fix | Delete
* Hostnames may be in the form of hostname:portnumber (eg: wordpress.org:2467)
[2018] Fix | Delete
* to specify an alternate FTP/SSH port.
[2019] Fix | Delete
*
[2020] Fix | Delete
* Plugins may override this form by returning true|false via the {@see 'request_filesystem_credentials'} filter.
[2021] Fix | Delete
*
[2022] Fix | Delete
* @since 2.5.0
[2023] Fix | Delete
* @since 4.6.0 The `$context` parameter default changed from `false` to an empty string.
[2024] Fix | Delete
*
[2025] Fix | Delete
* @global string $pagenow
[2026] Fix | Delete
*
[2027] Fix | Delete
* @param string $form_post The URL to post the form to.
[2028] Fix | Delete
* @param string $type Optional. Chosen type of filesystem. Default empty.
[2029] Fix | Delete
* @param bool|WP_Error $error Optional. Whether the current request has failed
[2030] Fix | Delete
* to connect, or an error object. Default false.
[2031] Fix | Delete
* @param string $context Optional. Full path to the directory that is tested
[2032] Fix | Delete
* for being writable. Default empty.
[2033] Fix | Delete
* @param array $extra_fields Optional. Extra `POST` fields to be checked
[2034] Fix | Delete
* for inclusion in the post. Default null.
[2035] Fix | Delete
* @param bool $allow_relaxed_file_ownership Optional. Whether to allow Group/World writable.
[2036] Fix | Delete
* Default false.
[2037] Fix | Delete
* @return bool|array True if no filesystem credentials are required,
[2038] Fix | Delete
* false if they are required but have not been provided,
[2039] Fix | Delete
* array of credentials if they are required and have been provided.
[2040] Fix | Delete
*/
[2041] Fix | Delete
function request_filesystem_credentials( $form_post, $type = '', $error = false, $context = '', $extra_fields = null, $allow_relaxed_file_ownership = false ) {
[2042] Fix | Delete
global $pagenow;
[2043] Fix | Delete
[2044] Fix | Delete
/**
[2045] Fix | Delete
* Filters the filesystem credentials.
[2046] Fix | Delete
*
[2047] Fix | Delete
* Returning anything other than an empty string will effectively short-circuit
[2048] Fix | Delete
* output of the filesystem credentials form, returning that value instead.
[2049] Fix | Delete
*
[2050] Fix | Delete
* A filter should return true if no filesystem credentials are required, false if they are required but have not been
[2051] Fix | Delete
* provided, or an array of credentials if they are required and have been provided.
[2052] Fix | Delete
*
[2053] Fix | Delete
* @since 2.5.0
[2054] Fix | Delete
* @since 4.6.0 The `$context` parameter default changed from `false` to an empty string.
[2055] Fix | Delete
*
[2056] Fix | Delete
* @param mixed $credentials Credentials to return instead. Default empty string.
[2057] Fix | Delete
* @param string $form_post The URL to post the form to.
[2058] Fix | Delete
* @param string $type Chosen type of filesystem.
[2059] Fix | Delete
* @param bool|WP_Error $error Whether the current request has failed to connect,
[2060] Fix | Delete
* or an error object.
[2061] Fix | Delete
* @param string $context Full path to the directory that is tested for
[2062] Fix | Delete
* being writable.
[2063] Fix | Delete
* @param array $extra_fields Extra POST fields.
[2064] Fix | Delete
* @param bool $allow_relaxed_file_ownership Whether to allow Group/World writable.
[2065] Fix | Delete
*/
[2066] Fix | Delete
$req_cred = apply_filters( 'request_filesystem_credentials', '', $form_post, $type, $error, $context, $extra_fields, $allow_relaxed_file_ownership );
[2067] Fix | Delete
if ( '' !== $req_cred ) {
[2068] Fix | Delete
return $req_cred;
[2069] Fix | Delete
}
[2070] Fix | Delete
[2071] Fix | Delete
if ( empty( $type ) ) {
[2072] Fix | Delete
$type = get_filesystem_method( array(), $context, $allow_relaxed_file_ownership );
[2073] Fix | Delete
}
[2074] Fix | Delete
[2075] Fix | Delete
if ( 'direct' === $type ) {
[2076] Fix | Delete
return true;
[2077] Fix | Delete
}
[2078] Fix | Delete
[2079] Fix | Delete
if ( is_null( $extra_fields ) ) {
[2080] Fix | Delete
$extra_fields = array( 'version', 'locale' );
[2081] Fix | Delete
}
[2082] Fix | Delete
[2083] Fix | Delete
$credentials = get_option(
[2084] Fix | Delete
'ftp_credentials',
[2085] Fix | Delete
array(
[2086] Fix | Delete
'hostname' => '',
[2087] Fix | Delete
'username' => '',
[2088] Fix | Delete
)
[2089] Fix | Delete
);
[2090] Fix | Delete
[2091] Fix | Delete
$submitted_form = wp_unslash( $_POST );
[2092] Fix | Delete
[2093] Fix | Delete
// Verify nonce, or unset submitted form field values on failure.
[2094] Fix | Delete
if ( ! isset( $_POST['_fs_nonce'] ) || ! wp_verify_nonce( $_POST['_fs_nonce'], 'filesystem-credentials' ) ) {
[2095] Fix | Delete
unset(
[2096] Fix | Delete
$submitted_form['hostname'],
[2097] Fix | Delete
$submitted_form['username'],
[2098] Fix | Delete
$submitted_form['password'],
[2099] Fix | Delete
$submitted_form['public_key'],
[2100] Fix | Delete
$submitted_form['private_key'],
[2101] Fix | Delete
$submitted_form['connection_type']
[2102] Fix | Delete
);
[2103] Fix | Delete
}
[2104] Fix | Delete
[2105] Fix | Delete
// If defined, set it to that. Else, if POST'd, set it to that. If not, set it to whatever it previously was (saved details in option).
[2106] Fix | Delete
$credentials['hostname'] = defined( 'FTP_HOST' ) ? FTP_HOST : ( ! empty( $submitted_form['hostname'] ) ? $submitted_form['hostname'] : $credentials['hostname'] );
[2107] Fix | Delete
$credentials['username'] = defined( 'FTP_USER' ) ? FTP_USER : ( ! empty( $submitted_form['username'] ) ? $submitted_form['username'] : $credentials['username'] );
[2108] Fix | Delete
$credentials['password'] = defined( 'FTP_PASS' ) ? FTP_PASS : ( ! empty( $submitted_form['password'] ) ? $submitted_form['password'] : '' );
[2109] Fix | Delete
[2110] Fix | Delete
// Check to see if we are setting the public/private keys for ssh.
[2111] Fix | Delete
$credentials['public_key'] = defined( 'FTP_PUBKEY' ) ? FTP_PUBKEY : ( ! empty( $submitted_form['public_key'] ) ? $submitted_form['public_key'] : '' );
[2112] Fix | Delete
$credentials['private_key'] = defined( 'FTP_PRIKEY' ) ? FTP_PRIKEY : ( ! empty( $submitted_form['private_key'] ) ? $submitted_form['private_key'] : '' );
[2113] Fix | Delete
[2114] Fix | Delete
// Sanitize the hostname, some people might pass in odd data.
[2115] Fix | Delete
$credentials['hostname'] = preg_replace( '|\w+://|', '', $credentials['hostname'] ); // Strip any schemes off.
[2116] Fix | Delete
[2117] Fix | Delete
if ( strpos( $credentials['hostname'], ':' ) ) {
[2118] Fix | Delete
list( $credentials['hostname'], $credentials['port'] ) = explode( ':', $credentials['hostname'], 2 );
[2119] Fix | Delete
if ( ! is_numeric( $credentials['port'] ) ) {
[2120] Fix | Delete
unset( $credentials['port'] );
[2121] Fix | Delete
}
[2122] Fix | Delete
} else {
[2123] Fix | Delete
unset( $credentials['port'] );
[2124] Fix | Delete
}
[2125] Fix | Delete
[2126] Fix | Delete
if ( ( defined( 'FTP_SSH' ) && FTP_SSH ) || ( defined( 'FS_METHOD' ) && 'ssh2' === FS_METHOD ) ) {
[2127] Fix | Delete
$credentials['connection_type'] = 'ssh';
[2128] Fix | Delete
} elseif ( ( defined( 'FTP_SSL' ) && FTP_SSL ) && 'ftpext' === $type ) { // Only the FTP Extension understands SSL.
[2129] Fix | Delete
$credentials['connection_type'] = 'ftps';
[2130] Fix | Delete
} elseif ( ! empty( $submitted_form['connection_type'] ) ) {
[2131] Fix | Delete
$credentials['connection_type'] = $submitted_form['connection_type'];
[2132] Fix | Delete
} elseif ( ! isset( $credentials['connection_type'] ) ) { // All else fails (and it's not defaulted to something else saved), default to FTP.
[2133] Fix | Delete
$credentials['connection_type'] = 'ftp';
[2134] Fix | Delete
}
[2135] Fix | Delete
if ( ! $error
[2136] Fix | Delete
&& ( ( ! empty( $credentials['password'] ) && ! empty( $credentials['username'] ) && ! empty( $credentials['hostname'] ) )
[2137] Fix | Delete
|| ( 'ssh' === $credentials['connection_type'] && ! empty( $credentials['public_key'] ) && ! empty( $credentials['private_key'] ) )
[2138] Fix | Delete
)
[2139] Fix | Delete
) {
[2140] Fix | Delete
$stored_credentials = $credentials;
[2141] Fix | Delete
[2142] Fix | Delete
if ( ! empty( $stored_credentials['port'] ) ) { // Save port as part of hostname to simplify above code.
[2143] Fix | Delete
$stored_credentials['hostname'] .= ':' . $stored_credentials['port'];
[2144] Fix | Delete
}
[2145] Fix | Delete
[2146] Fix | Delete
unset( $stored_credentials['password'], $stored_credentials['port'], $stored_credentials['private_key'], $stored_credentials['public_key'] );
[2147] Fix | Delete
[2148] Fix | Delete
if ( ! wp_installing() ) {
[2149] Fix | Delete
update_option( 'ftp_credentials', $stored_credentials );
[2150] Fix | Delete
}
[2151] Fix | Delete
[2152] Fix | Delete
return $credentials;
[2153] Fix | Delete
}
[2154] Fix | Delete
$hostname = isset( $credentials['hostname'] ) ? $credentials['hostname'] : '';
[2155] Fix | Delete
$username = isset( $credentials['username'] ) ? $credentials['username'] : '';
[2156] Fix | Delete
$public_key = isset( $credentials['public_key'] ) ? $credentials['public_key'] : '';
[2157] Fix | Delete
$private_key = isset( $credentials['private_key'] ) ? $credentials['private_key'] : '';
[2158] Fix | Delete
$port = isset( $credentials['port'] ) ? $credentials['port'] : '';
[2159] Fix | Delete
$connection_type = isset( $credentials['connection_type'] ) ? $credentials['connection_type'] : '';
[2160] Fix | Delete
[2161] Fix | Delete
if ( $error ) {
[2162] Fix | Delete
$error_string = __( '<strong>Error</strong>: Could not connect to the server. Please verify the settings are correct.' );
[2163] Fix | Delete
if ( is_wp_error( $error ) ) {
[2164] Fix | Delete
$error_string = esc_html( $error->get_error_message() );
[2165] Fix | Delete
}
[2166] Fix | Delete
echo '<div id="message" class="error"><p>' . $error_string . '</p></div>';
[2167] Fix | Delete
}
[2168] Fix | Delete
[2169] Fix | Delete
$types = array();
[2170] Fix | Delete
if ( extension_loaded( 'ftp' ) || extension_loaded( 'sockets' ) || function_exists( 'fsockopen' ) ) {
[2171] Fix | Delete
$types['ftp'] = __( 'FTP' );
[2172] Fix | Delete
}
[2173] Fix | Delete
if ( extension_loaded( 'ftp' ) ) { // Only this supports FTPS.
[2174] Fix | Delete
$types['ftps'] = __( 'FTPS (SSL)' );
[2175] Fix | Delete
}
[2176] Fix | Delete
if ( extension_loaded( 'ssh2' ) ) {
[2177] Fix | Delete
$types['ssh'] = __( 'SSH2' );
[2178] Fix | Delete
}
[2179] Fix | Delete
[2180] Fix | Delete
/**
[2181] Fix | Delete
* Filters the connection types to output to the filesystem credentials form.
[2182] Fix | Delete
*
[2183] Fix | Delete
* @since 2.9.0
[2184] Fix | Delete
* @since 4.6.0 The `$context` parameter default changed from `false` to an empty string.
[2185] Fix | Delete
*
[2186] Fix | Delete
* @param string[] $types Types of connections.
[2187] Fix | Delete
* @param array $credentials Credentials to connect with.
[2188] Fix | Delete
* @param string $type Chosen filesystem method.
[2189] Fix | Delete
* @param bool|WP_Error $error Whether the current request has failed to connect,
[2190] Fix | Delete
* or an error object.
[2191] Fix | Delete
* @param string $context Full path to the directory that is tested for being writable.
[2192] Fix | Delete
*/
[2193] Fix | Delete
$types = apply_filters( 'fs_ftp_connection_types', $types, $credentials, $type, $error, $context );
[2194] Fix | Delete
[2195] Fix | Delete
?>
[2196] Fix | Delete
<form action="<?php echo esc_url( $form_post ); ?>" method="post">
[2197] Fix | Delete
<div id="request-filesystem-credentials-form" class="request-filesystem-credentials-form">
[2198] Fix | Delete
<?php
[2199] Fix | Delete
// Print a H1 heading in the FTP credentials modal dialog, default is a H2.
[2200] Fix | Delete
$heading_tag = 'h2';
[2201] Fix | Delete
if ( 'plugins.php' === $pagenow || 'plugin-install.php' === $pagenow ) {
[2202] Fix | Delete
$heading_tag = 'h1';
[2203] Fix | Delete
}
[2204] Fix | Delete
echo "<$heading_tag id='request-filesystem-credentials-title'>" . __( 'Connection Information' ) . "</$heading_tag>";
[2205] Fix | Delete
?>
[2206] Fix | Delete
<p id="request-filesystem-credentials-desc">
[2207] Fix | Delete
<?php
[2208] Fix | Delete
$label_user = __( 'Username' );
[2209] Fix | Delete
$label_pass = __( 'Password' );
[2210] Fix | Delete
_e( 'To perform the requested action, WordPress needs to access your web server.' );
[2211] Fix | Delete
echo ' ';
[2212] Fix | Delete
if ( ( isset( $types['ftp'] ) || isset( $types['ftps'] ) ) ) {
[2213] Fix | Delete
if ( isset( $types['ssh'] ) ) {
[2214] Fix | Delete
_e( 'Please enter your FTP or SSH credentials to proceed.' );
[2215] Fix | Delete
$label_user = __( 'FTP/SSH Username' );
[2216] Fix | Delete
$label_pass = __( 'FTP/SSH Password' );
[2217] Fix | Delete
} else {
[2218] Fix | Delete
_e( 'Please enter your FTP credentials to proceed.' );
[2219] Fix | Delete
$label_user = __( 'FTP Username' );
[2220] Fix | Delete
$label_pass = __( 'FTP Password' );
[2221] Fix | Delete
}
[2222] Fix | Delete
echo ' ';
[2223] Fix | Delete
}
[2224] Fix | Delete
_e( 'If you do not remember your credentials, you should contact your web host.' );
[2225] Fix | Delete
[2226] Fix | Delete
$hostname_value = esc_attr( $hostname );
[2227] Fix | Delete
if ( ! empty( $port ) ) {
[2228] Fix | Delete
$hostname_value .= ":$port";
[2229] Fix | Delete
}
[2230] Fix | Delete
[2231] Fix | Delete
$password_value = '';
[2232] Fix | Delete
if ( defined( 'FTP_PASS' ) ) {
[2233] Fix | Delete
$password_value = '*****';
[2234] Fix | Delete
}
[2235] Fix | Delete
?>
[2236] Fix | Delete
</p>
[2237] Fix | Delete
<label for="hostname">
[2238] Fix | Delete
<span class="field-title"><?php _e( 'Hostname' ); ?></span>
[2239] Fix | Delete
<input name="hostname" type="text" id="hostname" aria-describedby="request-filesystem-credentials-desc" class="code" placeholder="<?php esc_attr_e( 'example: www.wordpress.org' ); ?>" value="<?php echo $hostname_value; ?>"<?php disabled( defined( 'FTP_HOST' ) ); ?> />
[2240] Fix | Delete
</label>
[2241] Fix | Delete
<div class="ftp-username">
[2242] Fix | Delete
<label for="username">
[2243] Fix | Delete
<span class="field-title"><?php echo $label_user; ?></span>
[2244] Fix | Delete
<input name="username" type="text" id="username" value="<?php echo esc_attr( $username ); ?>"<?php disabled( defined( 'FTP_USER' ) ); ?> />
[2245] Fix | Delete
</label>
[2246] Fix | Delete
</div>
[2247] Fix | Delete
<div class="ftp-password">
[2248] Fix | Delete
<label for="password">
[2249] Fix | Delete
<span class="field-title"><?php echo $label_pass; ?></span>
[2250] Fix | Delete
<input name="password" type="password" id="password" value="<?php echo $password_value; ?>"<?php disabled( defined( 'FTP_PASS' ) ); ?> />
[2251] Fix | Delete
<?php
[2252] Fix | Delete
if ( ! defined( 'FTP_PASS' ) ) {
[2253] Fix | Delete
_e( 'This password will not be stored on the server.' );}
[2254] Fix | Delete
?>
[2255] Fix | Delete
</label>
[2256] Fix | Delete
</div>
[2257] Fix | Delete
<fieldset>
[2258] Fix | Delete
<legend><?php _e( 'Connection Type' ); ?></legend>
[2259] Fix | Delete
<?php
[2260] Fix | Delete
$disabled = disabled( ( defined( 'FTP_SSL' ) && FTP_SSL ) || ( defined( 'FTP_SSH' ) && FTP_SSH ), true, false );
[2261] Fix | Delete
foreach ( $types as $name => $text ) :
[2262] Fix | Delete
?>
[2263] Fix | Delete
<label for="<?php echo esc_attr( $name ); ?>">
[2264] Fix | Delete
<input type="radio" name="connection_type" id="<?php echo esc_attr( $name ); ?>" value="<?php echo esc_attr( $name ); ?>" <?php checked( $name, $connection_type ); ?> <?php echo $disabled; ?> />
[2265] Fix | Delete
<?php echo $text; ?>
[2266] Fix | Delete
</label>
[2267] Fix | Delete
<?php
[2268] Fix | Delete
endforeach;
[2269] Fix | Delete
?>
[2270] Fix | Delete
</fieldset>
[2271] Fix | Delete
<?php
[2272] Fix | Delete
if ( isset( $types['ssh'] ) ) {
[2273] Fix | Delete
$hidden_class = '';
[2274] Fix | Delete
if ( 'ssh' !== $connection_type || empty( $connection_type ) ) {
[2275] Fix | Delete
$hidden_class = ' class="hidden"';
[2276] Fix | Delete
}
[2277] Fix | Delete
?>
[2278] Fix | Delete
<fieldset id="ssh-keys"<?php echo $hidden_class; ?>>
[2279] Fix | Delete
<legend><?php _e( 'Authentication Keys' ); ?></legend>
[2280] Fix | Delete
<label for="public_key">
[2281] Fix | Delete
<span class="field-title"><?php _e( 'Public Key:' ); ?></span>
[2282] Fix | Delete
<input name="public_key" type="text" id="public_key" aria-describedby="auth-keys-desc" value="<?php echo esc_attr( $public_key ); ?>"<?php disabled( defined( 'FTP_PUBKEY' ) ); ?> />
[2283] Fix | Delete
</label>
[2284] Fix | Delete
<label for="private_key">
[2285] Fix | Delete
<span class="field-title"><?php _e( 'Private Key:' ); ?></span>
[2286] Fix | Delete
<input name="private_key" type="text" id="private_key" value="<?php echo esc_attr( $private_key ); ?>"<?php disabled( defined( 'FTP_PRIKEY' ) ); ?> />
[2287] Fix | Delete
</label>
[2288] Fix | Delete
<p id="auth-keys-desc"><?php _e( 'Enter the location on the server where the public and private keys are located. If a passphrase is needed, enter that in the password field above.' ); ?></p>
[2289] Fix | Delete
</fieldset>
[2290] Fix | Delete
<?php
[2291] Fix | Delete
}
[2292] Fix | Delete
[2293] Fix | Delete
foreach ( (array) $extra_fields as $field ) {
[2294] Fix | Delete
if ( isset( $submitted_form[ $field ] ) ) {
[2295] Fix | Delete
echo '<input type="hidden" name="' . esc_attr( $field ) . '" value="' . esc_attr( $submitted_form[ $field ] ) . '" />';
[2296] Fix | Delete
}
[2297] Fix | Delete
}
[2298] Fix | Delete
?>
[2299] Fix | Delete
<p class="request-filesystem-credentials-action-buttons">
[2300] Fix | Delete
<?php wp_nonce_field( 'filesystem-credentials', '_fs_nonce', false, true ); ?>
[2301] Fix | Delete
<button class="button cancel-button" data-js-action="close" type="button"><?php _e( 'Cancel' ); ?></button>
[2302] Fix | Delete
<?php submit_button( __( 'Proceed' ), '', 'upgrade', false ); ?>
[2303] Fix | Delete
</p>
[2304] Fix | Delete
</div>
[2305] Fix | Delete
</form>
[2306] Fix | Delete
<?php
[2307] Fix | Delete
return false;
[2308] Fix | Delete
}
[2309] Fix | Delete
[2310] Fix | Delete
/**
[2311] Fix | Delete
* Prints the filesystem credentials modal when needed.
[2312] Fix | Delete
*
[2313] Fix | Delete
* @since 4.2.0
[2314] Fix | Delete
*/
[2315] Fix | Delete
function wp_print_request_filesystem_credentials_modal() {
[2316] Fix | Delete
$filesystem_method = get_filesystem_method();
[2317] Fix | Delete
[2318] Fix | Delete
ob_start();
[2319] Fix | Delete
$filesystem_credentials_are_stored = request_filesystem_credentials( self_admin_url() );
[2320] Fix | Delete
ob_end_clean();
[2321] Fix | Delete
[2322] Fix | Delete
$request_filesystem_credentials = ( 'direct' !== $filesystem_method && ! $filesystem_credentials_are_stored );
[2323] Fix | Delete
if ( ! $request_filesystem_credentials ) {
[2324] Fix | Delete
return;
[2325] Fix | Delete
}
[2326] Fix | Delete
?>
[2327] Fix | Delete
<div id="request-filesystem-credentials-dialog" class="notification-dialog-wrap request-filesystem-credentials-dialog">
[2328] Fix | Delete
<div class="notification-dialog-background"></div>
[2329] Fix | Delete
<div class="notification-dialog" role="dialog" aria-labelledby="request-filesystem-credentials-title" tabindex="0">
[2330] Fix | Delete
<div class="request-filesystem-credentials-dialog-content">
[2331] Fix | Delete
<?php request_filesystem_credentials( site_url() ); ?>
[2332] Fix | Delete
</div>
[2333] Fix | Delete
</div>
[2334] Fix | Delete
</div>
[2335] Fix | Delete
<?php
[2336] Fix | Delete
}
[2337] Fix | Delete
[2338] Fix | Delete
/**
[2339] Fix | Delete
* Attempts to clear the opcode cache for an individual PHP file.
[2340] Fix | Delete
*
[2341] Fix | Delete
* This function can be called safely without having to check the file extension
[2342] Fix | Delete
* or availability of the OPcache extension.
[2343] Fix | Delete
*
[2344] Fix | Delete
* Whether or not invalidation is possible is cached to improve performance.
[2345] Fix | Delete
*
[2346] Fix | Delete
* @since 5.5.0
[2347] Fix | Delete
*
[2348] Fix | Delete
* @link https://www.php.net/manual/en/function.opcache-invalidate.php
[2349] Fix | Delete
*
[2350] Fix | Delete
* @param string $filepath Path to the file, including extension, for which the opcode cache is to be cleared.
[2351] Fix | Delete
* @param bool $force Invalidate even if the modification time is not newer than the file in cache.
[2352] Fix | Delete
* Default false.
[2353] Fix | Delete
* @return bool True if opcache was invalidated for `$filepath`, or there was nothing to invalidate.
[2354] Fix | Delete
* False if opcache invalidation is not available, or is disabled via filter.
[2355] Fix | Delete
*/
[2356] Fix | Delete
function wp_opcache_invalidate( $filepath, $force = false ) {
[2357] Fix | Delete
static $can_invalidate = null;
[2358] Fix | Delete
[2359] Fix | Delete
/*
[2360] Fix | Delete
* Check to see if WordPress is able to run `opcache_invalidate()` or not, and cache the value.
[2361] Fix | Delete
*
[2362] Fix | Delete
* First, check to see if the function is available to call, then if the host has restricted
[2363] Fix | Delete
* the ability to run the function to avoid a PHP warning.
[2364] Fix | Delete
*
[2365] Fix | Delete
* `opcache.restrict_api` can specify the path for files allowed to call `opcache_invalidate()`.
[2366] Fix | Delete
*
[2367] Fix | Delete
* If the host has this set, check whether the path in `opcache.restrict_api` matches
[2368] Fix | Delete
* the beginning of the path of the origin file.
[2369] Fix | Delete
*
[2370] Fix | Delete
* `$_SERVER['SCRIPT_FILENAME']` approximates the origin file's path, but `realpath()`
[2371] Fix | Delete
* is necessary because `SCRIPT_FILENAME` can be a relative path when run from CLI.
[2372] Fix | Delete
*
[2373] Fix | Delete
* For more details, see:
[2374] Fix | Delete
* - https://www.php.net/manual/en/opcache.configuration.php
[2375] Fix | Delete
* - https://www.php.net/manual/en/reserved.variables.server.php
[2376] Fix | Delete
* - https://core.trac.wordpress.org/ticket/36455
[2377] Fix | Delete
*/
[2378] Fix | Delete
if ( null === $can_invalidate
[2379] Fix | Delete
&& function_exists( 'opcache_invalidate' )
[2380] Fix | Delete
&& ( ! ini_get( 'opcache.restrict_api' )
[2381] Fix | Delete
|| stripos( realpath( $_SERVER['SCRIPT_FILENAME'] ), ini_get( 'opcache.restrict_api' ) ) === 0 )
[2382] Fix | Delete
) {
[2383] Fix | Delete
$can_invalidate = true;
[2384] Fix | Delete
}
[2385] Fix | Delete
[2386] Fix | Delete
// If invalidation is not available, return early.
[2387] Fix | Delete
if ( ! $can_invalidate ) {
[2388] Fix | Delete
return false;
[2389] Fix | Delete
}
[2390] Fix | Delete
[2391] Fix | Delete
// Verify that file to be invalidated has a PHP extension.
[2392] Fix | Delete
if ( '.php' !== strtolower( substr( $filepath, -4 ) ) ) {
[2393] Fix | Delete
return false;
[2394] Fix | Delete
}
[2395] Fix | Delete
[2396] Fix | Delete
/**
[2397] Fix | Delete
* Filters whether to invalidate a file from the opcode cache.
[2398] Fix | Delete
*
[2399] Fix | Delete
* @since 5.5.0
[2400] Fix | Delete
*
[2401] Fix | Delete
* @param bool $will_invalidate Whether WordPress will invalidate `$filepath`. Default true.
[2402] Fix | Delete
* @param string $filepath The path to the PHP file to invalidate.
[2403] Fix | Delete
*/
[2404] Fix | Delete
if ( apply_filters( 'wp_opcache_invalidate_file', true, $filepath ) ) {
[2405] Fix | Delete
return opcache_invalidate( $filepath, $force );
[2406] Fix | Delete
}
[2407] Fix | Delete
[2408] Fix | Delete
return false;
[2409] Fix | Delete
}
[2410] Fix | Delete
[2411] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function