Version Description
- New: Default values can now be provided to custom parameters.
- Fix: Script tags, custom field placeholder and backslash being stripped after saving the shortcode sometimes.
- Fix: Rel attribute being modified for links.
- New: Added "Manage shortcodes" link to plugin list page for easy access after activation.
Download this release
Release Info
Developer | vaakash |
Plugin | Shortcoder |
Version | 5.2 |
Comparing to | |
See all releases |
Code changes from version 5.1 to 5.2
- admin/admin.php +7 -0
- admin/css/style-insert.css +28 -0
- admin/css/style.css +22 -1
- admin/edit.php +13 -7
- admin/insert.php +19 -3
- admin/js/script.js +14 -6
- readme.txt +7 -1
- shortcoder.php +43 -16
admin/admin.php
CHANGED
@@ -18,6 +18,8 @@ class SC_Admin{
|
|
18 |
|
19 |
add_action( 'wp_ajax_sc_admin_ajax', array( __class__, 'admin_ajax' ) );
|
20 |
|
|
|
|
|
21 |
}
|
22 |
|
23 |
public static function register_post_type(){
|
@@ -243,6 +245,11 @@ class SC_Admin{
|
|
243 |
|
244 |
}
|
245 |
|
|
|
|
|
|
|
|
|
|
|
246 |
public static function clean_get(){
|
247 |
|
248 |
foreach( $_GET as $k => $v ){
|
18 |
|
19 |
add_action( 'wp_ajax_sc_admin_ajax', array( __class__, 'admin_ajax' ) );
|
20 |
|
21 |
+
add_filter( 'plugin_action_links_' . SC_BASE_NAME, array( __CLASS__, 'action_links' ) );
|
22 |
+
|
23 |
}
|
24 |
|
25 |
public static function register_post_type(){
|
245 |
|
246 |
}
|
247 |
|
248 |
+
public static function action_links( $links ){
|
249 |
+
array_unshift( $links, '<a href="'. esc_url( admin_url( 'edit.php?post_type=shortcoder') ) .'">Manage shortcodes</a>' );
|
250 |
+
return $links;
|
251 |
+
}
|
252 |
+
|
253 |
public static function clean_get(){
|
254 |
|
255 |
foreach( $_GET as $k => $v ){
|
admin/css/style-insert.css
CHANGED
@@ -206,6 +206,34 @@ p .button {
|
|
206 |
text-align: center;
|
207 |
}
|
208 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
209 |
/** Footer **/
|
210 |
.footer_thanks {
|
211 |
margin: 20px 0 0 0;
|
206 |
text-align: center;
|
207 |
}
|
208 |
|
209 |
+
.ufw{
|
210 |
+
text-decoration: none;
|
211 |
+
float: right;
|
212 |
+
color: #000;
|
213 |
+
position: relative;
|
214 |
+
}
|
215 |
+
.ufw:hover{
|
216 |
+
text-decoration: underline;;
|
217 |
+
}
|
218 |
+
.ufw i{
|
219 |
+
opacity: 0.5;
|
220 |
+
}
|
221 |
+
.ufw span{
|
222 |
+
display: none;
|
223 |
+
position: absolute;
|
224 |
+
right: 0;
|
225 |
+
top: 150%;
|
226 |
+
text-align: right;
|
227 |
+
background: #333;
|
228 |
+
color: #fff;
|
229 |
+
padding: 5px 10px;
|
230 |
+
border-radius: 5px;
|
231 |
+
box-shadow: 0 2px 5px -2px rgba(0, 0, 0, 0.5);
|
232 |
+
}
|
233 |
+
.ufw:hover span{
|
234 |
+
display: block;
|
235 |
+
}
|
236 |
+
|
237 |
/** Footer **/
|
238 |
.footer_thanks {
|
239 |
margin: 20px 0 0 0;
|
admin/css/style.css
CHANGED
@@ -139,7 +139,7 @@
|
|
139 |
cursor: auto !important;
|
140 |
width: 330px;
|
141 |
}
|
142 |
-
.sc_params_form h4{
|
143 |
margin: 0 0 15px 0;
|
144 |
}
|
145 |
.sc_params_form p{
|
@@ -174,6 +174,9 @@
|
|
174 |
#edit-slug-buttons{
|
175 |
margin-left: 6px;
|
176 |
}
|
|
|
|
|
|
|
177 |
|
178 |
#misc-publishing-actions #visibility{
|
179 |
display: none;
|
@@ -307,6 +310,24 @@
|
|
307 |
.feedback a:hover{
|
308 |
text-decoration: underline;
|
309 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
310 |
.stars {
|
311 |
display: inline-flex;
|
312 |
line-height: 1;
|
139 |
cursor: auto !important;
|
140 |
width: 330px;
|
141 |
}
|
142 |
+
.sc_params_form h4:first-child{
|
143 |
margin: 0 0 15px 0;
|
144 |
}
|
145 |
.sc_params_form p{
|
174 |
#edit-slug-buttons{
|
175 |
margin-left: 6px;
|
176 |
}
|
177 |
+
#edit-slug-box{
|
178 |
+
margin-bottom: 1.5em;
|
179 |
+
}
|
180 |
|
181 |
#misc-publishing-actions #visibility{
|
182 |
display: none;
|
310 |
.feedback a:hover{
|
311 |
text-decoration: underline;
|
312 |
}
|
313 |
+
.feedback .adjust_icons .dashicons{
|
314 |
+
font-size: 14px;
|
315 |
+
height: 14px;
|
316 |
+
margin-top: 3px;
|
317 |
+
}
|
318 |
+
.feedback .ufw{
|
319 |
+
background: linear-gradient(180deg, #2196F3, #58a4e1);
|
320 |
+
color: #fff;
|
321 |
+
}
|
322 |
+
.feedback .ufw a{
|
323 |
+
color: #fff;
|
324 |
+
}
|
325 |
+
.feedback .ufw span{
|
326 |
+
opacity: 0.8;
|
327 |
+
display: block;
|
328 |
+
font-style: italic;
|
329 |
+
margin-top: 5px;
|
330 |
+
}
|
331 |
.stars {
|
332 |
display: inline-flex;
|
333 |
line-height: 1;
|
admin/edit.php
CHANGED
@@ -12,7 +12,7 @@ class SC_Admin_Edit{
|
|
12 |
|
13 |
add_action( 'save_post_' . SC_POST_TYPE, array( __class__, 'save_post' ) );
|
14 |
|
15 |
-
add_filter( 'wp_insert_post_data' , array( __class__, 'before_insert_post' ) ,
|
16 |
|
17 |
add_action( 'admin_enqueue_scripts', array( __class__, 'enqueue_scripts' ) );
|
18 |
|
@@ -150,6 +150,10 @@ class SC_Admin_Edit{
|
|
150 |
$post[ 'post_title' ] = $post[ 'post_name' ];
|
151 |
}
|
152 |
|
|
|
|
|
|
|
|
|
153 |
return $post;
|
154 |
}
|
155 |
|
@@ -194,9 +198,9 @@ class SC_Admin_Edit{
|
|
194 |
if( $editor[ 'active' ] == 'code' ){
|
195 |
echo '<div class="sc_cm_menu"></div>';
|
196 |
$content = user_can_richedit() ? esc_textarea( $post->post_content ) : $post->post_content;
|
197 |
-
echo '<textarea name="
|
198 |
}else{
|
199 |
-
wp_editor( $post->post_content, '
|
200 |
'wpautop'=> false,
|
201 |
'textarea_rows'=> 20,
|
202 |
'tinymce' => ( $editor[ 'active' ] == 'visual' )
|
@@ -271,6 +275,8 @@ class SC_Admin_Edit{
|
|
271 |
echo '<li><span class="dashicons dashicons-list-view"></span>' . __( 'Custom parameter', 'shortcoder' ) . '<ul>';
|
272 |
echo '<li class="sc_params_form"><h4>' . __( 'Enter custom parameter name', 'shortcoder' ) . '</h4>';
|
273 |
echo '<input type="text" class="sc_cp_box widefat" pattern="[a-zA-Z0-9]+"/>';
|
|
|
|
|
274 |
echo '<button class="button sc_cp_btn">' . __( 'Insert parameter', 'shortcoder' ) . '</button>';
|
275 |
echo '<p class="sc_cp_info"><small>' . __( 'Only alphabets and numbers allowed. Custom parameters are case insensitive', 'shortcoder' ) . '</small></p></li>';
|
276 |
echo '</ul></li>';
|
@@ -314,10 +320,10 @@ class SC_Admin_Edit{
|
|
314 |
echo '<div class="feedback">';
|
315 |
echo '<ul>
|
316 |
<li><a href="https://wordpress.org/support/plugin/shortcoder/reviews/?rate=5#new-post" target="_blank">Rate and review</a><div class="stars"><span class="dashicons dashicons-star-filled"></span><span class="dashicons dashicons-star-filled"></span><span class="dashicons dashicons-star-filled"></span><span class="dashicons dashicons-star-filled"></span><span class="dashicons dashicons-star-filled"></span></div></li>
|
317 |
-
<li><a href="https://www.aakashweb.com/forum/discuss/wordpress-plugins/shortcoder/#new-post" target="_blank">
|
318 |
-
<li><a href="https://
|
319 |
-
<li><a href="https://www.aakashweb.com/docs/shortcoder-doc/" target="_blank">FAQ</a></li>
|
320 |
<li><a href="https://www.aakashweb.com/wordpress-plugins/" target="_blank">More plugins</a></li>
|
|
|
321 |
</ul>';
|
322 |
echo '</div>';
|
323 |
}
|
@@ -325,7 +331,7 @@ class SC_Admin_Edit{
|
|
325 |
public static function footer_text( $text ){
|
326 |
|
327 |
if( SC_Admin::is_sc_admin_page() ){
|
328 |
-
return '<span 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
|
329 |
}
|
330 |
|
331 |
return $text;
|
12 |
|
13 |
add_action( 'save_post_' . SC_POST_TYPE, array( __class__, 'save_post' ) );
|
14 |
|
15 |
+
add_filter( 'wp_insert_post_data' , array( __class__, 'before_insert_post' ) , 99, 1 );
|
16 |
|
17 |
add_action( 'admin_enqueue_scripts', array( __class__, 'enqueue_scripts' ) );
|
18 |
|
150 |
$post[ 'post_title' ] = $post[ 'post_name' ];
|
151 |
}
|
152 |
|
153 |
+
if( $_POST && isset( $_POST[ 'sc_content' ] ) ){
|
154 |
+
$post[ 'post_content' ] = $_POST[ 'sc_content' ];
|
155 |
+
}
|
156 |
+
|
157 |
return $post;
|
158 |
}
|
159 |
|
198 |
if( $editor[ 'active' ] == 'code' ){
|
199 |
echo '<div class="sc_cm_menu"></div>';
|
200 |
$content = user_can_richedit() ? esc_textarea( $post->post_content ) : $post->post_content;
|
201 |
+
echo '<textarea name="sc_content" id="sc_content" class="sc_cm_content">' . $content . '</textarea>';
|
202 |
}else{
|
203 |
+
wp_editor( $post->post_content, 'sc_content', array(
|
204 |
'wpautop'=> false,
|
205 |
'textarea_rows'=> 20,
|
206 |
'tinymce' => ( $editor[ 'active' ] == 'visual' )
|
275 |
echo '<li><span class="dashicons dashicons-list-view"></span>' . __( 'Custom parameter', 'shortcoder' ) . '<ul>';
|
276 |
echo '<li class="sc_params_form"><h4>' . __( 'Enter custom parameter name', 'shortcoder' ) . '</h4>';
|
277 |
echo '<input type="text" class="sc_cp_box widefat" pattern="[a-zA-Z0-9]+"/>';
|
278 |
+
echo '<h4>' . __( 'Default value', 'shortcoder' ) . '</h4>';
|
279 |
+
echo '<input type="text" class="sc_cp_default widefat"/>';
|
280 |
echo '<button class="button sc_cp_btn">' . __( 'Insert parameter', 'shortcoder' ) . '</button>';
|
281 |
echo '<p class="sc_cp_info"><small>' . __( 'Only alphabets and numbers allowed. Custom parameters are case insensitive', 'shortcoder' ) . '</small></p></li>';
|
282 |
echo '</ul></li>';
|
320 |
echo '<div class="feedback">';
|
321 |
echo '<ul>
|
322 |
<li><a href="https://wordpress.org/support/plugin/shortcoder/reviews/?rate=5#new-post" target="_blank">Rate and review</a><div class="stars"><span class="dashicons dashicons-star-filled"></span><span class="dashicons dashicons-star-filled"></span><span class="dashicons dashicons-star-filled"></span><span class="dashicons dashicons-star-filled"></span><span class="dashicons dashicons-star-filled"></span></div></li>
|
323 |
+
<li><a href="https://www.aakashweb.com/forum/discuss/wordpress-plugins/shortcoder/#new-post" target="_blank">Support forum</a> / <a href="https://www.aakashweb.com/docs/shortcoder-doc/" target="_blank">FAQ</a></li>
|
324 |
+
<li class="adjust_icons"><a href="https://twitter.com/aakashweb" target="_blank">Follow on Twitter <span class="dashicons dashicons-twitter"></span></a> <a href="https://facebook.com/aakashweb" target="_blank">Facebook <span class="dashicons dashicons-facebook"></span></a></li>
|
|
|
325 |
<li><a href="https://www.aakashweb.com/wordpress-plugins/" target="_blank">More plugins</a></li>
|
326 |
+
<li class="ufw"><a href="https://www.aakashweb.com/wordpress-plugins/ultimate-floating-widgets/" target="_blank"><i>Check out</i> - <strong>Ultimate floating widgets</strong></a><span>A WordPress plugin to create floating widgets from the same developer</span></li>
|
327 |
</ul>';
|
328 |
echo '</div>';
|
329 |
}
|
331 |
public static function footer_text( $text ){
|
332 |
|
333 |
if( SC_Admin::is_sc_admin_page() ){
|
334 |
+
return '<span 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.</span>';
|
335 |
}
|
336 |
|
337 |
return $text;
|
admin/insert.php
CHANGED
@@ -12,6 +12,7 @@
|
|
12 |
|
13 |
<div class="sc_menu">
|
14 |
<input type="search" class="sc_search" placeholder="Search ..." />
|
|
|
15 |
</div>
|
16 |
|
17 |
<div class="sc_list">
|
@@ -27,8 +28,23 @@ if( empty( $shortcodes ) ){
|
|
27 |
$id = $options[ 'id' ];
|
28 |
$content = $options[ 'content' ];
|
29 |
$settings = $options[ 'settings' ];
|
|
|
30 |
|
31 |
-
preg_match_all( '/%%
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
|
33 |
$enclosed_sc = strpos( $content, '$$enclosed_content$$' ) !== false ? 'true' : 'false';
|
34 |
|
@@ -47,12 +63,12 @@ if( empty( $shortcodes ) ){
|
|
47 |
|
48 |
echo '<div class="sc_options">';
|
49 |
|
50 |
-
if( !empty( $params
|
51 |
echo '<h4>' . __( 'Available parameters', 'shortcoder' ) . ': </h4>';
|
52 |
echo '<div class="sc_params_wrap">';
|
53 |
$temp = array();
|
54 |
|
55 |
-
foreach( $params
|
56 |
$cleaned = str_replace( '%', '', $v );
|
57 |
if( !in_array( $cleaned, $temp ) ){
|
58 |
array_push( $temp, $cleaned );
|
12 |
|
13 |
<div class="sc_menu">
|
14 |
<input type="search" class="sc_search" placeholder="Search ..." />
|
15 |
+
<a href="https://www.aakashweb.com/wordpress-plugins/ultimate-floating-widgets/" target="_blank" class="ufw"><i>Check out</i> : Ultimate floating widgets<span>A WordPress plugin to create floating widgets.</span></a>
|
16 |
</div>
|
17 |
|
18 |
<div class="sc_list">
|
28 |
$id = $options[ 'id' ];
|
29 |
$content = $options[ 'content' ];
|
30 |
$settings = $options[ 'settings' ];
|
31 |
+
$params = array();
|
32 |
|
33 |
+
preg_match_all( '/%%(.*?)%%/', $content, $matches );
|
34 |
+
|
35 |
+
$cp_data = $matches[1];
|
36 |
+
|
37 |
+
if( !empty( $cp_data ) ){
|
38 |
+
foreach( $cp_data as $data ){
|
39 |
+
$colon_pos = strpos( $data, ':' );
|
40 |
+
if( $colon_pos === false ){
|
41 |
+
array_push( $params, trim( $data ) );
|
42 |
+
}else{
|
43 |
+
$cp_name = substr( $data, 0, $colon_pos );
|
44 |
+
array_push( $params, trim( $cp_name ) );
|
45 |
+
}
|
46 |
+
}
|
47 |
+
}
|
48 |
|
49 |
$enclosed_sc = strpos( $content, '$$enclosed_content$$' ) !== false ? 'true' : 'false';
|
50 |
|
63 |
|
64 |
echo '<div class="sc_options">';
|
65 |
|
66 |
+
if( !empty( $params ) ){
|
67 |
echo '<h4>' . __( 'Available parameters', 'shortcoder' ) . ': </h4>';
|
68 |
echo '<div class="sc_params_wrap">';
|
69 |
$temp = array();
|
70 |
|
71 |
+
foreach( $params as $k => $v ){
|
72 |
$cleaned = str_replace( '%', '', $v );
|
73 |
if( !in_array( $cleaned, $temp ) ){
|
74 |
array_push( $temp, $cleaned );
|
admin/js/script.js
CHANGED
@@ -7,7 +7,7 @@ $(document).ready(function(){
|
|
7 |
|
8 |
load_cm_sc_mode();
|
9 |
|
10 |
-
window.sc_cm = CodeMirror.fromTextArea(document.getElementById('
|
11 |
lineNumbers: true,
|
12 |
mode: 'sc_mode',
|
13 |
indentWithTabs: false,
|
@@ -32,9 +32,11 @@ $(document).ready(function(){
|
|
32 |
var version = '<small>v' + SC_VARS['sc_version'] + '</small>';
|
33 |
$('.wp-heading-inline').append(version);
|
34 |
|
35 |
-
|
36 |
|
37 |
}
|
|
|
|
|
38 |
}
|
39 |
|
40 |
$('.sc_params_list').appendTo('body');
|
@@ -79,7 +81,7 @@ $(document).ready(function(){
|
|
79 |
if(stream.match(/\$\$[a-z0-9A-Z:_]+\$\$/)){
|
80 |
return 'number sc_param';
|
81 |
}
|
82 |
-
if(stream.match(
|
83 |
return 'atom sc_param';
|
84 |
}
|
85 |
stream.next();
|
@@ -95,10 +97,14 @@ $(document).ready(function(){
|
|
95 |
|
96 |
var add_top_coffee_btn = function(){
|
97 |
|
98 |
-
$('#screen-meta-links').prepend('<div class="screen-meta-toggle ie_top_link hide-if-no-js"><button aria-controls="import-export-tab" aria-expanded="false" class="show-settings button">Import / Export</button></div>');
|
99 |
-
|
100 |
$('#screen-meta-links').prepend('<div class="screen-meta-toggle cfe_top_link"><a class="show-settings button" href="https://www.paypal.me/vaakash/" target="_blank">Buy me a Coffee</a></div>');
|
101 |
|
|
|
|
|
|
|
|
|
|
|
|
|
102 |
$('#screen-meta').append('<div id="import-export-tab" class="hidden"></div>');
|
103 |
|
104 |
$('#ie_content > div').appendTo('#import-export-tab');
|
@@ -148,11 +154,13 @@ $(document).ready(function(){
|
|
148 |
$('.sc_cp_btn').on('click', function(){
|
149 |
|
150 |
var $cp_box = $('.sc_cp_box');
|
|
|
151 |
var $cp_info = $('.sc_cp_info');
|
152 |
var param_val = $cp_box.val().trim();
|
|
|
153 |
|
154 |
if( param_val != '' && $cp_box[0].checkValidity() ){
|
155 |
-
insert_in_editor('%%' + param_val + '%%');
|
156 |
$cp_info.removeClass('red');
|
157 |
close_params_list();
|
158 |
}else{
|
7 |
|
8 |
load_cm_sc_mode();
|
9 |
|
10 |
+
window.sc_cm = CodeMirror.fromTextArea(document.getElementById('sc_content'), {
|
11 |
lineNumbers: true,
|
12 |
mode: 'sc_mode',
|
13 |
indentWithTabs: false,
|
32 |
var version = '<small>v' + SC_VARS['sc_version'] + '</small>';
|
33 |
$('.wp-heading-inline').append(version);
|
34 |
|
35 |
+
add_top_import_export_btn();
|
36 |
|
37 |
}
|
38 |
+
|
39 |
+
add_top_coffee_btn();
|
40 |
}
|
41 |
|
42 |
$('.sc_params_list').appendTo('body');
|
81 |
if(stream.match(/\$\$[a-z0-9A-Z:_]+\$\$/)){
|
82 |
return 'number sc_param';
|
83 |
}
|
84 |
+
if(stream.match(/%%.*?%%/)){
|
85 |
return 'atom sc_param';
|
86 |
}
|
87 |
stream.next();
|
97 |
|
98 |
var add_top_coffee_btn = function(){
|
99 |
|
|
|
|
|
100 |
$('#screen-meta-links').prepend('<div class="screen-meta-toggle cfe_top_link"><a class="show-settings button" href="https://www.paypal.me/vaakash/" target="_blank">Buy me a Coffee</a></div>');
|
101 |
|
102 |
+
}
|
103 |
+
|
104 |
+
var add_top_import_export_btn = function(){
|
105 |
+
|
106 |
+
$('#screen-meta-links').prepend('<div class="screen-meta-toggle ie_top_link hide-if-no-js"><button aria-controls="import-export-tab" aria-expanded="false" class="show-settings button">Import / Export</button></div>');
|
107 |
+
|
108 |
$('#screen-meta').append('<div id="import-export-tab" class="hidden"></div>');
|
109 |
|
110 |
$('#ie_content > div').appendTo('#import-export-tab');
|
154 |
$('.sc_cp_btn').on('click', function(){
|
155 |
|
156 |
var $cp_box = $('.sc_cp_box');
|
157 |
+
var $cp_default = $('.sc_cp_default');
|
158 |
var $cp_info = $('.sc_cp_info');
|
159 |
var param_val = $cp_box.val().trim();
|
160 |
+
var default_val = $cp_default.val().trim();
|
161 |
|
162 |
if( param_val != '' && $cp_box[0].checkValidity() ){
|
163 |
+
insert_in_editor('%%' + param_val + ':' + default_val + '%%');
|
164 |
$cp_info.removeClass('red');
|
165 |
close_params_list();
|
166 |
}else{
|
readme.txt
CHANGED
@@ -8,7 +8,7 @@ License: GPLv2 or later
|
|
8 |
Requires PHP: 5.3
|
9 |
Requires at least: 4.4
|
10 |
Tested up to: 5.3.2
|
11 |
-
Stable tag: 5.
|
12 |
|
13 |
Create custom "Shortcodes" easily for HTML, JavaScript snippets and use the shortcodes within posts, pages & widgets.
|
14 |
|
@@ -88,6 +88,12 @@ Please check the following if you notice that the shortcode content is not print
|
|
88 |
|
89 |
== Changelog ==
|
90 |
|
|
|
|
|
|
|
|
|
|
|
|
|
91 |
= 5.1 =
|
92 |
* New: Import/Export link added to the shortcoder list page.
|
93 |
* Fix: `empty()` was throwing error at some places for users using PHP 5.5 below as function return value was passed to it.
|
8 |
Requires PHP: 5.3
|
9 |
Requires at least: 4.4
|
10 |
Tested up to: 5.3.2
|
11 |
+
Stable tag: 5.2
|
12 |
|
13 |
Create custom "Shortcodes" easily for HTML, JavaScript snippets and use the shortcodes within posts, pages & widgets.
|
14 |
|
88 |
|
89 |
== Changelog ==
|
90 |
|
91 |
+
= 5.2 =
|
92 |
+
* New: Default values can now be provided to custom parameters.
|
93 |
+
* Fix: Script tags, custom field placeholder and backslash being stripped after saving the shortcode sometimes.
|
94 |
+
* Fix: Rel attribute being modified for links.
|
95 |
+
* New: Added "Manage shortcodes" link to plugin list page for easy access after activation.
|
96 |
+
|
97 |
= 5.1 =
|
98 |
* New: Import/Export link added to the shortcoder list page.
|
99 |
* Fix: `empty()` was throwing error at some places for users using PHP 5.5 below as function return value was passed to it.
|
shortcoder.php
CHANGED
@@ -4,11 +4,11 @@ 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 |
*/
|
10 |
|
11 |
-
define( 'SC_VERSION', '5.
|
12 |
define( 'SC_PATH', plugin_dir_path( __FILE__ ) ); // All have trailing slash
|
13 |
define( 'SC_URL', plugin_dir_url( __FILE__ ) );
|
14 |
define( 'SC_ADMIN_URL', trailingslashit( plugin_dir_url( __FILE__ ) . 'admin' ) );
|
@@ -203,16 +203,43 @@ final class Shortcoder{
|
|
203 |
$keys = array();
|
204 |
$values = array();
|
205 |
|
206 |
-
|
207 |
-
|
208 |
-
|
|
|
|
|
|
|
|
|
209 |
}
|
210 |
|
211 |
-
|
212 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
213 |
|
214 |
-
|
215 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
216 |
|
217 |
return $content;
|
218 |
|
@@ -246,15 +273,15 @@ final class Shortcoder{
|
|
246 |
public static function replace_custom_fields( $content ){
|
247 |
|
248 |
global $post;
|
249 |
-
|
250 |
preg_match_all('/\$\$[^\s]+\$\$/', $content, $matches );
|
251 |
-
|
252 |
$cf_tags = $matches[0];
|
253 |
-
|
254 |
if( empty( $cf_tags ) ){
|
255 |
return $content;
|
256 |
}
|
257 |
-
|
258 |
foreach( $cf_tags as $tag ){
|
259 |
|
260 |
if( strpos( $tag, 'custom_field:' ) === false ){
|
@@ -262,15 +289,15 @@ final class Shortcoder{
|
|
262 |
}
|
263 |
|
264 |
preg_match( '/:[^\s\$]+/', $tag, $match );
|
265 |
-
|
266 |
if( empty( $match ) ){
|
267 |
continue;
|
268 |
}
|
269 |
-
|
270 |
$match = substr( $match[0], 1 );
|
271 |
$value = get_post_meta( $post->ID, $match, true );
|
272 |
$content = str_replace( $tag, $value, $content );
|
273 |
-
|
274 |
}
|
275 |
|
276 |
return $content;
|
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.2
|
8 |
Author URI: https://www.aakashweb.com/
|
9 |
*/
|
10 |
|
11 |
+
define( 'SC_VERSION', '5.2' );
|
12 |
define( 'SC_PATH', plugin_dir_path( __FILE__ ) ); // All have trailing slash
|
13 |
define( 'SC_URL', plugin_dir_url( __FILE__ ) );
|
14 |
define( 'SC_ADMIN_URL', trailingslashit( plugin_dir_url( __FILE__ ) . 'admin' ) );
|
203 |
$keys = array();
|
204 |
$values = array();
|
205 |
|
206 |
+
preg_match_all('/%%(.*?)%%/', $content, $matches);
|
207 |
+
|
208 |
+
$cp_tags = $matches[0];
|
209 |
+
$cp_data = $matches[1];
|
210 |
+
|
211 |
+
if( empty( $matches[0] ) ){
|
212 |
+
return $content;
|
213 |
}
|
214 |
|
215 |
+
$to_replace = array();
|
216 |
+
|
217 |
+
foreach( $cp_data as $data ){
|
218 |
+
|
219 |
+
$data = trim( $data );
|
220 |
+
$colon_pos = strpos( $data, ':' );
|
221 |
+
$cp_name = '';
|
222 |
+
|
223 |
+
if( $colon_pos === false ){
|
224 |
+
$cp_name = $data;
|
225 |
+
}else{
|
226 |
+
$cp_name = substr( $data, 0, $colon_pos );
|
227 |
+
}
|
228 |
|
229 |
+
if( array_key_exists( $cp_name, $params ) ){
|
230 |
+
array_push( $to_replace, $params[ $cp_name ] );
|
231 |
+
}else{
|
232 |
+
if( $colon_pos === false ){
|
233 |
+
array_push( $to_replace, '' ); # Has no default parameter
|
234 |
+
}else{
|
235 |
+
$cp_value = substr( $data, $colon_pos+1 );
|
236 |
+
array_push( $to_replace, $cp_value );
|
237 |
+
}
|
238 |
+
}
|
239 |
+
|
240 |
+
}
|
241 |
+
|
242 |
+
$content = str_ireplace( $cp_tags, $to_replace, $content );
|
243 |
|
244 |
return $content;
|
245 |
|
273 |
public static function replace_custom_fields( $content ){
|
274 |
|
275 |
global $post;
|
276 |
+
|
277 |
preg_match_all('/\$\$[^\s]+\$\$/', $content, $matches );
|
278 |
+
|
279 |
$cf_tags = $matches[0];
|
280 |
+
|
281 |
if( empty( $cf_tags ) ){
|
282 |
return $content;
|
283 |
}
|
284 |
+
|
285 |
foreach( $cf_tags as $tag ){
|
286 |
|
287 |
if( strpos( $tag, 'custom_field:' ) === false ){
|
289 |
}
|
290 |
|
291 |
preg_match( '/:[^\s\$]+/', $tag, $match );
|
292 |
+
|
293 |
if( empty( $match ) ){
|
294 |
continue;
|
295 |
}
|
296 |
+
|
297 |
$match = substr( $match[0], 1 );
|
298 |
$value = get_post_meta( $post->ID, $match, true );
|
299 |
$content = str_replace( $tag, $value, $content );
|
300 |
+
|
301 |
}
|
302 |
|
303 |
return $content;
|