Shortcoder - Version 4.1

Version Description

  • New: Import/export feature for shortcodes.
  • Fix: Visual editor is now disabled by default.
  • Fix: Added instructions in admin page.
Download this release

Release Info

Developer vaakash
Plugin Icon 128x128 Shortcoder
Version 4.1
Comparing to
See all releases

Code changes from version 4.0.3 to 4.1

admin/css/style.css CHANGED
@@ -318,6 +318,27 @@ h1.sc_title .title-count {
318
  margin-right: 5px;
319
  }
320
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
321
  .rate_link{
322
  float: right;
323
  }
@@ -348,6 +369,18 @@ h1.sc_title .title-count {
348
  color: #000;
349
  }
350
 
 
 
 
 
 
 
 
 
 
 
 
 
351
  @keyframes spin {
352
  from {transform:rotate(0deg);}
353
  to {transform:rotate(360deg);}
318
  margin-right: 5px;
319
  }
320
 
321
+ #import_form{
322
+ display: none;
323
+ }
324
+
325
+ .sc_note{
326
+ background: #f5f9f9;
327
+ padding: 10px;
328
+ color: #009688;
329
+ border-radius: 5px;
330
+ position: relative;
331
+ padding-left: 38px;
332
+ box-shadow: 0 2px 1px -2px;
333
+ }
334
+ .sc_note:before {
335
+ content: "\f348";
336
+ font-family: dashicons;
337
+ position: absolute;
338
+ left: 10px;
339
+ font-size: 18px;
340
+ }
341
+
342
  .rate_link{
343
  float: right;
344
  }
369
  color: #000;
370
  }
371
 
372
+ .button em {
373
+ display: none;
374
+ }
375
+
376
+ .button:hover em {
377
+ display: inline-block;
378
+ }
379
+
380
+ .fright{
381
+ float: right;
382
+ }
383
+
384
  @keyframes spin {
385
  from {transform:rotate(0deg);}
386
  to {transform:rotate(360deg);}
admin/js/script.js CHANGED
@@ -104,6 +104,9 @@ $(document).ready(function(){
104
  return '<button class="button button-primary sc_insert_params"><span class="dashicons dashicons-plus"></span> Insert shortcode paramerters <span class="dashicons dashicons-arrow-down"></span></button>';
105
  });
106
  $( '.params_wrap' ).appendTo( 'body' );
 
 
 
107
  });
108
 
109
  $( document ).on( 'click', '.sc_insert_params', function(e){
@@ -154,5 +157,18 @@ $(document).ready(function(){
154
  $( '.sort_icon' ).toggleClass( 'dashicons-arrow-up-alt' );
155
  });
156
 
 
 
 
 
 
 
 
 
 
 
 
 
 
157
  });
158
  })( jQuery );
104
  return '<button class="button button-primary sc_insert_params"><span class="dashicons dashicons-plus"></span> Insert shortcode paramerters <span class="dashicons dashicons-arrow-down"></span></button>';
105
  });
106
  $( '.params_wrap' ).appendTo( 'body' );
107
+ $( '.quicktags-toolbar' ).append(function(){
108
+ return '<a href="#" class="ed_button button button-small fright sc_enable_vedit" title="Enable visual editor"><span class="dashicons dashicons-visibility"></span></a>';
109
+ });
110
  });
111
 
112
  $( document ).on( 'click', '.sc_insert_params', function(e){
157
  $( '.sort_icon' ).toggleClass( 'dashicons-arrow-up-alt' );
158
  });
159
 
160
+ $( document ).on( 'change', '#import', function(){
161
+
162
+ if( confirm( $( '.import_desc' ).text() ) ){
163
+ $( '#import_form' ).submit();
164
+ }
165
+
166
+ });
167
+
168
+ $( document ).on( 'click', '.sc_enable_vedit', function(e){
169
+ e.preventDefault();
170
+ window.location = window.location + '&visual_edit=1';
171
+ });
172
+
173
  });
174
  })( jQuery );
admin/sc-admin.php CHANGED
@@ -83,13 +83,26 @@ class Shortcoder_Admin{
83
 
84
  public static function list_shortcodes(){
85
 
 
 
86
  $shortcodes = Shortcoder::list_all();
87
  $g = self::clean_get();
88
 
89
  echo '<h3 class="page_title">' . __( 'List of shortcodes created', 'shortcoder' );
90
  echo '<span class="sc_menu">';
 
 
 
 
 
 
 
 
 
91
  echo '<button class="button sort_btn" title="' . __( 'Sort list', 'shortcoder' ) . '"><span class="dashicons dashicons-menu"></span> <span class="dashicons dashicons-arrow-down-alt sort_icon"></span></button>';
 
92
  echo '<a href="' . self::get_link(array( 'action' => 'new' )) . '" class="button button-primary sc_new_btn"><span class="dashicons dashicons-plus"></span> ' . __( 'Create a new shortcode', 'shortcoder' ) . '</a>';
 
93
  echo '</span>';
94
  echo '</h3>';
95
 
@@ -136,7 +149,7 @@ class Shortcoder_Admin{
136
  }
137
  echo '</ul>';
138
 
139
-
140
 
141
  }
142
 
@@ -183,15 +196,18 @@ class Shortcoder_Admin{
183
 
184
  echo '<div class="sc_section">';
185
  echo '<label for="sc_name">' . __( 'Name', 'shortcoder' ) . '</label>';
186
- echo '<div class="sc_name_wrap"><input type="text" id="sc_name" name="sc_name" value="' . esc_attr( $sc_name ) . '" class="widefat" required="required" ' . ( ( $action == 'edit' ) ? 'readonly="readonly"' : 'placeholder="' . __( 'Enter a name for the shortcode, case sensitive', 'shortcoder' ) . '"' ) . ' pattern="[a-zA-z0-9 \-]+" title="' . __( 'Allowed characters A to Z, a to z, 0 to 9, hyphens, underscores and space', 'shortcoder' ) . '" />';
187
  echo ( $action == 'edit' ) ? '<div class="copy_shortcode">Your shortcode is - <strong contenteditable>' . self::get_shortcode( $sc_name ) . '</strong></div>' : '';
 
188
  echo '</div></div>';
189
 
190
  echo '<div class="sc_section">';
191
  echo '<label for="sc_content">' . __( 'Shortcode content', 'shortcoder' ) . '</label>';
192
- wp_editor( $values[ 'content' ], 'sc_content', array( 'wpautop'=> false, 'textarea_rows'=> 12 ) );
193
  echo '</div>';
194
 
 
 
195
  echo '<h4>' . __( 'Settings', 'shortcoder' ) . '</h4>';
196
  echo '<div class="sc_section">';
197
  echo '<label><input type="checkbox" name="sc_disable" value="1" ' . checked( $values[ 'disabled' ], '1', false ) . '/> ' . __( 'Temporarily disable this shortcode', 'shortcoder' ) . '</label>';
83
 
84
  public static function list_shortcodes(){
85
 
86
+ Shortcoder_Import::check_import();
87
+
88
  $shortcodes = Shortcoder::list_all();
89
  $g = self::clean_get();
90
 
91
  echo '<h3 class="page_title">' . __( 'List of shortcodes created', 'shortcoder' );
92
  echo '<span class="sc_menu">';
93
+
94
+ echo '<label for="import" class="button"><span class="dashicons dashicons-upload"></span><em>' . __( 'Import shortcodes', 'shortcoder' ) . '</em></label>';
95
+
96
+ echo '<a href="' . self::get_link(array(
97
+ 'action' => 'sc_export',
98
+ '_wpnonce' => wp_create_nonce( 'sc_export_data' )
99
+ ), 'admin-ajax.php' ) . '" class="button"><span class="dashicons dashicons-download"></span><em>' . __( 'Export shortcodes', 'shortcoder' ) . '</em></a>';
100
+
101
+
102
  echo '<button class="button sort_btn" title="' . __( 'Sort list', 'shortcoder' ) . '"><span class="dashicons dashicons-menu"></span> <span class="dashicons dashicons-arrow-down-alt sort_icon"></span></button>';
103
+
104
  echo '<a href="' . self::get_link(array( 'action' => 'new' )) . '" class="button button-primary sc_new_btn"><span class="dashicons dashicons-plus"></span> ' . __( 'Create a new shortcode', 'shortcoder' ) . '</a>';
105
+
106
  echo '</span>';
107
  echo '</h3>';
108
 
149
  }
150
  echo '</ul>';
151
 
152
+ Shortcoder_Import::import_form();
153
 
154
  }
155
 
196
 
197
  echo '<div class="sc_section">';
198
  echo '<label for="sc_name">' . __( 'Name', 'shortcoder' ) . '</label>';
199
+ echo '<div class="sc_name_wrap"><input type="text" id="sc_name" name="sc_name" value="' . esc_attr( $sc_name ) . '" class="widefat" required="required" ' . ( ( $action == 'edit' ) ? 'readonly="readonly"' : 'placeholder="' . __( 'Enter a name for the shortcode, case sensitive', 'shortcoder' ) . '"' ) . ' pattern="[a-zA-z0-9 \-]+" />';
200
  echo ( $action == 'edit' ) ? '<div class="copy_shortcode">Your shortcode is - <strong contenteditable>' . self::get_shortcode( $sc_name ) . '</strong></div>' : '';
201
+ echo ( $action != 'edit' ) ? '<div class="copy_shortcode">' . __( 'Allowed characters A to Z, a to z, 0 to 9, hyphens, underscores and space', 'shortcoder' ) . '</div>' : '';
202
  echo '</div></div>';
203
 
204
  echo '<div class="sc_section">';
205
  echo '<label for="sc_content">' . __( 'Shortcode content', 'shortcoder' ) . '</label>';
206
+ wp_editor( $values[ 'content' ], 'sc_content', array( 'wpautop'=> false, 'textarea_rows'=> 15, 'tinymce' => isset( $g[ 'visual_edit' ] ) ) );
207
  echo '</div>';
208
 
209
+ echo '<p class="sc_note">' . __( 'Note: You can use any HTML, JavaScript, CSS as shortcode content. Shortcoder does not manipulate the shortcode content. What you provide above is what you get as output. Please verify the shortcode content for any syntax or JavaScript errors.', 'shortcoder' ) . '</p>';
210
+
211
  echo '<h4>' . __( 'Settings', 'shortcoder' ) . '</h4>';
212
  echo '<div class="sc_section">';
213
  echo '<label><input type="checkbox" name="sc_disable" value="1" ' . checked( $values[ 'disabled' ], '1', false ) . '/> ' . __( 'Temporarily disable this shortcode', 'shortcoder' ) . '</label>';
includes/import.php ADDED
@@ -0,0 +1,110 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Shortcoder_Import{
4
+
5
+ public static function init(){
6
+
7
+ add_action( 'wp_ajax_sc_export', array( __CLASS__, 'do_export' ) );
8
+
9
+ }
10
+
11
+ public static function import_form(){
12
+
13
+ echo '<form method="post" enctype="multipart/form-data" id="import_form">';
14
+ echo '<p class="import_desc"> ' . __( 'Are you sure want to import shortcodes ?', 'shortcoder' ) . '</p>';
15
+ echo '<input type="file" name="import" id="import" accept="text/plain"/>';
16
+ wp_nonce_field( 'sc_import_data' );
17
+ echo '<input type="submit" />';
18
+ echo '</form>';
19
+
20
+ }
21
+
22
+ public static function check_import(){
23
+
24
+ if( isset( $_POST ) && !empty( $_FILES[ 'import' ][ 'tmp_name' ] ) ){
25
+
26
+ check_admin_referer( 'sc_import_data' );
27
+
28
+ $file = wp_import_handle_upload();
29
+
30
+ if ( isset( $file['error'] ) ){
31
+ self::print_notice( __( 'Failed to import file. Error: ', 'shortcoder' ) . $file['error'] );
32
+ return false;
33
+ }
34
+
35
+ $file_id = absint( $file['id'] );
36
+ $file_path = get_attached_file( $file_id );
37
+
38
+ self::do_import( $file_path );
39
+
40
+ }
41
+
42
+ }
43
+
44
+ public static function do_import( $file_path ){
45
+
46
+ if ( !is_file( $file_path ) ){
47
+ self::print_notice( __( 'Uploaded file does not exist for import. ', 'shortcoder' ) . $file_path );
48
+ }
49
+
50
+ $imported_json = file_get_contents( $file_path );
51
+ $imported_data = json_decode( $imported_json, true );
52
+
53
+ if( $imported_data && !empty( $imported_data ) ){
54
+
55
+ $shortcodes = Shortcoder::list_all();
56
+ $import_count = 0;
57
+
58
+ if( isset( $imported_data[ 'shortcodes' ] ) ){
59
+
60
+ foreach( $imported_data[ 'shortcodes' ] as $name => $content ){
61
+ $shortcodes[ $name ] = wp_parse_args( $content, Shortcoder::defaults() );
62
+ $import_count++;
63
+ }
64
+
65
+ if( update_option( 'shortcoder_data', $shortcodes ) ){
66
+ self::print_notice( $import_count . __( ' shortcodes imported successfully !', 'shortcoder' ), 'success' );
67
+ }else{
68
+ self::print_notice( __( 'shortcodes are not updated because all the shortcodes remain the same.', 'shortcoder' ) );
69
+ return false;
70
+ }
71
+
72
+ }
73
+
74
+ }else{
75
+ self:print_notice( __( 'Failed to decode JSON in imported data.', 'shortcoder' ) );
76
+ }
77
+
78
+ }
79
+
80
+ public static function do_export(){
81
+
82
+ check_admin_referer( 'sc_export_data' );
83
+
84
+ $export_file_name = 'shortcoder export ' . date( 'm/d/Y' ) . '.txt';
85
+ $shortcodes = Shortcoder::list_all();
86
+
87
+ $to_export = array(
88
+ 'shortcodes' => $shortcodes
89
+ );
90
+
91
+ $export_json = json_encode( $to_export );
92
+
93
+ header('Content-Disposition: attachment; filename="' . $export_file_name . '"');
94
+ header('Content-Type: text/plain');
95
+ header('Content-Length: ' . strlen( $export_json ));
96
+ header('Connection: close');
97
+
98
+ echo $export_json;
99
+
100
+ }
101
+
102
+ public static function print_notice( $msg, $type = 'error' ){
103
+ echo '<div class="notice notice-' . $type . ' is-dismissible"><p>' . $msg . '</p></div>';
104
+ }
105
+
106
+ }
107
+
108
+ Shortcoder_Import::init();
109
+
110
+ ?>
readme.txt CHANGED
@@ -6,8 +6,8 @@ Tags: shortcode, html, javascript, shortcodes, short code, posts, pages, widgets
6
  Donate link: https://goo.gl/qMF3iE
7
  License: GPLv2 or later
8
  Requires at least: 3.3
9
- Tested up to: 4.8
10
- Stable tag: 4.0.3
11
 
12
  Create custom "Shortcodes" easily for HTML, JavaScript snippets and use the shortcodes within posts, pages & widgets.
13
 
@@ -91,6 +91,11 @@ Note: When you disable a shortcode, the shortcode will not be executed in the pa
91
 
92
  == Changelog ==
93
 
 
 
 
 
 
94
  = 4.0.3 =
95
  * New: Added feature to sort created shortcodes list.
96
  * Fix: HTML errors in admin page
6
  Donate link: https://goo.gl/qMF3iE
7
  License: GPLv2 or later
8
  Requires at least: 3.3
9
+ Tested up to: 4.8.1
10
+ Stable tag: 4.1
11
 
12
  Create custom "Shortcodes" easily for HTML, JavaScript snippets and use the shortcodes within posts, pages & widgets.
13
 
91
 
92
  == Changelog ==
93
 
94
+ = 4.1 =
95
+ * New: Import/export feature for shortcodes.
96
+ * Fix: Visual editor is now disabled by default.
97
+ * Fix: Added instructions in admin page.
98
+
99
  = 4.0.3 =
100
  * New: Added feature to sort created shortcodes list.
101
  * Fix: HTML errors in admin page
shortcoder.php CHANGED
@@ -4,11 +4,11 @@ Plugin Name: Shortcoder
4
  Plugin URI: https://www.aakashweb.com/
5
  Description: Shortcoder is a plugin which allows to create a custom shortcode and store HTML, Javascript and other snippets in it. So if that shortcode is used in any post or pages, then the code stored in the shortcode get executed in that place. You can create a shortcode for Youtube videos, adsense ads, buttons and more.
6
  Author: Aakash Chakravarthy
7
- Version: 4.0.3
8
  Author URI: https://www.aakashweb.com/
9
  */
10
 
11
- define( 'SC_VERSION', '4.0.3');
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' ) );
@@ -43,6 +43,7 @@ class Shortcoder{
43
  public static function includes(){
44
 
45
  include_once( SC_PATH . 'includes/metadata.php' );
 
46
  include_once( SC_PATH . 'admin/sc-admin.php' );
47
 
48
  }
4
  Plugin URI: https://www.aakashweb.com/
5
  Description: Shortcoder is a plugin which allows to create a custom shortcode and store HTML, Javascript and other snippets in it. So if that shortcode is used in any post or pages, then the code stored in the shortcode get executed in that place. You can create a shortcode for Youtube videos, adsense ads, buttons and more.
6
  Author: Aakash Chakravarthy
7
+ Version: 4.1
8
  Author URI: https://www.aakashweb.com/
9
  */
10
 
11
+ define( 'SC_VERSION', '4.1');
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' ) );
43
  public static function includes(){
44
 
45
  include_once( SC_PATH . 'includes/metadata.php' );
46
+ include_once( SC_PATH . 'includes/import.php' );
47
  include_once( SC_PATH . 'admin/sc-admin.php' );
48
 
49
  }