Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 21
0.00% covered (danger)
0.00%
0 / 1
CRAP
n/a
0 / 0
wpcom_enqueue_documentation_links_assets
0.00% covered (danger)
0.00%
0 / 20
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2/**
3 * WPCOM overrides to Core documentation links.
4 *
5 * @package automattic/jetpack-mu-wpcom
6 */
7
8use Automattic\Jetpack\Jetpack_Mu_Wpcom;
9
10/**
11 * Enqueue assets
12 */
13function wpcom_enqueue_documentation_links_assets() {
14    $asset_file = include Jetpack_Mu_Wpcom::BASE_DIR . 'build/wpcom-documentation-links/wpcom-documentation-links.asset.php';
15
16    wp_enqueue_script(
17        'wpcom-documentation-links-script',
18        plugins_url( 'build/wpcom-documentation-links/wpcom-documentation-links.js', Jetpack_Mu_Wpcom::BASE_FILE ),
19        $asset_file['dependencies'] ?? array(),
20        $asset_file['version'] ?? filemtime( Jetpack_Mu_Wpcom::BASE_DIR . 'build/wpcom-documentation-links/wpcom-documentation-links.js' ),
21        true
22    );
23
24    wp_enqueue_style(
25        'wpcom-documentation-links-styles',
26        plugins_url( 'build/wpcom-documentation-links/wpcom-documentation-links.css', Jetpack_Mu_Wpcom::BASE_FILE ),
27        array(),
28        filemtime( Jetpack_Mu_Wpcom::BASE_DIR . 'build/wpcom-documentation-links/wpcom-documentation-links.css' )
29    );
30
31    // This is a way to get the data from the customize-controls script and change the link to the wpcom support page.
32    global $wp_scripts;
33    $data = $wp_scripts->get_data( 'customize-controls', 'data' );
34
35    if ( $data ) {
36        $data = str_replace( 'https:\\/\\/wordpress.org\\/documentation\\/article\\/site-editor\\/\\', 'https:\\/\\/wordpress.com\\/support\\/site-editor\\/\\', $data );
37        $wp_scripts->registered['customize-controls']->extra['data'] = $data;
38    }
39
40    wp_set_script_translations( 'wpcom-documentation-links-script', 'jetpack-mu-wpcom' );
41}
42
43add_action( 'enqueue_block_editor_assets', 'wpcom_enqueue_documentation_links_assets', 100 );