1 | <?php |
---|
2 | /** |
---|
3 | * Plugin Name: Code Tester |
---|
4 | * Plugin URI: https://wpsmith.net |
---|
5 | * Description: This contains all your site's core functionality so that it is theme independent. |
---|
6 | * Version: 0.1.1 |
---|
7 | * Author: Travis Smith |
---|
8 | * Author URI: http://wpsmith.net |
---|
9 | * |
---|
10 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU |
---|
11 | * General Public License version 2, as published by the Free Software Foundation. You may NOT assume |
---|
12 | * that you can use any other version of the GPL. |
---|
13 | * |
---|
14 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without |
---|
15 | * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
---|
16 | * |
---|
17 | */ |
---|
18 | |
---|
19 | define( 'WPS_DIR', dirname( __FILE__ ) ); |
---|
20 | |
---|
21 | add_filter( 'page_templates', 'wps_page_templates' ); |
---|
22 | /** |
---|
23 | * Filter Templates |
---|
24 | * Validation/Sanitization of templates would be required by function. |
---|
25 | * |
---|
26 | * @param array $templates Array of templates. |
---|
27 | * @return array $templates Modified Array of templates. |
---|
28 | */ |
---|
29 | function wps_page_templates( $templates ) { |
---|
30 | $templates['test.php'] = 'Test'; |
---|
31 | |
---|
32 | return $templates; |
---|
33 | } |
---|
34 | |
---|
35 | add_action( 'template_include', 'wps_template_include' ); //template_include |
---|
36 | /** |
---|
37 | * Template Page Inclusion/Redirect |
---|
38 | * |
---|
39 | * @param string $template Template name. |
---|
40 | * @return string $template Modified template name. |
---|
41 | */ |
---|
42 | function wps_template_include( $template ) { |
---|
43 | |
---|
44 | if ( is_page_template( 'test.php' ) ) |
---|
45 | $new_template = WPS_DIR . '\test.php'; |
---|
46 | |
---|
47 | if ( isset( $new_template ) && wp_template_exists( $new_template ) ) |
---|
48 | return $new_template; |
---|
49 | |
---|
50 | return $template; |
---|
51 | } |
---|
52 | |
---|
53 | /** |
---|
54 | * Determine whether file exists and is a template. |
---|
55 | * |
---|
56 | * @param string $full_path Full path of the file. |
---|
57 | * @return boolean|string False if not a template, Template Name if so. |
---|
58 | */ |
---|
59 | function wp_template_exists( $full_path ) { |
---|
60 | if ( file_exists( $full_path ) ) |
---|
61 | preg_match( '|Template Name:(.*)$|mi', file_get_contents( $full_path ), $header ); |
---|
62 | else |
---|
63 | return false; |
---|
64 | |
---|
65 | return _cleanup_header_comment( $header[1] ); |
---|
66 | } |
---|