PluginProbe ʕ •ᴥ•ʔ
Shortcoder — Create Shortcodes for Anything / 5.4
Shortcoder — Create Shortcodes for Anything v5.4
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
340 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', array(
222 'active' => $editor[ 'active' ]
223 ));
224
225 if( $editor[ 'active' ] != 'code' ){
226 return false;
227 }
228
229 $cm_settings = array();
230 $cm_settings[ 'codeEditor' ] = wp_enqueue_code_editor(array(
231 'type' => 'htmlmixed'
232 ));
233
234 wp_localize_script( 'sc-admin-js', 'SC_CODEMIRROR', $cm_settings );
235
236 }
237
238 public static function custom_params_list(){
239
240 $sc_wp_params = Shortcoder::wp_params_list();
241
242 echo '<ul class="sc_params_list">';
243
244 foreach( $sc_wp_params as $group => $group_info ){
245 echo '<li><span class="dashicons dashicons-' . $group_info['icon'] . '"></span>';
246 echo $group_info[ 'name' ];
247 echo '<ul class="sc_wp_params">';
248 foreach( $group_info[ 'params' ] as $param_id => $param_name ){
249 echo '<li data-id="' . $param_id . '">' . $param_name . '</li>';
250 }
251 echo '</ul></li>';
252 }
253
254 echo '<li><span class="dashicons dashicons-list-view"></span>' . __( 'Custom parameter', 'shortcoder' ) . '<ul>';
255 echo '<li class="sc_params_form"><h4>' . __( 'Enter custom parameter name', 'shortcoder' ) . '</h4>';
256 echo '<input type="text" class="sc_cp_box widefat" pattern="[a-zA-Z0-9_-]+"/>';
257 echo '<h4>' . __( 'Default value', 'shortcoder' ) . '</h4>';
258 echo '<input type="text" class="sc_cp_default widefat"/>';
259 echo '<button class="button sc_cp_btn">' . __( 'Insert parameter', 'shortcoder' ) . '</button>';
260 echo '<p class="sc_cp_info"><small>' . __( 'Only alphabets, numbers, underscores and hyphens are allowed. Custom parameters are case insensitive', 'shortcoder' ) . '</small></p></li>';
261 echo '</ul></li>';
262
263 echo '<li><span class="dashicons dashicons-screenoptions"></span>' . __( 'Custom Fields', 'shortcoder' ) . '<ul>';
264 echo '<li class="sc_params_form"><h4>' . __( 'Enter custom field name', 'shortcoder' ) . '</h4>';
265 echo '<input type="text" class="sc_cf_box widefat" pattern="[a-zA-Z0-9_-]+"/>';
266 echo '<button class="button sc_cf_btn">' . __( 'Insert custom field', 'shortcoder' ) . '</button>';
267 echo '<p class="sc_cf_info"><small>' . __( 'Only alphabets, numbers, underscore and hyphens are allowed. Cannot be empty.', 'shortcoder' ) . '</small></p></li>';
268 echo '</ul></li>';
269
270 echo '</ul>';
271
272 }
273
274 public static function hidden_section( $post, $settings ){
275
276 self::custom_params_list();
277
278 }
279
280 public static function feedback( $post ){
281 echo '<div class="feedback">';
282
283 echo '<p>Get updates on the WordPress plugins, tips and tricks to enhance your WordPress experience. No spam.</p>';
284
285 echo '<div class="subscribe_form" data-action="https://aakashweb.us19.list-manage.com/subscribe/post-json?u=b7023581458d048107298247e&id=ef5ab3c5c4&c=">
286 <input type="email" class="subscribe_email_box" placeholder="Your email address">
287 <p class="subscribe_confirm">Thanks for subscribing !</p>
288 <button class="button subscribe_btn"><span class="dashicons dashicons-email"></span> Subscribe</button>
289 </div>';
290
291 echo '<ul>
292 <li><a href="https://www.facebook.com/aakashweb" target="_blank">Follow on Facebook <span class="dashicons dashicons-arrow-right-alt2"></span></a></li>
293 <li><a href="https://twitter.com/aakashweb" target="_blank">Follow on Twitter <span class="dashicons dashicons-arrow-right-alt2"></span></a></li>
294 </ul>
295 ';
296
297 echo '<div class="ufw"><h4><a href="https://www.aakashweb.com/wordpress-plugins/ultimate-floating-widgets-pro/?utm_source=shortcoder&utm_medium=sidebar&utm_campaign=ufw-pro" target="_blank">
298 <i>Create <span class="dashicons dashicons-arrow-right-alt2"></span></i>
299 <br/> Floating/sticky widgets</a></h4>
300 <img src="' . SC_ADMIN_URL . 'images/ufw.png" class="balloon" />
301 <p>If you want to create floating/sticky sidebar widgets, then Ultimate floating widgets plugins lets you do that. Check it out.</p></div>';
302
303 echo '<a class="rate_review" href="https://wordpress.org/support/plugin/shortcoder/reviews/?rate=5#new-post" target="_blank">
304 <h4>Rate &amp; Review</h4>
305 <span class="dashicons dashicons-star-filled"></span>
306 <p>Like this plugin ? please do rate and review.</p>
307 </a>';
308
309 echo '<div class="cfe_bottom">';
310 echo '<img src="' . SC_ADMIN_URL . '/images/coffee.svg" />';
311 echo '<h3>Buy me a Coffee !</h3><p>If you like this plugin, buy me a coffee and help support this plugin !</p>';
312 echo '<div class="cfe_form">';
313 echo '<select class="cfe_amt">';
314 for($i = 5; $i <= 15; $i++){
315 echo '<option value="' . $i . '" ' . ($i == 6 ? 'selected="selected"' : '') . '>$' . $i . '</option>';
316 }
317 echo '<option value="">Custom</option>';
318 echo '</select>';
319 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>';
320 echo '</div>';
321 echo '</div>';
322
323 echo '</div>';
324 }
325
326 public static function footer_text( $text ){
327
328 if( SC_Admin::is_sc_admin_page() ){
329 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>';
330 }
331
332 return $text;
333
334 }
335
336 }
337
338 SC_Admin_Edit::init();
339
340 ?>