Version Description
Download this release
Release Info
Developer | vaakash |
Plugin | Shortcoder |
Version | 5.4 |
Comparing to | |
See all releases |
Code changes from version 5.3.4 to 5.4
- admin/edit.php +10 -29
- admin/insert.php +2 -0
- admin/js/blocks/shortcoder.js +2 -1
- admin/js/script.js +69 -39
- readme.txt +12 -3
- shortcoder.php +13 -3
admin/edit.php
CHANGED
@@ -218,39 +218,20 @@ class SC_Admin_Edit{
|
|
218 |
$settings = Shortcoder::get_sc_settings( $post->ID );
|
219 |
$editor = self::editor_props( $settings );
|
220 |
|
221 |
-
wp_localize_script( 'sc-admin-js', 'SC_EDITOR',
|
|
|
|
|
222 |
|
223 |
if( $editor[ 'active' ] != 'code' ){
|
224 |
return false;
|
225 |
}
|
226 |
|
227 |
-
$
|
228 |
-
$
|
229 |
-
'
|
230 |
-
|
231 |
-
),
|
232 |
-
'js' => array(
|
233 |
-
'codemirror.min.js',
|
234 |
-
'mode/htmlmixed/htmlmixed.min.js',
|
235 |
-
'mode/css/css.min.js',
|
236 |
-
'mode/xml/xml.min.js',
|
237 |
-
'mode/javascript/javascript.min.js',
|
238 |
-
'addon/selection/active-line.min.js',
|
239 |
-
'addon/mode/overlay.min.js'
|
240 |
-
)
|
241 |
-
);
|
242 |
|
243 |
-
|
244 |
-
foreach( $files as $index => $file ){
|
245 |
-
$url = $cm_cdn_url . $file;
|
246 |
-
$id = 'sc-cm-' . $index;
|
247 |
-
if( $type == 'css' ){
|
248 |
-
wp_enqueue_style( $id, $url, array(), SC_VERSION );
|
249 |
-
}else{
|
250 |
-
wp_enqueue_script( $id, $url, array( 'sc-admin-js' ), SC_VERSION );
|
251 |
-
}
|
252 |
-
}
|
253 |
-
}
|
254 |
|
255 |
}
|
256 |
|
@@ -272,11 +253,11 @@ class SC_Admin_Edit{
|
|
272 |
|
273 |
echo '<li><span class="dashicons dashicons-list-view"></span>' . __( 'Custom parameter', 'shortcoder' ) . '<ul>';
|
274 |
echo '<li class="sc_params_form"><h4>' . __( 'Enter custom parameter name', 'shortcoder' ) . '</h4>';
|
275 |
-
echo '<input type="text" class="sc_cp_box widefat" pattern="[a-zA-Z0-9_]+"/>';
|
276 |
echo '<h4>' . __( 'Default value', 'shortcoder' ) . '</h4>';
|
277 |
echo '<input type="text" class="sc_cp_default widefat"/>';
|
278 |
echo '<button class="button sc_cp_btn">' . __( 'Insert parameter', 'shortcoder' ) . '</button>';
|
279 |
-
echo '<p class="sc_cp_info"><small>' . __( 'Only alphabets, numbers and
|
280 |
echo '</ul></li>';
|
281 |
|
282 |
echo '<li><span class="dashicons dashicons-screenoptions"></span>' . __( 'Custom Fields', 'shortcoder' ) . '<ul>';
|
218 |
$settings = Shortcoder::get_sc_settings( $post->ID );
|
219 |
$editor = self::editor_props( $settings );
|
220 |
|
221 |
+
wp_localize_script( 'sc-admin-js', 'SC_EDITOR', array(
|
222 |
+
'active' => $editor[ 'active' ]
|
223 |
+
));
|
224 |
|
225 |
if( $editor[ 'active' ] != 'code' ){
|
226 |
return false;
|
227 |
}
|
228 |
|
229 |
+
$cm_settings = array();
|
230 |
+
$cm_settings[ 'codeEditor' ] = wp_enqueue_code_editor(array(
|
231 |
+
'type' => 'htmlmixed'
|
232 |
+
));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
233 |
|
234 |
+
wp_localize_script( 'sc-admin-js', 'SC_CODEMIRROR', $cm_settings );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
235 |
|
236 |
}
|
237 |
|
253 |
|
254 |
echo '<li><span class="dashicons dashicons-list-view"></span>' . __( 'Custom parameter', 'shortcoder' ) . '<ul>';
|
255 |
echo '<li class="sc_params_form"><h4>' . __( 'Enter custom parameter name', 'shortcoder' ) . '</h4>';
|
256 |
+
echo '<input type="text" class="sc_cp_box widefat" pattern="[a-zA-Z0-9_-]+"/>';
|
257 |
echo '<h4>' . __( 'Default value', 'shortcoder' ) . '</h4>';
|
258 |
echo '<input type="text" class="sc_cp_default widefat"/>';
|
259 |
echo '<button class="button sc_cp_btn">' . __( 'Insert parameter', 'shortcoder' ) . '</button>';
|
260 |
+
echo '<p class="sc_cp_info"><small>' . __( 'Only alphabets, numbers, underscores and hyphens are allowed. Custom parameters are case insensitive', 'shortcoder' ) . '</small></p></li>';
|
261 |
echo '</ul></li>';
|
262 |
|
263 |
echo '<li><span class="dashicons dashicons-screenoptions"></span>' . __( 'Custom Fields', 'shortcoder' ) . '<ul>';
|
admin/insert.php
CHANGED
@@ -123,5 +123,7 @@ echo '</div>';
|
|
123 |
|
124 |
<div class="footer_thanks">Thanks for using <a href="https://www.aakashweb.com/wordpress-plugins/shortcoder/" target="_blank">Shortcoder</a> • Please <a href="https://wordpress.org/support/plugin/shortcoder/reviews/?rate=5#new-post" target="_blank">rate 5 stars</a> and spread the word.</div>
|
125 |
|
|
|
|
|
126 |
</body>
|
127 |
</html>
|
123 |
|
124 |
<div class="footer_thanks">Thanks for using <a href="https://www.aakashweb.com/wordpress-plugins/shortcoder/" target="_blank">Shortcoder</a> • Please <a href="https://wordpress.org/support/plugin/shortcoder/reviews/?rate=5#new-post" target="_blank">rate 5 stars</a> and spread the word.</div>
|
125 |
|
126 |
+
<?php do_action( 'sc_do_insert_popup_footer' ); ?>
|
127 |
+
|
128 |
</body>
|
129 |
</html>
|
admin/js/blocks/shortcoder.js
CHANGED
@@ -24,7 +24,8 @@
|
|
24 |
'value': props.attributes.text,
|
25 |
'style': {
|
26 |
'font-family': 'monospace',
|
27 |
-
'font-size': '15px'
|
|
|
28 |
}
|
29 |
}),
|
30 |
el( 'button', {
|
24 |
'value': props.attributes.text,
|
25 |
'style': {
|
26 |
'font-family': 'monospace',
|
27 |
+
'font-size': '15px',
|
28 |
+
'padding': '10px'
|
29 |
}
|
30 |
}),
|
31 |
el( 'button', {
|
admin/js/script.js
CHANGED
@@ -3,25 +3,12 @@ $(document).ready(function(){
|
|
3 |
|
4 |
var init = function(){
|
5 |
|
6 |
-
if(window.SC_EDITOR == 'code'){
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
lineNumbers: true,
|
13 |
-
mode: 'sc_mode',
|
14 |
-
indentWithTabs: false,
|
15 |
-
lineWrapping: true,
|
16 |
-
styleActiveLine: true,
|
17 |
-
htmlMode: true
|
18 |
-
});
|
19 |
-
sc_cm.setSize( null, 500 );
|
20 |
-
sc_cm.on('change', function(){
|
21 |
-
sc_cm.save();
|
22 |
-
});
|
23 |
-
}else{
|
24 |
-
$('.sc_editor_toolbar').append('<p>Unable to load code editor. Please check console for errors or try deactivating other plugin/themes.</p>');
|
25 |
}
|
26 |
|
27 |
$('.sc_editor_toolbar').appendTo('.sc_cm_menu');
|
@@ -57,8 +44,7 @@ $(document).ready(function(){
|
|
57 |
}
|
58 |
|
59 |
var insert_in_editor = function(data){
|
60 |
-
|
61 |
-
if(window.SC_EDITOR == 'code'){
|
62 |
var doc = window.sc_cm.getDoc();
|
63 |
doc.replaceRange(data, doc.getCursor());
|
64 |
}else{
|
@@ -78,29 +64,73 @@ $(document).ready(function(){
|
|
78 |
document.body.removeChild(el);
|
79 |
};
|
80 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
81 |
var load_cm_sc_mode = function(){
|
82 |
-
|
83 |
-
if(typeof CodeMirror
|
|
|
84 |
return false;
|
85 |
}
|
86 |
|
87 |
-
CodeMirror.
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
98 |
}
|
99 |
-
|
100 |
-
|
101 |
-
};
|
102 |
-
|
103 |
-
|
|
|
|
|
|
|
|
|
|
|
104 |
}
|
105 |
|
106 |
var close_params_list = function(){
|
3 |
|
4 |
var init = function(){
|
5 |
|
6 |
+
if(typeof window.SC_EDITOR !== 'undefined' && typeof window.SC_EDITOR.active !== 'undefined' && window.SC_EDITOR.active == 'code'){
|
7 |
+
|
8 |
+
var codemirror_loaded = load_codemirror();
|
9 |
+
|
10 |
+
if(!codemirror_loaded){
|
11 |
+
$('.sc_editor_toolbar').append('<p>Unable to load code editor. Please check browser console (press Ctrl+Shift+J) for errors or try deactivating any code editor related plugin/themes.</p>');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
}
|
13 |
|
14 |
$('.sc_editor_toolbar').appendTo('.sc_cm_menu');
|
44 |
}
|
45 |
|
46 |
var insert_in_editor = function(data){
|
47 |
+
if(window.SC_EDITOR.active == 'code'){
|
|
|
48 |
var doc = window.sc_cm.getDoc();
|
49 |
doc.replaceRange(data, doc.getCursor());
|
50 |
}else{
|
64 |
document.body.removeChild(el);
|
65 |
};
|
66 |
|
67 |
+
var load_codemirror = function(){
|
68 |
+
|
69 |
+
if(typeof window.SC_CODEMIRROR === 'undefined'){
|
70 |
+
console.error('Shortcoder: Codemirror settings are not loaded');
|
71 |
+
return false;
|
72 |
+
}
|
73 |
+
|
74 |
+
if(typeof window.wp === 'undefined' || typeof window.wp.codeEditor === 'undefined'){
|
75 |
+
console.error('Shortcoder: codeEditor namespace is not available');
|
76 |
+
return false;
|
77 |
+
}
|
78 |
+
|
79 |
+
var sc_mode_loaded = load_cm_sc_mode();
|
80 |
+
var mode = sc_mode_loaded ? 'sc_mode' : 'htmlmixed';
|
81 |
+
|
82 |
+
wp.codeEditor.defaultSettings.codemirror['mode'] = mode;
|
83 |
+
|
84 |
+
var editor = wp.codeEditor.initialize(document.getElementById('sc_content'), window.SC_CODEMIRROR);
|
85 |
+
|
86 |
+
editor.codemirror.setSize( null, 500 );
|
87 |
+
editor.codemirror.on('change', function(){
|
88 |
+
editor.codemirror.save();
|
89 |
+
});
|
90 |
+
|
91 |
+
window.sc_cm = editor.codemirror;
|
92 |
+
|
93 |
+
return true;
|
94 |
+
|
95 |
+
}
|
96 |
+
|
97 |
var load_cm_sc_mode = function(){
|
98 |
+
|
99 |
+
if(typeof wp.CodeMirror === 'undefined'){
|
100 |
+
console.error('Shortcoder: CodeMirror library is not loaded/available');
|
101 |
return false;
|
102 |
}
|
103 |
|
104 |
+
if(typeof wp.CodeMirror.overlayMode === 'undefined'){
|
105 |
+
console.error('Shortcoder: CodeMirror overlay method is not available');
|
106 |
+
return false;
|
107 |
+
}
|
108 |
+
|
109 |
+
try{
|
110 |
+
wp.CodeMirror.defineMode('sc_mode', function(config, parserConfig){
|
111 |
+
var sc_overlay = {
|
112 |
+
token: function(stream, state){
|
113 |
+
if(stream.match(/\$\$[a-z0-9A-Z:_]+\$\$/)){
|
114 |
+
return 'number sc_param';
|
115 |
+
}
|
116 |
+
if(stream.match(/%%.*?%%/)){
|
117 |
+
return 'atom sc_param';
|
118 |
+
}
|
119 |
+
if(stream.match(/\[(.+?)?\](?:(.+?)?\[\/\])?/)){
|
120 |
+
return 'string sc_param';
|
121 |
+
}
|
122 |
+
stream.next();
|
123 |
}
|
124 |
+
};
|
125 |
+
return wp.CodeMirror.overlayMode(wp.CodeMirror.getMode(config, parserConfig.backdrop || 'htmlmixed'), sc_overlay);
|
126 |
+
});
|
127 |
+
}catch(error){
|
128 |
+
console.error('Shortcoder: Unable to load shortcoder mode.', error);
|
129 |
+
return false;
|
130 |
+
}
|
131 |
+
|
132 |
+
return true;
|
133 |
+
|
134 |
}
|
135 |
|
136 |
var close_params_list = function(){
|
readme.txt
CHANGED
@@ -6,9 +6,9 @@ Tags: shortcode, html, javascript, shortcodes, snippets, posts, pages, widgets,
|
|
6 |
Donate link: https://www.paypal.me/vaakash/
|
7 |
License: GPLv2 or later
|
8 |
Requires PHP: 5.3
|
9 |
-
Requires at least: 4.
|
10 |
-
Tested up to: 5.
|
11 |
-
Stable tag: 5.
|
12 |
|
13 |
Create custom "Shortcodes" easily for HTML, JavaScript snippets and use the shortcodes within posts, pages & widgets.
|
14 |
|
@@ -106,6 +106,15 @@ No, right now the plugin supports only HTML, Javascript and CSS as shortcode con
|
|
106 |
|
107 |
## Changelog
|
108 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
109 |
### 5.3.4
|
110 |
* New: Tested with WordPress 5.6
|
111 |
* Fix: Handle warning with `trim` while fetching page metadata at some pages.
|
6 |
Donate link: https://www.paypal.me/vaakash/
|
7 |
License: GPLv2 or later
|
8 |
Requires PHP: 5.3
|
9 |
+
Requires at least: 4.9.0
|
10 |
+
Tested up to: 5.7
|
11 |
+
Stable tag: 5.4
|
12 |
|
13 |
Create custom "Shortcodes" easily for HTML, JavaScript snippets and use the shortcodes within posts, pages & widgets.
|
14 |
|
106 |
|
107 |
## Changelog
|
108 |
|
109 |
+
### 5.4
|
110 |
+
* New: Code editor is now loaded locally and not from cloudflare.
|
111 |
+
* New: Code editor now shows hints and highlights any syntax error.
|
112 |
+
* New: Hyphens can now be used in shortcode custom parameters.
|
113 |
+
* Fix: Handle scenario where shortcode attribute is received as a string sometimes.
|
114 |
+
* Fix: Notice where `wp_localize_script` was called incorrectly.
|
115 |
+
* Fix: Handle scenario where HTML is passed as shortcode parameter.
|
116 |
+
* New: WordPress requirement changed from 4.4 to 4.9
|
117 |
+
|
118 |
### 5.3.4
|
119 |
* New: Tested with WordPress 5.6
|
120 |
* Fix: Handle warning with `trim` while fetching page metadata at some pages.
|
shortcoder.php
CHANGED
@@ -4,13 +4,13 @@ Plugin Name: Shortcoder
|
|
4 |
Plugin URI: https://www.aakashweb.com/wordpress-plugins/shortcoder/
|
5 |
Description: Shortcoder plugin allows to create a custom shortcodes for HTML, JavaScript and other snippets. Now the shortcodes can be used in posts/pages and the snippet will be replaced in place.
|
6 |
Author: Aakash Chakravarthy
|
7 |
-
Version: 5.
|
8 |
Author URI: https://www.aakashweb.com/
|
9 |
Text Domain: shortcoder
|
10 |
Domain Path: /languages
|
11 |
*/
|
12 |
|
13 |
-
define( 'SC_VERSION', '5.
|
14 |
define( 'SC_PATH', plugin_dir_path( __FILE__ ) ); // All have trailing slash
|
15 |
define( 'SC_URL', plugin_dir_url( __FILE__ ) );
|
16 |
define( 'SC_ADMIN_URL', trailingslashit( plugin_dir_url( __FILE__ ) . 'admin' ) );
|
@@ -48,6 +48,7 @@ final class Shortcoder{
|
|
48 |
|
49 |
public static function execute_shortcode( $atts, $enclosed_content = null ){
|
50 |
|
|
|
51 |
$shortcodes = self::get_shortcodes();
|
52 |
|
53 |
if( empty( $shortcodes ) ){
|
@@ -204,7 +205,7 @@ final class Shortcoder{
|
|
204 |
|
205 |
$params = array_change_key_case( $params, CASE_LOWER );
|
206 |
|
207 |
-
preg_match_all('/%%([a-zA-Z0-9_]+)\:?(.*?)%%/', $content, $matches);
|
208 |
|
209 |
$cp_tags = $matches[0];
|
210 |
$cp_names = $matches[1];
|
@@ -219,6 +220,15 @@ final class Shortcoder{
|
|
219 |
|
220 |
if( array_key_exists( $name, $params ) ){
|
221 |
$value = $params[ $name ];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
222 |
}
|
223 |
|
224 |
if( empty( $value ) ){
|
4 |
Plugin URI: https://www.aakashweb.com/wordpress-plugins/shortcoder/
|
5 |
Description: Shortcoder plugin allows to create a custom shortcodes for HTML, JavaScript and other snippets. Now the shortcodes can be used in posts/pages and the snippet will be replaced in place.
|
6 |
Author: Aakash Chakravarthy
|
7 |
+
Version: 5.4
|
8 |
Author URI: https://www.aakashweb.com/
|
9 |
Text Domain: shortcoder
|
10 |
Domain Path: /languages
|
11 |
*/
|
12 |
|
13 |
+
define( 'SC_VERSION', '5.4' );
|
14 |
define( 'SC_PATH', plugin_dir_path( __FILE__ ) ); // All have trailing slash
|
15 |
define( 'SC_URL', plugin_dir_url( __FILE__ ) );
|
16 |
define( 'SC_ADMIN_URL', trailingslashit( plugin_dir_url( __FILE__ ) . 'admin' ) );
|
48 |
|
49 |
public static function execute_shortcode( $atts, $enclosed_content = null ){
|
50 |
|
51 |
+
$atts = (array) $atts;
|
52 |
$shortcodes = self::get_shortcodes();
|
53 |
|
54 |
if( empty( $shortcodes ) ){
|
205 |
|
206 |
$params = array_change_key_case( $params, CASE_LOWER );
|
207 |
|
208 |
+
preg_match_all('/%%([a-zA-Z0-9_\-]+)\:?(.*?)%%/', $content, $matches);
|
209 |
|
210 |
$cp_tags = $matches[0];
|
211 |
$cp_names = $matches[1];
|
220 |
|
221 |
if( array_key_exists( $name, $params ) ){
|
222 |
$value = $params[ $name ];
|
223 |
+
|
224 |
+
// Handle scenario when the attributes are added with paragraph tags by autop
|
225 |
+
if( substr( $value, 0, 4 ) == '</p>' ){
|
226 |
+
$value = substr( $value, 4 );
|
227 |
+
if( substr( $value, -3 ) == '<p>' ){
|
228 |
+
$value = substr( $value, 0, -3 );
|
229 |
+
}
|
230 |
+
}
|
231 |
+
|
232 |
}
|
233 |
|
234 |
if( empty( $value ) ){
|