| 1 |
<?php |
| 2 |
/** |
| 3 |
* @package Awesome Support/Scripts |
| 4 |
* @author AwesomeSupport <contact@getawesomesupport.com> |
| 5 |
* @license GPL-2.0+ |
| 6 |
* @link https://getawesomesupport.com |
| 7 |
* @copyright 2015-2017 AwesomeSupport |
| 8 |
*/ |
| 9 |
|
| 10 |
// If this file is called directly, abort. |
| 11 |
if ( ! defined( 'WPINC' ) ) { |
| 12 |
die; |
| 13 |
} |
| 14 |
|
| 15 |
add_action( 'wp_enqueue_scripts', 'wpas_register_assets_front_end', 5 ); |
| 16 |
/** |
| 17 |
* Register all front-end assets |
| 18 |
* |
| 19 |
* @since 3.3 |
| 20 |
* @return void |
| 21 |
*/ |
| 22 |
function wpas_register_assets_front_end() { |
| 23 |
|
| 24 |
// Optionally load bootstrap 4 or bootstrap 3 files from cdn. |
| 25 |
// These assets are also duplicated and loaded on the back-end |
| 26 |
$load_bs4 = wpas_get_option('load_bs4_files_fe', '0') ; |
| 27 |
if ( '1' === $load_bs4 ) { |
| 28 |
wpas_register_bs4_theme_styles() ; |
| 29 |
wp_register_script( 'wpas-bootstrap-4-popper', WPAS_URL . 'assets/public/vendor/popper/js/popper.min.js', array( 'jquery' ), '1.11.0', true ); |
| 30 |
wp_register_script( 'wpas-bootstrap-4-js', WPAS_URL . 'assets/public/vendor/bootstrap/4.0.0/js/bootstrap.min.js', array( 'jquery' ), '4.0.0', true ); |
| 31 |
} |
| 32 |
if ( '2' === $load_bs4 ) { |
| 33 |
// Boostrap 3 styles and scripts |
| 34 |
wp_register_style( 'wpas-bootstrap-3', WPAS_URL . 'assets/public/vendor/bootstrap/3.3.7/css/bootstrap.min.css', array(), '3.3.7' ); |
| 35 |
wp_register_style( 'wpas-bootstrap-3-ss', WPAS_URL . 'assets/public/vendor/bootstrap/3.3.7/css/bootstrap-theme.min.css', array(), '3.3.7' ); |
| 36 |
wp_register_script( 'wpas-bootstrap-3-js', WPAS_URL . 'assets/public/vendor/bootstrap/3.3.7/js/bootstrap.min.js', array( 'jquery' ), '3.3.7', true ); |
| 37 |
} |
| 38 |
|
| 39 |
// Our styles |
| 40 |
wp_register_style( 'wpas-plugin-styles', WPAS_URL . 'assets/public/css/public.css', array(), WPAS_VERSION ); |
| 41 |
|
| 42 |
// Select2 styles are loaded based on a setting. This asset is also duplicated on the back-end. |
| 43 |
// Note that we are hardcoding a version number into the wp_register_script call so that we can force caches to update when switching between options. |
| 44 |
$which_select2_css = wpas_get_option('select2_css_file', 'min') ; |
| 45 |
$which_select2_version = wpas_get_option('select2_version', 'select2-4-0-5') ; |
| 46 |
switch ( $which_select2_css ) { |
| 47 |
case 'min': |
| 48 |
wp_register_style( 'wpas-select2', WPAS_URL . "assets/admin/css/vendor/select2/$which_select2_version/select2.min.css", null, WPAS_VERSION.'.1', 'all' ); |
| 49 |
break ; |
| 50 |
|
| 51 |
case 'full': |
| 52 |
wp_register_style( 'wpas-select2', WPAS_URL . "assets/admin/css/vendor/select2/$which_select2_version/select2.css", null, WPAS_VERSION.'.2', 'all' ); |
| 53 |
break ; |
| 54 |
} |
| 55 |
|
| 56 |
// Scripts |
| 57 |
wp_register_script( 'wpas-plugin-script', WPAS_URL . 'assets/public/js/public-dist.js', array( 'jquery' ), WPAS_VERSION, true ); |
| 58 |
|
| 59 |
// Select2 scripts are loaded based on a setting. This asset is also duplicated on the back-end. |
| 60 |
// Note that we are hardcoding a version number into the wp_register_script call so that we can force caches to update when switching between options. |
| 61 |
$which_select2_js = wpas_get_option('select2_js_file', 'full-min') ; |
| 62 |
$which_select2_version = wpas_get_option('select2_version', 'select2-4-0-5') ; |
| 63 |
switch ( $which_select2_js ) { |
| 64 |
case 'full': |
| 65 |
wp_register_script( 'wpas-select2', WPAS_URL . "assets/admin/js/vendor/select2/$which_select2_version/select2.full.js", array( 'jquery' ), WPAS_VERSION.'.1', 'all' ); |
| 66 |
break ; |
| 67 |
|
| 68 |
case 'full-min': |
| 69 |
wp_register_script( 'wpas-select2', WPAS_URL . "assets/admin/js/vendor/select2/$which_select2_version/select2.full.min.js", array( 'jquery' ), WPAS_VERSION.'.2', 'all' ); |
| 70 |
break ; |
| 71 |
|
| 72 |
case 'partial': |
| 73 |
wp_register_script( 'wpas-select2', WPAS_URL . "assets/admin/js/vendor/select2/$which_select2_version/select2.js", array( 'jquery' ), WPAS_VERSION.'.3', 'all' ); |
| 74 |
break ; |
| 75 |
|
| 76 |
case 'partial-min': |
| 77 |
wp_register_script( 'wpas-select2', WPAS_URL . "assets/admin/js/vendor/select2/$which_select2_version/select2.min.js", array( 'jquery' ), WPAS_VERSION.'.4', 'all' ); |
| 78 |
break ; |
| 79 |
} |
| 80 |
|
| 81 |
// Include magnific popup |
| 82 |
wpas_add_magnific(); |
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
// JS Objects |
| 87 |
wp_localize_script( 'wpas-plugin-script', 'wpas', wpas_get_javascript_object() ); |
| 88 |
|
| 89 |
} |
| 90 |
|
| 91 |
add_action( 'admin_enqueue_scripts', 'wpas_register_assets_back_end', 5 ); |
| 92 |
/** |
| 93 |
* Register all back-end assets |
| 94 |
* |
| 95 |
* @since 3.3 |
| 96 |
* @return void |
| 97 |
* |
| 98 |
* @TODO: It is possible that most of the function below should be wrapped in a conditional similar to this: |
| 99 |
* if ( true == wpas_is_plugin_page() ) |
| 100 |
*/ |
| 101 |
function wpas_register_assets_back_end() { |
| 102 |
|
| 103 |
// Optionally load bootstrap 4 or bootstrap 3 files from cdn. |
| 104 |
// These assets are also duplicated and loaded on the front-end |
| 105 |
$load_bs4 = wpas_get_option('load_bs4_files_be', '0') ; |
| 106 |
if ( '1' === $load_bs4 ) { |
| 107 |
wpas_register_bs4_theme_styles(); |
| 108 |
wp_register_script( 'wpas-bootstrap-4-popper', WPAS_URL . 'assets/public/vendor/popper/js/popper.min.js', array( 'jquery' ), '1.11.0', true ); |
| 109 |
wp_register_script( 'wpas-bootstrap-4-js', WPAS_URL . 'assets/public/vendor/bootstrap/4.0.0/js/bootstrap.min.js', array( 'jquery' ), '4.0.0', true ); |
| 110 |
} |
| 111 |
if ( '2' === $load_bs4 ) { |
| 112 |
// Boostrap 3 styles and scripts |
| 113 |
wp_register_style( 'wpas-bootstrap-3', WPAS_URL . 'assets/public/vendor/bootstrap/3.3.7/css/bootstrap.min.css', array(), '3.3.7' ); |
| 114 |
wp_register_style( 'wpas-bootstrap-3-ss', WPAS_URL . 'assets/public/vendor/bootstrap/3.3.7/css/bootstrap-theme.min.css', array(), '3.3.7' ); |
| 115 |
wp_register_script( 'wpas-bootstrap-3-js', WPAS_URL . 'assets/public/vendor/bootstrap/3.3.7/js/bootstrap.min.js', array( 'jquery' ), '3.3.7', true ); |
| 116 |
} |
| 117 |
|
| 118 |
// Other 3rd party styles |
| 119 |
wp_register_style( 'wpas-datepicker', WPAS_URL . 'assets/public/css/component_datepicker.css', null, WPAS_VERSION, 'all' ); // NOTE: This asset is duplicated in the back-end |
| 120 |
wp_register_style( 'wpas-simple-hint', WPAS_URL . 'assets/public/vendor/simple-hint/css/simple-hint.min.css', null, '2.1.1' ); |
| 121 |
if ( intval( $load_bs4 ) <= 0 ) { |
| 122 |
wp_register_style( 'wpas-flexboxgrid', WPAS_URL . 'assets/admin/css/vendor/flexboxgrid.min.css', null, '6.2.0', 'all' ); |
| 123 |
} |
| 124 |
|
| 125 |
// Our styles |
| 126 |
wp_register_style( 'wpas-admin-styles', WPAS_URL . 'assets/admin/css/admin.css', array( 'wpas-select2' ), WPAS_VERSION ); |
| 127 |
wp_register_style( 'wpas-admin-reply-history', WPAS_URL . 'assets/admin/css/admin-reply-history.css', array(), WPAS_VERSION ); |
| 128 |
wp_register_style( 'wpas-admin-print-ticket', WPAS_URL . 'assets/admin/css/admin-print-ticket.css', null, WPAS_VERSION ); |
| 129 |
wp_register_style( 'wpas-admin-icons', WPAS_URL . 'assets/admin/css/admin-icons.css', array(), WPAS_VERSION ); |
| 130 |
|
| 131 |
// Select2 styles are loaded based on a setting. This asset is also duplicated on the front-end. |
| 132 |
// Note that we are hardcoding a version number into the wp_register_script call so that we can force caches to update when switching between options. |
| 133 |
$which_select2_css = wpas_get_option('select2_css_file', 'min') ; |
| 134 |
$which_select2_version = wpas_get_option('select2_version', 'select2-4-0-5') ; |
| 135 |
switch ( $which_select2_css ) { |
| 136 |
case 'min': |
| 137 |
wp_register_style( 'wpas-select2', WPAS_URL . "assets/admin/css/vendor/select2/$which_select2_version/select2.min.css", null, WPAS_VERSION.'.1', 'all' ); |
| 138 |
break ; |
| 139 |
|
| 140 |
case 'full': |
| 141 |
wp_register_style( 'wpas-select2', WPAS_URL . "assets/admin/css/vendor/select2/$which_select2_version/select2.css", null, WPAS_VERSION.'.2', 'all' ); |
| 142 |
break ; |
| 143 |
} |
| 144 |
|
| 145 |
|
| 146 |
// Our Scripts |
| 147 |
wp_register_script( 'wpas-admin-about-linkify', WPAS_URL . 'assets/admin/js/vendor/linkify.min.js', array( 'jquery' ), WPAS_VERSION ); |
| 148 |
wp_register_script( 'wpas-admin-about-linkify-jquery', WPAS_URL . 'assets/admin/js/vendor/linkify-jquery.min.js', array( 'jquery' ), WPAS_VERSION ); |
| 149 |
wp_register_script( 'wpas-admin-about-moment', WPAS_URL . 'assets/admin/js/vendor/moment.min.js', array( 'jquery' ), WPAS_VERSION ); |
| 150 |
wp_register_script( 'wpas-admin-about-script', WPAS_URL . 'assets/admin/js/admin-about.js', array( 'jquery' ), WPAS_VERSION ); |
| 151 |
wp_register_script( 'wpas-admin-optin-script', WPAS_URL . 'assets/admin/js/admin-optin.js', array( 'jquery' ), WPAS_VERSION ); |
| 152 |
wp_localize_script( 'wpas-admin-optin-script', 'WPAS_Optin', array( |
| 153 |
'nonce' => wp_create_nonce('wpas_admin_optin'), // Créez la nonce et transmettez-la au script |
| 154 |
)); |
| 155 |
wp_register_script( 'wpas-admin-script', WPAS_URL . 'assets/admin/js/admin.js', array( 'jquery', 'wpas-select2' ), WPAS_VERSION ); |
| 156 |
wp_register_script( 'wpas-admin-toolbars-script', WPAS_URL . 'assets/admin/js/admin-toolbars.js', array( 'jquery', 'wpas-select2' ), WPAS_VERSION ); |
| 157 |
wp_register_script( 'wpas-admin-tabletojson', WPAS_URL . 'assets/admin/js/vendor/jquery.tabletojson.min.js', array( 'jquery' ), WPAS_VERSION ); |
| 158 |
wp_register_script( 'wpas-admin-reply', WPAS_URL . 'assets/admin/js/admin-reply.js', array( 'jquery' ), WPAS_VERSION ); |
| 159 |
wp_register_script( 'wpas-admin-reply-history', WPAS_URL . 'assets/admin/js/admin-reply-history.js', array( 'jquery' ), WPAS_VERSION ); |
| 160 |
wp_register_script( 'wpas-autolinker', WPAS_URL . 'assets/public/vendor/Autolinker/Autolinker.min.js', null, '0.19.0', true ); |
| 161 |
wp_register_script( 'wpas-users', WPAS_URL . 'assets/admin/js/admin-users.js', null, WPAS_VERSION, true ); |
| 162 |
wp_register_script( 'wpas-admin-helpers_functions', WPAS_URL . 'assets/public/js/helpers_functions.js', null, WPAS_VERSION ); |
| 163 |
wp_register_script( 'wpas-admin-upload', WPAS_URL . 'assets/public/js/component_upload.js', array( 'jquery' ), WPAS_VERSION ); |
| 164 |
wp_register_script( 'wpas-admin-print-ticket', WPAS_URL . 'assets/admin/js/admin-print-ticket.js', array( 'jquery' ), WPAS_VERSION ); |
| 165 |
wp_register_script( 'wpas-admin-edit-ticket-content-script', WPAS_URL . 'assets/admin/js/admin-edit-ticket-content.js', array( 'jquery' ), WPAS_VERSION ); |
| 166 |
// @TODO: Why is the version set to TIME() below instead of WPAS_VERSION? |
| 167 |
wp_register_script( |
| 168 |
'wpas-datepicker', |
| 169 |
WPAS_URL . 'assets/public/js/component_datepicker.js', |
| 170 |
array('jquery', 'jquery-ui-core', 'jquery-ui-datepicker'), |
| 171 |
time(), |
| 172 |
true |
| 173 |
); |
| 174 |
|
| 175 |
// Select2 scripts are loaded based on a setting. This asset is also duplicated on the front-end. |
| 176 |
// Note that we are hardcoding a version number into the wp_register_script call so that we can force caches to update when switching between options. |
| 177 |
$which_select2_js = wpas_get_option('select2_js_file', 'partial-min') ; |
| 178 |
$which_select2_version = wpas_get_option('select2_version', 'select2-4-0-5') ; |
| 179 |
switch ( $which_select2_js ) { |
| 180 |
case 'full': |
| 181 |
wp_register_script( 'wpas-select2', WPAS_URL . "assets/admin/js/vendor/select2/$which_select2_version/select2.full.js", array( 'jquery' ), WPAS_VERSION.'.1', 'all' ); |
| 182 |
break ; |
| 183 |
|
| 184 |
case 'full-min': |
| 185 |
wp_register_script( 'wpas-select2', WPAS_URL . "assets/admin/js/vendor/select2/$which_select2_version/select2.full.min.js", array( 'jquery' ), WPAS_VERSION.'.2', 'all' ); |
| 186 |
break ; |
| 187 |
|
| 188 |
case 'partial': |
| 189 |
wp_register_script( 'wpas-select2', WPAS_URL . "assets/admin/js/vendor/select2/$which_select2_version/select2.js", array( 'jquery' ), WPAS_VERSION.'.3', 'all' ); |
| 190 |
break ; |
| 191 |
|
| 192 |
case 'partial-min': |
| 193 |
wp_register_script( 'wpas-select2', WPAS_URL . "assets/admin/js/vendor/select2/$which_select2_version/select2.min.js", array( 'jquery' ), WPAS_VERSION.'.4', 'all' ); |
| 194 |
break ; |
| 195 |
} |
| 196 |
|
| 197 |
// JS Objects |
| 198 |
wp_localize_script( 'wpas-admin-script', 'wpas', wpas_get_javascript_object() ); |
| 199 |
wp_localize_script( 'wpas-admin-reply', 'wpasL10n', array( |
| 200 |
'alertDelete' => __( 'Are you sure you want to delete this reply?', 'awesome-support' ), |
| 201 |
'alertNoTinyMCE' => __( 'No instance of TinyMCE found. Please use wp_editor on this page at least once: http://codex.wordpress.org/Function_Reference/wp_editor', 'awesome-support' ), |
| 202 |
'alertNoContent' => __( "You can't submit an empty reply", 'awesome-support' ), |
| 203 |
'reply_nonce' => wp_create_nonce( 'wpas_edit_reply' ), |
| 204 |
'editor_content_nonce' => wp_create_nonce( 'wpas-editor-content-nonce' ) |
| 205 |
) ); |
| 206 |
wp_localize_script( 'wpas-admin-reply-history', 'WPAS_Reply_History', array( |
| 207 |
'ajax_url' => admin_url( 'admin-ajax.php' ), |
| 208 |
'date_label' => __( 'Edited on', 'awesome-support' ), |
| 209 |
'wpas_history_reply_nonce' => wp_create_nonce( 'wpas_history_reply_nonce' ) |
| 210 |
)); |
| 211 |
|
| 212 |
// Print ticket vars |
| 213 |
wp_localize_script( 'wpas-admin-print-ticket', 'WPAS_Print', array( |
| 214 |
'admin_url' => admin_url(), |
| 215 |
'plugin_url' => WPAS_URL, |
| 216 |
'nonce' => wp_create_nonce( 'wpas_print_ticket' ), |
| 217 |
'print' => __( 'Print', 'awesome-support' ), |
| 218 |
'cancel' => __( 'Cancel', 'awesome-support' ), |
| 219 |
'print_ticket' => __( 'Print ticket', 'awesome-support' ), |
| 220 |
'print_tickets' => __( 'Print tickets', 'awesome-support' ), |
| 221 |
'include_replies' => __( 'Include replies', 'awesome-support' ), |
| 222 |
'include_history' => __( 'Include history', 'awesome-support' ), |
| 223 |
'include_private_notes' => __( 'Include private notes', 'awesome-support' ), |
| 224 |
'include_custom_fields' => __( 'Include custom fields', 'awesome-support' ), |
| 225 |
'include_attachments' => __( 'Include attachments', 'awesome-support' ), |
| 226 |
) ); |
| 227 |
|
| 228 |
|
| 229 |
// Custom admin notice style and script (only when wizard notice is active) |
| 230 |
if ( ! get_option( 'wpas_plugin_setup', false ) && ! get_option( 'wpas_skip_wizard_setup', false ) && wpas_is_asadmin() ) { |
| 231 |
wp_enqueue_style( 'wpas-admin-wizard-notice', WPAS_URL . 'assets/admin/css/wizard-notice.css', array(), WPAS_VERSION ); |
| 232 |
wp_enqueue_script( 'wpas-admin-wizard-script', WPAS_URL . 'assets/admin/js/admin-wizard.js', array( 'jquery' ), WPAS_VERSION ); |
| 233 |
wp_localize_script( 'wpas-admin-wizard-script', 'WPAS_Wizard', array( |
| 234 |
'ajax_url' => admin_url( 'admin-ajax.php' ), |
| 235 |
'about_page' => admin_url( 'edit.php?post_type=ticket&page=wpas-about' ), |
| 236 |
'nonce' => wp_create_nonce('wpas_admin_wizard'), // Create nonce and transmit it to the script |
| 237 |
)); |
| 238 |
} |
| 239 |
wp_register_style( 'wpas-admin-gdpr', WPAS_URL . 'assets/admin/css/admin-gdpr.css', array(), WPAS_VERSION ); |
| 240 |
|
| 241 |
// Include magnific popup |
| 242 |
if ( true == wpas_is_plugin_page() ) { |
| 243 |
wpas_add_magnific(); |
| 244 |
} |
| 245 |
|
| 246 |
// Edit ticket content! |
| 247 |
if ( true == wpas_is_plugin_page() ) { |
| 248 |
wp_enqueue_editor(); |
| 249 |
wp_enqueue_media(); |
| 250 |
} |
| 251 |
|
| 252 |
} |
| 253 |
|
| 254 |
add_action( 'wp_enqueue_scripts', 'wpas_assets_front_end', 10 ); |
| 255 |
/** |
| 256 |
* Register and enqueue public-facing style sheet. |
| 257 |
* |
| 258 |
* @since 1.0.2 |
| 259 |
*/ |
| 260 |
function wpas_assets_front_end() { |
| 261 |
|
| 262 |
// Make sure we only enqueue on our plugin's pages |
| 263 |
if ( wpas_is_plugin_page() ) { |
| 264 |
|
| 265 |
// Optionally load bootstrap 4 or bootstrap 3 files from cdn. |
| 266 |
$load_bs4 = wpas_get_option('load_bs4_files_fe', '0') ; |
| 267 |
if ( '1' === $load_bs4 ) { |
| 268 |
// Boostrap 4 styles and scripts |
| 269 |
wp_enqueue_style( 'wpas-bootstrap-4' ); |
| 270 |
wp_enqueue_script( 'wpas-bootstrap-4-popper' ); |
| 271 |
wp_enqueue_script( 'wpas-bootstrap-4-js' ); |
| 272 |
} |
| 273 |
if ( '2' === $load_bs4 ) { |
| 274 |
// Boostrap 3 styles and scripts |
| 275 |
wp_enqueue_style( 'wpas-bootstrap-3' ); |
| 276 |
wp_enqueue_style( 'wpas-bootstrap-3-ss' ); |
| 277 |
wp_enqueue_script( 'wpas-bootstrap-3-js' ); |
| 278 |
} |
| 279 |
|
| 280 |
// @todo - where are the SELECT2 scripts being enqueued? |
| 281 |
// Feels like they shoudl be enqueued here - maybe controlled via a setting in TICKETS->SETTINGS->ADVANCED |
| 282 |
|
| 283 |
// Our Custom Styles |
| 284 |
wp_enqueue_style( 'wpas-plugin-styles' ); |
| 285 |
|
| 286 |
$stylesheet = wpas_get_theme_stylesheet(); |
| 287 |
|
| 288 |
if ( file_exists( $stylesheet ) && true === boolval( wpas_get_option( 'theme_stylesheet' ) ) ) { |
| 289 |
wp_register_style( 'wpas-theme-styles', wpas_get_theme_stylesheet_uri(), array(), WPAS_VERSION ); |
| 290 |
wp_enqueue_style( 'wpas-theme-styles' ); |
| 291 |
} |
| 292 |
|
| 293 |
// GDPR Privacy options script and style. |
| 294 |
wp_enqueue_editor(); |
| 295 |
wp_register_script( 'wpas-gdpr-script', WPAS_URL . 'assets/public/js/component-privacy-popup.js', array( 'jquery' ), WPAS_VERSION ); |
| 296 |
wp_localize_script( 'wpas-gdpr-script', 'WPAS_GDPR', array( |
| 297 |
'ajax_url' => admin_url( 'admin-ajax.php' ), |
| 298 |
'nonce' => wp_create_nonce( 'wpas-gdpr-nonce' ) |
| 299 |
) ); |
| 300 |
wp_enqueue_script( 'wpas-gdpr-script' ); |
| 301 |
|
| 302 |
// Our Custom Scripts |
| 303 |
wp_enqueue_script( 'wpas-plugin-script' ); |
| 304 |
|
| 305 |
} |
| 306 |
|
| 307 |
} |
| 308 |
|
| 309 |
add_action( 'admin_enqueue_scripts', 'wpas_enqueue_assets_back_end', 10 ); |
| 310 |
/** |
| 311 |
* Register and enqueue admin-specific style sheet. |
| 312 |
* |
| 313 |
* @since 1.0.0 |
| 314 |
* @return null Return early if no settings page is registered. |
| 315 |
*/ |
| 316 |
function wpas_enqueue_assets_back_end() { |
| 317 |
|
| 318 |
// Make sure we only enqueue on our plugin's pages |
| 319 |
if ( wpas_is_plugin_page() ) { |
| 320 |
|
| 321 |
// Optionally load bootstrap 4 or bootstrap 3 files from cdn. |
| 322 |
$load_bs4 = wpas_get_option('load_bs4_files_be', '0') ; |
| 323 |
if ( '1' === $load_bs4 ) { |
| 324 |
// Boostrap 4 styles and scripts |
| 325 |
wp_enqueue_style( 'wpas-bootstrap-4' ); |
| 326 |
wp_enqueue_script( 'wpas-bootstrap-4-popper' ); |
| 327 |
wp_enqueue_script( 'wpas-bootstrap-4-js' ); |
| 328 |
} |
| 329 |
if ( '2' === $load_bs4 ) { |
| 330 |
// Boostrap 3 styles and scripts |
| 331 |
wp_enqueue_style( 'wpas-bootstrap-3' ); |
| 332 |
wp_enqueue_style( 'wpas-bootstrap-3-ss' ); |
| 333 |
wp_enqueue_script( 'wpas-bootstrap-3-js' ); |
| 334 |
} |
| 335 |
|
| 336 |
// Our Styles |
| 337 |
wp_enqueue_style( 'wpas-select2' ); |
| 338 |
wp_enqueue_style( 'wpas-datepicker' ); |
| 339 |
wp_enqueue_style( 'wpas-flexboxgrid' ); |
| 340 |
wp_enqueue_style( 'wpas-admin-styles' ); |
| 341 |
wp_enqueue_style( 'wpas-admin-icons' ); |
| 342 |
|
| 343 |
if ( isset( $_GET['action'] ) && 'edit' === $_GET['action'] ) { |
| 344 |
wp_enqueue_style( 'wpas-simple-hint' ); |
| 345 |
} |
| 346 |
|
| 347 |
// Our Scripts |
| 348 |
if ( 'ticket' == get_post_type() ) { |
| 349 |
wp_dequeue_script( 'autosave' ); |
| 350 |
} |
| 351 |
|
| 352 |
$page = isset( $_GET['page'] ) ? sanitize_text_field( wp_unslash( $_GET['page'] ) ) : ''; |
| 353 |
$action = isset( $_GET['action'] ) ? sanitize_text_field( wp_unslash( $_GET['action'] ) ) : ''; |
| 354 |
|
| 355 |
if ( 'wpas-about' === $page ) { |
| 356 |
wp_enqueue_script( 'wpas-admin-about-linkify' ); |
| 357 |
wp_enqueue_script( 'wpas-admin-about-linkify-jquery' ); |
| 358 |
wp_enqueue_script( 'wpas-admin-about-moment' ); |
| 359 |
wp_enqueue_script( 'wpas-admin-about-script' ); |
| 360 |
} |
| 361 |
|
| 362 |
if ( 'wpas-optin' === $page ) { |
| 363 |
wp_enqueue_script( 'wpas-admin-optin-script' ); |
| 364 |
} |
| 365 |
|
| 366 |
wp_enqueue_script( 'wpas-select2' ); |
| 367 |
wp_enqueue_script( 'wpas-datepicker' ); |
| 368 |
|
| 369 |
wp_enqueue_script( 'wpas-admin-script' ); |
| 370 |
wp_enqueue_script( 'wpas-admin-toolbars-script' ) ; |
| 371 |
wp_enqueue_script( 'wpas-admin-tabletojson' ); |
| 372 |
wp_enqueue_script( 'wpas-users' ); |
| 373 |
wp_localize_script( 'wpas-users', 'WPAS_get_users', array( |
| 374 |
'get_users_nonce' => wp_create_nonce( 'wpas-get-users' ) |
| 375 |
) ); |
| 376 |
wp_enqueue_script( 'wpas-admin-helpers_functions' ); |
| 377 |
wp_enqueue_script( 'wpas-admin-upload' ); |
| 378 |
|
| 379 |
if ( 'edit' === $action && 'ticket' == get_post_type() ) { |
| 380 |
wp_enqueue_style( 'wpas-admin-reply-history' ); |
| 381 |
wp_enqueue_script( 'wpas-admin-reply' ); |
| 382 |
wp_enqueue_script( 'wpas-admin-reply-history' ); |
| 383 |
wp_enqueue_script( 'wpas-autolinker' ); |
| 384 |
} |
| 385 |
|
| 386 |
wp_enqueue_script( 'wpas-admin-edit-ticket-content-script'); |
| 387 |
wp_localize_script( 'wpas-admin-edit-ticket-content-script', 'WPAS_Edit_Ticket_Content', array( |
| 388 |
'ajax_url' => admin_url( 'admin-ajax.php' ), |
| 389 |
'editor_content_nonce' => wp_create_nonce( 'wpas-editor-content-nonce' ) |
| 390 |
)); |
| 391 |
|
| 392 |
if ( wpas_is_admin_all_tickets_page() ) { |
| 393 |
wp_enqueue_style( 'wpas-admin-print-ticket' ); |
| 394 |
wp_enqueue_script( 'wpas-admin-print-ticket' ); |
| 395 |
} |
| 396 |
|
| 397 |
} |
| 398 |
|
| 399 |
wp_register_script( 'wpas-gdpr-admin-script', WPAS_URL . 'assets/admin/js/admin-gdpr.js', array( 'jquery' ), WPAS_VERSION ); |
| 400 |
wp_localize_script( 'wpas-gdpr-admin-script', 'WPAS_GDPR', array( |
| 401 |
'ajax_url' => admin_url( 'admin-ajax.php' ), |
| 402 |
'nonce' => wp_create_nonce( 'wpas-gdpr-nonce' ), |
| 403 |
) ); |
| 404 |
|
| 405 |
$screen = get_current_screen(); |
| 406 |
if ( $screen && in_array( $screen->id, array( 'profile', 'user-edit' ), true ) ) { |
| 407 |
wp_enqueue_style( 'wpas-admin-gdpr' ); |
| 408 |
wp_enqueue_script( 'wpas-gdpr-admin-script' ); |
| 409 |
} |
| 410 |
} |
| 411 |
|
| 412 |
/** |
| 413 |
* JavaScript object. |
| 414 |
* |
| 415 |
* The plugin uses a couple of JS variables that we pass |
| 416 |
* to the main script through a "wpas" object. |
| 417 |
* |
| 418 |
* @since 3.0.2 |
| 419 |
* @return array The JavaScript object |
| 420 |
*/ |
| 421 |
function wpas_get_javascript_object() { |
| 422 |
|
| 423 |
global $post; |
| 424 |
|
| 425 |
if ( ! isset( $post ) || ! is_object( $post ) || ! is_a( $post, 'WP_Post' ) ) { |
| 426 |
return array(); |
| 427 |
} |
| 428 |
|
| 429 |
$upload_max_files = (int) wpas_get_option( 'attachments_max', 2 ); |
| 430 |
$upload_max_size = (int) wpas_get_option( 'filesize_max' ); |
| 431 |
|
| 432 |
// Editors translations |
| 433 |
if ( in_array( $post->ID, wpas_get_submission_pages() ) ) { |
| 434 |
$empty_editor = _x( "You can't submit an empty ticket", 'JavaScript validation error message', 'awesome-support' ); |
| 435 |
} else { |
| 436 |
$empty_editor = _x( "You can't submit an empty reply", 'JavaScript validation error message', 'awesome-support' ); |
| 437 |
} |
| 438 |
|
| 439 |
// translators: %d is the maximum number of files. |
| 440 |
$fileUploadMaxError = sprintf( __('You can only upload a maximum of %d files', 'awesome-support' ), $upload_max_files ); |
| 441 |
|
| 442 |
// translators: %d is the maximum size of files. |
| 443 |
$x_content = __( 'The maximum file size allowed for one file is %d MB', 'awesome-support' ); |
| 444 |
|
| 445 |
$object = array( |
| 446 |
'ajaxurl' => admin_url( 'admin-ajax.php' ), |
| 447 |
'emailCheck' => true === boolval( wpas_get_option( 'enable_mail_check', false ) ) ? 'true' : 'false', |
| 448 |
'useAutolinker' => true === boolval( wpas_get_option( 'use_autolinker', true ) ) ? 'true' : 'false', |
| 449 |
'fileUploadMax' => $upload_max_files, |
| 450 |
'fileUploadSize' => $upload_max_size * 1048576, // We base our calculation on binary prefixes |
| 451 |
'fileUploadMaxError' => $fileUploadMaxError, |
| 452 |
'fileUploadMaxSizeError' => array( |
| 453 |
__( 'The following file(s) are too big to be uploaded:', 'awesome-support' ), |
| 454 |
sprintf( $x_content, $upload_max_size ) |
| 455 |
), |
| 456 |
'translations' => array( |
| 457 |
'emptyEditor' => $empty_editor, |
| 458 |
'onSubmit' => _x( 'Submitting...', 'ticket submission button text while submitting', 'awesome-support' ), |
| 459 |
), |
| 460 |
'front_replies_nonce' => wp_create_nonce( 'wpas_loads_replies' ), |
| 461 |
'front_delete_att_nonce' => wp_create_nonce( 'wpas-delete-attachs') |
| 462 |
); |
| 463 |
|
| 464 |
if ( 'ticket' === $post->post_type ) { |
| 465 |
$object['ticket_id'] = $post->ID; |
| 466 |
} |
| 467 |
|
| 468 |
return $object; |
| 469 |
|
| 470 |
} |
| 471 |
|
| 472 |
/** |
| 473 |
* Register bootstrap 4 theme theme stylesheets |
| 474 |
* |
| 475 |
* @since 4.1.0 |
| 476 |
* |
| 477 |
* @return void |
| 478 |
*/ |
| 479 |
function wpas_register_bs4_theme_styles() { |
| 480 |
$bs4_theme = wpas_get_option('bs4_theme', 'default') ; |
| 481 |
switch ( $bs4_theme ) { |
| 482 |
|
| 483 |
case 'default': |
| 484 |
wp_register_style( 'wpas-bootstrap-4', WPAS_URL . 'assets/public/vendor/bootstrap/4.0.0/css/bootstrap.min.css', array(), '4.0.0' ); |
| 485 |
break ; |
| 486 |
|
| 487 |
case 'awesome': |
| 488 |
wp_register_style( 'wpas-bootstrap-4', WPAS_URL . 'assets/admin/css/vendor/bootstrap4themes/awesome-support/' . $bs4_theme . '/bootstrap.min.css', array(), WPAS_VERSION ); |
| 489 |
break ; |
| 490 |
|
| 491 |
case 'custom': |
| 492 |
wp_register_style( 'wpas-bootstrap-4', WPAS_URL . 'assets/admin/css/vendor/bootstrap4themes/custom/style.css', array(), WPAS_VERSION ); |
| 493 |
break ; |
| 494 |
|
| 495 |
default: |
| 496 |
wp_register_style( 'wpas-bootstrap-4', WPAS_URL . 'assets/admin/css/vendor/bootstrap4themes/bootswatch/' . $bs4_theme . '/bootstrap.min.css', array(), WPAS_VERSION ); |
| 497 |
break ; |
| 498 |
} |
| 499 |
} |