Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "Purge Minit Cache" button to the admin bar #66

Open
sidati opened this issue Mar 10, 2016 · 7 comments
Open

Add "Purge Minit Cache" button to the admin bar #66

sidati opened this issue Mar 10, 2016 · 7 comments

Comments

@sidati
Copy link

sidati commented Mar 10, 2016

Hi @kasparsd,

Why not add a Purge Button in the admin bar ??

purge-minit

    add_action('admin_bar_menu', function(){

        global $wp_admin_bar;

        $wp_admin_bar->add_node(array(
            'id' => 'minit_purge_button',
            'title' => __('Purge Minit', 'minit'),
            'parent' => false,
            'href' => add_query_arg(array(
                    'purge_minit' => true,
                    '_wpnonce' => wp_create_nonce('purge_minit')
                ), admin_url()),
            'group' => false,
            'meta' => array()
        ));

    }, 999);
@kasparsd kasparsd changed the title Why not Purge Minit button ? Add "Purge Minit Cache" button to the admin bar Mar 10, 2016
@kasparsd
Copy link
Owner

@sidati That is an excellent idea. Thank you posting the code sample.

@sidati
Copy link
Author

sidati commented Mar 12, 2016

@kasparsd Glad you like it,
By the way, if you have minutes, take a look to my pull request concerning the @import css functions
https://github.com/sidati/minit/commit/3f0f618746f3a172b53582f24405977e8517a229

@ahansson89
Copy link

I like this! I dont think we should register it with an anonymous function though. It makes it hard to remove it for those who does not want it.

@sidati
Copy link
Author

sidati commented Mar 18, 2016

@kasparsd @ahansson89
why not adding some settings array with a filter like in JS plugins, so devs can enable or disable any core feature; something like :

    $settings = apply_filters('minit_settings', array(
        'admin_bar_button' => true,
        'move_css_import_to_top' => true,
        'comments_in_combined_file' => true,
        'minify_css' => false
        'exlude_externals' => false
    ));

@ahansson89
Copy link

I like this idea a lot!

@ahansson89
Copy link

That said, I think stuff like this could go in a different plugin like this: https://github.com/markoheijnen/Minit-Pro

@szepeviktor
Copy link
Contributor

szepeviktor commented Sep 9, 2016

<?php
/*
Plugin Name: Fluch cache button
Version: 0.1.0
Description: Add an admin bar button to flush the object cache.
Author: Viktor Szépe
Plugin URI: https://github.com/szepeviktor/wordpress-plugin-construction
GitHub Plugin URI: https://github.com/szepeviktor/wordpress-plugin-construction
*/

if ( function_exists( 'wp_cache_flush' ) ) {
    add_action( 'admin_bar_menu', 'o1_flush_cache_button', 100 );
}

function o1_flush_cache_button( $wp_admin_bar ) {

    if ( ! current_user_can( 'manage_options' ) ) {
        return;
    }

    if ( 'flush' === $_GET['flush-cache-button']
        && wp_verify_nonce( $_GET['_wpnonce'], 'flush-cache-button' )
    ) {
        wp_cache_flush();
        add_action( 'admin_notices', function () {
            echo '<div class="notice notice-success is-dismissible"><p>Object Cache flushed.</p></div>';
        } );
    }

    $dashboard_url = admin_url( add_query_arg( 'flush-cache-button', 'flush', 'index.php' ) );
    $args = array(
        'id'    => 'flush_cache_button',
        'title' => 'Flush Object Cache',
        'href'  => wp_nonce_url( $dashboard_url, 'flush-cache-button' ),
        'meta'  => array( 'class' => 'flush-cache-button' )
    );
    $wp_admin_bar->add_node( $args );
}

https://github.com/szepeviktor/wordpress-plugin-construction/blob/master/mu-cache-flush-button/flush-cache-button.php

You only need to chage wp_cache_flush(); and rephrase messages.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants