PluginProbe ʕ •ᴥ•ʔ
Shortcoder — Create Shortcodes for Anything / 6.5.1
Shortcoder — Create Shortcodes for Anything v6.5.1
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 11 months ago font 11 months ago images 11 months ago js 11 months ago admin.php 11 months ago edit.php 11 months ago form.php 11 months ago insert.php 11 months ago manage.php 11 months ago settings.php 11 months ago tools.php 11 months ago
edit.php
383 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 '<input type="text" class="sc_title_shortcut" title="' . esc_attr__( 'Display name', 'shortcoder' ) . '" placeholder="' . esc_attr__( 'Enter display name', 'shortcoder' ) . '"/>';
34 echo '</div>';
35
36 echo '<div id="edit-slug-box">';
37 echo '<strong>' . esc_html__( 'Your shortcode', 'shortcoder' ) . ': </strong>';
38 echo '<code class="sc_preview_text">' . esc_html( Shortcoder::get_sc_tag( $post->ID ) ) . '</code>';
39 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>';
40 echo '<a href="#sc_mb_settings" class="sc_settings_link">' . esc_html__( 'Settings', 'shortcoder' ) . '</a>';
41 echo '</div>';
42
43 // Editor
44 self::editor( $post, $settings );
45
46 // Hidden section
47 self::hidden_section( $post, $settings );
48
49 }
50
51 public static function add_meta_boxes(){
52
53 add_meta_box( 'sc_mb_settings', __( 'Shortcode settings', 'shortcoder' ), array( __CLASS__, 'settings_form' ), SC_POST_TYPE, 'normal', 'default' );
54
55 add_meta_box( 'sc_mb_more_plugins', __( 'Support', 'shortcoder' ), array( __CLASS__, 'more_plugins' ), SC_POST_TYPE, 'side', 'default' );
56
57 add_meta_box( 'sc_mb_links', __( 'WordPress News', 'shortcoder' ), array( __CLASS__, 'feedback' ), SC_POST_TYPE, 'side', 'default' );
58
59 remove_meta_box( 'slugdiv', SC_POST_TYPE, 'normal' );
60
61 remove_meta_box( 'commentstatusdiv', SC_POST_TYPE, 'normal' );
62
63 remove_meta_box( 'commentsdiv', SC_POST_TYPE, 'normal' );
64
65 }
66
67 public static function settings_form( $post ){
68
69 wp_nonce_field( 'sc_post_nonce', 'sc_nonce' );
70
71 $settings = Shortcoder::get_sc_settings( $post->ID );
72
73 $fields = array(
74
75 array( __( 'Display name', 'shortcoder' ), SC_Admin_Form::field( 'text', array(
76 'value' => $post->post_title,
77 'name' => 'post_title',
78 'class' => 'widefat',
79 'helper' => __( 'Name of the shortcode to display when it is listed', 'shortcoder' )
80 ))),
81
82 array( __( 'Description', 'shortcoder' ), SC_Admin_Form::field( 'textarea', array(
83 'value' => $settings[ '_sc_description' ],
84 'name' => '_sc_description',
85 'class' => 'widefat',
86 'helper' => __( 'Description of the shortcode for identification', 'shortcoder' )
87 ))),
88
89 array( __( 'Temporarily disable shortcode', 'shortcoder' ), SC_Admin_Form::field( 'select', array(
90 'value' => $settings[ '_sc_disable_sc' ],
91 'name' => '_sc_disable_sc',
92 'list' => array(
93 'yes' => __( 'Yes', 'shortcoder' ),
94 'no' => __( 'No', 'shortcoder' )
95 ),
96 'helper' => __( 'Select to disable the shortcode from executing in all the places where it is used.', 'shortcoder' )
97 ))),
98
99 array( __( 'Disable shortcode for administrators', 'shortcoder' ), SC_Admin_Form::field( 'select', array(
100 'value' => $settings[ '_sc_disable_admin' ],
101 'name' => '_sc_disable_admin',
102 'list' => array(
103 'yes' => __( 'Yes', 'shortcoder' ),
104 'no' => __( 'No', 'shortcoder' )
105 ),
106 'helper' => __( 'Select to disable the shortcode from executing for administrators.', 'shortcoder' )
107 ))),
108
109 array( __( 'Execute shortcode on devices', 'shortcoder' ), SC_Admin_Form::field( 'select', array(
110 'value' => $settings[ '_sc_allowed_devices' ],
111 'name' => '_sc_allowed_devices',
112 'list' => array(
113 'all' => __( 'All devices', 'shortcoder' ),
114 'desktop_only' => __( 'Desktop only', 'shortcoder' ),
115 'mobile_only' => __( 'Mobile only', 'shortcoder' )
116 ),
117 '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' )
118 ))),
119
120 array( __( 'Execute blocks', 'shortcoder' ), SC_Admin_Form::field( 'select', array(
121 'value' => $settings[ '_sc_execute_blocks' ],
122 'name' => '_sc_execute_blocks',
123 'list' => array(
124 'yes' => __( 'Yes', 'shortcoder' ),
125 'no' => __( 'No', 'shortcoder' )
126 ),
127 'helper' => __( 'If the shortcode content contains WordPress blocks HTML, select yes to execute it. Note: The CSS/JS required for the blocks should be included on the page manually as required.', 'shortcoder' )
128 ))),
129
130 );
131
132 echo SC_Admin_Form::table( apply_filters( 'sc_mod_sc_settings_fields', $fields, $settings ) );
133
134 }
135
136 public static function save_post( $post_id ){
137
138 // Checks save status
139 $is_autosave = wp_is_post_autosave( $post_id );
140 $is_revision = wp_is_post_revision( $post_id );
141 $is_valid_nonce = ( isset( $_POST[ 'sc_nonce' ] ) && wp_verify_nonce( $_POST[ 'sc_nonce' ], 'sc_post_nonce' ) );
142
143 // Exits script depending on save status
144 if ( $is_autosave || $is_revision || !$is_valid_nonce ){
145 return;
146 }
147
148 $default_settings = Shortcoder::default_sc_settings();
149 $skip_sanitize = array();
150
151 foreach( $default_settings as $key => $val ){
152
153 if( array_key_exists( $key, $_POST ) ){
154 if( in_array( $key, $skip_sanitize ) ){
155 $val = current_user_can( 'unfiltered_html' ) ? $_POST[ $key ] : wp_kses_post( $_POST[ $key ] );
156 }else{
157 $val = sanitize_text_field( $_POST[ $key ] );
158 }
159 update_post_meta( $post_id, $key, $val );
160 }
161
162 }
163
164 }
165
166 public static function before_insert_post( $post ){
167
168 if( $post[ 'post_type' ] != SC_POST_TYPE ){
169 return $post;
170 }
171
172 $post_title = sanitize_text_field( $post[ 'post_title' ] );
173 if( empty( $post_title ) ){
174 $post[ 'post_title' ] = sanitize_text_field( $post[ 'post_name' ] );
175 }
176
177 if( $_POST && isset( $_POST[ 'sc_content' ] ) ){
178 $post[ 'post_content' ] = current_user_can( 'unfiltered_html' ) ? $_POST[ 'sc_content' ] : wp_kses_post( $_POST[ 'sc_content' ] );
179 }
180
181 return $post;
182 }
183
184 public static function editor_props( $settings ){
185
186 $g = SC_Admin::clean_get();
187
188 if( empty( $settings[ '_sc_editor' ] ) ){
189 $general_settings = Shortcoder::get_settings();
190 $settings[ '_sc_editor' ] = $general_settings[ 'default_editor' ];
191 }
192
193 $list = apply_filters( 'sc_mod_editors', array(
194 'text' => __( 'Text editor', 'shortcoder' ),
195 'visual' => __( 'Visual editor', 'shortcoder' ),
196 'code' => __( 'Code editor', 'shortcoder' )
197 ));
198
199 $editor = ( isset( $g[ 'editor' ] ) && array_key_exists( $g[ 'editor' ], $list ) ) ? $g[ 'editor' ] : $settings[ '_sc_editor' ];
200
201 $switch = '<span class="sc_editor_list sc_editor_icon_' . esc_attr( $editor ) . '">';
202 $switch .= '<select name="_sc_editor" class="sc_editor" title="' . esc_attr__( 'Switch editor', 'shortcoder' ) . '">';
203 foreach( $list as $id => $name ){
204 $switch .= '<option value="' . esc_attr( $id ) . '" ' . selected( $editor, $id, false ) . '>' . esc_html( $name ) . '</option>';
205 }
206 $switch .= '</select>';
207 $switch .= '</span>';
208
209 return array(
210 'active' => $editor,
211 'switch_html' => $switch
212 );
213
214 }
215
216 public static function editor( $post, $settings ){
217
218 $editor = self::editor_props( $settings );
219
220 echo '<div class="hidden">';
221 echo '<div class="sc_editor_toolbar">';
222 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>';
223 echo $editor[ 'switch_html' ];
224 echo '</div>';
225 echo '</div>';
226
227 $post_data = get_post( $post->ID );
228 $post_content = $post_data->post_content;
229
230 if( SC_Admin::is_edit_page( 'new' ) ){
231 $general_settings = Shortcoder::get_settings();
232 $post_content = $general_settings[ 'default_content' ];
233 }
234
235 if( $editor[ 'active' ] == 'code' ){
236 echo '<div class="sc_cm_menu"></div>';
237 echo '<textarea name="sc_content" id="sc_content" class="sc_cm_content">' . esc_textarea( $post_content ) . '</textarea>';
238 }
239
240 if( in_array( $editor[ 'active' ], array( 'text', 'visual' ) ) ){
241 wp_editor( $post_content, 'sc_content', array(
242 'wpautop'=> false,
243 'textarea_rows'=> 20,
244 'tinymce' => ( $editor[ 'active' ] == 'visual' )
245 ));
246 }
247
248 if( !current_user_can( 'unfiltered_html' ) ){
249 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>';
250 }
251
252 do_action( 'sc_do_after_editor', $post, $settings, $editor );
253
254 }
255
256 public static function enqueue_scripts( $hook ){
257
258 global $post;
259
260 if( !SC_Admin::is_sc_admin_page() || $hook == 'edit.php' || $hook == 'edit-tags.php' || $hook == 'term.php' || $hook == 'shortcoder_page_settings' || is_null( $post ) ){
261 return false;
262 }
263
264 $settings = Shortcoder::get_sc_settings( $post->ID );
265 $editor = self::editor_props( $settings );
266
267 wp_localize_script( 'sc-admin-js', 'SC_EDITOR', array(
268 'active' => $editor[ 'active' ]
269 ));
270
271 if( $editor[ 'active' ] != 'code' ){
272 return false;
273 }
274
275 $cm_settings = array();
276 $cm_settings[ 'codeEditor' ] = wp_enqueue_code_editor(array(
277 'type' => 'htmlmixed'
278 ));
279
280 wp_localize_script( 'sc-admin-js', 'SC_CODEMIRROR', $cm_settings );
281
282 }
283
284 public static function custom_params_list(){
285
286 $sc_wp_params = Shortcoder::wp_params_list();
287
288 echo '<ul class="sc_params_list">';
289
290 foreach( $sc_wp_params as $group => $group_info ){
291 echo '<li><span class="dashicons dashicons-' . esc_attr( $group_info['icon'] ) . '"></span>';
292 echo esc_html( $group_info[ 'name' ] );
293 echo '<ul class="sc_wp_params">';
294 foreach( $group_info[ 'params' ] as $param_id => $param_name ){
295 echo '<li data-id="' . esc_attr( $param_id ) . '">' . esc_html( $param_name ) . '</li>';
296 }
297 echo '</ul></li>';
298 }
299
300 echo '<li><span class="dashicons dashicons-list-view"></span>' . esc_html__( 'Custom parameter', 'shortcoder' ) . '<ul>';
301 echo '<li class="sc_params_form">';
302 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>';
303 echo '<h4>' . esc_html__( 'Enter custom parameter name', 'shortcoder' ) . '</h4>';
304 echo '<input type="text" class="sc_cp_box widefat" pattern="[a-zA-Z0-9_-]+"/>';
305 echo '<h4>' . esc_html__( 'Default value', 'shortcoder' ) . '</h4>';
306 echo '<input type="text" class="sc_cp_default widefat"/>';
307 echo '<button class="button sc_cp_btn">' . esc_html__( 'Insert parameter', 'shortcoder' ) . '</button>';
308 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>';
309 echo '</ul></li>';
310
311 echo '<li><span class="dashicons dashicons-screenoptions"></span>' . esc_html__( 'Custom Fields', 'shortcoder' ) . '<ul>';
312 echo '<li class="sc_params_form">';
313 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>';
314 echo '<h4>' . esc_html__( 'Enter custom field name', 'shortcoder' ) . '</h4>';
315 echo '<input type="text" class="sc_cf_box widefat" pattern="[a-zA-Z0-9_-]+"/>';
316 echo '<h4>' . esc_html__( 'Default value', 'shortcoder' ) . '</h4>';
317 echo '<input type="text" class="sc_cf_default widefat"/>';
318 echo '<button class="button sc_cf_btn">' . esc_html__( 'Insert custom field', 'shortcoder' ) . '</button>';
319 echo '<p class="sc_cf_info"><small>' . esc_html__( 'Only alphabets, numbers, underscore and hyphens are allowed. Cannot be empty.', 'shortcoder' ) . '</small></p></li>';
320 echo '</ul></li>';
321
322 echo '</ul>';
323
324 }
325
326 public static function hidden_section( $post, $settings ){
327
328 self::custom_params_list();
329
330 }
331
332 public static function feedback( $post ){
333 echo '<div class="feedback">';
334
335 echo '<p>Get updates on the WordPress plugins, tips and tricks to enhance your WordPress experience. No spam.</p>';
336
337 echo '<div class="subscribe_form">
338 <input type="text" value="' . esc_attr( get_option( 'admin_email' ) ) . '" class="subscribe_email_box" placeholder="Your email address">
339 <button class="button subscribe_btn"><span class="dashicons dashicons-email"></span> Subscribe</button>
340 </div>';
341
342 echo '</div>';
343 }
344
345 public static function more_plugins( $post ){
346
347 echo '<div class="feedback">';
348
349 echo '<ul>';
350 echo '<li><a href="https://twitter.com/intent/follow?screen_name=aakashweb" target="_blank"><span class="dashicons dashicons-twitter"></span> Follow on Twitter</a></li>';
351 echo '<li><a href="https://www.facebook.com/aakashweb/" target="_blank"><span class="dashicons dashicons-facebook-alt"></span> Follow on Facebook</a></li>';
352 echo '<li><a href="https://www.aakashweb.com/forum/discuss/wordpress-plugins/shortcoder/" target="_blank"><span class="dashicons dashicons-format-chat"></span> Support Forum</a></li>';
353 echo '<li><a href="https://wordpress.org/support/plugin/shortcoder/reviews/?rate=5#new-post" target="_blank"><span class="dashicons dashicons-star-filled"></span> Rate plugin</a></li>';
354 echo '</ul>';
355
356 echo '<h3>More WordPress plugins from us</h3>';
357 echo '<ul>';
358 echo '<li><a href="https://www.aakashweb.com/wordpress-plugins/super-rss-reader/?utm_source=shortcoder&utm_medium=sidebar&utm_campaign=srr-pro" target="_blank">Super RSS Reader</a> - Display RSS feeds</li>';
359 echo '<li><a href="https://www.aakashweb.com/wordpress-plugins/announcer/?utm_source=shortcoder&utm_medium=sidebar&utm_campaign=announcer-pro" target="_blank">Announcer</a> - Add notification message bars easily</li>';
360 echo '<li><a href="https://www.aakashweb.com/wordpress-plugins/ultimate-floating-widgets/?utm_source=shortcoder&utm_medium=sidebar&utm_campaign=ufw-pro" target="_blank">Ultimate Floating Widget</a> - Create floating sidebar popup and add widgets inside</li>';
361 echo '<li><a href="https://www.aakashweb.com/wordpress-plugins/wp-socializer/?utm_source=shortcoder&utm_medium=sidebar&utm_campaign=wpsr-pro" target="_blank">WP Socializer</a> - Add beautiful social media share icons</li>';
362 echo '<li><a href="https://www.aakashweb.com/wordpress-plugins/?utm_source=shortcoder&utm_medium=sidebar&utm_campaign=aw" target="_blank">More</a> <span class="dashicons dashicons-arrow-right-alt"></span></li>';
363 echo '</ul>';
364
365 echo '</div>';
366
367 }
368
369 public static function footer_text( $text ){
370
371 if( SC_Admin::is_sc_admin_page() ){
372 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>';
373 }
374
375 return $text;
376
377 }
378
379 }
380
381 SC_Admin_Edit::init();
382
383 ?>