Skip to content

Commit 7a8380b

Browse files
authored
Merge pull request #62 from dartiss/develop
Version 2.3.5
2 parents 695521a + caace49 commit 7a8380b

15 files changed

+269
-270
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Code Embed
22

3-
<img src="https://ps.w.org/simple-embed-code/assets/icon-128x128.png" align="left">Code Embed allows you to embed code – JavaScript and HTML primarily – in a post. This is incredibly useful for embedding video, etc, when required and is used, amongst other, by Mozilla.
3+
<img src="https://ps.w.org/simple-embed-code/assets/icon-128x128.png" align="left">Code Embed allows you to embed code – JavaScript, CSS and HTML primarily – in a post. This is incredibly useful for embedding video, etc, when required and is used, amongst other, by Mozilla.
44

55
It cannot be used for server side code, such as PHP.
66

assets/screenshot-1.png

100755100644
172 KB
Loading

assets/screenshot-2.png

100755100644
40.7 KB
Loading

assets/screenshot-3.png

100755100644
-236 KB
Loading

assets/screenshot-4.png

100755100644
-129 KB
Loading

assets/screenshot-5.png

100755100644
-232 KB
Loading

assets/screenshot-6.png

-75.8 KB
Binary file not shown.

includes/add-embeds.php

Lines changed: 79 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,42 @@
11
<?php
22
/**
3-
* Add Embed to Posts
4-
*
5-
* Functions to add embed code to posts
6-
*
7-
* @package simple-embed-code
8-
*/
3+
* Add Embed to Posts
4+
*
5+
* Functions to add embed code to posts
6+
*
7+
* @package simple-embed-code
8+
*/
99

1010
/**
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-
11+
* Add filter to add embed code
12+
*
13+
* Filter to add embed to any posts
14+
*
15+
* @uses ce_get_embed_code Get embed code from other posts
16+
*
17+
* @param string $content Post content without embedded code.
18+
* @return string Post content with embedded code.
19+
*/
2320
function ce_filter( $content ) {
2421

2522
global $post;
2623

27-
// Set initial values
24+
// Set initial values.
2825

2926
$options = get_option( 'artiss_code_embed' );
3027
$found_pos = strpos( $content, $options['opening_ident'] . $options['keyword_ident'], 0 );
3128
$prefix_len = strlen( $options['opening_ident'] . $options['keyword_ident'] );
3229

33-
// Loop around the post content looking for all requests for code embeds
30+
// Loop around the post content looking for all requests for code embeds.
3431

3532
while ( false !== $found_pos ) {
3633

37-
// Get the position of the closing identifier - ignore if one is not found
34+
// Get the position of the closing identifier - ignore if one is not found!
3835

3936
$end_pos = strpos( $content, $options['closing_ident'], $found_pos + $prefix_len );
4037
if ( false !== $end_pos ) {
4138

42-
// Extract the suffix
39+
// Extract the suffix.
4340

4441
$suffix_len = $end_pos - ( $found_pos + $prefix_len );
4542
if ( 0 === $suffix_len ) {
@@ -49,7 +46,7 @@ function ce_filter( $content ) {
4946
}
5047
$full_suffix = $suffix;
5148

52-
// Check for responsive part of suffix
49+
// Check for responsive part of suffix.
5350

5451
$responsive = false;
5552
$max_width = false;
@@ -60,8 +57,8 @@ function ce_filter( $content ) {
6057

6158
if ( false !== $res_pos ) {
6259

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
60+
// If responsive section found, check it's at the end of has an underscore afterwards.
61+
// Otherwise it may be part of something else.
6562

6663
if ( strlen( $suffix ) - 4 === $res_pos ) {
6764
$responsive = true;
@@ -80,41 +77,41 @@ function ce_filter( $content ) {
8077
}
8178
}
8279

83-
// Get the custom field data and replace in the post
80+
// Get the custom field data and replace in the post.
8481

8582
$search = $options['opening_ident'] . $options['keyword_ident'] . $suffix . $options['closing_ident'];
8683

87-
// Get the meta for the current post
84+
// Get the meta for the current post.
8885

8986
$post_meta = get_post_meta( $post->ID, $options['keyword_ident'] . $suffix, false );
9087
if ( isset( $post_meta[0] ) ) {
9188
$html = $post_meta[0];
9289
} else {
93-
// No meta found, so look for it elsewhere
90+
// No meta found, so look for it elsewhere.
9491
$html = ce_get_embed_code( $options['keyword_ident'], $suffix );
9592
}
9693

97-
// Build the string to search for
94+
// Build the string to search for.
9895

9996
$search = $options['opening_ident'] . $options['keyword_ident'] . $full_suffix . $options['closing_ident'];
10097

101-
// Build the string of code to replace with
98+
// Build the string of code to replace with.
10299

103100
$replace = ce_generate_code( $html, $responsive, $max_width );
104101

105-
// Now modify all references
102+
// Now modify all references.
106103

107104
$content = str_replace( $search, $replace, $content );
108105

109106
}
110107
$found_pos = strpos( $content, $options['opening_ident'] . $options['keyword_ident'], $found_pos + 1 );
111108
}
112109

113-
// Loop around the post content looking for HTTP addresses
110+
// Loop around the post content looking for HTTP addresses.
114111

115112
$content = ce_quick_replace( $content, $options, 'http://' );
116113

117-
// Loop around the post content looking for HTTPS addresses
114+
// Loop around the post content looking for HTTPS addresses.
118115

119116
$content = ce_quick_replace( $content, $options, 'https://' );
120117

@@ -125,18 +122,15 @@ function ce_filter( $content ) {
125122
add_filter( 'widget_content', 'ce_filter' );
126123

127124
/**
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-
125+
* Quick Replace
126+
*
127+
* Function to do a quick search/replace of the content
128+
*
129+
* @param string $content The content.
130+
* @param string $options The options array.
131+
* @param string $search The string to search for.
132+
* @return string The updated content
133+
*/
140134
function ce_quick_replace( $content = '', $options = '', $search = '' ) {
141135

142136
$start_pos = strpos( $content, $options['opening_ident'] . $search, 0 );
@@ -163,18 +157,15 @@ function ce_quick_replace( $content = '', $options = '', $search = '' ) {
163157
}
164158

165159
/**
166-
* Generate Embed Code
167-
*
168-
* Function to generate the embed code that will be output
169-
*
170-
* @since 2.0
171-
*
172-
* @param $html string The embed code (required)
173-
* @param $responsive string Responsive output required? (optional)
174-
* @param $max_width string Maximum width of responsive output (optional)
175-
* @return string The embed code
176-
*/
177-
160+
* Generate Embed Code
161+
*
162+
* Function to generate the embed code that will be output
163+
*
164+
* @param string $html The embed code (required).
165+
* @param string $responsive Responsive output required? (optional).
166+
* @param string $max_width Maximum width of responsive output (optional).
167+
* @return string The embed code
168+
*/
178169
function ce_generate_code( $html, $responsive = '', $max_width = '' ) {
179170

180171
$code = "\n";
@@ -203,22 +194,19 @@ function ce_generate_code( $html, $responsive = '', $max_width = '' ) {
203194
}
204195

205196
/**
206-
* Get the Global Embed Code
207-
*
208-
* Function to look for and, if available, return the global embed code
209-
*
210-
* @since 1.6
211-
*
212-
* @uses ce_report_error Generate an error message
213-
*
214-
* @param $ident string The embed code opening identifier
215-
* @param $suffix string The embed code suffix
216-
* @return string The embed code (or error)
217-
*/
218-
197+
* Get the Global Embed Code
198+
*
199+
* Function to look for and, if available, return the global embed code
200+
*
201+
* @uses ce_report_error Generate an error message
202+
*
203+
* @param string $ident The embed code opening identifier.
204+
* @param string $suffix The embed code suffix.
205+
* @return string The embed code (or error)
206+
*/
219207
function ce_get_embed_code( $ident, $suffix ) {
220208

221-
// Meta was not found in current post so look across meta table - find the number of distinct code results
209+
// Meta was not found in current post so look across meta table - find the number of distinct code results.
222210

223211
$meta_name = $ident . $suffix;
224212
global $wpdb;
@@ -227,29 +215,29 @@ function ce_get_embed_code( $ident, $suffix ) {
227215

228216
if ( 0 < $records ) {
229217

230-
// Results were found
218+
// Results were found.
231219

232220
$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
233221
$total_records = $wpdb->num_rows;
234222

235223
if ( 1 === $records ) {
236224

237-
// Only one unique code result returned so assume this is the global embed
225+
// Only one unique code result returned so assume this is the global embed.
238226

239227
foreach ( $meta as $meta_data ) {
240228
$html = $meta_data->meta_value;
241229
}
242230
} else {
243231

244-
// More than one unique code result returned, so output the list of posts
232+
// More than one unique code result returned, so output the list of posts.
245233

246234
/* 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 */
247235
$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 );
248236
$html = ce_report_error( $error, 'Code Embed', false );
249237
}
250238
} else {
251239

252-
// No meta code was found so write out an error
240+
// No meta code was found so write out an error.
253241

254242
/* translators: %s: the embed name */
255243
$html = ce_report_error( sprintf( __( 'No embed code was found for %s', 'simple-embed-code' ), $meta_name ), 'Code Embed', false );
@@ -259,17 +247,13 @@ function ce_get_embed_code( $ident, $suffix ) {
259247
}
260248

261249
/**
262-
* Fetch a file
263-
*
264-
* Use WordPress API to fetch a file and check results
265-
*
266-
* @since 2.0
267-
*
268-
* @param string $filein File name to fetch
269-
* @param string $header Only get headers?
270-
* @return string Array containing file contents or false to indicate a failure
271-
*/
272-
250+
* Fetch a file
251+
*
252+
* Use WordPress API to fetch a file and check results
253+
*
254+
* @param string $filein File name to fetch.
255+
* @return string Array containing file contents or false to indicate a failure
256+
*/
273257
function ce_get_file( $filein ) {
274258

275259
if ( function_exists( 'vip_safe_wp_remote_get' ) ) {
@@ -294,18 +278,15 @@ function ce_get_file( $filein ) {
294278
}
295279

296280
/**
297-
* Report an error (1.4)
298-
*
299-
* Function to report an error
300-
*
301-
* @since 1.6
302-
*
303-
* @param $error string Error message
304-
* @param $plugin_name string The name of the plugin
305-
* @param $echo string True or false, depending on whether you wish to return or echo the results
306-
* @return string True or the output text
307-
*/
308-
281+
* Report an error
282+
*
283+
* Function to report an error
284+
*
285+
* @param string $error Error message.
286+
* @param string $plugin_name The name of the plugin.
287+
* @param string $echo True or false, depending on whether you wish to return or echo the results.
288+
* @return string True or the output text
289+
*/
309290
function ce_report_error( $error, $plugin_name, $echo = true ) {
310291

311292
$output = '<p style="color: #f00; font-weight: bold;">' . $plugin_name . ': ' . $error . "</p>\n";
@@ -318,4 +299,3 @@ function ce_report_error( $error, $plugin_name, $echo = true ) {
318299
}
319300

320301
}
321-

includes/add-scripts.php

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,20 @@
11
<?php
22
/**
3-
* Add Scripts
4-
*
5-
* Add CSS to the main theme
6-
*
7-
* @package simple-embed-code
8-
*/
3+
* Add Scripts
4+
*
5+
* Add CSS to the main theme
6+
*
7+
* @package simple-embed-code
8+
*/
99

1010
/**
11-
* Add scripts to theme
12-
*
13-
* Add styles to the main theme
14-
*
15-
* @since 2.0
16-
*/
17-
11+
* Add scripts to theme
12+
*
13+
* Add styles to the main theme
14+
*/
1815
function ce_main_scripts() {
1916

20-
wp_register_style( 'ce_responsive', plugins_url( 'css/video-container.min.css', dirname( __FILE__ ) ) );
17+
wp_register_style( 'ce_responsive', plugins_url( 'css/video-container.min.css', dirname( __FILE__ ) ), array(), CODE_EMBED_VERSION );
2118

2219
wp_enqueue_style( 'ce_responsive' );
2320

0 commit comments

Comments
 (0)