@@ -116,9 +116,6 @@ public function __construct() {
116
116
/* Flush icon */
117
117
add_action ( 'admin_bar_menu ' , array ( __CLASS__ , 'add_flush_icon ' ), 90 );
118
118
119
- /* Flush icon script */
120
- add_action ( 'admin_bar_menu ' , array ( __CLASS__ , 'add_flush_icon_script ' ), 90 );
121
-
122
119
/* Flush REST endpoint */
123
120
add_action ( 'rest_api_init ' , array ( __CLASS__ , 'add_flush_rest_endpoint ' ) );
124
121
@@ -695,6 +692,22 @@ public static function add_flush_icon( $wp_admin_bar ) {
695
692
/* Enqueue style */
696
693
wp_enqueue_style ( 'cachify-admin-bar-flush ' );
697
694
695
+ /* Enqueue script */
696
+ wp_enqueue_script ( 'cachify-admin-bar-flush ' );
697
+
698
+ /* Localize script */
699
+ wp_localize_script (
700
+ 'cachify-admin-bar-flush ' ,
701
+ 'cachify_admin_bar_flush_ajax_object ' ,
702
+ array (
703
+ 'url ' => esc_url_raw ( rest_url ( self ::REST_NAMESPACE . '/ ' . self ::REST_ROUTE_FLUSH ) ),
704
+ 'nonce ' => wp_create_nonce ( 'wp_rest ' ),
705
+ 'flushing ' => __ ( 'Flushing cache ' , 'cachify ' ),
706
+ 'flushed ' => __ ( 'Cache flushed successfully ' , 'cachify ' ),
707
+ 'dashicon_success ' => self ::get_dashicon_success_class (),
708
+ )
709
+ );
710
+
698
711
/* Print area for aria live updates */
699
712
echo '<span class="ab-aria-live-area screen-reader-text" aria-live="polite"></span> ' ;
700
713
/* Check if the flush action was used without AJAX */
@@ -739,39 +752,6 @@ public static function get_dashicon_success_class() {
739
752
return 'dashicons-yes-alt ' ;
740
753
}
741
754
742
- /**
743
- * Add a script to query the REST endpoint and animate the flush icon in admin bar menu
744
- *
745
- * @hook mixed cachify_user_can_flush_cache ?
746
- *
747
- * @param object $wp_admin_bar Object of menu items.
748
- *
749
- * @since 2.4.0
750
- */
751
- public static function add_flush_icon_script ( $ wp_admin_bar ) {
752
- /* Quit */
753
- if ( ! is_admin_bar_showing () || ! apply_filters ( 'cachify_user_can_flush_cache ' , current_user_can ( 'manage_options ' ) ) ) {
754
- return ;
755
- }
756
-
757
- /* Enqueue script */
758
- wp_enqueue_script ( 'cachify-admin-bar-flush ' );
759
-
760
- /* Localize script */
761
- wp_localize_script (
762
- 'cachify-admin-bar-flush ' ,
763
- 'cachify_admin_bar_flush_ajax_object ' ,
764
- array (
765
- 'url ' => esc_url_raw ( rest_url ( self ::REST_NAMESPACE . '/ ' . self ::REST_ROUTE_FLUSH ) ),
766
- 'nonce ' => wp_create_nonce ( 'wp_rest ' ),
767
- 'flushing ' => __ ( 'Flushing cache ' , 'cachify ' ),
768
- 'flushed ' => __ ( 'Cache flushed successfully ' , 'cachify ' ),
769
- 'dashicon_success ' => self ::get_dashicon_success_class (),
770
- )
771
- );
772
- }
773
-
774
-
775
755
/**
776
756
* Registers an REST endpoint for the flush operation
777
757
*
0 commit comments