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
524 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 | Shortcoder_Import::check_import(); |
| 87 | |
| 88 | $shortcodes = Shortcoder::list_all(); |
| 89 | $g = self::clean_get(); |
| 90 | |
| 91 | echo '<h3 class="page_title">' . __( 'List of shortcodes created', 'shortcoder' ); |
| 92 | echo '<span class="sc_menu">'; |
| 93 | |
| 94 | echo '<label for="import" class="button"><span class="dashicons dashicons-upload"></span><em>' . __( 'Import shortcodes', 'shortcoder' ) . '</em></label>'; |
| 95 | |
| 96 | echo '<a href="' . self::get_link(array( |
| 97 | 'action' => 'sc_export', |
| 98 | '_wpnonce' => wp_create_nonce( 'sc_export_data' ) |
| 99 | ), 'admin-ajax.php' ) . '" class="button"><span class="dashicons dashicons-download"></span><em>' . __( 'Export shortcodes', 'shortcoder' ) . '</em></a>'; |
| 100 | |
| 101 | |
| 102 | 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>'; |
| 103 | |
| 104 | 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>'; |
| 105 | |
| 106 | echo '</span>'; |
| 107 | echo '</h3>'; |
| 108 | |
| 109 | if( isset( $g[ 'sort' ] ) ){ |
| 110 | $sort = $g[ 'sort' ]; |
| 111 | if( $sort == 'asc' ){ |
| 112 | uksort($shortcodes, 'strcasecmp' ); |
| 113 | }else if( $sort == 'desc' ){ |
| 114 | uksort($shortcodes, 'strcasecmp' ); |
| 115 | $shortcodes = array_reverse( $shortcodes, True ); |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | echo '<ul class="sc_list" data-empty="' . __( 'No shortcodes are created. Go ahead create one !', 'shortcoder' ) . '">'; |
| 120 | foreach( $shortcodes as $name => $data ){ |
| 121 | |
| 122 | $data = wp_parse_args( $data, Shortcoder::defaults() ); |
| 123 | |
| 124 | $link = self::get_link(array( |
| 125 | 'action' => 'edit', |
| 126 | 'name' => $name |
| 127 | )); |
| 128 | |
| 129 | $delete_link = self::get_link(array( |
| 130 | 'action' => 'sc_admin_ajax', |
| 131 | 'do' => 'delete', |
| 132 | 'name' => $name, |
| 133 | '_wpnonce' => wp_create_nonce( 'sc_delete_nonce' ) |
| 134 | ), 'admin-ajax.php' ); |
| 135 | |
| 136 | $disabled_text = ( $data[ 'disabled' ] == '1' ) ? '<small class="disabled_text">' . __( 'Temporarily disabled', 'shortcoder' ) . '</small>' : ''; |
| 137 | |
| 138 | echo '<li data-name="' . esc_attr( $name ) . '">'; |
| 139 | echo '<a href="' . $link . '" class="sc_link" title="' . __( 'Edit shortcode', 'shortcoder' ) . '">' . $name . $disabled_text . '</a>'; |
| 140 | echo '<span class="sc_controls">'; |
| 141 | echo '<a href="#" class="sc_copy" title="' . __( 'Copy shortcode', 'shortcoder' ) . '"><span class="dashicons dashicons-editor-code"></span></a>'; |
| 142 | echo '<a href="' . $delete_link . '" class="sc_delete" title="' . __( 'Delete', 'shortcoder' ) . '"><span class="dashicons dashicons-trash"></span></a>'; |
| 143 | echo '</span>'; |
| 144 | |
| 145 | echo '<input type="text" value="' . self::get_shortcode( $name ) . '" class="sc_copy_box" readonly="readonly" title="' . __( 'Copy shortcode', 'shortcoder' ) . '" />'; |
| 146 | |
| 147 | echo '</li>'; |
| 148 | |
| 149 | } |
| 150 | echo '</ul>'; |
| 151 | |
| 152 | Shortcoder_Import::import_form(); |
| 153 | |
| 154 | } |
| 155 | |
| 156 | public static function new_shortcode(){ |
| 157 | self::edit_shortcode( 'new' ); |
| 158 | } |
| 159 | |
| 160 | public static function edit_shortcode( $action = 'edit' ){ |
| 161 | |
| 162 | self::save_shortcode(); |
| 163 | |
| 164 | $shortcodes = Shortcoder::list_all(); |
| 165 | $g = self::clean_get(); |
| 166 | |
| 167 | $page_title = __( 'New shortcode', 'shortcoder' ); |
| 168 | $action_btn = __( 'Create shortcode', 'shortcoder' ); |
| 169 | $sc_name = ''; |
| 170 | $values = array(); |
| 171 | |
| 172 | if( $action == 'edit' ){ |
| 173 | |
| 174 | $page_title = __( 'Edit shortcode', 'shortcoder' ); |
| 175 | $action_btn = __( 'Save settings', 'shortcoder' ); |
| 176 | |
| 177 | if( !( isset( $g[ 'name' ] ) && array_key_exists( $g[ 'name' ], $shortcodes ) ) ){ |
| 178 | echo '<p align="center">' . __( 'Invalid shortcode or Shortcode does not exist !' ) . '</p>'; |
| 179 | return false; |
| 180 | } |
| 181 | |
| 182 | $sc_name = $g[ 'name' ]; |
| 183 | $values = $shortcodes[ $sc_name ]; |
| 184 | |
| 185 | } |
| 186 | |
| 187 | $values = wp_parse_args( $values, Shortcoder::defaults() ); |
| 188 | |
| 189 | echo '<h3 class="page_title">' . $page_title; |
| 190 | echo '<div class="sc_menu">'; |
| 191 | echo '<a href="' . self::get_link() . '" class="button sc_back_btn"><span class="dashicons dashicons-arrow-left-alt2"></span> ' . __( 'Back', 'shortcoder' ) . '</a>'; |
| 192 | echo '</div>'; |
| 193 | echo '</h3>'; |
| 194 | |
| 195 | echo '<form method="post">'; |
| 196 | |
| 197 | echo '<div class="sc_section">'; |
| 198 | echo '<label for="sc_name">' . __( 'Name', 'shortcoder' ) . '</label>'; |
| 199 | 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 \-]+" />'; |
| 200 | echo ( $action == 'edit' ) ? '<div class="copy_shortcode">Your shortcode is - <strong contenteditable>' . self::get_shortcode( $sc_name ) . '</strong></div>' : ''; |
| 201 | echo ( $action != 'edit' ) ? '<div class="copy_shortcode">' . __( 'Allowed characters A to Z, a to z, 0 to 9, hyphens, underscores and space', 'shortcoder' ) . '</div>' : ''; |
| 202 | echo '</div></div>'; |
| 203 | |
| 204 | echo '<div class="sc_section">'; |
| 205 | echo '<label for="sc_content">' . __( 'Shortcode content', 'shortcoder' ) . '</label>'; |
| 206 | wp_editor( $values[ 'content' ], 'sc_content', array( 'wpautop'=> false, 'textarea_rows'=> 15, 'tinymce' => isset( $g[ 'visual_edit' ] ) ) ); |
| 207 | echo '</div>'; |
| 208 | |
| 209 | echo '<p class="sc_note">' . __( 'Note: You can use any HTML, JavaScript, CSS as shortcode content. Shortcoder does not manipulate the shortcode content. What you provide above is what you get as output. Please verify the shortcode content for any syntax or JavaScript errors.', 'shortcoder' ) . '</p>'; |
| 210 | |
| 211 | echo '<h4>' . __( 'Settings', 'shortcoder' ) . '</h4>'; |
| 212 | echo '<div class="sc_section">'; |
| 213 | echo '<label><input type="checkbox" name="sc_disable" value="1" ' . checked( $values[ 'disabled' ], '1', false ) . '/> ' . __( 'Temporarily disable this shortcode', 'shortcoder' ) . '</label>'; |
| 214 | echo '<label><input type="checkbox" name="sc_hide_admin" value="1" ' . checked( $values[ 'hide_admin' ], '1', false ) . '/> ' . __( 'Disable this Shortcode for administrators' ) . '</label>'; |
| 215 | echo '</div>'; |
| 216 | |
| 217 | $device_options = array( |
| 218 | 'all' => __( 'On both desktop and mobile devices', 'shortcoder' ), |
| 219 | 'mobile_only' => __( 'On mobile devices alone', 'shortcoder' ), |
| 220 | 'desktop_only' => __( 'On desktops alone', 'shortcoder' ) |
| 221 | ); |
| 222 | |
| 223 | echo '<h4>' . __( 'Visibility', 'shortcoder' ) . '</h4>'; |
| 224 | echo '<div class="sc_section">'; |
| 225 | echo '<label>' . __( 'Show this shortcode', 'shortcoder' ); |
| 226 | echo '<select name="sc_devices">'; |
| 227 | foreach( $device_options as $id => $name ){ |
| 228 | echo '<option value="' . $id . '" ' . selected( $values[ 'devices' ], $id ) . '>' . $name . '</option>'; |
| 229 | } |
| 230 | echo '</select></label>'; |
| 231 | echo '</div>'; |
| 232 | |
| 233 | wp_nonce_field( 'sc_edit_nonce' ); |
| 234 | |
| 235 | echo '<footer class="page_footer">'; |
| 236 | echo '<button class="button button-primary">' . $action_btn . '</button>'; |
| 237 | |
| 238 | if( $action == 'edit' ){ |
| 239 | $delete_link = self::get_link(array( |
| 240 | 'action' => 'sc_admin_ajax', |
| 241 | 'do' => 'delete', |
| 242 | 'name' => $sc_name, |
| 243 | '_wpnonce' => wp_create_nonce( 'sc_delete_nonce' ) |
| 244 | ), 'admin-ajax.php' ); |
| 245 | echo '<a href="' . $delete_link . '" class="button sc_delete_ep" title="' . __( 'Delete', 'shortcoder' ) . '"><span class="dashicons dashicons-trash"></span></a>'; |
| 246 | } |
| 247 | |
| 248 | echo '</footer>'; |
| 249 | |
| 250 | echo '</form>'; |
| 251 | |
| 252 | $sc_wp_params = Shortcoder::wp_params_list(); |
| 253 | |
| 254 | echo '<ul class="params_wrap">'; |
| 255 | echo '<li>' . __( 'WordPress information', 'shortcoder' ) . '<ul class="wp_params">'; |
| 256 | foreach( $sc_wp_params as $id => $name ){ |
| 257 | echo '<li data-id="' . $id . '">' . $name . '</li>'; |
| 258 | } |
| 259 | echo '</ul></li>'; |
| 260 | echo '<li>' . __( 'Custom parameter', 'shortcoder' ) . '<ul>'; |
| 261 | echo '<li class="cp_form"><h4>' . __( 'Enter custom parameter name', 'shortcoder' ) . '</h4>'; |
| 262 | 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>'; |
| 263 | echo '</ul></li>'; |
| 264 | echo '</ul>'; |
| 265 | } |
| 266 | |
| 267 | public static function save_shortcode(){ |
| 268 | |
| 269 | if( $_POST && check_admin_referer( 'sc_edit_nonce' ) ){ |
| 270 | |
| 271 | $p = wp_parse_args( self::clean_post(), array( |
| 272 | 'sc_name' => '', |
| 273 | 'sc_content' => '', |
| 274 | 'sc_disable' => 0, |
| 275 | 'sc_hide_admin' => 0, |
| 276 | 'sc_devices' => 'all', |
| 277 | )); |
| 278 | |
| 279 | if( !trim( $p[ 'sc_name' ] ) ){ |
| 280 | self::print_notice( 0 ); |
| 281 | return false; |
| 282 | } |
| 283 | |
| 284 | $shortcodes = Shortcoder::list_all(); |
| 285 | $name = self::clean_name( $p[ 'sc_name' ] ); |
| 286 | $values = array( |
| 287 | 'content' => $p[ 'sc_content' ], |
| 288 | 'disabled' => $p[ 'sc_disable' ], |
| 289 | 'hide_admin' => $p[ 'sc_hide_admin' ], |
| 290 | 'devices' => $p[ 'sc_devices' ] |
| 291 | ); |
| 292 | |
| 293 | if( array_key_exists( $name, $shortcodes ) ){ |
| 294 | self::print_notice( 2 ); |
| 295 | }else{ |
| 296 | self::print_notice( 1 ); |
| 297 | } |
| 298 | |
| 299 | $shortcodes[ $name ] = $values; |
| 300 | |
| 301 | update_option( 'shortcoder_data', $shortcodes ); |
| 302 | |
| 303 | /* |
| 304 | wp_safe_redirect( self::get_link( array( |
| 305 | 'action' => 'edit', |
| 306 | 'name' => urlencode( $name ), |
| 307 | 'msg' => ( $todo == 'new' ) ? 1 : 2 |
| 308 | )));*/ |
| 309 | } |
| 310 | |
| 311 | } |
| 312 | |
| 313 | public static function delete_shortcode( $name ){ |
| 314 | |
| 315 | $shortcodes = Shortcoder::list_all(); |
| 316 | |
| 317 | if( array_key_exists( $name, $shortcodes ) ){ |
| 318 | unset( $shortcodes[ $name ] ); |
| 319 | update_option( 'shortcoder_data', $shortcodes ); |
| 320 | return true; |
| 321 | }else{ |
| 322 | return false; |
| 323 | } |
| 324 | |
| 325 | } |
| 326 | |
| 327 | public static function get_link( $params = array(), $page = 'options-general.php' ){ |
| 328 | |
| 329 | $params[ 'page' ] = 'shortcoder'; |
| 330 | return add_query_arg( $params, admin_url( $page ) ); |
| 331 | |
| 332 | } |
| 333 | |
| 334 | public static function get_shortcode( $name = '' ){ |
| 335 | return esc_attr( '[sc name="' . $name . '"]' ); |
| 336 | } |
| 337 | |
| 338 | public static function admin_ajax(){ |
| 339 | |
| 340 | $g = self::clean_get(); |
| 341 | |
| 342 | if( $g[ 'do' ] == 'delete' && isset( $g[ 'name' ] ) && check_admin_referer( 'sc_delete_nonce' ) ){ |
| 343 | if( self::delete_shortcode( $g[ 'name' ] ) ){ |
| 344 | echo 'DELETED'; |
| 345 | }else{ |
| 346 | echo 'FAILED'; |
| 347 | } |
| 348 | } |
| 349 | |
| 350 | if( $g[ 'do' ] == 'insert_shortcode' ){ |
| 351 | include_once( 'sc-insert.php' ); |
| 352 | } |
| 353 | |
| 354 | die(0); |
| 355 | } |
| 356 | |
| 357 | public static function add_qt_button(){ |
| 358 | |
| 359 | $screen = get_current_screen(); |
| 360 | if( self::$pagehook == $screen->id ) |
| 361 | return; |
| 362 | |
| 363 | echo ' |
| 364 | <script> |
| 365 | window.onload = function(){ |
| 366 | if( typeof QTags === "function" ){ |
| 367 | QTags.addButton( "QT_sc_insert", "Shortcoder", sc_show_insert ); |
| 368 | } |
| 369 | } |
| 370 | function sc_show_insert(){ |
| 371 | tb_show( "Insert a Shortcode", "' . admin_url( 'admin-ajax.php?action=sc_admin_ajax&do=insert_shortcode&TB_iframe=true' ) . '" ); |
| 372 | } |
| 373 | </script>'; |
| 374 | } |
| 375 | |
| 376 | public static function register_mce(){ |
| 377 | add_filter( 'mce_buttons', array( __class__, 'register_mce_button' ) ); |
| 378 | add_filter( 'mce_external_plugins', array( __class__, 'register_mce_js' ) ); |
| 379 | } |
| 380 | |
| 381 | public static function register_mce_button( $buttons ){ |
| 382 | |
| 383 | if( self::is_sc_admin() ) |
| 384 | return $buttons; |
| 385 | |
| 386 | array_push( $buttons, 'separator', 'shortcoder' ); |
| 387 | return $buttons; |
| 388 | } |
| 389 | |
| 390 | public static function register_mce_js( $plugins ){ |
| 391 | |
| 392 | if( self::is_sc_admin() ) |
| 393 | return $plugins; |
| 394 | |
| 395 | $plugins[ 'shortcoder' ] = SC_ADMIN_URL . '/js/tinymce/editor_plugin.js'; |
| 396 | return $plugins; |
| 397 | } |
| 398 | |
| 399 | public static function page_bottom(){ |
| 400 | |
| 401 | echo '<div class="coffee_box"> |
| 402 | <div class="coffee_amt_wrap"> |
| 403 | <p><select class="coffee_amt"> |
| 404 | <option value="2">$2</option> |
| 405 | <option value="3">$3</option> |
| 406 | <option value="4">$4</option> |
| 407 | <option value="5" selected="selected">$5</option> |
| 408 | <option value="6">$6</option> |
| 409 | <option value="7">$7</option> |
| 410 | <option value="8">$8</option> |
| 411 | <option value="9">$9</option> |
| 412 | <option value="10">$10</option> |
| 413 | <option value="11">$11</option> |
| 414 | <option value="12">$12</option> |
| 415 | <option value="">Custom</option> |
| 416 | </select></p> |
| 417 | <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> |
| 418 | </div> |
| 419 | <h2>Buy me a coffee !</h2> |
| 420 | <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>'; |
| 421 | echo '</div>'; |
| 422 | |
| 423 | 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>. |
| 424 | |
| 425 | <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> |
| 426 | |
| 427 | </p>'; |
| 428 | |
| 429 | } |
| 430 | |
| 431 | public static function top_sharebar(){ |
| 432 | echo ' |
| 433 | <div class="top_sharebar"> |
| 434 | |
| 435 | <a href="https://goo.gl/r8Qr7Y" class="help_link" target="_blank" title="Help"><span class="dashicons dashicons-editor-help"></span></a> |
| 436 | <a href="https://goo.gl/URfxp2" class="help_link" target="_blank" title="Report issue"><span class="dashicons dashicons-flag"></span></a> |
| 437 | |
| 438 | <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> |
| 439 | <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> |
| 440 | |
| 441 | </div>'; |
| 442 | } |
| 443 | |
| 444 | public static function action_links( $links ){ |
| 445 | array_unshift( $links, '<a href="https://goo.gl/qMF3iE" target="_blank">Donate</a>' ); |
| 446 | array_unshift( $links, '<a href="'. esc_url( admin_url( 'options-general.php?page=shortcoder' ) ) .'">⚙️ Settings</a>' ); |
| 447 | return $links; |
| 448 | } |
| 449 | |
| 450 | public static function print_notice( $id = '' ){ |
| 451 | |
| 452 | $g = self::clean_get(); |
| 453 | $type = 'success'; |
| 454 | $msg = ''; |
| 455 | |
| 456 | if( $id == '' ){ |
| 457 | if( !isset( $g[ 'msg' ] ) ){ |
| 458 | return false; |
| 459 | } |
| 460 | $id = $g[ 'msg' ]; |
| 461 | } |
| 462 | |
| 463 | if( $id == 0 ){ |
| 464 | $msg = __( 'Shortcode name is empty. Cannot save settings !', 'shortcoder' ); |
| 465 | $type = 'error'; |
| 466 | } |
| 467 | |
| 468 | if( $id == 1 ){ |
| 469 | $msg = __( 'Shortcode created successfully', 'shortcoder' ); |
| 470 | } |
| 471 | |
| 472 | if( $id == 2 ){ |
| 473 | $msg = __( 'Shortcode updated successfully', 'shortcoder' ); |
| 474 | } |
| 475 | |
| 476 | if( $id == 3 ){ |
| 477 | $msg = __( 'Shortcode deleted successfully', 'shortcoder' ); |
| 478 | } |
| 479 | |
| 480 | if( $msg != '' ){ |
| 481 | echo '<div class="notice notice-' . $type . ' is-dismissible"><p>' . $msg . '</p></div>'; |
| 482 | } |
| 483 | } |
| 484 | |
| 485 | public static function clean_name( $name = '' ){ |
| 486 | |
| 487 | return trim( preg_replace('/[^0-9a-zA-Z\- _]/', '', $name ) ); |
| 488 | |
| 489 | } |
| 490 | |
| 491 | public static function clean_get(){ |
| 492 | |
| 493 | foreach( $_GET as $k=>$v ){ |
| 494 | $_GET[$k] = sanitize_text_field( $v ); |
| 495 | } |
| 496 | |
| 497 | return $_GET; |
| 498 | } |
| 499 | |
| 500 | public static function clean_post(){ |
| 501 | |
| 502 | return stripslashes_deep( $_POST ); |
| 503 | |
| 504 | } |
| 505 | |
| 506 | public static function is_sc_admin(){ |
| 507 | |
| 508 | if( !function_exists( 'get_current_screen' ) ) |
| 509 | return false; |
| 510 | |
| 511 | $screen = get_current_screen(); |
| 512 | if( self::$pagehook == $screen->id ){ |
| 513 | return true; |
| 514 | }else{ |
| 515 | return false; |
| 516 | } |
| 517 | |
| 518 | } |
| 519 | |
| 520 | } |
| 521 | |
| 522 | Shortcoder_Admin::init(); |
| 523 | |
| 524 | ?> |