Skip to content

Commit ec45066

Browse files
committed
merge hooks to add flush icon style and script (#326)
1 parent 8cdb0fa commit ec45066

File tree

1 file changed

+16
-36
lines changed

1 file changed

+16
-36
lines changed

inc/class-cachify.php

+16-36
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,6 @@ public function __construct() {
116116
/* Flush icon */
117117
add_action( 'admin_bar_menu', array( __CLASS__, 'add_flush_icon' ), 90 );
118118

119-
/* Flush icon script */
120-
add_action( 'admin_bar_menu', array( __CLASS__, 'add_flush_icon_script' ), 90 );
121-
122119
/* Flush REST endpoint */
123120
add_action( 'rest_api_init', array( __CLASS__, 'add_flush_rest_endpoint' ) );
124121

@@ -695,6 +692,22 @@ public static function add_flush_icon( $wp_admin_bar ) {
695692
/* Enqueue style */
696693
wp_enqueue_style( 'cachify-admin-bar-flush' );
697694

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+
698711
/* Print area for aria live updates */
699712
echo '<span class="ab-aria-live-area screen-reader-text" aria-live="polite"></span>';
700713
/* Check if the flush action was used without AJAX */
@@ -739,39 +752,6 @@ public static function get_dashicon_success_class() {
739752
return 'dashicons-yes-alt';
740753
}
741754

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-
775755
/**
776756
* Registers an REST endpoint for the flush operation
777757
*

0 commit comments

Comments
 (0)