|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* BetterOptin Metabox |
|
4
|
|
|
* |
|
5
|
|
|
* @package BetterOptin/Metabox |
|
6
|
|
|
* @author ThemeAvenue <[email protected]> |
|
7
|
|
|
* @license GPL-2.0+ |
|
8
|
|
|
* @link http://themeavenue.net |
|
9
|
|
|
* @copyright 2015 ThemeAvenue |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
// If this file is called directly, abort. |
|
13
|
|
|
if ( ! defined( 'WPINC' ) ) { |
|
14
|
|
|
die; |
|
15
|
|
|
} |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Retrieve the popup templates list. |
|
19
|
|
|
* |
|
20
|
|
|
* @since 1.0.0 |
|
21
|
|
|
* @return array List of available templates with the associated screenshot |
|
22
|
|
|
*/ |
|
23
|
|
|
function wpbo_get_templates_list() { |
|
24
|
|
|
|
|
25
|
|
|
/* Set the default templates directory */ |
|
26
|
|
|
$directory = array( |
|
27
|
|
|
'path' => WPBO_PATH . 'templates', |
|
28
|
|
|
'url' => WPBO_URL . 'templates' |
|
29
|
|
|
); |
|
30
|
|
|
|
|
31
|
|
|
/* Allow for extra directories */ |
|
32
|
|
|
$dirs = apply_filters( 'wpbo_templates_dirs', array( $directory ) ); |
|
33
|
|
|
$list = array(); |
|
34
|
|
|
|
|
35
|
|
|
foreach( $dirs as $key => $dir ) { |
|
36
|
|
|
|
|
37
|
|
|
$exceptions = array( '.', '..' ); |
|
38
|
|
|
|
|
39
|
|
|
if( !isset( $_GET['test_template'] ) ) |
|
40
|
|
|
$exceptions[] = 'template-test.php'; |
|
41
|
|
|
|
|
42
|
|
|
/* Get file paths with trailing slashes */ |
|
43
|
|
|
$path = trailingslashit( $dir['path'] ); |
|
44
|
|
|
$url = trailingslashit( $dir['url'] ); |
|
45
|
|
|
|
|
46
|
|
|
/* Scan the content */ |
|
47
|
|
|
$templates = scandir( $path ); |
|
48
|
|
|
|
|
49
|
|
|
foreach( $templates as $key => $template ) { |
|
50
|
|
|
|
|
51
|
|
|
$images = array( 'png', 'jpg', 'jpeg', 'gif' ); // Allowed images types |
|
52
|
|
|
|
|
53
|
|
|
/* Don't process the '.' and '..' */ |
|
54
|
|
|
if( in_array( $template, $exceptions ) ) |
|
55
|
|
|
continue; |
|
56
|
|
|
|
|
57
|
|
|
/* Get file extension */ |
|
58
|
|
|
$ext = pathinfo( $path . $template, PATHINFO_EXTENSION ); |
|
59
|
|
|
|
|
60
|
|
|
/* Only check the php files */ |
|
61
|
|
|
if( 'php' != $ext ) |
|
62
|
|
|
continue; |
|
63
|
|
|
|
|
64
|
|
|
/* Get template base name */ |
|
65
|
|
|
$tpl = str_replace( ".$ext", '', $template ); |
|
66
|
|
|
|
|
67
|
|
|
foreach( $images as $k => $type ) { |
|
68
|
|
|
|
|
69
|
|
|
$imgfile = $tpl . '.' . $type; |
|
70
|
|
|
|
|
71
|
|
|
if( file_exists( $path . $imgfile ) ) { |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* @todo need to get image URL |
|
75
|
|
|
*/ |
|
76
|
|
|
$img = $url . $imgfile; |
|
77
|
|
|
break; |
|
78
|
|
|
|
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/* Add new template to the list */ |
|
84
|
|
|
$list[$tpl] = $img; |
|
|
|
|
|
|
85
|
|
|
|
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
return $list; |
|
90
|
|
|
|
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
add_action( 'plugins_loaded', 'wpbo_save_templates' ); |
|
94
|
|
|
/** |
|
95
|
|
|
* Save Customized Templates. |
|
96
|
|
|
* |
|
97
|
|
|
* @since 1.0.0 |
|
98
|
|
|
*/ |
|
99
|
|
|
function wpbo_save_templates() { |
|
100
|
|
|
|
|
101
|
|
|
if ( ! isset( $_GET['wpbo_popup'] ) || ! isset( $_POST['wpbo_nonce'] ) ) { |
|
102
|
|
|
return; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
$post_id = intval( $_GET['wpbo_popup'] ); |
|
106
|
|
|
|
|
107
|
|
|
if ( 'wpbo-popup' != get_post_type( $post_id ) ) { |
|
108
|
|
|
return; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
if ( ! wp_verify_nonce( $_POST['wpbo_nonce'], 'wpbo_customize_template' ) ) { |
|
112
|
|
|
return; |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
View Code Duplication |
if ( isset( $_POST['taed-outerhtml'] ) ) { |
|
116
|
|
|
update_post_meta( $post_id, '_wpbo_template_editor', htmlentities( $_POST['taed-outerhtml'], ENT_COMPAT | ENT_HTML401, 'UTF-8' ) ); |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
View Code Duplication |
if ( isset( $_POST['taed-outerhtmlclean'] ) ) { |
|
120
|
|
|
update_post_meta( $post_id, '_wpbo_template_display', htmlentities( $_POST['taed-outerhtmlclean'], ENT_COMPAT | ENT_HTML401, 'UTF-8' ) ); |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
/* Read-only redirect */ |
|
124
|
|
|
wp_redirect( add_query_arg( array( 'post_type' => 'wpbo-popup', |
|
125
|
|
|
'page' => 'wpbo-customizer', |
|
126
|
|
|
'wpbo_popup' => $post_id, |
|
127
|
|
|
'message' => 'updated' |
|
128
|
|
|
), admin_url( 'edit.php' ) ) ); |
|
129
|
|
|
|
|
130
|
|
|
exit; |
|
131
|
|
|
|
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
|
|
135
|
|
|
add_action( 'init', 'wpbo_reset_template' ); |
|
136
|
|
|
/** |
|
137
|
|
|
* Reset to default template. |
|
138
|
|
|
* |
|
139
|
|
|
* Deletes all customizations from database which |
|
140
|
|
|
* will result in using the default template file. |
|
141
|
|
|
* |
|
142
|
|
|
* @since 1.0.0 |
|
143
|
|
|
*/ |
|
144
|
|
|
function wpbo_reset_template() { |
|
145
|
|
|
|
|
146
|
|
|
if ( isset( $_GET['wpbo_reset'] ) && isset( $_GET['wpbo_popup'] ) && wp_verify_nonce( $_GET['wpbo_reset'], 'reset_template' ) ) { |
|
147
|
|
|
|
|
148
|
|
|
delete_post_meta( $_GET['wpbo_popup'], '_wpbo_template_editor' ); |
|
149
|
|
|
delete_post_meta( $_GET['wpbo_popup'], '_wpbo_template_display' ); |
|
150
|
|
|
|
|
151
|
|
|
wp_redirect( add_query_arg( array( |
|
152
|
|
|
'wpbo_popup' => $_GET['wpbo_popup'], |
|
153
|
|
|
'post_type' => 'wpbo-popup', |
|
154
|
|
|
'page' => 'wpbo-customizer' |
|
155
|
|
|
), admin_url( 'edit.php' ) ) ); |
|
156
|
|
|
|
|
157
|
|
|
exit; |
|
158
|
|
|
|
|
159
|
|
|
} |
|
160
|
|
|
|
|
161
|
|
|
} |
If you define a variable conditionally, it can happen that it is not defined for all execution paths.
Let’s take a look at an example:
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.
Available Fixes
Check for existence of the variable explicitly:
Define a default value for the variable:
Add a value for the missing path: