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,243 @@
<?php
final class BWFAN_WLM_Add_User_To_Pay_Per_Post extends BWFAN_Action {
private static $ins = null;
protected function __construct() {
$this->action_name = __( 'Add User to Pay Per Post', 'wp-marketing-automations-pro' );
$this->required_fields = array( 'user_id', 'content_id' );
$this->support_v2 = true;
$this->action_priority = 35;
}
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' ) ) {
$pay_per_posts = $this->get_view_data();
BWFAN_Core()->admin->set_actions_js_data( $this->get_class_slug(), 'pay_per_posts', $pay_per_posts );
}
}
/**
* @return array
*/
public function get_view_data() {
global $WishListMemberInstance;
$pay_per_posts = $WishListMemberInstance->get_pay_per_posts( array( 'ID', 'post_title' ), false );
$options = array();
if ( ! empty( $pay_per_posts ) ) {
foreach ( $pay_per_posts as $ppp ) {
$options[ $ppp->ID ] = $ppp->post_title;
}
}
return $options;
}
/**
* Show the html fields for the current action.
*/
public function get_view() {
?>
<script>
jQuery(document).ready(function ($) {
$('body').on('select2:select', '.bwfan-ppp-search', function (e) {
var temp_ppp = {};
var ppp_data = $(this).select2('data');
ppp_data.forEach(function (item) {
temp_ppp[item.id] = item.text;
});
$(this).parent().find('.bwfan_searched_ppp_name').val(JSON.stringify(temp_ppp));
});
});
</script>
<script type="text/html" id="tmpl-action-<?php echo esc_html__( $this->get_slug() ); ?>">
<#
searched_ppp = (_.has(data.actionSavedData, 'data') && _.has(data.actionSavedData.data, 'searched_ppp')) ? data.actionSavedData.data.searched_ppp : '';
selected_content_id = (_.has(data.actionSavedData, 'data') && _.has(data.actionSavedData.data, 'content_id')) ? data.actionSavedData.data.content_id : {};
#>
<div class="bwfan-input-form clearfix">
<label for="" class="bwfan-label-title"><?php esc_html_e( 'Select Pay Per Posts', 'wp-marketing-automations-pro' ); ?></label>
<select required id="" data-search="ppp" data-search-text="<?php esc_attr_e( 'Select Pay Per Posts', 'wp-marketing-automations-pro' ); ?>" class="bwfan-select2ajax-single bwfan-ppp-search bwfan-input-wrapper" name="bwfan[{{data.action_id}}][data][content_id][]" multiple>
<#
if(_.size(searched_ppp) >0) {
temp_selected_ppp = JSON.parse(searched_ppp);
_.each( selected_content_id, function( v ){
#>
<option value="{{v}}" selected>{{temp_selected_ppp[v]}}</option>
<#
})
}
#>
</select>
<input type="hidden" class="bwfan_searched_ppp_name" name="bwfan[{{data.action_id}}][data][searched_ppp]" value="{{searched_ppp}}"/>
</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(
'content_id' => $task_meta['data']['content_id'],
'user_id' => absint( $task_meta['global']['user_id'] ),
);
if ( empty( $data_to_set['user_id'] ) ) {
$email = ( isset( $task_meta['global']['email'] ) && is_email( $task_meta['global']['email'] ) ) ? $task_meta['global']['email'] : '';
$user = is_email( $email ) ? get_user_by( 'email', $email ) : '';
$data_to_set['user_id'] = $user instanceof WP_User ? $user->ID : 0;
}
return $data_to_set;
}
public function make_v2_data( $automation_data, $step_data ) {
$content_ids = isset( $step_data['content_id'] ) ? $step_data['content_id'] : [];
$content_ids = is_array( $content_ids ) && ! empty( $content_ids ) ? array_map( function ( $data ) {
return $data['id'];
}, $step_data['content_id'] ) : [];
$data_to_set = array();
$data_to_set['content_id'] = $content_ids;
$user_id = isset( $automation_data['global']['user_id'] ) ? $automation_data['global']['user_id'] : 0;
if ( 0 === absint( $user_id ) ) {
$email = ( isset( $automation_data['global']['email'] ) && is_email( $automation_data['global']['email'] ) ) ? $automation_data['global']['email'] : '';
$user = is_email( $email ) ? get_user_by( 'email', $email ) : '';
$user_id = $user instanceof WP_User ? $user->ID : 0;
}
$data_to_set['user_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,
'message' => 'User added to pay per post successfully',
);
}
return $result;
}
/**
* 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();
}
$user = get_userdata( $this->data['user_id'] );
if ( false === $user ) {
return array(
'status' => 4,
'message' => __( 'User does not exists', 'wp-marketing-automations-pro' ),
);
}
global $WishListMemberInstance;
foreach ( $this->data['content_id'] as $content_id ) {
$WishListMemberInstance->add_post_users( get_post_type( $content_id ), $content_id, $user->ID );
}
return true;
}
public function process_v2() {
$user = get_userdata( $this->data['user_id'] );
if ( false === $user ) {
return $this->skipped_response( __( 'User does not exists', 'wp-marketing-automations-pro' ) );
}
if ( empty( $this->data['content_id'] ) || ! is_array( $this->data['content_id'] ) ) {
return $this->skipped_response( __( 'Invalid pay per post', 'wp-marketing-automations-pro' ) );
}
global $WishListMemberInstance;
foreach ( $this->data['content_id'] as $content_id ) {
$WishListMemberInstance->add_post_users( get_post_type( $content_id ), $content_id, $user->ID );
};
return $this->success_message( __( 'User added to pay per post.', 'wp-marketing-automations-pro' ) );
}
public function get_fields_schema() {
return [
[
"id" => 'content_id',
"label" => __( 'Select Pay Per Post', 'wp-marketing-automations-pro' ),
"type" => 'custom_search',
'autocompleterOption' => [
'path' => 'wlm_pay_per_post',
'slug' => 'wlm_pay_per_post',
'labelText' => 'pay per post'
],
"allowFreeTextSearch" => false,
"required" => true,
"errorMsg" => __( "Pay Per Post is required", 'wp-marketing-automations-pro' ),
]
];
}
public function get_desc_text( $data ) {
$data = json_decode( wp_json_encode( $data ), true );
if ( ! isset( $data['content_id'] ) || empty( $data['content_id'] ) ) {
return '';
}
$content_ids = [];
foreach ( $data['content_id'] as $content_id ) {
if ( ! isset( $content_id['name'] ) || empty( $content_id['name'] ) ) {
continue;
}
$content_ids[] = $content_id['name'];
}
return $content_ids;
}
}
/**
* Register this action. Registering the action will make it eligible to see it on single automation screen in select actions dropdown.
*/
return 'BWFAN_WLM_Add_User_To_Pay_Per_Post';

View File

@@ -0,0 +1,217 @@
<?php
final class BWFAN_WLM_Remove_User_From_Pay_Per_Post extends BWFAN_Action {
private static $ins = null;
protected function __construct() {
$this->action_name = __( 'Remove User from Pay Per Post', 'wp-marketing-automations-pro' );
$this->required_fields = array( 'user_id', 'content_id' );
$this->support_v2 = true;
$this->action_priority = 40;
}
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
/**
* Show the html fields for the current action.
*/
public function get_view() {
?>
<script>
jQuery(document).ready(function ($) {
$('body').on('select2:select', '.bwfan-ppp-search', function (e) {
var temp_ppp = {};
var ppp_data = $(this).select2('data');
ppp_data.forEach(function (item) {
temp_ppp[item.id] = item.text;
});
$(this).parent().find('.bwfan_searched_ppp_name').val(JSON.stringify(temp_ppp));
});
});
</script>
<script type="text/html" id="tmpl-action-<?php echo esc_html__( $this->get_slug() ); ?>">
<#
searched_ppp = (_.has(data.actionSavedData, 'data') && _.has(data.actionSavedData.data, 'searched_ppp')) ? data.actionSavedData.data.searched_ppp : '';
selected_content_id = (_.has(data.actionSavedData, 'data') && _.has(data.actionSavedData.data, 'content_id')) ? data.actionSavedData.data.content_id : {};
#>
<div class="bwfan-input-form clearfix">
<label for="" class="bwfan-label-title"><?php esc_html_e( 'Select Pay Per Posts', 'wp-marketing-automations-pro' ); ?></label>
<select required id="" data-search="ppp" data-search-text="<?php esc_attr_e( 'Select Pay Per Posts', 'wp-marketing-automations-pro' ); ?>" class="bwfan-select2ajax-single bwfan-ppp-search bwfan-input-wrapper" name="bwfan[{{data.action_id}}][data][content_id][]" multiple>
<#
if(_.size(searched_ppp) >0) {
temp_selected_ppp = JSON.parse(searched_ppp);
_.each( selected_content_id, function( v ){
#>
<option value="{{v}}" selected>{{temp_selected_ppp[v]}}</option>
<#
})
}
#>
</select>
<input type="hidden" class="bwfan_searched_ppp_name" name="bwfan[{{data.action_id}}][data][searched_ppp]" value="{{searched_ppp}}"/>
</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(
'content_id' => $task_meta['data']['content_id'],
'user_id' => absint( $task_meta['global']['user_id'] ),
);
if ( empty( $data_to_set['user_id'] ) ) {
$email = ( isset( $task_meta['global']['email'] ) && is_email( $task_meta['global']['email'] ) ) ? $task_meta['global']['email'] : '';
$user = is_email( $email ) ? get_user_by( 'email', $email ) : '';
$data_to_set['user_id'] = $user instanceof WP_User ? $user->ID : 0;
}
return $data_to_set;
}
public function make_v2_data( $automation_data, $step_data ) {
$content_ids = isset( $step_data['content_id'] ) ? $step_data['content_id'] : [];
$content_ids = is_array( $content_ids ) && ! empty( $content_ids ) ? array_map( function ( $data ) {
return $data['id'];
}, $step_data['content_id'] ) : [];
$data_to_set = array();
$data_to_set['content_id'] = $content_ids;
$user_id = isset( $automation_data['global']['user_id'] ) ? $automation_data['global']['user_id'] : 0;
if ( 0 === absint( $user_id ) ) {
$email = ( isset( $automation_data['global']['email'] ) && is_email( $automation_data['global']['email'] ) ) ? $automation_data['global']['email'] : '';
$user = is_email( $email ) ? get_user_by( 'email', $email ) : '';
$user_id = $user instanceof WP_User ? $user->ID : 0;
}
$data_to_set['user_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,
'message' => 'User removed from pay per post successfully',
);
}
return $result;
}
/**
* 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();
}
$user = get_userdata( $this->data['user_id'] );
if ( false === $user ) {
return array(
'status' => 4,
'message' => __( 'User does not exists', 'wp-marketing-automations-pro' ),
);
}
global $WishListMemberInstance;
foreach ( $this->data['content_id'] as $content_id ) {
$WishListMemberInstance->remove_post_users( get_post_type( $content_id ), $content_id, $user->ID );
}
return true;
}
public function process_v2() {
$user = get_userdata( $this->data['user_id'] );
if ( false === $user ) {
return $this->skipped_response( __( 'User does not exists', 'wp-marketing-automations-pro' ) );
}
if ( empty( $this->data['content_id'] ) || ! is_array( $this->data['content_id'] ) ) {
return $this->skipped_response( __( 'Invalid pay per post', 'wp-marketing-automations-pro' ) );
}
global $WishListMemberInstance;
foreach ( $this->data['content_id'] as $content_id ) {
$WishListMemberInstance->remove_post_users( get_post_type( $content_id ), $content_id, $user->ID );
}
return $this->success_message( __( 'User removed from pay per post.', 'wp-marketing-automations-pro' ) );
}
public function get_fields_schema() {
return [
[
"id" => 'content_id',
"label" => __( 'Select Pay Per Post', 'wp-marketing-automations-pro' ),
"type" => 'custom_search',
'autocompleterOption' => [
'path' => 'wlm_pay_per_post',
'slug' => 'wlm_pay_per_post',
'labelText' => 'pay per post'
],
"allowFreeTextSearch" => false,
"required" => true,
"errorMsg" => __( "Pay Per Post is required", 'wp-marketing-automations-pro' ),
]
];
}
public function get_desc_text( $data ) {
$data = json_decode( wp_json_encode( $data ), true );
if ( ! isset( $data['content_id'] ) || empty( $data['content_id'] ) ) {
return '';
}
$content_ids = [];
foreach ( $data['content_id'] as $content_id ) {
if ( ! isset( $content_id['name'] ) || empty( $content_id['name'] ) ) {
continue;
}
$content_ids[] = $content_id['name'];
}
return $content_ids;
}
}
/**
* Register this action. Registering the action will make it eligible to see it on single automation screen in select actions dropdown.
*/
return 'BWFAN_WLM_Remove_User_From_Pay_Per_Post';

View File

@@ -0,0 +1,217 @@
<?php
final class BWFAN_WLM_User_Add_Level extends BWFAN_Action {
private static $ins = null;
protected function __construct() {
$this->action_name = __( 'Add User to Level', 'wp-marketing-automations-pro' );
$this->required_fields = array( 'user_id', 'members_level' );
$this->support_v2 = true;
$this->action_priority = 15;
}
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' ) ) {
$membership_levels = $this->get_view_data();
BWFAN_Core()->admin->set_actions_js_data( $this->get_class_slug(), 'membership_level', $membership_levels );
}
}
/**
* @return array
*/
public function get_view_data() {
$levels = wlmapi_get_levels();
$options = array();
if ( ! empty( $levels['levels']['level'] ) ) {
foreach ( $levels['levels']['level'] as $level ) {
$options[ $level['id'] ] = $level['name'];
}
}
return $options;
}
/**
* 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_members_level = (_.has(data.actionSavedData, 'data') && _.has(data.actionSavedData.data, 'members_level')) ? data.actionSavedData.data.members_level : '';
#>
<div class="bwfan-<?php echo esc_html__( $this->get_slug() ); ?> clearfix bwfan-pl-0 bwfan-pr-0 bwfan-mb-15">
<label for="" class="bwfan-label-title"><?php echo esc_html__( 'Membership Level', 'wp-marketing-automations-pro' ); ?></label>
<select required id="" class="bwfan-input-wrapper" name="bwfan[{{data.action_id}}][data][members_level]">
<#
if(_.has(data.actionFieldsOptions, 'membership_level') && _.isObject(data.actionFieldsOptions.membership_level) ) {
_.each( data.actionFieldsOptions.membership_level, function( value, key ){
selected = (key == selected_members_level) ? 'selected' : '';
#>
<option value="{{key}}" {{selected}}>{{value}}</option>
<# })
}
#>
</select>
<div class="clearfix bwfan_field_desc">
</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['members_level'] = $task_meta['data']['members_level'];
$user_id = BWFAN_PRO_Common::maybe_get_user_id_from_task_meta( $task_meta['global'] );
if ( ! empty( $user_id ) ) {
$data_to_set['user_id'] = $user_id;
}
return $data_to_set;
}
public function make_v2_data( $automation_data, $step_data ) {
$data_to_set = array();
$data_to_set['members_level'] = isset( $step_data['members_level'][0]['id'] ) ? $step_data['members_level'][0]['id'] : 0;
$user_id = isset( $automation_data['global']['user_id'] ) ? $automation_data['global']['user_id'] : 0;
if ( 0 === absint( $user_id ) ) {
$email = ( isset( $automation_data['global']['email'] ) && is_email( $automation_data['global']['email'] ) ) ? $automation_data['global']['email'] : '';
$user = is_email( $email ) ? get_user_by( 'email', $email ) : '';
$user_id = $user instanceof WP_User ? $user->ID : 0;
}
$data_to_set['user_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,
'message' => 'Membership level is assigned / updated to user\'s membership',
);
}
return $result;
}
/**
* 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();
}
$membership_level = $this->data['members_level'];
$user = get_userdata( $this->data['user_id'] );
if ( false === $user ) {
return array(
'status' => 4,
'message' => __( 'User does not exists', 'wp-marketing-automations-pro' ),
);
}
return $this->add_user_to_membership_levels( $this->data['user_id'], $membership_level );
}
public function add_user_to_membership_levels( $user_id, $membership_level ) {
global $WishListMemberInstance;
$WishListMemberInstance->schedule_to_level( 'wpm_add_membership', $membership_level, [ $user_id ], '' );
return true;
}
public function process_v2() {
$membership_level = $this->data['members_level'];
$user = get_userdata( $this->data['user_id'] );
if ( false === $user ) {
return $this->skipped_response( __( 'User does not exists', 'wp-marketing-automations-pro' ) );
}
$this->add_user_to_membership_levels( $this->data['user_id'], $membership_level );
return $this->success_message( __( 'User added to level.', 'wp-marketing-automations-pro' ) );
}
public function get_fields_schema() {
return [
[
"id" => 'members_level',
"label" => __( 'Membership Level', 'wp-marketing-automations-pro' ),
"type" => 'custom_search',
'autocompleterOption' => [
'path' => 'wlm_levels',
'slug' => 'wlm_levels',
'labelText' => 'level'
],
"allowFreeTextSearch" => false,
"required" => true,
"errorMsg" => __( "Level is required", 'wp-marketing-automations-pro' ),
"multiple" => false
]
];
}
public function get_desc_text( $data ) {
$data = json_decode( wp_json_encode( $data ), true );
if ( ! isset( $data['members_level'] ) || empty( $data['members_level'] ) ) {
return '';
}
$members_levels = [];
foreach ( $data['members_level'] as $members_level ) {
if ( ! isset( $members_level['name'] ) || empty( $members_level['name'] ) ) {
continue;
}
$members_levels[] = $members_level['name'];
}
return $members_levels;
}
}
/**
* Register this action. Registering the action will make it eligible to see it on single automation screen in select actions dropdown.
*/
return 'BWFAN_WLM_User_Add_Level';

View File

@@ -0,0 +1,231 @@
<?php
final class BWFAN_WLM_User_Cancel_Level extends BWFAN_Action {
private static $ins = null;
protected function __construct() {
$this->action_name = __( 'Cancel User Level', 'wp-marketing-automations-pro' );
$this->required_fields = array( 'user_id', 'members_level' );
$this->action_priority = 25;
$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' ) ) {
$membership_levels = $this->get_view_data();
BWFAN_Core()->admin->set_actions_js_data( $this->get_class_slug(), 'membership_level', $membership_levels );
}
}
/**
* @return array
*/
public function get_view_data() {
$levels = wlmapi_get_levels();
$options = array();
if ( ! empty( $levels['levels']['level'] ) ) {
foreach ( $levels['levels']['level'] as $level ) {
$options[ $level['id'] ] = $level['name'];
}
}
return $options;
}
/**
* 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_members_level = (_.has(data.actionSavedData, 'data') && _.has(data.actionSavedData.data, 'members_level')) ? data.actionSavedData.data.members_level : '';
#>
<div class="bwfan-<?php echo esc_html__( $this->get_slug() ); ?> clearfix bwfan-pl-0 bwfan-pr-0 bwfan-mb-15">
<label for="" class="bwfan-label-title"><?php echo esc_html__( 'Membership Level', 'wp-marketing-automations-pro' ); ?></label>
<select required id="" class="bwfan-input-wrapper" name="bwfan[{{data.action_id}}][data][members_level]">
<#
if(_.has(data.actionFieldsOptions, 'membership_level') && _.isObject(data.actionFieldsOptions.membership_level) ) {
_.each( data.actionFieldsOptions.membership_level, function( value, key ){
selected = (key == selected_members_level) ? 'selected' : '';
#>
<option value="{{key}}" {{selected}}>{{value}}</option>
<# })
}
#>
</select>
<div class="clearfix bwfan_field_desc">
</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['members_level'] = $task_meta['data']['members_level'];
$user_id = BWFAN_PRO_Common::maybe_get_user_id_from_task_meta( $task_meta['global'] );
if ( ! empty( $user_id ) ) {
$data_to_set['user_id'] = $user_id;
}
return $data_to_set;
}
public function make_v2_data( $automation_data, $step_data ) {
$data_to_set = array();
$data_to_set['members_level'] = isset( $step_data['members_level'][0]['id'] ) ? $step_data['members_level'][0]['id'] : 0;
$user_id = isset( $automation_data['global']['user_id'] ) ? $automation_data['global']['user_id'] : 0;
if ( 0 === absint( $user_id ) ) {
$email = ( isset( $automation_data['global']['email'] ) && is_email( $automation_data['global']['email'] ) ) ? $automation_data['global']['email'] : '';
$user = is_email( $email ) ? get_user_by( 'email', $email ) : '';
$user_id = $user instanceof WP_User ? $user->ID : 0;
}
$data_to_set['user_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,
'message' => 'Membership level is assigned / updated to user\'s membership',
);
}
return $result;
}
/**
* 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();
}
$membership_level = $this->data['members_level'];
$user = get_userdata( $this->data['user_id'] );
if ( false === $user ) {
return array(
'status' => 4,
'message' => __( 'User does not exists', 'wp-marketing-automations-pro' ),
);
}
$member_level_added = $this->cancel_user_from_membership_levels( $this->data['user_id'], $membership_level );
return $member_level_added;
}
public function cancel_user_from_membership_levels( $user_id, $membership_level ) {
global $WishListMemberInstance;
/*
* fetch email notification settings
*/
$level_email_settings = $WishListMemberInstance->GetOption( 'wpm_levels' )[ $membership_level ]['level_email'];
$level_email_settings = isset( $level_email_settings ) ? $level_email_settings : 'sendlevel';
$level_data = array();
$level_data['wlm_levels'] = array( $membership_level );
$level_data['level_email'] = $level_email_settings;
$level_data['userids'] = $user_id;
$level_data['level_action'] = 'cancel_user_level';
$WishListMemberInstance->schedule_user_level( $level_data );
return true;
}
public function process_v2() {
$membership_level = $this->data['members_level'];
$user = get_userdata( $this->data['user_id'] );
if ( false === $user ) {
return $this->skipped_response( __( 'User does not exists', 'wp-marketing-automations-pro' ) );
}
$this->cancel_user_from_membership_levels( $this->data['user_id'], $membership_level );
return $this->success_message( __( 'User level cancelled.', 'wp-marketing-automations-pro' ) );
}
public function get_fields_schema() {
return [
[
"id" => 'members_level',
"label" => __( 'Membership Level', 'wp-marketing-automations-pro' ),
"type" => 'custom_search',
'autocompleterOption' => [
'path' => 'wlm_levels',
'slug' => 'wlm_levels',
'labelText' => 'level'
],
"allowFreeTextSearch" => false,
"required" => true,
"errorMsg" => __( "Level is required", 'wp-marketing-automations-pro' ),
"multiple" => false
]
];
}
public function get_desc_text( $data ) {
$data = json_decode( wp_json_encode( $data ), true );
if ( ! isset( $data['members_level'] ) || empty( $data['members_level'] ) ) {
return '';
}
$members_levels = [];
foreach ( $data['members_level'] as $members_level ) {
if ( ! isset( $members_level['name'] ) || empty( $members_level['name'] ) ) {
continue;
}
$members_levels[] = $members_level['name'];
}
return $members_levels;
}
}
/**
* Register this action. Registering the action will make it eligible to see it on single automation screen in select actions dropdown.
*/
return 'BWFAN_WLM_User_Cancel_Level';

View File

@@ -0,0 +1,235 @@
<?php
final class BWFAN_WLM_User_Move_Level extends BWFAN_Action {
private static $ins = null;
protected function __construct() {
$this->action_name = __( 'Move User to Level', 'wp-marketing-automations-pro' );
$this->required_fields = array( 'user_id', 'members_level' );
$this->support_v2 = true;
$this->action_priority = 30;
}
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' ) ) {
$membership_levels = $this->get_view_data();
BWFAN_Core()->admin->set_actions_js_data( $this->get_class_slug(), 'membership_level', $membership_levels );
}
}
/**
* @return array
*/
public function get_view_data() {
$levels = wlmapi_get_levels();
$options = array();
if ( ! empty( $levels['levels']['level'] ) ) {
foreach ( $levels['levels']['level'] as $level ) {
$options[ $level['id'] ] = $level['name'];
}
}
return $options;
}
/**
* 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_members_level = (_.has(data.actionSavedData, 'data') && _.has(data.actionSavedData.data, 'members_level')) ? data.actionSavedData.data.members_level : '';
#>
<div class="bwfan-<?php echo esc_html__( $this->get_slug() ); ?> clearfix bwfan-pl-0 bwfan-pr-0 bwfan-mb-15">
<label for="" class="bwfan-label-title"><?php echo esc_html__( 'Membership Level', 'wp-marketing-automations-pro' ); ?></label>
<select required id="" class="bwfan-input-wrapper" name="bwfan[{{data.action_id}}][data][members_level]">
<#
if(_.has(data.actionFieldsOptions, 'membership_level') && _.isObject(data.actionFieldsOptions.membership_level) ) {
_.each( data.actionFieldsOptions.membership_level, function( value, key ){
selected = (key == selected_members_level) ? 'selected' : '';
#>
<option value="{{key}}" {{selected}}>{{value}}</option>
<# })
}
#>
</select>
<div class="clearfix bwfan_field_desc">
</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['members_level'] = $task_meta['data']['members_level'];
$user_id = BWFAN_PRO_Common::maybe_get_user_id_from_task_meta( $task_meta['global'] );
if ( ! empty( $user_id ) ) {
$data_to_set['user_id'] = $user_id;
}
return $data_to_set;
}
public function make_v2_data( $automation_data, $step_data ) {
$data_to_set = array();
$data_to_set['members_level'] = isset( $step_data['members_level'][0]['id'] ) ? $step_data['members_level'][0]['id'] : 0;
$user_id = isset( $automation_data['global']['user_id'] ) ? $automation_data['global']['user_id'] : 0;
if ( 0 === absint( $user_id ) ) {
$email = ( isset( $automation_data['global']['email'] ) && is_email( $automation_data['global']['email'] ) ) ? $automation_data['global']['email'] : '';
$user = is_email( $email ) ? get_user_by( 'email', $email ) : '';
$user_id = $user instanceof WP_User ? $user->ID : 0;
}
$data_to_set['user_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,
'message' => 'Membership level is assigned / updated to user\'s membership',
);
}
return $result;
}
/**
* 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();
}
$membership_level = $this->data['members_level'];
$user = get_userdata( $this->data['user_id'] );
if ( false === $user ) {
return array(
'status' => 4,
'message' => __( 'User does not exists', 'wp-marketing-automations-pro' ),
);
}
$member_level_moved = $this->move_user_to_membership_levels( $this->data['user_id'], $membership_level );
return $member_level_moved;
}
public function move_user_to_membership_levels( $user_id, $membership_level ) {
global $WishListMemberInstance;
$move_from_level = $WishListMemberInstance->get_membership_levels( $user_id );
if ( $move_from_level[0] === $membership_level ) {
return array(
'status' => 4,
'message' => __( 'User cannot move to same level', 'wp-marketing-automations-pro' ),
);
}
$level_data = array(
'wlm_level_from' => $move_from_level[0],
'wlm_levels' => $membership_level,
'schedule_date' => '',
'userids' => $user_id,
'level_action' => 'move_user_level'
);
$WishListMemberInstance->schedule_user_level( $level_data );
return true;
}
public function process_v2() {
$membership_level = $this->data['members_level'];
$user = get_userdata( $this->data['user_id'] );
if ( false === $user ) {
return $this->skipped_response( __( 'User does not exists', 'wp-marketing-automations-pro' ) );
}
$this->move_user_to_membership_levels( $this->data['user_id'], $membership_level );
return $this->success_message( __( 'User level cancelled.', 'wp-marketing-automations-pro' ) );
}
public function get_fields_schema() {
return [
[
"id" => 'members_level',
"label" => __( 'Membership Level', 'wp-marketing-automations-pro' ),
"type" => 'custom_search',
'autocompleterOption' => [
'path' => 'wlm_levels',
'slug' => 'wlm_levels',
'labelText' => 'level'
],
"allowFreeTextSearch" => false,
"required" => true,
"errorMsg" => __( "Level is required", 'wp-marketing-automations-pro' ),
"multiple" => false
]
];
}
public function get_desc_text( $data ) {
$data = json_decode( wp_json_encode( $data ), true );
if ( ! isset( $data['members_level'] ) || empty( $data['members_level'] ) ) {
return '';
}
$members_levels = [];
foreach ( $data['members_level'] as $members_level ) {
if ( ! isset( $members_level['name'] ) || empty( $members_level['name'] ) ) {
continue;
}
$members_levels[] = $members_level['name'];
}
return $members_levels;
}
}
/**
* Register this action. Registering the action will make it eligible to see it on single automation screen in select actions dropdown.
*/
return 'BWFAN_WLM_User_Move_Level';

View File

@@ -0,0 +1,217 @@
<?php
final class BWFAN_WLM_User_Remove_Level extends BWFAN_Action {
private static $ins = null;
protected function __construct() {
$this->action_name = __( 'Remove User from Level', 'wp-marketing-automations-pro' );
$this->required_fields = array( 'user_id', 'members_level' );
$this->support_v2 = true;
$this->action_priority = 20;
}
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' ) ) {
$membership_levels = $this->get_view_data();
BWFAN_Core()->admin->set_actions_js_data( $this->get_class_slug(), 'membership_level', $membership_levels );
}
}
/**
* @return array
*/
public function get_view_data() {
$levels = wlmapi_get_levels();
$options = array();
if ( ! empty( $levels['levels']['level'] ) ) {
foreach ( $levels['levels']['level'] as $level ) {
$options[ $level['id'] ] = $level['name'];
}
}
return $options;
}
/**
* 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_members_level = (_.has(data.actionSavedData, 'data') && _.has(data.actionSavedData.data, 'members_level')) ? data.actionSavedData.data.members_level : '';
#>
<div class="bwfan-<?php echo esc_html__( $this->get_slug() ); ?> clearfix bwfan-pl-0 bwfan-pr-0 bwfan-mb-15">
<label for="" class="bwfan-label-title"><?php echo esc_html__( 'Membership Level', 'wp-marketing-automations-pro' ); ?></label>
<select required id="" class="bwfan-input-wrapper" name="bwfan[{{data.action_id}}][data][members_level]">
<#
if(_.has(data.actionFieldsOptions, 'membership_level') && _.isObject(data.actionFieldsOptions.membership_level) ) {
_.each( data.actionFieldsOptions.membership_level, function( value, key ){
selected = (key == selected_members_level) ? 'selected' : '';
#>
<option value="{{key}}" {{selected}}>{{value}}</option>
<# })
}
#>
</select>
<div class="clearfix bwfan_field_desc">
</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['members_level'] = $task_meta['data']['members_level'];
$user_id = BWFAN_PRO_Common::maybe_get_user_id_from_task_meta( $task_meta['global'] );
if ( ! empty( $user_id ) ) {
$data_to_set['user_id'] = $user_id;
}
return $data_to_set;
}
public function make_v2_data( $automation_data, $step_data ) {
$data_to_set = array();
$data_to_set['members_level'] = isset( $step_data['members_level'][0]['id'] ) ? $step_data['members_level'][0]['id'] : 0;
$user_id = isset( $automation_data['global']['user_id'] ) ? $automation_data['global']['user_id'] : 0;
if ( 0 === absint( $user_id ) ) {
$email = ( isset( $automation_data['global']['email'] ) && is_email( $automation_data['global']['email'] ) ) ? $automation_data['global']['email'] : '';
$user = is_email( $email ) ? get_user_by( 'email', $email ) : '';
$user_id = $user instanceof WP_User ? $user->ID : 0;
}
$data_to_set['user_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,
'message' => 'Membership level is assigned / updated to user\'s membership',
);
}
return $result;
}
/**
* 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();
}
$membership_level = $this->data['members_level'];
$user = get_userdata( $this->data['user_id'] );
if ( false === $user ) {
return array(
'status' => 4,
'message' => __( 'User does not exists', 'wp-marketing-automations-pro' ),
);
}
$member_level_added = $this->add_user_to_membership_levels( $this->data['user_id'], $membership_level );
return $member_level_added;
}
public function add_user_to_membership_levels( $user_id, $membership_level ) {
global $WishListMemberInstance;
$WishListMemberInstance->schedule_to_level( 'wpm_del_membership', $membership_level, [ $user_id ], '' );
return true;
}
public function process_v2() {
$membership_level = $this->data['members_level'];
$user = get_userdata( $this->data['user_id'] );
if ( false === $user ) {
return $this->skipped_response( __( 'User does not exists', 'wp-marketing-automations-pro' ) );
}
$this->add_user_to_membership_levels( $this->data['user_id'], $membership_level );
return $this->success_message( __( 'User level cancelled.', 'wp-marketing-automations-pro' ) );
}
public function get_fields_schema() {
return [
[
"id" => 'members_level',
"label" => __( 'Membership Level', 'wp-marketing-automations-pro' ),
"type" => 'custom_search',
'autocompleterOption' => [
'path' => 'wlm_levels',
'slug' => 'wlm_levels',
'labelText' => 'level'
],
"allowFreeTextSearch" => false,
"required" => true,
"errorMsg" => __( "Level is required", 'wp-marketing-automations-pro' ),
"multiple" => false
]
];
}
public function get_desc_text( $data ) {
$data = json_decode( wp_json_encode( $data ), true );
if ( ! isset( $data['members_level'] ) || empty( $data['members_level'] ) ) {
return '';
}
$members_levels = [];
foreach ( $data['members_level'] as $members_level ) {
if ( ! isset( $members_level['name'] ) || empty( $members_level['name'] ) ) {
continue;
}
$members_levels[] = $members_level['name'];
}
return $members_levels;
}
}
/**
* Register this action. Registering the action will make it eligible to see it on single automation screen in select actions dropdown.
*/
return 'BWFAN_WLM_User_Remove_Level';

View File

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

View File

@@ -0,0 +1,30 @@
<?php
final class BWFAN_WLM_Integration extends BWFAN_Integration {
public static $integration_type = null;
public static $headers = null;
private static $ins = null;
private function __construct() {
$this->action_dir = __DIR__;
$this->nice_name = __( 'WishList Member', 'wp-marketing-automations-pro' );
$this->group_name = __( 'Membership', 'wp-marketing-automations-pro' );
$this->group_slug = 'wlm';
$this->priority = 60;
}
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
}
/**
* Register this class as an integration.
*/
if ( function_exists( 'bwfan_is_wlm_active' ) && bwfan_is_wlm_active() ) {
BWFAN_Load_Integrations::register( 'BWFAN_WLM_Integration' );
}

View File

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

View File

@@ -0,0 +1,329 @@
<?php
#[AllowDynamicProperties]
final class BWFAN_WLM_Add_Level extends BWFAN_Event {
private static $instance = null;
public $user_id = null;
public $level_id = null;
public $email = null;
private function __construct() {
$this->event_merge_tag_groups = array( 'wc_customer', 'wlm_wishlist' );
$this->event_name = esc_html__( 'User Added to Membership Level', 'wp-marketing-automations-pro' );
$this->event_desc = esc_html__( 'This event runs after a user added to membership level.', 'wp-marketing-automations-pro' );
$this->event_rule_groups = array(
'wlm',
'wc_customer',
'bwf_contact_segments',
'bwf_contact',
'bwf_contact_fields',
'bwf_contact_user',
'bwf_contact_wc',
'bwf_contact_geo',
'bwf_engagement',
'bwf_broadcast',
'wp_user'
);
$this->optgroup_label = esc_html__( 'WishList Member', 'wp-marketing-automations-pro' );
$this->support_lang = true;
$this->priority = 25;
$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( 'wishlistmember_add_user_levels', [ $this, 'added_level_to_user' ], 20, 3 );
}
public function added_level_to_user( $user_id, $new_levels, $removed_levels ) {
$this->process( $user_id, $new_levels, $removed_levels );
}
/**
* Make the required data for the current event and send it asynchronously.
*
* @param $user_id
* @param $new_levels
* @param $removed_levels
*/
public function process( $user_id, $new_levels, $removed_levels ) {
$data = $this->get_default_data();
$user_data = get_userdata( $user_id );
if ( ! $user_data instanceof WP_User ) {
return;
}
$data['user_id'] = $user_id;
$new_level = $new_levels;
if ( is_array( $new_level ) ) {
$new_level = array_values( $new_level );
}
$data['level_id'] = $new_level[0];
$data['email'] = $user_data->user_email;
$this->send_async_call( $data );
}
/** localise wishlist members level options */
public function admin_enqueue_assets() {
if ( BWFAN_Common::is_load_admin_assets( 'automation' ) ) {
$membership_levels = $this->get_view_data();
BWFAN_Core()->admin->set_events_js_data( $this->get_slug(), 'membership_levels', $membership_levels );
}
}
/** get wishlist members levels
* @return array
*/
public function get_view_data() {
$levels = wlmapi_get_levels();
$options = array();
if ( ! empty( $levels['levels']['level'] ) ) {
foreach ( $levels['levels']['level'] as $level ) {
$options[ $level['id'] ] = $level['name'];
}
}
return $options;
}
/**
* 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_member_level = (_.has(data, 'eventSavedData') &&_.has(data.eventSavedData, 'members_level')) ? data.eventSavedData.members_level : '';
#>
<div class="bwfan_mt15"></div>
<div class="bwfan-col-sm-12 bwfan-pl-0">
<label for="" class="bwfan-label-title"><?php echo esc_html__( 'Membership Level', 'wp-marketing-automations-pro' ); ?></label>
<select required id="" class="bwfan-input-wrapper" name="event_meta[members_level]">
<option value="any"><?php echo esc_html__( 'Any', 'wp-marketing-automations-pro' ); ?></option>
<#
if(_.has(data.eventFieldsOptions, 'membership_levels') && _.isObject(data.eventFieldsOptions.membership_levels) ) {
_.each( data.eventFieldsOptions.membership_levels, function( value, key ){
selected = (key == selected_member_level) ? 'selected' : '';
#>
<option value="{{key}}" {{selected}}>{{value}}</option>
<# })
}
#>
</select>
</div>
</script>
<?php
}
/**
* Set up rules data
*
* @param $automation_data
*/
public function pre_executable_actions( $automation_data ) {
BWFAN_Core()->rules->setRulesData( $this->user_id, 'user_id' );
BWFAN_Core()->rules->setRulesData( $this->level_id, 'level_id' );
BWFAN_Core()->rules->setRulesData( BWFAN_Common::get_bwf_customer( $this->get_email_event(), $this->get_user_id_event() ), 'bwf_customer' );
}
public function get_email_event() {
return is_email( $this->email ) ? $this->email : null;
}
public function get_user_id_event() {
return $this->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']['user_id'] = $this->user_id;
$data_to_send['global']['level_id'] = $this->level_id;
$data_to_send['global']['email'] = $this->get_email_event();
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();
$new_level_url = admin_url();
$new_level_url = add_query_arg( array(
'page' => 'WishListMember',
'wl' => 'setup/levels',
'level_id' => $global_data['level_id'] . '#levels_access-' . $global_data['level_id'],
), $new_level_url );
?>
<li>
<strong><?php echo esc_html__( 'Membership Level:', 'wp-marketing-automations-pro' ); ?> </strong>
<a target="_blank" href="<?php echo $new_level_url; //phpcs:ignore WordPress.Security.EscapeOutput ?>"><?php echo esc_html__( '#' . $global_data['level_id'] ); ?></a>
</li>
<li>
<strong><?php echo esc_html__( 'Email:', 'wp-marketing-automations-pro' ); ?> </strong>
<?php echo esc_html__( $global_data['email'] ); ?>
</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( 'level_id' );
if ( ( empty( $get_data ) || intval( $get_data ) !== intval( $task_meta['global']['level_id'] ) ) ) {
$set_data = array(
'user_id' => intval( $task_meta['global']['user_id'] ),
'email' => $task_meta['global']['email'],
'level_id' => $task_meta['global']['level_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() {
$user_id = BWFAN_Common::$events_async_data['user_id'];
$new_level = BWFAN_Common::$events_async_data['level_id'];
$this->user_id = $user_id;
$this->email = BWFAN_Common::$events_async_data['email'];
$this->level_id = $new_level;
return $this->run_automations();
}
/** validate event data before creating task
*
* @param $automations_arr
*
* @return mixed
*/
public function validate_event_data_before_creating_task( $automations_arr ) {
$automations_arr_temp = $automations_arr;
foreach ( $automations_arr as $automation_id => $automation_data ) {
if ( 'any' !== $automation_data['event_meta']['members_level'] && absint( $automation_data['event_meta']['members_level'] ) !== absint( $this->level_id ) ) {
unset( $automations_arr_temp[ $automation_id ] );
}
}
return $automations_arr_temp;
}
/**
* v2 Method: Validate event settings
*
* @param $automation_data
*
* @return bool
*/
public function validate_v2_event_settings( $automation_data ) {
$saved_level_ids = isset( $automation_data['event_meta']['members_level'] ) && is_array( $automation_data['event_meta']['members_level'] ) ? array_column( $automation_data['event_meta']['members_level'], 'id' ) : [];
if ( ! in_array( $automation_data['level_id'], $saved_level_ids, false ) ) {
return false;
}
return true;
}
/**
* Capture the async data for the current event.
*
* @return array|bool
*/
public function capture_v2_data( $automation_data ) {
$user_id = BWFAN_Common::$events_async_data['user_id'];
$new_level = BWFAN_Common::$events_async_data['level_id'];
$this->user_id = $user_id;
$this->email = BWFAN_Common::$events_async_data['email'];
$this->level_id = $new_level;
$automation_data['user_id'] = $this->user_id;
$automation_data['email'] = $this->email;
$automation_data['level_id'] = $this->level_id;
return $automation_data;
}
/**
* v2 Method: Get field Schema
*
* @return array[]
*/
public function get_fields_schema() {
$default = [
'any' => 'Any'
];
$options = array_replace( $default, $this->get_view_data() );
$options = BWFAN_PRO_Common::prepared_field_options( $options );
return [
[
"id" => 'members_level',
"label" => __( 'Membership Level', 'wp-marketing-automations-pro' ),
"type" => 'custom_search',
'autocompleterOption' => [
'path' => 'wlm_levels',
'slug' => 'wlm_levels',
'labelText' => 'level'
],
"allowFreeTextSearch" => false,
"required" => true,
"errorMsg" => __( "Level is required", 'wp-marketing-automations-pro' ),
"multiple" => false
]
];
}
}
/**
* Register this event to a source.
* This will show the current event in dropdown in single automation screen.
*/
if ( function_exists( 'bwfan_is_wlm_active' ) && bwfan_is_wlm_active() ) {
return 'BWFAN_WLM_Add_Level';
}

View File

@@ -0,0 +1,325 @@
<?php
#[AllowDynamicProperties]
final class BWFAN_WLM_Cancel_Level extends BWFAN_Event {
private static $instance = null;
public $user_id = null;
public $level_id = null;
public $email = null;
private function __construct() {
$this->event_merge_tag_groups = array( 'wc_customer', 'wlm_wishlist' );
$this->event_name = esc_html__( 'User Membership Level Cancelled', 'wp-marketing-automations-pro' );
$this->event_desc = esc_html__( 'This event runs after a user cancelled from membership level.', 'wp-marketing-automations-pro' );
$this->event_rule_groups = array(
'wlm',
'wc_customer',
'bwf_contact_segments',
'bwf_contact',
'bwf_contact_fields',
'bwf_contact_user',
'bwf_contact_wc',
'bwf_contact_geo',
'bwf_engagement',
'bwf_broadcast',
'wp_user'
);
$this->optgroup_label = esc_html__( 'WishList Member', 'wp-marketing-automations-pro' );
$this->support_lang = true;
$this->priority = 35;
$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( 'wishlistmember_cancel_user_levels', [ $this, 'cancelled_level_from_user' ], 20, 3 );
}
/*
* $cancelled_levels is the array containing level id or ids
*/
public function cancelled_level_from_user( $user_id, $cancelled_level ) {
$this->process( $user_id, $cancelled_level );
}
/**
* Make the required data for the current event and send it asynchronously.
*
* @param $user_id
* @param $cancelled_level
*/
public function process( $user_id, $cancelled_level ) {
$data = $this->get_default_data();
$user_data = get_userdata( $user_id );
if ( ! $user_data instanceof WP_User ) {
return;
}
$data['user_id'] = $user_id;
$cancelled_level = $cancelled_level;
if ( is_array( $cancelled_level ) ) {
$cancelled_level = array_values( $cancelled_level );
}
$data['level_id'] = $cancelled_level[0];
$data['email'] = $user_data->user_email;
$this->send_async_call( $data );
}
/** localise wishlist members level options */
public function admin_enqueue_assets() {
if ( BWFAN_Common::is_load_admin_assets( 'automation' ) ) {
$membership_levels = $this->get_view_data();
BWFAN_Core()->admin->set_events_js_data( $this->get_slug(), 'membership_levels', $membership_levels );
}
}
/** get wishlist members levels
* @return array
*/
public function get_view_data() {
$levels = wlmapi_get_levels();
$options = array();
if ( ! empty( $levels['levels']['level'] ) ) {
foreach ( $levels['levels']['level'] as $level ) {
$options[ $level['id'] ] = $level['name'];
}
}
return $options;
}
/**
* 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_member_level = (_.has(data, 'eventSavedData') &&_.has(data.eventSavedData, 'members_level')) ? data.eventSavedData.members_level : '';
#>
<div class="bwfan_mt15"></div>
<div class="bwfan-col-sm-12 bwfan-pl-0">
<label for="" class="bwfan-label-title"><?php echo esc_html__( 'Membership Level', 'wp-marketing-automations-pro' ); ?></label>
<select required id="" class="bwfan-input-wrapper" name="event_meta[members_level]">
<option value="any"><?php echo esc_html__( 'Any', 'wp-marketing-automations-pro' ); ?></option>
<#
if(_.has(data.eventFieldsOptions, 'membership_levels') && _.isObject(data.eventFieldsOptions.membership_levels) ) {
_.each( data.eventFieldsOptions.membership_levels, function( value, key ){
selected = (key == selected_member_level) ? 'selected' : '';
#>
<option value="{{key}}" {{selected}}>{{value}}</option>
<# })
}
#>
</select>
</div>
</script>
<?php
}
/**
* Set up rules data
*
* @param $automation_data
*/
public function pre_executable_actions( $automation_data ) {
BWFAN_Core()->rules->setRulesData( $this->user_id, 'user_id' );
BWFAN_Core()->rules->setRulesData( $this->level_id, 'level_id' );
BWFAN_Core()->rules->setRulesData( BWFAN_Common::get_bwf_customer( $this->get_email_event(), $this->get_user_id_event() ), 'bwf_customer' );
}
public function get_email_event() {
return is_email( $this->email ) ? $this->email : null;
}
public function get_user_id_event() {
return $this->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']['user_id'] = $this->user_id;
$data_to_send['global']['level_id'] = $this->level_id;
$data_to_send['global']['email'] = $this->get_email_event();
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();
$new_level_url = admin_url();
$new_level_url = add_query_arg( array(
'page' => 'WishListMember',
'wl' => 'setup/levels',
'level_id' => $global_data['level_id'] . '#levels_access-' . $global_data['level_id'],
), $new_level_url );
?>
<li>
<strong><?php echo esc_html__( 'Membership Level:', 'wp-marketing-automations-pro' ); ?> </strong>
<a target="_blank" href="<?php echo $new_level_url; //phpcs:ignore WordPress.Security.EscapeOutput ?>"><?php echo esc_html__( '#' . $global_data['level_id'] ); ?></a>
</li>
<li>
<strong><?php echo esc_html__( 'Email:', 'wp-marketing-automations-pro' ); ?> </strong>
<?php echo esc_html__( $global_data['email'] ); ?>
</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( 'level_id' );
if ( ( empty( $get_data ) || intval( $get_data ) !== intval( $task_meta['global']['level_id'] ) ) ) {
$set_data = array(
'user_id' => intval( $task_meta['global']['user_id'] ),
'email' => $task_meta['global']['email'],
'level_id' => $task_meta['global']['level_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() {
$user_id = BWFAN_Common::$events_async_data['user_id'];
$new_level = BWFAN_Common::$events_async_data['level_id'];
$this->user_id = $user_id;
$this->email = BWFAN_Common::$events_async_data['email'];
$this->level_id = $new_level;
return $this->run_automations();
}
/** validate event data before creating task
*
* @param $automations_arr
*
* @return mixed
*/
public function validate_event_data_before_creating_task( $automations_arr ) {
$automations_arr_temp = $automations_arr;
foreach ( $automations_arr as $automation_id => $automation_data ) {
if ( 'any' !== $automation_data['event_meta']['members_level'] && absint( $automation_data['event_meta']['members_level'] ) !== absint( $this->level_id ) ) {
unset( $automations_arr_temp[ $automation_id ] );
}
}
return $automations_arr_temp;
}
/**
* v2 Method: Get field Schema
*
* @return array[]
*/
public function get_fields_schema() {
return [
[
"id" => 'members_level',
"label" => __( 'Membership Level', 'wp-marketing-automations-pro' ),
"type" => 'custom_search',
'autocompleterOption' => [
'path' => 'wlm_levels',
'slug' => 'wlm_levels',
'labelText' => 'level'
],
"allowFreeTextSearch" => false,
"required" => true,
"errorMsg" => __( "Level is required", 'wp-marketing-automations-pro' ),
"multiple" => false
]
];
}
/**
* v2 Method: Validate event settings
*
* @param $automation_data
*
* @return bool
*/
public function validate_v2_event_settings( $automation_data ) {
$saved_level_ids = isset( $automation_data['event_meta']['members_level'] ) && is_array( $automation_data['event_meta']['members_level'] ) ? array_column( $automation_data['event_meta']['members_level'], 'id' ) : [];
if ( ! in_array( $automation_data['level_id'], $saved_level_ids, false ) ) {
return false;
}
return true;
}
/**
* Capture the async data for the current event.
*
* @return array|bool
*/
public function capture_v2_data( $automation_data ) {
$user_id = BWFAN_Common::$events_async_data['user_id'];
$new_level = BWFAN_Common::$events_async_data['level_id'];
$this->user_id = $user_id;
$this->email = BWFAN_Common::$events_async_data['email'];
$this->level_id = $new_level;
$automation_data['user_id'] = $this->user_id;
$automation_data['email'] = $this->email;
$automation_data['level_id'] = $this->level_id;
return $automation_data;
}
}
/**
* Register this event to a source.
* This will show the current event in dropdown in single automation screen.
*/
if ( function_exists( 'bwfan_is_wlm_active' ) && bwfan_is_wlm_active() ) {
return 'BWFAN_WLM_Cancel_Level';
}

View File

@@ -0,0 +1,344 @@
<?php
#[AllowDynamicProperties]
final class BWFAN_WLM_Expired_User_Level extends BWFAN_Event {
private static $instance = null;
public $user_id = null;
public $level_id = null;
public $email = null;
public $expire_date = null;
private function __construct() {
$this->event_merge_tag_groups = array( 'wc_customer', 'wlm_wishlist', 'wlm_user_level_expire_date' );
$this->event_name = esc_html__( 'User Membership Level Expired', 'wp-marketing-automations-pro' );
$this->event_desc = esc_html__( 'This event runs after a user membership level get expired.', 'wp-marketing-automations-pro' );
$this->event_rule_groups = array(
'wlm',
'wc_customer',
'bwf_contact_segments',
'bwf_contact',
'bwf_contact_fields',
'bwf_contact_user',
'bwf_contact_wc',
'bwf_contact_geo',
'bwf_engagement',
'bwf_broadcast',
'wp_user'
);
$this->optgroup_label = esc_html__( 'WishList Member', 'wp-marketing-automations-pro' );
$this->support_lang = true;
$this->priority = 40;
$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( 'wishlistmember_expire_user_levels', [ $this, 'expired_level_from_user' ], 20, 3 );
}
/**
*
* @param int $user_id
* @param array $expired_levels expired level ids
*/
public function expired_level_from_user( $user_id, $expired_levels ) {
$this->process( $user_id, $expired_levels );
}
/**
* Make the required data for the current event and send it asynchronously.
*
* @param int $user_id
* @param array $expired_level
*/
public function process( $user_id, $expired_level ) {
$data = $this->get_default_data();
$user_data = get_userdata( $user_id );
if ( ! $user_data instanceof WP_User ) {
return;
}
$data['user_id'] = $user_id;
if ( is_array( $expired_level ) ) {
$expired_level = array_values( $expired_level );
}
$data['level_id'] = $expired_level[0];
global $WishListMemberInstance;
$wpm_levels = $WishListMemberInstance->GetOption( 'wpm_levels' );
$data['expire_date'] = strtotime( $wpm_levels[ $data['level_id'] ]['expire_date'] );
$data['email'] = $user_data->user_email;
$this->send_async_call( $data );
}
/** localise wishlist members level options */
public function admin_enqueue_assets() {
if ( BWFAN_Common::is_load_admin_assets( 'automation' ) ) {
$membership_levels = $this->get_view_data();
BWFAN_Core()->admin->set_events_js_data( $this->get_slug(), 'membership_levels', $membership_levels );
}
}
/** get wishlist members levels
* @return array
*/
public function get_view_data() {
$levels = wlmapi_get_levels();
$options = array();
if ( ! empty( $levels['levels']['level'] ) ) {
foreach ( $levels['levels']['level'] as $level ) {
$options[ $level['id'] ] = $level['name'];
}
}
return $options;
}
/**
* 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_member_level = (_.has(data, 'eventSavedData') &&_.has(data.eventSavedData, 'members_level')) ? data.eventSavedData.members_level : '';
#>
<div class="bwfan_mt15"></div>
<div class="bwfan-col-sm-12 bwfan-pl-0">
<label for="" class="bwfan-label-title"><?php echo esc_html__( 'Membship Level', 'wp-marketing-automations-pro' ); ?></label>
<select required id="" class="bwfan-input-wrapper" name="event_meta[members_level]">
<option value="any"><?php echo esc_html__( 'Any', 'wp-marketing-automations-pro' ); ?></option>
<#
if(_.has(data.eventFieldsOptions, 'membership_levels') && _.isObject(data.eventFieldsOptions.membership_levels) ) {
_.each( data.eventFieldsOptions.membership_levels, function( value, key ){
selected = (key == selected_member_level) ? 'selected' : '';
#>
<option value="{{key}}" {{selected}}>{{value}}</option>
<# })
}
#>
</select>
</div>
</script>
<?php
}
/**
* Set up rules data
*
* @param $automation_data
*/
public function pre_executable_actions( $automation_data ) {
BWFAN_Core()->rules->setRulesData( $this->user_id, 'user_id' );
BWFAN_Core()->rules->setRulesData( $this->level_id, 'level_id' );
BWFAN_Core()->rules->setRulesData( BWFAN_Common::get_bwf_customer( $this->get_email_event(), $this->get_user_id_event() ), 'bwf_customer' );
BWFAN_Core()->rules->setRulesData( $this->expire_date, 'expire_date' );
}
public function get_email_event() {
return is_email( $this->email ) ? $this->email : null;
}
public function get_user_id_event() {
return $this->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']['user_id'] = $this->user_id;
$data_to_send['global']['level_id'] = $this->level_id;
$data_to_send['global']['email'] = $this->get_email_event();
$data_to_send['global']['expire_date'] = $this->expire_date;
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();
$new_level_url = admin_url();
$new_level_url = add_query_arg( array(
'page' => 'WishListMember',
'wl' => 'setup/levels',
'level_id' => $global_data['level_id'] . '#levels_access-' . $global_data['level_id'],
), $new_level_url );
?>
<li>
<strong><?php echo esc_html__( 'Membership Level:', 'wp-marketing-automations-pro' ); ?> </strong>
<a target="_blank" href="<?php echo $new_level_url; //phpcs:ignore WordPress.Security.EscapeOutput ?>"><?php echo esc_html__( '#' . $global_data['level_id'] ); ?></a>
</li>
<li>
<strong><?php echo esc_html__( 'Expired On:', 'wp-marketing-automations-pro' ); ?> </strong>
<?php echo esc_html__( date( 'd-m-Y', $global_data['expire_date'] ) ); ?>
</li>
<li>
<strong><?php echo esc_html__( 'Email:', 'wp-marketing-automations-pro' ); ?> </strong>
<?php echo esc_html__( $global_data['email'] ); ?>
</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( 'level_id' );
if ( ( empty( $get_data ) || intval( $get_data ) !== intval( $task_meta['global']['level_id'] ) ) ) {
$set_data = array(
'user_id' => intval( $task_meta['global']['user_id'] ),
'email' => $task_meta['global']['email'],
'level_id' => $task_meta['global']['level_id'],
'expire_date' => $task_meta['global']['expire_date']
);
BWFAN_Merge_Tag_Loader::set_data( $set_data );
}
}
/**
* Capture the async data for the current event.
* @return array|bool
*/
public function capture_async_data() {
$user_id = BWFAN_Common::$events_async_data['user_id'];
$new_level = BWFAN_Common::$events_async_data['level_id'];
$this->user_id = $user_id;
$this->email = BWFAN_Common::$events_async_data['email'];
$this->level_id = $new_level;
$this->expire_date = BWFAN_Common::$events_async_data['expire_date'];
return $this->run_automations();
}
/** validate event data before creating task
*
* @param $automations_arr
*
* @return mixed
*/
public function validate_event_data_before_creating_task( $automations_arr ) {
$automations_arr_temp = $automations_arr;
foreach ( $automations_arr as $automation_id => $automation_data ) {
if ( 'any' !== $automation_data['event_meta']['members_level'] && absint( $automation_data['event_meta']['members_level'] ) !== absint( $this->level_id ) ) {
unset( $automations_arr_temp[ $automation_id ] );
}
}
return $automations_arr_temp;
}
/**
* v2 Method: Validate event settings
*
* @param $automation_data
*
* @return bool
*/
public function validate_v2_event_settings( $automation_data ) {
$saved_level_ids = isset( $automation_data['event_meta']['members_level'] ) && is_array( $automation_data['event_meta']['members_level'] ) ? array_column( $automation_data['event_meta']['members_level'], 'id' ) : [];
if ( ! in_array( $automation_data['level_id'], $saved_level_ids, false ) ) {
return false;
}
return true;
}
/**
* Capture the async data for the current event.
*
* @return array|bool
*/
public function capture_v2_data( $automation_data ) {
$user_id = BWFAN_Common::$events_async_data['user_id'];
$new_level = BWFAN_Common::$events_async_data['level_id'];
$this->user_id = $user_id;
$this->email = BWFAN_Common::$events_async_data['email'];
$this->level_id = $new_level;
$this->expire_date = BWFAN_Common::$events_async_data['expire_date'];
$automation_data['user_id'] = $this->user_id;
$automation_data['email'] = $this->email;
$automation_data['level_id'] = $this->level_id;
$automation_data['expire_date'] = $this->expire_date;
return $automation_data;
}
/**
* v2 Method: Get field Schema
*
* @return array[]
*/
public function get_fields_schema() {
return [
[
"id" => 'members_level',
"label" => __( 'Membership Level', 'wp-marketing-automations-pro' ),
"type" => 'custom_search',
'autocompleterOption' => [
'path' => 'wlm_levels',
'slug' => 'wlm_levels',
'labelText' => 'level'
],
"allowFreeTextSearch" => false,
"required" => true,
"errorMsg" => __( "Level is required", 'wp-marketing-automations-pro' ),
"multiple" => false
]
];
}
}
/**
* Register this event to a source.
* This will show the current event in dropdown in single automation screen.
*/
if ( function_exists( 'bwfan_is_wlm_active' ) && bwfan_is_wlm_active() ) {
return 'BWFAN_WLM_Expired_User_Level';
}

View File

@@ -0,0 +1,321 @@
<?php
#[AllowDynamicProperties]
final class BWFAN_WLM_Remove_Level extends BWFAN_Event {
private static $instance = null;
public $user_id = null;
public $level_id = null;
public $email = null;
private function __construct() {
$this->event_merge_tag_groups = array( 'wc_customer', 'wlm_wishlist' );
$this->event_name = esc_html__( 'User Removed from Membership Level', 'wp-marketing-automations-pro' );
$this->event_desc = esc_html__( 'This event runs after a user removed from membership level.', 'wp-marketing-automations-pro' );
$this->event_rule_groups = array(
'wlm',
'wc_customer',
'bwf_contact_segments',
'bwf_contact',
'bwf_contact_fields',
'bwf_contact_user',
'bwf_contact_wc',
'bwf_contact_geo',
'bwf_engagement',
'bwf_broadcast',
'wp_user'
);
$this->optgroup_label = esc_html__( 'WishList Member', 'wp-marketing-automations-pro' );
$this->support_lang = true;
$this->priority = 30;
$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( 'wishlistmember_remove_user_levels', [ $this, 'remove_level_from_user' ], 20, 3 );
}
public function remove_level_from_user( $user_id, $removed_levels, $new_levels ) {
$this->process( $user_id, $removed_levels, $new_levels );
}
/**
* Make the required data for the current event and send it asynchronously.
*
* @param $user_id
* @param $removed_levels
* @param $new_levels
*/
public function process( $user_id, $removed_levels, $new_levels ) {
$data = $this->get_default_data();
$user_data = get_userdata( $user_id );
if ( ! $user_data instanceof WP_User ) {
return;
}
$data['user_id'] = $user_id;
$remove_level = $removed_levels;
if ( is_array( $remove_level ) ) {
$remove_level = array_values( $remove_level );
}
$data['level_id'] = $remove_level[0];
$data['email'] = $user_data->user_email;
$this->send_async_call( $data );
}
/** localise wishlist members level options */
public function admin_enqueue_assets() {
if ( BWFAN_Common::is_load_admin_assets( 'automation' ) ) {
$membership_levels = $this->get_view_data();
BWFAN_Core()->admin->set_events_js_data( $this->get_slug(), 'membership_levels', $membership_levels );
}
}
/** get wishlist members levels
* @return array
*/
public function get_view_data() {
$levels = wlmapi_get_levels();
$options = array();
if ( ! empty( $levels['levels']['level'] ) ) {
foreach ( $levels['levels']['level'] as $level ) {
$options[ $level['id'] ] = $level['name'];
}
}
return $options;
}
/**
* 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_member_level = (_.has(data, 'eventSavedData') &&_.has(data.eventSavedData, 'members_level')) ? data.eventSavedData.members_level : '';
#>
<div class="bwfan_mt15"></div>
<div class="bwfan-col-sm-12 bwfan-pl-0">
<label for="" class="bwfan-label-title"><?php echo esc_html__( 'Membership Level', 'wp-marketing-automations-pro' ); ?></label>
<select required id="" class="bwfan-input-wrapper" name="event_meta[members_level]">
<option value="any"><?php echo esc_html__( 'Any', 'wp-marketing-automations-pro' ); ?></option>
<#
if(_.has(data.eventFieldsOptions, 'membership_levels') && _.isObject(data.eventFieldsOptions.membership_levels) ) {
_.each( data.eventFieldsOptions.membership_levels, function( value, key ){
selected = (key == selected_member_level) ? 'selected' : '';
#>
<option value="{{key}}" {{selected}}>{{value}}</option>
<# })
}
#>
</select>
</div>
</script>
<?php
}
/**
* Set up rules data
*
* @param $automation_data
*/
public function pre_executable_actions( $automation_data ) {
BWFAN_Core()->rules->setRulesData( $this->user_id, 'user_id' );
BWFAN_Core()->rules->setRulesData( $this->level_id, 'level_id' );
BWFAN_Core()->rules->setRulesData( BWFAN_Common::get_bwf_customer( $this->get_email_event(), $this->get_user_id_event() ), 'bwf_customer' );
}
public function get_email_event() {
return is_email( $this->email ) ? $this->email : null;
}
public function get_user_id_event() {
return $this->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']['user_id'] = $this->get_user_id_event();
$data_to_send['global']['level_id'] = $this->level_id;
$data_to_send['global']['email'] = $this->get_email_event();
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();
$removed_level_url = admin_url();
$removed_level_url = add_query_arg( array(
'page' => 'WishListMember',
'wl' => 'setup/levels',
'level_id' => $global_data['level_id'] . '#levels_access-' . $global_data['level_id'],
), $removed_level_url );
?>
<li>
<strong><?php echo esc_html__( 'Membership Level:', 'wp-marketing-automations-pro' ); ?> </strong>
<a target="_blank" href="<?php echo $removed_level_url; //phpcs:ignore WordPress.Security.EscapeOutput ?>"><?php echo esc_html__( '#' . $global_data['level_id'] ); ?></a>
</li>
<li>
<strong><?php echo esc_html__( 'Email:', 'wp-marketing-automations-pro' ); ?> </strong>
<?php echo esc_html__( $global_data['email'] ); ?>
</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( 'level_id' );
if ( ( empty( $get_data ) || intval( $get_data ) !== intval( $task_meta['global']['level_id'] ) ) ) {
$set_data = array(
'user_id' => intval( $task_meta['global']['user_id'] ),
'email' => $task_meta['global']['email'],
'level_id' => $task_meta['global']['level_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() {
$user_id = BWFAN_Common::$events_async_data['user_id'];
$level_id = BWFAN_Common::$events_async_data['level_id'];
$this->user_id = $user_id;
$this->email = BWFAN_Common::$events_async_data['email'];
$this->level_id = $level_id;
return $this->run_automations();
}
/** validate event data before creating task
*
* @param $automations_arr
*
* @return mixed
*/
public function validate_event_data_before_creating_task( $automations_arr ) {
$automations_arr_temp = $automations_arr;
foreach ( $automations_arr as $automation_id => $automation_data ) {
if ( 'any' !== $automation_data['event_meta']['members_level'] && absint( $automation_data['event_meta']['members_level'] ) !== absint( $this->level_id ) ) {
unset( $automations_arr_temp[ $automation_id ] );
}
}
return $automations_arr_temp;
}
/**
* v2 Method: Validate event settings
*
* @param $automation_data
*
* @return bool
*/
public function validate_v2_event_settings( $automation_data ) {
$saved_level_ids = isset( $automation_data['event_meta']['members_level'] ) && is_array( $automation_data['event_meta']['members_level'] ) ? array_column( $automation_data['event_meta']['members_level'], 'id' ) : [];
if ( ! in_array( $automation_data['level_id'], $saved_level_ids, false ) ) {
return false;
}
return true;
}
/**
* Capture the async data for the current event.
*
* @return array|bool
*/
public function capture_v2_data( $automation_data ) {
$user_id = BWFAN_Common::$events_async_data['user_id'];
$level_id = BWFAN_Common::$events_async_data['level_id'];
$this->user_id = $user_id;
$this->email = BWFAN_Common::$events_async_data['email'];
$this->level_id = $level_id;
$automation_data['user_id'] = $this->user_id;
$automation_data['email'] = $this->email;
$automation_data['level_id'] = $this->level_id;
return $automation_data;
}
/**
* v2 Method: Get field Schema
*
* @return array[]
*/
public function get_fields_schema() {
return [
[
"id" => 'members_level',
"label" => __( 'Membership Level', 'wp-marketing-automations-pro' ),
"type" => 'custom_search',
'autocompleterOption' => [
'path' => 'wlm_levels',
'slug' => 'wlm_levels',
'labelText' => 'level'
],
"allowFreeTextSearch" => false,
"required" => true,
"errorMsg" => __( "Level is required", 'wp-marketing-automations-pro' ),
"multiple" => false
]
];
}
}
/**
* Register this event to a source.
* This will show the current event in dropdown in single automation screen.
*/
if ( function_exists( 'bwfan_is_wlm_active' ) && bwfan_is_wlm_active() ) {
return 'BWFAN_WLM_Remove_Level';
}

View File

@@ -0,0 +1,347 @@
<?php
return false;
final class BWFAN_WLM_Unexpire_User_Level extends BWFAN_Event {
private static $instance = null;
public $user_id = null;
public $level_id = null;
public $email = null;
public $expire_date = null;
private function __construct() {
$this->event_merge_tag_groups = array( 'wc_customer', 'wlm_wishlist', 'wlm_user_level_expire_date' );
$this->event_name = esc_html__( 'User Membership Level Unexpire ', 'wp-marketing-automations-pro' );
$this->event_desc = esc_html__( 'This event runs after a user membership level unexpire.', 'wp-marketing-automations-pro' );
$this->event_rule_groups = array(
'wlm',
'wc_customer',
'bwf_contact_segments',
'bwf_contact',
'bwf_contact_fields',
'bwf_contact_user',
'bwf_contact_wc',
'bwf_contact_geo',
'bwf_engagement',
'bwf_broadcast',
'wp_user'
);
$this->optgroup_label = esc_html__( 'WishList Member', 'wp-marketing-automations-pro' );
$this->support_lang = true;
$this->priority = 45;
$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( 'wishlistmember_unexpire_user_levels', [ $this, 'unexpire_level_from_user' ], 20, 3 );
}
/**
*
* @param int $user_id
* @param array $unexpire_levels unexpired level ids
*/
public function unexpire_level_from_user( $user_id, $unexpire_levels ) {
$this->process( $user_id, $unexpire_levels );
}
/**
* Make the required data for the current event and send it asynchronously.
*
* @param int $user_id
* @param array $unexpire_levels
*/
public function process( $user_id, $unexpire_levels ) {
$data = $this->get_default_data();
$user_data = get_userdata( $user_id );
if ( ! $user_data instanceof WP_User ) {
return;
}
$data['user_id'] = $user_id;
$unexpire_levels = $unexpire_levels;
if ( is_array( $unexpire_levels ) ) {
$unexpire_levels = array_values( $unexpire_levels );
}
$data['level_id'] = $unexpire_levels[0];
global $WishListMemberInstance;
$wpm_levels = $WishListMemberInstance->GetOption( 'wpm_levels' );
$data['expire_date'] = strtotime( $wpm_levels[ $data['level_id'] ]['expire_date'] );
$data['email'] = $user_data->user_email;
$this->send_async_call( $data );
}
/** localise wishlist members level options */
public function admin_enqueue_assets() {
if ( BWFAN_Common::is_load_admin_assets( 'automation' ) ) {
$membership_levels = $this->get_view_data();
BWFAN_Core()->admin->set_events_js_data( $this->get_slug(), 'membership_levels', $membership_levels );
}
}
/** get wishlist members levels
* @return array
*/
public function get_view_data() {
$levels = wlmapi_get_levels();
$options = array();
if ( ! empty( $levels['levels']['level'] ) ) {
foreach ( $levels['levels']['level'] as $level ) {
$options[ $level['id'] ] = $level['name'];
}
}
return $options;
}
/**
* 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_member_level = (_.has(data, 'eventSavedData') &&_.has(data.eventSavedData, 'members_level')) ? data.eventSavedData.members_level : '';
#>
<div class="bwfan_mt15"></div>
<div class="bwfan-col-sm-12 bwfan-pl-0">
<label for="" class="bwfan-label-title"><?php echo esc_html__( 'Membership Level', 'wp-marketing-automations-pro' ); ?></label>
<select required id="" class="bwfan-input-wrapper" name="event_meta[members_level]">
<option value="any"><?php echo esc_html__( 'Any', 'wp-marketing-automations-pro' ); ?></option>
<#
if(_.has(data.eventFieldsOptions, 'membership_levels') && _.isObject(data.eventFieldsOptions.membership_levels) ) {
_.each( data.eventFieldsOptions.membership_levels, function( value, key ){
selected = (key == selected_member_level) ? 'selected' : '';
#>
<option value="{{key}}" {{selected}}>{{value}}</option>
<# })
}
#>
</select>
</div>
</script>
<?php
}
/**
* Set up rules data
*
* @param $automation_data
*/
public function pre_executable_actions( $automation_data ) {
BWFAN_Core()->rules->setRulesData( $this->user_id, 'user_id' );
BWFAN_Core()->rules->setRulesData( $this->level_id, 'level_id' );
BWFAN_Core()->rules->setRulesData( BWFAN_Common::get_bwf_customer( $this->get_email_event(), $this->get_user_id_event() ), 'bwf_customer' );
BWFAN_Core()->rules->setRulesData( $this->expire_date, 'expire_date' );
}
public function get_email_event() {
return is_email( $this->email ) ? $this->email : null;
}
public function get_user_id_event() {
return $this->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']['user_id'] = $this->user_id;
$data_to_send['global']['level_id'] = $this->level_id;
$data_to_send['global']['email'] = $this->get_email_event();
$data_to_send['global']['expire_date'] = $this->expire_date;
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();
$new_level_url = admin_url();
$new_level_url = add_query_arg( array(
'page' => 'WishListMember',
'wl' => 'setup/levels',
'level_id' => $global_data['level_id'] . '#levels_access-' . $global_data['level_id'],
), $new_level_url );
?>
<li>
<strong><?php echo esc_html__( 'Membership Level:', 'wp-marketing-automations-pro' ); ?> </strong>
<a target="_blank" href="<?php echo $new_level_url; //phpcs:ignore WordPress.Security.EscapeOutput ?>"><?php echo esc_html__( '#' . $global_data['level_id'] ); ?></a>
</li>
<li>
<strong><?php echo esc_html__( 'Will Be Expired On:', 'wp-marketing-automations-pro' ); ?> </strong>
<?php echo esc_html__( date( 'd-m-Y', $global_data['expire_date'] ) ); ?>
</li>
<li>
<strong><?php echo esc_html__( 'Email:', 'wp-marketing-automations-pro' ); ?> </strong>
<?php echo esc_html__( $global_data['email'] ); ?>
</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( 'level_id' );
if ( ( empty( $get_data ) || intval( $get_data ) !== intval( $task_meta['global']['level_id'] ) ) ) {
$set_data = array(
'user_id' => intval( $task_meta['global']['user_id'] ),
'email' => $task_meta['global']['email'],
'level_id' => $task_meta['global']['level_id'],
'expire_date' => $task_meta['global']['expire_date']
);
BWFAN_Merge_Tag_Loader::set_data( $set_data );
}
}
/**
* Capture the async data for the current event.
* @return array|bool
*/
public function capture_async_data() {
$user_id = BWFAN_Common::$events_async_data['user_id'];
$new_level = BWFAN_Common::$events_async_data['level_id'];
$this->user_id = $user_id;
$this->email = BWFAN_Common::$events_async_data['email'];
$this->level_id = $new_level;
$this->expire_date = BWFAN_Common::$events_async_data['expire_date'];
return $this->run_automations();
}
/** validate event data before creating task
*
* @param $automations_arr
*
* @return mixed
*/
public function validate_event_data_before_creating_task( $automations_arr ) {
$automations_arr_temp = $automations_arr;
foreach ( $automations_arr as $automation_id => $automation_data ) {
if ( 'any' !== $automation_data['event_meta']['members_level'] && absint( $automation_data['event_meta']['members_level'] ) !== absint( $this->level_id ) ) {
unset( $automations_arr_temp[ $automation_id ] );
}
}
return $automations_arr_temp;
}
/**
* v2 Method: Validate event settings
*
* @param $automation_data
*
* @return bool
*/
public function validate_automation_settings( $automation_data ) {
if ( isset( $automation_data['v'] ) && 2 === absint( $automation_data['v'] ) ) {
return true;
}
$saved_level_ids = isset( $automation_data['event_meta']['members_level'] ) && is_array( $automation_data['event_meta']['members_level'] ) ? array_column( $automation_data['event_meta']['members_level'], 'id' ) : [];
if ( ! in_array( $automation_data['level_id'], $saved_level_ids, false ) ) {
return false;
}
return false;
}
/**
* Capture the async data for the current event.
*
* @return array|bool
*/
public function capture_v2_data( $automation_data ) {
$this->user_id = BWFAN_Common::$events_async_data['user_id'];
$this->level_id = BWFAN_Common::$events_async_data['level_id'];
$this->email = BWFAN_Common::$events_async_data['email'];
$automation_data['user_id'] = $this->user_id;
$automation_data['email'] = $this->email;
$automation_data['level_id'] = $this->level_id;
return $automation_data;
}
/**
* v2 Method: Get field Schema
*
* @return array[]
*/
public function get_fields_schema() {
return [
[
"id" => 'members_level',
"label" => __( 'Membership Level', 'wp-marketing-automations-pro' ),
"type" => 'custom_search',
'autocompleterOption' => [
'path' => 'wlm_levels',
'slug' => 'wlm_levels',
'labelText' => 'level'
],
"allowFreeTextSearch" => false,
"required" => true,
"errorMsg" => __( "Level is required", 'wp-marketing-automations-pro' ),
"multiple" => false
]
];
}
}
/**
* Register this event to a source.
* This will show the current event in dropdown in single automation screen.
*/
if ( function_exists( 'bwfan_is_wlm_active' ) && bwfan_is_wlm_active() ) {
return 'BWFAN_WLM_Unexpire_User_Level';
}

View File

@@ -0,0 +1,621 @@
<?php
#[AllowDynamicProperties]
final class BWFAN_WLM_User_Registration extends BWFAN_Event {
private static $instance = null;
public $form_id = 0;
public $form_title = '';
public $entry = [];
public $fields = [];
public $email = '';
public $level_id = '';
private function __construct() {
$this->event_merge_tag_groups = array( 'wc_customer', 'wlm_forms' );
$this->event_name = esc_html__( 'User Submits a Registration Form', 'wp-marketing-automations-pro' );
$this->event_desc = esc_html__( 'This event runs after a user submit a registration form.', 'wp-marketing-automations-pro' );
$this->event_rule_groups = array(
'wlm',
'wc_customer',
'wlm_forms',
'bwf_contact_segments',
'bwf_contact',
'bwf_contact_fields',
'bwf_contact_user',
'bwf_contact_wc',
'bwf_contact_geo',
'bwf_engagement',
'bwf_broadcast',
'wp_user'
);
$this->optgroup_label = esc_html__( 'WishList Member', 'wp-marketing-automations-pro' );
$this->support_lang = true;
$this->priority = 20;
$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( 'wishlistmember_user_registered', [ $this, 'added_new_user' ], 20, 2 );
add_action( 'wp_ajax_bwfan_get_wlm_form_fields', array( $this, 'bwfan_get_wlm_form_fields' ) );
add_filter( 'bwfan_all_event_js_data', array( $this, 'add_form_data' ), 10, 2 );
}
public function added_new_user( $user_id, $data ) {
$this->process( $user_id, $data );
}
/**
* Make the required data for the current event and send it asynchronously.
*
* @param $user_id
* @param $form_data
*/
public function process( $user_id, $form_data ) {
$data = $this->get_default_data();
$user_data = get_userdata( $user_id );
if ( ! $user_data instanceof WP_User ) {
return;
}
if ( ! isset( $form_data['wpm_id'] ) ) {
return;
}
//Get form id from level settings
global $wpdb;
$wlm_option_table = $wpdb->prefix . 'wlm_options';
$wpm_levels = $wpdb->get_row( "Select * from {$wlm_option_table} WHERE option_name LIKE 'wpm_levels' LIMIT 1" ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
if ( ! empty( $wpm_levels ) ) {
$wpm_levels = maybe_unserialize( $wpm_levels->option_value );
} else {
return;
}
if ( ! isset( $wpm_levels[ $form_data['wpm_id'] ] ) ) {
return;
}
$level_info = $wpm_levels[ $form_data['wpm_id'] ];
$regpage_form_id = 'default';
if ( isset( $level_info['custom_reg_form'] ) && isset( $level_info['enable_custom_reg_form'] ) ) {
$regpage_form_id = $level_info['custom_reg_form'];
}
$data['level_id'] = $form_data['wpm_id'];
$data['email'] = $user_data->user_email;
$data['entry'] = $form_data;
$data['form_id'] = $form_data['wlm_form_id'];
$data['form_title'] = $this->get_form_title( $form_data['wlm_form_id'] );
$data['fields'] = $this->get_form_fields( $form_data['wlm_form_id'] );
$this->send_async_call( $data );
}
/** get form title using form id
*
* @param $form_id
*
* @return mixed|string
*/
public function get_form_title( $form_id ) {
$form_title = '';
$forms = $this->get_view_data();
if ( isset( $forms[ $form_id ] ) ) {
$form_title = $forms[ $form_id ];
} else {
$form_title = $forms['default'];
}
return $form_title;
}
/** get wishlist members levels
* @return array
*/
public function get_view_data() {
global $wpdb;
$options = array();
$options['default'] = esc_attr__( 'Default registration form', 'uncanny-automator-pro' );
$forms = $wpdb->get_results( "SELECT option_name,option_value FROM `{$wpdb->prefix}wlm_options` WHERE `option_name` LIKE 'CUSTOMREGFORM-%' ORDER BY `option_name` ASC", ARRAY_A ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
foreach ( $forms as $k => $form ) {
$form_value = maybe_unserialize( wlm_serialize_corrector( $form['option_value'] ) );
$all_forms[ $form['option_name'] ] = $form_value['form_name'];
}
if ( ! empty( $all_forms ) ) {
foreach ( $all_forms as $key => $form ) {
$options[ $key ] = $form;
}
}
return $options;
}
/** form fields using form id */
public function get_form_fields( $form_id ) {
global $wpdb;
$fields = [];
if ( $form_id != 'default' ) {
$form = $wpdb->get_var( "SELECT option_value FROM `{$wpdb->prefix}wlm_options` WHERE `option_name` LIKE '%{$form_id}%' ORDER BY `option_name` ASC" ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
$form_value = maybe_unserialize( wlm_serialize_corrector( $form ) );
$form_fields = $form_value['form_dissected']['fields'];
if ( is_array( $form_fields ) ) {
foreach ( $form_fields as $field ) {
if ( $field['attributes']['type'] != 'password' ) {
$fields[ $field['attributes']['name'] ] = str_replace( ':', '', $field['label'] );
}
}
}
} elseif ( $form_id == 'default' ) {
$form_fields = $this->get_default_form_fields();
if ( is_array( $form_fields ) ) {
foreach ( $form_fields as $key => $field ) {
$fields[ $key ] = $field;
}
}
}
return $fields;
}
/** default fields for user registration in wishlist member
* @return mixed|void
*/
public function get_default_form_fields() {
$fields = [
'firstname' => __( 'First name', 'wp-marketing-automations-pro' ),
'lastname' => __( 'Last name', 'wp-marketing-automations-pro' ),
'email' => __( 'Email', 'wp-marketing-automations-pro' ),
'username' => __( 'Username', 'wp-marketing-automations-pro' ),
];
return apply_filters( 'bwfan_wlm_default_form_field', $fields );
}
/** localise wishlist members level options */
public function admin_enqueue_assets() {
if ( BWFAN_Common::is_load_admin_assets( 'automation' ) ) {
$registration_forms = $this->get_view_data();
BWFAN_Core()->admin->set_events_js_data( $this->get_slug(), 'registration_forms', $registration_forms );
}
}
/**
* 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_reg_form = (_.has(data, 'eventSavedData') &&_.has(data.eventSavedData, 'reg_form')) ? data.eventSavedData.reg_form : '';
selected_field_map = (_.has(data, 'eventSavedData') &&_.has(data.eventSavedData, 'email_map')) ? data.eventSavedData.email_map : '';
#>
<div class="bwfan_mt15"></div>
<div class="bwfan-col-sm-12 bwfan-pl-0">
<label for="" class="bwfan-label-title"><?php echo esc_html__( 'Select Form', 'wp-marketing-automations-pro' ); ?></label>
<select required id="bwfan-wlm_form_submit_form_id" class="bwfan-input-wrapper" name="event_meta[reg_form]">
<option value=""><?php esc_html_e( 'Choose Form', 'wp-marketing-automations-pro' ); ?></option>
<#
if(_.has(data.eventFieldsOptions, 'registration_forms') && _.isObject(data.eventFieldsOptions.registration_forms) ) {
_.each( data.eventFieldsOptions.registration_forms, function( value, key ){
selected = (key == selected_reg_form) ? 'selected' : '';
#>
<option value="{{key}}" {{selected}}>{{value}}</option>
<# })
}
#>
</select>
</div>
<#
show_mapping = !_.isEmpty(selected_reg_form)?'block':'none';
#>
<div class="bwfan_mt15"></div>
<div class="bwfan-wlm-forms-map bwfan-col-sm-12 bwfan-p-0 bwfan-mt-5">
<div class="bwfan_spinner bwfan_hide"></div>
<div class="bwfan-col-sm-12 bwfan-p-0 bwfan-wlm-field-map" style="display:{{show_mapping}}">
<label for="" class="bwfan-label-title"><?php esc_html_e( 'Map Email field if exists (optional)', 'wp-marketing-automations-pro' ); ?></label>
<select id="bwfan-wlm_email_field_map" class="bwfan-input-wrapper" name="event_meta[email_map]">
<option value=""><?php esc_html_e( 'None', 'wp-marketing-automations-pro' ); ?></option>
<#
_.each( bwfan_events_js_data['wlm_user_registration']['selected_form_fields'], function( value, key ){
selected =(key == selected_field_map)?'selected':'';
#>
<option value="{{key}}" {{selected}}>{{value}}</option>
<# })
#>
</select>
</div>
</div>
</script>
<script>
jQuery(document).on('change', '#bwfan-wlm_form_submit_form_id', function () {
var selected_id = jQuery(this).val();
bwfan_events_js_data['wlm_user_registration']['selected_id'] = selected_id;
if (_.isEmpty(selected_id)) {
jQuery(".bwfan-wlm-field-map").hide();
return false;
}
jQuery(".bwfan-wlm-forms-map .bwfan_spinner").removeClass('bwfan_hide');
jQuery(".bwfan-wlm-field-map").hide();
jQuery.ajax({
method: 'post',
url: "<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>",
datatype: "JSON",
data: {
action: 'bwfan_get_wlm_form_fields',
id: selected_id,
},
success: function (response) {
jQuery(".bwfan-wlm-forms-map .bwfan_spinner").addClass('bwfan_hide');
jQuery(".bwfan-wlm-field-map").show();
update_wlm_email_field_map(response.fields);
_
bwfan_events_js_data['wlm_user_registration']['selected_form_fields'] = response.fields;
}
});
});
function update_wlm_email_field_map(fields) {
jQuery("#bwfan-wlm_email_field_map").html('');
var option = '<option value="">None</option>';
if (_.size(fields) > 0 && _.isObject(fields)) {
_.each(fields, function (v, e) {
option += '<option value="' + e + '">' + v + '</option>';
});
}
jQuery("#bwfan-wlm_email_field_map").html(option);
}
jQuery('body').on('bwfan-change-rule', function (e, v) {
if ('wlm_form_field' !== v.value) {
return;
}
var options = '';
_.each(bwfan_events_js_data['wlm_user_registration']['selected_form_fields'], function (value, key) {
options += '<option value="' + key + '">' + value + '</option>';
});
v.scope.find('.bwfan_wlm_form_fields').html(options);
});
jQuery('body').on('bwfan-selected-merge-tag', function (e, v) {
if ('wishlist_member_form_field' !== v.tag) {
return;
}
var options = '';
var i = 1;
var selected = '';
_.each(bwfan_events_js_data['wlm_user_registration']['selected_form_fields'], function (value, key) {
selected = (i == 1) ? 'selected' : '';
options += '<option value="' + key + '" ' + selected + '>' + value + '</option>';
i++;
});
jQuery('.bwfan_wlm_form_fields').html(options);
jQuery('.bwfan_tag_select').trigger('change');
});
</script>
<?php
}
/**
* Set up rules data
*
* @param $automation_data
*/
public function pre_executable_actions( $automation_data ) {
$email_map = $automation_data['event_meta']['email_map'];
$this->email = ( ! empty( $email_map ) && isset( $this->entry[ $email_map ] ) && is_email( trim( $this->entry[ $email_map ] ) ) ) ? $this->entry[ $email_map ] : '';
BWFAN_Core()->rules->setRulesData( $this->form_id, 'form_id' );
BWFAN_Core()->rules->setRulesData( $this->form_title, 'form_title' );
BWFAN_Core()->rules->setRulesData( $this->entry, 'entry' );
BWFAN_Core()->rules->setRulesData( $this->fields, 'fields' );
BWFAN_Core()->rules->setRulesData( $this->email, 'email' );
BWFAN_Core()->rules->setRulesData( $this->level_id, 'level_id' );
BWFAN_Core()->rules->setRulesData( BWFAN_Common::get_bwf_customer( $this->email, $this->get_user_id_event() ), 'bwf_customer' );
}
public function get_user_id_event() {
if ( is_email( $this->email ) ) {
$user = get_user_by( 'email', $this->email );
return ( $user instanceof WP_User ) ? $user->ID : false;
}
return false;
}
/**
* 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']['form_id'] = $this->form_id;
$data_to_send['global']['form_title'] = $this->form_title;
$data_to_send['global']['entry'] = $this->entry;
$data_to_send['global']['fields'] = $this->fields;
$data_to_send['global']['email'] = $this->email;
$data_to_send['global']['level_id'] = $this->level_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();
?>
<li>
<strong><?php echo esc_html__( 'Form ID:', 'wp-marketing-automations-pro' ); ?> </strong>
<span><?php echo esc_html__( $global_data['form_id'] ); ?></span>
</li>
<li>
<strong><?php echo esc_html__( 'Form Title:', 'wp-marketing-automations-pro' ); ?> </strong>
<?php echo esc_html__( $global_data['form_title'] ); ?>
</li>
<?php
return ob_get_clean();
}
public function get_email_event() {
return is_email( $this->email ) ? $this->email : null;
}
/**
* 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( 'form_id' );
if ( ( empty( $get_data ) || strval( $get_data ) !== strval( $task_meta['global']['form_id'] ) ) ) {
$set_data = array(
'form_id' => $task_meta['global']['form_id'],
'form_title' => $task_meta['global']['form_title'],
'entry' => $task_meta['global']['entry'],
'fields' => $task_meta['global']['fields'],
'email' => $task_meta['global']['email'],
'level_id' => $task_meta['global']['level_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->form_id = BWFAN_Common::$events_async_data['form_id'];
$this->form_title = BWFAN_Common::$events_async_data['form_title'];
$this->entry = BWFAN_Common::$events_async_data['entry'];
$this->fields = BWFAN_Common::$events_async_data['fields'];
$this->entry_id = BWFAN_Common::$events_async_data['entry_id'];
$this->email = BWFAN_Common::$events_async_data['email'];
$this->level_id = BWFAN_Common::$events_async_data['level_id'];
return $this->run_automations();
}
/** validate event data before creating task
*
* @param $automations_arr
*
* @return mixed
*/
public function validate_event_data_before_creating_task( $automations_arr ) {
$automations_arr_temp = $automations_arr;
foreach ( $automations_arr as $automation_id => $automation_data ) {
if ( strval( $automation_data['event_meta']['reg_form'] ) === strval( 'default' ) ) {
$reg_form = 'DEFAULT-' . $this->level_id;
} else {
$reg_form = $automation_data['event_meta']['reg_form'];
}
if ( strval( $this->form_id ) !== strval( $reg_form ) ) {
unset( $automations_arr_temp[ $automation_id ] );
}
}
return $automations_arr_temp;
}
public function add_form_data( $event_js_data, $automation_meta ) {
if ( ! isset( $automation_meta['event_meta'] ) || ! isset( $event_js_data['wlm_user_registration'] ) || ! isset( $automation_meta['event_meta']['reg_form'] ) ) {
return $event_js_data;
}
if ( isset( $automation_meta['event'] ) && ! empty( $automation_meta['event'] ) && 'wlm_user_registration' !== $automation_meta['event'] ) {
return $event_js_data;
}
$event_js_data['wlm_user_registration']['selected_id'] = $automation_meta['event_meta']['reg_form'];
$fields = $this->get_form_fields( $automation_meta['event_meta']['reg_form'] );
$event_js_data['wlm_user_registration']['selected_form_fields'] = $fields;
return $event_js_data;
}
/**
* get form field on ajax
*/
public function bwfan_get_wlm_form_fields() {
BWFAN_PRO_Common::nocache_headers();
$form_id = sanitize_text_field( $_POST['id'] ); // WordPress.CSRF.NonceVerification.NoNonceVerification
$fields = [];
if ( empty( $form_id ) ) {
wp_send_json( array(
'fields' => $fields,
) );
}
$fields = $this->get_form_fields( $form_id );
/** fields for v2 */
if ( isset( $_POST['fromApp'] ) && $_POST['fromApp'] ) {
$finalarr = [];
foreach ( $fields as $key => $value ) {
$finalarr[] = [
'key' => $key,
'value' => $value
];
}
wp_send_json( array(
'results' => $finalarr
) );
exit;
}
wp_send_json( array(
'fields' => $fields,
) );
}
/**
* v2 Method: Validate event settings
*
* @param $automation_data
*
* @return bool
*/
public function validate_v2_event_settings( $automation_data ) {
$matched_form = strval( $automation_data['event_meta']['bwfan-wlm_form_submit_form_id'] );
if ( $matched_form === 'default' ) {
$matched_form = strval( 'DEFAULT-' . $automation_data['level_id'] );
}
if ( strval( $automation_data['form_id'] ) !== $matched_form ) {
return false;
}
return true;
}
/**
* Capture v2 data.
* @return array|bool
*/
public function capture_v2_data( $automation_data ) {
$this->form_id = BWFAN_Common::$events_async_data['form_id'];
$this->form_title = BWFAN_Common::$events_async_data['form_title'];
$this->entry = BWFAN_Common::$events_async_data['entry'];
$this->fields = BWFAN_Common::$events_async_data['fields'];
$this->entry_id = BWFAN_Common::$events_async_data['entry_id'];
$this->email = BWFAN_Common::$events_async_data['email'];
$this->level_id = BWFAN_Common::$events_async_data['level_id'];
$automation_data['form_id'] = $this->form_id;
$automation_data['form_title'] = $this->form_title;
$automation_data['entry'] = $this->entry;
$automation_data['fields'] = $this->fields;
$automation_data['entry_id'] = $this->entry_id;
$automation_data['email'] = $this->email;
$automation_data['level_id'] = $this->level_id;
return $automation_data;
}
/**
* v2 Method: Get field Schema
*
* @return array[]
*/
public function get_fields_schema() {
$options = array_replace( [ '' => 'Select' ], $this->get_view_data() );
$options = BWFAN_PRO_Common::prepared_field_options( $options );
return [
[
'id' => 'bwfan-wlm_form_submit_form_id',
'label' => __( "Select Form", 'wp-marketing-automations-pro' ),
'type' => 'select',
'options' => $options,
'label' => __( 'Select Form', 'wp-marketing-automations-pro' ),
"class" => 'bwfan-input-wrapper',
"placeholder" => 'Select',
"required" => true,
"errorMsg" => __( "Form is required.", 'wp-marketing-automations-pro' ),
"description" => ""
],
[
'id' => 'bwfan-wlm_email_field_map',
'type' => 'ajax',
'label' => __( 'Select Email Field', 'wp-marketing-automations-pro' ),
"class" => 'bwfan-input-wrapper',
"tip" => "Map the field to be used by appropriate Rules and Actions.",
"required" => true,
'placeholder' => __( 'Select', 'wp-marketing-automations-pro' ),
"description" => "",
"ajax_cb" => 'bwfan_get_wlm_form_fields',
"ajax_field" => [
'id' => 'bwfan-wlm_form_submit_form_id'
],
"toggler" => [
'fields' => array(
array(
'id' => 'bwfan-wlm_form_submit_form_id',
'value' => '',
),
),
'relation' => 'AND',
]
],
];
}
}
/**
* Register this event to a source.
* This will show the current event in dropdown in single automation screen.
*/
if ( function_exists( 'bwfan_is_wlm_active' ) && bwfan_is_wlm_active() ) {
return 'BWFAN_WLM_User_Registration';
}

View File

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

View File

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

View File

@@ -0,0 +1,46 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
class BWFAN_WLM_levels {
private static $ins = null;
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public function get_slug() {
return 'wlm_levels';
}
public function get_options( $search ) {
$action = BWFAN_Core()->integration->get_action( 'wlm_user_add_level' );
if ( ! $action instanceof BWFAN_Action ) {
return [];
}
$data = $action->get_view_data();
if ( empty( $search ) ) {
return $data;
}
return BWFAN_PRO_Common::search_srting_from_data( $data, $search );
}
}
if ( class_exists( 'BWFAN_Load_Custom_Search' ) ) {
BWFAN_Load_Custom_Search::register( 'BWFAN_WLM_levels' );
}

View File

@@ -0,0 +1,46 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
class BWFAN_WLM_Pay_Per_Post {
private static $ins = null;
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public function get_slug() {
return 'wlm_pay_per_post';
}
public function get_options( $search ) {
$action = BWFAN_Core()->integration->get_action( 'wlm_add_user_to_pay_per_post' );
if ( ! $action instanceof BWFAN_Action ) {
return [];
}
$data = $action->get_view_data();
if ( empty( $search ) ) {
return $data;
}
return BWFAN_PRO_Common::search_srting_from_data( $data, $search );
}
}
if ( class_exists( 'BWFAN_Load_Custom_Search' ) ) {
BWFAN_Load_Custom_Search::register( 'BWFAN_WLM_Pay_Per_Post' );
}

View File

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

View File

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

View File

@@ -0,0 +1,140 @@
<?php
class BWFAN_WLM_Form_Field extends BWFAN_Merge_Tag {
private static $instance = null;
public function __construct() {
$this->tag_name = 'wishlist_member_form_field';
$this->tag_description = __( 'WishList Form Field', 'wp-marketing-automations-pro' );
add_shortcode( 'bwfan_wishlist_member_form_field', array( $this, 'parse_shortcode' ) );
add_action( 'wp_ajax_bwfan_get_wlm_reg_form_field', array( $this, 'bwfan_get_wlm_reg_form_field' ) );
}
public static function get_instance() {
if ( null === self::$instance ) {
self::$instance = new self();
}
return self::$instance;
}
/**
* Show the html in popup for the merge tag.
*/
public function get_view() {
$this->get_back_button();
?>
<label for="" class="bwfan-label-title"><?php echo esc_html__( 'Select Field', 'wp-marketing-automations-pro' ); ?></label>
<select id="" class="bwfan-input-wrapper bwfan-mb-15 bwfan_tag_select bwfan_wlm_form_fields" name="field"></select>
<?php
if ( $this->support_fallback ) {
$this->get_fallback();
}
$this->get_preview();
$this->get_copy_button();
}
/**
* Parse the merge tag and return its value.
*
* @param $attr
*
* @return mixed|string|void
*/
public function parse_shortcode( $attr ) {
if ( true === BWFAN_Merge_Tag_Loader::get_data( 'is_preview' ) ) {
return $this->get_dummy_preview();
}
$entry = BWFAN_Merge_Tag_Loader::get_data( 'entry' );
$field_value = '';
$attr_field = isset( $attr['field'] ) ? str_replace( ' ', '_', $attr['field'] ) : '';
if ( empty( $attr_field ) || ! isset( $entry[ $attr_field ] ) ) {
return $this->parse_shortcode_output( $field_value, $attr );
}
$field_value = $entry[ $attr_field ];
return $this->parse_shortcode_output( $field_value, $attr );
}
/**
* Show dummy value of the current merge tag.
*
* @return string
*
* @todo:Hard values shouldn't be passed
*/
public function get_dummy_preview() {
return 'Test';
}
public function bwfan_get_wlm_reg_form_field() {
BWFAN_PRO_Common::nocache_headers();
$finalarr = [];
$automationId = absint( sanitize_text_field( $_POST['automationId'] ) );
/** Check Automation */
$automation_obj = BWFAN_Automation_V2::get_instance( $automationId );
/** Check for automation exists */
if ( empty( $automation_obj->error ) ) {
$automation_meta = $automation_obj->get_automation_meta_data();
if ( isset( $automation_meta['event_meta'] ) && isset( $automation_meta['event_meta']['bwfan-wlm_form_submit_form_id'] ) ) {
$form_id = sanitize_text_field( $automation_meta['event_meta']['bwfan-wlm_form_submit_form_id'] );
$fields = [];
if ( ! empty( $form_id ) ) {
$obj = BWFAN_WLM_User_Registration::get_instance();
$fields = $obj->get_form_fields( $form_id );
}
/** Handling form fields for the v2 automations */
foreach ( $fields as $key => $value ) {
$finalarr[] = [
'key' => $key,
'value' => $value
];
}
}
}
wp_send_json( array(
'results' => $finalarr
) );
exit;
}
/**
* Returns merge tag schema
*
* @return array[]
*/
public function get_setting_schema() {
return [
[
'id' => 'field',
'type' => 'ajax',
'label' => __( 'Select Field', 'wp-marketing-automations-pro' ),
"class" => 'bwfan-input-wrapper',
"required" => true,
'placeholder' => __( 'Select', 'wp-marketing-automations-pro' ),
"description" => "",
"ajax_cb" => 'bwfan_get_wlm_reg_form_field',
]
];
}
}
/**
* Register this merge tag to a group.
*/
if ( function_exists( 'bwfan_is_wlm_active' ) && bwfan_is_wlm_active() ) {
BWFAN_Merge_Tag_Loader::register( 'wlm_forms', 'BWFAN_WLM_Form_Field', null, __( 'WooCommerce Membership', 'wp-marketing-automations-pro' ) );
}

View File

@@ -0,0 +1,57 @@
<?php
class BWFAN_WLM_Form_ID extends BWFAN_Merge_Tag {
private static $instance = null;
public function __construct() {
$this->tag_name = 'wishlist_member_form_id';
$this->tag_description = __( 'WishList Form ID', 'wp-marketing-automations-pro' );
add_shortcode( 'bwfan_wishlist_member_form_id', array( $this, 'parse_shortcode' ) );
}
public static function get_instance() {
if ( null === self::$instance ) {
self::$instance = new self();
}
return self::$instance;
}
/**
* Parse the merge tag and return its value.
*
* @param $attr
*
* @return mixed|string|void
*/
public function parse_shortcode( $attr ) {
if ( true === BWFAN_Merge_Tag_Loader::get_data( 'is_preview' ) ) {
return $this->get_dummy_preview();
}
$form_id = BWFAN_Merge_Tag_Loader::get_data( 'form_id' );
return $this->parse_shortcode_output( $form_id, $attr );
}
/**
* Show dummy value of the current merge tag.
*
* @return string
*
* @todo:Hard values shouldn't be passed
*/
public function get_dummy_preview() {
return '11';
}
}
/**
* Register this merge tag to a group.
*/
if ( function_exists( 'bwfan_is_wlm_active' ) && bwfan_is_wlm_active() ) {
BWFAN_Merge_Tag_Loader::register( 'wlm_forms', 'BWFAN_WLM_Form_ID', null, __( 'Wishlist Member', 'wp-marketing-automations-pro' ) );
}

View File

@@ -0,0 +1,57 @@
<?php
class BWFAN_WLM_Form_Title extends BWFAN_Merge_Tag {
private static $instance = null;
public function __construct() {
$this->tag_name = 'wishlist_member_form_title';
$this->tag_description = __( 'WishList Form Title', 'wp-marketing-automations-pro' );
add_shortcode( 'bwfan_wishlist_member_form_title', array( $this, 'parse_shortcode' ) );
}
public static function get_instance() {
if ( null === self::$instance ) {
self::$instance = new self();
}
return self::$instance;
}
/**
* Parse the merge tag and return its value.
*
* @param $attr
*
* @return mixed|string|void
*/
public function parse_shortcode( $attr ) {
if ( true === BWFAN_Merge_Tag_Loader::get_data( 'is_preview' ) ) {
return $this->get_dummy_preview();
}
$form_title = BWFAN_Merge_Tag_Loader::get_data( 'form_title' );
return $this->parse_shortcode_output( $form_title, $attr );
}
/**
* Show dummy value of the current merge tag.
*
* @return string
*
* @todo:Hard values shouldn't be passed
*/
public function get_dummy_preview() {
return '11';
}
}
/**
* Register this merge tag to a group.
*/
if ( function_exists( 'bwfan_is_wlm_active' ) && bwfan_is_wlm_active() ) {
BWFAN_Merge_Tag_Loader::register( 'wlm_forms', 'BWFAN_WLM_Form_Title', null, __( 'WooCommerce Membership', 'wp-marketing-automations-pro' ) );
}

View File

@@ -0,0 +1,59 @@
<?php
class BWFAN_WLM_Level_ID extends BWFAN_Merge_Tag {
private static $instance = null;
public function __construct() {
$this->tag_name = 'wishlist_member_level_id';
$this->tag_description = __( 'WishList Member Level ID', 'wp-marketing-automations-pro' );
add_shortcode( 'bwfan_wishlist_member_level_id', array( $this, 'parse_shortcode' ) );
}
public static function get_instance() {
if ( null === self::$instance ) {
self::$instance = new self();
}
return self::$instance;
}
/**
* Parse the merge tag and return its value.
*
* @param $attr
*
* @return mixed|string|void
*/
public function parse_shortcode( $attr ) {
if ( true === BWFAN_Merge_Tag_Loader::get_data( 'is_preview' ) ) {
return $this->get_dummy_preview();
}
$level_id = BWFAN_Merge_Tag_Loader::get_data( 'level_id' );
if ( empty( $level_id ) ) {
return $this->parse_shortcode_output( '', $attr );
}
return $this->parse_shortcode_output( $level_id, $attr );
}
/**
* Show dummy value of the current merge tag.
*
* @return string
*
* @todo:Hard values shouldn't be passed
*/
public function get_dummy_preview() {
return 11;
}
}
/**
* Register this merge tag to a group.
*/
if ( function_exists( 'bwfan_is_wlm_active' ) && bwfan_is_wlm_active() ) {
BWFAN_Merge_Tag_Loader::register( 'wlm_wishlist', 'BWFAN_WLM_Level_ID', null, __( 'WooCommerce Membership', 'wp-marketing-automations-pro' ) );
}

View File

@@ -0,0 +1,62 @@
<?php
class BWFAN_WLM_Level_Name extends BWFAN_Merge_Tag {
private static $instance = null;
public function __construct() {
$this->tag_name = 'wishlist_member_level_name';
$this->tag_description = __( 'WishList Member Level Name', 'wp-marketing-automations-pro' );
add_shortcode( 'bwfan_wishlist_member_level_name', array( $this, 'parse_shortcode' ) );
}
public static function get_instance() {
if ( null === self::$instance ) {
self::$instance = new self();
}
return self::$instance;
}
/**
* Parse the merge tag and return its value.
*
* @param $attr
*
* @return mixed|string|void
*/
public function parse_shortcode( $attr ) {
if ( true === BWFAN_Merge_Tag_Loader::get_data( 'is_preview' ) ) {
return $this->get_dummy_preview();
}
$level_id = BWFAN_Merge_Tag_Loader::get_data( 'level_id' );
if ( empty( $level_id ) ) {
return $this->parse_shortcode_output( '', $attr );
}
$level_name = wlmapi_get_level( $level_id );
$level_name = isset( $level_name['level'] ) && isset( $level_name['level']['name'] ) ? $level_name['level']['name'] : '';
return $this->parse_shortcode_output( $level_name, $attr );
}
/**
* Show dummy value of the current merge tag.
*
* @return string
*
* @todo:Hard values shouldn't be passed
*/
public function get_dummy_preview() {
return 'Platinum';
}
}
/**
* Register this merge tag to a group.
*/
if ( function_exists( 'bwfan_is_wlm_active' ) && bwfan_is_wlm_active() ) {
BWFAN_Merge_Tag_Loader::register( 'wlm_wishlist', 'BWFAN_WLM_Level_Name', null, __( 'WooCommerce Membership', 'wp-marketing-automations-pro' ) );
}

View File

@@ -0,0 +1,59 @@
<?php
class BWFAN_WLM_User_Level_Expire_Date extends BWFAN_Merge_Tag {
private static $instance = null;
public function __construct() {
$this->tag_name = 'wishlist_member_level_expire_date';
$this->tag_description = __( 'WishList Member Level Expiry Date', 'wp-marketing-automations-pro' );
add_shortcode( 'bwfan_wishlist_member_level_expire_date', array( $this, 'parse_shortcode' ) );
}
public static function get_instance() {
if ( null === self::$instance ) {
self::$instance = new self();
}
return self::$instance;
}
/**
* Parse the merge tag and return its value.
*
* @param $attr
*
* @return mixed|string|void
*/
public function parse_shortcode( $attr ) {
if ( true === BWFAN_Merge_Tag_Loader::get_data( 'is_preview' ) ) {
return $this->get_dummy_preview();
}
$expire_date = BWFAN_Merge_Tag_Loader::get_data( 'expire_date' );
if ( empty( $expire_date ) ) {
return $this->parse_shortcode_output( '', $attr );
}
return $this->parse_shortcode_output( date( 'Y-m-d', $expire_date ), $attr );
}
/**
* Show dummy value of the current merge tag.
*
* @return string
*
* @todo:Hard values shouldn't be passed
*/
public function get_dummy_preview() {
return date( 'Y-m-d' );
}
}
/**
* Register this merge tag to a group.
*/
if ( function_exists( 'bwfan_is_wlm_active' ) && bwfan_is_wlm_active() ) {
BWFAN_Merge_Tag_Loader::register( 'wlm_user_level_expire_date', 'BWFAN_WLM_User_Level_Expire_Date', null, __( 'WooCommerce Membership', 'wp-marketing-automations-pro' ) );
}

View File

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