Last active
June 10, 2020 13:36
-
-
Save jordantrizz/d664bec3d4560183672692a61c61c6a1 to your computer and use it in GitHub Desktop.
Nginx Helper - Role Purge Cache
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: Nginx Helper - Role Purge Cache | |
* Plugin URI: https://rtcamp.com/nginx-helper/ | |
* Description: Allows store manager role to purge page and site cache. | |
* Version: 0.1 | |
* Author: Hubert, Koen Adams, Jordan Trask | |
* Author URI: https:// | |
* Text Domain: nginx-helper-store-manager | |
* Domain Path: /languages | |
* Requires at least: 3.0 | |
* Tested up to: 5.4 | |
* | |
* @link https:// | |
* @since 0.1 | |
* @package nginx-helper-store-manager | |
*/ | |
add_action( 'admin_bar_menu', 'admin_bar_add_nginx_helper_purge_button_for_more_user_roles', 80 ); | |
function admin_bar_add_nginx_helper_purge_button_for_more_user_roles() { | |
global $wp_admin_bar; | |
// https://wordpress.org/plugins/nginx-helper/ | |
// check if plugin nginx helper is active | |
if( ! is_plugin_active('nginx-helper/nginx-helper.php')) { | |
return; | |
} | |
// check if shop_manager or editor | |
if( ! current_user_can('editor') && ! current_user_can('shop_manager')) { | |
return; | |
} | |
if ( is_admin() ) { | |
$nginx_helper_urls = 'all'; | |
$link_title = __( 'Purge Cache', 'kick-off-wp' ); | |
} else { | |
$nginx_helper_urls = 'current-url'; | |
$link_title = __( 'Purge Cache Page', 'kick-off-wp' ); | |
} | |
$purge_url = add_query_arg( | |
array( | |
'nginx_helper_action' => 'purge', | |
'nginx_helper_urls' => $nginx_helper_urls, | |
) | |
); | |
$nonced_url = wp_nonce_url( $purge_url, 'nginx_helper-purge_all' ); | |
$args = array( | |
'id' => 'kowp_purge_nginx_helper_cache', | |
'title' => $link_title, | |
'href' => $nonced_url, | |
'meta' => array( | |
'title' => $link_title, | |
), | |
); | |
$wp_admin_bar->add_menu( $args ); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment