| @@ -16,15 +16,20 @@ | ||
| 16 | 16 | return; |
| 17 | 17 | } |
| 18 | 18 | |
| 19 | 19 | // Load admin toolbar feature once WordPress, all plugins, and the theme are fully loaded and instantiated. |
| 20 | - add_action( 'wp_loaded', array( $this, 'load_toolbar' ) ); | |
| 20 | + if ( is_admin() ) { | |
| 21 | + add_action( 'wp_loaded', array( $this, 'load_toolbar' ) ); | |
| 22 | + } else { | |
| 23 | + // to avoid AMP complaining about the AMP conditional being checked too early. | |
| 24 | + add_action( 'wp', array( $this, 'load_toolbar' ) ); | |
| 25 | + } | |
| 21 | 26 | } |
| 22 | 27 | |
| 23 | 28 | public function load_toolbar() |
| 24 | 29 | { |
| 25 | 30 | // Check permissions and that toolbar is not hidden via filter. |
| 26 | - if ( current_user_can( 'manage_options' ) && apply_filters( 'autoptimize_filter_toolbar_show', true ) ) { | |
| 31 | + if ( current_user_can( 'manage_options' ) && apply_filters( 'autoptimize_filter_toolbar_show', true ) && ! autoptimizeMain::is_amp_markup( '' ) ) { | |
| 27 | 32 | |
| 28 | 33 | // Create a handler for the AJAX toolbar requests. |
| 29 | 34 | add_action( 'wp_ajax_autoptimize_delete_cache', array( $this, 'delete_cache' ) ); |
| 30 | 35 | |
| @@ -73,40 +78,47 @@ | ||
| 73 | 78 | $color = ( 100 == $percentage ) ? 'red' : ( ( $percentage > 80 ) ? 'orange' : 'green' ); |
| 74 | 79 | |
| 75 | 80 | // Create or add new items into the Admin Toolbar. |
| 76 | 81 | // Main "Autoptimize" node. |
| 77 | - $wp_admin_bar->add_node( array( | |
| 78 | - 'id' => 'autoptimize', | |
| 79 | - 'title' => '<span class="ab-icon"></span><span class="ab-label">' . __( 'Autoptimize', 'autoptimize' ) . '</span>', | |
| 80 | - 'href' => admin_url( 'options-general.php?page=autoptimize' ), | |
| 81 | - 'meta' => array( 'class' => 'bullet-' . $color ), | |
| 82 | - )); | |
| 82 | + $_my_name = apply_filters( 'autoptimize_filter_settings_is_pro', false ) ? __( 'Autoptimize Pro', 'autoptimize' ) : __( 'Autoptimize', 'autoptimize' ); | |
| 83 | + $wp_admin_bar->add_node( | |
| 84 | + array( | |
| 85 | + 'id' => 'autoptimize', | |
| 86 | + 'title' => '<span class="ab-icon"></span><span class="ab-label">' . $_my_name . '</span>', | |
| 87 | + 'href' => admin_url( 'options-general.php?page=autoptimize' ), | |
| 88 | + 'meta' => array( 'class' => 'bullet-' . $color ), | |
| 89 | + ) | |
| 90 | + ); | |
| 83 | 91 | |
| 84 | 92 | // "Cache Info" node. |
| 85 | - $wp_admin_bar->add_node( array( | |
| 86 | - 'id' => 'autoptimize-cache-info', | |
| 87 | - 'title' => '<p>' . __( 'Cache Info', 'autoptimize' ) . '</p>' . | |
| 88 | - '<div class="autoptimize-radial-bar" percentage="' . $percentage . '">' . | |
| 89 | - '<div class="autoptimize-circle">' . | |
| 90 | - '<div class="mask full"><div class="fill bg-' . $color . '"></div></div>' . | |
| 91 | - '<div class="mask half"><div class="fill bg-' . $color . '"></div></div>' . | |
| 92 | - '<div class="shadow"></div>' . | |
| 93 | - '</div>' . | |
| 94 | - '<div class="inset"><div class="percentage"><div class="numbers ' . $color . '">' . $percentage . '%</div></div></div>' . | |
| 95 | - '</div>' . | |
| 96 | - '<table>' . | |
| 97 | - '<tr><td>' . __( 'Size', 'autoptimize' ) . ':</td><td class="size ' . $color . '">' . $size . '</td></tr>' . | |
| 98 | - '<tr><td>' . __( 'Files', 'autoptimize' ) . ':</td><td class="files white">' . $files . '</td></tr>' . | |
| 99 | - '</table>', | |
| 100 | - 'parent' => 'autoptimize', | |
| 101 | - )); | |
| 93 | + $wp_admin_bar->add_node( | |
| 94 | + array( | |
| 95 | + 'id' => 'autoptimize-cache-info', | |
| 96 | + 'title' => '<p>' . __( 'CSS/ JS Cache Info', 'autoptimize' ) . '</p>' . | |
| 97 | + '<div class="autoptimize-radial-bar" percentage="' . $percentage . '">' . | |
| 98 | + '<div class="autoptimize-circle">' . | |
| 99 | + '<div class="mask full"><div class="fill bg-' . $color . '"></div></div>' . | |
| 100 | + '<div class="mask half"><div class="fill bg-' . $color . '"></div></div>' . | |
| 101 | + '<div class="shadow"></div>' . | |
| 102 | + '</div>' . | |
| 103 | + '<div class="inset"><div class="percentage"><div class="numbers ' . $color . '">' . $percentage . '%</div></div></div>' . | |
| 104 | + '</div>' . | |
| 105 | + '<table>' . | |
| 106 | + '<tr><td>' . __( 'Size', 'autoptimize' ) . ':</td><td class="size ' . $color . '">' . $size . '</td></tr>' . | |
| 107 | + '<tr><td>' . __( 'Files', 'autoptimize' ) . ':</td><td class="files white">' . $files . '</td></tr>' . | |
| 108 | + '</table>', | |
| 109 | + 'parent' => 'autoptimize', | |
| 110 | + ) | |
| 111 | + ); | |
| 102 | 112 | |
| 103 | 113 | // "Delete Cache" node. |
| 104 | - $wp_admin_bar->add_node( array( | |
| 105 | - 'id' => 'autoptimize-delete-cache', | |
| 106 | - 'title' => __( 'Delete Cache', 'autoptimize' ), | |
| 107 | - 'parent' => 'autoptimize', | |
| 108 | - )); | |
| 114 | + $wp_admin_bar->add_node( | |
| 115 | + array( | |
| 116 | + 'id' => 'autoptimize-delete-cache', | |
| 117 | + 'title' => __( 'Clear CSS/ JS Cache', 'autoptimize' ), | |
| 118 | + 'parent' => 'autoptimize', | |
| 119 | + ) | |
| 120 | + ); | |
| 109 | 121 | } |
| 110 | 122 | |
| 111 | 123 | public function delete_cache() |
| 112 | 124 | { |
| @@ -130,14 +142,19 @@ | ||
| 130 | 142 | wp_enqueue_script( 'autoptimize-toolbar', plugins_url( '/static/toolbar.js', __FILE__ ), array( 'jquery' ), AUTOPTIMIZE_PLUGIN_VERSION, true ); |
| 131 | 143 | |
| 132 | 144 | // Localizes a registered script with data for a JavaScript variable. |
| 133 | 145 | // Needed for the AJAX to work properly on the frontend. |
| 134 | - wp_localize_script( 'autoptimize-toolbar', 'autoptimize_ajax_object', array( | |
| 135 | - 'ajaxurl' => admin_url( 'admin-ajax.php' ), | |
| 136 | - 'error_msg' => sprintf( __( 'Your Autoptimize cache might not have been purged successfully, please check on the <a href=%s>Autoptimize settings page</a>.', 'autoptimize' ), admin_url( 'options-general.php?page=autoptimize' ) . ' style="white-space:nowrap;"' ), | |
| 137 | - 'dismiss_msg' => __( 'Dismiss this notice.' ), | |
| 138 | - 'nonce' => wp_create_nonce( 'ao_delcache_nonce' ), | |
| 139 | - ) ); | |
| 146 | + wp_localize_script( | |
| 147 | + 'autoptimize-toolbar', | |
| 148 | + 'autoptimize_ajax_object', | |
| 149 | + array( | |
| 150 | + 'ajaxurl' => admin_url( 'admin-ajax.php' ), | |
| 151 | + // translators: links to the Autoptimize settings page. | |
| 152 | + 'error_msg' => sprintf( __( 'Your Autoptimize cache might not have been purged successfully, please check on the <a href=%s>Autoptimize settings page</a>.', 'autoptimize' ), admin_url( 'options-general.php?page=autoptimize' ) . ' style="white-space:nowrap;"' ), | |
| 153 | + 'dismiss_msg' => __( 'Dismiss this notice.' ), | |
| 154 | + 'nonce' => wp_create_nonce( 'ao_delcache_nonce' ), | |
| 155 | + ) | |
| 156 | + ); | |
| 140 | 157 | } |
| 141 | 158 | |
| 142 | 159 | public function format_filesize( $bytes, $decimals = 2 ) |
| 143 | 160 | { |