Web Hosting
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

WordPress fix Reply To: Why not work Template Name for Pages in wp 4.9

Discussion in 'Misc WordPress Requests' started by Ahir Hemant, Nov 17, 2017.

  1. Ahir Hemant

    Guest

    Reply To: Why not work Template Name for Pages in wp 4.9, by Ahir Hemant

    Hi
    here is small patch: Add below code in your theme’s function.php
    then clear cache from top:Clear File Cache(Option showing at top of admin bar)

    if( ! defined( 'ABSPATH' ) ) exit;
    if( !class_exists( 'bs_clear_template' ) ) {
    class bs_clear_template {
    function __construct() {
    add_action( 'admin_init', array( $this, 'plugin_setup' ), 10 );
    }

    function plugin_setup() {
    add_action( 'admin_bar_menu', array($this, 'add_cache_button'), 999 );
    add_action( 'admin_footer', array($this, 'output_button_script') );
    add_action( 'wp_ajax_bs_bust_file_cache', array( $this, 'handle_cache_bust' ) );
    }

    function handle_cache_bust() {
    check_ajax_referer( 'handle_cache_bust', 'nonce' );

    global $wpdb;
    $wpdb->query( "DELETE FROM <code>$wpdb->options</code> WHERE <code>option_name</code> LIKE '_transient_files_%' LIMIT 1" );

    wp_die();
    }

    function output_button_script() {
    echo '
    <script>
    jQuery(function($) {
    $("#wp-admin-bar-bust_file_cache>a").on("click", function(e) {
    e.preventDefault();

    $(this).text("Please wait...");
    $.post(ajaxurl, {"action": "bs_bust_file_cache", "nonce": $(this).attr("href").replace("#", "")}, function() {
    window.location.reload();
    });
    });
    });
    </script>';
    }

    function add_cache_button( $wp_admin_bar ) {
    if( is_admin() ) {
    $nonce = wp_create_nonce( 'handle_cache_bust' );
    $wp_admin_bar->add_node( array(
    'id' => 'bust_file_cache',
    'title' => 'Clear File Cache',
    'href' => '#' . $nonce,
    ) );
    }
    }
    }

    new bs_clear_template();
    }

    Please note this is just patch for now.
    Thanks
    Ahir

    Reply To: Why not work Template Name for Pages in wp 4.9
     
    #1

Share This Page

Web Hosting