Skip to content

Commit

Permalink
Merge pull request #60 from newfold-labs/PRESS4-498
Browse files Browse the repository at this point in the history
Press4 498
  • Loading branch information
circlecube authored Mar 18, 2024
2 parents f12eb13 + 31ec621 commit b0b5be1
Showing 1 changed file with 62 additions and 7 deletions.
69 changes: 62 additions & 7 deletions includes/Listeners/Jetpack.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,29 @@

namespace NewfoldLabs\WP\Module\Data\Listeners;

use function NewfoldLabs\WP\ModuleLoader\container;

/**
* Monitors Jetpack events
*/
class Jetpack extends Listener {

/**
* Brand code constants
*
* @var brand_code
*/
private $brand_code = array(
'bluehost' => '86241',
'hostgator' => '57686',
'web' => '86239',
'crazy-domains' => '57687',
'hostgator-india' => '57686',
'bluehost-india' => '86241',
'hostgator-latam' => '57686',
'default' => '86240',
);

/**
* Register the hooks for the listener
*
Expand All @@ -19,7 +37,7 @@ public function register_hooks() {
// Module enabled/disabled
add_action( 'jetpack_pre_activate_module', array( $this, 'module_enabled' ) );
add_action( 'jetpack_pre_deactivate_module', array( $this, 'module_disabled' ) );

add_action( 'activated_plugin', array( $this, 'detect_plugin_activation' ), 10, 1 );
// Publicize
add_action( 'publicize_save_meta', array( $this, 'publicize' ), 10, 4 );
}
Expand All @@ -29,15 +47,15 @@ public function register_hooks() {
*
* @param integer $id Jetpack Site ID
* @param string $secret Jetpack blog token
* @param integer|boolan $public Whether the site is public
* @param integer|boolan $is_public Whether the site is public
* @return void
*/
public function connected( $id, $secret, $public ) {
public function connected( $id, $secret, $is_public ) {
$this->push(
'jetpack_connected',
array(
'id' => $id,
'public' => $public,
'public' => $is_public,
)
);
}
Expand All @@ -49,7 +67,13 @@ public function connected( $id, $secret, $public ) {
* @return void
*/
public function module_enabled( $module ) {
$this->push( 'jetpack_module_enabled', array( 'label_key' => 'module', 'module' => $module ) );
$this->push(
'jetpack_module_enabled',
array(
'label_key' => 'module',
'module' => $module,
)
);
}

/**
Expand All @@ -59,7 +83,13 @@ public function module_enabled( $module ) {
* @return void
*/
public function module_disabled( $module ) {
$this->push( 'jetpack_module_disabled', array( 'label_key' => 'module', 'module' => $module ) );
$this->push(
'jetpack_module_disabled',
array(
'label_key' => 'module',
'module' => $module,
)
);
}

/**
Expand All @@ -76,6 +106,31 @@ public function publicize( $submit_post, $post_id, $service_name, $connection )
if ( ! $submit_post ) {
return;
}
$this->push( 'jetpack_publicized', array( 'label_key' => 'service', 'service' => $service_name ) );
$this->push(
'jetpack_publicized',
array(
'label_key' => 'service',
'service' => $service_name,
)
);
}

/**
* Post publicized
*
* @param bool $plugin Plugin information
* @return void
*/
public function detect_plugin_activation( $plugin ) {
$container = container();
if ( 'jetpack/jetpack.php' === $plugin ) {
$brand = $container->plugin()->brand;
if ( empty( $brand ) || ! array_key_exists( $brand, $this->brand_code ) ) {
$brand = 'default';
}
$jetpack_affiliate_code = get_option( 'jetpack_affiliate_code' );
! $jetpack_affiliate_code &&
update_option( 'jetpack_affiliate_code', $this->brand_code[ $brand ] );
}
}
}

0 comments on commit b0b5be1

Please sign in to comment.