PluginProbe ʕ •ᴥ•ʔ
Shortcoder — Create Shortcodes for Anything / 5.0.1
Shortcoder — Create Shortcodes for Anything v5.0.1
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
333 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 echo '<textarea name="content" id="content" class="sc_cm_content">' . $post->post_content . '</textarea>';
192 }else{
193 wp_editor( $post->post_content, 'content', array(
194 'wpautop'=> false,
195 'textarea_rows'=> 20,
196 'tinymce' => ( $editor[ 'active' ] == 'visual' )
197 ));
198 }
199
200 }
201
202 public static function enqueue_scripts( $hook ){
203
204 global $post;
205
206 if( !SC_Admin::is_sc_admin_page() || $hook == 'edit.php' || $hook == 'edit-tags.php' || $hook == 'term.php' ){
207 return false;
208 }
209
210 $settings = Shortcoder::get_sc_settings( $post->ID );
211 $editor = self::editor_props( $settings );
212
213 wp_localize_script( 'sc-admin-js', 'SC_EDITOR', $editor[ 'active' ] );
214
215 if( $editor[ 'active' ] != 'code' ){
216 return false;
217 }
218
219 $cm_cdn_url = 'https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.46.0/';
220 $cm_files = array(
221 'css' => array(
222 'codemirror.min.css'
223 ),
224 'js' => array(
225 'codemirror.min.js',
226 'mode/htmlmixed/htmlmixed.min.js',
227 'mode/css/css.min.js',
228 'mode/xml/xml.min.js',
229 'mode/javascript/javascript.min.js',
230 'addon/selection/active-line.min.js',
231 'addon/mode/overlay.min.js'
232 )
233 );
234
235 foreach( $cm_files as $type => $files ){
236 foreach( $files as $index => $file ){
237 $url = $cm_cdn_url . $file;
238 $id = 'sc-cm-' . $index;
239 if( $type == 'css' ){
240 wp_enqueue_style( $id, $url, array(), SC_VERSION );
241 }else{
242 wp_enqueue_script( $id, $url, array( 'sc-admin-js' ), SC_VERSION );
243 }
244 }
245 }
246
247 }
248
249 public static function custom_params_list(){
250
251 $sc_wp_params = Shortcoder::wp_params_list();
252
253 echo '<ul class="sc_params_list">';
254
255 foreach( $sc_wp_params as $group => $group_info ){
256 echo '<li><span class="dashicons dashicons-' . $group_info['icon'] . '"></span>';
257 echo $group_info[ 'name' ];
258 echo '<ul class="sc_wp_params">';
259 foreach( $group_info[ 'params' ] as $param_id => $param_name ){
260 echo '<li data-id="' . $param_id . '">' . $param_name . '</li>';
261 }
262 echo '</ul></li>';
263 }
264
265 echo '<li><span class="dashicons dashicons-list-view"></span>' . __( 'Custom parameter', 'shortcoder' ) . '<ul>';
266 echo '<li class="sc_params_form"><h4>' . __( 'Enter custom parameter name', 'shortcoder' ) . '</h4>';
267 echo '<input type="text" class="sc_cp_box widefat" pattern="[a-zA-Z0-9]+"/>';
268 echo '<button class="button sc_cp_btn">' . __( 'Insert parameter', 'shortcoder' ) . '</button>';
269 echo '<p class="sc_cp_info"><small>' . __( 'Only alphabets and numbers allowed. Custom parameters are case insensitive', 'shortcoder' ) . '</small></p></li>';
270 echo '</ul></li>';
271
272 echo '<li><span class="dashicons dashicons-screenoptions"></span>' . __( 'Custom Fields', 'shortcoder' ) . '<ul>';
273 echo '<li class="sc_params_form"><h4>' . __( 'Enter custom field name', 'shortcoder' ) . '</h4>';
274 echo '<input type="text" class="sc_cf_box widefat" pattern="[a-zA-Z0-9_-]+"/>';
275 echo '<button class="button sc_cf_btn">' . __( 'Insert custom field', 'shortcoder' ) . '</button>';
276 echo '<p class="sc_cf_info"><small>' . __( 'Only alphabets, numbers, underscore and hyphens are allowed. Cannot be empty.', 'shortcoder' ) . '</small></p></li>';
277 echo '</ul></li>';
278
279 echo '</ul>';
280
281 }
282
283 public static function hidden_section( $post, $settings ){
284
285 self::custom_params_list();
286
287 }
288
289 public static function coffee_box( $post ){
290 echo '<div class="cfe_mb">';
291 echo '<div class="cfe_text">';
292 echo '<p>If you like this plugin, buy me a coffee !</p>';
293 echo '<img src="' . SC_ADMIN_URL . '/images/coffee.svg" />';
294 echo '</div>';
295 echo '<div class="cfe_form">';
296 echo '<select class="cfe_amt">';
297 for($i = 5; $i <= 15; $i++){
298 echo '<option value="' . $i . '" ' . ($i == 6 ? 'selected="selected"' : '') . '>$' . $i . '</option>';
299 }
300 echo '<option value="">Custom</option>';
301 echo '</select>';
302 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>';
303 echo '</div>';
304 echo '</div>';
305 }
306
307 public static function feedback( $post ){
308 echo '<div class="feedback">';
309 echo '<ul>
310 <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>
311 <li><a href="https://www.aakashweb.com/forum/discuss/wordpress-plugins/shortcoder/#new-post" target="_blank">Request a feature</a></li>
312 <li><a href="https://www.aakashweb.com/forum/discuss/wordpress-plugins/shortcoder/#new-post" target="_blank">Report a bug</a></li>
313 <li><a href="https://www.aakashweb.com/docs/shortcoder-doc/" target="_blank">FAQ</a></li>
314 <li><a href="https://www.aakashweb.com/wordpress-plugins/" target="_blank">More plugins</a></li>
315 </ul>';
316 echo '</div>';
317 }
318
319 public static function footer_text( $text ){
320
321 if( SC_Admin::is_sc_admin_page() ){
322 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>';
323 }
324
325 return $text;
326
327 }
328
329 }
330
331 SC_Admin_Edit::init();
332
333 ?>