| 1 |
<?php |
| 2 |
defined( 'ABSPATH' ) or die( 'Cheatin\' uh?' ); |
| 3 |
|
| 4 |
/** |
| 5 |
* Add some CSS on the whole administration |
| 6 |
* |
| 7 |
* @since 1.0 |
| 8 |
*/ |
| 9 |
add_action( 'admin_print_styles', '_imagify_admin_print_styles' ); |
| 10 |
function _imagify_admin_print_styles() { |
| 11 |
global $pagenow; |
| 12 |
$current_screen = get_current_screen(); |
| 13 |
$css_ext = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '.css' : '.min.css'; |
| 14 |
$js_ext = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '.js' : '.min.js'; |
| 15 |
|
| 16 |
wp_register_style( |
| 17 |
'imagify-css-admin', |
| 18 |
IMAGIFY_ASSETS_CSS_URL . 'admin' . $css_ext, |
| 19 |
array(), |
| 20 |
IMAGIFY_VERSION |
| 21 |
); |
| 22 |
|
| 23 |
wp_register_style( |
| 24 |
'imagify-css-sweetalert', |
| 25 |
IMAGIFY_ASSETS_CSS_URL . 'sweetalert' . $css_ext, |
| 26 |
array(), |
| 27 |
IMAGIFY_VERSION |
| 28 |
); |
| 29 |
|
| 30 |
wp_register_style( |
| 31 |
'imagify-css-twentytwenty', |
| 32 |
IMAGIFY_ASSETS_CSS_URL . 'twentytwenty' . $css_ext, |
| 33 |
array(), |
| 34 |
IMAGIFY_VERSION |
| 35 |
); |
| 36 |
|
| 37 |
wp_register_script( |
| 38 |
'imagify-js-async', |
| 39 |
IMAGIFY_ASSETS_JS_URL . 'imagify.min.js', |
| 40 |
array(), |
| 41 |
IMAGIFY_VERSION, |
| 42 |
true |
| 43 |
); |
| 44 |
|
| 45 |
wp_register_script( |
| 46 |
'imagify-js-admin', |
| 47 |
IMAGIFY_ASSETS_JS_URL . 'admin' . $js_ext, |
| 48 |
array(), |
| 49 |
IMAGIFY_VERSION, |
| 50 |
true |
| 51 |
); |
| 52 |
|
| 53 |
wp_register_script( |
| 54 |
'imagify-js-options', |
| 55 |
IMAGIFY_ASSETS_JS_URL . 'options' . $js_ext, |
| 56 |
array(), |
| 57 |
IMAGIFY_VERSION, |
| 58 |
true |
| 59 |
); |
| 60 |
|
| 61 |
wp_register_script( |
| 62 |
'imagify-js-upload', |
| 63 |
IMAGIFY_ASSETS_JS_URL . 'upload' . $js_ext, |
| 64 |
array( 'jquery' ), |
| 65 |
IMAGIFY_VERSION, |
| 66 |
true |
| 67 |
); |
| 68 |
|
| 69 |
wp_register_script( |
| 70 |
'imagify-js-sweetalert', |
| 71 |
IMAGIFY_ASSETS_JS_URL . 'sweetalert.min.js', |
| 72 |
array( 'jquery' ), |
| 73 |
IMAGIFY_VERSION, |
| 74 |
true |
| 75 |
); |
| 76 |
|
| 77 |
wp_register_script( |
| 78 |
'imagify-js-chart', |
| 79 |
IMAGIFY_ASSETS_JS_URL . 'chart' . $js_ext, |
| 80 |
array(), |
| 81 |
IMAGIFY_VERSION, |
| 82 |
true |
| 83 |
); |
| 84 |
|
| 85 |
wp_register_script( |
| 86 |
'imagify-js-bulk', |
| 87 |
IMAGIFY_ASSETS_JS_URL . 'bulk' . $js_ext, |
| 88 |
array( 'jquery', 'imagify-js-chart' ), |
| 89 |
IMAGIFY_VERSION, |
| 90 |
true |
| 91 |
); |
| 92 |
|
| 93 |
wp_register_script( |
| 94 |
'imagify-js-twentytwenty', |
| 95 |
IMAGIFY_ASSETS_JS_URL . 'jquery.twentytwenty' . $js_ext, |
| 96 |
array( 'jquery', 'imagify-js-event-move', 'imagify-js-chart' ), |
| 97 |
IMAGIFY_VERSION, |
| 98 |
true |
| 99 |
); |
| 100 |
wp_register_script( |
| 101 |
'imagify-js-event-move', |
| 102 |
IMAGIFY_ASSETS_JS_URL . 'jquery.event.move' . $js_ext, |
| 103 |
array( 'jquery' ), |
| 104 |
IMAGIFY_VERSION, |
| 105 |
true |
| 106 |
); |
| 107 |
|
| 108 |
/* |
| 109 |
* Styles loaded in the whole admnistration |
| 110 |
*/ |
| 111 |
wp_enqueue_style( 'imagify-css-admin' ); |
| 112 |
wp_enqueue_style( 'imagify-css-sweetalert' ); |
| 113 |
|
| 114 |
/* |
| 115 |
* Scripts loaded in the whole admnistration |
| 116 |
*/ |
| 117 |
wp_enqueue_script( 'imagify-js-sweetalert' ); |
| 118 |
wp_enqueue_script( 'imagify-js-admin' ); |
| 119 |
|
| 120 |
$admin_data = get_imagify_localize_script_translations( 'admin' ); |
| 121 |
wp_localize_script( 'imagify-js-admin', 'imagifyAdmin', $admin_data ); |
| 122 |
wp_enqueue_script( 'imagify-js-admin' ); |
| 123 |
|
| 124 |
/* |
| 125 |
* Scripts loaded in /wp-admin/options-general.php?page=imagify |
| 126 |
*/ |
| 127 |
if ( isset( $current_screen ) && ( 'settings_page_imagify' === $current_screen->base || 'settings_page_imagify-network' === $current_screen->base ) ) { |
| 128 |
wp_enqueue_script( 'imagify-js-chart' ); |
| 129 |
wp_enqueue_script( 'imagify-js-event-move' ); |
| 130 |
wp_enqueue_script( 'imagify-js-twentytwenty' ); |
| 131 |
wp_enqueue_script( 'imagify-js-options' ); |
| 132 |
wp_enqueue_style( 'imagify-css-twentytwenty' ); |
| 133 |
|
| 134 |
$options_data = get_imagify_localize_script_translations( 'options' ); |
| 135 |
wp_localize_script( 'imagify-js-options', 'imagifyOptions', $options_data ); |
| 136 |
} |
| 137 |
|
| 138 |
/** |
| 139 |
* Scripts loaded in /wp-admin/upload.php and post.php |
| 140 |
*/ |
| 141 |
if ( isset( $current_screen ) && ( 'upload' === $current_screen->base || 'post' === $current_screen->base ) ) { |
| 142 |
$upload_data = get_imagify_localize_script_translations( 'upload' ); |
| 143 |
wp_localize_script( 'imagify-js-upload', 'imagifyUpload', $upload_data ); |
| 144 |
wp_enqueue_script( 'imagify-js-chart' ); |
| 145 |
wp_enqueue_script( 'imagify-js-upload' ); |
| 146 |
} |
| 147 |
|
| 148 |
/** |
| 149 |
* Scripts loaded in: |
| 150 |
* /wp-admin/post.php (for attachment post type) |
| 151 |
* /wp-admin/upload.php (for attachments list) |
| 152 |
* |
| 153 |
*/ |
| 154 |
if ( isset( $current_screen ) && ( ('post' === $current_screen->base && 'attachment' === $current_screen->post_type ) || 'upload' === $current_screen->base ) ) { |
| 155 |
wp_localize_script( 'imagify-js-twentytwenty', 'imagifyTTT', get_imagify_localize_script_translations( 'twentytwenty' ) ); |
| 156 |
wp_enqueue_script( 'imagify-js-chart' ); |
| 157 |
wp_enqueue_script( 'imagify-js-event-move' ); |
| 158 |
wp_enqueue_script( 'imagify-js-twentytwenty' ); |
| 159 |
wp_enqueue_style( 'imagify-css-twentytwenty' ); |
| 160 |
} |
| 161 |
|
| 162 |
/** |
| 163 |
* Scripts loaded in /wp-admin/upload.php?page=imagify-bulk-optimization |
| 164 |
*/ |
| 165 |
if ( isset( $current_screen ) && 'media_page_imagify-bulk-optimization' === $current_screen->base ) { |
| 166 |
wp_enqueue_script( 'heartbeat' ); |
| 167 |
|
| 168 |
$bulk_data = get_imagify_localize_script_translations( 'bulk' ); |
| 169 |
$bulk_data['heartbeat_id'] = 'update_bulk_data'; |
| 170 |
$bulk_data['ajax_action'] = 'imagify_get_unoptimized_attachment_ids'; |
| 171 |
$bulk_data['ajax_context'] = 'wp'; |
| 172 |
|
| 173 |
wp_localize_script( 'imagify-js-bulk', 'imagifyBulk', $bulk_data ); |
| 174 |
wp_enqueue_script( 'imagify-js-chart' ); |
| 175 |
wp_enqueue_script( 'imagify-js-async' ); |
| 176 |
wp_enqueue_script( 'imagify-js-bulk' ); |
| 177 |
} |
| 178 |
} |
| 179 |
|
| 180 |
/** |
| 181 |
* Add Intercom on Options page an Bulk Optimization |
| 182 |
* |
| 183 |
* @since 1.0 |
| 184 |
*/ |
| 185 |
add_action( 'admin_footer-media_page_imagify-bulk-optimization', '_imagify_admin_print_intercom' ); |
| 186 |
add_action( 'admin_footer-settings_page_imagify', '_imagify_admin_print_intercom' ); |
| 187 |
function _imagify_admin_print_intercom() { |
| 188 |
$user = get_imagify_user(); |
| 189 |
|
| 190 |
if ( ! imagify_valid_key() || empty( $user->is_intercom ) ) { |
| 191 |
return; |
| 192 |
} |
| 193 |
?> |
| 194 |
<script> |
| 195 |
window.intercomSettings = { |
| 196 |
app_id: "cd6nxj3z", |
| 197 |
user_id: <?php echo (int) $user->id; ?>, |
| 198 |
}; |
| 199 |
</script> |
| 200 |
<script>(function(){var w=window;var ic=w.Intercom;if(typeof ic==="function"){ic('reattach_activator');ic('update',intercomSettings);}else{var d=document;var i=function(){i.c(arguments)};i.q=[];i.c=function(args){i.q.push(args)};w.Intercom=i;function l(){var s=d.createElement('script');s.type='text/javascript';s.async=true;s.src='https://widget.intercom.io/widget/cd6nxj3z';var x=d.getElementsByTagName('script')[0];x.parentNode.insertBefore(s,x);}if(w.attachEvent){w.attachEvent('onload',l);}else{w.addEventListener('load',l,false);}}})()</script> |
| 201 |
<?php |
| 202 |
} |
| 203 |
|
| 204 |
/** |
| 205 |
* Remove Yoast SEO bugged script |
| 206 |
* |
| 207 |
* @since 1.4.1 |
| 208 |
*/ |
| 209 |
add_action( 'wp_print_scripts', '_imagify_dequeue_yoastseo_script' ); |
| 210 |
function _imagify_dequeue_yoastseo_script() { |
| 211 |
global $pagenow; |
| 212 |
$current_screen = get_current_screen(); |
| 213 |
|
| 214 |
if ( isset( $current_screen ) && 'post' === $current_screen->base && 'attachment' === $current_screen->post_type ) { |
| 215 |
wp_dequeue_script( 'yoast-seo' ); |
| 216 |
wp_deregister_script( 'yoast-seo' ); |
| 217 |
} |
| 218 |
} |