PluginProbe ʕ •ᴥ•ʔ
Shortcodes and extra features for Phlox theme / 2.17.21
Shortcodes and extra features for Phlox theme v2.17.21
2.17.21 2.17.20 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.6 1.0.9 1.1.0 1.3.0 1.3.1 1.3.10 1.3.14 1.3.2 1.3.3 1.3.6 1.4.0 1.4.1 1.4.2 1.5.0 1.5.2 1.6.0 1.6.2 1.6.4 1.7.0 1.7.2 2.10.0 2.10.1 2.10.3 2.10.5 2.10.7 2.10.8 2.10.9 2.11.0 2.11.1 2.11.2 2.12.0 2.14.0 2.15.0 2.15.2 2.15.4 2.15.5 2.15.6 2.15.7 2.15.8 2.15.9 2.16.0 2.16.1 2.16.2 2.16.3 2.16.4 2.17.0 2.17.1 2.17.12 2.17.13 2.17.14 2.17.15 2.17.16 2.17.2 2.17.3 2.17.4 2.17.5 2.17.6 2.17.8 2.17.9 2.4.12 2.4.13 2.4.14 2.4.16 2.4.18 2.4.19 2.4.9 2.5.0 2.5.1 2.5.10 2.5.11 2.5.12 2.5.13 2.5.14 2.5.15 2.5.16 2.5.17 2.5.19 2.5.2 2.5.20 2.5.3 2.5.7 2.5.8 2.5.9 2.6.0 2.6.1 2.6.10 2.6.12 2.6.13 2.6.14 2.6.15 2.6.16 2.6.17 2.6.19 2.6.2 2.6.20 2.6.4 2.6.5 2.6.7 2.7.0 2.7.1 2.7.10 2.7.11 2.7.12 2.7.13 2.7.14 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 2.7.8 2.7.9 2.8.0 2.8.1 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 2.8.7 2.8.9 2.9.0 2.9.12 2.9.14 2.9.15 2.9.16 2.9.17 2.9.18 2.9.19 2.9.2 2.9.20 2.9.21 2.9.22 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 2.9.8
auxin-elements / includes / classes / class-auxin-page-template.php
auxin-elements / includes / classes Last commit date
class-auxels-admin-assets.php 5 months ago class-auxels-archive-menu-links.php 5 months ago class-auxels-envato-elements.php 5 months ago class-auxels-import-parser.php 3 years ago class-auxels-import.php 3 years ago class-auxels-search-post-type.php 5 months ago class-auxels-wc-attribute-nav-menu.php 5 months ago class-auxin-admin-dashboard.php 5 months ago class-auxin-demo-importer.php 2 days ago class-auxin-dependency-sorting.php 3 years ago class-auxin-import.php 5 months ago class-auxin-install.php 5 months ago class-auxin-master-nav-menu-admin.php 5 months ago class-auxin-page-template.php 5 months ago class-auxin-permalink.php 5 months ago class-auxin-plugin-requirements.php 3 years ago class-auxin-post-type-base.php 5 months ago class-auxin-svg-support-allowedattributes.php 7 years ago class-auxin-svg-support-allowedtags.php 7 years ago class-auxin-svg-support.php 1 year ago class-auxin-walker-nav-menu-back.php 5 months ago class-auxin-welcome-sections.php 1 year ago class-auxin-welcome.php 1 month ago class-auxin-whitelabel.php 3 years ago class-auxin-widget-indie.php 5 months ago class-auxin-widget-shortcode-map.php 5 months ago class-auxin-widget.php 5 months ago
class-auxin-page-template.php
214 lines
1 <?php
2 /**
3 * Custom Page Templates for Plugins
4 *
5 *
6 * @package Auxin
7 * @license LICENSE.txt
8 * @author averta
9 * @link http://phlox.pro/
10 * @copyright (c) 2010-2026 averta
11 */
12 class Auxin_Page_Template {
13
14 /**
15 * The array of templates that this plugin tracks.
16 *
17 * @var array
18 */
19 private $templates = array();
20
21 /**
22 * The array of template directories that are required to be tracked.
23 *
24 * @var array
25 */
26 private $template_directories = array();
27
28 /**
29 * Instance of this class.
30 *
31 * @var object
32 */
33 protected static $instance = null;
34
35
36 /**
37 * Return an instance of this class.
38 *
39 * @return object A single instance of this class.
40 */
41 public static function get_instance() {
42
43 // If the single instance hasn't been set, set it now.
44 if ( null == self::$instance ) {
45 self::$instance = new self;
46 }
47
48 return self::$instance;
49 }
50
51 /**
52 * Initializes the plugin by setting filters and administration functions.
53 */
54 private function __construct() {
55
56 // Add a filter to the save post to inject out template into the page cache
57 add_filter( 'wp_insert_post_data', array( $this, 'register_templates' ) );
58
59 // Add a filter to the template include to determine if the page has our
60 add_filter( 'template_include', array( $this, 'include_template') );
61
62 // Add a filter to the attributes metabox to inject template into the dropdown.
63 add_filter( "theme_page_templates", array( $this, 'add_page_templates' ), 10, 3 );
64 }
65
66 /**
67 * Add the auxin page templates to the theme templates.
68 */
69 public function add_page_templates( $page_templates, $wp_theme, $post ) {
70 // Make sure the templates ($this->templates) are collected.
71 if( ! $this->get_templates() ){
72 return $page_templates;
73 }
74
75 return $page_templates + $this->templates;
76 }
77
78 /**
79 * Collect and retrieve the page templates
80 *
81 * @return array
82 */
83 private function get_templates(){
84
85 // Return the templates if they were retrieved before.
86 if( ! empty( $this->templates ) ){
87 return $this->templates;
88 }
89
90 /**
91 * $templates An array containing the list of template file names and labels
92 *
93 * @var array
94 * @example array(
95 * 'custom-template-name1.php' => __( 'Custom Template Name1', 'plugin-domain' ),
96 * 'custom-template-name2.php' => __( 'Custom Template Name2', 'plugin-domain' )
97 * );
98 */
99 $this->templates = apply_filters( 'auxin/core_elements/page_templates/file_names', $this->templates );
100
101 return $this->templates;
102 }
103
104 /**
105 * Collect and retrieve the page template directories.
106 *
107 * @return array
108 */
109 private function get_template_directories(){
110
111 // Return the template directories if they were retrieved before.
112 if( ! empty( $this->template_directories ) ){
113 return $this->template_directories;
114 }
115
116 /**
117 * An array containing the list of template directories.
118 *
119 * @var array
120 * @example array(
121 * 'path/to/custom/page/template1',
122 * 'path/to/custom/page/template2'
123 * );
124 */
125 $this->template_directories = apply_filters( 'auxin/core_elements/page_templates/directories', $this->template_directories );
126
127 return $this->template_directories;
128 }
129
130
131 /**
132 * Adds custom template to the pages cache in order to trick WordPress
133 * into thinking the template file exists where it doens't really exist.
134 */
135 public function register_templates( $atts ) {
136
137 // Create the key used for the themes cache
138 $cache_key = 'page_templates-' . md5( get_theme_root() . '/' . get_stylesheet() );
139
140 // If cache list doesn't exist, or it's empty prepare an array
141 $templates = wp_get_theme()->get_page_templates();
142 if ( empty( $templates ) ) {
143 $templates = array();
144 }
145
146 // Make sure the templates ($this->templates) are collected.
147 $this->get_templates();
148
149 // Quit if no custom template is defined.
150 if( empty( $this->templates ) || ! is_array( $this->templates ) ){
151 return $templates;
152 }
153
154 // New cache, therefore remove the old one
155 wp_cache_delete( $cache_key , 'themes');
156
157 // Now add our template to the list of templates by merging our templates
158 $templates = array_merge( $templates, $this->templates );
159
160 // Add the modified cache to allow WordPress to pick it up for listing
161 wp_cache_add( $cache_key, $templates, 'themes', 1800 );
162
163 return $atts;
164 }
165
166 /**
167 * Checks if the template is assigned to the page
168 */
169 public function include_template( $template ) {
170
171 // Return the search template if we're searching (instead of the template for the first result)
172 if ( is_search() ) {
173 return $template;
174 }
175
176 global $post;
177 if ( ! $post ) {
178 return $template;
179 }
180
181 // Make sure the templates ($this->templates) are collected.
182 $this->get_templates();
183
184 // Get the saved template name id
185 $template_file_id = get_post_meta( $post->ID, '_wp_page_template', true );
186
187 // Return default template if we don't have a custom one defined
188 if ( ! isset( $this->templates[ $template_file_id ] ) ) {
189 return $template;
190 }
191
192 // Make sure the template directories ($this->template_directories) are collected.
193 $this->get_template_directories();
194
195 // Quit if no custom template directory is defined.
196 if( empty( $this->template_directories ) || ! is_array( $this->template_directories ) ){
197 return $template;
198 }
199
200 foreach ( $this->template_directories as $directory ) {
201 $template_file = trailingslashit( $directory ) . $template_file_id;
202
203 // Just to be safe, we check if the file exist first
204 if ( file_exists( $template_file ) ) {
205 return $template_file;
206 }
207 }
208
209 // Return template
210 return $template;
211 }
212
213 }
214