PluginProbe ʕ •ᴥ•ʔ
Shortcoder — Create Shortcodes for Anything / 5.6
Shortcoder — Create Shortcodes for Anything v5.6
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
356 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 '</div>';
40
41 // Editor
42 self::editor( $post, $settings );
43
44 // Hidden section
45 self::hidden_section( $post, $settings );
46
47 }
48
49 public static function add_meta_boxes(){
50
51 add_meta_box( 'sc_mb_settings', __( 'Shortcode settings', 'shortcoder' ), array( __CLASS__, 'settings_form' ), SC_POST_TYPE, 'normal', 'default' );
52
53 add_meta_box( 'sc_mb_links', __( 'WordPress News', 'shortcoder' ), array( __CLASS__, 'feedback' ), SC_POST_TYPE, 'side', 'default' );
54
55 add_meta_box( 'sc_mb_more_plugins', __( 'More plugins from us', 'shortcoder' ), array( __CLASS__, 'more_plugins' ), SC_POST_TYPE, 'side', 'default' );
56
57 remove_meta_box( 'slugdiv', SC_POST_TYPE, 'normal' );
58
59 remove_meta_box( 'commentstatusdiv', SC_POST_TYPE, 'normal' );
60
61 remove_meta_box( 'commentsdiv', SC_POST_TYPE, 'normal' );
62
63 }
64
65 public static function settings_form( $post ){
66
67 wp_nonce_field( 'sc_post_nonce', 'sc_nonce' );
68
69 $settings = Shortcoder::get_sc_settings( $post->ID );
70
71 $fields = array(
72
73 array( __( 'Display name', 'shortcoder' ), SC_Admin_Form::field( 'text', array(
74 'value' => $post->post_title,
75 'name' => 'post_title',
76 'class' => 'widefat',
77 'helper' => __( 'Name of the shortcode to display when it is listed', 'shortcoder' )
78 ))),
79
80 array( __( 'Temporarily disable shortcode', 'shortcoder' ), SC_Admin_Form::field( 'select', array(
81 'value' => $settings[ '_sc_disable_sc' ],
82 'name' => '_sc_disable_sc',
83 'list' => array(
84 'yes' => 'Yes',
85 'no' => 'No'
86 ),
87 'helper' => __( 'Select to disable the shortcode from executing in all the places where it is used.', 'shortcoder' )
88 ))),
89
90 array( __( 'Disable shortcode for administrators', 'shortcoder' ), SC_Admin_Form::field( 'select', array(
91 'value' => $settings[ '_sc_disable_admin' ],
92 'name' => '_sc_disable_admin',
93 'list' => array(
94 'yes' => 'Yes',
95 'no' => 'No'
96 ),
97 'helper' => __( 'Select to disable the shortcode from executing for administrators.', 'shortcoder' )
98 ))),
99
100 array( __( 'Execute shortcode in devices', 'shortcoder' ), SC_Admin_Form::field( 'select', array(
101 'value' => $settings[ '_sc_allowed_devices' ],
102 'name' => '_sc_allowed_devices',
103 'list' => array(
104 'all' => 'All devices',
105 'desktop_only' => 'Desktop only',
106 'mobile_only' => 'Mobile only'
107 ),
108 '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' )
109 ))),
110
111 );
112
113 echo SC_Admin_Form::table($fields);
114
115 }
116
117 public static function save_post( $post_id ){
118
119 // Checks save status
120 $is_autosave = wp_is_post_autosave( $post_id );
121 $is_revision = wp_is_post_revision( $post_id );
122 $is_valid_nonce = ( isset( $_POST[ 'sc_nonce' ] ) && wp_verify_nonce( $_POST[ 'sc_nonce' ], 'sc_post_nonce' ) );
123
124 // Exits script depending on save status
125 if ( $is_autosave || $is_revision || !$is_valid_nonce ){
126 return;
127 }
128
129 $default_settings = Shortcoder::default_sc_settings();
130
131 foreach( $default_settings as $key => $val ){
132
133 if( array_key_exists( $key, $_POST ) ){
134 $val = sanitize_text_field( $_POST[ $key ] );
135 update_post_meta( $post_id, $key, $val );
136 }
137
138 }
139
140 }
141
142 public static function before_insert_post( $post ){
143
144 if( $post[ 'post_type' ] != SC_POST_TYPE ){
145 return $post;
146 }
147
148 $post_title = trim( $post[ 'post_title' ] );
149 if( empty( $post_title ) ){
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
160 public static function editor_props( $settings ){
161
162 $g = SC_Admin::clean_get();
163
164 if( empty( $settings[ '_sc_editor' ] ) ){
165 $general_settings = Shortcoder::get_settings();
166 $settings[ '_sc_editor' ] = $general_settings[ 'default_editor' ];
167 }
168
169 $list = array(
170 'text' => __( 'Text editor', 'shortcoder' ),
171 'visual' => __( 'Visual editor', 'shortcoder' ),
172 'code' => __( 'Code editor', 'shortcoder' )
173 );
174
175 $editor = ( isset( $g[ 'editor' ] ) && array_key_exists( $g[ 'editor' ], $list ) ) ? $g[ 'editor' ] : $settings[ '_sc_editor' ];
176
177 $switch = '<span class="sc_editor_list sc_editor_icon_' . $editor . '">';
178 $switch .= '<select name="_sc_editor" class="sc_editor" title="' . __( 'Switch editor', 'shortcoder' ) . '">';
179 foreach( $list as $id => $name ){
180 $switch .= '<option value="' . $id . '" ' . selected( $editor, $id, false ) . '>' . $name . '</option>';
181 }
182 $switch .= '</select>';
183 $switch .= '</span>';
184
185 return array(
186 'active' => $editor,
187 'switch_html' => $switch
188 );
189
190 }
191
192 public static function editor( $post, $settings ){
193
194 $editor = self::editor_props( $settings );
195
196 echo '<div class="hidden">';
197 echo '<div class="sc_editor_toolbar">';
198 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>';
199 echo $editor[ 'switch_html' ];
200 echo '</div>';
201 echo '</div>';
202
203 if( SC_Admin::is_edit_page( 'new' ) ){
204 $general_settings = Shortcoder::get_settings();
205 $post->post_content = $general_settings[ 'default_content' ];
206 }
207
208 if( $editor[ 'active' ] == 'code' ){
209 echo '<div class="sc_cm_menu"></div>';
210 $content = user_can_richedit() ? esc_textarea( $post->post_content ) : $post->post_content;
211 echo '<textarea name="sc_content" id="sc_content" class="sc_cm_content">' . $content . '</textarea>';
212 }else{
213 wp_editor( $post->post_content, 'sc_content', array(
214 'wpautop'=> false,
215 'textarea_rows'=> 20,
216 'tinymce' => ( $editor[ 'active' ] == 'visual' )
217 ));
218 }
219
220 }
221
222 public static function enqueue_scripts( $hook ){
223
224 global $post;
225
226 if( !SC_Admin::is_sc_admin_page() || $hook == 'edit.php' || $hook == 'edit-tags.php' || $hook == 'term.php' || $hook == 'shortcoder_page_settings' ){
227 return false;
228 }
229
230 $settings = Shortcoder::get_sc_settings( $post->ID );
231 $editor = self::editor_props( $settings );
232
233 wp_localize_script( 'sc-admin-js', 'SC_EDITOR', array(
234 'active' => $editor[ 'active' ]
235 ));
236
237 if( $editor[ 'active' ] != 'code' ){
238 return false;
239 }
240
241 $cm_settings = array();
242 $cm_settings[ 'codeEditor' ] = wp_enqueue_code_editor(array(
243 'type' => 'htmlmixed'
244 ));
245
246 wp_localize_script( 'sc-admin-js', 'SC_CODEMIRROR', $cm_settings );
247
248 }
249
250 public static function custom_params_list(){
251
252 $sc_wp_params = Shortcoder::wp_params_list();
253
254 echo '<ul class="sc_params_list">';
255
256 foreach( $sc_wp_params as $group => $group_info ){
257 echo '<li><span class="dashicons dashicons-' . $group_info['icon'] . '"></span>';
258 echo $group_info[ 'name' ];
259 echo '<ul class="sc_wp_params">';
260 foreach( $group_info[ 'params' ] as $param_id => $param_name ){
261 echo '<li data-id="' . $param_id . '">' . $param_name . '</li>';
262 }
263 echo '</ul></li>';
264 }
265
266 echo '<li><span class="dashicons dashicons-list-view"></span>' . __( 'Custom parameter', 'shortcoder' ) . '<ul>';
267 echo '<li class="sc_params_form"><h4>' . __( 'Enter custom parameter name', 'shortcoder' ) . '</h4>';
268 echo '<input type="text" class="sc_cp_box widefat" pattern="[a-zA-Z0-9_-]+"/>';
269 echo '<h4>' . __( 'Default value', 'shortcoder' ) . '</h4>';
270 echo '<input type="text" class="sc_cp_default widefat"/>';
271 echo '<button class="button sc_cp_btn">' . __( 'Insert parameter', 'shortcoder' ) . '</button>';
272 echo '<p class="sc_cp_info"><small>' . __( 'Only alphabets, numbers, underscores and hyphens are allowed. Custom parameters are case insensitive', 'shortcoder' ) . '</small></p></li>';
273 echo '</ul></li>';
274
275 echo '<li><span class="dashicons dashicons-screenoptions"></span>' . __( 'Custom Fields', 'shortcoder' ) . '<ul>';
276 echo '<li class="sc_params_form"><h4>' . __( 'Enter custom field name', 'shortcoder' ) . '</h4>';
277 echo '<input type="text" class="sc_cf_box widefat" pattern="[a-zA-Z0-9_-]+"/>';
278 echo '<button class="button sc_cf_btn">' . __( 'Insert custom field', 'shortcoder' ) . '</button>';
279 echo '<p class="sc_cf_info"><small>' . __( 'Only alphabets, numbers, underscore and hyphens are allowed. Cannot be empty.', 'shortcoder' ) . '</small></p></li>';
280 echo '</ul></li>';
281
282 echo '</ul>';
283
284 }
285
286 public static function hidden_section( $post, $settings ){
287
288 self::custom_params_list();
289
290 }
291
292 public static function feedback( $post ){
293 echo '<div class="feedback">';
294
295 echo '<p>Get updates on the WordPress plugins, tips and tricks to enhance your WordPress experience. No spam.</p>';
296
297 echo '<div class="subscribe_form" data-action="https://aakashweb.us19.list-manage.com/subscribe/post-json?u=b7023581458d048107298247e&id=ef5ab3c5c4&c=">
298 <input type="email" value="' . get_option( 'admin_email' ) . '" class="subscribe_email_box" placeholder="Your email address">
299 <p class="subscribe_confirm">Thanks for subscribing !</p>
300 <button class="button subscribe_btn"><span class="dashicons dashicons-email"></span> Subscribe</button>
301 </div>';
302
303 echo '<p>';
304 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>';
305 echo '<a href="https://www.facebook.com/aakashweb/" target="_blank" class="button facebook_btn"><span class="dashicons dashicons-facebook-alt"></span> on Facebook</a>';
306 echo '</p>';
307
308 echo '</div>';
309 }
310
311 public static function more_plugins( $post ){
312
313 echo '<div class="feedback">';
314 echo '<div class="promo_slides">';
315 echo '<div class="promo_slide">';
316 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>';
317 echo '</div>';
318
319 echo '<div class="promo_slide">';
320 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>';
321 echo '</div>';
322
323 echo '<div class="promo_slide">';
324 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>';
325 echo '</div>';
326 echo '</div>';
327
328 echo '<p class="promo_btns">
329 <a href="#" onclick="sc_next_promo_slide(-1, event)" class="promo_btn"><span class="dashicons dashicons-arrow-left-alt2"></span> Prev</a>
330 <a href="#" onclick="sc_next_promo_slide(1, event)" class="promo_btn right">Next <span class="dashicons dashicons-arrow-right-alt2"></span></a>
331 </p>';
332
333 echo '<p>';
334 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>';
335 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>';
336 echo '</p>';
337
338 echo '</div>';
339
340 }
341
342 public static function footer_text( $text ){
343
344 if( SC_Admin::is_sc_admin_page() ){
345 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>';
346 }
347
348 return $text;
349
350 }
351
352 }
353
354 SC_Admin_Edit::init();
355
356 ?>