PluginProbe ʕ •ᴥ•ʔ
Shortcoder — Create Shortcodes for Anything / 5.8
Shortcoder — Create Shortcodes for Anything v5.8
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 4 years ago font 4 years ago images 4 years ago js 4 years ago admin.php 4 years ago edit.php 4 years ago form.php 4 years ago insert.php 4 years ago manage.php 4 years ago settings.php 4 years ago tools.php 4 years ago
edit.php
368 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="' . __( 'Name of the shortcode. Allowed characters are alphabets, numbers, hyphens and underscore.', 'shortcoder' ) . '" value="' . $post->post_name . '" name="post_name" id="post_name" pattern="[a-zA-z0-9\-_]+" required placeholder="' . __( 'Enter shortcode name', 'shortcoder' ) . '" />';
33 echo '</div>';
34
35 echo '<div id="edit-slug-box">';
36 echo '<strong>' . __( 'Your shortcode', 'shortcoder' ) . ': </strong>';
37 echo '<code class="sc_preview_text">' . 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> ' . __( 'Copy', 'shortcoder' ) . '</button></span>';
39 echo '<a href="#sc_mb_settings" class="sc_settings_link">' . __( '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($fields);
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
139 foreach( $default_settings as $key => $val ){
140
141 if( array_key_exists( $key, $_POST ) ){
142 $val = sanitize_text_field( $_POST[ $key ] );
143 update_post_meta( $post_id, $key, $val );
144 }
145
146 }
147
148 }
149
150 public static function before_insert_post( $post ){
151
152 if( $post[ 'post_type' ] != SC_POST_TYPE ){
153 return $post;
154 }
155
156 $post_title = trim( $post[ 'post_title' ] );
157 if( empty( $post_title ) ){
158 $post[ 'post_title' ] = $post[ 'post_name' ];
159 }
160
161 if( $_POST && isset( $_POST[ 'sc_content' ] ) ){
162 $post[ 'post_content' ] = $_POST[ 'sc_content' ];
163 }
164
165 return $post;
166 }
167
168 public static function editor_props( $settings ){
169
170 $g = SC_Admin::clean_get();
171
172 if( empty( $settings[ '_sc_editor' ] ) ){
173 $general_settings = Shortcoder::get_settings();
174 $settings[ '_sc_editor' ] = $general_settings[ 'default_editor' ];
175 }
176
177 $list = array(
178 'text' => __( 'Text editor', 'shortcoder' ),
179 'visual' => __( 'Visual editor', 'shortcoder' ),
180 'code' => __( 'Code editor', 'shortcoder' )
181 );
182
183 $editor = ( isset( $g[ 'editor' ] ) && array_key_exists( $g[ 'editor' ], $list ) ) ? $g[ 'editor' ] : $settings[ '_sc_editor' ];
184
185 $switch = '<span class="sc_editor_list sc_editor_icon_' . $editor . '">';
186 $switch .= '<select name="_sc_editor" class="sc_editor" title="' . __( 'Switch editor', 'shortcoder' ) . '">';
187 foreach( $list as $id => $name ){
188 $switch .= '<option value="' . $id . '" ' . selected( $editor, $id, false ) . '>' . $name . '</option>';
189 }
190 $switch .= '</select>';
191 $switch .= '</span>';
192
193 return array(
194 'active' => $editor,
195 'switch_html' => $switch
196 );
197
198 }
199
200 public static function editor( $post, $settings ){
201
202 $editor = self::editor_props( $settings );
203
204 echo '<div class="hidden">';
205 echo '<div class="sc_editor_toolbar">';
206 echo '<button class="button button-primary sc_insert_param"><span class="dashicons dashicons-plus"></span>' . __( 'Insert shortcode parameters', 'shortcoder' ) . '<span class="dashicons dashicons-arrow-down"></span></button>';
207 echo $editor[ 'switch_html' ];
208 echo '</div>';
209 echo '</div>';
210
211 if( SC_Admin::is_edit_page( 'new' ) ){
212 $general_settings = Shortcoder::get_settings();
213 $post->post_content = $general_settings[ 'default_content' ];
214 }
215
216 if( $editor[ 'active' ] == 'code' ){
217 echo '<div class="sc_cm_menu"></div>';
218 $content = user_can_richedit() ? esc_textarea( $post->post_content ) : $post->post_content;
219 echo '<textarea name="sc_content" id="sc_content" class="sc_cm_content">' . $content . '</textarea>';
220 }else{
221 wp_editor( $post->post_content, 'sc_content', array(
222 'wpautop'=> false,
223 'textarea_rows'=> 20,
224 'tinymce' => ( $editor[ 'active' ] == 'visual' )
225 ));
226 }
227
228 }
229
230 public static function enqueue_scripts( $hook ){
231
232 global $post;
233
234 if( !SC_Admin::is_sc_admin_page() || $hook == 'edit.php' || $hook == 'edit-tags.php' || $hook == 'term.php' || $hook == 'shortcoder_page_settings' ){
235 return false;
236 }
237
238 $settings = Shortcoder::get_sc_settings( $post->ID );
239 $editor = self::editor_props( $settings );
240
241 wp_localize_script( 'sc-admin-js', 'SC_EDITOR', array(
242 'active' => $editor[ 'active' ]
243 ));
244
245 if( $editor[ 'active' ] != 'code' ){
246 return false;
247 }
248
249 $cm_settings = array();
250 $cm_settings[ 'codeEditor' ] = wp_enqueue_code_editor(array(
251 'type' => 'htmlmixed'
252 ));
253
254 wp_localize_script( 'sc-admin-js', 'SC_CODEMIRROR', $cm_settings );
255
256 }
257
258 public static function custom_params_list(){
259
260 $sc_wp_params = Shortcoder::wp_params_list();
261
262 echo '<ul class="sc_params_list">';
263
264 foreach( $sc_wp_params as $group => $group_info ){
265 echo '<li><span class="dashicons dashicons-' . $group_info['icon'] . '"></span>';
266 echo $group_info[ 'name' ];
267 echo '<ul class="sc_wp_params">';
268 foreach( $group_info[ 'params' ] as $param_id => $param_name ){
269 echo '<li data-id="' . $param_id . '">' . $param_name . '</li>';
270 }
271 echo '</ul></li>';
272 }
273
274 echo '<li><span class="dashicons dashicons-list-view"></span>' . __( 'Custom parameter', 'shortcoder' ) . '<ul>';
275 echo '<li class="sc_params_form">';
276 echo '<p>' . __( '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="' . __( 'More information', 'shortcoder' ) . '"><span class="dashicons dashicons-info"></span></a></p>';
277 echo '<h4>' . __( 'Enter custom parameter name', 'shortcoder' ) . '</h4>';
278 echo '<input type="text" class="sc_cp_box widefat" pattern="[a-zA-Z0-9_-]+"/>';
279 echo '<h4>' . __( 'Default value', 'shortcoder' ) . '</h4>';
280 echo '<input type="text" class="sc_cp_default widefat"/>';
281 echo '<button class="button sc_cp_btn">' . __( 'Insert parameter', 'shortcoder' ) . '</button>';
282 echo '<p class="sc_cp_info"><small>' . __( 'Only alphabets, numbers, underscores and hyphens are allowed. Custom parameters are case insensitive', 'shortcoder' ) . '</small></p></li>';
283 echo '</ul></li>';
284
285 echo '<li><span class="dashicons dashicons-screenoptions"></span>' . __( 'Custom Fields', 'shortcoder' ) . '<ul>';
286 echo '<li class="sc_params_form">';
287 echo '<p>' . __( '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="' . __( 'More information', 'shortcoder' ) . '"><span class="dashicons dashicons-info"></span></a></p>';
288 echo '<h4>' . __( 'Enter custom field name', 'shortcoder' ) . '</h4>';
289 echo '<input type="text" class="sc_cf_box widefat" pattern="[a-zA-Z0-9_-]+"/>';
290 echo '<button class="button sc_cf_btn">' . __( 'Insert custom field', 'shortcoder' ) . '</button>';
291 echo '<p class="sc_cf_info"><small>' . __( 'Only alphabets, numbers, underscore and hyphens are allowed. Cannot be empty.', 'shortcoder' ) . '</small></p></li>';
292 echo '</ul></li>';
293
294 echo '</ul>';
295
296 }
297
298 public static function hidden_section( $post, $settings ){
299
300 self::custom_params_list();
301
302 }
303
304 public static function feedback( $post ){
305 echo '<div class="feedback">';
306
307 echo '<p>Get updates on the WordPress plugins, tips and tricks to enhance your WordPress experience. No spam.</p>';
308
309 echo '<div class="subscribe_form" data-action="https://aakashweb.us19.list-manage.com/subscribe/post-json?u=b7023581458d048107298247e&id=ef5ab3c5c4&c=">
310 <input type="text" value="' . get_option( 'admin_email' ) . '" class="subscribe_email_box" placeholder="Your email address">
311 <p class="subscribe_confirm">Thanks for subscribing !</p>
312 <button class="button subscribe_btn"><span class="dashicons dashicons-email"></span> Subscribe</button>
313 </div>';
314
315 echo '<p>';
316 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>';
317 echo '<a href="https://www.facebook.com/aakashweb/" target="_blank" class="button facebook_btn"><span class="dashicons dashicons-facebook-alt"></span> on Facebook</a>';
318 echo '</p>';
319
320 echo '</div>';
321 }
322
323 public static function more_plugins( $post ){
324
325 echo '<div class="feedback">';
326 echo '<div class="promo_slides">';
327 echo '<div class="promo_slide">';
328 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="' . SC_ADMIN_URL . 'images/super-rss-reader.png" /></a>';
329 echo '</div>';
330
331 echo '<div class="promo_slide">';
332 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="' . SC_ADMIN_URL . 'images/ultimate-floating-widgets.png" /></a>';
333 echo '</div>';
334
335 echo '<div class="promo_slide">';
336 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="' . SC_ADMIN_URL . 'images/announcer.png" /></a>';
337 echo '</div>';
338 echo '</div>';
339
340 echo '<p class="promo_btns">
341 <a href="#" onclick="sc_next_promo_slide(-1, event)" class="promo_btn"><span class="dashicons dashicons-arrow-left-alt2"></span> Prev</a>
342 <a href="#" onclick="sc_next_promo_slide(1, event)" class="promo_btn right">Next <span class="dashicons dashicons-arrow-right-alt2"></span></a>
343 </p>';
344
345 echo '<p>';
346 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>';
347 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>';
348 echo '</p>';
349
350 echo '</div>';
351
352 }
353
354 public static function footer_text( $text ){
355
356 if( SC_Admin::is_sc_admin_page() ){
357 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>';
358 }
359
360 return $text;
361
362 }
363
364 }
365
366 SC_Admin_Edit::init();
367
368 ?>