WordPress.org

Plugin Directory

Changeset 592322


Ignore:
Timestamp:
08/30/12 10:32:03 (20 months ago)
Author:
donncha
Message:

Allow editors to delete cached files for specific pages via the admin bar. See http://wordpress.org/support/topic/plugin-wp-super-cache-allow-editor-role-to-delete-cache?replies=8

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wp-super-cache/trunk/wp-cache.php

    r581266 r592322  
    378378add_filter( 'wp_super_cache_error_checking', 'wp_cache_manager_error_checks' ); 
    379379 
    380 function wp_cache_manager_updates() { 
    381     global $wp_cache_mobile_enabled, $wp_supercache_cache_list, $wp_cache_config_file, $wp_cache_hello_world, $wp_cache_clear_on_post_edit, $cache_rebuild_files, $wp_cache_mutex_disabled, $wp_cache_not_logged_in, $wp_cache_make_known_anon, $cache_path, $wp_cache_object_cache, $_wp_using_ext_object_cache, $wp_cache_refresh_single_only, $cache_compression, $wp_cache_mod_rewrite, $wp_supercache_304, $wp_super_cache_late_init, $wp_cache_front_page_checks, $cache_page_secret, $wp_cache_disable_utf8, $wp_cache_no_cache_for_get; 
    382     global $cache_schedule_type, $cache_scheduled_time, $cache_max_time, $cache_time_interval, $wp_cache_shutdown_gc; 
    383  
    384     if ( !wpsupercache_site_admin() ) 
    385         return false; 
    386  
    387     if ( false == isset( $cache_page_secret ) ) { 
    388         $cache_page_secret = md5( date( 'H:i:s' ) . mt_rand() ); 
    389         wp_cache_replace_line('^ *\$cache_page_secret', "\$cache_page_secret = '" . $cache_page_secret . "';", $wp_cache_config_file); 
    390     } 
    391  
     380function admin_bar_delete_page() { 
    392381    // Delete cache for a specific page 
    393     if ( isset( $_GET[ 'action' ] ) && $_GET[ 'action' ] == 'delete' && ( isset( $_GET[ '_wpnonce' ] ) ? wp_verify_nonce( $_REQUEST[ '_wpnonce' ], 'delete-cache' ) : false ) ) { 
     382    if ( function_exists('current_user_can') && false == current_user_can('delete_others_posts') ) 
     383        return false; 
     384    if ( isset( $_GET[ 'action' ] ) && $_GET[ 'action' ] == 'delcachepage' && ( isset( $_GET[ '_wpnonce' ] ) ? wp_verify_nonce( $_REQUEST[ '_wpnonce' ], 'delete-cache' ) : false ) ) { 
    394385        $path = get_supercache_dir() . preg_replace( '/:.*$/', '', $_GET[ 'path' ] ); 
    395386        $files = get_all_supercache_filenames( $path ); 
     
    399390        wp_redirect( preg_replace( '/[ <>\'\"\r\n\t\(\)]/', '', $_GET[ 'path' ] ) ); 
    400391        die(); 
     392    } 
     393} 
     394if ( isset( $_GET[ 'action' ] ) && $_GET[ 'action' ] == 'delcachepage' ) 
     395   add_action( 'admin_init', 'admin_bar_delete_page' ); 
     396 
     397function wp_cache_manager_updates() { 
     398    global $wp_cache_mobile_enabled, $wp_supercache_cache_list, $wp_cache_config_file, $wp_cache_hello_world, $wp_cache_clear_on_post_edit, $cache_rebuild_files, $wp_cache_mutex_disabled, $wp_cache_not_logged_in, $wp_cache_make_known_anon, $cache_path, $wp_cache_object_cache, $_wp_using_ext_object_cache, $wp_cache_refresh_single_only, $cache_compression, $wp_cache_mod_rewrite, $wp_supercache_304, $wp_super_cache_late_init, $wp_cache_front_page_checks, $cache_page_secret, $wp_cache_disable_utf8, $wp_cache_no_cache_for_get; 
     399    global $cache_schedule_type, $cache_scheduled_time, $cache_max_time, $cache_time_interval, $wp_cache_shutdown_gc; 
     400 
     401    if ( !wpsupercache_site_admin() ) 
     402        return false; 
     403 
     404    if ( false == isset( $cache_page_secret ) ) { 
     405        $cache_page_secret = md5( date( 'H:i:s' ) . mt_rand() ); 
     406        wp_cache_replace_line('^ *\$cache_page_secret', "\$cache_page_secret = '" . $cache_page_secret . "';", $wp_cache_config_file); 
    401407    } 
    402408 
     
    31113117        return false; 
    31123118 
    3113     if ( !wpsupercache_site_admin() ) 
     3119    if ( function_exists('current_user_can') && false == current_user_can('delete_others_posts') ) 
    31143120        return false; 
    31153121 
     
    31193125                'title' => __( 'Delete Cache', 'wp-super-cache' ), 
    31203126                'meta' => array( 'title' => __( 'Delete cache of the current page', 'wp-super-cache' ) ), 
    3121                 'href' => wp_nonce_url( admin_url( 'options-general.php?page=wpsupercache&action=delete&path=' . urlencode( $_SERVER[ 'REQUEST_URI' ] ) ), 'delete-cache' ) 
     3127                'href' => wp_nonce_url( admin_url( 'index.php?action=delcachepage&path=' . urlencode( $_SERVER[ 'REQUEST_URI' ] ) ), 'delete-cache' ) 
    31223128                ) ); 
    31233129} 
Note: See TracChangeset for help on using the changeset viewer.