PluginProbe
Virtue/Ascend/Pinnacle Toolkit / 2.4
Virtue/Ascend/Pinnacle Toolkit v2.4
4.9.12.2 trunk 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 3.0 3.1 3.2 3.3 3.4 3.7 All 48 releases
virtue-toolkit / pagetemplater.php

pagetemplater.php in Virtue/Ascend/Pinnacle Toolkit 2.4, at pagetemplater.php

175 lines 5.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 class Kadence_Page_Templater_Pinnacle {
4
5
6 protected $plugin_slug;
7 private static $instance;
8 protected $templates;
9
10 public static function get_instance() {
11
12 if( null == self::$instance ) {
13 self::$instance = new Kadence_Page_Templater_Pinnacle();
14 }
15 return self::$instance;
16 }
17 private function __construct() {
18
19 $this->templates = array();
20
21 add_filter('page_attributes_dropdown_pages_args', array( $this, 'register_project_templates' ) );
22
23 add_filter('wp_insert_post_data', array( $this, 'register_project_templates' ) );
24
25 add_filter('template_include', array( $this, 'view_project_template') );
26
27 $this->templates = array(
28 'template-contact.php' => __('Contact', 'kadencetoolkit'),
29 );
30
31 }
32
33 public function register_project_templates( $atts ) {
34
35 // Create the key used for the themes cache
36 $cache_key = 'page_templates-' . md5( get_theme_root() . '/' . get_stylesheet() );
37
38 $templates = wp_get_theme()->get_page_templates();
39
40 if ( empty( $templates ) ) {
41 $templates = array();
42 }
43 // New cache, therefore remove the old one
44 wp_cache_delete( $cache_key , 'themes');
45
46 // Now add our template to the list of templates by merging our templates
47 // with the existing templates array from the cache.
48 $templates = array_merge( $templates, $this->templates );
49
50 // Add the modified cache to allow WordPress to pick it up for listing
51 // available templates
52 wp_cache_add( $cache_key, $templates, 'themes', 1800 );
53
54 return $atts;
55
56 }
57
58 /**
59 * Checks if the template is assigned to the page
60 */
61 public function view_project_template( $template ) {
62
63 global $post;
64
65 if (!isset($this->templates[get_post_meta( $post->ID, '_wp_page_template', true )] ) ) {
66
67 return $template;
68
69 }
70
71 $file = plugin_dir_path(__FILE__). get_post_meta( $post->ID, '_wp_page_template', true );
72
73 // Just to be safe, we check if the file exist first
74 if( file_exists( $file ) ) {
75 return $file;
76 } else {
77 echo $file;
78 }
79
80 return $template;
81
82 }
83
84 }
85 $the_theme = wp_get_theme();
86 if( ($the_theme->get( 'Name' ) == 'Pinnacle' || $the_theme->get( 'Template') == 'pinnacle') && ( $the_theme->get( 'Version') >= '1.0.6' ) ) {
87 add_action( 'plugins_loaded', array( 'Kadence_Page_Templater_Pinnacle', 'get_instance' ) );
88 }
89 class Kadence_Page_Templater_Virtue {
90
91
92 protected $plugin_slug;
93 private static $instance;
94 protected $templates;
95
96 public static function get_instance() {
97
98 if( null == self::$instance ) {
99 self::$instance = new Kadence_Page_Templater_Virtue();
100 }
101 return self::$instance;
102 }
103 private function __construct() {
104
105 $this->templates = array();
106
107 add_filter('page_attributes_dropdown_pages_args', array( $this, 'register_project_templates' ) );
108
109 add_filter('wp_insert_post_data', array( $this, 'register_project_templates' ) );
110
111 add_filter('template_include', array( $this, 'view_project_template') );
112
113 $this->templates = array(
114 'page-contact.php' => __('Contact', 'kadencetoolkit'),
115 );
116
117 }
118
119 public function register_project_templates( $atts ) {
120
121 // Create the key used for the themes cache
122 $cache_key = 'page_templates-' . md5( get_theme_root() . '/' . get_stylesheet() );
123
124 $templates = wp_get_theme()->get_page_templates();
125
126 if ( empty( $templates ) ) {
127 $templates = array();
128 }
129 // New cache, therefore remove the old one
130 wp_cache_delete( $cache_key , 'themes');
131
132 // Now add our template to the list of templates by merging our templates
133 // with the existing templates array from the cache.
134 $templates = array_merge( $templates, $this->templates );
135
136 // Add the modified cache to allow WordPress to pick it up for listing
137 // available templates
138 wp_cache_add( $cache_key, $templates, 'themes', 1800 );
139
140 return $atts;
141
142 }
143
144 /**
145 * Checks if the template is assigned to the page
146 */
147 public function view_project_template( $template ) {
148
149 global $post;
150
151 if (!isset($this->templates[get_post_meta( $post->ID, '_wp_page_template', true )] ) ) {
152
153 return $template;
154
155 }
156
157 $file = plugin_dir_path(__FILE__). get_post_meta( $post->ID, '_wp_page_template', true );
158
159 // Just to be safe, we check if the file exist first
160 if( file_exists( $file ) ) {
161 return $file;
162 } else {
163 echo $file;
164 }
165
166 return $template;
167
168 }
169
170 }
171 $the_theme = wp_get_theme();
172 if( ($the_theme->get( 'Name' ) == 'Virtue' || $the_theme->get( 'Template') == 'virtue') && ( $the_theme->get( 'Version') >= '2.3.5' ) ) {
173 add_action( 'plugins_loaded', array( 'Kadence_Page_Templater_Virtue', 'get_instance' ) );
174 }
175