Support » Fixing WordPress » Why not work Template Name for Pages in wp 4.9

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator Steven Stern (sterndata)

    (@sterndata)

    Support Volunteer

    Ahir Hemant

    (@hemant-ahir)

    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

    gohelkunjan

    (@gohelkunjan)

    Thank you so much bro…
    🙂

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Why not work Template Name for Pages in wp 4.9’ is closed to new replies.