1414 add_action ( 'init ' , 'pcm_show_flush_cache_column ' );
1515
1616 function pcm_show_flush_cache_column () {
17- if ( current_user_can ('administrator ' ) || current_user_can ('editor ' ) || current_user_can ('manage_woocommerce ' ) ) {
17+ if ( current_user_can ('manage_options ' ) || current_user_can ('edit_posts ' ) || current_user_can ('manage_woocommerce ' ) ) {
1818 $ column = new FlushObjectCachePageColumn ();
1919 $ column ->add ();
2020 }
@@ -24,7 +24,7 @@ function flush_object_cache_for_single_page_notice() {
2424 $ state = get_option ( 'flush-object-cache-for-single-page-notice ' , 'activating ' );
2525
2626 if ( 'activating ' === $ state &&
27- ( current_user_can ('administrator ' ) || current_user_can ('editor ' ) || current_user_can ('manage_woocommerce ' ) )
27+ ( current_user_can ('manage_options ' ) || current_user_can ('edit_posts ' ) || current_user_can ('manage_woocommerce ' ) )
2828 ) {
2929 add_action ( 'admin_notices ' , function () {
3030 $ screen = get_current_screen ();
@@ -68,7 +68,7 @@ public function add() {
6868 }
6969
7070 public function add_flush_object_cache_link ( $ actions , $ post ) {
71- if ( current_user_can ('administrator ' ) || current_user_can ('editor ' ) || current_user_can ('manage_woocommerce ' ) ) {
71+ if ( current_user_can ('manage_options ' ) || current_user_can ('edit_posts ' ) || current_user_can ('manage_woocommerce ' ) ) {
7272 $ actions ['flush_object_cache_url ' ] =
7373 '<a data-id=" ' . esc_attr ( $ post ->ID ) . '" '
7474 . ' data-nonce=" ' . wp_create_nonce ( 'flush-object-cache_ ' . $ post ->ID ) . '" '
@@ -80,28 +80,28 @@ public function add_flush_object_cache_link( $actions, $post ) {
8080 }
8181
8282 public function flush_object_cache_column () {
83- if ( ! ( current_user_can ('administrator ' ) || current_user_can ('editor ' ) || current_user_can ('manage_woocommerce ' ) ) ) {
84- die ( json_encode ( array ( 'success ' => false , ' message ' => 'Unauthorized ' ) ) );
83+ if ( ! ( current_user_can ('manage_options ' ) || current_user_can ('edit_posts ' ) || current_user_can ('manage_woocommerce ' ) ) ) {
84+ wp_send_json_error ( array ( 'message ' => 'Unauthorized ' ), 403 );
8585 }
8686
87- if ( ! isset ( $ _GET ['nonce ' ] ) || ! wp_verify_nonce ( sanitize_text_field ( wp_unslash ( $ _GET ['nonce ' ] ) ), 'flush-object-cache_ ' . intval ( $ _GET ['id ' ] ) ) ) {
88- die ( json_encode ( array ( 'success ' => false , ' message ' => 'Nonce verification failed ' ) ) );
87+ if ( ! isset ( $ _POST ['nonce ' ] ) || ! wp_verify_nonce ( sanitize_text_field ( wp_unslash ( $ _POST ['nonce ' ] ) ), 'flush-object-cache_ ' . intval ( $ _POST ['id ' ] ) ) ) {
88+ wp_send_json_error ( array ( 'message ' => 'Nonce verification failed ' ), 403 );
8989 }
9090
91- $ url_key = get_permalink ( intval ( $ _GET ['id ' ] ) );
92- $ page_title = get_the_title ( intval ( $ _GET ['id ' ] ) );
91+ $ url_key = get_permalink ( intval ( $ _POST ['id ' ] ) );
92+ $ page_title = get_the_title ( intval ( $ _POST ['id ' ] ) );
9393 update_option ( 'page-title ' , $ page_title );
9494
9595 global $ batcache , $ wp_object_cache ;
9696
9797 if ( ! isset ( $ batcache ) || ! is_object ( $ batcache ) || ! method_exists ( $ wp_object_cache , 'incr ' ) ) {
98- die ( json_encode ( array ( 'success ' => false ) ) );
98+ wp_send_json_error ( array ( 'message ' => ' Batcache not available ' ) );
9999 }
100100
101101 $ batcache ->configure_groups ();
102102 $ url = apply_filters ( 'batcache_manager_link ' , $ url_key );
103103 if ( empty ( $ url ) ) {
104- die ( json_encode ( array ( 'success ' => false ) ) );
104+ wp_send_json_error ( array ( 'message ' => ' Empty URL ' ) );
105105 }
106106
107107 do_action ( 'batcache_manager_before_flush ' , $ url );
@@ -111,11 +111,12 @@ public function flush_object_cache_column() {
111111 wp_cache_add ( "{$ url_key }_version " , 0 , $ batcache ->group );
112112 wp_cache_incr ( "{$ url_key }_version " , 1 , $ batcache ->group );
113113
114+ $ retval = wp_cache_get ( "{$ url_key }_version " , $ batcache ->group );
114115 if ( property_exists ( $ wp_object_cache , 'no_remote_groups ' ) ) {
115116 $ k = array_search ( $ batcache ->group , (array ) $ wp_object_cache ->no_remote_groups );
116117 if ( false !== $ k ) {
117118 unset( $ wp_object_cache ->no_remote_groups [ $ k ] );
118- wp_cache_set ( "{$ url_key }_version " , $ batcache ->group );
119+ wp_cache_set ( "{$ url_key }_version " , $ retval , $ batcache ->group );
119120 $ wp_object_cache ->no_remote_groups [ $ k ] = $ batcache ->group ;
120121 }
121122 }
@@ -125,14 +126,15 @@ public function flush_object_cache_column() {
125126 // Also store the flushed URL so it shows on the settings page
126127 update_option ( 'single-page-url-flushed ' , $ url );
127128
128- die ( json_encode ( array ( 'success ' => true ) ) );
129+ wp_send_json_success ( array ( 'message ' => ' Cache flushed ' ) );
129130 }
130131
131132 public function load_js () {
133+ $ js_file = plugin_dir_path ( dirname ( __FILE__ ) ) . 'public/js/column.js ' ;
132134 wp_enqueue_script (
133135 'flush-object-cache-column ' ,
134136 plugin_dir_url ( dirname ( __FILE__ ) ) . 'public/js/column.js ' ,
135- array (), time () , true
137+ array (), file_exists ( $ js_file ) ? filemtime ( $ js_file ) : ' 1.0 ' , true
136138 );
137139 }
138140 }
0 commit comments