assets
3 months ago
pages
3 days ago
AHSC_Admin_Bar.php
5 months ago
AHSC_Admin_Menu.php
5 months ago
index.php
5 months ago
AHSC_Admin_Bar.php
109 lines
| 1 | <?php |
| 2 | if ( ! defined( 'ABSPATH' ) ) { |
| 3 | exit; |
| 4 | } |
| 5 | \add_action( 'admin_bar_menu', 'AHSC_add_admin_bar_menu_links' , 100 ); |
| 6 | |
| 7 | //die(var_export(__( 'Purge Cache','aruba-hispeed-cache' ),true)); |
| 8 | const AHSC_MENUBAR_PARENT_ITEM = 'aruba_spa'; |
| 9 | //$topurge = 'current-url'; |
| 10 | //$AHSC_AB_title =esc_html(__( 'Purge page cache', 'aruba-hispeed-cache' )); |
| 11 | //var_dump(esc_html(__( 'Purge page cache', 'aruba-hispeed-cache' ))); |
| 12 | /* |
| 13 | if ( \is_admin() ) { |
| 14 | $topurge = 'all'; |
| 15 | $AHSC_AB_title = esc_html(__( 'Purge Cache', 'aruba-hispeed-cache' )) ; |
| 16 | //esc_html(__( 'Purge Cache', 'aruba-hispeed-cache' )); |
| 17 | }*/ |
| 18 | |
| 19 | |
| 20 | |
| 21 | |
| 22 | /** |
| 23 | * Netodo che aggiunge action link alla admin bar. |
| 24 | * |
| 25 | * @doc see https://developer.wordpress.org/reference/hooks/admin_bar_menu/ |
| 26 | * |
| 27 | * @param WP_Admin_Bar $wp_admin_bar The WP_Admin_Bar instance, passed by reference. |
| 28 | * @return void |
| 29 | */ |
| 30 | function AHSC_add_admin_bar_menu_links( $wp_admin_bar ) { |
| 31 | //global $AHSC_AB_title,$topurge; |
| 32 | $AHSC_AB_title =esc_html(__( 'Purge page cache', 'aruba-hispeed-cache' )); |
| 33 | //var_dump(esc_html(__( 'Purge page cache', 'aruba-hispeed-cache' ))); |
| 34 | |
| 35 | if ( \is_admin() ) { |
| 36 | $topurge = 'all'; |
| 37 | $AHSC_AB_title = esc_html(__( 'Purge Cache', 'aruba-hispeed-cache' )) ; |
| 38 | //esc_html(__( 'Purge Cache', 'aruba-hispeed-cache' )); |
| 39 | }else{ |
| 40 | $topurge = 'current-url'; |
| 41 | } |
| 42 | if ( is_user_logged_in() && current_user_can( 'manage_options' )){ |
| 43 | $wp_admin_bar->add_menu( |
| 44 | array( |
| 45 | 'id' => 'ahsc-purge-link', |
| 46 | 'parent' => ( ! \is_null( $wp_admin_bar->get_node( AHSC_MENUBAR_PARENT_ITEM ) ) ) ? AHSC_MENUBAR_PARENT_ITEM : false, |
| 47 | 'title' => AHSC_Menu_get_title(), |
| 48 | 'meta' => array( |
| 49 | 'title' => $AHSC_AB_title, |
| 50 | 'data-topurge' => $topurge, |
| 51 | 'onclick' => 'ahscBtnPurger(); return;' |
| 52 | ), |
| 53 | ) |
| 54 | ); |
| 55 | |
| 56 | $wp_admin_bar->add_menu( |
| 57 | array( |
| 58 | 'id' => 'ahsc-transient-purge', |
| 59 | 'parent' => ( ! \is_null( $wp_admin_bar->get_node( AHSC_MENUBAR_PARENT_ITEM ) ) ) ? AHSC_MENUBAR_PARENT_ITEM : false, |
| 60 | 'title' =>'<span class="ab-icon ahsc-ab-icon" aria-hidden="true"></span><span class="ab-label">'.esc_html(__( 'Purge Expired Transient', 'aruba-hispeed-cache' )).'</span>', |
| 61 | 'meta' => array( |
| 62 | 'title' => esc_html(__( 'Purge Expired Transient', 'aruba-hispeed-cache' )), |
| 63 | 'onclick' => 'ahscBtnTransientPurger(); return;' |
| 64 | ), |
| 65 | ) |
| 66 | ); |
| 67 | |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | |
| 72 | /** |
| 73 | * This method adds and localizes the toolbar.js on both the frontend and backend. |
| 74 | * |
| 75 | * @return void |
| 76 | */ |
| 77 | function AHSC_localize_toolbar_js() { |
| 78 | |
| 79 | if ( \is_admin() ) { |
| 80 | $topurge = 'all'; |
| 81 | }else{ |
| 82 | $topurge = 'current-url'; |
| 83 | } |
| 84 | if ( is_user_logged_in() && current_user_can( 'manage_options' )) { |
| 85 | //global $topurge; |
| 86 | $js_param = array( |
| 87 | 'ahsc_ajax_url' => \admin_url('admin-ajax.php'), |
| 88 | 'ahsc_topurge' => $topurge, |
| 89 | 'ahsc_nonce' => \wp_create_nonce('ahsc-purge-cache'), |
| 90 | ); |
| 91 | \wp_add_inline_script('ahcs-toolbar', 'const AHSC_TOOLBAR = ' . \wp_json_encode($js_param), 'before'); |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * Get the title whit icon. |
| 97 | * |
| 98 | * @return string |
| 99 | */ |
| 100 | function AHSC_Menu_get_title() { |
| 101 | //global $AHSC_AB_title; |
| 102 | $AHSC_AB_title =esc_html(__( 'Purge page cache', 'aruba-hispeed-cache' )); |
| 103 | |
| 104 | if ( \is_admin() ) { |
| 105 | $AHSC_AB_title = esc_html(__( 'Purge Cache', 'aruba-hispeed-cache' )) ; |
| 106 | } |
| 107 | $title = '<span class="ab-icon ahsc-ab-icon" aria-hidden="true"></span><span class="ab-label">' . $AHSC_AB_title . '</span>'; |
| 108 | return $title; |
| 109 | } |