PluginProbe ʕ •ᴥ•ʔ
Shortcoder — Create Shortcodes for Anything / 5.3.3
Shortcoder — Create Shortcodes for Anything v5.3.3
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 5 years ago font 5 years ago images 5 years ago js 5 years ago admin.php 5 years ago edit.php 5 years ago form.php 5 years ago insert.php 5 years ago manage.php 5 years ago tools.php 5 years ago
edit.php
359 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', __( 'Get updates', 'shortcoder' ), array( __CLASS__, 'feedback' ), SC_POST_TYPE, 'side', 'default' );
54
55 remove_meta_box( 'slugdiv', SC_POST_TYPE, 'normal' );
56
57 remove_meta_box( 'commentstatusdiv', SC_POST_TYPE, 'normal' );
58
59 remove_meta_box( 'commentsdiv', SC_POST_TYPE, 'normal' );
60
61 }
62
63 public static function settings_form( $post ){
64
65 wp_nonce_field( 'sc_post_nonce', 'sc_nonce' );
66
67 $settings = Shortcoder::get_sc_settings( $post->ID );
68
69 $fields = array(
70
71 array( __( 'Display name', 'shortcoder' ), SC_Admin_Form::field( 'text', array(
72 'value' => $post->post_title,
73 'name' => 'post_title',
74 'class' => 'widefat',
75 'helper' => __( 'Name of the shortcode to display when it is listed', 'shortcoder' )
76 ))),
77
78 array( __( 'Temporarily disable shortcode', 'shortcoder' ), SC_Admin_Form::field( 'select', array(
79 'value' => $settings[ '_sc_disable_sc' ],
80 'name' => '_sc_disable_sc',
81 'list' => array(
82 'yes' => 'Yes',
83 'no' => 'No'
84 ),
85 'helper' => __( 'Select to disable the shortcode from executing in all the places where it is used.', 'shortcoder' )
86 ))),
87
88 array( __( 'Disable shortcode for administrators', 'shortcoder' ), SC_Admin_Form::field( 'select', array(
89 'value' => $settings[ '_sc_disable_admin' ],
90 'name' => '_sc_disable_admin',
91 'list' => array(
92 'yes' => 'Yes',
93 'no' => 'No'
94 ),
95 'helper' => __( 'Select to disable the shortcode from executing for administrators.', 'shortcoder' )
96 ))),
97
98 array( __( 'Execute shortcode in devices', 'shortcoder' ), SC_Admin_Form::field( 'select', array(
99 'value' => $settings[ '_sc_allowed_devices' ],
100 'name' => '_sc_allowed_devices',
101 'list' => array(
102 'all' => 'All devices',
103 'desktop_only' => 'Desktop only',
104 'mobile_only' => 'Mobile only'
105 ),
106 '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' )
107 ))),
108
109 );
110
111 echo SC_Admin_Form::table($fields);
112
113 }
114
115 public static function save_post( $post_id ){
116
117 // Checks save status
118 $is_autosave = wp_is_post_autosave( $post_id );
119 $is_revision = wp_is_post_revision( $post_id );
120 $is_valid_nonce = ( isset( $_POST[ 'sc_nonce' ] ) && wp_verify_nonce( $_POST[ 'sc_nonce' ], 'sc_post_nonce' ) );
121
122 // Exits script depending on save status
123 if ( $is_autosave || $is_revision || !$is_valid_nonce ){
124 return;
125 }
126
127 $default_settings = Shortcoder::default_sc_settings();
128
129 foreach( $default_settings as $key => $val ){
130
131 if( array_key_exists( $key, $_POST ) ){
132 $val = sanitize_text_field( $_POST[ $key ] );
133 update_post_meta( $post_id, $key, $val );
134 }
135
136 }
137
138 }
139
140 public static function before_insert_post( $post ){
141
142 if( $post[ 'post_type' ] != SC_POST_TYPE ){
143 return $post;
144 }
145
146 $post_title = trim( $post[ 'post_title' ] );
147 if( empty( $post_title ) ){
148 $post[ 'post_title' ] = $post[ 'post_name' ];
149 }
150
151 if( $_POST && isset( $_POST[ 'sc_content' ] ) ){
152 $post[ 'post_content' ] = $_POST[ 'sc_content' ];
153 }
154
155 return $post;
156 }
157
158 public static function editor_props( $settings ){
159
160 $g = SC_Admin::clean_get();
161
162 $list = array(
163 'text' => __( 'Text editor', 'shortcoder' ),
164 'visual' => __( 'Visual editor', 'shortcoder' ),
165 'code' => __( 'Code editor', 'shortcoder' )
166 );
167
168 $editor = ( isset( $g[ 'editor' ] ) && array_key_exists( $g[ 'editor' ], $list ) ) ? $g[ 'editor' ] : $settings[ '_sc_editor' ];
169
170 $switch = '<span class="sc_editor_list sc_editor_icon_' . $editor . '">';
171 $switch .= '<select name="_sc_editor" class="sc_editor" title="' . __( 'Switch editor', 'shortcoder' ) . '">';
172 foreach( $list as $id => $name ){
173 $switch .= '<option value="' . $id . '" ' . selected( $editor, $id, false ) . '>' . $name . '</option>';
174 }
175 $switch .= '</select>';
176 $switch .= '</span>';
177
178 return array(
179 'active' => $editor,
180 'switch_html' => $switch
181 );
182
183 }
184
185 public static function editor( $post, $settings ){
186
187 $editor = self::editor_props( $settings );
188
189 echo '<div class="hidden">';
190 echo '<div class="sc_editor_toolbar">';
191 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>';
192 echo $editor[ 'switch_html' ];
193 echo '</div>';
194 echo '</div>';
195
196 if( $editor[ 'active' ] == 'code' ){
197 echo '<div class="sc_cm_menu"></div>';
198 $content = user_can_richedit() ? esc_textarea( $post->post_content ) : $post->post_content;
199 echo '<textarea name="sc_content" id="sc_content" class="sc_cm_content">' . $content . '</textarea>';
200 }else{
201 wp_editor( $post->post_content, 'sc_content', array(
202 'wpautop'=> false,
203 'textarea_rows'=> 20,
204 'tinymce' => ( $editor[ 'active' ] == 'visual' )
205 ));
206 }
207
208 }
209
210 public static function enqueue_scripts( $hook ){
211
212 global $post;
213
214 if( !SC_Admin::is_sc_admin_page() || $hook == 'edit.php' || $hook == 'edit-tags.php' || $hook == 'term.php' ){
215 return false;
216 }
217
218 $settings = Shortcoder::get_sc_settings( $post->ID );
219 $editor = self::editor_props( $settings );
220
221 wp_localize_script( 'sc-admin-js', 'SC_EDITOR', $editor[ 'active' ] );
222
223 if( $editor[ 'active' ] != 'code' ){
224 return false;
225 }
226
227 $cm_cdn_url = 'https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.58.2/';
228 $cm_files = array(
229 'css' => array(
230 'codemirror.min.css'
231 ),
232 'js' => array(
233 'codemirror.min.js',
234 'mode/htmlmixed/htmlmixed.min.js',
235 'mode/css/css.min.js',
236 'mode/xml/xml.min.js',
237 'mode/javascript/javascript.min.js',
238 'addon/selection/active-line.min.js',
239 'addon/mode/overlay.min.js'
240 )
241 );
242
243 foreach( $cm_files as $type => $files ){
244 foreach( $files as $index => $file ){
245 $url = $cm_cdn_url . $file;
246 $id = 'sc-cm-' . $index;
247 if( $type == 'css' ){
248 wp_enqueue_style( $id, $url, array(), SC_VERSION );
249 }else{
250 wp_enqueue_script( $id, $url, array( 'sc-admin-js' ), SC_VERSION );
251 }
252 }
253 }
254
255 }
256
257 public static function custom_params_list(){
258
259 $sc_wp_params = Shortcoder::wp_params_list();
260
261 echo '<ul class="sc_params_list">';
262
263 foreach( $sc_wp_params as $group => $group_info ){
264 echo '<li><span class="dashicons dashicons-' . $group_info['icon'] . '"></span>';
265 echo $group_info[ 'name' ];
266 echo '<ul class="sc_wp_params">';
267 foreach( $group_info[ 'params' ] as $param_id => $param_name ){
268 echo '<li data-id="' . $param_id . '">' . $param_name . '</li>';
269 }
270 echo '</ul></li>';
271 }
272
273 echo '<li><span class="dashicons dashicons-list-view"></span>' . __( 'Custom parameter', 'shortcoder' ) . '<ul>';
274 echo '<li class="sc_params_form"><h4>' . __( 'Enter custom parameter name', 'shortcoder' ) . '</h4>';
275 echo '<input type="text" class="sc_cp_box widefat" pattern="[a-zA-Z0-9_]+"/>';
276 echo '<h4>' . __( 'Default value', 'shortcoder' ) . '</h4>';
277 echo '<input type="text" class="sc_cp_default widefat"/>';
278 echo '<button class="button sc_cp_btn">' . __( 'Insert parameter', 'shortcoder' ) . '</button>';
279 echo '<p class="sc_cp_info"><small>' . __( 'Only alphabets, numbers and underscores are allowed. Custom parameters are case insensitive', 'shortcoder' ) . '</small></p></li>';
280 echo '</ul></li>';
281
282 echo '<li><span class="dashicons dashicons-screenoptions"></span>' . __( 'Custom Fields', 'shortcoder' ) . '<ul>';
283 echo '<li class="sc_params_form"><h4>' . __( 'Enter custom field name', 'shortcoder' ) . '</h4>';
284 echo '<input type="text" class="sc_cf_box widefat" pattern="[a-zA-Z0-9_-]+"/>';
285 echo '<button class="button sc_cf_btn">' . __( 'Insert custom field', 'shortcoder' ) . '</button>';
286 echo '<p class="sc_cf_info"><small>' . __( 'Only alphabets, numbers, underscore and hyphens are allowed. Cannot be empty.', 'shortcoder' ) . '</small></p></li>';
287 echo '</ul></li>';
288
289 echo '</ul>';
290
291 }
292
293 public static function hidden_section( $post, $settings ){
294
295 self::custom_params_list();
296
297 }
298
299 public static function feedback( $post ){
300 echo '<div class="feedback">';
301
302 echo '<p>Get updates on the WordPress plugins, tips and tricks to enhance your WordPress experience. No spam.</p>';
303
304 echo '<div class="subscribe_form" data-action="https://aakashweb.us19.list-manage.com/subscribe/post-json?u=b7023581458d048107298247e&id=ef5ab3c5c4&c=">
305 <input type="email" class="subscribe_email_box" placeholder="Your email address">
306 <p class="subscribe_confirm">Thanks for subscribing !</p>
307 <button class="button subscribe_btn"><span class="dashicons dashicons-email"></span> Subscribe</button>
308 </div>';
309
310 echo '<ul>
311 <li><a href="https://www.facebook.com/aakashweb" target="_blank">Follow on Facebook <span class="dashicons dashicons-arrow-right-alt2"></span></a></li>
312 <li><a href="https://twitter.com/aakashweb" target="_blank">Follow on Twitter <span class="dashicons dashicons-arrow-right-alt2"></span></a></li>
313 </ul>
314 ';
315
316 echo '<div class="ufw"><h4><a href="https://www.aakashweb.com/wordpress-plugins/ultimate-floating-widgets/?utm_source=shortcoder&utm_medium=sidebar&utm_campaign=ufw" target="_blank">
317 <i>Create <span class="dashicons dashicons-arrow-right-alt2"></span></i>
318 <br/> Floating/sticky widgets</a></h4>
319 <img src="' . SC_ADMIN_URL . 'images/ufw.png" class="balloon" />
320 <p>If you want to create floating/sticky sidebar widgets, then Ultimate floating widgets plugins lets you do that. Check it out.</p></div>';
321
322 echo '<a class="rate_review" href="https://wordpress.org/support/plugin/shortcoder/reviews/?rate=5#new-post" target="_blank">
323 <h4>Rate &amp; Review</h4>
324 <span class="dashicons dashicons-star-filled"></span>
325 <p>Like this plugin ? please do rate and review.</p>
326 </a>';
327
328 echo '<div class="cfe_bottom">';
329 echo '<img src="' . SC_ADMIN_URL . '/images/coffee.svg" />';
330 echo '<h3>Buy me a Coffee !</h3><p>If you like this plugin, buy me a coffee and help support this plugin !</p>';
331 echo '<div class="cfe_form">';
332 echo '<select class="cfe_amt">';
333 for($i = 5; $i <= 15; $i++){
334 echo '<option value="' . $i . '" ' . ($i == 6 ? 'selected="selected"' : '') . '>$' . $i . '</option>';
335 }
336 echo '<option value="">Custom</option>';
337 echo '</select>';
338 echo '<a class="button button-primary cfe_btn" href="https://www.paypal.me/vaakash/6" data-link="https://www.paypal.me/vaakash/" target="_blank">' . __( 'Buy me a coffee !', 'shortcoder' ) . '</a>';
339 echo '</div>';
340 echo '</div>';
341
342 echo '</div>';
343 }
344
345 public static function footer_text( $text ){
346
347 if( SC_Admin::is_sc_admin_page() ){
348 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>';
349 }
350
351 return $text;
352
353 }
354
355 }
356
357 SC_Admin_Edit::init();
358
359 ?>