about
7 years ago
css
7 years ago
img
8 years ago
js
7 years ago
menu
8 years ago
partials
7 years ago
scss
7 years ago
settings
7 years ago
admin-notices.php
8 years ago
admin.php
7 years ago
class-strong-testimonials-admin-category-list.php
8 years ago
class-strong-testimonials-admin-list.php
7 years ago
class-strong-testimonials-admin-scripts.php
8 years ago
class-strong-testimonials-defaults.php
7 years ago
class-strong-testimonials-help.php
8 years ago
class-strong-testimonials-list-table.php
7 years ago
class-strong-testimonials-page-shortcodes.php
7 years ago
class-strong-testimonials-post-editor.php
7 years ago
class-strong-testimonials-updater.php
7 years ago
class-strong-views-list-table.php
8 years ago
class-walker-strong-category-checklist.php
7 years ago
class-walker-strong-form-category-checklist.php
7 years ago
compat.php
8 years ago
custom-fields-ajax.php
8 years ago
custom-fields.php
7 years ago
form-preview.php
8 years ago
view-list-order.php
8 years ago
views-ajax.php
7 years ago
views-validate.php
7 years ago
views.php
7 years ago
class-strong-testimonials-admin-scripts.php
396 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Class Strong_Testimonials_Admin_Scripts |
| 4 | */ |
| 5 | class Strong_Testimonials_Admin_Scripts { |
| 6 | |
| 7 | /** |
| 8 | * Strong_Testimonials_Admin_Scripts constructor. |
| 9 | */ |
| 10 | public function __construct() {} |
| 11 | |
| 12 | /** |
| 13 | * Initialize. |
| 14 | */ |
| 15 | public static function init() { |
| 16 | self::add_actions(); |
| 17 | } |
| 18 | |
| 19 | /** |
| 20 | * Add actions and filters. |
| 21 | */ |
| 22 | public static function add_actions() { |
| 23 | add_action( 'admin_init', array( __CLASS__, 'admin_register' ) ); |
| 24 | add_action( 'admin_enqueue_scripts', array( __CLASS__, 'admin_dequeue_scripts' ), 500 ); |
| 25 | add_action( 'admin_enqueue_scripts', array( __CLASS__, 'admin_enqueue_scripts' ) ); |
| 26 | |
| 27 | add_action( 'admin_print_styles-wpm-testimonial_page_testimonial-views', array( __CLASS__, 'admin_views' ) ); |
| 28 | add_action( 'admin_print_styles-wpm-testimonial_page_testimonial-fields', array( __CLASS__, 'admin_fields' ) ); |
| 29 | add_action( 'admin_print_styles-wpm-testimonial_page_testimonial-settings', array( __CLASS__, 'admin_settings' ) ); |
| 30 | add_action( 'admin_print_styles-wpm-testimonial_page_about-strong-testimonials', array( __CLASS__, 'admin_about' ) ); |
| 31 | add_action( 'admin_print_styles-wpm-testimonial_page_testimonial-shortcodes', array( __CLASS__, 'admin_shortcodes' ) ); |
| 32 | |
| 33 | add_action( 'load-edit.php', array( __CLASS__, 'admin_load_edit' ) ); |
| 34 | add_action( 'load-post.php', array( __CLASS__, 'admin_load_post' ) ); |
| 35 | add_action( 'load-post-new.php', array( __CLASS__, 'admin_load_post' ) ); |
| 36 | add_action( 'load-edit-tags.php', array( __CLASS__, 'admin_load_edit_tags' ) ); |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * Register admin scripts. |
| 41 | */ |
| 42 | public static function admin_register() { |
| 43 | |
| 44 | $plugin_version = get_option( 'wpmtst_plugin_version' ); |
| 45 | |
| 46 | $min = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
| 47 | |
| 48 | wp_register_style( 'wpmtst-font-awesome', |
| 49 | WPMTST_PUBLIC_URL . 'fonts/font-awesome-4.6.3/css/font-awesome.min.css', |
| 50 | array(), |
| 51 | '4.6.3' ); |
| 52 | |
| 53 | wp_register_script( 'wpmtst-help', |
| 54 | WPMTST_ADMIN_URL . 'js/help.js', |
| 55 | array( 'jquery' ), |
| 56 | $plugin_version, |
| 57 | true ); |
| 58 | |
| 59 | wp_register_script( 'wpmtst-admin-script', |
| 60 | WPMTST_ADMIN_URL . 'js/admin.js', |
| 61 | array( 'jquery', 'underscore' ), |
| 62 | $plugin_version, |
| 63 | true ); |
| 64 | |
| 65 | wp_register_style( 'wpmtst-admin-style', |
| 66 | WPMTST_ADMIN_URL . 'css/admin.css', |
| 67 | array( 'wpmtst-font-awesome' ), |
| 68 | $plugin_version ); |
| 69 | |
| 70 | wp_register_style( 'wpmtst-post-editor', |
| 71 | WPMTST_ADMIN_URL . 'css/post-editor.css', |
| 72 | array( 'wpmtst-font-awesome' ), |
| 73 | $plugin_version ); |
| 74 | |
| 75 | wp_register_script( 'wpmtst-custom-spinner', |
| 76 | WPMTST_ADMIN_URL . 'js/custom-spinner.js', |
| 77 | array( 'jquery' ), |
| 78 | $plugin_version, |
| 79 | true ); |
| 80 | |
| 81 | wp_register_script( 'autosize', |
| 82 | WPMTST_ADMIN_URL . 'js/lib/autosize/autosize.min.js', |
| 83 | array(), |
| 84 | '4.0.1', |
| 85 | true ); |
| 86 | |
| 87 | /** |
| 88 | * Form tab |
| 89 | */ |
| 90 | wp_register_style( 'wpmtst-admin-form-style', |
| 91 | WPMTST_ADMIN_URL . 'css/admin-form.css', |
| 92 | array( 'wpmtst-admin-style' ), |
| 93 | $plugin_version ); |
| 94 | |
| 95 | wp_register_script( 'wpmtst-admin-form-script', |
| 96 | WPMTST_ADMIN_URL . 'js/admin-form.js', |
| 97 | array( 'wpmtst-admin-script', 'autosize' ), |
| 98 | $plugin_version, |
| 99 | true ); |
| 100 | |
| 101 | /** |
| 102 | * Compatibility tab |
| 103 | */ |
| 104 | wp_register_style( 'wpmtst-admin-compat-style', |
| 105 | WPMTST_ADMIN_URL . 'css/admin-compat.css', |
| 106 | array(), |
| 107 | $plugin_version ); |
| 108 | |
| 109 | wp_register_script( 'wpmtst-admin-compat-script', |
| 110 | WPMTST_ADMIN_URL . 'js/admin-compat.js', |
| 111 | array( 'jquery', 'wpmtst-custom-spinner', 'wpmtst-help' ), |
| 112 | $plugin_version, |
| 113 | true ); |
| 114 | |
| 115 | /** |
| 116 | * Fields |
| 117 | */ |
| 118 | wp_register_style( 'wpmtst-admin-fields-style', |
| 119 | WPMTST_ADMIN_URL . 'css/fields.css', |
| 120 | array(), |
| 121 | $plugin_version ); |
| 122 | |
| 123 | wp_register_style( 'wpmtst-admin-form-preview', |
| 124 | WPMTST_ADMIN_URL . 'css/form-preview.css', |
| 125 | array(), |
| 126 | $plugin_version ); |
| 127 | |
| 128 | wp_register_script( 'wpmtst-admin-fields-script', |
| 129 | WPMTST_ADMIN_URL . 'js/admin-fields.js', |
| 130 | array( 'jquery', 'jquery-ui-sortable', 'wpmtst-help' ), |
| 131 | $plugin_version, |
| 132 | true ); |
| 133 | |
| 134 | $params = array( |
| 135 | 'ajax_nonce' => wp_create_nonce( 'wpmtst-admin' ), |
| 136 | 'newField' => _x( 'New Field', 'Field editor: The default label for new fields', 'strong-testimonials' ), |
| 137 | 'inUse' => _x( '(in use)', 'Fields editor: To indicate when a field type can only be used once.', 'strong-testimonials' ), |
| 138 | 'noneFound' => _x( '(none found)', 'Fields editor: To indicate when no categories have been found.', 'strong-testimonials' ), |
| 139 | ); |
| 140 | wp_localize_script( 'wpmtst-admin-fields-script', 'wpmtstAdmin', $params ); |
| 141 | |
| 142 | /** |
| 143 | * Ratings |
| 144 | */ |
| 145 | wp_register_style( 'wpmtst-rating-display', |
| 146 | WPMTST_PUBLIC_URL . 'css/rating-display.css', |
| 147 | array( 'wpmtst-font-awesome' ), |
| 148 | $plugin_version ); |
| 149 | |
| 150 | wp_register_style( 'wpmtst-rating-form', |
| 151 | WPMTST_PUBLIC_URL . 'css/rating-form.css', |
| 152 | array( 'wpmtst-font-awesome' ), |
| 153 | $plugin_version ); |
| 154 | |
| 155 | wp_register_script( 'wpmtst-rating-script', |
| 156 | WPMTST_ADMIN_URL . 'js/rating-edit.js', |
| 157 | array( 'jquery' ), |
| 158 | $plugin_version, |
| 159 | true ); |
| 160 | |
| 161 | /** |
| 162 | * Views |
| 163 | */ |
| 164 | wp_register_style( 'wpmtst-admin-views-style', |
| 165 | WPMTST_ADMIN_URL . 'css/views.css', |
| 166 | array(), |
| 167 | $plugin_version ); |
| 168 | |
| 169 | wp_register_script( 'wpmtst-admin-views-script', |
| 170 | WPMTST_ADMIN_URL . 'js/views.js', |
| 171 | array( 'jquery', 'jquery-ui-sortable', 'wp-color-picker', 'jquery-masonry', 'wpmtst-help' ), |
| 172 | $plugin_version, |
| 173 | true ); |
| 174 | |
| 175 | /** |
| 176 | * Category filter in View editor. |
| 177 | * |
| 178 | * JavaScript adapted under GPL-2.0+ license |
| 179 | * from Post Category Filter plugin by Javier Villanueva (http://www.jahvi.com) |
| 180 | * |
| 181 | * @since 2.2.0 |
| 182 | */ |
| 183 | wp_register_script( 'wpmtst-view-category-filter-script', |
| 184 | WPMTST_ADMIN_URL . 'js/view-category-filter.js', |
| 185 | array( 'jquery' ), |
| 186 | $plugin_version, |
| 187 | true ); |
| 188 | |
| 189 | wp_register_style( 'wpmtst-about-style', |
| 190 | WPMTST_ADMIN_URL . 'css/about.css', |
| 191 | array(), |
| 192 | $plugin_version ); |
| 193 | |
| 194 | /** |
| 195 | * Add-on licenses |
| 196 | * |
| 197 | * @since 2.18 |
| 198 | */ |
| 199 | wp_register_script( 'wpmtst-addons-script', |
| 200 | WPMTST_ADMIN_URL . 'js/addon-licenses.js', |
| 201 | array( 'jquery' ), |
| 202 | $plugin_version, |
| 203 | true ); |
| 204 | |
| 205 | $params = array( |
| 206 | 'ajax_nonce' => wp_create_nonce( 'wpmtst-admin' ), |
| 207 | 'requiredField' => __( 'This field is required.', 'strong-testimonials' ), |
| 208 | 'errorMessage' => __( 'An error occurred, please try again.', 'strong-testimonials' ), |
| 209 | 'restoreDefault' => __( 'Restore the default settings?', 'strong-testimonials' ), |
| 210 | ); |
| 211 | wp_localize_script( 'wpmtst-addons-script', 'strongAddonAdmin', $params ); |
| 212 | |
| 213 | /** |
| 214 | * Are You Sure? for dirty forms |
| 215 | * |
| 216 | * @since 2.18 |
| 217 | */ |
| 218 | wp_register_script( 'wpmtst-ays-script', |
| 219 | WPMTST_ADMIN_URL . "js/lib/are-you-sure/jquery.are-you-sure{$min}.js", |
| 220 | array( 'jquery' ), |
| 221 | $plugin_version, |
| 222 | true ); |
| 223 | } |
| 224 | |
| 225 | /** |
| 226 | * Enqueue global admin scripts. |
| 227 | */ |
| 228 | public static function admin_enqueue_scripts() { |
| 229 | $plugin_version = get_option( 'wpmtst_plugin_version' ); |
| 230 | |
| 231 | wp_enqueue_script( 'wpmtst-admin-global', |
| 232 | WPMTST_ADMIN_URL . 'js/admin-global.js', |
| 233 | array( 'jquery' ), |
| 234 | $plugin_version, |
| 235 | true ); |
| 236 | |
| 237 | wp_localize_script( |
| 238 | 'wpmtst-admin-global', |
| 239 | 'wpmtst_admin', |
| 240 | array( |
| 241 | 'nonce' => wp_create_nonce( 'wpmtst-admin' ), |
| 242 | 'templateTagTitle' => __( 'click to insert into message at caret', 'strong-testimonials' ), |
| 243 | ) |
| 244 | ); |
| 245 | } |
| 246 | |
| 247 | /** |
| 248 | * Enqueue specific styles and scripts. |
| 249 | * |
| 250 | * Using separate hooks for readability, troubleshooting, and future refactoring. Focus on _where_. |
| 251 | * |
| 252 | * @since 2.12.0 |
| 253 | */ |
| 254 | |
| 255 | /** |
| 256 | * Views |
| 257 | */ |
| 258 | public static function admin_views() { |
| 259 | wp_enqueue_style( 'wpmtst-admin-style' ); |
| 260 | wp_enqueue_script( 'wpmtst-admin-script' ); |
| 261 | |
| 262 | wp_enqueue_style( 'wpmtst-admin-views-style' ); |
| 263 | wp_enqueue_script( 'wpmtst-admin-views-script' ); |
| 264 | wp_enqueue_script( 'wpmtst-view-category-filter-script' ); |
| 265 | |
| 266 | wp_enqueue_style( 'wp-color-picker' ); |
| 267 | } |
| 268 | |
| 269 | /** |
| 270 | * Fields |
| 271 | */ |
| 272 | public static function admin_fields() { |
| 273 | wp_enqueue_style( 'wpmtst-admin-style' ); |
| 274 | wp_enqueue_script( 'wpmtst-admin-script' ); |
| 275 | |
| 276 | wp_enqueue_style( 'wpmtst-admin-fields-style' ); |
| 277 | wp_enqueue_script( 'wpmtst-admin-fields-script' ); |
| 278 | |
| 279 | wp_enqueue_style( 'wpmtst-admin-form-preview' ); |
| 280 | wp_enqueue_style( 'wpmtst-rating-form' ); |
| 281 | } |
| 282 | |
| 283 | /** |
| 284 | * Settings |
| 285 | */ |
| 286 | public static function admin_settings() { |
| 287 | $tab = isset( $_GET['tab'] ) ? $_GET['tab'] : ''; |
| 288 | |
| 289 | switch ( $tab ) { |
| 290 | case 'form': |
| 291 | wp_enqueue_style( 'wpmtst-admin-form-style' ); |
| 292 | wp_enqueue_script( 'wpmtst-admin-form-script' ); |
| 293 | break; |
| 294 | case 'compat': |
| 295 | wp_enqueue_style( 'wpmtst-admin-compat-style' ); |
| 296 | wp_enqueue_script( 'wpmtst-admin-compat-script' ); |
| 297 | break; |
| 298 | case 'licenses': |
| 299 | wp_enqueue_style( 'wpmtst-admin-style' ); |
| 300 | wp_enqueue_script( 'wpmtst-addons-script' ); |
| 301 | break; |
| 302 | default: |
| 303 | wp_enqueue_style( 'wpmtst-admin-style' ); |
| 304 | wp_enqueue_script( 'wpmtst-admin-script' ); |
| 305 | } |
| 306 | } |
| 307 | |
| 308 | /** |
| 309 | * About |
| 310 | */ |
| 311 | public static function admin_about() { |
| 312 | wp_enqueue_style( 'wpmtst-admin-style' ); |
| 313 | wp_enqueue_script( 'wpmtst-admin-script' ); |
| 314 | wp_enqueue_style( 'wpmtst-about-style' ); |
| 315 | } |
| 316 | |
| 317 | /** |
| 318 | * Shortcodes |
| 319 | * |
| 320 | * @since 2.31.0 |
| 321 | */ |
| 322 | public static function admin_shortcodes() { |
| 323 | wp_enqueue_style( 'wpmtst-admin-style' ); |
| 324 | wp_enqueue_style( 'wpmtst-rating-display' ); |
| 325 | } |
| 326 | |
| 327 | /** |
| 328 | * List table |
| 329 | */ |
| 330 | public static function admin_load_edit() { |
| 331 | if ( wpmtst_is_testimonial_screen() ) { |
| 332 | wp_enqueue_style( 'wpmtst-admin-style' ); |
| 333 | wp_enqueue_script( 'wpmtst-admin-script' ); |
| 334 | wp_enqueue_style( 'wpmtst-rating-display' ); |
| 335 | } |
| 336 | } |
| 337 | |
| 338 | /** |
| 339 | * Categories |
| 340 | */ |
| 341 | public static function admin_load_edit_tags() { |
| 342 | if ( wpmtst_is_testimonial_screen() ) { |
| 343 | wp_enqueue_style( 'wpmtst-admin-style' ); |
| 344 | } |
| 345 | } |
| 346 | |
| 347 | /** |
| 348 | * Edit post |
| 349 | */ |
| 350 | public static function admin_load_post() { |
| 351 | if ( wpmtst_is_testimonial_screen() ) { |
| 352 | wp_enqueue_style( 'wpmtst-post-editor' ); |
| 353 | wp_enqueue_script( 'wpmtst-admin-script' ); |
| 354 | |
| 355 | wp_enqueue_style( 'wpmtst-rating-display' ); |
| 356 | wp_enqueue_style( 'wpmtst-rating-form' ); |
| 357 | wp_enqueue_script( 'wpmtst-rating-script' ); |
| 358 | } |
| 359 | } |
| 360 | |
| 361 | /** |
| 362 | * Known theme and plugin conflicts. |
| 363 | * |
| 364 | * @param $hook |
| 365 | */ |
| 366 | public static function admin_dequeue_scripts( $hook ) { |
| 367 | if ( wp_style_is( 'CPTStyleSheets' ) ) { |
| 368 | wp_dequeue_style( 'CPTStyleSheets' ); |
| 369 | } |
| 370 | |
| 371 | $hooks_to_script = array( |
| 372 | 'wpm-testimonial_page_testimonial-views', |
| 373 | 'wpm-testimonial_page_testimonial-fields', |
| 374 | 'wpm-testimonial_page_testimonial-settings', |
| 375 | 'wpm-testimonial_page_about-strong-testimonials', |
| 376 | ); |
| 377 | |
| 378 | if ( wpmtst_is_testimonial_screen() ) { |
| 379 | $hooks_to_script = array_merge( $hooks_to_script, array( 'edit.php' ) ); |
| 380 | } |
| 381 | |
| 382 | /** |
| 383 | * Block RT Themes and their overzealous JavaScript on our admin pages. |
| 384 | * @since 2.2.12.1 |
| 385 | */ |
| 386 | if ( in_array( $hook, $hooks_to_script ) ) { |
| 387 | if ( class_exists( 'RTThemeAdmin' ) && wp_script_is( 'admin-scripts' ) ) { |
| 388 | wp_dequeue_script( 'admin-scripts' ); |
| 389 | } |
| 390 | } |
| 391 | } |
| 392 | |
| 393 | } |
| 394 | |
| 395 | Strong_Testimonials_Admin_Scripts::init(); |
| 396 |