PluginProbe ʕ •ᴥ•ʔ
Shortcoder — Create Shortcodes for Anything / 6.0
Shortcoder — Create Shortcodes for Anything v6.0
trunk 3.0 3.0.1 3.1 3.2 3.3 3.4 3.4.1 4.0 4.0.1 4.0.2 4.0.3 4.1 4.1.1 4.1.2 4.1.3 4.1.4 4.1.5 4.1.6 4.1.7 4.1.8 4.1.9 4.2 4.3 4.4 4.5 4.6 5.0 5.0.1 5.0.2 5.0.3 5.0.4 5.1 5.2 5.2.1 5.3 5.3.1 5.3.2 5.3.3 5.3.4 5.4 5.5 5.6 5.7 5.8 6.0 6.1 6.2 6.3 6.3.1 6.3.2 6.4 6.5 6.5.1 6.5.2 6.5.3
shortcoder / admin / edit.php
shortcoder / admin Last commit date
css 3 years ago font 3 years ago images 3 years ago js 3 years ago admin.php 3 years ago edit.php 3 years ago form.php 3 years ago insert.php 3 years ago manage.php 3 years ago settings.php 3 years ago tools.php 3 years ago
edit.php
380 lines
1 <?php
2
3 if( ! defined( 'ABSPATH' ) ) exit;
4
5 class SC_Admin_Edit{
6
7 public static function init(){
8
9 add_action( 'edit_form_after_title', array( __CLASS__, 'after_title' ) );
10
11 add_action( 'add_meta_boxes', array( __CLASS__, 'add_meta_boxes' ) );
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
19 add_filter( 'admin_footer_text', array( __CLASS__, 'footer_text' ) );
20
21 }
22
23 public static function after_title( $post ){
24
25 if( $post->post_type != SC_POST_TYPE ){
26 return;
27 }
28
29 $settings = Shortcoder::get_sc_settings( $post->ID );
30
31 echo '<div id="sc_name">';
32 echo '<input type="text" class="widefat" title="' . esc_attr__( 'Name of the shortcode. Allowed characters are alphabets, numbers, hyphens and underscore.', 'shortcoder' ) . '" value="' . esc_attr( $post->post_name ) . '" name="post_name" id="post_name" pattern="[a-zA-z0-9\-_]+" required placeholder="' . esc_attr__( 'Enter shortcode name', 'shortcoder' ) . '" />';
33 echo '</div>';
34
35 echo '<div id="edit-slug-box">';
36 echo '<strong>' . esc_html__( 'Your shortcode', 'shortcoder' ) . ': </strong>';
37 echo '<code class="sc_preview_text">' . esc_html( Shortcoder::get_sc_tag( $post->ID ) ) . '</code>';
38 echo '<span id="edit-slug-buttons"><button type="button" class="sc_copy button button-small"><span class="dashicons dashicons-yes"></span> ' . esc_html__( 'Copy', 'shortcoder' ) . '</button></span>';
39 echo '<a href="#sc_mb_settings" class="sc_settings_link">' . esc_html__( 'Settings', 'shortcoder' ) . '</a>';
40 echo '</div>';
41
42 // Editor
43 self::editor( $post, $settings );
44
45 // Hidden section
46 self::hidden_section( $post, $settings );
47
48 }
49
50 public static function add_meta_boxes(){
51
52 add_meta_box( 'sc_mb_settings', __( 'Shortcode settings', 'shortcoder' ), array( __CLASS__, 'settings_form' ), SC_POST_TYPE, 'normal', 'default' );
53
54 add_meta_box( 'sc_mb_links', __( 'WordPress News', 'shortcoder' ), array( __CLASS__, 'feedback' ), SC_POST_TYPE, 'side', 'default' );
55
56 add_meta_box( 'sc_mb_more_plugins', __( 'More plugins from us', 'shortcoder' ), array( __CLASS__, 'more_plugins' ), SC_POST_TYPE, 'side', 'default' );
57
58 remove_meta_box( 'slugdiv', SC_POST_TYPE, 'normal' );
59
60 remove_meta_box( 'commentstatusdiv', SC_POST_TYPE, 'normal' );
61
62 remove_meta_box( 'commentsdiv', SC_POST_TYPE, 'normal' );
63
64 }
65
66 public static function settings_form( $post ){
67
68 wp_nonce_field( 'sc_post_nonce', 'sc_nonce' );
69
70 $settings = Shortcoder::get_sc_settings( $post->ID );
71
72 $fields = array(
73
74 array( __( 'Display name', 'shortcoder' ), SC_Admin_Form::field( 'text', array(
75 'value' => $post->post_title,
76 'name' => 'post_title',
77 'class' => 'widefat',
78 'helper' => __( 'Name of the shortcode to display when it is listed', 'shortcoder' )
79 ))),
80
81 array( __( 'Description', 'shortcoder' ), SC_Admin_Form::field( 'textarea', array(
82 'value' => $settings[ '_sc_description' ],
83 'name' => '_sc_description',
84 'class' => 'widefat',
85 'helper' => __( 'Description of the shortcode for identification', 'shortcoder' )
86 ))),
87
88 array( __( 'Temporarily disable shortcode', 'shortcoder' ), SC_Admin_Form::field( 'select', array(
89 'value' => $settings[ '_sc_disable_sc' ],
90 'name' => '_sc_disable_sc',
91 'list' => array(
92 'yes' => 'Yes',
93 'no' => 'No'
94 ),
95 'helper' => __( 'Select to disable the shortcode from executing in all the places where it is used.', 'shortcoder' )
96 ))),
97
98 array( __( 'Disable shortcode for administrators', 'shortcoder' ), SC_Admin_Form::field( 'select', array(
99 'value' => $settings[ '_sc_disable_admin' ],
100 'name' => '_sc_disable_admin',
101 'list' => array(
102 'yes' => 'Yes',
103 'no' => 'No'
104 ),
105 'helper' => __( 'Select to disable the shortcode from executing for administrators.', 'shortcoder' )
106 ))),
107
108 array( __( 'Execute shortcode on devices', 'shortcoder' ), SC_Admin_Form::field( 'select', array(
109 'value' => $settings[ '_sc_allowed_devices' ],
110 'name' => '_sc_allowed_devices',
111 'list' => array(
112 'all' => 'All devices',
113 'desktop_only' => 'Desktop only',
114 'mobile_only' => 'Mobile only'
115 ),
116 'helper' => __( 'Select the devices where the shortcode should be executed. Note: If any caching plugin is used, a separate caching for desktop and mobile might be required.', 'shortcoder' )
117 ))),
118
119 );
120
121 echo SC_Admin_Form::table( apply_filters( 'sc_mod_sc_settings_fields', $fields, $settings ) );
122
123 }
124
125 public static function save_post( $post_id ){
126
127 // Checks save status
128 $is_autosave = wp_is_post_autosave( $post_id );
129 $is_revision = wp_is_post_revision( $post_id );
130 $is_valid_nonce = ( isset( $_POST[ 'sc_nonce' ] ) && wp_verify_nonce( $_POST[ 'sc_nonce' ], 'sc_post_nonce' ) );
131
132 // Exits script depending on save status
133 if ( $is_autosave || $is_revision || !$is_valid_nonce ){
134 return;
135 }
136
137 $default_settings = Shortcoder::default_sc_settings();
138 $skip_sanitize = array();
139
140 foreach( $default_settings as $key => $val ){
141
142 if( array_key_exists( $key, $_POST ) ){
143 if( in_array( $key, $skip_sanitize ) ){
144 $val = current_user_can( 'unfiltered_html' ) ? $_POST[ $key ] : wp_kses_post( $_POST[ $key ] );
145 }else{
146 $val = sanitize_text_field( $_POST[ $key ] );
147 }
148 update_post_meta( $post_id, $key, $val );
149 }
150
151 }
152
153 }
154
155 public static function before_insert_post( $post ){
156
157 if( $post[ 'post_type' ] != SC_POST_TYPE ){
158 return $post;
159 }
160
161 $post_title = sanitize_text_field( $post[ 'post_title' ] );
162 if( empty( $post_title ) ){
163 $post[ 'post_title' ] = sanitize_text_field( $post[ 'post_name' ] );
164 }
165
166 if( $_POST && isset( $_POST[ 'sc_content' ] ) ){
167 $post[ 'post_content' ] = current_user_can( 'unfiltered_html' ) ? $_POST[ 'sc_content' ] : wp_kses_post( $_POST[ 'sc_content' ] );
168 }
169
170 return $post;
171 }
172
173 public static function editor_props( $settings ){
174
175 $g = SC_Admin::clean_get();
176
177 if( empty( $settings[ '_sc_editor' ] ) ){
178 $general_settings = Shortcoder::get_settings();
179 $settings[ '_sc_editor' ] = $general_settings[ 'default_editor' ];
180 }
181
182 $list = apply_filters( 'sc_mod_editors', array(
183 'text' => __( 'Text editor', 'shortcoder' ),
184 'visual' => __( 'Visual editor', 'shortcoder' ),
185 'code' => __( 'Code editor', 'shortcoder' )
186 ));
187
188 $editor = ( isset( $g[ 'editor' ] ) && array_key_exists( $g[ 'editor' ], $list ) ) ? $g[ 'editor' ] : $settings[ '_sc_editor' ];
189
190 $switch = '<span class="sc_editor_list sc_editor_icon_' . esc_attr( $editor ) . '">';
191 $switch .= '<select name="_sc_editor" class="sc_editor" title="' . esc_attr__( 'Switch editor', 'shortcoder' ) . '">';
192 foreach( $list as $id => $name ){
193 $switch .= '<option value="' . esc_attr( $id ) . '" ' . selected( $editor, $id, false ) . '>' . esc_html( $name ) . '</option>';
194 }
195 $switch .= '</select>';
196 $switch .= '</span>';
197
198 return array(
199 'active' => $editor,
200 'switch_html' => $switch
201 );
202
203 }
204
205 public static function editor( $post, $settings ){
206
207 $editor = self::editor_props( $settings );
208
209 echo '<div class="hidden">';
210 echo '<div class="sc_editor_toolbar">';
211 echo '<button class="button button-primary sc_insert_param"><span class="dashicons dashicons-plus"></span>' . esc_html__( 'Insert shortcode parameters', 'shortcoder' ) . '<span class="dashicons dashicons-arrow-down"></span></button>';
212 echo $editor[ 'switch_html' ];
213 echo '</div>';
214 echo '</div>';
215
216 if( SC_Admin::is_edit_page( 'new' ) ){
217 $general_settings = Shortcoder::get_settings();
218 $post->post_content = $general_settings[ 'default_content' ];
219 }
220
221 if( $editor[ 'active' ] == 'code' ){
222 echo '<div class="sc_cm_menu"></div>';
223 echo '<textarea name="sc_content" id="sc_content" class="sc_cm_content">' . esc_textarea( $post->post_content ) . '</textarea>';
224 }
225
226 if( in_array( $editor[ 'active' ], array( 'text', 'visual' ) ) ){
227 wp_editor( $post->post_content, 'sc_content', array(
228 'wpautop'=> false,
229 'textarea_rows'=> 20,
230 'tinymce' => ( $editor[ 'active' ] == 'visual' )
231 ));
232 }
233
234 if( !current_user_can( 'unfiltered_html' ) ){
235 echo '<div class="notice notice-info"><p>' . esc_html__( 'Note: Your user role does not permit saving unrestricted HTML. Some tags and attributes will be removed before saving the content.', 'shortcoder' ) . '</p></div>';
236 }
237
238 do_action( 'sc_do_after_editor', $post, $settings, $editor );
239
240 }
241
242 public static function enqueue_scripts( $hook ){
243
244 global $post;
245
246 if( !SC_Admin::is_sc_admin_page() || $hook == 'edit.php' || $hook == 'edit-tags.php' || $hook == 'term.php' || $hook == 'shortcoder_page_settings' ){
247 return false;
248 }
249
250 $settings = Shortcoder::get_sc_settings( $post->ID );
251 $editor = self::editor_props( $settings );
252
253 wp_localize_script( 'sc-admin-js', 'SC_EDITOR', array(
254 'active' => $editor[ 'active' ]
255 ));
256
257 if( $editor[ 'active' ] != 'code' ){
258 return false;
259 }
260
261 $cm_settings = array();
262 $cm_settings[ 'codeEditor' ] = wp_enqueue_code_editor(array(
263 'type' => 'htmlmixed'
264 ));
265
266 wp_localize_script( 'sc-admin-js', 'SC_CODEMIRROR', $cm_settings );
267
268 }
269
270 public static function custom_params_list(){
271
272 $sc_wp_params = Shortcoder::wp_params_list();
273
274 echo '<ul class="sc_params_list">';
275
276 foreach( $sc_wp_params as $group => $group_info ){
277 echo '<li><span class="dashicons dashicons-' . esc_attr( $group_info['icon'] ) . '"></span>';
278 echo esc_html( $group_info[ 'name' ] );
279 echo '<ul class="sc_wp_params">';
280 foreach( $group_info[ 'params' ] as $param_id => $param_name ){
281 echo '<li data-id="' . esc_attr( $param_id ) . '">' . esc_html( $param_name ) . '</li>';
282 }
283 echo '</ul></li>';
284 }
285
286 echo '<li><span class="dashicons dashicons-list-view"></span>' . esc_html__( 'Custom parameter', 'shortcoder' ) . '<ul>';
287 echo '<li class="sc_params_form">';
288 echo '<p>' . esc_html__( 'Insert parameters in content and replace them with custom values when using the shortcode.', 'shortcoder' ) . '<a href="https://www.aakashweb.com/docs/shortcoder/custom-parameters/" target="_blank" title="' . esc_attr__( 'More information', 'shortcoder' ) . '"><span class="dashicons dashicons-info"></span></a></p>';
289 echo '<h4>' . esc_html__( 'Enter custom parameter name', 'shortcoder' ) . '</h4>';
290 echo '<input type="text" class="sc_cp_box widefat" pattern="[a-zA-Z0-9_-]+"/>';
291 echo '<h4>' . esc_html__( 'Default value', 'shortcoder' ) . '</h4>';
292 echo '<input type="text" class="sc_cp_default widefat"/>';
293 echo '<button class="button sc_cp_btn">' . esc_html__( 'Insert parameter', 'shortcoder' ) . '</button>';
294 echo '<p class="sc_cp_info"><small>' . esc_html__( 'Only alphabets, numbers, underscores and hyphens are allowed. Custom parameters are case insensitive', 'shortcoder' ) . '</small></p></li>';
295 echo '</ul></li>';
296
297 echo '<li><span class="dashicons dashicons-screenoptions"></span>' . esc_html__( 'Custom Fields', 'shortcoder' ) . '<ul>';
298 echo '<li class="sc_params_form">';
299 echo '<p>' . esc_html__( 'Pull a custom field value of the current post and display it inside the shortcode content.', 'shortcoder' ) . '<a href="https://www.aakashweb.com/docs/shortcoder/shortcode-parameters/#custom-fields" target="_blank" title="' . esc_attr__( 'More information', 'shortcoder' ) . '"><span class="dashicons dashicons-info"></span></a></p>';
300 echo '<h4>' . esc_html__( 'Enter custom field name', 'shortcoder' ) . '</h4>';
301 echo '<input type="text" class="sc_cf_box widefat" pattern="[a-zA-Z0-9_-]+"/>';
302 echo '<button class="button sc_cf_btn">' . esc_html__( 'Insert custom field', 'shortcoder' ) . '</button>';
303 echo '<p class="sc_cf_info"><small>' . esc_html__( 'Only alphabets, numbers, underscore and hyphens are allowed. Cannot be empty.', 'shortcoder' ) . '</small></p></li>';
304 echo '</ul></li>';
305
306 echo '</ul>';
307
308 }
309
310 public static function hidden_section( $post, $settings ){
311
312 self::custom_params_list();
313
314 }
315
316 public static function feedback( $post ){
317 echo '<div class="feedback">';
318
319 echo '<p>Get updates on the WordPress plugins, tips and tricks to enhance your WordPress experience. No spam.</p>';
320
321 echo '<div class="subscribe_form" data-action="https://aakashweb.us19.list-manage.com/subscribe/post-json?u=b7023581458d048107298247e&id=ef5ab3c5c4&c=">
322 <input type="text" value="' . esc_attr( get_option( 'admin_email' ) ) . '" class="subscribe_email_box" placeholder="Your email address">
323 <p class="subscribe_confirm">Thanks for subscribing !</p>
324 <button class="button subscribe_btn"><span class="dashicons dashicons-email"></span> Subscribe</button>
325 </div>';
326
327 echo '<p>';
328 echo '<a href="https://twitter.com/intent/follow?screen_name=aakashweb" target="_blank" class="button twitter_btn"><span class="dashicons dashicons-twitter"></span> Follow us on Twitter</a>';
329 echo '<a href="https://www.facebook.com/aakashweb/" target="_blank" class="button facebook_btn"><span class="dashicons dashicons-facebook-alt"></span> on Facebook</a>';
330 echo '</p>';
331
332 echo '</div>';
333 }
334
335 public static function more_plugins( $post ){
336
337 echo '<div class="feedback">';
338 echo '<div class="promo_slides">';
339 echo '<div class="promo_slide">';
340 echo '<a class="side_banner" href="https://www.aakashweb.com/wordpress-plugins/super-rss-reader/?utm_source=wp-socializer&utm_medium=sidebar&utm_campaign=srr-pro" target="_blank"><img src="' . esc_url( SC_ADMIN_URL ) . 'images/super-rss-reader.png" /></a>';
341 echo '</div>';
342
343 echo '<div class="promo_slide">';
344 echo '<a class="side_banner" href="https://www.aakashweb.com/wordpress-plugins/ultimate-floating-widgets/?utm_source=wp-socializer&utm_medium=sidebar&utm_campaign=ufw-pro" target="_blank"><img src="' . esc_url( SC_ADMIN_URL ) . 'images/ultimate-floating-widgets.png" /></a>';
345 echo '</div>';
346
347 echo '<div class="promo_slide">';
348 echo '<a class="side_banner" href="https://www.aakashweb.com/wordpress-plugins/announcer/?utm_source=wp-socializer&utm_medium=sidebar&utm_campaign=announcer-pro" target="_blank"><img src="' . esc_url( SC_ADMIN_URL ) . 'images/announcer.png" /></a>';
349 echo '</div>';
350 echo '</div>';
351
352 echo '<p class="promo_btns">
353 <a href="#" onclick="sc_next_promo_slide(-1, event)" class="promo_btn"><span class="dashicons dashicons-arrow-left-alt2"></span> Prev</a>
354 <a href="#" onclick="sc_next_promo_slide(1, event)" class="promo_btn right">Next <span class="dashicons dashicons-arrow-right-alt2"></span></a>
355 </p>';
356
357 echo '<p>';
358 echo '<a href="https://wordpress.org/support/plugin/shortcoder/reviews/?rate=5#new-post" target="_blank" class="button"><span class="dashicons dashicons-star-filled"></span> Rate this plugin</a>';
359 echo '<a href="https://www.aakashweb.com/forum/discuss/wordpress-plugins/shortcoder/" target="_blank" class="button"><span class="dashicons dashicons-format-chat"></span> Support forum</a>';
360 echo '</p>';
361
362 echo '</div>';
363
364 }
365
366 public static function footer_text( $text ){
367
368 if( SC_Admin::is_sc_admin_page() ){
369 return '<span class="footer_thanks">Thanks for using <a href="https://www.aakashweb.com/wordpress-plugins/shortcoder/" target="_blank">Shortcoder</a> &bull; 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>';
370 }
371
372 return $text;
373
374 }
375
376 }
377
378 SC_Admin_Edit::init();
379
380 ?>