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-super.../inc
File: delete-cache-button.php
<?php
[0] Fix | Delete
if ( defined( 'WPSCDISABLEDELETEBUTTON' ) ) {
[1] Fix | Delete
return;
[2] Fix | Delete
}
[3] Fix | Delete
[4] Fix | Delete
/**
[5] Fix | Delete
* Adds "Delete Cache" button in WP Toolbar.
[6] Fix | Delete
*/
[7] Fix | Delete
function wpsc_admin_bar_render( $wp_admin_bar ) {
[8] Fix | Delete
[9] Fix | Delete
if ( ! function_exists( 'current_user_can' ) || ! is_user_logged_in() ) {
[10] Fix | Delete
return false;
[11] Fix | Delete
}
[12] Fix | Delete
[13] Fix | Delete
$path_to_home = rtrim( (string) parse_url( get_option( 'home' ), PHP_URL_PATH ), '/' );
[14] Fix | Delete
if ( ( is_singular() || is_archive() || is_front_page() || is_search() ) && current_user_can( 'delete_others_posts' ) ) {
[15] Fix | Delete
[16] Fix | Delete
$site_regex = preg_quote( $path_to_home, '`' );
[17] Fix | Delete
$req_uri = preg_replace( '/[ <>\'\"\r\n\t\(\)]/', '', $_SERVER[ 'REQUEST_URI' ] );
[18] Fix | Delete
$path = preg_replace( '`^' . $site_regex . '`', '', $req_uri );
[19] Fix | Delete
[20] Fix | Delete
$wp_admin_bar->add_menu( array(
[21] Fix | Delete
'parent' => '',
[22] Fix | Delete
'id' => 'delete-cache',
[23] Fix | Delete
'title' => __( 'Delete Cache', 'wp-super-cache' ),
[24] Fix | Delete
'meta' => array( 'title' => __( 'Delete cache of the current page', 'wp-super-cache' ) ),
[25] Fix | Delete
'href' => wp_nonce_url( admin_url( 'index.php?action=delcachepage&path=' . rawurlencode( $path ) ), 'delete-cache-' . $path . '_0', 'nonce' )
[26] Fix | Delete
) );
[27] Fix | Delete
}
[28] Fix | Delete
[29] Fix | Delete
if ( is_admin() && ( wpsupercache_site_admin() || current_user_can( 'delete_others_posts' ) ) ) {
[30] Fix | Delete
$wp_admin_bar->add_menu( array(
[31] Fix | Delete
'parent' => '',
[32] Fix | Delete
'id' => 'delete-cache',
[33] Fix | Delete
'title' => __( 'Delete Cache', 'wp-super-cache' ),
[34] Fix | Delete
'meta' => array( 'title' => __( 'Delete Super Cache cached files', 'wp-super-cache' ) ),
[35] Fix | Delete
'href' => wp_nonce_url( admin_url( 'index.php?admin=1&action=delcachepage&path=' . rawurlencode( trailingslashit( $path_to_home ) ) ), 'delete-cache-' . trailingslashit( $path_to_home ) . '_1', 'nonce' )
[36] Fix | Delete
) );
[37] Fix | Delete
}
[38] Fix | Delete
}
[39] Fix | Delete
add_action( 'admin_bar_menu', 'wpsc_admin_bar_render', 99 );
[40] Fix | Delete
[41] Fix | Delete
function wpsc_delete_cache_scripts() {
[42] Fix | Delete
if ( ! is_user_logged_in() ) {
[43] Fix | Delete
return;
[44] Fix | Delete
}
[45] Fix | Delete
[46] Fix | Delete
if (
[47] Fix | Delete
is_plugin_active( 'amp/amp.php' ) ||
[48] Fix | Delete
( function_exists( 'ampforwp_is_amp_endpoint' ) && ampforwp_is_amp_endpoint() )
[49] Fix | Delete
) {
[50] Fix | Delete
wp_cache_debug( 'AMP detected. Not loading Delete Cache button JavaScript.' );
[51] Fix | Delete
return;
[52] Fix | Delete
}
[53] Fix | Delete
[54] Fix | Delete
$path_to_home = rtrim( (string) parse_url( get_option( 'home' ), PHP_URL_PATH ), '/' );
[55] Fix | Delete
[56] Fix | Delete
wp_enqueue_script( 'delete-cache-button', plugins_url( '/delete-cache-button.js', __FILE__ ), array('jquery'), '1.0', 1 );
[57] Fix | Delete
[58] Fix | Delete
if ( ( is_singular() || is_archive() || is_front_page() || is_search() ) && current_user_can( 'delete_others_posts' ) ) {
[59] Fix | Delete
$site_regex = preg_quote( $path_to_home, '`' );
[60] Fix | Delete
$req_uri = preg_replace( '/[ <>\'\"\r\n\t\(\)]/', '', $_SERVER[ 'REQUEST_URI' ] );
[61] Fix | Delete
$path_to_home = preg_replace( '`^' . $site_regex . '`', '', $req_uri );
[62] Fix | Delete
$admin = 0;
[63] Fix | Delete
} else {
[64] Fix | Delete
$admin = 1;
[65] Fix | Delete
}
[66] Fix | Delete
[67] Fix | Delete
if ( $path_to_home === '' ) {
[68] Fix | Delete
$path_to_home = '/';
[69] Fix | Delete
}
[70] Fix | Delete
[71] Fix | Delete
$nonce = wp_create_nonce( 'delete-cache-' . $path_to_home . '_' . $admin );
[72] Fix | Delete
wp_localize_script( 'delete-cache-button', 'wpsc_ajax', array( 'ajax_url' => admin_url( 'admin-ajax.php' ), 'path' => $path_to_home, 'admin' => $admin, 'nonce' => $nonce ) );
[73] Fix | Delete
}
[74] Fix | Delete
add_action( 'wp_ajax_ajax-delete-cache', 'wpsc_admin_bar_delete_cache_ajax' );
[75] Fix | Delete
add_action( 'admin_enqueue_scripts', 'wpsc_delete_cache_scripts' );
[76] Fix | Delete
[77] Fix | Delete
/**
[78] Fix | Delete
* Delete cache for a specific page.
[79] Fix | Delete
*/
[80] Fix | Delete
function wpsc_admin_bar_delete_cache_ajax() {
[81] Fix | Delete
// response output
[82] Fix | Delete
header( "Content-Type: application/json" );
[83] Fix | Delete
if ( ! wpsc_delete_cache_directory() ) {
[84] Fix | Delete
if ( defined( 'WPSCDELETEERROR' ) ) {
[85] Fix | Delete
return json_decode( constant( 'WPSCDELETEERROR' ) );
[86] Fix | Delete
} else {
[87] Fix | Delete
return json_decode( false );
[88] Fix | Delete
}
[89] Fix | Delete
}
[90] Fix | Delete
}
[91] Fix | Delete
[92] Fix | Delete
function wpsc_admin_bar_delete_cache() {
[93] Fix | Delete
$referer = wp_get_referer();
[94] Fix | Delete
[95] Fix | Delete
if ( ! isset( $_GET['admin'] ) ) {
[96] Fix | Delete
$_GET['admin'] = 0;
[97] Fix | Delete
}
[98] Fix | Delete
[99] Fix | Delete
foreach( array( 'path', 'nonce', 'admin' ) as $part ) {
[100] Fix | Delete
if ( isset( $_GET[ $part ] ) ) {
[101] Fix | Delete
$_POST[ $part ] = $_GET[ $part ];
[102] Fix | Delete
}
[103] Fix | Delete
}
[104] Fix | Delete
wpsc_delete_cache_directory();
[105] Fix | Delete
[106] Fix | Delete
$req_path = isset( $_POST['path'] ) ? sanitize_text_field( stripslashes( $_POST['path'] ) ) : '';
[107] Fix | Delete
$valid_nonce = ( $req_path && isset( $_POST['nonce'] ) ) ? wp_verify_nonce( $_POST['nonce'], 'delete-cache-' . $_POST['path'] . '_' . $_POST['admin'] ) : false;
[108] Fix | Delete
[109] Fix | Delete
if (
[110] Fix | Delete
$valid_nonce
[111] Fix | Delete
&& $referer
[112] Fix | Delete
&& $req_path
[113] Fix | Delete
&& (
[114] Fix | Delete
false !== stripos( $referer, $req_path )
[115] Fix | Delete
|| 0 === stripos( $referer, wp_login_url() )
[116] Fix | Delete
)
[117] Fix | Delete
) {
[118] Fix | Delete
/**
[119] Fix | Delete
* Hook into the cache deletion process after a successful cache deletion from the admin bar button.
[120] Fix | Delete
*
[121] Fix | Delete
* @since 1.9
[122] Fix | Delete
*
[123] Fix | Delete
* @param string $req_path Path of the page where the cache flush was requested.
[124] Fix | Delete
* @param string $referer Referer URL.
[125] Fix | Delete
*/
[126] Fix | Delete
do_action( 'wpsc_after_delete_cache_admin_bar', $req_path, $referer );
[127] Fix | Delete
[128] Fix | Delete
if ( $_POST['admin'] ) {
[129] Fix | Delete
wp_safe_redirect( $referer );
[130] Fix | Delete
} else {
[131] Fix | Delete
wp_safe_redirect( esc_url_raw( home_url( $req_path ) ) );
[132] Fix | Delete
}
[133] Fix | Delete
exit;
[134] Fix | Delete
} else {
[135] Fix | Delete
die( "Oops. Problem with nonce. Please delete cached page from settings page." );
[136] Fix | Delete
}
[137] Fix | Delete
}
[138] Fix | Delete
[139] Fix | Delete
if ( 'delcachepage' === filter_input( INPUT_GET, 'action' ) ) {
[140] Fix | Delete
add_action( 'admin_init', 'wpsc_admin_bar_delete_cache' );
[141] Fix | Delete
}
[142] Fix | Delete
[143] Fix | Delete
function wpsc_delete_cache_directory() {
[144] Fix | Delete
if ( ! current_user_can( 'delete_others_posts' ) ) {
[145] Fix | Delete
return false;
[146] Fix | Delete
}
[147] Fix | Delete
[148] Fix | Delete
$req_path = isset( $_POST['path'] ) ? sanitize_text_field( stripslashes( $_POST['path'] ) ) : '';
[149] Fix | Delete
$valid_nonce = ( $req_path && isset( $_POST['nonce'] ) ) ? wp_verify_nonce( $_POST['nonce'], 'delete-cache-' . $_POST['path'] . '_' . $_POST['admin'] ) : false;
[150] Fix | Delete
[151] Fix | Delete
if ( ! $valid_nonce ) {
[152] Fix | Delete
wp_cache_debug( 'wpsc_delete_cache_directory: nonce was not valid' );
[153] Fix | Delete
return false;
[154] Fix | Delete
}
[155] Fix | Delete
[156] Fix | Delete
$path = $valid_nonce ? realpath( trailingslashit( get_supercache_dir() . str_replace( '..', '', preg_replace( '/:.*$/', '', $req_path ) ) ) ) : false;
[157] Fix | Delete
[158] Fix | Delete
if ( $path ) {
[159] Fix | Delete
if ( isset( $_POST['admin'] ) && (int) $_POST['admin'] === 1 ) {
[160] Fix | Delete
global $file_prefix;
[161] Fix | Delete
wp_cache_debug( 'Cleaning cache for this site.' );
[162] Fix | Delete
wp_cache_clean_cache( $file_prefix );
[163] Fix | Delete
return;
[164] Fix | Delete
}
[165] Fix | Delete
$path = trailingslashit( $path );
[166] Fix | Delete
$supercachepath = realpath( get_supercache_dir() );
[167] Fix | Delete
[168] Fix | Delete
if ( false === wp_cache_confirm_delete( $path ) || ! str_starts_with( $path, $supercachepath ) ) {
[169] Fix | Delete
wp_cache_debug( 'Could not delete directory: ' . $path );
[170] Fix | Delete
define( 'WPSCDELETEERROR', 'Could not delete directory' );
[171] Fix | Delete
return false;
[172] Fix | Delete
}
[173] Fix | Delete
[174] Fix | Delete
wp_cache_debug( 'Deleting cache files in directory: ' . $path );
[175] Fix | Delete
wpsc_delete_files( $path );
[176] Fix | Delete
return;
[177] Fix | Delete
} else {
[178] Fix | Delete
wp_cache_debug( 'wpsc_delete_cache_directory: Could not delete directory. It does not exist: ' . esc_attr( $_POST['path'] ) );
[179] Fix | Delete
}
[180] Fix | Delete
}
[181] Fix | Delete
[182] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function