css
3 years ago
font
3 years ago
images
3 years ago
js
3 years ago
admin.php
3 years ago
edit.php
3 years ago
form.php
3 years ago
insert.php
3 years ago
manage.php
3 years ago
settings.php
3 years ago
tools.php
3 years ago
edit.php
371 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="' . esc_attr__( 'Name of the shortcode. Allowed characters are alphabets, numbers, hyphens and underscore.', 'shortcoder' ) . '" value="' . esc_attr( $post->post_name ) . '" name="post_name" id="post_name" pattern="[a-zA-z0-9\-_]+" required placeholder="' . esc_attr__( 'Enter shortcode name', 'shortcoder' ) . '" />'; |
| 33 | echo '</div>'; |
| 34 | |
| 35 | echo '<div id="edit-slug-box">'; |
| 36 | echo '<strong>' . esc_html__( 'Your shortcode', 'shortcoder' ) . ': </strong>'; |
| 37 | echo '<code class="sc_preview_text">' . esc_html( 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> ' . esc_html__( 'Copy', 'shortcoder' ) . '</button></span>'; |
| 39 | echo '<a href="#sc_mb_settings" class="sc_settings_link">' . esc_html__( 'Settings', 'shortcoder' ) . '</a>'; |
| 40 | echo '</div>'; |
| 41 | |
| 42 | // Editor |
| 43 | self::editor( $post, $settings ); |
| 44 | |
| 45 | // Hidden section |
| 46 | self::hidden_section( $post, $settings ); |
| 47 | |
| 48 | } |
| 49 | |
| 50 | public static function add_meta_boxes(){ |
| 51 | |
| 52 | add_meta_box( 'sc_mb_settings', __( 'Shortcode settings', 'shortcoder' ), array( __CLASS__, 'settings_form' ), SC_POST_TYPE, 'normal', 'default' ); |
| 53 | |
| 54 | add_meta_box( 'sc_mb_more_plugins', __( 'Support', 'shortcoder' ), array( __CLASS__, 'more_plugins' ), SC_POST_TYPE, 'side', 'default' ); |
| 55 | |
| 56 | add_meta_box( 'sc_mb_links', __( 'WordPress News', 'shortcoder' ), array( __CLASS__, 'feedback' ), SC_POST_TYPE, 'side', 'default' ); |
| 57 | |
| 58 | remove_meta_box( 'slugdiv', SC_POST_TYPE, 'normal' ); |
| 59 | |
| 60 | remove_meta_box( 'commentstatusdiv', SC_POST_TYPE, 'normal' ); |
| 61 | |
| 62 | remove_meta_box( 'commentsdiv', SC_POST_TYPE, 'normal' ); |
| 63 | |
| 64 | } |
| 65 | |
| 66 | public static function settings_form( $post ){ |
| 67 | |
| 68 | wp_nonce_field( 'sc_post_nonce', 'sc_nonce' ); |
| 69 | |
| 70 | $settings = Shortcoder::get_sc_settings( $post->ID ); |
| 71 | |
| 72 | $fields = array( |
| 73 | |
| 74 | array( __( 'Display name', 'shortcoder' ), SC_Admin_Form::field( 'text', array( |
| 75 | 'value' => $post->post_title, |
| 76 | 'name' => 'post_title', |
| 77 | 'class' => 'widefat', |
| 78 | 'helper' => __( 'Name of the shortcode to display when it is listed', 'shortcoder' ) |
| 79 | ))), |
| 80 | |
| 81 | array( __( 'Description', 'shortcoder' ), SC_Admin_Form::field( 'textarea', array( |
| 82 | 'value' => $settings[ '_sc_description' ], |
| 83 | 'name' => '_sc_description', |
| 84 | 'class' => 'widefat', |
| 85 | 'helper' => __( 'Description of the shortcode for identification', 'shortcoder' ) |
| 86 | ))), |
| 87 | |
| 88 | array( __( 'Temporarily disable shortcode', 'shortcoder' ), SC_Admin_Form::field( 'select', array( |
| 89 | 'value' => $settings[ '_sc_disable_sc' ], |
| 90 | 'name' => '_sc_disable_sc', |
| 91 | 'list' => array( |
| 92 | 'yes' => 'Yes', |
| 93 | 'no' => 'No' |
| 94 | ), |
| 95 | 'helper' => __( 'Select to disable the shortcode from executing in all the places where it is used.', 'shortcoder' ) |
| 96 | ))), |
| 97 | |
| 98 | array( __( 'Disable shortcode for administrators', 'shortcoder' ), SC_Admin_Form::field( 'select', array( |
| 99 | 'value' => $settings[ '_sc_disable_admin' ], |
| 100 | 'name' => '_sc_disable_admin', |
| 101 | 'list' => array( |
| 102 | 'yes' => 'Yes', |
| 103 | 'no' => 'No' |
| 104 | ), |
| 105 | 'helper' => __( 'Select to disable the shortcode from executing for administrators.', 'shortcoder' ) |
| 106 | ))), |
| 107 | |
| 108 | array( __( 'Execute shortcode on devices', 'shortcoder' ), SC_Admin_Form::field( 'select', array( |
| 109 | 'value' => $settings[ '_sc_allowed_devices' ], |
| 110 | 'name' => '_sc_allowed_devices', |
| 111 | 'list' => array( |
| 112 | 'all' => 'All devices', |
| 113 | 'desktop_only' => 'Desktop only', |
| 114 | 'mobile_only' => 'Mobile only' |
| 115 | ), |
| 116 | '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' ) |
| 117 | ))), |
| 118 | |
| 119 | ); |
| 120 | |
| 121 | echo SC_Admin_Form::table( apply_filters( 'sc_mod_sc_settings_fields', $fields, $settings ) ); |
| 122 | |
| 123 | } |
| 124 | |
| 125 | public static function save_post( $post_id ){ |
| 126 | |
| 127 | // Checks save status |
| 128 | $is_autosave = wp_is_post_autosave( $post_id ); |
| 129 | $is_revision = wp_is_post_revision( $post_id ); |
| 130 | $is_valid_nonce = ( isset( $_POST[ 'sc_nonce' ] ) && wp_verify_nonce( $_POST[ 'sc_nonce' ], 'sc_post_nonce' ) ); |
| 131 | |
| 132 | // Exits script depending on save status |
| 133 | if ( $is_autosave || $is_revision || !$is_valid_nonce ){ |
| 134 | return; |
| 135 | } |
| 136 | |
| 137 | $default_settings = Shortcoder::default_sc_settings(); |
| 138 | $skip_sanitize = array(); |
| 139 | |
| 140 | foreach( $default_settings as $key => $val ){ |
| 141 | |
| 142 | if( array_key_exists( $key, $_POST ) ){ |
| 143 | if( in_array( $key, $skip_sanitize ) ){ |
| 144 | $val = current_user_can( 'unfiltered_html' ) ? $_POST[ $key ] : wp_kses_post( $_POST[ $key ] ); |
| 145 | }else{ |
| 146 | $val = sanitize_text_field( $_POST[ $key ] ); |
| 147 | } |
| 148 | update_post_meta( $post_id, $key, $val ); |
| 149 | } |
| 150 | |
| 151 | } |
| 152 | |
| 153 | } |
| 154 | |
| 155 | public static function before_insert_post( $post ){ |
| 156 | |
| 157 | if( $post[ 'post_type' ] != SC_POST_TYPE ){ |
| 158 | return $post; |
| 159 | } |
| 160 | |
| 161 | $post_title = sanitize_text_field( $post[ 'post_title' ] ); |
| 162 | if( empty( $post_title ) ){ |
| 163 | $post[ 'post_title' ] = sanitize_text_field( $post[ 'post_name' ] ); |
| 164 | } |
| 165 | |
| 166 | if( $_POST && isset( $_POST[ 'sc_content' ] ) ){ |
| 167 | $post[ 'post_content' ] = current_user_can( 'unfiltered_html' ) ? $_POST[ 'sc_content' ] : wp_kses_post( $_POST[ 'sc_content' ] ); |
| 168 | } |
| 169 | |
| 170 | return $post; |
| 171 | } |
| 172 | |
| 173 | public static function editor_props( $settings ){ |
| 174 | |
| 175 | $g = SC_Admin::clean_get(); |
| 176 | |
| 177 | if( empty( $settings[ '_sc_editor' ] ) ){ |
| 178 | $general_settings = Shortcoder::get_settings(); |
| 179 | $settings[ '_sc_editor' ] = $general_settings[ 'default_editor' ]; |
| 180 | } |
| 181 | |
| 182 | $list = apply_filters( 'sc_mod_editors', array( |
| 183 | 'text' => __( 'Text editor', 'shortcoder' ), |
| 184 | 'visual' => __( 'Visual editor', 'shortcoder' ), |
| 185 | 'code' => __( 'Code editor', 'shortcoder' ) |
| 186 | )); |
| 187 | |
| 188 | $editor = ( isset( $g[ 'editor' ] ) && array_key_exists( $g[ 'editor' ], $list ) ) ? $g[ 'editor' ] : $settings[ '_sc_editor' ]; |
| 189 | |
| 190 | $switch = '<span class="sc_editor_list sc_editor_icon_' . esc_attr( $editor ) . '">'; |
| 191 | $switch .= '<select name="_sc_editor" class="sc_editor" title="' . esc_attr__( 'Switch editor', 'shortcoder' ) . '">'; |
| 192 | foreach( $list as $id => $name ){ |
| 193 | $switch .= '<option value="' . esc_attr( $id ) . '" ' . selected( $editor, $id, false ) . '>' . esc_html( $name ) . '</option>'; |
| 194 | } |
| 195 | $switch .= '</select>'; |
| 196 | $switch .= '</span>'; |
| 197 | |
| 198 | return array( |
| 199 | 'active' => $editor, |
| 200 | 'switch_html' => $switch |
| 201 | ); |
| 202 | |
| 203 | } |
| 204 | |
| 205 | public static function editor( $post, $settings ){ |
| 206 | |
| 207 | $editor = self::editor_props( $settings ); |
| 208 | |
| 209 | echo '<div class="hidden">'; |
| 210 | echo '<div class="sc_editor_toolbar">'; |
| 211 | echo '<button class="button button-primary sc_insert_param"><span class="dashicons dashicons-plus"></span>' . esc_html__( 'Insert shortcode parameters', 'shortcoder' ) . '<span class="dashicons dashicons-arrow-down"></span></button>'; |
| 212 | echo $editor[ 'switch_html' ]; |
| 213 | echo '</div>'; |
| 214 | echo '</div>'; |
| 215 | |
| 216 | $post_data = get_post( $post->ID ); |
| 217 | $post_content = $post_data->post_content; |
| 218 | |
| 219 | if( SC_Admin::is_edit_page( 'new' ) ){ |
| 220 | $general_settings = Shortcoder::get_settings(); |
| 221 | $post_content = $general_settings[ 'default_content' ]; |
| 222 | } |
| 223 | |
| 224 | if( $editor[ 'active' ] == 'code' ){ |
| 225 | echo '<div class="sc_cm_menu"></div>'; |
| 226 | echo '<textarea name="sc_content" id="sc_content" class="sc_cm_content">' . esc_textarea( $post_content ) . '</textarea>'; |
| 227 | } |
| 228 | |
| 229 | if( in_array( $editor[ 'active' ], array( 'text', 'visual' ) ) ){ |
| 230 | wp_editor( $post_content, 'sc_content', array( |
| 231 | 'wpautop'=> false, |
| 232 | 'textarea_rows'=> 20, |
| 233 | 'tinymce' => ( $editor[ 'active' ] == 'visual' ) |
| 234 | )); |
| 235 | } |
| 236 | |
| 237 | if( !current_user_can( 'unfiltered_html' ) ){ |
| 238 | echo '<div class="notice notice-info"><p>' . esc_html__( 'Note: Your user role does not permit saving unrestricted HTML. Some tags and attributes will be removed before saving the content.', 'shortcoder' ) . '</p></div>'; |
| 239 | } |
| 240 | |
| 241 | do_action( 'sc_do_after_editor', $post, $settings, $editor ); |
| 242 | |
| 243 | } |
| 244 | |
| 245 | public static function enqueue_scripts( $hook ){ |
| 246 | |
| 247 | global $post; |
| 248 | |
| 249 | if( !SC_Admin::is_sc_admin_page() || $hook == 'edit.php' || $hook == 'edit-tags.php' || $hook == 'term.php' || $hook == 'shortcoder_page_settings' ){ |
| 250 | return false; |
| 251 | } |
| 252 | |
| 253 | $settings = Shortcoder::get_sc_settings( $post->ID ); |
| 254 | $editor = self::editor_props( $settings ); |
| 255 | |
| 256 | wp_localize_script( 'sc-admin-js', 'SC_EDITOR', array( |
| 257 | 'active' => $editor[ 'active' ] |
| 258 | )); |
| 259 | |
| 260 | if( $editor[ 'active' ] != 'code' ){ |
| 261 | return false; |
| 262 | } |
| 263 | |
| 264 | $cm_settings = array(); |
| 265 | $cm_settings[ 'codeEditor' ] = wp_enqueue_code_editor(array( |
| 266 | 'type' => 'htmlmixed' |
| 267 | )); |
| 268 | |
| 269 | wp_localize_script( 'sc-admin-js', 'SC_CODEMIRROR', $cm_settings ); |
| 270 | |
| 271 | } |
| 272 | |
| 273 | public static function custom_params_list(){ |
| 274 | |
| 275 | $sc_wp_params = Shortcoder::wp_params_list(); |
| 276 | |
| 277 | echo '<ul class="sc_params_list">'; |
| 278 | |
| 279 | foreach( $sc_wp_params as $group => $group_info ){ |
| 280 | echo '<li><span class="dashicons dashicons-' . esc_attr( $group_info['icon'] ) . '"></span>'; |
| 281 | echo esc_html( $group_info[ 'name' ] ); |
| 282 | echo '<ul class="sc_wp_params">'; |
| 283 | foreach( $group_info[ 'params' ] as $param_id => $param_name ){ |
| 284 | echo '<li data-id="' . esc_attr( $param_id ) . '">' . esc_html( $param_name ) . '</li>'; |
| 285 | } |
| 286 | echo '</ul></li>'; |
| 287 | } |
| 288 | |
| 289 | echo '<li><span class="dashicons dashicons-list-view"></span>' . esc_html__( 'Custom parameter', 'shortcoder' ) . '<ul>'; |
| 290 | echo '<li class="sc_params_form">'; |
| 291 | echo '<p>' . esc_html__( 'Insert parameters in content and replace them with custom values when using the shortcode.', 'shortcoder' ) . '<a href="https://www.aakashweb.com/docs/shortcoder/custom-parameters/" target="_blank" title="' . esc_attr__( 'More information', 'shortcoder' ) . '"><span class="dashicons dashicons-info"></span></a></p>'; |
| 292 | echo '<h4>' . esc_html__( 'Enter custom parameter name', 'shortcoder' ) . '</h4>'; |
| 293 | echo '<input type="text" class="sc_cp_box widefat" pattern="[a-zA-Z0-9_-]+"/>'; |
| 294 | echo '<h4>' . esc_html__( 'Default value', 'shortcoder' ) . '</h4>'; |
| 295 | echo '<input type="text" class="sc_cp_default widefat"/>'; |
| 296 | echo '<button class="button sc_cp_btn">' . esc_html__( 'Insert parameter', 'shortcoder' ) . '</button>'; |
| 297 | echo '<p class="sc_cp_info"><small>' . esc_html__( 'Only alphabets, numbers, underscores and hyphens are allowed. Custom parameters are case insensitive', 'shortcoder' ) . '</small></p></li>'; |
| 298 | echo '</ul></li>'; |
| 299 | |
| 300 | echo '<li><span class="dashicons dashicons-screenoptions"></span>' . esc_html__( 'Custom Fields', 'shortcoder' ) . '<ul>'; |
| 301 | echo '<li class="sc_params_form">'; |
| 302 | echo '<p>' . esc_html__( 'Pull a custom field value of the current post and display it inside the shortcode content.', 'shortcoder' ) . '<a href="https://www.aakashweb.com/docs/shortcoder/shortcode-parameters/#custom-fields" target="_blank" title="' . esc_attr__( 'More information', 'shortcoder' ) . '"><span class="dashicons dashicons-info"></span></a></p>'; |
| 303 | echo '<h4>' . esc_html__( 'Enter custom field name', 'shortcoder' ) . '</h4>'; |
| 304 | echo '<input type="text" class="sc_cf_box widefat" pattern="[a-zA-Z0-9_-]+"/>'; |
| 305 | echo '<button class="button sc_cf_btn">' . esc_html__( 'Insert custom field', 'shortcoder' ) . '</button>'; |
| 306 | echo '<p class="sc_cf_info"><small>' . esc_html__( 'Only alphabets, numbers, underscore and hyphens are allowed. Cannot be empty.', 'shortcoder' ) . '</small></p></li>'; |
| 307 | echo '</ul></li>'; |
| 308 | |
| 309 | echo '</ul>'; |
| 310 | |
| 311 | } |
| 312 | |
| 313 | public static function hidden_section( $post, $settings ){ |
| 314 | |
| 315 | self::custom_params_list(); |
| 316 | |
| 317 | } |
| 318 | |
| 319 | public static function feedback( $post ){ |
| 320 | echo '<div class="feedback">'; |
| 321 | |
| 322 | echo '<p>Get updates on the WordPress plugins, tips and tricks to enhance your WordPress experience. No spam.</p>'; |
| 323 | |
| 324 | echo '<div class="subscribe_form" data-action="https://aakashweb.us19.list-manage.com/subscribe/post-json?u=b7023581458d048107298247e&id=ef5ab3c5c4&c="> |
| 325 | <input type="text" value="' . esc_attr( get_option( 'admin_email' ) ) . '" class="subscribe_email_box" placeholder="Your email address"> |
| 326 | <p class="subscribe_confirm">Thanks for subscribing !</p> |
| 327 | <button class="button subscribe_btn"><span class="dashicons dashicons-email"></span> Subscribe</button> |
| 328 | </div>'; |
| 329 | |
| 330 | echo '</div>'; |
| 331 | } |
| 332 | |
| 333 | public static function more_plugins( $post ){ |
| 334 | |
| 335 | echo '<div class="feedback">'; |
| 336 | |
| 337 | echo '<ul>'; |
| 338 | echo '<li><a href="https://twitter.com/intent/follow?screen_name=aakashweb" target="_blank"><span class="dashicons dashicons-twitter"></span> Follow on Twitter</a></li>'; |
| 339 | echo '<li><a href="https://www.facebook.com/aakashweb/" target="_blank"><span class="dashicons dashicons-facebook-alt"></span> Follow on Facebook</a></li>'; |
| 340 | echo '<li><a href="https://www.aakashweb.com/forum/discuss/wordpress-plugins/shortcoder/" target="_blank"><span class="dashicons dashicons-format-chat"></span> Support Forum</a></li>'; |
| 341 | echo '<li><a href="https://wordpress.org/support/plugin/shortcoder/reviews/?rate=5#new-post" target="_blank"><span class="dashicons dashicons-star-filled"></span> Rate plugin</a></li>'; |
| 342 | echo '</ul>'; |
| 343 | |
| 344 | echo '<h3>More WordPress plugins from us</h3>'; |
| 345 | echo '<ul>'; |
| 346 | echo '<li><a href="https://www.aakashweb.com/wordpress-plugins/super-rss-reader/?utm_source=shortcoder&utm_medium=sidebar&utm_campaign=srr-pro" target="_blank">Super RSS Reader</a> - Display RSS feeds</li>'; |
| 347 | echo '<li><a href="https://www.aakashweb.com/wordpress-plugins/announcer/?utm_source=shortcoder&utm_medium=sidebar&utm_campaign=announcer-pro" target="_blank">Announcer</a> - Add notification message bars easily</li>'; |
| 348 | echo '<li><a href="https://www.aakashweb.com/wordpress-plugins/ultimate-floating-widgets/?utm_source=shortcoder&utm_medium=sidebar&utm_campaign=ufw-pro" target="_blank">Ultimate Floating Widget</a> - Create floating sidebar popup and add widgets inside</li>'; |
| 349 | echo '<li><a href="https://www.aakashweb.com/wordpress-plugins/wp-socializer/?utm_source=shortcoder&utm_medium=sidebar&utm_campaign=wpsr-pro" target="_blank">WP Socializer</a> - Add beautiful social media share icons</li>'; |
| 350 | echo '<li><a href="https://www.aakashweb.com/wordpress-plugins/?utm_source=shortcoder&utm_medium=sidebar&utm_campaign=aw" target="_blank">More</a> <span class="dashicons dashicons-arrow-right-alt"></span></li>'; |
| 351 | echo '</ul>'; |
| 352 | |
| 353 | echo '</div>'; |
| 354 | |
| 355 | } |
| 356 | |
| 357 | public static function footer_text( $text ){ |
| 358 | |
| 359 | if( SC_Admin::is_sc_admin_page() ){ |
| 360 | return '<span class="footer_thanks">Thanks for using <a href="https://www.aakashweb.com/wordpress-plugins/shortcoder/" target="_blank">Shortcoder</a> • 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>'; |
| 361 | } |
| 362 | |
| 363 | return $text; |
| 364 | |
| 365 | } |
| 366 | |
| 367 | } |
| 368 | |
| 369 | SC_Admin_Edit::init(); |
| 370 | |
| 371 | ?> |