Skip to content

Commit

Permalink
Use a dedicated assets class for connection assets
Browse files Browse the repository at this point in the history
  • Loading branch information
manzoorwanijk committed Jul 17, 2024
1 parent d26a3cd commit 636ef04
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 24 deletions.
43 changes: 43 additions & 0 deletions projects/packages/connection/src/class-connection-assets.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
/**
* Connection_Assets.
*
* @package automattic/jetpack-connection
*/

namespace Automattic\Jetpack\Connection;

use Automattic\Jetpack\Assets;

/**
* Connection_Assets class.
*/
class Connection_Assets {

/**
* Initialize the class.
*/
public static function configure() {
add_action( 'wp_loaded', array( __CLASS__, 'register_assets' ) );
}

/**
* Register assets.
*/
public static function register_assets() {
if ( ! wp_script_is( 'jetpack-connection', 'registered' ) ) {

Assets::register_script(
'jetpack-connection',
'../dist/jetpack-connection.js',
__FILE__,
array(
'in_footer' => true,
'textdomain' => 'jetpack-idc',
)
);

Initial_State::render_script( 'jetpack-connection' );
}
}
}
23 changes: 0 additions & 23 deletions projects/packages/connection/src/class-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
namespace Automattic\Jetpack\Connection;

use Automattic\Jetpack\A8c_Mc_Stats;
use Automattic\Jetpack\Assets;
use Automattic\Jetpack\Constants;
use Automattic\Jetpack\Heartbeat;
use Automattic\Jetpack\Partner;
Expand Down Expand Up @@ -156,28 +155,6 @@ public static function configure() {

// Initial Partner management.
Partner::init();

add_action( 'init', array( __CLASS__, 'register_assets' ) );
}

/**
* Register assets.
*/
public static function register_assets() {
if ( ! wp_script_is( 'jetpack-connection', 'registered' ) ) {

Assets::register_script(
'jetpack-connection',
'../dist/jetpack-connection.js',
__FILE__,
array(
'in_footer' => true,
'textdomain' => 'jetpack-idc',
)
);

Initial_State::render_script( 'jetpack-connection' );
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion projects/packages/publicize/src/class-publicize-assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Publicize_Assets {
* Initialize the class.
*/
public static function configure() {
add_action( 'init', array( __CLASS__, 'register_assets' ) );
add_action( 'wp_loaded', array( __CLASS__, 'register_assets' ) );
}

/**
Expand Down
1 change: 1 addition & 0 deletions projects/plugins/jetpack/class.jetpack.php
Original file line number Diff line number Diff line change
Expand Up @@ -911,6 +911,7 @@ public function configure() {

// Assets should be registered regardless of connection status.
\Automattic\Jetpack\Publicize\Publicize_Assets::configure();
\Automattic\Jetpack\Connection\Connection_Assets::configure();

$modules = new Automattic\Jetpack\Modules();
if ( $modules->is_active( 'publicize' ) && $this->connection_manager->has_connected_user() ) {
Expand Down
1 change: 1 addition & 0 deletions projects/plugins/social/src/class-jetpack-social.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ function () {

// Assets should be registered regardless of connection status.
\Automattic\Jetpack\Publicize\Publicize_Assets::configure();
\Automattic\Jetpack\Connection\Connection_Assets::configure();

if ( ! $this->is_connected() ) {
return;
Expand Down

0 comments on commit 636ef04

Please sign in to comment.