PluginProbe ʕ •ᴥ•ʔ
Shortcoder — Create Shortcodes for Anything / 5.0.4
Shortcoder — Create Shortcodes for Anything v5.0.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 6 years ago font 6 years ago images 6 years ago js 6 years ago admin.php 6 years ago edit.php 6 years ago form.php 6 years ago insert.php 6 years ago manage.php 6 years ago tools.php 6 years ago
edit.php
334 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.', 'sc' ) . '" value="' . $post->post_name . '" name="post_name" id="post_name" pattern="[a-zA-z0-9\-_]+" required placeholder="' . __( 'Enter shortcode name', 'sc' ) . '" />';
33 echo '</div>';
34
35 echo '<div id="edit-slug-box">';
36 echo '<strong>' . __( 'Your shortcode', 'sc' ) . ': </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</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', 'sc' ), array( __class__, 'settings_form' ), SC_POST_TYPE, 'normal', 'default' );
52
53 add_meta_box( 'sc_mb_coffee', __( 'Buy me a coffee !', 'sc' ), array( __class__, 'coffee_box' ), SC_POST_TYPE, 'side', 'default' );
54
55 add_meta_box( 'sc_mb_links', __( 'Feedback', 'sc' ), array( __class__, 'feedback' ), SC_POST_TYPE, 'side', 'default' );
56
57 remove_meta_box( 'slugdiv', SC_POST_TYPE, 'normal' );
58
59 }
60
61 public static function settings_form( $post ){
62
63 wp_nonce_field( 'sc_post_nonce', 'sc_nonce' );
64
65 $settings = Shortcoder::get_sc_settings( $post->ID );
66
67 $fields = array(
68
69 array( __( 'Display name', 'sc' ), SC_Admin_Form::field( 'text', array(
70 'value' => $post->post_title,
71 'name' => 'post_title',
72 'class' => 'widefat',
73 'helper' => __( 'Name of the shortcode to display when it is listed', 'sc' )
74 ))),
75
76 array( __( 'Temporarily disable shortcode', 'sc' ), SC_Admin_Form::field( 'select', array(
77 'value' => $settings[ '_sc_disable_sc' ],
78 'name' => '_sc_disable_sc',
79 'list' => array(
80 'yes' => 'Yes',
81 'no' => 'No'
82 ),
83 'helper' => __( 'Select to disable the shortcode from executing in all the places where it is used.', 'sc' )
84 ))),
85
86 array( __( 'Disable shortcode for administrators', 'sc' ), SC_Admin_Form::field( 'select', array(
87 'value' => $settings[ '_sc_disable_admin' ],
88 'name' => '_sc_disable_admin',
89 'list' => array(
90 'yes' => 'Yes',
91 'no' => 'No'
92 ),
93 'helper' => __( 'Select to disable the shortcode from executing for administrators.', 'sc' )
94 ))),
95
96 array( __( 'Execute shortcode in devices', 'sc' ), SC_Admin_Form::field( 'select', array(
97 'value' => $settings[ '_sc_allowed_devices' ],
98 'name' => '_sc_allowed_devices',
99 'list' => array(
100 'all' => 'All devices',
101 'desktop_only' => 'Desktop only',
102 'mobile_only' => 'Mobile only'
103 ),
104 '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.', 'sc' )
105 ))),
106
107 );
108
109 echo SC_Admin_Form::table($fields);
110
111 }
112
113 public static function save_post( $post_id ){
114
115 // Checks save status
116 $is_autosave = wp_is_post_autosave( $post_id );
117 $is_revision = wp_is_post_revision( $post_id );
118 $is_valid_nonce = ( isset( $_POST[ 'sc_nonce' ] ) && wp_verify_nonce( $_POST[ 'sc_nonce' ], 'sc_post_nonce' ) );
119
120 // Exits script depending on save status
121 if ( $is_autosave || $is_revision || !$is_valid_nonce ){
122 return;
123 }
124
125 $default_settings = Shortcoder::default_sc_settings();
126
127 foreach( $default_settings as $key => $val ){
128
129 if( array_key_exists( $key, $_POST ) ){
130 $val = sanitize_text_field( $_POST[ $key ] );
131 update_post_meta( $post_id, $key, $val );
132 }
133
134 }
135
136 }
137
138 public static function before_insert_post( $post ){
139
140 if( $post[ 'post_type' ] != SC_POST_TYPE ){
141 return $post;
142 }
143
144 if( empty( trim( $post[ 'post_title' ] ) ) ){
145 $post[ 'post_title' ] = $post[ 'post_name' ];
146 }
147
148 return $post;
149 }
150
151 public static function editor_props( $settings ){
152
153 $g = SC_Admin::clean_get();
154
155 $list = array(
156 'text' => __( 'Text editor', 'sc' ),
157 'visual' => __( 'Visual editor', 'sc' ),
158 'code' => __( 'Code editor', 'sc' )
159 );
160
161 $editor = ( isset( $g[ 'editor' ] ) && array_key_exists( $g[ 'editor' ], $list ) ) ? $g[ 'editor' ] : $settings[ '_sc_editor' ];
162
163 $switch = '<span class="sc_editor_list sc_editor_icon_' . $editor . '">';
164 $switch .= '<select name="_sc_editor" class="sc_editor" title="' . __( 'Switch editor', 'sc' ) . '">';
165 foreach( $list as $id => $name ){
166 $switch .= '<option value="' . $id . '" ' . selected( $editor, $id, false ) . '>' . $name . '</option>';
167 }
168 $switch .= '</select>';
169 $switch .= '</span>';
170
171 return array(
172 'active' => $editor,
173 'switch_html' => $switch
174 );
175
176 }
177
178 public static function editor( $post, $settings ){
179
180 $editor = self::editor_props( $settings );
181
182 echo '<div class="hidden">';
183 echo '<div class="sc_editor_toolbar">';
184 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>';
185 echo $editor[ 'switch_html' ];
186 echo '</div>';
187 echo '</div>';
188
189 if( $editor[ 'active' ] == 'code' ){
190 echo '<div class="sc_cm_menu"></div>';
191 $content = user_can_richedit() ? esc_textarea( $post->post_content ) : $post->post_content;
192 echo '<textarea name="content" id="content" class="sc_cm_content">' . $content . '</textarea>';
193 }else{
194 wp_editor( $post->post_content, 'content', array(
195 'wpautop'=> false,
196 'textarea_rows'=> 20,
197 'tinymce' => ( $editor[ 'active' ] == 'visual' )
198 ));
199 }
200
201 }
202
203 public static function enqueue_scripts( $hook ){
204
205 global $post;
206
207 if( !SC_Admin::is_sc_admin_page() || $hook == 'edit.php' || $hook == 'edit-tags.php' || $hook == 'term.php' ){
208 return false;
209 }
210
211 $settings = Shortcoder::get_sc_settings( $post->ID );
212 $editor = self::editor_props( $settings );
213
214 wp_localize_script( 'sc-admin-js', 'SC_EDITOR', $editor[ 'active' ] );
215
216 if( $editor[ 'active' ] != 'code' ){
217 return false;
218 }
219
220 $cm_cdn_url = 'https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.46.0/';
221 $cm_files = array(
222 'css' => array(
223 'codemirror.min.css'
224 ),
225 'js' => array(
226 'codemirror.min.js',
227 'mode/htmlmixed/htmlmixed.min.js',
228 'mode/css/css.min.js',
229 'mode/xml/xml.min.js',
230 'mode/javascript/javascript.min.js',
231 'addon/selection/active-line.min.js',
232 'addon/mode/overlay.min.js'
233 )
234 );
235
236 foreach( $cm_files as $type => $files ){
237 foreach( $files as $index => $file ){
238 $url = $cm_cdn_url . $file;
239 $id = 'sc-cm-' . $index;
240 if( $type == 'css' ){
241 wp_enqueue_style( $id, $url, array(), SC_VERSION );
242 }else{
243 wp_enqueue_script( $id, $url, array( 'sc-admin-js' ), SC_VERSION );
244 }
245 }
246 }
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 '<button class="button sc_cp_btn">' . __( 'Insert parameter', 'shortcoder' ) . '</button>';
270 echo '<p class="sc_cp_info"><small>' . __( 'Only alphabets and numbers allowed. Custom parameters are case insensitive', 'shortcoder' ) . '</small></p></li>';
271 echo '</ul></li>';
272
273 echo '<li><span class="dashicons dashicons-screenoptions"></span>' . __( 'Custom Fields', 'shortcoder' ) . '<ul>';
274 echo '<li class="sc_params_form"><h4>' . __( 'Enter custom field name', 'shortcoder' ) . '</h4>';
275 echo '<input type="text" class="sc_cf_box widefat" pattern="[a-zA-Z0-9_-]+"/>';
276 echo '<button class="button sc_cf_btn">' . __( 'Insert custom field', 'shortcoder' ) . '</button>';
277 echo '<p class="sc_cf_info"><small>' . __( 'Only alphabets, numbers, underscore and hyphens are allowed. Cannot be empty.', 'shortcoder' ) . '</small></p></li>';
278 echo '</ul></li>';
279
280 echo '</ul>';
281
282 }
283
284 public static function hidden_section( $post, $settings ){
285
286 self::custom_params_list();
287
288 }
289
290 public static function coffee_box( $post ){
291 echo '<div class="cfe_mb">';
292 echo '<div class="cfe_text">';
293 echo '<p>If you like this plugin, buy me a coffee !</p>';
294 echo '<img src="' . SC_ADMIN_URL . '/images/coffee.svg" />';
295 echo '</div>';
296 echo '<div class="cfe_form">';
297 echo '<select class="cfe_amt">';
298 for($i = 5; $i <= 15; $i++){
299 echo '<option value="' . $i . '" ' . ($i == 6 ? 'selected="selected"' : '') . '>$' . $i . '</option>';
300 }
301 echo '<option value="">Custom</option>';
302 echo '</select>';
303 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 coffee !</a>';
304 echo '</div>';
305 echo '</div>';
306 }
307
308 public static function feedback( $post ){
309 echo '<div class="feedback">';
310 echo '<ul>
311 <li><a href="https://wordpress.org/support/plugin/shortcoder/reviews/?rate=5#new-post" target="_blank">Rate and review</a><div class="stars"><span class="dashicons dashicons-star-filled"></span><span class="dashicons dashicons-star-filled"></span><span class="dashicons dashicons-star-filled"></span><span class="dashicons dashicons-star-filled"></span><span class="dashicons dashicons-star-filled"></span></div></li>
312 <li><a href="https://www.aakashweb.com/forum/discuss/wordpress-plugins/shortcoder/#new-post" target="_blank">Request a feature</a></li>
313 <li><a href="https://www.aakashweb.com/forum/discuss/wordpress-plugins/shortcoder/#new-post" target="_blank">Report a bug</a></li>
314 <li><a href="https://www.aakashweb.com/docs/shortcoder-doc/" target="_blank">FAQ</a></li>
315 <li><a href="https://www.aakashweb.com/wordpress-plugins/" target="_blank">More plugins</a></li>
316 </ul>';
317 echo '</div>';
318 }
319
320 public static function footer_text( $text ){
321
322 if( SC_Admin::is_sc_admin_page() ){
323 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 &bull; <a href="https://www.paypal.me/vaakash/" target="_blank">Buy me a coffee !</a></span>';
324 }
325
326 return $text;
327
328 }
329
330 }
331
332 SC_Admin_Edit::init();
333
334 ?>