Skip to content

Commit

Permalink
cs fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
diDroid committed Mar 12, 2024
1 parent ab4a24c commit 9c81138
Showing 1 changed file with 104 additions and 85 deletions.
189 changes: 104 additions & 85 deletions includes/Listeners/Jetpack.php
Original file line number Diff line number Diff line change
@@ -1,101 +1,120 @@
<?php

namespace NewfoldLabs\WP\Module\Data\Listeners;

use function NewfoldLabs\WP\ModuleLoader\container;

/**
* Monitors Jetpack events
*/
class Jetpack extends Listener
{
private $brandCode = array(
'bluehost' => '86241',
'hostgator' => '57686',
'hostgator-india' => '57686',
'bluehost-india' => '86241',
'hostgator-latam' => '57686',
'default' => '86240'
);
class Jetpack extends Listener {

private $brandCode = array(
'bluehost' => '86241',
'hostgator' => '57686',
'hostgator-india' => '57686',
'bluehost-india' => '86241',
'hostgator-latam' => '57686',
'default' => '86240',
);

/**
* Register the hooks for the listener
*
* @return void
*/
public function register_hooks() {
// Connected
add_action( 'jetpack_site_registered', array( $this, 'connected' ), 10, 3 );
/**
* Register the hooks for the listener
*
* @return void
*/
public function register_hooks() {
// Connected
add_action( 'jetpack_site_registered', array( $this, 'connected' ), 10, 3 );

// 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 );
}
// 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 );
}

/**
* Jetpack connected
*
* @param integer $id Jetpack Site ID
* @param string $secret Jetpack blog token
* @param integer|boolan $public Whether the site is public
* @return void
*/
public function connected( $id, $secret, $public ) {
$this->push(
'jetpack_connected',
array(
'id' => $id,
'public' => $public,
)
);
}
/**
* Jetpack connected
*
* @param integer $id Jetpack Site ID
* @param string $secret Jetpack blog token
* @param integer|boolan $public Whether the site is public
* @return void
*/
public function connected( $id, $secret, $public ) {
$this->push(
'jetpack_connected',
array(
'id' => $id,
'public' => $public,
)
);
}

/**
* Jetpack module enabled
*
* @param string $module Name of the module
* @return void
*/
public function module_enabled( $module ) {
$this->push( 'jetpack_module_enabled', array( 'label_key' => 'module', 'module' => $module ) );
}
/**
* Jetpack module enabled
*
* @param string $module Name of the module
* @return void
*/
public function module_enabled( $module ) {
$this->push(
'jetpack_module_enabled',
array(
'label_key' => 'module',
'module' => $module,
)
);
}

/**
* Jetpack module disabled
*
* @param string $module Name of the module
* @return void
*/
public function module_disabled( $module ) {
$this->push( 'jetpack_module_disabled', array( 'label_key' => 'module', 'module' => $module ) );
}
/**
* Jetpack module disabled
*
* @param string $module Name of the module
* @return void
*/
public function module_disabled( $module ) {
$this->push(
'jetpack_module_disabled',
array(
'label_key' => 'module',
'module' => $module,
)
);
}

/**
* Post publicized
*
* @param bool $submit_post Whether to submit the post
* @param integer $post_id ID of the post being publicized
* @param string $service_name Service name
* @param array $connection Array of connection details
* @return void
*/
public function publicize( $submit_post, $post_id, $service_name, $connection ) {
// Bail if it's not being publicized
if ( ! $submit_post ) {
return;
}
$this->push( 'jetpack_publicized', array( 'label_key' => 'service', 'service' => $service_name ) );
}
/**
* Post publicized
*
* @param bool $submit_post Whether to submit the post
* @param integer $post_id ID of the post being publicized
* @param string $service_name Service name
* @param array $connection Array of connection details
* @return void
*/
public function publicize( $submit_post, $post_id, $service_name, $connection ) {
// Bail if it's not being publicized
if ( ! $submit_post ) {
return;
}
$this->push(
'jetpack_publicized',
array(
'label_key' => 'service',
'service' => $service_name,
)
);
}

public function detect_plugin_activation( $plugin ) {
$container = container();
if( $plugin == "jetpack/jetpack.php" ){
$jetpack_affiliate_code = get_option("jetpack_affiliate_code");
!$jetpack_affiliate_code && $this->brandCode[$container->plugin()->brand]
? update_option("jetpack_affiliate_code",$this->brandCode[$container->plugin()->brand])
: update_option("jetpack_affiliate_code",$this->brandCode['default']) ;
}
}
public function detect_plugin_activation( $plugin ) {
$container = container();
if ( $plugin == 'jetpack/jetpack.php' ) {
$jetpack_affiliate_code = get_option( 'jetpack_affiliate_code' );
! $jetpack_affiliate_code && $this->brandCode[ $container->plugin()->brand ]
? update_option( 'jetpack_affiliate_code', $this->brandCode[ $container->plugin()->brand ] )
: update_option( 'jetpack_affiliate_code', $this->brandCode['default'] );
}
}
}

0 comments on commit 9c81138

Please sign in to comment.