Edit File by line
/home/zeestwma/ajeebong.../wp-conte.../plugins/revslide.../includes
File: page-template.class.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* @author ThemePunch <info@themepunch.com>
[2] Fix | Delete
* @link https://www.themepunch.com/
[3] Fix | Delete
* @copyright 2024 ThemePunch
[4] Fix | Delete
*/
[5] Fix | Delete
[6] Fix | Delete
if( !defined( 'ABSPATH') ) exit();
[7] Fix | Delete
[8] Fix | Delete
class RevSliderPageTemplate {
[9] Fix | Delete
[10] Fix | Delete
/**
[11] Fix | Delete
* A reference to an instance of this class.
[12] Fix | Delete
*/
[13] Fix | Delete
private static $instance;
[14] Fix | Delete
[15] Fix | Delete
/**
[16] Fix | Delete
* The array of templates that this plugin tracks.
[17] Fix | Delete
*/
[18] Fix | Delete
protected $templates;
[19] Fix | Delete
[20] Fix | Delete
/**
[21] Fix | Delete
* Returns an instance of this class.
[22] Fix | Delete
*/
[23] Fix | Delete
public static function get_instance(){
[24] Fix | Delete
[25] Fix | Delete
if(null == self::$instance) self::$instance = new RevSliderPageTemplate();
[26] Fix | Delete
[27] Fix | Delete
return self::$instance;
[28] Fix | Delete
}
[29] Fix | Delete
[30] Fix | Delete
/**
[31] Fix | Delete
* Initializes the plugin by setting filters and administration functions.
[32] Fix | Delete
*/
[33] Fix | Delete
private function __construct(){
[34] Fix | Delete
[35] Fix | Delete
$this->templates = array();
[36] Fix | Delete
[37] Fix | Delete
// Add a filter to the attributes metabox to inject template into the cache.
[38] Fix | Delete
add_filter('page_attributes_dropdown_pages_args', array( $this, 'register_project_templates'));
[39] Fix | Delete
[40] Fix | Delete
// Add a filter to the save post to inject out template into the page cache
[41] Fix | Delete
add_filter('wp_insert_post_data', array($this, 'register_project_templates'));
[42] Fix | Delete
[43] Fix | Delete
// Add a filter to the template include to determine if the page has our
[44] Fix | Delete
// template assigned and return it's path
[45] Fix | Delete
add_filter('template_include', array($this, 'view_project_template'));
[46] Fix | Delete
[47] Fix | Delete
// Add your templates to this array.
[48] Fix | Delete
$this->templates = array('../public/views/revslider-page-template.php' => 'Slider Revolution Blank Template');
[49] Fix | Delete
[50] Fix | Delete
// Fix for WP 4.7
[51] Fix | Delete
add_filter('theme_page_templates', array($this, 'register_project_templates_new'));
[52] Fix | Delete
[53] Fix | Delete
// Add filters to the attributes metabox to inject templates to all posts
[54] Fix | Delete
$types = get_post_types([], 'objects');
[55] Fix | Delete
foreach($types as $type => $values){
[56] Fix | Delete
if(isset($type)) add_filter('theme_' . $type . '_templates', array($this, 'add_post_templates'));
[57] Fix | Delete
}
[58] Fix | Delete
}
[59] Fix | Delete
[60] Fix | Delete
[61] Fix | Delete
// Adds our template to the new post templates setting (WP >= 4.7)
[62] Fix | Delete
public function register_project_templates_new($post_templates){
[63] Fix | Delete
return array_merge($post_templates, $this->templates);
[64] Fix | Delete
}
[65] Fix | Delete
[66] Fix | Delete
[67] Fix | Delete
public function add_post_templates($templates){
[68] Fix | Delete
$my_virtual_templates = array('../public/views/revslider-page-template.php' => 'Slider Revolution Blank Template');
[69] Fix | Delete
[70] Fix | Delete
return array_merge($templates, $my_virtual_templates);
[71] Fix | Delete
}
[72] Fix | Delete
[73] Fix | Delete
[74] Fix | Delete
/**
[75] Fix | Delete
* Adds our template to the pages cache in order to trick WordPress
[76] Fix | Delete
* into thinking the template file exists where it doens't really exist.
[77] Fix | Delete
*
[78] Fix | Delete
*/
[79] Fix | Delete
[80] Fix | Delete
public function register_project_templates($atts){
[81] Fix | Delete
[82] Fix | Delete
// Create the key used for the themes cache
[83] Fix | Delete
$cache_key = 'page_templates-' . md5(get_theme_root() . '/' . get_stylesheet());
[84] Fix | Delete
[85] Fix | Delete
// Retrieve the cache list.
[86] Fix | Delete
// If it doesn't exist, or it's empty prepare an array
[87] Fix | Delete
$templates = wp_get_theme()->get_page_templates();
[88] Fix | Delete
[89] Fix | Delete
if(empty($templates)) $templates = array();
[90] Fix | Delete
[91] Fix | Delete
// New cache, therefore remove the old one
[92] Fix | Delete
wp_cache_delete($cache_key , 'themes');
[93] Fix | Delete
[94] Fix | Delete
// Now add our template to the list of templates by merging our templates
[95] Fix | Delete
// with the existing templates array from the cache.
[96] Fix | Delete
$templates = array_merge($templates, $this->templates);
[97] Fix | Delete
[98] Fix | Delete
// Add the modified cache to allow WordPress to pick it up for listing
[99] Fix | Delete
// available templates
[100] Fix | Delete
wp_cache_add($cache_key, $templates, 'themes', 1800);
[101] Fix | Delete
[102] Fix | Delete
return $atts;
[103] Fix | Delete
}
[104] Fix | Delete
[105] Fix | Delete
/**
[106] Fix | Delete
* Checks if the template is assigned to the page
[107] Fix | Delete
*/
[108] Fix | Delete
public function view_project_template($template){
[109] Fix | Delete
[110] Fix | Delete
if(is_search()) return $template; //fix for search issue (B-5798177839)
[111] Fix | Delete
[112] Fix | Delete
global $post;
[113] Fix | Delete
[114] Fix | Delete
if(!isset($post->ID)) return $template;
[115] Fix | Delete
[116] Fix | Delete
if(!isset($this->templates[get_post_meta(
[117] Fix | Delete
$post->ID, '_wp_page_template', true
[118] Fix | Delete
)])){
[119] Fix | Delete
return $template;
[120] Fix | Delete
}
[121] Fix | Delete
[122] Fix | Delete
$file = plugin_dir_path(__FILE__). get_post_meta($post->ID, '_wp_page_template', true);
[123] Fix | Delete
[124] Fix | Delete
// Just to be safe, we check if the file exist first
[125] Fix | Delete
if(file_exists($file)){
[126] Fix | Delete
return $file;
[127] Fix | Delete
}else{
[128] Fix | Delete
echo $file;
[129] Fix | Delete
}
[130] Fix | Delete
[131] Fix | Delete
return $template;
[132] Fix | Delete
}
[133] Fix | Delete
}
[134] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function