Version Description
- Enhancement: All the code is now compliant with the full-fat VIP coding standards. It was no mean feat but, as a result, the plugin is more secure than ever before
- Enhancement: The default is to now use double braces around your embed name, which is kind-of the universal default for template tags such as this. If you're an existing user, your current configuration won't change, though - this only affects new users
- Enhancement: Improved translation output, including where I'd accidentally added an extra character to the text domain
- Enhancement: Using the
checked
function on fields, rather than the form parameter - Enhancement: Added a useful links sidebar to the Help for both screens
- Maintenance: Throughout, use Yoda conditions I now do
- Maintenance: Added links to the sparkly new Github repo
- Bug: When updating the options you sometimes didn't get a confirmation message. You do now!
- Bug: Fixed a weird one where I was referencing a variable that I was never using _()_/
Download this release
Release Info
Developer | dartiss |
Plugin | Code Embed |
Version | 2.3 |
Comparing to | |
See all releases |
Code changes from version 2.2.2 to 2.3
- css/video-container UNCOMPRESSED.css +0 -16
- css/video-container.css +16 -1
- css/video-container.min.css +1 -0
- includes/add-embeds.php +327 -317
- includes/add-scripts.php +26 -27
- includes/admin-config.php +244 -198
- includes/initialise.php +58 -57
- includes/options-screen.php +130 -97
- includes/search-screen.php +94 -93
- readme.txt +37 -16
- simple-code-embed.php +39 -40
- uninstall.php +19 -20
css/video-container UNCOMPRESSED.css
DELETED
@@ -1,16 +0,0 @@
|
|
1 |
-
.ce-video-container {
|
2 |
-
position: relative;
|
3 |
-
padding-bottom: 56.25%;
|
4 |
-
height: 0;
|
5 |
-
overflow: hidden;
|
6 |
-
}
|
7 |
-
|
8 |
-
.ce-video-container iframe,
|
9 |
-
.ce-video-container object,
|
10 |
-
.ce-video-container embed {
|
11 |
-
position: absolute;
|
12 |
-
top: 0;
|
13 |
-
left: 0;
|
14 |
-
width: 100%;
|
15 |
-
height: 100%;
|
16 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
css/video-container.css
CHANGED
@@ -1 +1,16 @@
|
|
1 |
-
.ce-video-container
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
.ce-video-container {
|
2 |
+
position: relative;
|
3 |
+
padding-bottom: 56.25%;
|
4 |
+
height: 0;
|
5 |
+
overflow: hidden;
|
6 |
+
}
|
7 |
+
|
8 |
+
.ce-video-container iframe,
|
9 |
+
.ce-video-container object,
|
10 |
+
.ce-video-container embed {
|
11 |
+
position: absolute;
|
12 |
+
top: 0;
|
13 |
+
left: 0;
|
14 |
+
width: 100%;
|
15 |
+
height: 100%;
|
16 |
+
}
|
css/video-container.min.css
ADDED
@@ -0,0 +1 @@
|
|
|
1 |
+
.ce-video-container{position:relative;padding-bottom:56.25%;height:0;overflow:hidden;}.ce-video-container iframe,.ce-video-container object,.ce-video-container embed{position:absolute;top:0;left:0;width:100%;height:100%;}
|
includes/add-embeds.php
CHANGED
@@ -1,317 +1,327 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* Add Embed to Posts
|
4 |
-
*
|
5 |
-
* Functions to add embed code to posts
|
6 |
-
*
|
7 |
-
* @package
|
8 |
-
*/
|
9 |
-
|
10 |
-
/**
|
11 |
-
* Add filter to add embed code
|
12 |
-
*
|
13 |
-
* Filter to add embed to any posts
|
14 |
-
*
|
15 |
-
* @since
|
16 |
-
*
|
17 |
-
* @uses
|
18 |
-
*
|
19 |
-
* @param
|
20 |
-
* @return
|
21 |
-
*/
|
22 |
-
|
23 |
-
function ce_filter( $content ) {
|
24 |
-
|
25 |
-
global $post;
|
26 |
-
|
27 |
-
// Set initial values
|
28 |
-
|
29 |
-
$options
|
30 |
-
$found_pos
|
31 |
-
$prefix_len = strlen( $options[
|
32 |
-
|
33 |
-
// Loop around the post content looking for all requests for code embeds
|
34 |
-
|
35 |
-
while (
|
36 |
-
|
37 |
-
// Get the position of the closing identifier - ignore if one is not found
|
38 |
-
|
39 |
-
$end_pos = strpos( $content, $options[
|
40 |
-
if (
|
41 |
-
|
42 |
-
// Extract the suffix
|
43 |
-
|
44 |
-
$suffix_len = $end_pos - ( $found_pos + $prefix_len );
|
45 |
-
if ( $suffix_len
|
46 |
-
$suffix = '';
|
47 |
-
} else {
|
48 |
-
$suffix = substr( $content, $found_pos + $prefix_len, $suffix_len );
|
49 |
-
}
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
*
|
129 |
-
*
|
130 |
-
*
|
131 |
-
*
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
$
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
$
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
*
|
166 |
-
*
|
167 |
-
*
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
$
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
//
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Add Embed to Posts
|
4 |
+
*
|
5 |
+
* Functions to add embed code to posts
|
6 |
+
*
|
7 |
+
* @package simple-embed-code
|
8 |
+
*/
|
9 |
+
|
10 |
+
/**
|
11 |
+
* Add filter to add embed code
|
12 |
+
*
|
13 |
+
* Filter to add embed to any posts
|
14 |
+
*
|
15 |
+
* @since 1.5
|
16 |
+
*
|
17 |
+
* @uses ce_get_embed_code Get embed code from other posts
|
18 |
+
*
|
19 |
+
* @param string $content Post content without embedded code
|
20 |
+
* @return string Post content with embedded code
|
21 |
+
*/
|
22 |
+
|
23 |
+
function ce_filter( $content ) {
|
24 |
+
|
25 |
+
global $post;
|
26 |
+
|
27 |
+
// Set initial values
|
28 |
+
|
29 |
+
$options = get_option( 'artiss_code_embed' );
|
30 |
+
$found_pos = strpos( $content, $options['opening_ident'] . $options['keyword_ident'], 0 );
|
31 |
+
$prefix_len = strlen( $options['opening_ident'] . $options['keyword_ident'] );
|
32 |
+
|
33 |
+
// Loop around the post content looking for all requests for code embeds
|
34 |
+
|
35 |
+
while ( false !== $found_pos ) {
|
36 |
+
|
37 |
+
// Get the position of the closing identifier - ignore if one is not found
|
38 |
+
|
39 |
+
$end_pos = strpos( $content, $options['closing_ident'], $found_pos + $prefix_len );
|
40 |
+
if ( false !== $end_pos ) {
|
41 |
+
|
42 |
+
// Extract the suffix
|
43 |
+
|
44 |
+
$suffix_len = $end_pos - ( $found_pos + $prefix_len );
|
45 |
+
if ( 0 === $suffix_len ) {
|
46 |
+
$suffix = '';
|
47 |
+
} else {
|
48 |
+
$suffix = substr( $content, $found_pos + $prefix_len, $suffix_len );
|
49 |
+
}
|
50 |
+
$full_suffix = $suffix;
|
51 |
+
|
52 |
+
// Check for responsive part of suffix
|
53 |
+
|
54 |
+
$responsive = false;
|
55 |
+
$max_width = false;
|
56 |
+
$res_pos = false;
|
57 |
+
if ( 1 < strlen( $suffix ) ) {
|
58 |
+
$res_pos = strpos( $suffix, '_RES', 1 );
|
59 |
+
}
|
60 |
+
|
61 |
+
if ( false !== $res_pos ) {
|
62 |
+
|
63 |
+
// If responsive section found, check it's at the end of has an underscore afterwards
|
64 |
+
// Otherwise it may be part of something else
|
65 |
+
|
66 |
+
if ( strlen( $suffix ) - 4 === $res_pos ) {
|
67 |
+
$responsive = true;
|
68 |
+
} else {
|
69 |
+
if ( '_' === substr( $suffix, $res_pos + 4, 1 ) ) {
|
70 |
+
$responsive = true;
|
71 |
+
$max_width = substr( $suffix, $res_pos + 5 );
|
72 |
+
if ( ! is_numeric( $max_width ) ) {
|
73 |
+
$max_width = '';
|
74 |
+
}
|
75 |
+
}
|
76 |
+
}
|
77 |
+
|
78 |
+
if ( $responsive ) {
|
79 |
+
$suffix = substr( $suffix, 0, $res_pos );
|
80 |
+
}
|
81 |
+
}
|
82 |
+
|
83 |
+
// Get the custom field data and replace in the post
|
84 |
+
|
85 |
+
$search = $options['opening_ident'] . $options['keyword_ident'] . $suffix . $options['closing_ident'];
|
86 |
+
|
87 |
+
// Get the meta for the current post
|
88 |
+
|
89 |
+
$post_meta = get_post_meta( $post->ID, $options['keyword_ident'] . $suffix, false );
|
90 |
+
if ( isset( $post_meta[0] ) ) {
|
91 |
+
$html = $post_meta[0];
|
92 |
+
} else {
|
93 |
+
// No meta found, so look for it elsewhere
|
94 |
+
$html = ce_get_embed_code( $options['keyword_ident'], $suffix );
|
95 |
+
}
|
96 |
+
|
97 |
+
// Build the string to search for
|
98 |
+
|
99 |
+
$search = $options['opening_ident'] . $options['keyword_ident'] . $full_suffix . $options['closing_ident'];
|
100 |
+
|
101 |
+
// Build the string of code to replace with
|
102 |
+
|
103 |
+
$replace = ce_generate_code( $html, $responsive, $max_width, $options['debug'] );
|
104 |
+
|
105 |
+
// Now modify all references
|
106 |
+
|
107 |
+
$content = str_replace( $search, $replace, $content );
|
108 |
+
|
109 |
+
}
|
110 |
+
$found_pos = strpos( $content, $options['opening_ident'] . $options['keyword_ident'], $found_pos + 1 );
|
111 |
+
}
|
112 |
+
|
113 |
+
// Loop around the post content looking for HTTP addresses
|
114 |
+
|
115 |
+
$content = ce_quick_replace( $content, $options, 'http://' );
|
116 |
+
|
117 |
+
// Loop around the post content looking for HTTPS addresses
|
118 |
+
|
119 |
+
$content = ce_quick_replace( $content, $options, 'https://' );
|
120 |
+
|
121 |
+
return $content;
|
122 |
+
}
|
123 |
+
|
124 |
+
add_filter( 'the_content', 'ce_filter' );
|
125 |
+
add_filter( 'widget_content', 'ce_filter' );
|
126 |
+
|
127 |
+
/**
|
128 |
+
* Quick Replace
|
129 |
+
*
|
130 |
+
* Function to do a quick search/replace of the content
|
131 |
+
*
|
132 |
+
* @since 2.0
|
133 |
+
*
|
134 |
+
* @param $content string The content
|
135 |
+
* @param $options string The options array
|
136 |
+
* @param $search string The string to search for
|
137 |
+
* @return string The updated content
|
138 |
+
*/
|
139 |
+
|
140 |
+
function ce_quick_replace( $content = '', $options = '', $search = '' ) {
|
141 |
+
|
142 |
+
$start_pos = strpos( $content, $options['opening_ident'] . $search, 0 );
|
143 |
+
$prefix_len = strlen( $options['opening_ident'] );
|
144 |
+
|
145 |
+
while ( false !== $start_pos ) {
|
146 |
+
|
147 |
+
$start_pos = $start_pos + strlen( $options['opening_ident'] );
|
148 |
+
$end_pos = strpos( $content, $options['closing_ident'], $start_pos );
|
149 |
+
|
150 |
+
if ( false !== $end_pos ) {
|
151 |
+
$url = substr( $content, $start_pos, $end_pos - $start_pos );
|
152 |
+
$file = ce_get_file( $url );
|
153 |
+
if ( false !== $file ) {
|
154 |
+
$content = str_replace( $options['opening_ident'] . $url . $options['closing_ident'], $file['file'], $content );
|
155 |
+
} else {
|
156 |
+
ce_report_error( __( 'File could not be fetched', 'simple-embed-code' ), 'Code Embed', false );
|
157 |
+
}
|
158 |
+
}
|
159 |
+
}
|
160 |
+
|
161 |
+
return $content;
|
162 |
+
}
|
163 |
+
|
164 |
+
/**
|
165 |
+
* Generate Embed Code
|
166 |
+
*
|
167 |
+
* Function to generate the embed code that will be output
|
168 |
+
*
|
169 |
+
* @since 2.0
|
170 |
+
*
|
171 |
+
* @param $html string The embed code (required)
|
172 |
+
* @param $responsive string Responsive output required? (optional)
|
173 |
+
* @param $max_width string Maximum width of responsive output (optional)
|
174 |
+
* @param $debug boolean Whether to suppress debug output (1) or not
|
175 |
+
* @return string The embed code
|
176 |
+
*/
|
177 |
+
|
178 |
+
function ce_generate_code( $html, $responsive = '', $max_width = '', $debug = '' ) {
|
179 |
+
|
180 |
+
$code = "\n";
|
181 |
+
if ( 1 !== $debug ) {
|
182 |
+
$code .= '<!-- Code Embed v' . CODE_EMBED_VERSION . " -->\n";
|
183 |
+
}
|
184 |
+
|
185 |
+
if ( false !== $max_width ) {
|
186 |
+
$code .= '<div style="width: ' . $max_width . 'px; max-width: 100%">';
|
187 |
+
}
|
188 |
+
|
189 |
+
if ( $responsive ) {
|
190 |
+
$code .= '<div class="ce-video-container">';
|
191 |
+
}
|
192 |
+
|
193 |
+
$code .= $html;
|
194 |
+
|
195 |
+
if ( $responsive ) {
|
196 |
+
$code .= '</div>';
|
197 |
+
}
|
198 |
+
|
199 |
+
if ( false !== $max_width ) {
|
200 |
+
$code .= '</div>';
|
201 |
+
}
|
202 |
+
|
203 |
+
$code .= "\n";
|
204 |
+
if ( 1 !== $debug ) {
|
205 |
+
$code .= '<!-- ' . __( 'End of Code Embed output', 'simple-embed-code' ) . " -->\n";
|
206 |
+
}
|
207 |
+
|
208 |
+
return $code;
|
209 |
+
}
|
210 |
+
|
211 |
+
/**
|
212 |
+
* Get the Global Embed Code
|
213 |
+
*
|
214 |
+
* Function to look for and, if available, return the global embed code
|
215 |
+
*
|
216 |
+
* @since 1.6
|
217 |
+
*
|
218 |
+
* @uses ce_report_error Generate an error message
|
219 |
+
*
|
220 |
+
* @param $ident string The embed code opening identifier
|
221 |
+
* @param $suffix string The embed code suffix
|
222 |
+
* @return string The embed code (or error)
|
223 |
+
*/
|
224 |
+
|
225 |
+
function ce_get_embed_code( $ident, $suffix ) {
|
226 |
+
|
227 |
+
// Meta was not found in current post so look across meta table - find the number of distinct code results
|
228 |
+
|
229 |
+
$meta_name = $ident . $suffix;
|
230 |
+
global $wpdb;
|
231 |
+
$unique_records = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT meta_value FROM $wpdb->postmeta WHERE meta_key = %s", $meta_name ) ); // @codingStandardsIgnoreLine -- requires the latest data when called, so caching is inappropriate
|
232 |
+
$records = $wpdb->num_rows;
|
233 |
+
|
234 |
+
if ( 0 < $records ) {
|
235 |
+
|
236 |
+
// Results were found
|
237 |
+
|
238 |
+
$meta = $wpdb->get_results( $wpdb->prepare( "SELECT meta_value, post_title, ID FROM $wpdb->postmeta, $wpdb->posts WHERE meta_key = %s AND post_id = ID", $meta_name ) ); // @codingStandardsIgnoreLine -- requires the latest data when called, so caching is inappropriate
|
239 |
+
$total_records = $wpdb->num_rows;
|
240 |
+
|
241 |
+
if ( 1 === $records ) {
|
242 |
+
|
243 |
+
// Only one unique code result returned so assume this is the global embed
|
244 |
+
|
245 |
+
foreach ( $meta as $meta_data ) {
|
246 |
+
$html = $meta_data->meta_value;
|
247 |
+
}
|
248 |
+
} else {
|
249 |
+
|
250 |
+
// More than one unique code result returned, so output the list of posts
|
251 |
+
|
252 |
+
/* translators: %1$s: embed name, %2$d: number of pieces of code being stored with that name, %3$d: number of posts using that embed name */
|
253 |
+
$error = sprintf( __( 'Cannot use %1$s as a global code as it is being used to store %2$d unique pieces of code in %3$d posts', 'simple-embed-code' ), $meta_name, $records, $total_records );
|
254 |
+
$html = ce_report_error( $error, 'Code Embed', false );
|
255 |
+
}
|
256 |
+
} else {
|
257 |
+
|
258 |
+
// No meta code was found so write out an error
|
259 |
+
|
260 |
+
/* translators: %s: the embed name */
|
261 |
+
$html = ce_report_error( sprintf( __( 'No embed code was found for %s', 'simple-embed-code' ), $meta_name ), 'Code Embed', false );
|
262 |
+
|
263 |
+
}
|
264 |
+
return $html;
|
265 |
+
}
|
266 |
+
|
267 |
+
/**
|
268 |
+
* Fetch a file
|
269 |
+
*
|
270 |
+
* Use WordPress API to fetch a file and check results
|
271 |
+
*
|
272 |
+
* @since 2.0
|
273 |
+
*
|
274 |
+
* @param string $filein File name to fetch
|
275 |
+
* @param string $header Only get headers?
|
276 |
+
* @return string Array containing file contents or false to indicate a failure
|
277 |
+
*/
|
278 |
+
|
279 |
+
function ce_get_file( $filein ) {
|
280 |
+
|
281 |
+
if ( function_exists( 'vip_safe_wp_remote_get' ) ) {
|
282 |
+
|
283 |
+
$response = vip_safe_wp_remote_get( $filein, '', 3, 3 );
|
284 |
+
|
285 |
+
} else {
|
286 |
+
|
287 |
+
$response = wp_remote_get( $filein, array( 'timeout' => 3 ) ); // @codingStandardsIgnoreLine -- for non-VIP environments
|
288 |
+
|
289 |
+
}
|
290 |
+
|
291 |
+
if ( is_array( $response ) ) {
|
292 |
+
|
293 |
+
return $response['body'];
|
294 |
+
|
295 |
+
} else {
|
296 |
+
|
297 |
+
return false;
|
298 |
+
|
299 |
+
}
|
300 |
+
}
|
301 |
+
|
302 |
+
/**
|
303 |
+
* Report an error (1.4)
|
304 |
+
*
|
305 |
+
* Function to report an error
|
306 |
+
*
|
307 |
+
* @since 1.6
|
308 |
+
*
|
309 |
+
* @param $error string Error message
|
310 |
+
* @param $plugin_name string The name of the plugin
|
311 |
+
* @param $echo string True or false, depending on whether you wish to return or echo the results
|
312 |
+
* @return string True or the output text
|
313 |
+
*/
|
314 |
+
|
315 |
+
function ce_report_error( $error, $plugin_name, $echo = true ) {
|
316 |
+
|
317 |
+
$output = '<p style="color: #f00; font-weight: bold;">' . $plugin_name . ': ' . $error . "</p>\n";
|
318 |
+
|
319 |
+
if ( $echo ) {
|
320 |
+
echo esc_html( $output );
|
321 |
+
return true;
|
322 |
+
} else {
|
323 |
+
return $output;
|
324 |
+
}
|
325 |
+
|
326 |
+
}
|
327 |
+
|
includes/add-scripts.php
CHANGED
@@ -1,27 +1,26 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* Add Scripts
|
4 |
-
*
|
5 |
-
* Add CSS to the main theme
|
6 |
-
*
|
7 |
-
* @package
|
8 |
-
*/
|
9 |
-
|
10 |
-
/**
|
11 |
-
* Add scripts to theme
|
12 |
-
*
|
13 |
-
* Add styles to the main theme
|
14 |
-
*
|
15 |
-
* @since
|
16 |
-
*/
|
17 |
-
|
18 |
-
function ce_main_scripts() {
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
}
|
25 |
-
|
26 |
-
add_action( 'wp_enqueue_scripts', 'ce_main_scripts' );
|
27 |
-
?>
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Add Scripts
|
4 |
+
*
|
5 |
+
* Add CSS to the main theme
|
6 |
+
*
|
7 |
+
* @package simple-embed-code
|
8 |
+
*/
|
9 |
+
|
10 |
+
/**
|
11 |
+
* Add scripts to theme
|
12 |
+
*
|
13 |
+
* Add styles to the main theme
|
14 |
+
*
|
15 |
+
* @since 2.0
|
16 |
+
*/
|
17 |
+
|
18 |
+
function ce_main_scripts() {
|
19 |
+
|
20 |
+
wp_register_style( 'ce_responsive', plugins_url( 'css/video-container.min.css', dirname( __FILE__ ) ) );
|
21 |
+
|
22 |
+
wp_enqueue_style( 'ce_responsive' );
|
23 |
+
|
24 |
+
}
|
25 |
+
|
26 |
+
add_action( 'wp_enqueue_scripts', 'ce_main_scripts' );
|
|
includes/admin-config.php
CHANGED
@@ -1,198 +1,244 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* Administration Menu Options
|
4 |
-
*
|
5 |
-
* Add various adminstration menu options
|
6 |
-
*
|
7 |
-
* @package
|
8 |
-
*/
|
9 |
-
|
10 |
-
/**
|
11 |
-
* Add Settings link to plugin list
|
12 |
-
*
|
13 |
-
* Add a Settings link to the options listed against this plugin
|
14 |
-
*
|
15 |
-
* @since
|
16 |
-
*
|
17 |
-
* @param
|
18 |
-
* @param
|
19 |
-
* @return string
|
20 |
-
*/
|
21 |
-
|
22 |
-
function ce_add_settings_link( $links, $file ) {
|
23 |
-
|
24 |
-
static $this_plugin;
|
25 |
-
|
26 |
-
if (
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
* Add
|
42 |
-
*
|
43 |
-
*
|
44 |
-
*
|
45 |
-
* @
|
46 |
-
*
|
47 |
-
* @
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
*
|
133 |
-
*
|
134 |
-
*
|
135 |
-
*
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
*
|
161 |
-
*
|
162 |
-
*
|
163 |
-
*
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
*
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Administration Menu Options
|
4 |
+
*
|
5 |
+
* Add various adminstration menu options
|
6 |
+
*
|
7 |
+
* @package simple-embed-code
|
8 |
+
*/
|
9 |
+
|
10 |
+
/**
|
11 |
+
* Add Settings link to plugin list
|
12 |
+
*
|
13 |
+
* Add a Settings link to the options listed against this plugin
|
14 |
+
*
|
15 |
+
* @since 1.6
|
16 |
+
*
|
17 |
+
* @param string $links Current links
|
18 |
+
* @param string $file File in use
|
19 |
+
* @return string Links, now with settings added
|
20 |
+
*/
|
21 |
+
|
22 |
+
function ce_add_settings_link( $links, $file ) {
|
23 |
+
|
24 |
+
static $this_plugin;
|
25 |
+
|
26 |
+
if ( ! $this_plugin ) {
|
27 |
+
$this_plugin = plugin_basename( __FILE__ );
|
28 |
+
}
|
29 |
+
|
30 |
+
if ( false !== strpos( $file, 'code-embed.php' ) ) {
|
31 |
+
$settings_link = '<a href="admin.php?page=ce-options">' . __( 'Settings', 'simple-embed-code' ) . '</a>';
|
32 |
+
array_unshift( $links, $settings_link );
|
33 |
+
}
|
34 |
+
|
35 |
+
return $links;
|
36 |
+
}
|
37 |
+
|
38 |
+
add_filter( 'plugin_action_links', 'ce_add_settings_link', 10, 2 );
|
39 |
+
|
40 |
+
/**
|
41 |
+
* Add meta to plugin details
|
42 |
+
*
|
43 |
+
* Add options to plugin meta line
|
44 |
+
*
|
45 |
+
* @since 1.6
|
46 |
+
*
|
47 |
+
* @param string $links Current links
|
48 |
+
* @param string $file File in use
|
49 |
+
* @return string Links, now with settings added
|
50 |
+
*/
|
51 |
+
|
52 |
+
function ce_set_plugin_meta( $links, $file ) {
|
53 |
+
|
54 |
+
if ( false !== strpos( $file, 'code-embed.php' ) ) {
|
55 |
+
|
56 |
+
$links = array_merge( $links, array( '<a href="https://github.com/dartiss/code-embed">' . __( 'Github', 'simple-embed-code' ) . '</a>' ) );
|
57 |
+
|
58 |
+
$links = array_merge( $links, array( '<a href="https://wordpress.org/plugins/simple-embed-code/">' . __( 'Support', 'simple-embed-code' ) . '</a>' ) );
|
59 |
+
}
|
60 |
+
|
61 |
+
return $links;
|
62 |
+
}
|
63 |
+
|
64 |
+
add_filter( 'plugin_row_meta', 'ce_set_plugin_meta', 10, 2 );
|
65 |
+
|
66 |
+
/**
|
67 |
+
* Code Embed Menu
|
68 |
+
*
|
69 |
+
* Add a new option to the Admin menu and context menu
|
70 |
+
*
|
71 |
+
* @since 1.4
|
72 |
+
*
|
73 |
+
* @uses ce_help Return help text
|
74 |
+
*/
|
75 |
+
|
76 |
+
function ce_menu() {
|
77 |
+
|
78 |
+
// Add search sub-menu
|
79 |
+
|
80 |
+
global $ce_search_hook;
|
81 |
+
|
82 |
+
$ce_search_hook = add_submenu_page( 'tools.php', __( 'Code Embed Search', 'simple-embed-code' ), __( 'Code Search', 'simple-embed-code' ), 'edit_posts', 'ce-search', 'ce_search' );
|
83 |
+
|
84 |
+
add_action( 'load-' . $ce_search_hook, 'ce_add_search_help' );
|
85 |
+
|
86 |
+
// Add options sub-menu
|
87 |
+
|
88 |
+
global $ce_options_hook;
|
89 |
+
|
90 |
+
$ce_options_hook = add_submenu_page( 'options-general.php', __( 'Code Embed Settings', 'simple-embed-code' ), __( 'Code Embed', 'simple-embed-code' ), 'manage_options', 'ce-options', 'ce_options' );
|
91 |
+
|
92 |
+
add_action( 'load-' . $ce_options_hook, 'ce_add_options_help' );
|
93 |
+
|
94 |
+
}
|
95 |
+
|
96 |
+
add_action( 'admin_menu', 'ce_menu' );
|
97 |
+
|
98 |
+
/**
|
99 |
+
* Add Options Help
|
100 |
+
*
|
101 |
+
* Add help tab to options screen
|
102 |
+
*
|
103 |
+
* @since 2.0
|
104 |
+
*
|
105 |
+
* @uses ce_options_help Return help text
|
106 |
+
*/
|
107 |
+
|
108 |
+
function ce_add_options_help() {
|
109 |
+
|
110 |
+
global $ce_options_hook;
|
111 |
+
$screen = get_current_screen();
|
112 |
+
|
113 |
+
if ( $screen->id !== $ce_options_hook ) {
|
114 |
+
return;
|
115 |
+
}
|
116 |
+
|
117 |
+
$screen->add_help_tab(
|
118 |
+
array(
|
119 |
+
'id' => 'ce-options-help-tab',
|
120 |
+
'title' => __( 'Help', 'simple-embed-code' ),
|
121 |
+
'content' => ce_options_help(),
|
122 |
+
)
|
123 |
+
);
|
124 |
+
|
125 |
+
$screen->set_help_sidebar( ce_help_sidebar() );
|
126 |
+
}
|
127 |
+
|
128 |
+
/**
|
129 |
+
* Add Search Help
|
130 |
+
*
|
131 |
+
* Add help tab to search screen
|
132 |
+
*
|
133 |
+
* @since 2.0
|
134 |
+
*
|
135 |
+
* @uses ce_search_help Return help text
|
136 |
+
*/
|
137 |
+
|
138 |
+
function ce_add_search_help() {
|
139 |
+
|
140 |
+
global $ce_search_hook;
|
141 |
+
$screen = get_current_screen();
|
142 |
+
|
143 |
+
if ( $screen->id !== $ce_search_hook ) {
|
144 |
+
return;
|
145 |
+
}
|
146 |
+
|
147 |
+
$screen->add_help_tab(
|
148 |
+
array(
|
149 |
+
'id' => 'ce-search-help-tab',
|
150 |
+
'title' => __( 'Help', 'simple-embed-code' ),
|
151 |
+
'content' => ce_search_help(),
|
152 |
+
)
|
153 |
+
);
|
154 |
+
|
155 |
+
$screen->set_help_sidebar( ce_help_sidebar() );
|
156 |
+
}
|
157 |
+
|
158 |
+
/**
|
159 |
+
* Code Embed Options
|
160 |
+
*
|
161 |
+
* Define an option screen
|
162 |
+
*
|
163 |
+
* @since 1.4
|
164 |
+
*/
|
165 |
+
|
166 |
+
function ce_options() {
|
167 |
+
|
168 |
+
include_once( WP_PLUGIN_DIR . '/' . str_replace( basename( __FILE__ ), '', plugin_basename( __FILE__ ) ) . 'options-screen.php' );
|
169 |
+
|
170 |
+
}
|
171 |
+
|
172 |
+
/**
|
173 |
+
* Code Embed Search
|
174 |
+
*
|
175 |
+
* Define a the search screen
|
176 |
+
*
|
177 |
+
* @since 1.6
|
178 |
+
*/
|
179 |
+
|
180 |
+
function ce_search() {
|
181 |
+
|
182 |
+
include_once( WP_PLUGIN_DIR . '/' . str_replace( basename( __FILE__ ), '', plugin_basename( __FILE__ ) ) . 'search-screen.php' );
|
183 |
+
|
184 |
+
}
|
185 |
+
|
186 |
+
/**
|
187 |
+
* Code Embed Options Help
|
188 |
+
*
|
189 |
+
* Return help text for options screen
|
190 |
+
*
|
191 |
+
* @since 1.5
|
192 |
+
*
|
193 |
+
* @return string Help Text
|
194 |
+
*/
|
195 |
+
|
196 |
+
function ce_options_help() {
|
197 |
+
|
198 |
+
$help_text = '<p>' . __( 'Use this screen to modify the various settings, including the identifiers and keyword used to specify your embedded code.', 'simple-embed-code' ) . '</p>';
|
199 |
+
$help_text .= '<p>' . __( 'The first option allows to suppress debug output. Normally this is an HTML comment in your page source - if you wish to hide this then simply tick this option.', 'simple-embed-code' ) . '</p>';
|
200 |
+
$help_text .= '<p>' . __( 'The second option allows to specify whether code embed requests should work in excerpts.', 'simple-embed-code' ) . '</p>';
|
201 |
+
$help_text .= '<p>' . __( 'The keyword is the name used for your custom field. The custom field\'s value is the code that you wish to embed.', 'simple-embed-code' ) . '</p>';
|
202 |
+
$help_text .= '<p>' . __( 'The keyword, sandwiched with the identifier before and after, is what you then need to add to your post or page to activate the embed code.', 'simple-embed-code' ) . '</p>';
|
203 |
+
|
204 |
+
return $help_text;
|
205 |
+
}
|
206 |
+
|
207 |
+
/**
|
208 |
+
* Code Embed Search Help
|
209 |
+
*
|
210 |
+
* Return help text for search screen
|
211 |
+
*
|
212 |
+
* @since 1.6
|
213 |
+
*
|
214 |
+
* @return string Help Text
|
215 |
+
*/
|
216 |
+
|
217 |
+
function ce_search_help() {
|
218 |
+
|
219 |
+
$help_text = '<p>' . __( 'This screen allows you to search for the post and pages that a particular code embed has been used in.', 'simple-embed-code' ) . '</p>';
|
220 |
+
$help_text .= '<p>' . __( 'Simply enter the code suffix that you wish to search for and press the \'Search\' key to display a list of all the posts using it. In addition the code will be shown alongside it. Click on the post name to edit the post.', 'simple-embed-code' ) . '</p>';
|
221 |
+
$help_text .= '<p>' . __( 'The search results are grouped together in matching code groups, so posts with the same code will be shown together with the same color background.', 'simple-embed-code' ) . '</p>';
|
222 |
+
|
223 |
+
return $help_text;
|
224 |
+
}
|
225 |
+
|
226 |
+
/**
|
227 |
+
* Code Embed Help Sidebar
|
228 |
+
*
|
229 |
+
* Return sidebar help text
|
230 |
+
*
|
231 |
+
* @since 2.3
|
232 |
+
*
|
233 |
+
* @return string Help Text
|
234 |
+
*/
|
235 |
+
|
236 |
+
function ce_help_sidebar() {
|
237 |
+
|
238 |
+
$help_text = '<p><strong>' . __( 'For more information:', 'simple-embed-code' ) . '</strong></p>';
|
239 |
+
$help_text .= '<p><a href="https://wordpress.org/plugins/simple-embed-code/">' . __( 'Instructions', 'simple-embed-code' ) . '</a></p>';
|
240 |
+
$help_text .= '<p><a href="https://github.com/dartiss/code-embed">' . __( 'Github (code and issues)', 'simple-embed-code' ) . '</a></p>';
|
241 |
+
$help_text .= '<p><a href="https://wordpress.org/support/plugin/simple-embed-code">' . __( 'Support Forum', 'simple-embed-code' ) . '</a></p></h4>';
|
242 |
+
|
243 |
+
return $help_text;
|
244 |
+
}
|
includes/initialise.php
CHANGED
@@ -1,57 +1,58 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* Initialisation script
|
4 |
-
*
|
5 |
-
* Run everytime the plugin is initialised
|
6 |
-
*
|
7 |
-
* @package
|
8 |
-
* @since
|
9 |
-
*/
|
10 |
-
|
11 |
-
function ce_initialisation() {
|
12 |
-
|
13 |
-
// Add exerpt filter, if required
|
14 |
-
|
15 |
-
$options = get_option( 'artiss_code_embed' );
|
16 |
-
if ( isset( $options[
|
17 |
-
add_filter( 'the_excerpt', 'ce_filter', 1 );
|
18 |
-
}
|
19 |
-
|
20 |
-
// Check if plugin has upgraded and, if so, perform further actions
|
21 |
-
|
22 |
-
$version = get_option( 'code_embed_version' );
|
23 |
-
|
24 |
-
if ( $version
|
25 |
-
|
26 |
-
// Set up default option values (if not already set)
|
27 |
-
|
28 |
-
$options = get_option( 'artiss_code_embed' );
|
29 |
-
|
30 |
-
// If options don't exist, create an empty array
|
31 |
-
|
32 |
-
if ( !is_array( $options ) ) {
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
}
|
55 |
-
|
56 |
-
|
57 |
-
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Initialisation script
|
4 |
+
*
|
5 |
+
* Run everytime the plugin is initialised
|
6 |
+
*
|
7 |
+
* @package simple-embed-code
|
8 |
+
* @since 2.2
|
9 |
+
*/
|
10 |
+
|
11 |
+
function ce_initialisation() {
|
12 |
+
|
13 |
+
// Add exerpt filter, if required
|
14 |
+
|
15 |
+
$options = get_option( 'artiss_code_embed' );
|
16 |
+
if ( isset( $options['excerpt'] ) && 1 === $options['excerpt'] ) {
|
17 |
+
add_filter( 'the_excerpt', 'ce_filter', 1 );
|
18 |
+
}
|
19 |
+
|
20 |
+
// Check if plugin has upgraded and, if so, perform further actions
|
21 |
+
|
22 |
+
$version = get_option( 'code_embed_version' );
|
23 |
+
|
24 |
+
if ( code_embed_version !== $version ) {
|
25 |
+
|
26 |
+
// Set up default option values (if not already set)
|
27 |
+
|
28 |
+
$options = get_option( 'artiss_code_embed' );
|
29 |
+
|
30 |
+
// If options don't exist, create an empty array
|
31 |
+
|
32 |
+
if ( ! is_array( $options ) ) {
|
33 |
+
$options = array();
|
34 |
+
}
|
35 |
+
|
36 |
+
// Because of upgrading, check each option - if not set, apply default
|
37 |
+
|
38 |
+
$default_array = array(
|
39 |
+
'opening_ident' => '{{',
|
40 |
+
'keyword_ident' => 'CODE',
|
41 |
+
'closing_ident' => '}}',
|
42 |
+
'debug' => '',
|
43 |
+
'excerpts' => '',
|
44 |
+
);
|
45 |
+
|
46 |
+
// Merge existing and default options - any missing from existing will take the default settings
|
47 |
+
|
48 |
+
$new_options = array_merge( $default_array, $options );
|
49 |
+
|
50 |
+
// Update the options, if changed, and return the result
|
51 |
+
|
52 |
+
if ( $options !== $new_options ) {
|
53 |
+
update_option( 'artiss_code_embed', $new_options );
|
54 |
+
}
|
55 |
+
}
|
56 |
+
}
|
57 |
+
|
58 |
+
add_action( 'init', 'ce_initialisation' );
|
includes/options-screen.php
CHANGED
@@ -1,97 +1,130 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* Code Embed Options
|
4 |
-
*
|
5 |
-
* Allow the user to change the default options
|
6 |
-
*
|
7 |
-
* @package
|
8 |
-
* @since
|
9 |
-
*
|
10 |
-
* @uses ce_help
|
11 |
-
*/
|
12 |
-
?>
|
13 |
-
<div class="wrap">
|
14 |
-
<h1><?php
|
15 |
-
<?php
|
16 |
-
|
17 |
-
// If options have been updated on screen, update the database
|
18 |
-
|
19 |
-
if ( ( !empty( $_POST ) ) && ( check_admin_referer( 'code-embed-profile'
|
20 |
-
|
21 |
-
// Update the options array from the form fields. Strip invalid tags.
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
}
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
</
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
<
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
<
|
68 |
-
<
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
<
|
74 |
-
<
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
<
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Code Embed Options
|
4 |
+
*
|
5 |
+
* Allow the user to change the default options
|
6 |
+
*
|
7 |
+
* @package simple-embed-code
|
8 |
+
* @since 1.4
|
9 |
+
*
|
10 |
+
* @uses ce_help Return help text
|
11 |
+
*/
|
12 |
+
?>
|
13 |
+
<div class="wrap">
|
14 |
+
<h1><?php echo esc_html( ucwords( __( 'Code Embed options', 'simple-embed-code' ) ) ); ?></h1>
|
15 |
+
<?php
|
16 |
+
|
17 |
+
// If options have been updated on screen, update the database
|
18 |
+
|
19 |
+
if ( ( ! empty( $_POST ) ) && ( check_admin_referer( 'code-embed-profile', 'code_embed_profile_nonce' ) ) ) { // Input var okay.
|
20 |
+
|
21 |
+
// Update the options array from the form fields. Strip invalid tags.
|
22 |
+
|
23 |
+
if ( ! empty( $_POST['code_embed_opening'] ) ) {
|
24 |
+
$options['opening_ident'] = strtoupper( trim( sanitize_text_field( wp_unslash( $_POST['code_embed_opening'] ) ) ) ); // Input var okay.
|
25 |
+
} else {
|
26 |
+
$options['opening_ident'] = '{{';
|
27 |
+
}
|
28 |
+
|
29 |
+
if ( ! empty( $_POST['code_embed_keyword'] ) ) {
|
30 |
+
$options['keyword_ident'] = strtoupper( trim( sanitize_text_field( wp_unslash( $_POST['code_embed_keyword'] ) ) ) ); // Input var okay.
|
31 |
+
} else {
|
32 |
+
$options['keyword_ident'] = 'CODE';
|
33 |
+
}
|
34 |
+
|
35 |
+
if ( ! empty( $_POST['code_embed_closing'] ) ) {
|
36 |
+
$options['closing_ident'] = strtoupper( trim( sanitize_text_field( wp_unslash( $_POST['code_embed_closing'] ) ) ) ); // Input var okay.
|
37 |
+
} else {
|
38 |
+
$options['closing_ident'] = '}}';
|
39 |
+
}
|
40 |
+
|
41 |
+
if ( ! empty( $_POST['code_embed_debug'] ) ) {
|
42 |
+
$options['debug'] = sanitize_text_field( wp_unslash( $_POST['code_embed_debug'] ) ); // Input var okay.
|
43 |
+
} else {
|
44 |
+
$options['debug'] = '';
|
45 |
+
}
|
46 |
+
|
47 |
+
if ( isset( $_POST['code_embed_excerpt'] ) ) {
|
48 |
+
$options['excerpt'] = sanitize_text_field( wp_unslash( $_POST['code_embed_excerpt'] ) ); // Input var okay.
|
49 |
+
} else {
|
50 |
+
$options['excerpt'] = '';
|
51 |
+
}
|
52 |
+
|
53 |
+
update_option( 'artiss_code_embed', $options );
|
54 |
+
|
55 |
+
echo '<div class="updated fade"><p><strong>' . esc_html( __( 'Settings saved.', 'simple-embed-code' ) ) . "</strong></p></div>\n";
|
56 |
+
}
|
57 |
+
|
58 |
+
// Fetch options into an array
|
59 |
+
|
60 |
+
$options = get_option( 'artiss_code_embed' );
|
61 |
+
?>
|
62 |
+
|
63 |
+
<form method="post" action="<?php echo esc_html( get_bloginfo( 'wpurl' ) ) . '/wp-admin/options-general.php?page=ce-options'; ?>">
|
64 |
+
|
65 |
+
<table class="form-table">
|
66 |
+
<tr>
|
67 |
+
<th scope="row"><label for="code_embed_debug"><?php echo esc_html( ucwords( __( 'Hide debug', 'simple-embed-code' ) ) ); ?></label></th>
|
68 |
+
<td><input type="checkbox" name="code_embed_debug" value="1"
|
69 |
+
<?php checked( '1', $options['debug'] ); ?>
|
70 |
+
/><?php esc_html_e( 'Hide debug HTML comments in source', 'simple-embed-code' ); ?></td>
|
71 |
+
</tr>
|
72 |
+
|
73 |
+
<tr>
|
74 |
+
<th scope="row"><label for="code_embed_excerpt"><?php echo esc_html( ucwords( __( 'Allow in excerpts', 'simple-embed-code' ) ) ); ?></label></th>
|
75 |
+
<td><input type="checkbox" name="code_embed_excerpt" value="1"
|
76 |
+
<?php checked( '1', $options['excerpt'] ); ?>
|
77 |
+
/><?php esc_html_e( 'Allow embedded code to be shown in excerpts', 'simple-embed-code' ); ?></td>
|
78 |
+
</tr>
|
79 |
+
</table>
|
80 |
+
|
81 |
+
<?php echo '<h3>' . esc_html( ucwords( __( 'Identifier format', 'simple-embed-code' ) ) ) . '</h3>' . esc_html__( 'Specify the format that will be used to define the way the code is embedded in your post. The formats are case insensitive and characters < > [ ] are invalid.', 'simple-embed-code' ); ?>
|
82 |
+
|
83 |
+
<table class="form-table">
|
84 |
+
|
85 |
+
<tr>
|
86 |
+
<th scope="row"><label for="code_embed_keyword"><?php echo esc_html( ucwords( __( 'Keyword', 'simple-embed-code' ) ) ); ?></label></th>
|
87 |
+
<td><input type="text" size="12" maxlength="12" name="code_embed_keyword" value="<?php echo esc_html( $options['keyword_ident'] ); ?>"/><p class="description"><?php esc_html_e( 'The keyword that is used to name the custom field and then place in your post where the code should be embedded. A suffix on any type can then be placed on the end.', 'simple-embed-code' ); ?></p></td>
|
88 |
+
</tr>
|
89 |
+
|
90 |
+
<tr>
|
91 |
+
<th scope="row"><label for="code_embed_opening"><?php echo esc_html( ucwords( __( 'Opening Identifier', 'simple-embed-code' ) ) ); ?></label></th>
|
92 |
+
<td><input type="text" size="4" maxlength="4" name="code_embed_opening" value="<?php echo esc_html( $options['opening_ident'] ); ?>"/><p class="description"><?php esc_html_e( 'The character(s) that must be placed in the post before the keyword to uniquely identify it.', 'simple-embed-code' ); ?></p></td>
|
93 |
+
</tr>
|
94 |
+
|
95 |
+
<tr>
|
96 |
+
<th scope="row"><label for="code_embed_closing"><?php echo esc_html( ucwords( __( 'Closing Identifier', 'simple-embed-code' ) ) ); ?></label></th>
|
97 |
+
<td><input type="text" size="4" maxlength="4" name="code_embed_closing" value="<?php echo esc_html( $options['closing_ident'] ); ?>"/><p class="description"><?php esc_html_e( 'The character(s) that must be placed in the post after the keyword to uniquely identify it.', 'simple-embed-code' ); ?></p></td>
|
98 |
+
</tr>
|
99 |
+
|
100 |
+
</table>
|
101 |
+
|
102 |
+
<?php wp_nonce_field( 'code-embed-profile', 'code_embed_profile_nonce', true, true ); ?>
|
103 |
+
|
104 |
+
<br/><input type="submit" name="Submit" class="button-primary" value="<?php echo esc_html( ucwords( __( 'Save changes', 'simple-embed-code' ) ) ); ?>"/>
|
105 |
+
|
106 |
+
</form>
|
107 |
+
|
108 |
+
<?php
|
109 |
+
|
110 |
+
// How to embed
|
111 |
+
|
112 |
+
echo '<br/><h3>' . esc_html( ucwords( __( 'How to embed', 'simple-embed-code' ) ) ) . "</h3>\n";
|
113 |
+
|
114 |
+
/* translators: %1$s: example of custom field key value to use based on current settings, %2$s: details of key used in example */
|
115 |
+
echo '<p>' . sprintf( esc_html__( 'Based upon your current settings to embed some code simply add a custom field named %1$s, where %2$s is any suffix you wish. The code to embed is then added as the field value.', 'simple-embed-code' ), '<strong>' . esc_html( $options['keyword_ident'] ) . 'x</strong>', '<strong>x</strong>' ) . "\n";
|
116 |
+
|
117 |
+
/* translators: %1$s: example of how to embed code in a post based on current settings, %2$s: details of key used in example */
|
118 |
+
echo ' ' . sprintf( esc_html__( 'Then, to add the code into your post simple add %1$s where you wish it to appear. %2$s is the suffix you used for the custom field name.', 'simple-embed-code' ), '<strong>' . esc_html( $options['opening_ident'] ) . esc_html( $options['keyword_ident'] ) . 'x' . esc_html( $options['closing_ident'] ) . '</strong>', '<strong>x</strong>' ) . "</p>\n";
|
119 |
+
|
120 |
+
/* translators: %1$s: another example of adding a custom field, %2$s: another example of adding embed to a post */
|
121 |
+
echo '<p>' . sprintf( esc_html__( 'For example, I may add a custom field named %1$s, where the value is the code I wish to embed. I would then in my post add %2$s where I wish the code to then appear.', 'simple-embed-code' ), '<strong>' . esc_html( $options['keyword_ident'] ) . '1</strong>', '<strong>' . esc_html( $options['opening_ident'] ) . esc_html( $options['keyword_ident'] ) . '1' . esc_html( $options['closing_ident'] ) . '</strong>' ) . "</p>\n";
|
122 |
+
|
123 |
+
/* translators: %1$s: example embedding for responsive layout , %2$s: details of key used in example */
|
124 |
+
echo '<p>' . sprintf( esc_html__( 'To embed the same code but to make it responsive you would use %1$s. To set a maximum width you would use %2$s, where %3$s is the maximum width in pixels.', 'simple-embed-code' ), '<strong>' . esc_html( $options['opening_ident'] ) . esc_html( $options['keyword_ident'] ) . 'x_RES' . esc_html( $options['closing_ident'] ) . '</strong>', '<strong>' . esc_html( $options['opening_ident'] ) . esc_html( $options['keyword_ident'] ) . 'x_RES_y' . esc_html( $options['closing_ident'] ) . '</strong>', '<strong>y</strong>' ) . "</p>\n";
|
125 |
+
|
126 |
+
/* translators: %1$s: example of embedding a file, %2$s: details of key used in example */
|
127 |
+
echo '<p>' . sprintf( esc_html__( 'To embed an external URL you would type %1$s, where %2$s is the URL.', 'simple-embed-code' ), '<strong>' . esc_html( $options['opening_ident'] ) . 'url' . esc_html( $options['closing_ident'] ) . '</strong>', '<strong>url</strong>' ) . "</p>\n";
|
128 |
+
?>
|
129 |
+
|
130 |
+
</div>
|
includes/search-screen.php
CHANGED
@@ -1,93 +1,94 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* Code Embed Search
|
4 |
-
*
|
5 |
-
* Allow the user to change the default options
|
6 |
-
*
|
7 |
-
* @package
|
8 |
-
* @since
|
9 |
-
*/
|
10 |
-
?>
|
11 |
-
<div class="wrap">
|
12 |
-
<h1><?php
|
13 |
-
|
14 |
-
<?php
|
15 |
-
echo '<p>' .
|
16 |
-
?>
|
17 |
-
|
18 |
-
<?php
|
19 |
-
|
20 |
-
// Get the suffix
|
21 |
-
|
22 |
-
if (
|
23 |
-
$suffix = htmlspecialchars( $
|
24 |
-
} else {
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
?>
|
36 |
-
|
37 |
-
<
|
38 |
-
|
39 |
-
<?php echo $options[
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
<?php
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
$
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
$
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
echo '<
|
77 |
-
echo '<td><
|
78 |
-
echo "</
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
}
|
91 |
-
|
92 |
-
|
93 |
-
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Code Embed Search
|
4 |
+
*
|
5 |
+
* Allow the user to change the default options
|
6 |
+
*
|
7 |
+
* @package simple-embed-code
|
8 |
+
* @since 1.6
|
9 |
+
*/
|
10 |
+
?>
|
11 |
+
<div class="wrap">
|
12 |
+
<h1><?php echo esc_html( ucwords( __( 'Code Embed search', 'simple-embed-code' ) ) ); ?></h1>
|
13 |
+
|
14 |
+
<?php
|
15 |
+
echo '<p>' . esc_html__( 'Enter the suffix to search for below and press the \'Search\' button to view the results. Further help can be found by clicking on the Help tab at the top right-hand of the screen.', 'simple-embed-code' ) . '</p>';
|
16 |
+
?>
|
17 |
+
|
18 |
+
<?php
|
19 |
+
|
20 |
+
// Get the suffix from the submitted field
|
21 |
+
|
22 |
+
if ( ! empty( $_POST['ce_suffix'] ) && check_admin_referer( 'code-embed-search', 'code_embed_search_nonce' ) ) { // Input var okay.
|
23 |
+
$suffix = htmlspecialchars( sanitize_title( wp_unslash( $_POST['ce_suffix'] ) ) ); // Input var okay.
|
24 |
+
} else {
|
25 |
+
$suffix = '';
|
26 |
+
}
|
27 |
+
|
28 |
+
// Fetch options into an array
|
29 |
+
|
30 |
+
$options = get_option( 'artiss_code_embed' );
|
31 |
+
?>
|
32 |
+
|
33 |
+
<form method="post" action="<?php echo esc_html( get_bloginfo( 'wpurl' ) ) . '/wp-admin/tools.php?page=ce-search'; ?>">
|
34 |
+
|
35 |
+
<?php echo esc_html( $options['opening_ident'] ) . esc_html( $options['keyword_ident'] ); ?>
|
36 |
+
|
37 |
+
<input type="text" size="6" name="ce_suffix" value="<?php echo esc_html( $suffix ); ?>"/>
|
38 |
+
|
39 |
+
<?php echo esc_html( $options['closing_ident'] ); ?>
|
40 |
+
|
41 |
+
<?php wp_nonce_field( 'code-embed-search', 'code_embed_search_nonce', true, true ); ?>
|
42 |
+
|
43 |
+
<input type="submit" name="Submit" class="button-primary" value="<?php esc_html_e( 'Search', 'simple-embed-code' ); ?>"/>
|
44 |
+
|
45 |
+
</form>
|
46 |
+
|
47 |
+
<?php
|
48 |
+
if ( '' !== $suffix ) {
|
49 |
+
|
50 |
+
global $wpdb;
|
51 |
+
$meta = $wpdb->get_results( $wpdb->prepare( "SELECT meta_value, post_title, ID FROM $wpdb->postmeta, $wpdb->posts WHERE meta_key = %s AND post_id = ID ORDER BY meta_value", esc_html( $options['keyword_ident'] ) . esc_html( $suffix ) ) ); // @codingStandardsIgnoreLine -- being used for a simple, ad-hoc search feature in admin. Unlikely to be used much and caching on this is overkill
|
52 |
+
$records = $wpdb->num_rows;
|
53 |
+
|
54 |
+
if ( 0 < $records ) {
|
55 |
+
|
56 |
+
echo '<table class="form-table">';
|
57 |
+
$color1 = 'dfdfdf';
|
58 |
+
$color2 = 'ececec';
|
59 |
+
$color = $color1;
|
60 |
+
$prev_html = '';
|
61 |
+
|
62 |
+
foreach ( $meta as $meta_data ) {
|
63 |
+
$html = $meta_data->meta_value;
|
64 |
+
$post_title = $meta_data->post_title;
|
65 |
+
$post_id = $meta_data->ID;
|
66 |
+
|
67 |
+
// Switch background colours as the code changes
|
68 |
+
|
69 |
+
if ( $html !== $prev_html ) {
|
70 |
+
if ( $color === $color1 ) {
|
71 |
+
$color = $color2;
|
72 |
+
} else {
|
73 |
+
$color = $color1; }
|
74 |
+
}
|
75 |
+
|
76 |
+
echo '<tr style="background-color: #' . esc_html( $color ) . "\">\n";
|
77 |
+
echo '<td><a href="' . esc_html( home_url() ) . '/wp-admin/post.php?post=' . esc_html( $post_id ) . '&action=edit" style="color: #f00;">' . esc_html( $post_title ) . "</td>\n";
|
78 |
+
echo '<td><textarea readonly="readonly" rows="3" cols="80">' . esc_html( $html ) . "</textarea></td>\n";
|
79 |
+
echo "</tr>\n";
|
80 |
+
|
81 |
+
$prev_html = $html;
|
82 |
+
}
|
83 |
+
|
84 |
+
echo "</table>\n";
|
85 |
+
|
86 |
+
} else {
|
87 |
+
|
88 |
+
echo '<p style="color: #f00">' . esc_html__( 'No posts were found containing that embed code.', 'simple-embed-code' ) . "</p>\n";
|
89 |
+
|
90 |
+
}
|
91 |
+
}
|
92 |
+
?>
|
93 |
+
|
94 |
+
</div>
|
readme.txt
CHANGED
@@ -2,9 +2,9 @@
|
|
2 |
Contributors: dartiss
|
3 |
Tags: code, embed, html, javascript, script
|
4 |
Requires at least: 4.6
|
5 |
-
Tested up to: 4.9
|
6 |
Requires PHP: 5.3
|
7 |
-
Stable tag: 2.
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
@@ -12,7 +12,7 @@ Code Embed provides a very easy and efficient way to embed code (JavaScript and
|
|
12 |
|
13 |
== Description ==
|
14 |
|
15 |
-
Code Embed allows you to embed code
|
16 |
|
17 |
Key features include...
|
18 |
|
@@ -31,6 +31,8 @@ Technical specification...
|
|
31 |
* Designed for both single and multi-site installations
|
32 |
* PHP7 compatible
|
33 |
* Fully internationalized, ready for translations **If you would like to add a translation to this plugin then please head to our [Translating WordPress](https://translate.wordpress.org/projects/wp-plugins/simple-embed-code "Translating WordPress") page**
|
|
|
|
|
34 |
|
35 |
Please visit the [Github page](https://github.com/dartiss/code-embed "Github") for the latest code development, planned enhancements and known issues.
|
36 |
|
@@ -40,9 +42,9 @@ Here's how easy it is to use…
|
|
40 |
|
41 |
1. Once you have the plugin installed start a new post or page.
|
42 |
2. In the `Custom Fields` meta box enter a name of CODE1 and your embed code as the value. Save this.
|
43 |
-
3. In your post add
|
44 |
|
45 |
-
And that's it - when the post or page is viewed
|
46 |
|
47 |
**If you cannot find the location of the `Custom Fields` meta box on your post editor screen, please see the FAQ section for more information**
|
48 |
|
@@ -66,9 +68,9 @@ To embed in a post you need to find the meta box under the post named "Custom Fi
|
|
66 |
|
67 |
Now create a new custom field with the name of your keyword - e.g. `CODE`. The value of this field will be the code that you wish to embed. Save this custom field.
|
68 |
|
69 |
-
Now, wherever you wish the code to appear in your post, simply put the full identifier (opening, keyword and closing characters). For example,
|
70 |
|
71 |
-
If you wish to embed multiple pieces of code within a post you can add a suffix to the keyword. So we may set up 2 custom fields named `CODE1` and `CODE2`. Then in our post we would specify either
|
72 |
|
73 |
Don't forget - via the options screen you can change any part of this identifier to your own taste.
|
74 |
|
@@ -80,11 +82,11 @@ Obviously, be careful when embedding a URL that you have no control over, as thi
|
|
80 |
|
81 |
For example, using the default options you could embed the contents of a URL using the following method...
|
82 |
|
83 |
-
|
84 |
|
85 |
or
|
86 |
|
87 |
-
|
88 |
|
89 |
== Global Embedding ==
|
90 |
|
@@ -92,7 +94,7 @@ You can also create global embeds - that is creating one piece of embed code and
|
|
92 |
|
93 |
To do this simply make reference to an already defined (but unique) piece of embed code from another post or page.
|
94 |
|
95 |
-
So, let's say in one post you define a custom field named `CODE1`. You can, if you wish, place
|
96 |
|
97 |
However, bear in mind that the embed code name must be unique - you can't have defined it in multiple posts otherwise the plugin won't know which one you're referring to (although it will report this and list the posts that it has been used in).
|
98 |
|
@@ -106,7 +108,7 @@ Natively you cannot use the embed facilities within sidebar widgets. However, if
|
|
106 |
* In Administration, select the Widgets page from the Appearance menu. At the bottom there will be a set of Widget Logic options.
|
107 |
* Ensure Use 'widget_content' filter is ticked and press Save.
|
108 |
|
109 |
-
Although you cannot set up embed code within a widget you can make reference to it, for example by writing
|
110 |
|
111 |
== Responsive Output Conversion ==
|
112 |
|
@@ -114,11 +116,11 @@ Responsive output is where an element on a web page dynamically resizes dependin
|
|
114 |
|
115 |
Code Embed provides a simple suffix that can be added to an embed code and will convert the output to being responsive. This works best with videos.
|
116 |
|
117 |
-
To use, when adding the embed code onto the page, simply add `_RES` to the end, before the final identifier. For example,
|
118 |
|
119 |
This will now output the embedded code full width, but a width that is dynamic and will resize when required.
|
120 |
|
121 |
-
If you don't wish the output to be full width you can specify a maximum width by adding an additional `_x` on the end, where `x` is the required width in pixels. For example,
|
122 |
|
123 |
**It should be noted that this is an experimental addition and will not work in all circumstances.**
|
124 |
|
@@ -161,7 +163,15 @@ If you still can't find it then you may have a theme or plugin that removes this
|
|
161 |
|
162 |
= What's the maximum size of the embed code that I can save in a custom field? =
|
163 |
|
164 |
-
WordPress stores the custom field contents in a MySQL table using the `longtext` format. This can hold over 4 billion characters.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
165 |
|
166 |
== Screenshots ==
|
167 |
|
@@ -176,6 +186,17 @@ WordPress stores the custom field contents in a MySQL table using the `longtext`
|
|
176 |
|
177 |
[Learn more about my version numbering methodology](https://artiss.blog/2016/09/wordpress-plugin-versioning/ "WordPress Plugin Versioning")
|
178 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
179 |
= 2.2.2 =
|
180 |
* Maintenance: Updated README to work better with new plugin directory format. Also, now converting all text to US English, which is the WordPress standard. Snazzy.
|
181 |
* Maintenance: Updated all links to artiss.blog and removed donation links. Clickable.
|
@@ -268,5 +289,5 @@ versions of this plugin
|
|
268 |
|
269 |
== Upgrade Notice ==
|
270 |
|
271 |
-
= 2.
|
272 |
-
*
|
2 |
Contributors: dartiss
|
3 |
Tags: code, embed, html, javascript, script
|
4 |
Requires at least: 4.6
|
5 |
+
Tested up to: 4.9.4
|
6 |
Requires PHP: 5.3
|
7 |
+
Stable tag: 2.3
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
12 |
|
13 |
== Description ==
|
14 |
|
15 |
+
Code Embed allows you to embed code (JavaScript and HTML - it can't be used for server-side code, such as PHP) in a post, without the content being changed by the editor. This is incredibly useful for embedding third-party scripts, etc. The plugin is used by many large sites, including Mozilla.
|
16 |
|
17 |
Key features include...
|
18 |
|
31 |
* Designed for both single and multi-site installations
|
32 |
* PHP7 compatible
|
33 |
* Fully internationalized, ready for translations **If you would like to add a translation to this plugin then please head to our [Translating WordPress](https://translate.wordpress.org/projects/wp-plugins/simple-embed-code "Translating WordPress") page**
|
34 |
+
* GDPR compliant
|
35 |
+
* See FAQ for Gutenberg compatibility
|
36 |
|
37 |
Please visit the [Github page](https://github.com/dartiss/code-embed "Github") for the latest code development, planned enhancements and known issues.
|
38 |
|
42 |
|
43 |
1. Once you have the plugin installed start a new post or page.
|
44 |
2. In the `Custom Fields` meta box enter a name of CODE1 and your embed code as the value. Save this.
|
45 |
+
3. In your post add `{{CODE1}}` where you wish the embed code to appear.
|
46 |
|
47 |
+
And that's it - when the post or page is viewed `{{CODE1}}` will be replaced with the code that you asked to be embedded.
|
48 |
|
49 |
**If you cannot find the location of the `Custom Fields` meta box on your post editor screen, please see the FAQ section for more information**
|
50 |
|
68 |
|
69 |
Now create a new custom field with the name of your keyword - e.g. `CODE`. The value of this field will be the code that you wish to embed. Save this custom field.
|
70 |
|
71 |
+
Now, wherever you wish the code to appear in your post, simply put the full identifier (opening, keyword and closing characters). For example, `{{CODE}}`.
|
72 |
|
73 |
+
If you wish to embed multiple pieces of code within a post you can add a suffix to the keyword. So we may set up 2 custom fields named `CODE1` and `CODE2`. Then in our post we would specify either `{{CODE1}}` or `{{CODE2}}` depending on which you wish to display.
|
74 |
|
75 |
Don't forget - via the options screen you can change any part of this identifier to your own taste.
|
76 |
|
82 |
|
83 |
For example, using the default options you could embed the contents of a URL using the following method...
|
84 |
|
85 |
+
`{{http://www.example.com/code.php}}`
|
86 |
|
87 |
or
|
88 |
|
89 |
+
`{{https://www.example.com/code.html}}`
|
90 |
|
91 |
== Global Embedding ==
|
92 |
|
94 |
|
95 |
To do this simply make reference to an already defined (but unique) piece of embed code from another post or page.
|
96 |
|
97 |
+
So, let's say in one post you define a custom field named `CODE1`. You can, if you wish, place `{{CODE1}}` not just in that post but also in another and it will work.
|
98 |
|
99 |
However, bear in mind that the embed code name must be unique - you can't have defined it in multiple posts otherwise the plugin won't know which one you're referring to (although it will report this and list the posts that it has been used in).
|
100 |
|
108 |
* In Administration, select the Widgets page from the Appearance menu. At the bottom there will be a set of Widget Logic options.
|
109 |
* Ensure Use 'widget_content' filter is ticked and press Save.
|
110 |
|
111 |
+
Although you cannot set up embed code within a widget you can make reference to it, for example by writing `{{CODE1}}` in the widget.
|
112 |
|
113 |
== Responsive Output Conversion ==
|
114 |
|
116 |
|
117 |
Code Embed provides a simple suffix that can be added to an embed code and will convert the output to being responsive. This works best with videos.
|
118 |
|
119 |
+
To use, when adding the embed code onto the page, simply add `_RES` to the end, before the final identifier. For example, `{{CODE1_RES}}`. The `_RES` should not be added to the custom fields definition.
|
120 |
|
121 |
This will now output the embedded code full width, but a width that is dynamic and will resize when required.
|
122 |
|
123 |
+
If you don't wish the output to be full width you can specify a maximum width by adding an additional `_x` on the end, where `x` is the required width in pixels. For example, `{{CODE1_RES_500}}` this will output `CODE1` as responsive but with a maximum width of 500 pixels.
|
124 |
|
125 |
**It should be noted that this is an experimental addition and will not work in all circumstances.**
|
126 |
|
163 |
|
164 |
= What's the maximum size of the embed code that I can save in a custom field? =
|
165 |
|
166 |
+
WordPress stores the custom field contents in a MySQL table using the `longtext` format. This can hold over 4 billion characters.
|
167 |
+
|
168 |
+
== Does this work with Gutenberg? ==
|
169 |
+
|
170 |
+
Right now, no, as the custom fields meta box will not be present. However, a rather smart plugin named [Custom Fields for Gutenberg](https://wordpress.org/plugins/custom-fields-gutenberg/) will add this functionality back in - with that active, you can happily continue to use this plugin.
|
171 |
+
|
172 |
+
== Is this GDPR compliant? ==
|
173 |
+
|
174 |
+
It is, in that it doesn't save any data that could be odds with GDPR compliance (i.e. it's compliant by design). However, if you use this to embed third-party scripts, then those scripts may not be and you will need to speak to the providers for further details.
|
175 |
|
176 |
== Screenshots ==
|
177 |
|
186 |
|
187 |
[Learn more about my version numbering methodology](https://artiss.blog/2016/09/wordpress-plugin-versioning/ "WordPress Plugin Versioning")
|
188 |
|
189 |
+
= 2.3 =
|
190 |
+
* Enhancement: All the code is now compliant with the full-fat VIP coding standards. It was no mean feat but, as a result, the plugin is more secure than ever before
|
191 |
+
* Enhancement: The default is to now use double braces around your embed name, which is kind-of the universal default for template tags such as this. If you're an existing user, your current configuration won't change, though - this only affects new users
|
192 |
+
* Enhancement: Improved translation output, including where I'd accidentally added an extra character to the text domain
|
193 |
+
* Enhancement: Using the `checked` function on fields, rather than the form parameter
|
194 |
+
* Enhancement: Added a useful links sidebar to the Help for both screens
|
195 |
+
* Maintenance: Throughout, use Yoda conditions I now do
|
196 |
+
* Maintenance: Added links to the sparkly new Github repo
|
197 |
+
* Bug: When updating the options you sometimes didn't get a confirmation message. You do now!
|
198 |
+
* Bug: Fixed a weird one where I was referencing a variable that I was never using ¯\_(ツ)_/¯
|
199 |
+
|
200 |
= 2.2.2 =
|
201 |
* Maintenance: Updated README to work better with new plugin directory format. Also, now converting all text to US English, which is the WordPress standard. Snazzy.
|
202 |
* Maintenance: Updated all links to artiss.blog and removed donation links. Clickable.
|
289 |
|
290 |
== Upgrade Notice ==
|
291 |
|
292 |
+
= 2.3 =
|
293 |
+
* Numerous bug fixed and enhancements
|
simple-code-embed.php
CHANGED
@@ -1,40 +1,39 @@
|
|
1 |
-
<?php
|
2 |
-
/*
|
3 |
-
Plugin Name: Code Embed
|
4 |
-
Plugin URI: https://
|
5 |
-
Description: Code Embed provides a very easy and efficient way to embed code (JavaScript and HTML) in your posts and pages.
|
6 |
-
Version: 2.
|
7 |
-
Author: David Artiss
|
8 |
-
Author URI: https://artiss.blog
|
9 |
-
Text Domain: simple-embed-code
|
10 |
-
*/
|
11 |
-
|
12 |
-
/**
|
13 |
-
* Code Embed
|
14 |
-
*
|
15 |
-
* Embed code into a post
|
16 |
-
*
|
17 |
-
* @package
|
18 |
-
* @since
|
19 |
-
*/
|
20 |
-
|
21 |
-
define( '
|
22 |
-
|
23 |
-
// Include all the various functions
|
24 |
-
|
25 |
-
$functions_dir = plugin_dir_path( __FILE__ ) . 'includes/';
|
26 |
-
|
27 |
-
include_once( $functions_dir . 'initialise.php' );
|
28 |
-
|
29 |
-
if ( is_admin() ) {
|
30 |
-
|
31 |
-
include_once( $functions_dir . 'admin-config.php' );
|
32 |
-
|
33 |
-
} else {
|
34 |
-
|
35 |
-
include_once( $functions_dir . 'add-scripts.php' );
|
36 |
-
|
37 |
-
include_once( $functions_dir . 'add-embeds.php' );
|
38 |
-
|
39 |
-
}
|
40 |
-
?>
|
1 |
+
<?php
|
2 |
+
/*
|
3 |
+
Plugin Name: Code Embed
|
4 |
+
Plugin URI: https://github.com/dartiss/code-embed
|
5 |
+
Description: Code Embed provides a very easy and efficient way to embed code (JavaScript and HTML) in your posts and pages.
|
6 |
+
Version: 2.3
|
7 |
+
Author: David Artiss
|
8 |
+
Author URI: https://artiss.blog
|
9 |
+
Text Domain: simple-embed-code
|
10 |
+
*/
|
11 |
+
|
12 |
+
/**
|
13 |
+
* Code Embed
|
14 |
+
*
|
15 |
+
* Embed code into a post
|
16 |
+
*
|
17 |
+
* @package Code-Embed
|
18 |
+
* @since 1.6
|
19 |
+
*/
|
20 |
+
|
21 |
+
define( 'CODE_EMBED_VERSION', '2.3' );
|
22 |
+
|
23 |
+
// Include all the various functions
|
24 |
+
|
25 |
+
$functions_dir = plugin_dir_path( __FILE__ ) . 'includes/';
|
26 |
+
|
27 |
+
include_once( $functions_dir . 'initialise.php' ); // Initialisation scripts
|
28 |
+
|
29 |
+
if ( is_admin() ) {
|
30 |
+
|
31 |
+
include_once( $functions_dir . 'admin-config.php' ); // Various administration config. options
|
32 |
+
|
33 |
+
} else {
|
34 |
+
|
35 |
+
include_once( $functions_dir . 'add-scripts.php' ); // Add scripts to the main theme
|
36 |
+
|
37 |
+
include_once( $functions_dir . 'add-embeds.php' ); // Filter to apply code embeds
|
38 |
+
|
39 |
+
}
|
|
uninstall.php
CHANGED
@@ -1,20 +1,19 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* Uninstaller
|
4 |
-
*
|
5 |
-
* Uninstall the plugin by removing any options from the database
|
6 |
-
*
|
7 |
-
* @package
|
8 |
-
* @since
|
9 |
-
*/
|
10 |
-
|
11 |
-
// If the uninstall was not called by WordPress, exit
|
12 |
-
|
13 |
-
if ( !defined( 'WP_UNINSTALL_PLUGIN' ) ) {
|
14 |
-
exit();
|
15 |
-
}
|
16 |
-
|
17 |
-
// Delete any options
|
18 |
-
|
19 |
-
delete_site_option( 'artiss_code_embed' );
|
20 |
-
?>
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Uninstaller
|
4 |
+
*
|
5 |
+
* Uninstall the plugin by removing any options from the database
|
6 |
+
*
|
7 |
+
* @package simple-embed-code
|
8 |
+
* @since 1.6
|
9 |
+
*/
|
10 |
+
|
11 |
+
// If the uninstall was not called by WordPress, exit
|
12 |
+
|
13 |
+
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
|
14 |
+
exit();
|
15 |
+
}
|
16 |
+
|
17 |
+
// Delete any options
|
18 |
+
|
19 |
+
delete_site_option( 'artiss_code_embed' );
|
|