diff --git a/README.md b/README.md
index 6598784..ce4061e 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
# Code Embed
-
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.
+
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.
It cannot be used for server side code, such as PHP.
diff --git a/assets/screenshot-1.png b/assets/screenshot-1.png
old mode 100755
new mode 100644
index 1be6c44..95df8b2
Binary files a/assets/screenshot-1.png and b/assets/screenshot-1.png differ
diff --git a/assets/screenshot-2.png b/assets/screenshot-2.png
old mode 100755
new mode 100644
index 93d5ece..d9457df
Binary files a/assets/screenshot-2.png and b/assets/screenshot-2.png differ
diff --git a/assets/screenshot-3.png b/assets/screenshot-3.png
old mode 100755
new mode 100644
index 2727b2e..b8704c6
Binary files a/assets/screenshot-3.png and b/assets/screenshot-3.png differ
diff --git a/assets/screenshot-4.png b/assets/screenshot-4.png
old mode 100755
new mode 100644
index e2336b2..f1f3015
Binary files a/assets/screenshot-4.png and b/assets/screenshot-4.png differ
diff --git a/assets/screenshot-5.png b/assets/screenshot-5.png
old mode 100755
new mode 100644
index 894d39b..443f575
Binary files a/assets/screenshot-5.png and b/assets/screenshot-5.png differ
diff --git a/assets/screenshot-6.png b/assets/screenshot-6.png
deleted file mode 100644
index b94d0d7..0000000
Binary files a/assets/screenshot-6.png and /dev/null differ
diff --git a/includes/add-embeds.php b/includes/add-embeds.php
index 4422044..7c1e5b7 100644
--- a/includes/add-embeds.php
+++ b/includes/add-embeds.php
@@ -1,45 +1,42 @@
ID, $options['keyword_ident'] . $suffix, false );
if ( isset( $post_meta[0] ) ) {
$html = $post_meta[0];
} else {
- // No meta found, so look for it elsewhere
+ // No meta found, so look for it elsewhere.
$html = ce_get_embed_code( $options['keyword_ident'], $suffix );
}
- // Build the string to search for
+ // Build the string to search for.
$search = $options['opening_ident'] . $options['keyword_ident'] . $full_suffix . $options['closing_ident'];
- // Build the string of code to replace with
+ // Build the string of code to replace with.
$replace = ce_generate_code( $html, $responsive, $max_width );
- // Now modify all references
+ // Now modify all references.
$content = str_replace( $search, $replace, $content );
@@ -110,11 +107,11 @@ function ce_filter( $content ) {
$found_pos = strpos( $content, $options['opening_ident'] . $options['keyword_ident'], $found_pos + 1 );
}
- // Loop around the post content looking for HTTP addresses
+ // Loop around the post content looking for HTTP addresses.
$content = ce_quick_replace( $content, $options, 'http://' );
- // Loop around the post content looking for HTTPS addresses
+ // Loop around the post content looking for HTTPS addresses.
$content = ce_quick_replace( $content, $options, 'https://' );
@@ -125,18 +122,15 @@ function ce_filter( $content ) {
add_filter( 'widget_content', 'ce_filter' );
/**
-* Quick Replace
-*
-* Function to do a quick search/replace of the content
-*
-* @since 2.0
-*
-* @param $content string The content
-* @param $options string The options array
-* @param $search string The string to search for
-* @return string The updated content
-*/
-
+ * Quick Replace
+ *
+ * Function to do a quick search/replace of the content
+ *
+ * @param string $content The content.
+ * @param string $options The options array.
+ * @param string $search The string to search for.
+ * @return string The updated content
+ */
function ce_quick_replace( $content = '', $options = '', $search = '' ) {
$start_pos = strpos( $content, $options['opening_ident'] . $search, 0 );
@@ -163,18 +157,15 @@ function ce_quick_replace( $content = '', $options = '', $search = '' ) {
}
/**
-* Generate Embed Code
-*
-* Function to generate the embed code that will be output
-*
-* @since 2.0
-*
-* @param $html string The embed code (required)
-* @param $responsive string Responsive output required? (optional)
-* @param $max_width string Maximum width of responsive output (optional)
-* @return string The embed code
-*/
-
+ * Generate Embed Code
+ *
+ * Function to generate the embed code that will be output
+ *
+ * @param string $html The embed code (required).
+ * @param string $responsive Responsive output required? (optional).
+ * @param string $max_width Maximum width of responsive output (optional).
+ * @return string The embed code
+ */
function ce_generate_code( $html, $responsive = '', $max_width = '' ) {
$code = "\n";
@@ -203,22 +194,19 @@ function ce_generate_code( $html, $responsive = '', $max_width = '' ) {
}
/**
-* Get the Global Embed Code
-*
-* Function to look for and, if available, return the global embed code
-*
-* @since 1.6
-*
-* @uses ce_report_error Generate an error message
-*
-* @param $ident string The embed code opening identifier
-* @param $suffix string The embed code suffix
-* @return string The embed code (or error)
-*/
-
+ * Get the Global Embed Code
+ *
+ * Function to look for and, if available, return the global embed code
+ *
+ * @uses ce_report_error Generate an error message
+ *
+ * @param string $ident The embed code opening identifier.
+ * @param string $suffix The embed code suffix.
+ * @return string The embed code (or error)
+ */
function ce_get_embed_code( $ident, $suffix ) {
- // Meta was not found in current post so look across meta table - find the number of distinct code results
+ // Meta was not found in current post so look across meta table - find the number of distinct code results.
$meta_name = $ident . $suffix;
global $wpdb;
@@ -227,21 +215,21 @@ function ce_get_embed_code( $ident, $suffix ) {
if ( 0 < $records ) {
- // Results were found
+ // Results were found.
$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
$total_records = $wpdb->num_rows;
if ( 1 === $records ) {
- // Only one unique code result returned so assume this is the global embed
+ // Only one unique code result returned so assume this is the global embed.
foreach ( $meta as $meta_data ) {
$html = $meta_data->meta_value;
}
} else {
- // More than one unique code result returned, so output the list of posts
+ // More than one unique code result returned, so output the list of posts.
/* 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 */
$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 );
@@ -249,7 +237,7 @@ function ce_get_embed_code( $ident, $suffix ) {
}
} else {
- // No meta code was found so write out an error
+ // No meta code was found so write out an error.
/* translators: %s: the embed name */
$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 ) {
}
/**
-* Fetch a file
-*
-* Use WordPress API to fetch a file and check results
-*
-* @since 2.0
-*
-* @param string $filein File name to fetch
-* @param string $header Only get headers?
-* @return string Array containing file contents or false to indicate a failure
-*/
-
+ * Fetch a file
+ *
+ * Use WordPress API to fetch a file and check results
+ *
+ * @param string $filein File name to fetch.
+ * @return string Array containing file contents or false to indicate a failure
+ */
function ce_get_file( $filein ) {
if ( function_exists( 'vip_safe_wp_remote_get' ) ) {
@@ -294,18 +278,15 @@ function ce_get_file( $filein ) {
}
/**
-* Report an error (1.4)
-*
-* Function to report an error
-*
-* @since 1.6
-*
-* @param $error string Error message
-* @param $plugin_name string The name of the plugin
-* @param $echo string True or false, depending on whether you wish to return or echo the results
-* @return string True or the output text
-*/
-
+ * Report an error
+ *
+ * Function to report an error
+ *
+ * @param string $error Error message.
+ * @param string $plugin_name The name of the plugin.
+ * @param string $echo True or false, depending on whether you wish to return or echo the results.
+ * @return string True or the output text
+ */
function ce_report_error( $error, $plugin_name, $echo = true ) {
$output = '
' . $plugin_name . ': ' . $error . "
\n";
@@ -318,4 +299,3 @@ function ce_report_error( $error, $plugin_name, $echo = true ) {
}
}
-
diff --git a/includes/add-scripts.php b/includes/add-scripts.php
index 7d8cd72..91f1748 100644
--- a/includes/add-scripts.php
+++ b/includes/add-scripts.php
@@ -1,23 +1,20 @@
'{{',
@@ -42,11 +40,11 @@ function ce_initialisation() {
'excerpts' => '',
);
- // Merge existing and default options - any missing from existing will take the default settings
+ // Merge existing and default options - any missing from existing will take the default settings.
$new_options = array_merge( $default_array, $options );
- // Update the options, if changed, and return the result
+ // Update the options, if changed, and return the result.
if ( $options !== $new_options ) {
update_option( 'artiss_code_embed', $new_options );
diff --git a/includes/options-screen.php b/includes/options-screen.php
index d6c27dd..3b78961 100644
--- a/includes/options-screen.php
+++ b/includes/options-screen.php
@@ -1,20 +1,20 @@
' . esc_html( __( 'Settings saved.', 'simple-embed-code' ) ) . "
\n";
}
-// Fetch options into an array
+// Fetch options into an array.
$options = get_option( 'artiss_code_embed' );
?>
-
' . esc_html( ucwords( __( 'How to embed', 'simple-embed-code' ) ) ) . "
\n";
diff --git a/includes/search-screen.php b/includes/search-screen.php
index d269e5d..5f2a3cb 100644
--- a/includes/search-screen.php
+++ b/includes/search-screen.php
@@ -1,12 +1,12 @@
@@ -17,7 +17,7 @@
-
@@ -62,9 +62,9 @@
foreach ( $meta as $meta_data ) {
$html = $meta_data->meta_value;
$post_title = $meta_data->post_title;
- $post_id = $meta_data->ID;
+ $post_ident = $meta_data->ID;
- // Switch background colours as the code changes
+ // Switch background colours as the code changes.
if ( $html !== $prev_html ) {
if ( $color === $color1 ) {
@@ -74,7 +74,7 @@
}
echo '
\n";
- echo '| ' . esc_html( $post_title ) . " | \n";
+ echo '' . esc_html( $post_title ) . " | \n";
echo ' | \n";
echo "
\n";
diff --git a/readme.txt b/readme.txt
index 003e363..041f180 100644
--- a/readme.txt
+++ b/readme.txt
@@ -1,11 +1,11 @@
=== Code Embed ===
-Contributors: dartiss
+Contributors: dartiss
Donate link: https://artiss.blog/donate
-Tags: code, embed, html, javascript, script
+Tags: code, embed, html, css, javascript, script
Requires at least: 4.6
-Tested up to: 6.3
+Tested up to: 6.3
Requires PHP: 7.4
-Stable tag: 2.3.4
+Stable tag: 2.3.5
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
@@ -24,51 +24,52 @@ Key features include...
* Search for embedding code via a simple search option
* Add a simple suffix to the embed code to convert videos to responsive output
* Embed an external script directly using just the URL
-* And much, much more!
-
-Iconography is courtesy of the very talented [Janki Rathod](https://www.fiverr.com/jankirathore) ♥️
-
-👉 Please visit the [Github page](https://github.com/dartiss/code-embed "Github") for the latest code development, planned enhancements and known issues 👈
-
-== Getting Started ==
-
-To use this plugin, you need to have custom fields enabled on your site. If you're using the block editor, you may need to switch this on first - please scroll down to the next section to learn how to do this. If you're using the classic editor then you'll find the custom fields at the bottom of the editor screen.
+* And much, much more!
+
+Iconography is courtesy of the very talented [Janki Rathod](https://www.fiverr.com/jankirathore) ♥️
+
+👉 Please visit the [Github page](https://github.com/dartiss/code-embed "Github") for the latest code development, planned enhancements and known issues 👈
+
+== Getting Started ==
+
+To use this plugin, you need to have custom fields enabled on your site. If you're using the block editor, you may need to switch this on first - please scroll down to the next section to learn how to do this. If you're using the classic editor then you'll find the custom fields at the bottom of the editor screen.
+
+Although this plugin works for both posts and pages for simplicity I will simply refer to posts - bear in mind that pages work in the same way.
Once you have custom fields switched on, here's how easy it is to use…
-1. Once you have the plugin installed start a new post or page.
-2. In the `Custom Fields` meta box enter a name of CODE1 and your embed code as the value. Save this.
-3. In your post add `{{CODE1}}` where you wish the embed code to appear.
+1. Once you have the plugin installed start a new post.
+2. Scroll down to the bottom of the screen and look for the "Custom Fields" section.
+2. Under "Add New Custom Field" enter a name of `CODE1` and your embed code as the value
+3. In your post content add `{{CODE1}}` where you wish the embed code to appear.
-And that's it - when the post or page is viewed `{{CODE1}}` will be replaced with the code that you asked to be embedded.
+And that's it - when the post viewed or previewed `{{CODE1}}` will be replaced with the code that you asked to be embedded.
This should get you started - for more information and advanced options please see below.. Alternatively, there's a fantastic guide at [Elftronix](http://www.elftronix.com/free-easy-plugin-add-javascript-to-wordpress-posts-pages/ "Free Easy Plugin! Add Javascript to WordPress Posts & Pages") which I would recommend.
-Although this plugin works for both posts and pages for simplicity I will simply refer to posts - bear in mind that pages work in the same way.
-
-== Using this plugin with the block editor (aka Gutenberg) ==
-
-By default, custom fields are hidden inside the block editor but can be revealed.
-
-1. Edit or create a post
-2. Click the settings button (three dots) in the top, right-hand corner
-3. Go to Preferences
-4. Click the Panels tab
-5. You will find a button to toggle the 'Custom Fields' meta box - make sure this is toggled to "on"
-6. A button should appear titled "Enable & Reload" - you'll need to click on that and wait for the page to reload before the custom fields will appear
-
-Check out the screenshots for how the custom fields should look.
-
-== I can't find the custom fields ==
-
+== Using this plugin with the block editor (aka Gutenberg) ==
+
+By default, custom fields are hidden inside the block editor but can be revealed.
+
+1. Edit or create a post
+2. Click the settings button (three dots) in the top, right-hand corner
+3. Go to Preferences
+4. Click the Panels tab
+5. You will find a button to toggle the 'Custom Fields' meta box - make sure this is toggled to "on"
+6. A button should appear titled "Enable & Reload" - you'll need to click on that and wait for the page to reload before the custom fields will appear
+
+Check out the screenshots for how the custom fields should look.
+
+== I can't find the custom fields ==
+
For block editor users, I'm assuming you've done the above. For classic editor users, the custom fields should be present by default. In all cases they should appear at the bottom of the editor screen.
-If they're not present then you may have a theme or plugin that removes this or may have a problem with your WordPress installation - you will need to try normal diagnostics to try and resolve this, including requesting help on [the WordPress support forum](https://wordpress.org/support/forum/how-to-and-troubleshooting/ "Fixing WordPress Forum").
-
+If they're not present then you may have a theme or plugin that removes this or may have a problem with your WordPress installation - you will need to try the usual diagnostics to try and resolve this, including requesting help on [the WordPress support forum](https://wordpress.org/support/forum/how-to-and-troubleshooting/ "Fixing WordPress Forum").
+
Please bear in mind that the custom fields functionality is part of WordPress so it would be greatly appreciated if you don't give me poor reviews in this situation as, I say, this component is not part of this plugin but, by using it, keeps this plugin simple to use and bloat-free :)
-== The Code Embed Options Screen ==
-
+== The Code Embed Options Screen ==
+
Whilst in WP Admin, if you go to Settings -> Code Embed, you'll be able to access the options that are available for this plugin.
Code embedding is performed via a special keyword that you must use to uniquely identify where you wish the code to appear. This consist of an opening identifier (some that that goes at the beginning), a keyword and then a closing identifier. You may also add a suffix to the end of the keyword if you wish to embed multiple pieces of code within the same post.
@@ -155,14 +156,14 @@ By default embed code will not appear in excerpts. However, you can switch this
== Installation ==
-Code Embed can be found and installed via the Plugin menu within WordPress administration (Plugins -> Add New). Alternatively, it can be downloaded from WordPress.org and installed manually...
-
-1. Upload the entire `simple-embed-code` folder to your `wp-content/plugins/` directory.
-2. Activate the plugin through the 'Plugins' menu in WordPress administration.
-
-Voila! It's ready to go.
+Code Embed can be found and installed via the Plugin menu within WordPress administration (Plugins -> Add New). Alternatively, it can be downloaded from WordPress.org and installed manually...
-== Frequently Asked Questions ==
+1. Upload the entire `simple-embed-code` folder to your `wp-content/plugins/` directory.
+2. Activate the plugin through the 'Plugins' menu in WordPress administration.
+
+Voila! It's ready to go.
+
+== Frequently Asked Questions ==
= My code doesn't work =
@@ -172,53 +173,62 @@ Otherwise, it's likely to be your code and not this plugin. The best way to conf
= What's the maximum size of the embed code that I can save in a custom field? =
-WordPress stores the custom field contents in a MySQL table using the `longtext` format. This can hold over 4 billion characters.
-
-= Is this GDPR compliant? =
-
+WordPress stores the custom field contents in a MySQL table using the `longtext` format. This can hold over 4 billion characters.
+
+= Can I use the same embed name on multiple pages? =
+
+Yes you can. If you wish to share one set of embed code across multiple posts, though, then you need to give it a unique name (see "How to Use Global Embedding", above).
+
+= Is this GDPR compliant? =
+
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.
== Screenshots ==
-1. The custom field meta box with a Code Embed field set up to show some YouTube embed code
-2. Example embed code in a post
-3. The resultant video from the previous example code
-4. The options screen
-5. The search screen, showing search results
-6. The Custom Fields meta-box and the screen switch - both highlighted in red
-
-== Changelog ==
-
-I use semantic versioning, with the first release being 1.0.
-
-= 2.3.4 =
-* Bug: Fixed minor error that occurred due to the removal of the debug code in the last release. Sorry about that.
-
-= 2.3.3 =
-* Enhancement: I've removed the debug code. I allowed to be switched off but I've never used it and it may not have switched off properly anyway. So it's gone
-* Enhancement: Added some additional plugin meta
-
-= 2.3.2 =
-* Bug: Fixed another pesky bug that was affecting embedded URLs. My code to do this was years old and I couldn't understand why I'd written it the way I had. So I've re-written it from scratch
-
-= 2.3.1 =
-* Bug: Fixed a variable naming issue that I may, or may not (I did), have created in the latest release
-
-= 2.3 =
-* 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 ¯\_(ツ)_/¯
-
-= 2.2.2 =
-* 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.
-* Maintenance: Updated all links to artiss.blog and removed donation links. Clickable.
-* Maintenance: Minimum WordPress level is now 4.6 for this plugin, meaning I could remove various pieces of code. Strong and stable.
+1. The options screen
+2. The custom field meta box with a Code Embed field set up to show some YouTube embed code
+3. Example embed code in a post
+4. The block editor Settings screen showing the Custom field switch at the bottom
+5. The search screen showing the results of a search for {{CODE1}}
+
+== Changelog ==
+
+I use semantic versioning, with the first release being 1.0.
+
+= 2.3.5 =
+* Enhancement: Cleared up a big batch of code quality issues. Now it ticks all the boxes for both the WordPress and VIP rulesets in PHPCS.
+* Enhancement: A new, richer, header has been added to the plugin file.
+* Enhancement: The plugin version number is now used as a revision for the script queueing - this means that it be cached by the browser until the plugin release changes.
+* Enhancement: Lots of changes made to the README - hopeful it should read easier than before!
+
+= 2.3.4 =
+* Bug: Fixed minor error that occurred due to the removal of the debug code in the last release. Sorry about that.
+
+= 2.3.3 =
+* Enhancement: I've removed the debug code. I allowed to be switched off but I've never used it and it may not have switched off properly anyway. So it's gone
+* Enhancement: Added some additional plugin meta
+
+= 2.3.2 =
+* Bug: Fixed another pesky bug that was affecting embedded URLs. My code to do this was years old and I couldn't understand why I'd written it the way I had. So I've re-written it from scratch
+
+= 2.3.1 =
+* Bug: Fixed a variable naming issue that I may, or may not (I did), have created in the latest release
+
+= 2.3 =
+* 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 ¯\_(ツ)_/¯
+
+= 2.2.2 =
+* 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.
+* Maintenance: Updated all links to artiss.blog and removed donation links. Clickable.
+* Maintenance: Minimum WordPress level is now 4.6 for this plugin, meaning I could remove various pieces of code. Strong and stable.
* Maintenance: Lots of language updates, many of which are a consequence of the move to WordPress 4.6 (including removal of language files and links, etc). Verbacious.
= 2.2.1 =
@@ -307,5 +317,5 @@ versions of this plugin
== Upgrade Notice ==
-= 2.3.4 =
-* Minor bug fix
\ No newline at end of file
+= 2.3.5 =
+* Assorted minor enhancements - mainly code quality
\ No newline at end of file
diff --git a/simple-code-embed.php b/simple-code-embed.php
index 2a62243..45ac757 100644
--- a/simple-code-embed.php
+++ b/simple-code-embed.php
@@ -1,17 +1,32 @@