| 1 |
<?php |
| 2 |
/** |
| 3 |
* Connection_Assets. |
| 4 |
* |
| 5 |
* @package automattic/jetpack-connection |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace Automattic\Jetpack\Connection; |
| 9 |
|
| 10 |
use Automattic\Jetpack\Assets; |
| 11 |
|
| 12 |
/** |
| 13 |
* Connection_Assets class. |
| 14 |
*/ |
| 15 |
class Connection_Assets { |
| 16 |
|
| 17 |
/** |
| 18 |
* Initialize the class. |
| 19 |
*/ |
| 20 |
public static function configure() { |
| 21 |
add_action( 'wp_loaded', array( __CLASS__, 'register_assets' ) ); |
| 22 |
|
| 23 |
add_filter( 'jetpack_admin_js_script_data', array( Initial_State::class, 'set_connection_script_data' ), 10, 1 ); |
| 24 |
// Priority 20: set_connection_script_data() replaces the whole `connection` key at 10. |
| 25 |
add_filter( 'jetpack_admin_js_script_data', array( __CLASS__, 'add_script_data' ), 20 ); |
| 26 |
} |
| 27 |
|
| 28 |
/** |
| 29 |
* Add the package's image base URL to the admin script data. |
| 30 |
* |
| 31 |
* Other plugins' bundles request the disconnect dialog's images from this copy, so never rename one. |
| 32 |
* |
| 33 |
* @since 9.3.0 |
| 34 |
* |
| 35 |
* @param array $data Script data. |
| 36 |
* @return array |
| 37 |
*/ |
| 38 |
public static function add_script_data( $data ) { |
| 39 |
$data['connection']['assetsUrl'] = trailingslashit( plugins_url( 'assets/images/', __DIR__ ) ); |
| 40 |
|
| 41 |
return $data; |
| 42 |
} |
| 43 |
|
| 44 |
/** |
| 45 |
* Register assets. |
| 46 |
* |
| 47 |
* NOTICE: Please think twice before including Connection scripts in the frontend. |
| 48 |
* Those scripts are intended to be used in WP admin area. |
| 49 |
*/ |
| 50 |
public static function register_assets() { |
| 51 |
|
| 52 |
Assets::register_script( |
| 53 |
'jetpack-connection', |
| 54 |
'../dist/jetpack-connection.js', |
| 55 |
__FILE__, |
| 56 |
array( |
| 57 |
'in_footer' => true, |
| 58 |
'textdomain' => 'jetpack-connection', |
| 59 |
) |
| 60 |
); |
| 61 |
} |
| 62 |
} |
| 63 |
|