PluginProbe
Virtue/Ascend/Pinnacle Toolkit / 4.9.12.2
Virtue/Ascend/Pinnacle Toolkit v4.9.12.2
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 4.9.12.2, at pagetemplater.php

209 lines 7.5 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 add_filter('theme_page_templates', array( $this, 'register_project_templates_update') );
28
29 // Initialize template keys without translation (translation happens lazily)
30 $this->templates = array(
31 'template-contact.php' => 'Contact',
32 );
33
34 }
35
36 public function register_project_templates( $atts ) {
37
38 // Create the key used for the themes cache
39 $cache_key = 'page_templates-' . md5( get_theme_root() . '/' . get_stylesheet() );
40
41 $templates = wp_get_theme()->get_page_templates();
42
43 if ( empty( $templates ) ) {
44 $templates = array();
45 }
46 // New cache, therefore remove the old one
47 wp_cache_delete( $cache_key , 'themes');
48
49 // Now add our template to the list of templates by merging our templates
50 // with the existing templates array from the cache.
51 $templates = array_merge( $templates, $this->templates );
52
53 // Add the modified cache to allow WordPress to pick it up for listing
54 // available templates
55 wp_cache_add( $cache_key, $templates, 'themes', 1800 );
56
57 return $atts;
58
59 }
60 public function register_project_templates_update($templates ) {
61 if ( ! version_compare( $GLOBALS['wp_version'], '4.7', '<' ) ) {
62 // Translate template names when they're actually needed (after init)
63 $translated_templates = array();
64 foreach ( $this->templates as $key => $label ) {
65 $translated_templates[ $key ] = __( $label, 'virtue-toolkit' );
66 }
67 $templates = array_merge( $templates, $translated_templates );
68
69 }
70 return $templates;
71
72 }
73 /**
74 * Checks if the template is assigned to the page
75 */
76 public function view_project_template( $template ) {
77
78 global $post;
79
80 if ( !isset( $post ) ) return $template;
81
82 if (!isset($this->templates[get_post_meta( $post->ID, '_wp_page_template', true )] ) ) {
83
84 return $template;
85
86 }
87
88 $file = plugin_dir_path(__FILE__). get_post_meta( $post->ID, '_wp_page_template', true );
89
90 // Just to be safe, we check if the file exist first
91 if( file_exists( $file ) ) {
92 return $file;
93 } else {
94 echo $file;
95 }
96
97 return $template;
98
99 }
100
101 }
102 $the_theme = wp_get_theme();
103 if( ($the_theme->get( 'Name' ) == 'Pinnacle' && $the_theme->get( 'Version') >= '1.0.6' ) || ($the_theme->get( 'Template') == 'pinnacle') ) {
104 add_action( 'plugins_loaded', array( 'Kadence_Page_Templater_Pinnacle', 'get_instance' ) );
105 }
106 class Kadence_Page_Templater_Virtue {
107
108
109 protected $plugin_slug;
110 private static $instance;
111 protected $templates;
112
113 public static function get_instance() {
114
115 if( null == self::$instance ) {
116 self::$instance = new Kadence_Page_Templater_Virtue();
117 }
118 return self::$instance;
119 }
120 private function __construct() {
121
122 $this->templates = array();
123
124 add_filter('wp_dropdown_pages', array( $this, 'register_project_templates' ) );
125
126 add_filter('wp_insert_post_data', array( $this, 'register_project_templates' ) );
127
128 add_filter('template_include', array( $this, 'view_project_template') );
129
130 add_filter('theme_page_templates', array( $this, 'register_project_templates_update') );
131
132 // Initialize template keys without translation (translation happens lazily)
133 $this->templates = array(
134 'page-contact.php' => 'Contact',
135 );
136
137 }
138
139 public function register_project_templates( $atts ) {
140
141 // Create the key used for the themes cache
142 $cache_key = 'page_templates-' . md5( get_theme_root() . '/' . get_stylesheet() );
143
144 $templates = wp_get_theme()->get_page_templates();
145
146 if ( empty( $templates ) ) {
147 $templates = array();
148 }
149 // New cache, therefore remove the old one
150 wp_cache_delete( $cache_key , 'themes');
151
152 // Now add our template to the list of templates by merging our templates
153 // with the existing templates array from the cache.
154 $templates = array_merge( $templates, $this->templates );
155
156 // Add the modified cache to allow WordPress to pick it up for listing
157 // available templates
158 wp_cache_add( $cache_key, $templates, 'themes', 1800 );
159
160 return $atts;
161
162 }
163 public function register_project_templates_update($templates ) {
164 if ( ! version_compare( $GLOBALS['wp_version'], '4.7', '<' ) ) {
165 // Translate template names when they're actually needed (after init)
166 $translated_templates = array();
167 foreach ( $this->templates as $key => $label ) {
168 $translated_templates[ $key ] = __( $label, 'virtue-toolkit' );
169 }
170 $templates = array_merge( $templates, $translated_templates );
171
172 }
173 return $templates;
174
175 }
176
177 /**
178 * Checks if the template is assigned to the page
179 */
180 public function view_project_template( $template ) {
181
182 global $post;
183
184 if ( !isset( $post ) ) return $template;
185
186 if (!isset($this->templates[get_post_meta( $post->ID, '_wp_page_template', true )] ) ) {
187
188 return $template;
189
190 }
191
192 $file = plugin_dir_path(__FILE__). get_post_meta( $post->ID, '_wp_page_template', true );
193
194 // Just to be safe, we check if the file exist first
195 if( file_exists( $file ) ) {
196 return $file;
197 } else {
198 echo $file;
199 }
200
201 return $template;
202
203 }
204
205 }
206 $the_theme = wp_get_theme();
207 if( ($the_theme->get( 'Name' ) == 'Virtue' && $the_theme->get( 'Version') >= '2.3.5') || ($the_theme->get( 'Template') == 'virtue') ) {
208 add_action( 'plugins_loaded', array( 'Kadence_Page_Templater_Virtue', 'get_instance' ) );
209 }