Last active
December 27, 2015 21:01
-
-
Save glueckpress/0ccc84e6f93b89dee1d3 to your computer and use it in GitHub Desktop.
[WordPress][Cachify] Mini plugin to move Cachify’s trash icon to the primary/left part of the admin bar.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Plugin Name: Cachify | Customize admin bar icon. | |
* Description: Moves Cachify’s trash icon to the primary/left part of the admin bar. | |
* Version: 2015.12 | |
* Author: Caspar Hübinger | |
* Author URI: https://profiles.wordpress.org/glueckpress/ | |
* Plugin URI: https://gist.github.com/glueckpress/0ccc84e6f93b89dee1d3 | |
* License: GNU General Public License v3 | |
* License URI: http://www.gnu.org/licenses/gpl-3.0.html | |
*/ | |
if ( ! defined( 'ABSPATH' ) ) { | |
exit; | |
} | |
/** | |
* Initialize plugin. | |
* | |
* @return void | |
*/ | |
function cachify_customize_admin_bar_icon() { | |
if ( ! class_exists( 'Cachify' ) ) | |
return; | |
// Remove default admin bar icon. | |
remove_action( 'admin_bar_menu', array( 'Cachify', 'add_flush_icon' ), 90 ); | |
// Add custom admin bar icon. | |
add_action( 'admin_bar_menu', 'cachify_customize_admin_bar_icon__add_flush_icon', 90 ); | |
} | |
add_action( 'after_setup_theme', 'cachify_customize_admin_bar_icon' ); | |
/** | |
* Modified Cachify Trash Admin Bar Icon. | |
* | |
* @param object $wp_admin_bar Admin bar object | |
* @return void | |
*/ | |
function cachify_customize_admin_bar_icon__add_flush_icon( $wp_admin_bar ) { | |
if ( ! is_admin_bar_showing() OR ! apply_filters( 'cachify_user_can_flush_cache', current_user_can( 'manage_options' ) ) ) { | |
return; | |
} | |
$wp_admin_bar->add_menu( | |
array( | |
'id' => 'cachify', | |
'href' => wp_nonce_url( add_query_arg( '_cachify', 'flush' ), '_cachify__flush_nonce' ), | |
'title' => sprintf( | |
'<span class="ab-icon dashicons dashicons-trash"><span class="screen-reader-text">%s</span></span>', | |
__( 'Flush the cachify cache', 'cachify' ) | |
), | |
'meta' => array( | |
'title' => esc_attr__( 'Flush the cachify cache', 'cachify' ) | |
) | |
) | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment