css
8 years ago
images
8 years ago
js
8 years ago
sc-admin.php
8 years ago
sc-insert.php
8 years ago
sc-admin.php
508 lines
| 1 | <?php |
| 2 | |
| 3 | class Shortcoder_Admin{ |
| 4 | |
| 5 | private static $pagehook = 'settings_page_shortcoder'; |
| 6 | |
| 7 | public static function init(){ |
| 8 | |
| 9 | // Add menu |
| 10 | add_action( 'admin_menu', array( __class__, 'add_menu' ) ); |
| 11 | |
| 12 | // Enqueue the scripts and styles |
| 13 | add_action( 'admin_enqueue_scripts', array( __CLASS__, 'enqueue_scripts' ) ); |
| 14 | |
| 15 | // Register the action for admin ajax features |
| 16 | add_action( 'wp_ajax_sc_admin_ajax', array( __CLASS__, 'admin_ajax' ) ); |
| 17 | |
| 18 | // Register action links |
| 19 | add_filter( 'plugin_action_links_' . SC_BASE_NAME, array( __CLASS__, 'action_links' ) ); |
| 20 | |
| 21 | // Add Quick Tag button to the editor |
| 22 | add_action( 'admin_footer', array( __class__, 'add_qt_button' ) ); |
| 23 | |
| 24 | // Add TinyMCE button |
| 25 | add_action( 'admin_init', array( __class__, 'register_mce' ) ); |
| 26 | |
| 27 | } |
| 28 | |
| 29 | public static function add_menu(){ |
| 30 | |
| 31 | add_options_page( 'Shortcoder', 'Shortcoder', 'manage_options', 'shortcoder', array( __class__, 'admin_page' ) ); |
| 32 | |
| 33 | } |
| 34 | |
| 35 | public static function enqueue_scripts( $hook ){ |
| 36 | |
| 37 | if( $hook == self::$pagehook ){ |
| 38 | |
| 39 | wp_enqueue_style( 'sc-admin-css', SC_ADMIN_URL . '/css/style.css', array(), SC_VERSION ); |
| 40 | |
| 41 | wp_enqueue_script( 'jquery' ); |
| 42 | wp_enqueue_script( 'sc-admin-js', SC_ADMIN_URL . '/js/script.js', array( 'jquery' ), SC_VERSION ); |
| 43 | |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | public static function admin_page(){ |
| 48 | |
| 49 | echo '<div class="wrap">'; |
| 50 | echo '<div class="head_wrap">'; |
| 51 | echo '<h1 class="sc_title">Shortcoder <span class="title-count">' . SC_VERSION . '</span></h1>'; |
| 52 | self::top_sharebar(); |
| 53 | self::print_notice(); |
| 54 | echo '</div>'; |
| 55 | |
| 56 | echo '<div id="content">'; |
| 57 | |
| 58 | $g = self::clean_get(); |
| 59 | |
| 60 | if( !isset( $g[ 'action' ] ) ){ |
| 61 | $g[ 'action' ] = 'list'; |
| 62 | } |
| 63 | |
| 64 | if( $g[ 'action' ] == 'list' ){ |
| 65 | self::list_shortcodes(); |
| 66 | } |
| 67 | |
| 68 | if( $g[ 'action' ] == 'edit' ){ |
| 69 | self::edit_shortcode(); |
| 70 | } |
| 71 | |
| 72 | if( $g[ 'action' ] == 'new' ){ |
| 73 | self::new_shortcode(); |
| 74 | } |
| 75 | |
| 76 | echo '</div>'; |
| 77 | |
| 78 | self::page_bottom(); |
| 79 | |
| 80 | echo '</div>'; |
| 81 | |
| 82 | } |
| 83 | |
| 84 | public static function list_shortcodes(){ |
| 85 | |
| 86 | $shortcodes = Shortcoder::list_all(); |
| 87 | $g = self::clean_get(); |
| 88 | |
| 89 | echo '<h3 class="page_title">' . __( 'List of shortcodes created', 'shortcoder' ); |
| 90 | echo '<span class="sc_menu">'; |
| 91 | echo '<button class="button sort_btn" title="' . __( 'Sort list', 'shortcoder' ) . '"><span class="dashicons dashicons-menu"></span> <span class="dashicons dashicons-arrow-down-alt sort_icon"></span></button>'; |
| 92 | echo '<a href="' . self::get_link(array( 'action' => 'new' )) . '" class="button button-primary sc_new_btn"><span class="dashicons dashicons-plus"></span> ' . __( 'Create a new shortcode', 'shortcoder' ) . '</a>'; |
| 93 | echo '</span>'; |
| 94 | echo '</h3>'; |
| 95 | |
| 96 | if( isset( $g[ 'sort' ] ) ){ |
| 97 | $sort = $g[ 'sort' ]; |
| 98 | if( $sort == 'asc' ){ |
| 99 | uksort($shortcodes, 'strcasecmp' ); |
| 100 | }else if( $sort == 'desc' ){ |
| 101 | uksort($shortcodes, 'strcasecmp' ); |
| 102 | $shortcodes = array_reverse( $shortcodes, True ); |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | echo '<ul class="sc_list" data-empty="' . __( 'No shortcodes are created. Go ahead create one !', 'shortcoder' ) . '">'; |
| 107 | foreach( $shortcodes as $name => $data ){ |
| 108 | |
| 109 | $data = wp_parse_args( $data, Shortcoder::defaults() ); |
| 110 | |
| 111 | $link = self::get_link(array( |
| 112 | 'action' => 'edit', |
| 113 | 'name' => $name |
| 114 | )); |
| 115 | |
| 116 | $delete_link = self::get_link(array( |
| 117 | 'action' => 'sc_admin_ajax', |
| 118 | 'do' => 'delete', |
| 119 | 'name' => $name, |
| 120 | '_wpnonce' => wp_create_nonce( 'sc_delete_nonce' ) |
| 121 | ), 'admin-ajax.php' ); |
| 122 | |
| 123 | $disabled_text = ( $data[ 'disabled' ] == '1' ) ? '<small class="disabled_text">' . __( 'Temporarily disabled', 'shortcoder' ) . '</small>' : ''; |
| 124 | |
| 125 | echo '<li data-name="' . esc_attr( $name ) . '">'; |
| 126 | echo '<a href="' . $link . '" class="sc_link" title="' . __( 'Edit shortcode', 'shortcoder' ) . '">' . $name . $disabled_text . '</a>'; |
| 127 | echo '<span class="sc_controls">'; |
| 128 | echo '<a href="#" class="sc_copy" title="' . __( 'Copy shortcode', 'shortcoder' ) . '"><span class="dashicons dashicons-editor-code"></span></a>'; |
| 129 | echo '<a href="' . $delete_link . '" class="sc_delete" title="' . __( 'Delete', 'shortcoder' ) . '"><span class="dashicons dashicons-trash"></span></a>'; |
| 130 | echo '</span>'; |
| 131 | |
| 132 | echo '<input type="text" value="' . self::get_shortcode( $name ) . '" class="sc_copy_box" readonly="readonly" title="' . __( 'Copy shortcode', 'shortcoder' ) . '" />'; |
| 133 | |
| 134 | echo '</li>'; |
| 135 | |
| 136 | } |
| 137 | echo '</ul>'; |
| 138 | |
| 139 | |
| 140 | |
| 141 | } |
| 142 | |
| 143 | public static function new_shortcode(){ |
| 144 | self::edit_shortcode( 'new' ); |
| 145 | } |
| 146 | |
| 147 | public static function edit_shortcode( $action = 'edit' ){ |
| 148 | |
| 149 | self::save_shortcode(); |
| 150 | |
| 151 | $shortcodes = Shortcoder::list_all(); |
| 152 | $g = self::clean_get(); |
| 153 | |
| 154 | $page_title = __( 'New shortcode', 'shortcoder' ); |
| 155 | $action_btn = __( 'Create shortcode', 'shortcoder' ); |
| 156 | $sc_name = ''; |
| 157 | $values = array(); |
| 158 | |
| 159 | if( $action == 'edit' ){ |
| 160 | |
| 161 | $page_title = __( 'Edit shortcode', 'shortcoder' ); |
| 162 | $action_btn = __( 'Save settings', 'shortcoder' ); |
| 163 | |
| 164 | if( !( isset( $g[ 'name' ] ) && array_key_exists( $g[ 'name' ], $shortcodes ) ) ){ |
| 165 | echo '<p align="center">' . __( 'Invalid shortcode or Shortcode does not exist !' ) . '</p>'; |
| 166 | return false; |
| 167 | } |
| 168 | |
| 169 | $sc_name = $g[ 'name' ]; |
| 170 | $values = $shortcodes[ $sc_name ]; |
| 171 | |
| 172 | } |
| 173 | |
| 174 | $values = wp_parse_args( $values, Shortcoder::defaults() ); |
| 175 | |
| 176 | echo '<h3 class="page_title">' . $page_title; |
| 177 | echo '<div class="sc_menu">'; |
| 178 | echo '<a href="' . self::get_link() . '" class="button sc_back_btn"><span class="dashicons dashicons-arrow-left-alt2"></span> ' . __( 'Back', 'shortcoder' ) . '</a>'; |
| 179 | echo '</div>'; |
| 180 | echo '</h3>'; |
| 181 | |
| 182 | echo '<form method="post">'; |
| 183 | |
| 184 | echo '<div class="sc_section">'; |
| 185 | echo '<label for="sc_name">' . __( 'Name', 'shortcoder' ) . '</label>'; |
| 186 | echo '<div class="sc_name_wrap"><input type="text" id="sc_name" name="sc_name" value="' . esc_attr( $sc_name ) . '" class="widefat" required="required" ' . ( ( $action == 'edit' ) ? 'readonly="readonly"' : 'placeholder="' . __( 'Enter a name for the shortcode, case sensitive', 'shortcoder' ) . '"' ) . ' pattern="[a-zA-z0-9 \-]+" title="' . __( 'Allowed characters A to Z, a to z, 0 to 9, hyphens, underscores and space', 'shortcoder' ) . '" />'; |
| 187 | echo ( $action == 'edit' ) ? '<div class="copy_shortcode">Your shortcode is - <strong contenteditable>' . self::get_shortcode( $sc_name ) . '</strong></div>' : ''; |
| 188 | echo '</div></div>'; |
| 189 | |
| 190 | echo '<div class="sc_section">'; |
| 191 | echo '<label for="sc_content">' . __( 'Shortcode content', 'shortcoder' ) . '</label>'; |
| 192 | wp_editor( $values[ 'content' ], 'sc_content', array( 'wpautop'=> false, 'textarea_rows'=> 12 ) ); |
| 193 | echo '</div>'; |
| 194 | |
| 195 | echo '<h4>' . __( 'Settings', 'shortcoder' ) . '</h4>'; |
| 196 | echo '<div class="sc_section">'; |
| 197 | echo '<label><input type="checkbox" name="sc_disable" value="1" ' . checked( $values[ 'disabled' ], '1', false ) . '/> ' . __( 'Temporarily disable this shortcode', 'shortcoder' ) . '</label>'; |
| 198 | echo '<label><input type="checkbox" name="sc_hide_admin" value="1" ' . checked( $values[ 'hide_admin' ], '1', false ) . '/> ' . __( 'Disable this Shortcode for administrators' ) . '</label>'; |
| 199 | echo '</div>'; |
| 200 | |
| 201 | $device_options = array( |
| 202 | 'all' => __( 'On both desktop and mobile devices', 'shortcoder' ), |
| 203 | 'mobile_only' => __( 'On mobile devices alone', 'shortcoder' ), |
| 204 | 'desktop_only' => __( 'On desktops alone', 'shortcoder' ) |
| 205 | ); |
| 206 | |
| 207 | echo '<h4>' . __( 'Visibility', 'shortcoder' ) . '</h4>'; |
| 208 | echo '<div class="sc_section">'; |
| 209 | echo '<label>' . __( 'Show this shortcode', 'shortcoder' ); |
| 210 | echo '<select name="sc_devices">'; |
| 211 | foreach( $device_options as $id => $name ){ |
| 212 | echo '<option value="' . $id . '" ' . selected( $values[ 'devices' ], $id ) . '>' . $name . '</option>'; |
| 213 | } |
| 214 | echo '</select></label>'; |
| 215 | echo '</div>'; |
| 216 | |
| 217 | wp_nonce_field( 'sc_edit_nonce' ); |
| 218 | |
| 219 | echo '<footer class="page_footer">'; |
| 220 | echo '<button class="button button-primary">' . $action_btn . '</button>'; |
| 221 | |
| 222 | if( $action == 'edit' ){ |
| 223 | $delete_link = self::get_link(array( |
| 224 | 'action' => 'sc_admin_ajax', |
| 225 | 'do' => 'delete', |
| 226 | 'name' => $sc_name, |
| 227 | '_wpnonce' => wp_create_nonce( 'sc_delete_nonce' ) |
| 228 | ), 'admin-ajax.php' ); |
| 229 | echo '<a href="' . $delete_link . '" class="button sc_delete_ep" title="' . __( 'Delete', 'shortcoder' ) . '"><span class="dashicons dashicons-trash"></span></a>'; |
| 230 | } |
| 231 | |
| 232 | echo '</footer>'; |
| 233 | |
| 234 | echo '</form>'; |
| 235 | |
| 236 | $sc_wp_params = Shortcoder::wp_params_list(); |
| 237 | |
| 238 | echo '<ul class="params_wrap">'; |
| 239 | echo '<li>' . __( 'WordPress information', 'shortcoder' ) . '<ul class="wp_params">'; |
| 240 | foreach( $sc_wp_params as $id => $name ){ |
| 241 | echo '<li data-id="' . $id . '">' . $name . '</li>'; |
| 242 | } |
| 243 | echo '</ul></li>'; |
| 244 | echo '<li>' . __( 'Custom parameter', 'shortcoder' ) . '<ul>'; |
| 245 | echo '<li class="cp_form"><h4>' . __( 'Enter custom parameter name', 'shortcoder' ) . '</h4>'; |
| 246 | echo '<input type="text" class="cp_box" pattern="[a-zA-Z0-9]+"/> <button class="button cp_btn">' . __( 'Insert parameter', 'shortcoder' ) . '</button><p class="cp_info"><small>' . __( 'Only alphabets and numbers allowed. Custom parameters are case insensitive', 'shortcoder' ) . '</small></p></li>'; |
| 247 | echo '</ul></li>'; |
| 248 | echo '</ul>'; |
| 249 | } |
| 250 | |
| 251 | public static function save_shortcode(){ |
| 252 | |
| 253 | if( $_POST && check_admin_referer( 'sc_edit_nonce' ) ){ |
| 254 | |
| 255 | $p = wp_parse_args( self::clean_post(), array( |
| 256 | 'sc_name' => '', |
| 257 | 'sc_content' => '', |
| 258 | 'sc_disable' => 0, |
| 259 | 'sc_hide_admin' => 0, |
| 260 | 'sc_devices' => 'all', |
| 261 | )); |
| 262 | |
| 263 | if( !trim( $p[ 'sc_name' ] ) ){ |
| 264 | self::print_notice( 0 ); |
| 265 | return false; |
| 266 | } |
| 267 | |
| 268 | $shortcodes = Shortcoder::list_all(); |
| 269 | $name = self::clean_name( $p[ 'sc_name' ] ); |
| 270 | $values = array( |
| 271 | 'content' => $p[ 'sc_content' ], |
| 272 | 'disabled' => $p[ 'sc_disable' ], |
| 273 | 'hide_admin' => $p[ 'sc_hide_admin' ], |
| 274 | 'devices' => $p[ 'sc_devices' ] |
| 275 | ); |
| 276 | |
| 277 | if( array_key_exists( $name, $shortcodes ) ){ |
| 278 | self::print_notice( 2 ); |
| 279 | }else{ |
| 280 | self::print_notice( 1 ); |
| 281 | } |
| 282 | |
| 283 | $shortcodes[ $name ] = $values; |
| 284 | |
| 285 | update_option( 'shortcoder_data', $shortcodes ); |
| 286 | |
| 287 | /* |
| 288 | wp_safe_redirect( self::get_link( array( |
| 289 | 'action' => 'edit', |
| 290 | 'name' => urlencode( $name ), |
| 291 | 'msg' => ( $todo == 'new' ) ? 1 : 2 |
| 292 | )));*/ |
| 293 | } |
| 294 | |
| 295 | } |
| 296 | |
| 297 | public static function delete_shortcode( $name ){ |
| 298 | |
| 299 | $shortcodes = Shortcoder::list_all(); |
| 300 | |
| 301 | if( array_key_exists( $name, $shortcodes ) ){ |
| 302 | unset( $shortcodes[ $name ] ); |
| 303 | update_option( 'shortcoder_data', $shortcodes ); |
| 304 | return true; |
| 305 | }else{ |
| 306 | return false; |
| 307 | } |
| 308 | |
| 309 | } |
| 310 | |
| 311 | public static function get_link( $params = array(), $page = 'options-general.php' ){ |
| 312 | |
| 313 | $params[ 'page' ] = 'shortcoder'; |
| 314 | return add_query_arg( $params, admin_url( $page ) ); |
| 315 | |
| 316 | } |
| 317 | |
| 318 | public static function get_shortcode( $name = '' ){ |
| 319 | return esc_attr( '[sc name="' . $name . '"]' ); |
| 320 | } |
| 321 | |
| 322 | public static function admin_ajax(){ |
| 323 | |
| 324 | $g = self::clean_get(); |
| 325 | |
| 326 | if( $g[ 'do' ] == 'delete' && isset( $g[ 'name' ] ) && check_admin_referer( 'sc_delete_nonce' ) ){ |
| 327 | if( self::delete_shortcode( $g[ 'name' ] ) ){ |
| 328 | echo 'DELETED'; |
| 329 | }else{ |
| 330 | echo 'FAILED'; |
| 331 | } |
| 332 | } |
| 333 | |
| 334 | if( $g[ 'do' ] == 'insert_shortcode' ){ |
| 335 | include_once( 'sc-insert.php' ); |
| 336 | } |
| 337 | |
| 338 | die(0); |
| 339 | } |
| 340 | |
| 341 | public static function add_qt_button(){ |
| 342 | |
| 343 | $screen = get_current_screen(); |
| 344 | if( self::$pagehook == $screen->id ) |
| 345 | return; |
| 346 | |
| 347 | echo ' |
| 348 | <script> |
| 349 | window.onload = function(){ |
| 350 | if( typeof QTags === "function" ){ |
| 351 | QTags.addButton( "QT_sc_insert", "Shortcoder", sc_show_insert ); |
| 352 | } |
| 353 | } |
| 354 | function sc_show_insert(){ |
| 355 | tb_show( "Insert a Shortcode", "' . admin_url( 'admin-ajax.php?action=sc_admin_ajax&do=insert_shortcode&TB_iframe=true' ) . '" ); |
| 356 | } |
| 357 | </script>'; |
| 358 | } |
| 359 | |
| 360 | public static function register_mce(){ |
| 361 | add_filter( 'mce_buttons', array( __class__, 'register_mce_button' ) ); |
| 362 | add_filter( 'mce_external_plugins', array( __class__, 'register_mce_js' ) ); |
| 363 | } |
| 364 | |
| 365 | public static function register_mce_button( $buttons ){ |
| 366 | |
| 367 | if( self::is_sc_admin() ) |
| 368 | return $buttons; |
| 369 | |
| 370 | array_push( $buttons, 'separator', 'shortcoder' ); |
| 371 | return $buttons; |
| 372 | } |
| 373 | |
| 374 | public static function register_mce_js( $plugins ){ |
| 375 | |
| 376 | if( self::is_sc_admin() ) |
| 377 | return $plugins; |
| 378 | |
| 379 | $plugins[ 'shortcoder' ] = SC_ADMIN_URL . '/js/tinymce/editor_plugin.js'; |
| 380 | return $plugins; |
| 381 | } |
| 382 | |
| 383 | public static function page_bottom(){ |
| 384 | |
| 385 | echo '<div class="coffee_box"> |
| 386 | <div class="coffee_amt_wrap"> |
| 387 | <p><select class="coffee_amt"> |
| 388 | <option value="2">$2</option> |
| 389 | <option value="3">$3</option> |
| 390 | <option value="4">$4</option> |
| 391 | <option value="5" selected="selected">$5</option> |
| 392 | <option value="6">$6</option> |
| 393 | <option value="7">$7</option> |
| 394 | <option value="8">$8</option> |
| 395 | <option value="9">$9</option> |
| 396 | <option value="10">$10</option> |
| 397 | <option value="11">$11</option> |
| 398 | <option value="12">$12</option> |
| 399 | <option value="">Custom</option> |
| 400 | </select></p> |
| 401 | <a class="button button-primary buy_coffee_btn" href="https://www.paypal.me/vaakash/5" data-link="https://www.paypal.me/vaakash/" target="_blank">Buy me a coffee !</a> |
| 402 | </div> |
| 403 | <h2>Buy me a coffee !</h2> |
| 404 | <p>Thank you for using Shortcoder. If you found the plugin useful buy me a coffee ! Your donation will motivate and make me happy for all the efforts. You can donate via PayPal.</p>'; |
| 405 | echo '</div>'; |
| 406 | |
| 407 | echo '<p class="credits_box"><img src="' . SC_ADMIN_URL . '/images/aw.png" /> Created by <a href="https://goo.gl/aHKnsM" target="_blank">Aakash Chakravarthy</a> - Follow me on <a href="https://twitter.com/vaakash" target="_blank">Twitter</a>, <a href="https://fb.com/aakashweb" target="_blank">Facebook</a>, <a href="https://www.linkedin.com/in/vaakash/" target="_blank">LinkedIn</a>. Check out <a href="https://goo.gl/OAxx4l" target="_blank">my other works</a>. |
| 408 | |
| 409 | <a href="https://goo.gl/ltvnIE" class="rate_link" target="_blank">Rate <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> if you like Shortcoder</a> |
| 410 | |
| 411 | </p>'; |
| 412 | |
| 413 | } |
| 414 | |
| 415 | public static function top_sharebar(){ |
| 416 | echo ' |
| 417 | <div class="top_sharebar"> |
| 418 | |
| 419 | <a href="https://goo.gl/r8Qr7Y" class="help_link" target="_blank" title="Help"><span class="dashicons dashicons-editor-help"></span></a> |
| 420 | <a href="https://goo.gl/URfxp2" class="help_link" target="_blank" title="Report issue"><span class="dashicons dashicons-flag"></span></a> |
| 421 | |
| 422 | <a class="share_btn googleplus" href="https://plus.google.com/share?url=https%3A%2F%2Fwww.aakashweb.com%2Fwordpress-plugins%2Fshortcoder%2F" target="_blank"><span class="dashicons dashicons-googleplus"></span> Share</a> |
| 423 | <a class="share_btn twitter" href="https://twitter.com/intent/tweet?ref_src=twsrc%5Etfw&related=vaakash&text=Check%20out%20Shortcoder,%20a%20%23wordpress%20plugin%20to%20create%20shortcodes%20for%20HTML,%20JavaScript%20snippets%20easily&tw_p=tweetbutton&url=https%3A%2F%2Fwww.aakashweb.com%2Fwordpress-plugins%2Fwp-socializer%2F&via=vaakash" target="_blank"><span class="dashicons dashicons-twitter"></span> Tweet about Shortcoder</a> |
| 424 | |
| 425 | </div>'; |
| 426 | } |
| 427 | |
| 428 | public static function action_links( $links ){ |
| 429 | array_unshift( $links, '<a href="https://goo.gl/qMF3iE" target="_blank">Donate</a>' ); |
| 430 | array_unshift( $links, '<a href="'. esc_url( admin_url( 'options-general.php?page=shortcoder' ) ) .'">⚙️ Settings</a>' ); |
| 431 | return $links; |
| 432 | } |
| 433 | |
| 434 | public static function print_notice( $id = '' ){ |
| 435 | |
| 436 | $g = self::clean_get(); |
| 437 | $type = 'success'; |
| 438 | $msg = ''; |
| 439 | |
| 440 | if( $id == '' ){ |
| 441 | if( !isset( $g[ 'msg' ] ) ){ |
| 442 | return false; |
| 443 | } |
| 444 | $id = $g[ 'msg' ]; |
| 445 | } |
| 446 | |
| 447 | if( $id == 0 ){ |
| 448 | $msg = __( 'Shortcode name is empty. Cannot save settings !', 'shortcoder' ); |
| 449 | $type = 'error'; |
| 450 | } |
| 451 | |
| 452 | if( $id == 1 ){ |
| 453 | $msg = __( 'Shortcode created successfully', 'shortcoder' ); |
| 454 | } |
| 455 | |
| 456 | if( $id == 2 ){ |
| 457 | $msg = __( 'Shortcode updated successfully', 'shortcoder' ); |
| 458 | } |
| 459 | |
| 460 | if( $id == 3 ){ |
| 461 | $msg = __( 'Shortcode deleted successfully', 'shortcoder' ); |
| 462 | } |
| 463 | |
| 464 | if( $msg != '' ){ |
| 465 | echo '<div class="notice notice-' . $type . ' is-dismissible"><p>' . $msg . '</p></div>'; |
| 466 | } |
| 467 | } |
| 468 | |
| 469 | public static function clean_name( $name = '' ){ |
| 470 | |
| 471 | return trim( preg_replace('/[^0-9a-zA-Z\- _]/', '', $name ) ); |
| 472 | |
| 473 | } |
| 474 | |
| 475 | public static function clean_get(){ |
| 476 | |
| 477 | foreach( $_GET as $k=>$v ){ |
| 478 | $_GET[$k] = sanitize_text_field( $v ); |
| 479 | } |
| 480 | |
| 481 | return $_GET; |
| 482 | } |
| 483 | |
| 484 | public static function clean_post(){ |
| 485 | |
| 486 | return stripslashes_deep( $_POST ); |
| 487 | |
| 488 | } |
| 489 | |
| 490 | public static function is_sc_admin(){ |
| 491 | |
| 492 | if( !function_exists( 'get_current_screen' ) ) |
| 493 | return false; |
| 494 | |
| 495 | $screen = get_current_screen(); |
| 496 | if( self::$pagehook == $screen->id ){ |
| 497 | return true; |
| 498 | }else{ |
| 499 | return false; |
| 500 | } |
| 501 | |
| 502 | } |
| 503 | |
| 504 | } |
| 505 | |
| 506 | Shortcoder_Admin::init(); |
| 507 | |
| 508 | ?> |