Commit inicial - WordPress Análisis de Precios Unitarios

- WordPress core y plugins
- Tema Twenty Twenty-Four configurado
- Plugin allow-unfiltered-html.php simplificado
- .gitignore configurado para excluir wp-config.php y uploads

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
root
2025-11-03 21:04:30 -06:00
commit a22573bf0b
24068 changed files with 4993111 additions and 0 deletions

View File

@@ -0,0 +1,241 @@
<?php
final class BWFAN_AFFWP_Change_Affiliate_Rate extends BWFAN_Action {
private static $ins = null;
protected function __construct() {
$this->action_name = __( 'Change Affiliate Rate', 'wp-marketing-automations-pro' );
$this->action_desc = __( 'This action changes the affiliate\'s referral rate', 'wp-marketing-automations-pro' );
$this->required_fields = array( 'affiliate_id', 'rate_type', 'rate' );
$this->support_v2 = true;
}
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
/**
* Localize data for html fields for the current action.
*/
public function admin_enqueue_assets() {
if ( BWFAN_Common::is_load_admin_assets( 'automation' ) ) {
$data = $this->get_view_data();
BWFAN_Core()->admin->set_actions_js_data( $this->get_class_slug(), 'rate_types_options', $data );
}
}
public function get_view_data() {
return affwp_get_affiliate_rate_types();
}
/**
* Show the html fields for the current action.
*/
public function get_view() {
?>
<script type="text/html" id="tmpl-action-<?php echo esc_html__( $this->get_slug() ); ?>">
<#
selected_rate_type = (_.has(data.actionSavedData, 'data') && _.has(data.actionSavedData.data, 'rate_type')) ? data.actionSavedData.data.rate_type : '';
rate = (_.has(data.actionSavedData, 'data') && _.has(data.actionSavedData.data, 'rate')) ? data.actionSavedData.data.rate : '';
#>
<div class="bwfan-<?php echo esc_html__( $this->get_slug() ); ?>">
<label for="" class="bwfan-label-title"><?php echo esc_html__( 'Rate Type', 'wp-marketing-automations-pro' ); ?></label>
<select required id="" class="bwfan-input-wrapper" name="bwfan[{{data.action_id}}][data][rate_type]">
<option value=""><?php echo esc_html__( 'Choose Type', 'wp-marketing-automations-pro' ); ?></option>
<#
if(_.has(data.actionFieldsOptions, 'rate_types_options') && _.isObject(data.actionFieldsOptions.rate_types_options) ) {
_.each( data.actionFieldsOptions.rate_types_options, function( value, key ){
selected = (key == selected_rate_type) ? 'selected' : '';
#>
<option value="{{key}}" {{selected}}>{{value}}</option>
<# })
}
#>
</select>
</div>
<div class="bwfan-<?php echo esc_html__( $this->get_slug() ); ?>">
<label for="" class="bwfan-label-title"><?php echo esc_html__( 'Rate', 'wp-marketing-automations-pro' ); ?></label>
<div class="bwfan-col-sm-12 bwfan-pl-0 bwfan-pr-0">
<input type="text" required class="bwfan-input-wrapper" placeholder="<?php echo esc_html__( 'Affiliate new rate', 'wp-marketing-automations-pro' ); ?>" name="bwfan[{{data.action_id}}][data][rate]" value="{{rate}}">
</div>
</div>
</script>
<?php
}
/**
* Make all the data which is required by the current action.
* This data will be used while executing the task of this action.
*
* @param $integration_object
* @param $task_meta
*
* @return array|void
*/
public function make_data( $integration_object, $task_meta ) {
$data_to_set = array();
$data_to_set['rate_type'] = $task_meta['data']['rate_type'];
$data_to_set['rate'] = $task_meta['data']['rate'];
$data_to_set['affiliate_id'] = $task_meta['global']['affiliate_id'];
$data_to_set['user_id'] = isset( $task_meta['global']['user_id'] ) ? $task_meta['global']['user_id'] : 0;
$data_to_set['email'] = isset( $task_meta['global']['email'] ) ? $task_meta['global']['email'] : '';
if ( empty( $data_to_set['affiliate_id'] ) && intval( $data_to_set['user_id'] ) > 0 ) {
$data_to_set['affiliate_id'] = affwp_get_affiliate_id( $data_to_set['user_id'] );
}
if ( empty( $data_to_set['affiliate_id'] ) && ! empty( $data_to_set['email'] ) ) {
/** @var WP_User $user */
$user = get_user_by( 'email', $data_to_set['email'] );
if ( $user instanceof WP_User ) {
$data_to_set['user_id'] = $user->ID;
$data_to_set['affiliate_id'] = affwp_get_affiliate_id( $user->ID );
}
}
return $data_to_set;
}
public function make_v2_data( $automation_data, $step_data ) {
$data_to_set = array();
$data_to_set['rate_type'] = $step_data['rate_type'];
$data_to_set['rate'] = $step_data['rate'];
$data_to_set['affiliate_id'] = isset( $automation_data['global']['affiliate_id'] ) ? $automation_data['global']['affiliate_id'] : 0;
$data_to_set['user_id'] = isset( $automation_data['global']['user_id'] ) ? $automation_data['global']['user_id'] : 0;
$data_to_set['email'] = isset( $automation_data['global']['email'] ) ? $automation_data['global']['email'] : '';
if ( empty( $data_to_set['affiliate_id'] ) && intval( $data_to_set['user_id'] ) > 0 ) {
$data_to_set['affiliate_id'] = affwp_get_affiliate_id( $data_to_set['user_id'] );
}
if ( empty( $data_to_set['affiliate_id'] ) && ! empty( $data_to_set['email'] ) ) {
/** @var WP_User $user */
$user = get_user_by( 'email', $data_to_set['email'] );
if ( $user instanceof WP_User ) {
$data_to_set['user_id'] = $user->ID;
$data_to_set['affiliate_id'] = affwp_get_affiliate_id( $user->ID );
}
}
return $data_to_set;
}
/**
* Execute the current action.
* Return 3 for successful execution , 4 for permanent failure.
*
* @param $action_data
*
* @return array
*/
public function execute_action( $action_data ) {
$this->set_data( $action_data['processed_data'] );
$result = $this->process();
if ( true === $result ) {
return array(
'status' => 3,
);
}
return array(
'status' => 4,
'message' => __( 'Affiliate rate could not be changed', 'wp-marketing-automations-pro' ),
);
}
/**
* Process and do the actual processing for the current action.
* This function is present in every action class.
*/
public function process() {
$is_required_fields_present = $this->check_fields( $this->data, $this->required_fields );
if ( false === $is_required_fields_present ) {
return $this->show_fields_error();
}
if ( empty( $this->data['affiliate_id'] ) ) {
return false;
}
$affiliate = affwp_get_affiliate( $this->data['affiliate_id'] );
if ( empty( $affiliate ) ) {
return false;
}
affiliate_wp()->affiliates->update( $affiliate->ID, array(
'rate_type' => $this->data['rate_type'],
'rate' => $this->data['rate'],
), '', 'affiliate' );
return true;
}
public function process_v2() {
/** Perform Promotional checking */
$is_required_fields_present = $this->check_fields( $this->data, $this->required_fields );
if ( false === $is_required_fields_present ) {
return $this->skipped_response( __( 'Required fields missing.' ) );
}
if ( empty( $this->data['affiliate_id'] ) ) {
return $this->skipped_response( __( 'Affiliate not found.' ) );
}
$affiliate = affwp_get_affiliate( $this->data['affiliate_id'] );
if ( empty( $affiliate ) ) {
return $this->skipped_response( __( 'Affiliate not found.' ) );
}
affiliate_wp()->affiliates->update( $affiliate->ID, array(
'rate_type' => $this->data['rate_type'],
'rate' => $this->data['rate'],
), '', 'affiliate' );
return $this->success_message( __( 'Affiliate rate changed.' ) );
}
public function get_fields_schema() {
$rate_types = array_replace( [ '' => 'Select' ], $this->get_view_data() );
$rate_types = BWFAN_PRO_Common::prepared_field_options( $rate_types );
return [
[
'id' => 'rate_type',
'type' => 'wp_select',
'label' => __( 'Rate Type', 'wp-marketing-automations-pro' ),
'options' => $rate_types,
'placeholder' => __( 'Select Rate Type', 'wp-marketing-automations-pro' ),
'tip' => "",
"description" => "",
"required" => true,
"errorMsg" => __( "Rate type is required", 'wp-marketing-automations-pro' ),
],
[
'id' => 'rate',
'type' => 'text',
'label' => __( 'Rate', 'wp-marketing-automations-pro' ),
'placeholder' => __( 'Affiliate new rate', 'wp-marketing-automations-pro' ),
'tip' => "",
"description" => "",
"required" => true,
"errorMsg" => __( "Rate is required", 'wp-marketing-automations-pro' ),
]
];
}
public function get_desc_text( $data ) {
$data = json_decode( wp_json_encode( $data ), true );
if ( ! isset( $data['rate'] ) || empty( $data['rate'] ) ) {
return '';
}
$rates = $this->get_view_data();
return $data['rate'] . ' ' . $rates[ $data['rate_type'] ];
}
}
/**
* Register this action. Registering the action will make it eligible to see it on single automation screen in select action dropdown.
*/
return 'BWFAN_AFFWP_Change_Affiliate_Rate';

View File

@@ -0,0 +1,114 @@
<?php
final class BWFAN_AFFWP_Change_Affiliate_Status extends BWFAN_Action {
private static $ins = null;
protected function __construct() {
$this->action_name = __( 'Change Affiliate Status', 'wp-marketing-automations-pro' );
$this->action_desc = __( 'This action changes the affiliate\'s status', 'wp-marketing-automations-pro' );
$this->required_fields = array( 'affiliate_id', 'affiliate_status' );
$this->support_v1 = false;
$this->support_v2 = true;
}
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public function make_v2_data( $automation_data, $step_data ) {
$data_to_set = array();
$data_to_set['affiliate_status'] = $step_data['affiliate_status'];
$data_to_set['affiliate_id'] = isset( $automation_data['global']['affiliate_id'] ) ? $automation_data['global']['affiliate_id'] : 0;
$data_to_set['user_id'] = isset( $automation_data['global']['user_id'] ) ? $automation_data['global']['user_id'] : 0;
$data_to_set['email'] = isset( $automation_data['global']['email'] ) ? $automation_data['global']['email'] : '';
if ( empty( $data_to_set['affiliate_id'] ) && intval( $data_to_set['user_id'] ) > 0 ) {
$data_to_set['affiliate_id'] = affwp_get_affiliate_id( $data_to_set['user_id'] );
}
if ( empty( $data_to_set['affiliate_id'] ) && ! empty( $data_to_set['email'] ) ) {
/** @var WP_User $user */
$user = get_user_by( 'email', $data_to_set['email'] );
if ( $user instanceof WP_User ) {
$data_to_set['user_id'] = $user->ID;
$data_to_set['affiliate_id'] = affwp_get_affiliate_id( $user->ID );
}
}
return $data_to_set;
}
public function process_v2() {
/** Perform Promotional checking */
$is_required_fields_present = $this->check_fields( $this->data, $this->required_fields );
if ( false === $is_required_fields_present ) {
return $this->skipped_response( __( 'Required fields missing.' ) );
}
if ( empty( $this->data['affiliate_id'] ) ) {
return $this->skipped_response( __( 'Affiliate not found.' ) );
}
$affiliate = affwp_get_affiliate( $this->data['affiliate_id'] );
if ( empty( $affiliate ) ) {
return $this->skipped_response( __( 'Affiliate not found.' ) );
}
affiliate_wp()->affiliates->update( $affiliate->ID, array(
'status' => $this->data['affiliate_status'],
), '', 'affiliate' );
return $this->success_message( __( 'Affiliate rate changed.' ) );
}
public function get_fields_schema() {
$status = BWFAN_PRO_Common::prepared_field_options( $this->get_view_data() );
return [
[
'id' => 'affiliate_status',
'type' => 'wp_select',
'label' => __( 'Affiliate Status', 'wp-marketing-automations-pro' ),
'options' => $status,
'placeholder' => __( 'Select Status', 'wp-marketing-automations-pro' ),
'tip' => "",
"description" => "",
"required" => true,
],
];
}
public function get_view_data() {
return [
'active' => 'Active',
'inactive' => 'Inactive',
'pending' => 'Pending',
];
}
/** set default values */
public function get_default_values() {
return [
'affiliate_status' => 'active',
];
}
public function get_desc_text( $data ) {
$data = json_decode( wp_json_encode( $data ), true );
if ( ! isset( $data['affiliate_status'] ) || empty( $data['affiliate_status'] ) ) {
return '';
}
$status = $this->get_view_data();
return $status[ $data['affiliate_status'] ];
}
}
/**
* Register this action. Registering the action will make it eligible to see it on single automation screen in select action dropdown.
*/
return 'BWFAN_AFFWP_Change_Affiliate_Status';

View File

@@ -0,0 +1,183 @@
<?php
final class BWFAN_AFFWP_Change_Referral_Status extends BWFAN_Action {
private static $ins = null;
protected function __construct() {
$this->action_name = __( 'Change Referral Status', 'wp-marketing-automations-pro' );
$this->action_desc = __( 'This action changes affiliate\'s status', 'wp-marketing-automations-pro' );
$this->required_fields = array( 'referral_id', 'referral_status' );
// Excluded events which this action does not supports.
$this->included_events = array(
'affwp_makes_sale',
'affwp_referral_rejected',
'affwp_report',
);
$this->support_v2 = true;
}
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
/**
* Localize data for html fields for the current action.
*/
public function admin_enqueue_assets() {
if ( BWFAN_Common::is_load_admin_assets( 'automation' ) ) {
$data = $this->get_view_data();
BWFAN_Core()->admin->set_actions_js_data( $this->get_class_slug(), 'referral_status_options', $data );
}
}
public function get_view_data() {
return array(
'paid' => __( 'Paid', 'affiliate-wp' ),
'unpaid' => __( 'Unpaid', 'affiliate-wp' ),
'rejected' => __( 'Rejected', 'affiliate-wp' ),
'pending' => __( 'Pending', 'affiliate-wp' ),
);
}
/**
* Show the html fields for the current action.
*/
public function get_view() {
?>
<script type="text/html" id="tmpl-action-<?php echo esc_html__( $this->get_slug() ); ?>">
<#
selected_referral_status = (_.has(data.actionSavedData, 'data') && _.has(data.actionSavedData.data, 'referral_status')) ? data.actionSavedData.data.referral_status : '';
#>
<div class="bwfan-input-form clearfix">
<label for="" class="bwfan-label-title"><?php echo esc_html__( 'Status', 'woocommerce' ); ?></label>
<select required id="" class="bwfan-input-wrapper" name="bwfan[{{data.action_id}}][data][referral_status]">
<option value=""><?php echo esc_html__( 'Choose Status', 'wp-marketing-automations-pro' ); ?></option>
<#
if(_.has(data.actionFieldsOptions, 'referral_status_options') && _.isObject(data.actionFieldsOptions.referral_status_options) ) {
_.each( data.actionFieldsOptions.referral_status_options, function( value, key ){
selected = (key == selected_referral_status) ? 'selected' : '';
#>
<option value="{{key}}" {{selected}}>{{value}}</option>
<# })
}
#>
</select>
</div>
</script>
<?php
}
/**
* Make all the data which is required by the current action.
* This data will be used while executing the task of this action.
*
* @param $integration_object
* @param $task_meta
*
* @return array|void
*/
public function make_data( $integration_object, $task_meta ) {
$data_to_set = array();
$data_to_set['referral_status'] = $task_meta['data']['referral_status'];
$data_to_set['referral_id'] = $task_meta['global']['referral_id'];
return $data_to_set;
}
public function make_v2_data( $automation_data, $step_data ) {
$data_to_set = array();
$data_to_set['referral_status'] = $step_data['referral_status'];
$data_to_set['referral_id'] = $automation_data['global']['referral_id'];
return $data_to_set;
}
/**
* Execute the current action.
* Return 3 for successful execution , 4 for permanent failure.
*
* @param $action_data
*
* @return array
*/
public function execute_action( $action_data ) {
$this->set_data( $action_data['processed_data'] );
$result = $this->process();
if ( true === $result ) {
return array(
'status' => 3,
);
}
return array(
'status' => 4,
'message' => __( 'Referral status could not be changed', 'wp-marketing-automations-pro' ),
);
}
/**
* Process and do the actual processing for the current action.
* This function is present in every action class.
*/
public function process() {
$is_required_fields_present = $this->check_fields( $this->data, $this->required_fields );
if ( false === $is_required_fields_present ) {
return $this->show_fields_error();
}
return affwp_set_referral_status( $this->data['referral_id'], $this->data['referral_status'] );
}
public function process_v2() {
$result = affwp_set_referral_status( $this->data['referral_id'], $this->data['referral_status'] );
if ( ! empty( $result ) ) {
return $this->success_message( __( 'Affiliate status changed.' ) );
}
}
public function get_fields_schema() {
$rate_types = BWFAN_PRO_Common::prepared_field_options( $this->get_view_data() );
return [
[
'id' => 'referral_status',
'type' => 'wp_select',
'label' => __( 'Referral Status', 'wp-marketing-automations-pro' ),
'options' => $rate_types,
'placeholder' => __( 'Select Status', 'wp-marketing-automations-pro' ),
'tip' => "",
"description" => '',
"required" => true,
],
];
}
/** set default values */
public function get_default_values() {
return [
'referral_status' => 'paid',
];
}
public function get_desc_text( $data ) {
$data = json_decode( wp_json_encode( $data ), true );
if ( ! isset( $data['referral_status'] ) || empty( $data['referral_status'] ) ) {
return '';
}
$status = $this->get_view_data();
return $status[ $data['referral_status'] ];
}
}
/**
* Register this action. Registering the action will make it eligible to see it on single automation screen in select actions dropdown.
*/
return 'BWFAN_AFFWP_Change_Referral_Status';

View File

@@ -0,0 +1,2 @@
<?php
// Silence is golden.

View File

@@ -0,0 +1,34 @@
<?php
final class BWFAN_AFFWP_Integration extends BWFAN_Integration {
private static $instance = null;
/**
* BWFAN_AFFWP_Integration constructor.
*/
private function __construct() {
$this->action_dir = __DIR__;
$this->nice_name = __( 'AffiliateWP', 'wp-marketing-automations-pro' );
$this->group_name = __( 'Affiliate', 'wp-marketing-automations-pro' );
$this->group_slug = 'affiliate';
$this->priority = 75;
}
/**
* Ensures only one instance of the class is loaded or can be loaded.
*
* @return BWFAN_AFFWP_Integration|null
*/
public static function get_instance() {
if ( null === self::$instance ) {
self::$instance = new self();
}
return self::$instance;
}
}
if ( bwfan_is_affiliatewp_active() ) {
BWFAN_Load_Integrations::register( 'BWFAN_AFFWP_Integration' );
}

View File

@@ -0,0 +1,34 @@
<?php
class BWFAN_AFFWP_Source extends BWFAN_Source {
private static $instance = null;
public function __construct() {
$this->event_dir = __DIR__;
$this->nice_name = __( 'AffiliateWP', 'wp-marketing-automations-pro' );
$this->group_name = __( 'Affiliate', 'wp-marketing-automations-pro' );
$this->group_slug = 'affiliate';
$this->priority = 30;
}
/**
* Ensures only one instance of the class is loaded or can be loaded.
*
* @return BWFAN_AFFWP_Source|null
*/
public static function get_instance() {
if ( null === self::$instance ) {
self::$instance = new self();
}
return self::$instance;
}
}
/**
* Register this as a source.
*/
if ( bwfan_is_affiliatewp_active() ) {
BWFAN_Load_Sources::register( 'BWFAN_AFFWP_Source' );
}

View File

@@ -0,0 +1,750 @@
<?php
#[AllowDynamicProperties]
final class BWFAN_AFFWP_Affiliate_Report extends BWFAN_Event {
private static $instance = null;
public $affiliate_id = false;
public $referral_count = 0;
public $visits = 0;
public $commissions = 0;
public $from = false;
public $to = false;
public $user_id = 0;
private function __construct() {
$this->event_merge_tag_groups = array( 'aff_affiliate', 'aff_report', 'bwf_contact' );
$this->event_name = esc_html__( 'Affiliate Digests', 'wp-marketing-automations-pro' );
$this->event_desc = esc_html__( 'This event runs per affiliate and gives their report for the selected date range.', 'wp-marketing-automations-pro' );
$this->event_rule_groups = array(
'affiliatewp',
'affiliate_report',
'bwf_contact_segments',
'bwf_contact',
'bwf_contact_fields',
'bwf_contact_user',
'bwf_contact_wc',
'bwf_contact_geo',
'bwf_engagement',
'bwf_broadcast'
);
$this->optgroup_label = esc_html__( 'AffiliateWP', 'wp-marketing-automations-pro' );
$this->priority = 60;
$this->is_time_independent = true;
$this->customer_email_tag = '{{affwp_affiliate_email}}';
$this->v2 = true;
}
public static function get_instance() {
if ( null === self::$instance ) {
self::$instance = new self();
}
return self::$instance;
}
public function load_hooks() {
add_action( 'bwfan_send_affiliate_insights', array( $this, 'send_affiliate_insights' ), 10, 2 );
}
/**
* Localize data for html fields for the current event.
*/
public function admin_enqueue_assets() {
if ( BWFAN_Common::is_load_admin_assets( 'automation' ) ) {
$data = $this->get_view_data();
BWFAN_Core()->admin->set_events_js_data( $this->get_slug(), 'days_options', $data['days'] );
BWFAN_Core()->admin->set_events_js_data( $this->get_slug(), 'dates_options', $data['dates'] );
BWFAN_Core()->admin->set_events_js_data( $this->get_slug(), 'last_run', $data['last_run'] );
}
}
public function get_view_data() {
$days = [
'0' => __( 'Sunday', 'wp-marketing-automations-pro' ),
'1' => __( 'Monday', 'wp-marketing-automations-pro' ),
'2' => __( 'Tuesday', 'wp-marketing-automations-pro' ),
'3' => __( 'Wednesday', 'wp-marketing-automations-pro' ),
'4' => __( 'Thursday', 'wp-marketing-automations-pro' ),
'5' => __( 'Friday', 'wp-marketing-automations-pro' ),
'6' => __( 'Saturday', 'wp-marketing-automations-pro' ),
];
$dates = [];
for ( $i = 1; $i <= 28; $i ++ ) {
$dates[ $i ] = $i;
}
$dates['end_of_month'] = __( 'End Of Month', 'wp-marketing-automations-pro' );
$last_run = '';
if ( isset( $_GET['edit'] ) ) {
$last_run = BWFAN_Model_Automationmeta::get_meta( sanitize_text_field( $_GET['edit'] ), 'last_run' );
if ( false !== $last_run ) {
$last_run = date( get_option( 'date_format' ), strtotime( $last_run ) );
}
}
return [
'days' => $days,
'dates' => $dates,
'last_run' => $last_run,
];
}
/**
* Show the html fields for the current event.
*/
public function get_view( $db_eventmeta_saved_value ) {
?>
<script type="text/html" id="tmpl-event-<?php echo esc_html__( $this->get_slug() ); ?>">
<#
selected_day = (_.has(data, 'eventSavedData') &&_.has(data.eventSavedData, 'run_day')) ? data.eventSavedData.run_day : '';
selected_date = (_.has(data, 'eventSavedData') &&_.has(data.eventSavedData, 'run_date')) ? data.eventSavedData.run_date : '';
selected_run_type = (_.has(data, 'eventSavedData') &&_.has(data.eventSavedData, 'run_weekly_monthly')) ? data.eventSavedData.run_weekly_monthly : '';
selected_earning_weekly = (_.has(data, 'eventSavedData') &&_.has(data.eventSavedData, 'earning_weekly')) ? data.eventSavedData.earning_weekly : '';
selected_earning_monthly = (_.has(data, 'eventSavedData') &&_.has(data.eventSavedData, 'earning_monthly')) ? data.eventSavedData.earning_monthly : '';
if('' == selected_run_type){
selected_run_type = "weekly";
}
if('' == selected_earning_weekly){
selected_earning_weekly = "last_week";
}
if('' == selected_earning_monthly){
selected_earning_monthly = "last_month";
}
run_weekly = "weekly" === selected_run_type?'checked':'';
run_monthly = "monthly" === selected_run_type?'checked':'';
run_earning_weekly = "last_week" ===selected_earning_weekly?'checked':'';
run_earning_7_days = "last_7_days" ===selected_earning_weekly?'checked':'';
run_earning_monthly = "last_month" ===selected_earning_monthly?'checked':'';
run_earning_30_days = "last_30_days" ===selected_earning_monthly?'checked':'';
#>
<div class="bwfan-col-sm-12 bwfan-p-0 bwfan_mt15">
<label for="bwfan-run_weekly_monthly" class="bwfan-label-title"><?php echo esc_html__( 'Frequency', 'wp-marketing-automations-pro' ); ?></label>
<input type="radio" name="event_meta[run_weekly_monthly]" id="bwfan-run_weekly_monthly" class="bwfan-input-wrapper" value="weekly" {{run_weekly}}> <?php echo esc_html__( 'Weekly', 'wp-marketing-automations-pro' ); ?>
<input type="radio" name="event_meta[run_weekly_monthly]" id="bwfan-run_weekly_monthly" class="bwfan-input-wrapper" value="monthly" {{run_monthly}}> <?php echo esc_html__( 'Monthly', 'wp-marketing-automations-pro' ); ?>
</div>
<# hide_run_day = "monthly" === selected_run_type?"bwfan-display-none":''; #>
<div class="bwfan-col-sm-6 bwfan-pl-0 bwfan_mt15 bwfan-run-day {{hide_run_day}}">
<label for="" class="bwfan-label-title"><?php esc_html_e( 'Select Day', 'wp-marketing-automations-pro' ); ?></label>
<select required id="" class="bwfan-input-wrapper" name="event_meta[run_day]">
<#
if(_.has(data.eventFieldsOptions, 'days_options') && _.isObject(data.eventFieldsOptions.days_options) ) {
_.each( data.eventFieldsOptions.days_options, function( value, key ){
selected = (key == selected_day) ? 'selected' : '';
#>
<option value="{{key}}" {{selected}}>{{value}}</option>
<# })
} #>
</select>
</div>
<# hide_run_date = "weekly" === selected_run_type?"bwfan-display-none":''; #>
<div class="bwfan-col-sm-6 bwfan-pl-0 bwfan_mt15 bwfan-run-date {{hide_run_date}}">
<label for="" class="bwfan-label-title"><?php esc_html_e( 'Select Date', 'wp-marketing-automations-pro' ); ?></label>
<select required id="" class="bwfan-input-wrapper " name="event_meta[run_date]">
<#
if(_.has(data.eventFieldsOptions, 'dates_options') && _.isObject(data.eventFieldsOptions.dates_options) ) {
_.each( data.eventFieldsOptions.dates_options, function( value, key ){
selected = (key == selected_date) ? 'selected' : '';
#>
<option value="{{key}}" {{selected}}>{{value}}</option>
<# })
} #>
</select>
</div>
<# hide_earning_weekly = "monthly" === selected_run_type?"bwfan-display-none":''; #>
<div class="bwfan-col-sm-12 bwfan-p-0 bwfan_mt15 bwfan-earning-weekly {{hide_earning_weekly}}">
<label for="bwfan-run_weekly_monthly" class="bwfan-label-title"><?php echo esc_html__( 'Calculate Metrics', 'wp-marketing-automations-pro' ); ?></label>
<input type="radio" name="event_meta[earning_weekly]" id="bwfan_earning_period_earning_weekly" class="bwfan-input-wrapper" value="last_week" {{run_earning_weekly}}> <?php echo esc_html__( 'Last Week (Mon-Sun)', 'wp-marketing-automations-pro' ); ?>
<input type="radio" name="event_meta[earning_weekly]" id="bwfan_earning_period_earning_weekly" class="bwfan-input-wrapper" value="last_7_days" {{run_earning_7_days}}> <?php echo esc_html__( 'Last 7 days', 'wp-marketing-automations-pro' ); ?>
</div>
<# hide_earning_monthly = "weekly" === selected_run_type?"bwfan-display-none":''; #>
<div class="bwfan-col-sm-12 bwfan-p-0 bwfan_mt15 bwfan-earning-monthly {{hide_earning_monthly}}">
<label for="bwfan-run_weekly_monthly" class="bwfan-label-title"><?php echo esc_html__( 'Calculate Metrics', 'wp-marketing-automations-pro' ); ?></label>
<input type="radio" name="event_meta[earning_monthly]" id="bwfan_earning_period_monthly" class="bwfan-input-wrapper" value="last_month" {{run_earning_monthly}}> <?php echo esc_html__( 'Last Month', 'wp-marketing-automations-pro' ); ?>
<input type="radio" name="event_meta[earning_monthly]" id="bwfan_earning_period_monthly" class="bwfan-input-wrapper" value="last_30_days" {{run_earning_30_days}}> <?php echo esc_html__( 'Last 30 days', 'wp-marketing-automations-pro' ); ?>
</div>
<# if( _.has(data.eventFieldsOptions, 'last_run') && '' != data.eventFieldsOptions.last_run ) { #>
<div class="bwfan-clear"></div>
<div class="bwfan-input-form bwfan-row-sep bwfan_mt15"></div>
<div class="bwfan-col-sm-12 bwfan-p-0">
<div class="clearfix bwfan_field_desc"><?php echo esc_html__( 'This automation last ran on ', 'wp-marketing-automations-pro' ); ?>{{data.eventFieldsOptions.last_run}}</div>
</div>
<# } #>
</script>
<script>
jQuery(document).on('change', '#bwfan-run_weekly_monthly', function () {
var selected_run = jQuery(this).val();
if ("weekly" === selected_run) {
jQuery(".bwfan-run-day").removeClass("bwfan-display-none");
jQuery(".bwfan-run-date").addClass("bwfan-display-none");
jQuery(".bwfan-earning-weekly").removeClass("bwfan-display-none");
jQuery(".bwfan-earning-monthly").addClass("bwfan-display-none");
} else {
jQuery(".bwfan-run-day").addClass("bwfan-display-none");
jQuery(".bwfan-run-date").removeClass("bwfan-display-none");
jQuery(".bwfan-earning-weekly").addClass("bwfan-display-none");
jQuery(".bwfan-earning-monthly").removeClass("bwfan-display-none");
}
});
</script>
<?php
}
public function process( $affiliate_id, $referrals_count, $visits, $commissions, $from, $to ) {
$data = $this->get_default_data();
$data['affiliate_id'] = $affiliate_id;
$data['referral_count'] = $referrals_count;
$data['visits'] = $visits;
$data['commissions'] = $commissions;
$data['from'] = $from;
$data['to'] = $to;
$this->send_async_call( $data );
}
/**
* Set up rules data
*
* @param $automation_data
*/
public function pre_executable_actions( $automation_data ) {
BWFAN_Core()->rules->setRulesData( $this->affiliate_id, 'affiliate_id' );
BWFAN_Core()->rules->setRulesData( $this->referral_count, 'referral_count' );
BWFAN_Core()->rules->setRulesData( $this->visits, 'visits' );
BWFAN_Core()->rules->setRulesData( $this->commissions, 'commissions' );
BWFAN_Core()->rules->setRulesData( $this->from, 'from' );
BWFAN_Core()->rules->setRulesData( $this->to, 'to' );
BWFAN_Core()->rules->setRulesData( $this->user_id, 'user_id' );
}
/**
* Registers the tasks for current event.
*
* @param $automation_id
* @param $integration_data
* @param $event_data
*/
public function register_tasks( $automation_id, $integration_data, $event_data ) {
if ( ! is_array( $integration_data ) ) {
return;
}
$data_to_send = $this->get_event_data();
$this->create_tasks( $automation_id, $integration_data, $event_data, $data_to_send );
}
public function get_event_data() {
$data_to_send = [ 'global' => [] ];
$data_to_send['global']['affiliate_id'] = $this->affiliate_id;
$data_to_send['global']['referral_count'] = $this->referral_count;
$data_to_send['global']['visits'] = $this->visits;
$data_to_send['global']['commissions'] = $this->commissions;
$data_to_send['global']['from'] = $this->from;
$data_to_send['global']['to'] = $this->to;
$data_to_send['global']['user_id'] = $this->user_id;
return $data_to_send;
}
/**
* Make the view data for the current event which will be shown in task listing screen.
*
* @param $global_data
*
* @return false|string
*/
public function get_task_view( $global_data ) {
ob_start();
$format = get_option( 'date_format' );
$format = str_replace( 'Y', '', $format );
$format = str_replace( ',', '', $format );
$from = date( $format, strtotime( $global_data['from'] ) );
$to = date( $format, strtotime( $global_data['to'] ) );
$affiliate_id = isset( $global_data['affiliate_id'] ) ? $global_data['affiliate_id'] : 0;
?>
<li>
<strong><?php echo esc_html__( 'Range:', 'wp-marketing-automations-pro' ); ?> </strong>
<?php echo esc_html__( $from ) . ' - ' . esc_html__( $to ); ?>
</li>
<li>
<strong><?php echo esc_html__( 'Affiliate ID:', 'wp-marketing-automations-pro' ); ?> </strong>
<a target="_blank" href="<?php echo admin_url( 'admin.php' ) . '?page=affiliate-wp-affiliates&affiliate_id=' . $affiliate_id . '&action=edit_affiliate'; //phpcs:ignore WordPress.Security.EscapeOutput ?>"><?php echo esc_html__( $affiliate_id ); ?></a>
</li>
<li>
<strong><?php echo esc_html__( 'Referral Count:', 'wp-marketing-automations-pro' ); ?> </strong>
<?php echo esc_html__( $global_data['referral_count'] ); ?>
</li>
<li>
<strong><?php echo esc_html__( 'Referral Commissions:', 'wp-marketing-automations-pro' ); ?> </strong>
<?php echo esc_html__( $global_data['commissions'] ); ?>
</li>
<li>
<strong><?php echo esc_html__( 'Visits:', 'wp-marketing-automations-pro' ); ?> </strong>
<?php echo esc_html__( $global_data['visits'] ); ?>
</li>
<?php
return ob_get_clean();
}
/**
* Set global data for all the merge tags which are supported by this event.
*
* @param $task_meta
*/
public function set_merge_tags_data( $task_meta ) {
$get_data = BWFAN_Merge_Tag_Loader::get_data( 'referral_id' );
if ( ( empty( $get_data ) || intval( $get_data ) !== intval( $task_meta['global']['referral_id'] ) ) ) {
$set_data = array(
'affiliate_id' => intval( $task_meta['global']['affiliate_id'] ),
'referral_count' => intval( $task_meta['global']['referral_count'] ),
'visits' => intval( $task_meta['global']['visits'] ),
'commissions' => $task_meta['global']['commissions'],
'from' => $task_meta['global']['from'],
'to' => $task_meta['global']['to'],
'user_id' => $task_meta['global']['user_id'],
);
BWFAN_Merge_Tag_Loader::set_data( $set_data );
}
}
/**
* Capture the async data for the current event.
* @return array|bool
*/
public function capture_async_data() {
$this->affiliate_id = BWFAN_Common::$events_async_data['affiliate_id'];
$this->referral_count = BWFAN_Common::$events_async_data['referral_count'];
$this->visits = BWFAN_Common::$events_async_data['visits'];
$this->commissions = BWFAN_Common::$events_async_data['commissions'];
$this->from = BWFAN_Common::$events_async_data['from'];
$this->to = BWFAN_Common::$events_async_data['to'];
$this->user_id = affwp_get_affiliate_user_id( $this->affiliate_id );
return $this->run_automations();
}
public function get_email_event() {
if ( ! empty( absint( $this->user_id ) ) ) {
$user = get_user_by( 'id', absint( $this->user_id ) );
return ( $user instanceof WP_User ) ? $user->user_email : false;
}
return false;
}
public function get_user_id_event() {
return ! empty( absint( $this->user_id ) ) ? absint( $this->user_id ) : false;
}
/**
* This is a time independent event. A cron is run once a day and it makes all the tasks for the current event.
*
* @param $automation_id
* @param $automation_details
*/
public function make_task_data( $automation_id, $automation_details ) {
$affiliates = BWFAN_PRO_Common::get_all_active_affiliates();
if ( empty( $affiliates ) ) {
return;
}
$run_weekly = $automation_details['meta']['event_meta']['run_weekly_monthly'];
if ( 'weekly' === $run_weekly ) {
$this->run_weekly_automation( $automation_id, $automation_details['meta']['event_meta'], $affiliates );
return;
}
$this->run_monthly_automation( $automation_id, $automation_details['meta']['event_meta'], $affiliates );
}
private function run_weekly_automation( $automation_id, $event_meta, $affiliates ) {
$selected_day = intval( $event_meta['run_day'] );
$timestamp = current_time( 'timestamp' );
$date_time = new DateTime();
$date_time->setTimestamp( $timestamp );
$day_today = intval( $date_time->format( 'w' ) );
if ( $selected_day !== $day_today ) {
return;
}
$date_time->setTime( 00, 00, 00 );
$current_day = $date_time->format( 'Y-m-d' );
$last_run = BWFAN_Model_Automationmeta::get_meta( $automation_id, 'last_run' );
if ( false !== $last_run ) {
$last_run_obj = new DateTime( $last_run );
$diff = $date_time->diff( $last_run_obj );
if ( 7 > intval( $diff->days ) ) {
return;
}
$where = [
'bwfan_automation_id' => $automation_id,
'meta_key' => 'last_run',
];
$data = [
'meta_value' => $current_day,
];
BWFAN_Model_Automationmeta::update( $data, $where );
} else {
$meta = [
'bwfan_automation_id' => $automation_id,
'meta_key' => 'last_run',
'meta_value' => $current_day,
];
BWFAN_Model_Automationmeta::insert( $meta );
}
if ( 'last_week' === $event_meta['earning_weekly'] ) {
$to = date( 'Y-m-d', strtotime( 'last sunday' ) );
$last_week = new DateTime( $to );
$last_week->modify( '-6days' );
$from = date( 'Y-m-d', $last_week->getTimestamp() );
} else {
$date_time->modify( '-1day' );
$to = date( 'Y-m-d', $date_time->getTimestamp() );
$date_time->modify( '-6day' );
$from = date( 'Y-m-d', $date_time->getTimestamp() );
}
$affiliate_batches = array_chunk( $affiliates, 100 );
if ( count( $affiliate_batches ) === 0 ) {
return;
}
/** Check if automations v1 or v2 exists */
BWFAN_Core()->public->load_active_automations( $this->get_slug() );
BWFAN_Core()->public->load_active_v2_automations( $this->get_slug() );
if ( ( ! is_array( $this->automations_arr ) || count( $this->automations_arr ) === 0 ) && ( ! is_array( $this->automations_v2_arr ) || count( $this->automations_v2_arr ) === 0 ) ) {
return;
}
/**
* recurring action schedule 2 mins interval
* event slug as option key - bwf_async_event_{slug} = subscription_ids_array
* after running capture_subscription method, update the subscription id value in the option key
*/
$final_batches = [];
foreach ( $affiliate_batches as $ids ) {
$final_batches[] = [
'ids' => $ids,
'from' => $from,
'to' => $to,
];
}
$key = 'bwf_async_event_' . $this->get_slug() . '_' . time();
$args = [ 'key' => $key, 'aid' => $automation_id ];
if ( ! bwf_has_action_scheduled( 'bwfan_send_affiliate_insights', $args ) ) {
bwf_schedule_recurring_action( time(), 120, 'bwfan_send_affiliate_insights', $args );
update_option( $key, $final_batches, false );
}
}
private function run_monthly_automation( $automation_id, $event_meta, $affiliates ) {
$selected_date = $event_meta['run_date'];
$timestamp = current_time( 'timestamp' );
$date_time = new DateTime();
$date_time->setTimestamp( $timestamp );
$date_today = intval( $date_time->format( 'd' ) );
if ( 'end_of_month' === $selected_date ) {
$end_date = intval( $date_time->format( 't' ) );
if ( $end_date !== $date_today ) {
return;
}
} elseif ( intval( $selected_date ) !== $date_today ) {
return;
}
$date_time->setTime( 00, 00, 00 );
$current_day = $date_time->format( 'Y-m-d' );
$last_run = BWFAN_Model_Automationmeta::get_meta( $automation_id, 'last_run' );
if ( false !== $last_run ) {
$previous_month = clone $date_time;
$previous_month->modify( '-1month' );
$last_run_obj = new DateTime( $last_run );
$diff = $previous_month->diff( $last_run_obj );
if ( 0 === intval( $diff->invert ) && 0 !== intval( $diff->days ) ) {
return;
}
$where = [
'bwfan_automation_id' => $automation_id,
'meta_key' => 'last_run',
];
$data = [
'meta_value' => $current_day,
];
BWFAN_Model_Automationmeta::update( $data, $where );
} else {
$meta = [
'bwfan_automation_id' => $automation_id,
'meta_key' => 'last_run',
'meta_value' => $current_day,
];
BWFAN_Model_Automationmeta::insert( $meta );
}
if ( 'last_month' === $event_meta['earning_monthly'] ) {
$from = date( 'Y-m-d', strtotime( 'first day of last month' ) );
$to = date( 'Y-m-d', strtotime( 'last day of last month' ) );
} else {
$date_time->modify( '-1day' );
$to = date( 'Y-m-d', $date_time->getTimestamp() );
$date_time->modify( '+1day' );
$date_time->modify( '-1month' );
$from = date( 'Y-m-d', $date_time->getTimestamp() );
}
$affiliate_batches = array_chunk( $affiliates, 100 );
if ( count( $affiliate_batches ) === 0 ) {
return;
}
/** Check if automations v1 or v2 exists */
BWFAN_Core()->public->load_active_automations( $this->get_slug() );
BWFAN_Core()->public->load_active_v2_automations( $this->get_slug() );
if ( ( ! is_array( $this->automations_arr ) || count( $this->automations_arr ) === 0 ) && ( ! is_array( $this->automations_v2_arr ) || count( $this->automations_v2_arr ) === 0 ) ) {
return;
}
/**
* recurring action schedule 2 mins interval
* event slug as option key - bwf_async_event_{slug} = subscription_ids_array
* after running capture_subscription method, update the subscription id value in the option key
*/
$final_batches = [];
foreach ( $affiliate_batches as $ids ) {
$final_batches[] = [
'ids' => $ids,
'from' => $from,
'to' => $to,
];
}
$key = 'bwf_async_event_' . $this->get_slug() . '_' . time();
$args = [ 'key' => $key, 'aid' => $automation_id ];
if ( ! bwf_has_action_scheduled( 'bwfan_send_affiliate_insights', $args ) ) {
bwf_schedule_recurring_action( time(), 120, 'bwfan_send_affiliate_insights', $args );
update_option( $key, $final_batches, false );
}
}
/**
* Capture the async data for the current event.
* @return array|bool
*/
public function capture_v2_data( $automation_data ) {
$this->affiliate_id = BWFAN_Common::$events_async_data['affiliate_id'];
$this->referral_count = BWFAN_Common::$events_async_data['referral_count'];
$this->visits = BWFAN_Common::$events_async_data['visits'];
$this->commissions = BWFAN_Common::$events_async_data['commissions'];
$this->from = BWFAN_Common::$events_async_data['from'];
$this->to = BWFAN_Common::$events_async_data['to'];
$this->user_id = affwp_get_affiliate_user_id( $this->affiliate_id );
$automation_data['affiliate_id'] = $this->affiliate_id;
$automation_data['referral_count'] = $this->referral_count;
$automation_data['visits'] = $this->visits;
$automation_data['commissions'] = $this->commissions;
$automation_data['from'] = $this->from;
$automation_data['to'] = $this->to;
$automation_data['user_id'] = $this->user_id;
return $automation_data;
}
/** trigger affiliate report automations */
public function send_affiliate_insights( $option_key, $automation_id ) {
$affiliates = get_option( $option_key, [] );
if ( empty( $affiliates ) ) {
delete_option( $option_key );
bwf_unschedule_actions( 'bwfan_send_affiliate_insights', [ 'key' => $option_key, 'aid' => $automation_id ] );
return;
}
/** Validate automation */
$automation = BWFAN_Model_Automations::get_automation_with_data( $automation_id );
if ( isset( $automation['meta'] ) ) {
$meta = $automation['meta'];
unset( $automation['meta'] );
$automation = array_merge( $automation, $meta );
}
if ( 1 !== intval( $automation['status'] ) || ( 0 === absint( $automation['start'] ) && 2 === absint( $automation['v'] ) ) ) {
delete_option( $option_key );
bwf_unschedule_actions( 'bwfan_send_affiliate_insights', [ 'key' => $option_key, 'aid' => $automation_id ] );
return;
}
$updated_affiliates = $affiliates;
$start_time = time();
foreach ( $affiliates as $aff_key => $affiliate_ids ) {
/**checking 10 seconds of processing */
if ( ( time() - $start_time ) > 10 ) {
return;
}
foreach ( $affiliate_ids['ids'] as $affiliate_id ) {
$referrals_count = BWFAN_PRO_Common::get_referrals_count_from_period( $affiliate_id, $affiliate_ids['from'], $affiliate_ids['to'] );
$visits = BWFAN_PRO_Common::get_visits_from_period( $affiliate_id, $affiliate_ids['from'], $affiliate_ids['to'] );
$commissions = BWFAN_PRO_Common::get_commissions_from_period( $affiliate_id, $affiliate_ids['from'], $affiliate_ids['to'] );
$this->process( $affiliate_id, $referrals_count, $visits, $commissions, $affiliate_ids['from'], $affiliate_ids['to'] );
}
unset( $updated_affiliates[ $aff_key ] );
update_option( $option_key, $updated_affiliates, false );
}
}
/**
* v2 Method: Get field Schema
*
* @return array[]
*/
public function get_fields_schema() {
$data = $this->get_view_data();
$days = isset( $data['days'] ) ? BWFAN_PRO_Common::prepared_field_options( $data['days'] ) : [];
$dates = isset( $data['dates'] ) ? BWFAN_PRO_Common::prepared_field_options( $data['dates'] ) : [];
return [
[
'id' => 'run_weekly_monthly',
'label' => __( "Frequency", 'wp-marketing-automations-pro' ),
'type' => 'radio',
'options' => [
[
'label' => __( "Weekly", 'wp-marketing-automations-pro' ),
'value' => 'weekly',
],
[
'label' => __( "Monthly", 'wp-marketing-automations-pro' ),
'value' => 'monthly',
]
],
],
[
'id' => 'run_day',
'label' => __( 'Select Day', 'wp-marketing-automations-pro' ),
'type' => 'wp_select',
'options' => $days,
'class' => 'bwfan-input-wrapper',
'description' => '',
'required' => false,
'toggler' => [
'fields' => [
[
'id' => 'run_weekly_monthly',
'value' => 'weekly',
],
],
'relation' => 'AND',
],
],
[
'id' => 'run_date',
'label' => __( 'Select Date', 'wp-marketing-automations-pro' ),
'type' => 'wp_select',
'options' => $dates,
'class' => 'bwfan-input-wrapper',
'description' => '',
'required' => false,
'toggler' => [
'fields' => [
[
'id' => 'run_weekly_monthly',
'value' => 'monthly',
],
],
'relation' => 'AND',
],
],
[
'id' => 'earning_weekly',
'label' => __( "Calculate Metrics", 'wp-marketing-automations-pro' ),
'type' => 'radio',
'options' => [
[
'label' => __( "Last Week (Mon-Sun)", 'wp-marketing-automations-pro' ),
'value' => 'last_week',
],
[
'label' => __( "Last 7 days", 'wp-marketing-automations-pro' ),
'value' => 'last_7_days',
]
],
'toggler' => [
'fields' => [
[
'id' => 'run_weekly_monthly',
'value' => 'weekly',
],
],
'relation' => 'AND',
],
],
[
'id' => 'earning_monthly',
'label' => __( "Calculate Metrics", 'wp-marketing-automations-pro' ),
'type' => 'radio',
'options' => [
[
'label' => __( "Last Month", 'wp-marketing-automations-pro' ),
'value' => 'last_month',
],
[
'label' => __( "Last 30 days", 'wp-marketing-automations-pro' ),
'value' => 'last_30_days',
]
],
'toggler' => [
'fields' => [
[
'id' => 'run_weekly_monthly',
'value' => 'monthly',
],
],
'relation' => 'AND',
],
],
];
}
}
/**
* Register this event to a source.
* This will show the current event in dropdown in single automation screen.
*/
if ( bwfan_is_affiliatewp_active() ) {
return 'BWFAN_AFFWP_Affiliate_Report';
}

View File

@@ -0,0 +1,206 @@
<?php
#[AllowDynamicProperties]
final class BWFAN_AFFWP_Application_Approved extends BWFAN_Event {
private static $instance = null;
public $affiliate_id = null;
public $status = null;
public $old_status = null;
public $user_id = null;
private function __construct() {
$this->event_merge_tag_groups = array( 'aff_affiliate', 'bwf_contact' );
$this->optgroup_label = esc_html__( 'AffiliateWP', 'wp-marketing-automations-pro' );
$this->event_name = esc_html__( 'Application Approved', 'wp-marketing-automations-pro' );
$this->event_desc = esc_html__( 'This event runs after an affiliate application is approved.', 'wp-marketing-automations-pro' );
$this->event_rule_groups = array(
'affiliatewp',
'bwf_contact_segments',
'bwf_contact',
'bwf_contact_fields',
'bwf_contact_user',
'bwf_contact_wc',
'bwf_contact_geo',
'bwf_engagement',
'bwf_broadcast'
);
$this->priority = 10;
$this->customer_email_tag = '{{affwp_affiliate_email}}';
$this->v2 = true;
}
public static function get_instance() {
if ( null === self::$instance ) {
self::$instance = new self();
}
return self::$instance;
}
public function load_hooks() {
add_action( 'affwp_set_affiliate_status', array( $this, 'process' ), 10, 3 );
}
/**
* Make the required data for the current event and send it asynchronously.
*
* @param $affiliate_id
* @param $status
* @param $old_status
*/
public function process( $affiliate_id, $status, $old_status ) {
if ( 'active' !== $status || $status === $old_status ) {
return;
}
$data = $this->get_default_data();
$data['affiliate_id'] = $affiliate_id;
$data['status'] = $status;
$data['old_status'] = $old_status;
$this->send_async_call( $data );
}
/**
* Registers the tasks for current event.
*
* @param $automation_id
* @param $integration_data
* @param $event_data
*/
public function register_tasks( $automation_id, $integration_data, $event_data ) {
if ( ! is_array( $integration_data ) ) {
return;
}
$data_to_send = $this->get_event_data();
$this->create_tasks( $automation_id, $integration_data, $event_data, $data_to_send );
}
public function get_event_data() {
$data_to_send = [ 'global' => [] ];
$data_to_send['global']['affiliate_id'] = $this->affiliate_id;
$data_to_send['global']['status'] = $this->status;
$data_to_send['global']['old_status'] = $this->old_status;
$data_to_send['global']['user_id'] = $this->user_id;
return $data_to_send;
}
/**
* Make the view data for the current event which will be shown in task listing screen.
*
* @param $global_data
*
* @return false|string
*/
public function get_task_view( $global_data ) {
ob_start();
$affiliate_id = isset( $global_data['affiliate_id'] ) ? $global_data['affiliate_id'] : 0;
?>
<li>
<strong><?php echo esc_html__( 'Affiliate Id:', 'wp-marketing-automations-pro' ); ?> </strong>
<a target="_blank" href="<?php echo admin_url( 'admin.php' ) . '?page=affiliate-wp-affiliates&affiliate_id=' . $affiliate_id . '&action=edit_affiliate'; //phpcs:ignore WordPress.Security.EscapeOutput ?>"><?php echo esc_html__( $affiliate_id ); ?></a>
</li>
<li>
<strong><?php echo esc_html__( 'Status:', 'wp-marketing-automations-pro' ); ?> </strong>
<span><?php echo esc_html__( $global_data['status'] ); ?></span>
</li>
<li>
<strong><?php echo esc_html__( 'Old Status:', 'wp-marketing-automations-pro' ); ?> </strong>
<span><?php echo esc_html__( $global_data['old_status'] ); ?></span>
</li>
<?php
return ob_get_clean();
}
/**
* Capture the async data for the current event.
* @return array|bool
*/
public function capture_async_data() {
$this->affiliate_id = BWFAN_Common::$events_async_data['affiliate_id'];
$this->status = BWFAN_Common::$events_async_data['status'];
$this->old_status = BWFAN_Common::$events_async_data['old_status'];
$this->user_id = affwp_get_affiliate_user_id( $this->affiliate_id );
return $this->run_automations();
}
public function get_email_event() {
if ( ! empty( absint( $this->user_id ) ) ) {
$user = get_user_by( 'id', absint( $this->user_id ) );
return ( $user instanceof WP_User ) ? $user->user_email : false;
}
return false;
}
public function get_user_id_event() {
return ! empty( absint( $this->user_id ) ) ? absint( $this->user_id ) : false;
}
/**
* Set global data for all the merge tags which are supported by this event.
*
* @param $task_meta
*/
public function set_merge_tags_data( $task_meta ) {
$get_data = BWFAN_Merge_Tag_Loader::get_data( 'affiliate_id' );
if ( ( empty( $get_data ) || intval( $get_data ) !== intval( $task_meta['global']['affiliate_id'] ) ) ) {
$set_data = array(
'affiliate_id' => intval( $task_meta['global']['affiliate_id'] ),
'user_id' => intval( $task_meta['global']['user_id'] ),
);
BWFAN_Merge_Tag_Loader::set_data( $set_data );
}
}
/**
* Set up rules data
*
* @param $value
*/
public function pre_executable_actions( $value ) {
BWFAN_Core()->rules->setRulesData( $this->affiliate_id, 'affiliate_id' );
BWFAN_Core()->rules->setRulesData( $this->user_id, 'user_id' );
}
/**
* Capture the async data for the current event.
* @return array|bool
*/
public function capture_v2_data( $automation_data ) {
$this->affiliate_id = BWFAN_Common::$events_async_data['affiliate_id'];
$this->status = BWFAN_Common::$events_async_data['status'];
$this->old_status = BWFAN_Common::$events_async_data['old_status'];
$this->user_id = affwp_get_affiliate_user_id( $this->affiliate_id );
$automation_data['affiliate_id'] = $this->affiliate_id;
$automation_data['status'] = $this->status;
$automation_data['old_status'] = $this->old_status;
$automation_data['user_id'] = $this->user_id;
return $automation_data;
}
/**
* v2 Method: Get field schema
* @return array
*/
public function get_field_schema() {
return [];
}
}
/**
* Register this event to a source.
* This will show the current event in dropdown in single automation screen.
*/
if ( bwfan_is_affiliatewp_active() ) {
return 'BWFAN_AFFWP_Application_Approved';
}

View File

@@ -0,0 +1,206 @@
<?php
#[AllowDynamicProperties]
final class BWFAN_AFFWP_Application_Rejected extends BWFAN_Event {
private static $instance = null;
public $affiliate_id = null;
public $status = null;
public $old_status = null;
public $user_id = null;
private function __construct() {
$this->event_merge_tag_groups = array( 'aff_affiliate', 'bwf_contact' );
$this->optgroup_label = esc_html__( 'AffiliateWP', 'wp-marketing-automations-pro' );
$this->event_name = esc_html__( 'Application Rejected', 'wp-marketing-automations-pro' );
$this->event_desc = esc_html__( 'This event runs after an affiliate application is rejected.', 'wp-marketing-automations-pro' );
$this->event_rule_groups = array(
'affiliatewp',
'bwf_contact_segments',
'bwf_contact',
'bwf_contact_fields',
'bwf_contact_user',
'bwf_contact_wc',
'bwf_contact_geo',
'bwf_engagement',
'bwf_broadcast'
);
$this->priority = 10;
$this->customer_email_tag = '{{affwp_affiliate_email}}';
$this->v2 = true;
}
public static function get_instance() {
if ( null === self::$instance ) {
self::$instance = new self();
}
return self::$instance;
}
public function load_hooks() {
add_action( 'affwp_set_affiliate_status', array( $this, 'process' ), 10, 3 );
}
/**
* Make the required data for the current event and send it asynchronously.
*
* @param $affiliate_id
* @param $status
* @param $old_status
*/
public function process( $affiliate_id, $status, $old_status ) {
if ( 'rejected' !== $status || $old_status === $status ) {
return;
}
$data = $this->get_default_data();
$data['affiliate_id'] = $affiliate_id;
$data['status'] = $status;
$data['old_status'] = $old_status;
$this->send_async_call( $data );
}
/**
* Registers the tasks for current event.
*
* @param $automation_id
* @param $integration_data
* @param $event_data
*/
public function register_tasks( $automation_id, $integration_data, $event_data ) {
if ( ! is_array( $integration_data ) ) {
return;
}
$data_to_send = $this->get_event_data();
$this->create_tasks( $automation_id, $integration_data, $event_data, $data_to_send );
}
public function get_event_data() {
$data_to_send = [ 'global' => [] ];
$data_to_send['global']['affiliate_id'] = $this->affiliate_id;
$data_to_send['global']['status'] = $this->status;
$data_to_send['global']['old_status'] = $this->old_status;
$data_to_send['global']['user_id'] = $this->user_id;
return $data_to_send;
}
/**
* Make the view data for the current event which will be shown in task listing screen.
*
* @param $global_data
*
* @return false|string
*/
public function get_task_view( $global_data ) {
ob_start();
$affiliate_id = isset( $global_data['affiliate_id'] ) ? $global_data['affiliate_id'] : 0;
?>
<li>
<strong><?php echo esc_html__( 'Affiliate Id:', 'wp-marketing-automations-pro' ); ?> </strong>
<a target="_blank" href="<?php echo admin_url( 'admin.php' ) . '?page=affiliate-wp-affiliates&affiliate_id=' . $affiliate_id . '&action=edit_affiliate'; //phpcs:ignore WordPress.Security.EscapeOutput ?>"><?php echo esc_html__( $affiliate_id ); ?></a>
</li>
<li>
<strong><?php echo esc_html__( 'Old Status:', 'wp-marketing-automations-pro' ); ?> </strong>
<span><?php echo esc_html__( $global_data['old_status'] ); ?></span>
</li>
<li>
<strong><?php echo esc_html__( 'Status:', 'wp-marketing-automations-pro' ); ?> </strong>
<span><?php echo esc_html__( $global_data['status'] ); ?></span>
</li>
<?php
return ob_get_clean();
}
/**
* Capture the async data for the current event.
* @return array|bool
*/
public function capture_async_data() {
$this->affiliate_id = BWFAN_Common::$events_async_data['affiliate_id'];
$this->status = BWFAN_Common::$events_async_data['status'];
$this->old_status = BWFAN_Common::$events_async_data['old_status'];
$this->user_id = affwp_get_affiliate_user_id( $this->affiliate_id );
return $this->run_automations();
}
public function get_email_event() {
if ( ! empty( absint( $this->user_id ) ) ) {
$user = get_user_by( 'id', absint( $this->user_id ) );
return ( $user instanceof WP_User ) ? $user->user_email : false;
}
return false;
}
public function get_user_id_event() {
return ! empty( absint( $this->user_id ) ) ? absint( $this->user_id ) : false;
}
/**
* Set global data for all the merge tags which are supported by this event.
*
* @param $task_meta
*/
public function set_merge_tags_data( $task_meta ) {
$get_data = BWFAN_Merge_Tag_Loader::get_data( 'affiliate_id' );
if ( ( empty( $get_data ) || intval( $get_data ) !== intval( $task_meta['global']['affiliate_id'] ) ) ) {
$set_data = array(
'affiliate_id' => intval( $task_meta['global']['affiliate_id'] ),
'user_id' => intval( $task_meta['global']['user_id'] ),
);
BWFAN_Merge_Tag_Loader::set_data( $set_data );
}
}
/**
* Set up rules data
*
* @param $value
*/
public function pre_executable_actions( $value ) {
BWFAN_Core()->rules->setRulesData( $this->affiliate_id, 'affiliate_id' );
BWFAN_Core()->rules->setRulesData( $this->user_id, 'user_id' );
}
/**
* Capture the async data for the current event.
* @return array|bool
*/
public function capture_v2_data( $automation_data ) {
$this->affiliate_id = BWFAN_Common::$events_async_data['affiliate_id'];
$this->status = BWFAN_Common::$events_async_data['status'];
$this->old_status = BWFAN_Common::$events_async_data['old_status'];
$this->user_id = affwp_get_affiliate_user_id( $this->affiliate_id );
$automation_data['affiliate_id'] = $this->affiliate_id;
$automation_data['status'] = $this->status;
$automation_data['old_status'] = $this->old_status;
$automation_data['user_id'] = $this->user_id;
return $automation_data;
}
/**
* v2 Method: Get field schema
* @return array
*/
public function get_field_schema() {
return [];
}
}
/**
* Register this event to a source.
* This will show the current event in dropdown in single automation screen.
*/
if ( bwfan_is_affiliatewp_active() ) {
return 'BWFAN_AFFWP_Application_Rejected';
}

View File

@@ -0,0 +1,212 @@
<?php
#[AllowDynamicProperties]
final class BWFAN_AFFWP_Makes_Sale extends BWFAN_Event {
private static $instance = null;
public $referral_id = false;
public $affiliate_id = false;
public $old_status = '';
public $user_id = 0;
private function __construct() {
$this->event_merge_tag_groups = array( 'aff_affiliate', 'aff_referral', 'bwf_contact' );
$this->event_name = esc_html__( 'Affiliate Makes A Sale', 'wp-marketing-automations-pro' );
$this->event_desc = esc_html__( 'This event runs after an affiliate makes a sale.', 'wp-marketing-automations-pro' );
$this->event_rule_groups = array(
'affiliatewp',
'bwf_contact_segments',
'bwf_contact',
'bwf_contact_fields',
'bwf_contact_user',
'bwf_contact_wc',
'bwf_contact_geo',
'bwf_engagement',
'bwf_broadcast'
);
$this->optgroup_label = esc_html__( 'AffiliateWP', 'wp-marketing-automations-pro' );
$this->priority = 40;
$this->customer_email_tag = '{{affwp_affiliate_email}}';
$this->v2 = true;
}
public static function get_instance() {
if ( null === self::$instance ) {
self::$instance = new self();
}
return self::$instance;
}
public function load_hooks() {
add_action( 'affwp_set_referral_status', [ $this, 'process' ], 10, 3 );
}
/**
* Make the required data for the current event and send it asynchronously.
*
* @param $referral_id
* @param $new_status
* @param $old_status
*/
public function process( $referral_id, $new_status, $old_status ) {
if ( 'unpaid' !== $new_status || $old_status === $new_status ) {
return;
}
$data = $this->get_default_data();
$data['referral_id'] = $referral_id;
$data['old_status'] = $old_status;
$this->send_async_call( $data );
}
/**
* Set up rules data
*
* @param $automation_data
*/
public function pre_executable_actions( $automation_data ) {
BWFAN_Core()->rules->setRulesData( $this->affiliate_id, 'affiliate_id' );
BWFAN_Core()->rules->setRulesData( $this->referral_id, 'referral_id' );
BWFAN_Core()->rules->setRulesData( $this->user_id, 'user_id' );
}
/**
* Registers the tasks for current event.
*
* @param $automation_id
* @param $integration_data
* @param $event_data
*/
public function register_tasks( $automation_id, $integration_data, $event_data ) {
if ( ! is_array( $integration_data ) ) {
return;
}
$data_to_send = $this->get_event_data();
$this->create_tasks( $automation_id, $integration_data, $event_data, $data_to_send );
}
public function get_event_data() {
$data_to_send = [ 'global' => [] ];
$data_to_send['global']['referral_id'] = $this->referral_id;
$data_to_send['global']['affiliate_id'] = $this->affiliate_id;
$data_to_send['global']['old_status'] = $this->old_status;
$data_to_send['global']['user_id'] = $this->user_id;
return $data_to_send;
}
/**
* Make the view data for the current event which will be shown in task listing screen.
*
* @param $global_data
*
* @return false|string
*/
public function get_task_view( $global_data ) {
ob_start();
$affiliate_id = isset( $global_data['affiliate_id'] ) ? $global_data['affiliate_id'] : 0;
?>
<li>
<strong><?php echo esc_html__( 'Affiliate ID:', 'wp-marketing-automations-pro' ); ?> </strong>
<a target="_blank" href="<?php echo admin_url( 'admin.php' ) . '?page=affiliate-wp-affiliates&affiliate_id=' . $affiliate_id . '&action=edit_affiliate'; //phpcs:ignore WordPress.Security.EscapeOutput ?>"><?php echo esc_html__( $affiliate_id ); ?></a>
</li>
<li>
<strong><?php echo esc_html__( 'Referral ID:', 'wp-marketing-automations-pro' ); ?> </strong>
<span><?php echo esc_html__( $global_data['referral_id'] ); ?></span>
</li>
<li>
<strong><?php echo esc_html__( 'Old Status:', 'wp-marketing-automations-pro' ); ?> </strong>
<?php echo esc_html__( $global_data['old_status'] ); ?>
</li>
<li>
<strong><?php echo esc_html__( 'New Status:', 'wp-marketing-automations-pro' ); ?> </strong>
<?php echo esc_html__( 'unpaid' ); ?>
</li>
<?php
return ob_get_clean();
}
/**
* Set global data for all the merge tags which are supported by this event.
*
* @param $task_meta
*/
public function set_merge_tags_data( $task_meta ) {
$get_data = BWFAN_Merge_Tag_Loader::get_data( 'referral_id' );
if ( ( empty( $get_data ) || intval( $get_data ) !== intval( $task_meta['global']['referral_id'] ) ) ) {
$set_data = array(
'affiliate_id' => intval( $task_meta['global']['affiliate_id'] ),
'referral_id' => intval( $task_meta['global']['referral_id'] ),
'user_id' => intval( $task_meta['global']['user_id'] ),
);
BWFAN_Merge_Tag_Loader::set_data( $set_data );
}
}
/**
* Capture the async data for the current event.
* @return array|bool
*/
public function capture_async_data() {
$this->referral_id = BWFAN_Common::$events_async_data['referral_id'];
$this->old_status = BWFAN_Common::$events_async_data['old_status'];
$referral = affwp_get_referral( $this->referral_id );
$this->affiliate_id = $referral->affiliate_id;
$this->user_id = affwp_get_affiliate_user_id( $this->affiliate_id );
return $this->run_automations();
}
public function get_email_event() {
if ( ! empty( absint( $this->user_id ) ) ) {
$user = get_user_by( 'id', absint( $this->user_id ) );
return ( $user instanceof WP_User ) ? $user->user_email : false;
}
return false;
}
public function get_user_id_event() {
return ! empty( absint( $this->user_id ) ) ? absint( $this->user_id ) : false;
}
/**
* Capture the async data for the current event.
* @return array|bool
*/
public function capture_v2_data( $automation_data ) {
$this->referral_id = BWFAN_Common::$events_async_data['referral_id'];
$this->old_status = BWFAN_Common::$events_async_data['old_status'];
$referral = affwp_get_referral( $this->referral_id );
$this->affiliate_id = $referral->affiliate_id;
$this->user_id = affwp_get_affiliate_user_id( $this->affiliate_id );
$automation_data['affiliate_id'] = $this->affiliate_id;
$automation_data['referral_id'] = $this->referral_id;
$automation_data['old_status'] = $this->old_status;
$automation_data['user_id'] = $this->user_id;
return $automation_data;
}
/**
* v2 Method: Get field schema
* @return array
*/
public function get_field_schema() {
return [];
}
}
/**
* Register this event to a source.
* This will show the current event in dropdown in single automation screen.
*/
if ( bwfan_is_affiliatewp_active() ) {
return 'BWFAN_AFFWP_Makes_Sale';
}

View File

@@ -0,0 +1,212 @@
<?php
#[AllowDynamicProperties]
final class BWFAN_AFFWP_Referral_Rejected extends BWFAN_Event {
private static $instance = null;
public $referral_id = false;
public $affiliate_id = false;
public $old_status = '';
public $user_id = 0;
private function __construct() {
$this->event_merge_tag_groups = array( 'aff_affiliate', 'aff_referral', 'bwf_contact' );
$this->event_name = esc_html__( 'Referral Rejected', 'wp-marketing-automations-pro' );
$this->event_desc = esc_html__( 'This event runs after a referral is rejected.', 'wp-marketing-automations-pro' );
$this->event_rule_groups = array(
'affiliatewp',
'bwf_contact_segments',
'bwf_contact',
'bwf_contact_fields',
'bwf_contact_user',
'bwf_contact_wc',
'bwf_contact_geo',
'bwf_engagement',
'bwf_broadcast'
);
$this->optgroup_label = esc_html__( 'AffiliateWP', 'wp-marketing-automations-pro' );
$this->priority = 50;
$this->customer_email_tag = '{{affwp_affiliate_email}}';
$this->v2 = true;
}
public static function get_instance() {
if ( null === self::$instance ) {
self::$instance = new self();
}
return self::$instance;
}
public function load_hooks() {
add_action( 'affwp_set_referral_status', [ $this, 'process' ], 10, 3 );
}
/**
* Make the required data for the current event and send it asynchronously.
*
* @param $referral_id
* @param $new_status
* @param $old_status
*/
public function process( $referral_id, $new_status, $old_status ) {
if ( 'rejected' !== $new_status || $old_status === $new_status ) {
return;
}
$data = $this->get_default_data();
$data['referral_id'] = $referral_id;
$data['old_status'] = $old_status;
$this->send_async_call( $data );
}
/**
* Set up rules data
*
* @param $automation_data
*/
public function pre_executable_actions( $automation_data ) {
BWFAN_Core()->rules->setRulesData( $this->affiliate_id, 'affiliate_id' );
BWFAN_Core()->rules->setRulesData( $this->referral_id, 'referral_id' );
BWFAN_Core()->rules->setRulesData( $this->user_id, 'user_id' );
}
/**
* Registers the tasks for current event.
*
* @param $automation_id
* @param $integration_data
* @param $event_data
*/
public function register_tasks( $automation_id, $integration_data, $event_data ) {
if ( ! is_array( $integration_data ) ) {
return;
}
$data_to_send = $this->get_event_data();
$this->create_tasks( $automation_id, $integration_data, $event_data, $data_to_send );
}
public function get_event_data() {
$data_to_send = [ 'global' => [] ];
$data_to_send['global']['referral_id'] = $this->referral_id;
$data_to_send['global']['affiliate_id'] = $this->affiliate_id;
$data_to_send['global']['old_status'] = $this->old_status;
$data_to_send['global']['user_id'] = $this->user_id;
return $data_to_send;
}
/**
* Make the view data for the current event which will be shown in task listing screen.
*
* @param $global_data
*
* @return false|string
*/
public function get_task_view( $global_data ) {
ob_start();
$affiliate_id = isset( $global_data['affiliate_id'] ) ? $global_data['affiliate_id'] : 0;
?>
<li>
<strong><?php echo esc_html__( 'Affiliate ID:', 'wp-marketing-automations-pro' ); ?> </strong>
<a target="_blank" href="<?php echo admin_url( 'admin.php' ) . '?page=affiliate-wp-affiliates&affiliate_id=' . $affiliate_id . '&action=edit_affiliate'; //phpcs:ignore WordPress.Security.EscapeOutput ?>"><?php echo esc_html__( $affiliate_id ); ?></a>
</li>
<li>
<strong><?php echo esc_html__( 'Referral ID:', 'wp-marketing-automations-pro' ); ?> </strong>
<span><?php echo esc_html__( $global_data['referral_id'] ); ?></span>
</li>
<li>
<strong><?php echo esc_html__( 'Old Status:', 'wp-marketing-automations-pro' ); ?> </strong>
<?php echo esc_html__( $global_data['old_status'] ); ?>
</li>
<li>
<strong><?php echo esc_html__( 'New Status:', 'wp-marketing-automations-pro' ); ?> </strong>
<?php echo esc_html__( 'rejected' ); ?>
</li>
<?php
return ob_get_clean();
}
/**
* Set global data for all the merge tags which are supported by this event.
*
* @param $task_meta
*/
public function set_merge_tags_data( $task_meta ) {
$get_data = BWFAN_Merge_Tag_Loader::get_data( 'referral_id' );
if ( ( empty( $get_data ) || intval( $get_data ) !== intval( $task_meta['global']['referral_id'] ) ) ) {
$set_data = array(
'affiliate_id' => intval( $task_meta['global']['affiliate_id'] ),
'referral_id' => intval( $task_meta['global']['referral_id'] ),
'user_id' => intval( $task_meta['global']['user_id'] ),
);
BWFAN_Merge_Tag_Loader::set_data( $set_data );
}
}
/**
* Capture the async data for the current event.
* @return array|bool
*/
public function capture_async_data() {
$this->referral_id = BWFAN_Common::$events_async_data['referral_id'];
$this->old_status = BWFAN_Common::$events_async_data['old_status'];
$referral = affwp_get_referral( $this->referral_id );
$this->affiliate_id = $referral->affiliate_id;
$this->user_id = affwp_get_affiliate_user_id( $this->affiliate_id );
return $this->run_automations();
}
public function get_email_event() {
if ( ! empty( absint( $this->user_id ) ) ) {
$user = get_user_by( 'id', absint( $this->user_id ) );
return ( $user instanceof WP_User ) ? $user->user_email : false;
}
return false;
}
public function get_user_id_event() {
return ! empty( absint( $this->user_id ) ) ? absint( $this->user_id ) : false;
}
/**
* Capture the async data for the current event.
* @return array|bool
*/
public function capture_v2_data( $automation_data ) {
$this->referral_id = BWFAN_Common::$events_async_data['referral_id'];
$this->old_status = BWFAN_Common::$events_async_data['old_status'];
$referral = affwp_get_referral( $this->referral_id );
$this->affiliate_id = $referral->affiliate_id;
$this->user_id = affwp_get_affiliate_user_id( $this->affiliate_id );
$automation_data['affiliate_id'] = $this->affiliate_id;
$automation_data['referral_id'] = $this->referral_id;
$automation_data['old_status'] = $this->old_status;
$automation_data['user_id'] = $this->user_id;
return $automation_data;
}
/**
* v2 Method: Get field schema
* @return array
*/
public function get_field_schema() {
return [];
}
}
/**
* Register this event to a source.
* This will show the current event in dropdown in single automation screen.
*/
if ( bwfan_is_affiliatewp_active() ) {
return 'BWFAN_AFFWP_Referral_Rejected';
}

View File

@@ -0,0 +1,139 @@
<?php
#[AllowDynamicProperties]
final class BWFAN_AFFWP_Referral_Signup extends BWFAN_Event {
private static $instance = null;
public $affiliate_id = null;
public $referral_id = null;
public $first_name = '';
public $last_name = '';
public $email = '';
private function __construct() {
$this->event_merge_tag_groups = array( 'aff_affiliate', 'bwf_contact' );
$this->optgroup_label = __( 'AffiliateWP', 'wp-marketing-automations-pro' );
$this->event_name = __( 'Referral Sign Up', 'wp-marketing-automations-pro' );
$this->event_desc = __( 'This event runs after an Referral signed up.', 'wp-marketing-automations-pro' );
$this->event_rule_groups = array(
'affiliatewp',
'bwf_contact_segments',
'bwf_contact',
'bwf_contact_fields',
'bwf_contact_user',
'bwf_contact_wc',
'bwf_contact_geo',
'bwf_engagement',
'bwf_broadcast'
);
$this->priority = 63;
$this->is_time_independent = false;
$this->v2 = true;
$this->support_v1 = false;
}
public static function get_instance() {
if ( null === self::$instance ) {
self::$instance = new self();
}
return self::$instance;
}
public function load_hooks() {
add_action( 'affwp_insert_referral', array( $this, 'referral_created' ), 999, 1 );
}
/**
* @param $affiliate_id
* @param $status
* @param $args
*/
public function referral_created( $referral_id ) {
$referral = affwp_get_referral( $referral_id );
if ( ! $referral ) {
return;
}
if ( empty( $referral->affiliate_id ) ) {
return;
}
$this->referral_id = $referral_id;
$this->affiliate_id = $referral->affiliate_id;
$this->process( $referral->affiliate_id, $referral_id );
}
/**
* Make the required data for the current event and send it asynchronously.
*/
public function process( $affiliate_id, $referral_id ) {
$data = $this->get_default_data();
$data['affiliate_id'] = $affiliate_id;
$data['referral_id'] = $referral_id;
$this->send_async_call( $data );
}
public function capture_v2_data( $automation_data ) {
$this->affiliate_id = BWFAN_Common::$events_async_data['affiliate_id'];
$this->referral_id = BWFAN_Common::$events_async_data['referral_id'];
$referral = affwp_get_referral( $this->referral_id );
if ( ! $referral || empty( $referral->customer_id ) ) {
return '';
}
$customer_data = BWFAN_PRO_Common::get_referral_data( $referral->customer_id );
$email = isset( $customer_data['email'] ) ? $customer_data['email'] : '';
$this->email = ! empty( $email ) ? $email : affwp_get_affiliate_email( $this->affiliate_id );
$this->first_name = isset( $customer_data['first_name'] ) ? $customer_data['first_name'] : '';
$this->last_name = isset( $customer_data['last_name'] ) ? $customer_data['last_name'] : '';
$automation_data['affiliate_id'] = $this->affiliate_id;
$automation_data['referral_count'] = $this->referral_id;
$automation_data['email'] = $this->email;
$automation_data['last_name'] = $this->last_name;
$automation_data['first_name'] = $this->first_name;
return $automation_data;
}
public function get_event_data() {
$data_to_send = [ 'global' => [] ];
$data_to_send['global']['affiliate_id'] = $this->affiliate_id;
$data_to_send['global']['referral_id'] = $this->referral_id;
$data_to_send['global']['email'] = $this->email;
return $data_to_send;
}
/**
* Set global data for all the merge tags which are supported by this event.
*
* @param $task_meta
*/
public function set_merge_tags_data( $task_meta ) {
$get_data = BWFAN_Merge_Tag_Loader::get_data( 'affiliate_id' );
if ( ( empty( $get_data ) || intval( $get_data ) !== intval( $task_meta['global']['affiliate_id'] ) ) ) {
$set_data = array(
'affiliate_id' => intval( $task_meta['global']['affiliate_id'] ),
'referral_id' => intval( $task_meta['global']['referral_id'] ),
'email' => $task_meta['global']['email'],
);
BWFAN_Merge_Tag_Loader::set_data( $set_data );
}
}
/**
* v2 Method: Get field schema
* @return array
*/
public function get_field_schema() {
return [];
}
}
/**
* Register this event to a source.
* This will show the current event in dropdown in single automation screen.
*/
if ( bwfan_is_affiliatewp_active() ) {
return 'BWFAN_AFFWP_Referral_Signup';
}

View File

@@ -0,0 +1,215 @@
<?php
if ( ! class_exists( 'BWFAN_AFFWP_Referral_Status_Change' ) ) {
#[AllowDynamicProperties]
final class BWFAN_AFFWP_Referral_Status_Change extends BWFAN_Event {
private static $instance = null;
public $referral_id = null;
public $affiliate_id = null;
public $from_status = null;
public $to_status = null;
public $email = null;
private function __construct() {
$this->event_name = __( 'Referral Status Changed', 'wp-marketing-automations-pro' );
$this->event_desc = __( 'This event runs after an referrals status is changed.', 'wp-marketing-automations-pro' );
$this->event_merge_tag_groups = array( 'aff_affiliate', 'aff_report', 'bwf_contact' );
$this->event_rule_groups = array(
'affiliatewp',
'affiliate_report',
'bwf_contact_segments',
'bwf_contact',
'bwf_contact_fields',
'bwf_contact_user',
'bwf_contact_wc',
'bwf_contact_geo',
'bwf_engagement',
'bwf_broadcast'
);
$this->optgroup_label = __( 'AffiliateWP', 'wp-marketing-automations-pro' );
$this->priority = 61;
$this->is_time_independent = true;
$this->v2 = true;
$this->support_v1 = false;
}
public function load_hooks() {
add_action( 'affwp_set_referral_status', array( $this, 'affwp_referral_status_changed' ), 11, 3 );
}
public static function get_instance() {
if ( null === self::$instance ) {
self::$instance = new self();
}
return self::$instance;
}
public function affwp_referral_status_changed( $referral_id, $to_status, $from_status ) {
$this->referral_id = $referral_id;
$this->from_status = $from_status;
$this->to_status = $to_status;
$this->process( $this->referral_id, $to_status, $from_status );
}
/**
* Make the required data for the current event and send it asynchronously.
*
* @param $referral_id
* @param $from_status
* @param $to_status
*/
public function process( $referral_id, $to_status, $from_status ) {
$referral = affwp_get_referral( $referral_id );
if ( ! $referral ) {
return;
}
$affiliate_id = $referral->affiliate_id;
if ( empty( $referral->affiliate_id ) ) {
return;
}
$data = $this->get_default_data();
$data['affiliate_id'] = $affiliate_id;
$data['referral_id'] = $referral_id;
$data['from_status'] = $from_status;
$data['to_status'] = $to_status;
/** Run v2 automation */
$this->send_async_call( $data );
}
public function capture_v2_data( $automation_data ) {
$this->affiliate_id = BWFAN_Common::$events_async_data['affiliate_id'];
$this->referral_id = BWFAN_Common::$events_async_data['referral_id'];
$this->referral_id = BWFAN_Common::$events_async_data['referral_id'];
$referral = affwp_get_referral( $this->referral_id );
if ( ! $referral || empty( $referral->customer_id ) ) {
return '';
}
$customer_data = BWFAN_PRO_Common::get_referral_data( $referral->customer_id );
$email = isset( $customer_data['email'] ) ? $customer_data['email'] : '';
$this->email = ! empty( $email ) ? $email : affwp_get_affiliate_email( $this->affiliate_id );
$automation_data['affiliate_id'] = $this->affiliate_id;
$automation_data['referral_count'] = $this->referral_id;
$automation_data['email'] = $this->email;
return $automation_data;
}
public function get_event_data() {
$data_to_send = [ 'global' => [] ];
$data_to_send['global']['affiliate_id'] = $this->affiliate_id;
$data_to_send['global']['referral_id'] = $this->referral_id;
$data_to_send['global']['email'] = $this->email;
return $data_to_send;
}
/**
* Set global data for all the merge tags which are supported by this event.
*
* @param $task_meta
*/
public function set_merge_tags_data( $task_meta ) {
$referral_id = BWFAN_Merge_Tag_Loader::get_data( 'referral_id' );
if ( empty( $referral_id ) ) {
$set_data = array(
'referral_id' => $task_meta['global']['referral_id'],
'affiliate_id' => $task_meta['global']['affiliate_id'],
'email' => $task_meta['global']['email'],
);
BWFAN_Merge_Tag_Loader::set_data( $set_data );
}
}
/**
* validate v2 event settings
* @return bool
*/
public function validate_v2_event_settings( $automation_data ) {
if ( ! isset( $automation_data['event_meta'] ) || empty( $automation_data['event_meta'] ) || ! is_array( $automation_data['event_meta'] ) ) {
return false;
}
$current_automation_event_meta = $automation_data['event_meta'];
$current_status_to = isset( $current_automation_event_meta['to'] ) ? $current_automation_event_meta['to'] : '';
$current_status_from = isset( $current_automation_event_meta['from'] ) ? $current_automation_event_meta['from'] : '';
/** from any to any status checking */
if ( ( 'affwp-any' === $current_status_from && 'affwp-any' === $current_status_to ) ) {
return true;
}
/** checking any status to selected status */
if ( 'affwp-any' === $current_status_from ) {
return ( $automation_data['to_status'] === $current_status_to );
}
/** checking selected status to any status */
if ( 'affwp-any' === $current_status_to ) {
return ( $automation_data['from_status'] === $current_status_from );
}
/** checking selected status to selected status */
return ( ( $automation_data['from_status'] === $current_status_from ) && ( $automation_data['to_status'] === $current_status_to ) );
}
/**
* v2 Method: Get fields schema
* @return array[][]
*/
public function get_fields_schema() {
$default = [
'affwp-any' => 'Any'
];
$status = array_replace( $default, self::get_referral_status() );
$status = BWFAN_Common::prepared_field_options( $status );
return [
[
'id' => 'from',
'type' => 'wp_select',
'options' => $status,
'placeholder' => __( 'Select Status', 'wp-marketing-automations-pro' ),
'label' => __( 'From Status', 'wp-marketing-automations-pro' ),
"class" => 'bwfan-input-wrapper bwf-3-col-item',
"required" => true,
"description" => ""
],
[
'id' => 'to',
'type' => 'wp_select',
'options' => $status,
'label' => __( 'To Status', 'wp-marketing-automations-pro' ),
'placeholder' => __( 'Select Status', 'wp-marketing-automations-pro' ),
"class" => 'bwfan-input-wrapper bwf-3-col-item',
"required" => true,
"description" => ""
],
];
}
public static function get_referral_status() {
return array(
'pending' => __( 'Pending', 'wp-marketing-automations-pro' ),
'unpaid' => __( 'Unpaid (Accepted)', 'wp-marketing-automations-pro' ),
'paid' => __( 'Paid', 'wp-marketing-automations-pro' ),
'rejected' => __( 'Rejected', 'wp-marketing-automations-pro' )
);
}
/** set default values */
public function get_default_values() {
return [
'from' => 'affwp-any',
'to' => 'affwp-any',
];
}
}
/**
* Register this event to a source.
* This will show the current event in dropdown in single automation screen.
*/
if ( bwfan_is_affiliatewp_active() ) {
return 'BWFAN_AFFWP_Referral_Status_Change';
}
}

View File

@@ -0,0 +1,200 @@
<?php
#[AllowDynamicProperties]
final class BWFAN_AFFWP_Signup extends BWFAN_Event {
private static $instance = null;
public $affiliate_id = null;
public $status = null;
public $user_id = null;
private function __construct() {
$this->event_merge_tag_groups = array( 'aff_affiliate', 'bwf_contact' );
$this->optgroup_label = esc_html__( 'AffiliateWP', 'wp-marketing-automations-pro' );
$this->event_name = esc_html__( 'Application Sign Up', 'wp-marketing-automations-pro' );
$this->event_desc = esc_html__( 'This event runs after an affiliate signed up.', 'wp-marketing-automations-pro' );
$this->event_rule_groups = array(
'affiliatewp',
'bwf_contact_segments',
'bwf_contact',
'bwf_contact_fields',
'bwf_contact_user',
'bwf_contact_wc',
'bwf_contact_geo',
'bwf_engagement',
'bwf_broadcast'
);
$this->priority = 10;
$this->customer_email_tag = '{{affwp_affiliate_email}}';
$this->v2 = true;
}
public static function get_instance() {
if ( null === self::$instance ) {
self::$instance = new self();
}
return self::$instance;
}
public function load_hooks() {
add_action( 'affwp_register_user', array( $this, 'affiliate_created' ), 999, 3 );
add_action( 'affwp_auto_register_user', array( $this, 'affiliate_created' ), 999, 3 );
}
/**
* @param $affiliate_id
* @param $status
* @param $args
*/
public function affiliate_created( $affiliate_id, $status, $args ) {
$this->affiliate_id = $affiliate_id;
$this->status = $status;
$this->process();
}
/**
* Make the required data for the current event and send it asynchronously.
*/
public function process() {
$data = $this->get_default_data();
$data['affiliate_id'] = $this->affiliate_id;
$data['status'] = $this->status;
$this->send_async_call( $data );
}
/**
* Registers the tasks for current event.
*
* @param $automation_id
* @param $integration_data
* @param $event_data
*/
public function register_tasks( $automation_id, $integration_data, $event_data ) {
if ( ! is_array( $integration_data ) ) {
return;
}
$data_to_send = $this->get_event_data();
$this->create_tasks( $automation_id, $integration_data, $event_data, $data_to_send );
}
public function get_event_data() {
$data_to_send = [ 'global' => [] ];
$data_to_send['global']['affiliate_id'] = $this->affiliate_id;
$data_to_send['global']['status'] = $this->status;
$data_to_send['global']['user_id'] = $this->user_id;
return $data_to_send;
}
/**
* Make the view data for the current event which will be shown in task listing screen.
*
* @param $global_data
*
* @return false|string
*/
public function get_task_view( $global_data ) {
ob_start();
$affiliate_id = isset( $global_data['affiliate_id'] ) ? $global_data['affiliate_id'] : 0;
?>
<li>
<strong><?php echo esc_html__( 'Affiliate Id:', 'wp-marketing-automations-pro' ); ?> </strong>
<a target="_blank" href="<?php echo admin_url( 'admin.php' ) . '?page=affiliate-wp-affiliates&affiliate_id=' . $affiliate_id . '&action=edit_affiliate'; //phpcs:ignore WordPress.Security.EscapeOutput ?>"><?php echo esc_html__( $affiliate_id ); ?></a>
</li>
<li>
<strong><?php echo esc_html__( 'Status:', 'wp-marketing-automations-pro' ); ?> </strong>
<span><?php echo esc_html__( $global_data['status'] ); ?></span>
</li>
<?php
return ob_get_clean();
}
/**
* Capture the async data for the current event.
* @return array|bool
*/
public function capture_async_data() {
$this->affiliate_id = BWFAN_Common::$events_async_data['affiliate_id'];
$this->status = BWFAN_Common::$events_async_data['status'];
$this->user_id = affwp_get_affiliate_user_id( $this->affiliate_id );
return $this->run_automations();
}
public function get_email_event() {
if ( ! empty( absint( $this->user_id ) ) ) {
$user = get_user_by( 'id', absint( $this->user_id ) );
return ( $user instanceof WP_User ) ? $user->user_email : false;
}
return false;
}
public function get_user_id_event() {
return ! empty( absint( $this->user_id ) ) ? absint( $this->user_id ) : false;
}
/**
* Set global data for all the merge tags which are supported by this event.
*
* @param $task_meta
*/
public function set_merge_tags_data( $task_meta ) {
$get_data = BWFAN_Merge_Tag_Loader::get_data( 'affiliate_id' );
if ( ( empty( $get_data ) || intval( $get_data ) !== intval( $task_meta['global']['affiliate_id'] ) ) ) {
$set_data = array(
'affiliate_id' => intval( $task_meta['global']['affiliate_id'] ),
'user_id' => intval( $task_meta['global']['user_id'] ),
);
BWFAN_Merge_Tag_Loader::set_data( $set_data );
}
}
/**
* Set up rules data
*
* @param $value
*/
public function pre_executable_actions( $value ) {
BWFAN_Core()->rules->setRulesData( $this->affiliate_id, 'affiliate_id' );
BWFAN_Core()->rules->setRulesData( $this->user_id, 'user_id' );
}
/**
* Capture the async data for the current event.
* @return array|bool
*/
public function capture_v2_data( $automation_data ) {
$this->affiliate_id = BWFAN_Common::$events_async_data['affiliate_id'];
$this->status = BWFAN_Common::$events_async_data['status'];
$this->user_id = affwp_get_affiliate_user_id( $this->affiliate_id );
$automation_data['affiliate_id'] = $this->affiliate_id;
$automation_data['status'] = $this->status;
$automation_data['user_id'] = $this->user_id;
return $automation_data;
}
/**
* v2 Method: Get field schema
* @return array
*/
public function get_field_schema() {
return [];
}
}
/**
* Register this event to a source.
* This will show the current event in dropdown in single automation screen.
*/
if ( bwfan_is_affiliatewp_active() ) {
return 'BWFAN_AFFWP_Signup';
}

View File

@@ -0,0 +1,475 @@
<?php
#[AllowDynamicProperties]
final class BWFAN_AFFWP_Status_Change extends BWFAN_Event {
private static $instance = null;
public $affiliate_id = null;
public $from_status = null;
public $to_status = null;
public $user_id = null;
private function __construct() {
$this->optgroup_label = esc_html__( 'AffiliateWP', 'wp-marketing-automations-pro' );
$this->event_name = esc_html__( 'Affiliate Status Change', 'wp-marketing-automations-pro' );
$this->event_desc = esc_html__( 'This event runs after an affiliate status is changed.', 'wp-marketing-automations-pro' );
$this->event_merge_tag_groups = array( 'aff_affiliate', 'bwf_contact' );
$this->event_rule_groups = array(
'affiliatewp',
'bwf_contact_segments',
'bwf_contact',
'bwf_contact_fields',
'bwf_contact_user',
'bwf_contact_wc',
'bwf_contact_geo',
'bwf_engagement',
'bwf_broadcast'
);
$this->priority = 15.6;
$this->support_lang = true;
$this->v2 = true;
}
public static function get_instance() {
if ( null === self::$instance ) {
self::$instance = new self();
}
return self::$instance;
}
public function load_hooks() {
add_action( 'affwp_set_affiliate_status', array( $this, 'process' ), 11, 3 );
}
/**
* Localize data for html fields for the current event.
*/
public function admin_enqueue_assets() {
if ( false === BWFAN_Common::is_load_admin_assets( 'automation' ) ) {
return;
}
$wc_affiliate_statuses = $this->get_view_data();
BWFAN_Core()->admin->set_events_js_data( $this->get_slug(), 'from_options', $wc_affiliate_statuses );
BWFAN_Core()->admin->set_events_js_data( $this->get_slug(), 'to_options', $wc_affiliate_statuses );
}
public function get_view_data() {
$all_status = affwp_get_affiliate_statuses();
return $all_status;
}
/**
* Show the html fields for the current event.
*/
public function get_view( $db_eventmeta_saved_value ) {
?>
<script type="text/html" id="tmpl-event-<?php esc_attr_e( $this->get_slug() ); ?>">
<#
selected_from_status = (_.has(data, 'eventSavedData') &&_.has(data.eventSavedData, 'from')) ? data.eventSavedData.from : '';
selected_to_status = (_.has(data, 'eventSavedData') &&_.has(data.eventSavedData, 'to')) ? data.eventSavedData.to : '';
#>
<div class="bwfan_mt15"></div>
<div class="bwfan-col-sm-6 bwfan-pl-0">
<label for="" class="bwfan-label-title"><?php esc_html_e( 'From Status', 'wp-marketing-automations-pro' ); ?></label>
<select required id="" class="bwfan-input-wrapper" name="event_meta[from]">
<option value="any"><?php esc_html_e( 'Any', 'wp-marketing-automations-pro' ); ?></option>
<#
if(_.has(data.eventFieldsOptions, 'from_options') && _.isObject(data.eventFieldsOptions.from_options) ) {
_.each( data.eventFieldsOptions.from_options, function( value, key ){
selected = (key == selected_from_status) ? 'selected' : '';
#>
<option value="{{key}}" {{selected}}>{{value}}</option>
<# })
}
#>
</select>
</div>
<div class="bwfan-col-sm-6 bwfan-pr-0">
<label for="" class="bwfan-label-title"><?php esc_html_e( 'To Status', 'wp-marketing-automations-pro' ); ?></label>
<select required id="" class="bwfan-input-wrapper" name="event_meta[to]">
<option value="any"><?php esc_html_e( 'Any', 'wp-marketing-automations-pro' ); ?></option>
<#
if(_.has(data.eventFieldsOptions, 'to_options') && _.isObject(data.eventFieldsOptions.to_options) ) {
_.each( data.eventFieldsOptions.to_options, function( value, key ){
selected = (key == selected_to_status) ? 'selected' : '';
#>
<option value="{{key}}" {{selected}}>{{value}}</option>
<# })
}
#>
</select>
</div>
</script>
<?php
}
public function get_email_event() {
$user = ! empty( $this->user_id ) ? get_user_by( 'id', absint( $this->user_id ) ) : false;
return ( $user instanceof WP_User ) ? $user->user_email : false;
}
public function get_user_id_event() {
return ! empty( $this->user_id ) ? absint( $this->user_id ) : false;
}
/**
* Set up rules data
*
* @param $value
*/
public function pre_executable_actions( $value ) {
BWFAN_Core()->rules->setRulesData( $this->affiliate_id, 'affiliate_id' );
BWFAN_Core()->rules->setRulesData( $this->user_id, 'user_id' );
}
public function handle_single_automation_run( $value1, $automation_id ) {
$is_register_task = false;
$to_status = $this->to_status;
$from_status = $this->from_status;
$event_meta = $value1['event_meta'];
$from = $event_meta['from'];
$to = $event_meta['to'];
if ( 'any' === $from && 'any' === $to ) {
$is_register_task = true;
} elseif ( 'any' === $from && $to_status === $to ) {
$is_register_task = true;
} elseif ( $from_status === $from && 'any' === $to ) {
$is_register_task = true;
} elseif ( $from_status === $from && $to_status === $to ) {
$is_register_task = true;
}
if ( $is_register_task ) {
$all_statuses = affwp_get_affiliate_statuses();
$value1['from'] = $all_statuses[ $from_status ];
$value1['to'] = $all_statuses[ $to_status ];
return parent::handle_single_automation_run( $value1, $automation_id );
}
return '';
}
/**
* Check if the data provided in the Event is valid or not.
*
* @param $task_details
*
* @return array|mixed
*/
public function validate_event( $task_details ) {
$result = [];
$task_event = $task_details['event_data']['event_slug'];
$automation_id = $task_details['processed_data']['automation_id'];
$automation_details = BWFAN_Model_Automations::get_automation_with_data( $automation_id );
$current_automation_event = $automation_details['event'];
$current_automation_event_meta = $automation_details['meta']['event_meta'];
/** Current automation event does not match with the event of task when the task was made */
if ( $task_event !== $current_automation_event ) {
$result = $this->get_automation_event_status();
return $result;
}
$current_automation_status_from = $current_automation_event_meta['from'];
$current_automation_status_to = $current_automation_event_meta['to'];
/** Status Any to Any case */
if ( 'any' === $current_automation_status_from && 'any' === $current_automation_status_to ) {
$result = $this->get_automation_event_success();
return $result;
}
$affiliate_from_status = strtolower( $task_details['processed_data']['from'] );
$affiliate_to_status = strtolower( $task_details['processed_data']['to'] );
if ( $affiliate_from_status === $current_automation_status_from && $affiliate_to_status === $current_automation_status_to ) {
$result = $this->get_automation_event_success();
return $result;
}
if ( 'any' === $current_automation_status_from && $affiliate_to_status === $current_automation_status_to ) {
$result = $this->get_automation_event_success();
return $result;
}
if ( $affiliate_from_status === $current_automation_status_from && 'any' === $current_automation_status_to ) {
$result = $this->get_automation_event_success();
return $result;
}
$result['status'] = 4;
$result['message'] = __( 'Affiliate Status not validated', 'wp-marketing-automations-pro' );
return $result;
}
/**
* Make the required data for the current event and send it asynchronously.
*
* @param $affiliate_id
* @param $from_status
* @param $to_status
*/
public function process( $affiliate_id, $to_status, $from_status ) {
$data = $this->get_default_data();
$data['affiliate_id'] = $affiliate_id;
$data['from_status'] = $from_status;
$data['to_status'] = $to_status;
$this->send_async_call( $data );
}
/**
* Returns the current event settings set in the automation at the time of task creation.
*
* @param $value
*
* @return array
*/
public function get_automation_event_data( $value ) {
$event_meta = $value['event_meta'];
$event_data = [
'event_source' => $value['source'],
'event_slug' => $value['event'],
'validate_event' => 1,
'from_status' => isset( $event_meta['from'] ) ? $event_meta['from'] : '',
'to_status' => isset( $event_meta['to'] ) ? $event_meta['to'] : '',
'from' => isset( $value['from'] ) ? $value['from'] : '',
'to' => isset( $value['to'] ) ? $value['to'] : '',
];
return $event_data;
}
/**
* Registers the tasks for current event.
*
* @param $automation_id
* @param $actions : after processing events data
* @param $event_data
*/
public function register_tasks( $automation_id, $actions, $event_data ) {
if ( ! is_array( $actions ) ) {
return;
}
$data_to_send = $this->get_event_data( $event_data );
$this->create_tasks( $automation_id, $actions, $event_data, $data_to_send );
}
public function get_event_data( $event_data = array() ) {
$data_to_send = [ 'global' => [] ];
$data_to_send['global']['affiliate_id'] = $this->affiliate_id;
$data_to_send['global']['from'] = isset( $event_data['from_status'] ) ? $event_data['from_status'] : '';
$data_to_send['global']['to'] = isset( $event_data['to_status'] ) ? $event_data['to_status'] : '';
$data_to_send['global']['email'] = affwp_get_affiliate_email( $this->affiliate_id );
$data_to_send['global']['user_id'] = affwp_get_affiliate_user_id( $this->affiliate_id );
return $data_to_send;
}
/**
* Make the view data for the current event which will be shown in task listing screen.
*
* @param $global_data
*
* @return false|string
*/
public function get_task_view( $global_data ) {
ob_start();
$affiliate = affwp_get_affiliate( $global_data['affiliate_id'] );
$args = array(
'affiliate_id' => $global_data['affiliate_id'],
'page' => 'affiliate-wp-affiliates',
'action' => 'edit_affiliate'
);
$affiliate_edit_link = add_query_arg( $args, admin_url() . 'admin.php' );
?>
<li>
<strong><?php esc_html_e( 'Affiliate ID:', 'wp-marketing-automations-pro' ); ?> </strong>
<a target="_blank" href="<?php echo $affiliate_edit_link; //phpcs:ignore WordPress.Security.EscapeOutput
?>"><?php echo '#' . esc_html( $global_data['affiliate_id'] . ' ' . affwp_get_affiliate_name( $affiliate ) ); ?></a>
</li>
<li>
<strong><?php esc_html_e( 'Email:', 'wp-marketing-automations-pro' ); ?> </strong>
<?php esc_html_e( $global_data['email'] ); ?>
</li>
<li>
<strong><?php esc_html_e( 'From Status:', 'wp-marketing-automations-pro' ); ?> </strong>
<?php esc_html_e( $global_data['from'] ); ?>
</li>
<li>
<strong><?php esc_html_e( 'To Status:', 'wp-marketing-automations-pro' ); ?> </strong>
<?php esc_html_e( $global_data['to'] ); ?>
</li>
<?php
return ob_get_clean();
}
public function validate_event_data_before_executing_task( $data ) {
return $this->validate_affiliate( $data );
}
public function validate_affiliate( $data ) {
if ( ! isset( $data['affiliate_id'] ) ) {
return false;
}
$affiliate = affwp_get_affiliate( $data['affiliate_id'] );
if ( $affiliate instanceof \AffWP\Affiliate ) {
return true;
}
return false;
}
/**
* Set global data for all the merge tags which are supported by this event.
*
* @param $task_meta
*/
public function set_merge_tags_data( $task_meta ) {
$get_data = BWFAN_Merge_Tag_Loader::get_data( 'affiliate_id' );
if ( ( empty( $get_data ) || intval( $get_data ) !== intval( $task_meta['global']['affiliate_id'] ) ) ) {
$set_data = array(
'affiliate_id' => intval( $task_meta['global']['affiliate_id'] ),
'user_id' => intval( $task_meta['global']['user_id'] ),
);
BWFAN_Merge_Tag_Loader::set_data( $set_data );
}
}
/**
* Capture the async data for the current event.
* @return array|bool
*/
public function capture_async_data() {
$affiliate_id = BWFAN_Common::$events_async_data['affiliate_id'];
$from_status = BWFAN_Common::$events_async_data['from_status'];
$to_status = BWFAN_Common::$events_async_data['to_status'];
$this->affiliate_id = $affiliate_id;
$this->from_status = $from_status;
$this->to_status = $to_status;
$this->user_id = affwp_get_affiliate_user_id( $this->affiliate_id );
return $this->run_automations();
}
/**
* v2 Method: Validate event settings
*
* @param $automation_data
*
* @return bool
*/
public function validate_v2_event_settings( $automation_data ) {
if ( ! isset( $automation_data['event_meta'] ) || empty( $automation_data['event_meta'] ) ) {
return false;
}
$current_automation_status_from = $automation_data['event_meta']['from'];
$current_automation_status_to = $automation_data['event_meta']['to'];
/** Status Any to Any case */
if ( 'any' === $current_automation_status_from && 'any' === $current_automation_status_to ) {
return true;
}
$affiliate_from_status = strtolower( $automation_data['from_status'] );
$affiliate_to_status = strtolower( $automation_data['to_status'] );
if ( $affiliate_from_status === $current_automation_status_from && $affiliate_to_status === $current_automation_status_to ) {
return true;
}
if ( 'any' === $current_automation_status_from && $affiliate_to_status === $current_automation_status_to ) {
return true;
}
if ( $affiliate_from_status === $current_automation_status_from && 'any' === $current_automation_status_to ) {
return true;
}
return false;
}
/**
* Capture the async v2 data for the current event.
* @return array|bool
*/
public function capture_v2_data( $automation_data ) {
$affiliate_id = BWFAN_Common::$events_async_data['affiliate_id'];
$from_status = BWFAN_Common::$events_async_data['from_status'];
$to_status = BWFAN_Common::$events_async_data['to_status'];
$this->affiliate_id = $affiliate_id;
$this->from_status = $from_status;
$this->to_status = $to_status;
$this->user_id = affwp_get_affiliate_user_id( $this->affiliate_id );
$automation_data['from_status'] = $this->from_status;
$automation_data['affiliate_id'] = $this->affiliate_id;
$automation_data['to_status'] = $this->to_status;
$automation_data['user_id'] = $this->user_id;
return $automation_data;
}
/**
* v2 Method: Get field schema
* @return array
*/
public function get_fields_schema() {
$status = array_replace( [ 'any' => 'Any' ], $this->get_view_data() );
$status = BWFAN_PRO_Common::prepared_field_options( $status );
return [
[
'id' => 'from',
'type' => 'wp_select',
'label' => __( 'From status', 'wp-marketing-automations-pro' ),
'options' => $status,
'placeholder' => __( "Choose Status", 'wp-marketing-automations-pro' ),
'tip' => "",
"description" => "",
"required" => true,
],
[
'id' => 'to',
'type' => 'wp_select',
'label' => __( 'To status', 'wp-marketing-automations-pro' ),
'options' => $status,
'placeholder' => __( "Choose Status", 'wp-marketing-automations-pro' ),
'tip' => "",
"description" => "",
"required" => true,
],
];
}
public function get_default_values() {
return [
'from' => 'any',
'to' => 'any',
];
}
}
/**
* Register this event to a source.
* This will show the current event in dropdown in single automation screen.
*/
if ( bwfan_is_affiliatewp_active() ) {
return 'BWFAN_AFFWP_Status_Change';
}

View File

@@ -0,0 +1,2 @@
<?php
// Silence is golden.

View File

@@ -0,0 +1,2 @@
<?php
// Silence is golden.