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,224 @@
<?php
final class BWFAN_LD_Add_User_To_Group extends BWFAN_Action {
private static $ins = null;
protected function __construct() {
$this->action_name = __( 'Add User to Group', 'wp-marketing-automations-pro' );
$this->action_desc = __( 'This action adds a user to the group', 'wp-marketing-automations-pro' );
$this->required_fields = array( 'user_id', 'group_id' );
$this->action_priority = 15;
$this->support_v2 = true;
}
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
/**
* Localize data for html fields for the current action.
*/
public function admin_enqueue_assets() {
if ( BWFAN_Common::is_load_admin_assets( 'automation' ) ) {
$data = $this->get_view_data();
BWFAN_Core()->admin->set_actions_js_data( $this->get_class_slug(), 'groups', $data );
}
}
public function get_view_data() {
$groups = get_posts( array(
'post_type' => 'groups',
'posts_per_page' => - 1,
'status' => 'publish',
'suppress_filters' => false
) );
$group_array = array();
foreach ( $groups as $group ) {
$group_array[ $group->ID ] = $group->post_title;
}
return $group_array;
}
/**
* 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_group = (_.has(data.actionSavedData, 'data') && _.has(data.actionSavedData.data, 'group')) ? data.actionSavedData.data.group : '';
#>
<div class="bwfan-<?php echo esc_html__( $this->get_slug() ); ?>">
<label for="" class="bwfan-label-title"><?php echo esc_html__( 'Group', 'wp-marketing-automations-pro' ); ?></label>
<select required id="" class="bwfan-input-wrapper" name="bwfan[{{data.action_id}}][data][group]">
<option value=""><?php echo esc_html__( 'Choose any Group', 'wp-marketing-automations-pro' ); ?></option>
<#
if(_.has(data.actionFieldsOptions, 'groups') && _.isObject(data.actionFieldsOptions.groups) ) {
_.each( data.actionFieldsOptions.groups, function( value, key ){
selected = (key == selected_group) ? 'selected' : '';
#>
<option value="{{key}}" {{selected}}>{{value}}</option>
<# })
}
#>
</select>
<div class="clearfix bwfan_field_desc bwfan-mb20">Select the group in which you want to add user</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['user_id'] = $task_meta['global']['user_id'];
$data_to_set['group_id'] = $task_meta['data']['group'];
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 ) {
$data_to_set = array();
$data_to_set['user_id'] = isset( $step_data['user_id'] ) ? $step_data['user_id'] : 0;
$data_to_set['group_id'] = isset( $step_data['group'][0]['id'] ) ? $step_data['group'][0]['id'] : 0;
if ( empty( $data_to_set['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 ) : '';
$data_to_set['user_id'] = $user instanceof WP_User ? $user->ID : 0;
}
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 the group'
);
}
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();
}
$group_id = absint( $this->data['group_id'] );
if ( empty( $group_id ) ) {
return array(
'status' => 4,
'message' => __( 'Group was not selected', 'wp-marketing-automations-pro' ),
);
}
$user_id = $this->data['user_id'];
$user = get_userdata( $user_id );
if ( false === $user ) {
return array(
'status' => 4,
'message' => __( 'User does not exists', 'wp-marketing-automations-pro' ),
);
}
ld_update_group_access( $user_id, $group_id );
return true;
}
public function process_v2() {
$group_id = absint( $this->data['group_id'] );
if ( empty( $group_id ) ) {
return $this->skipped_response( __( 'Group was not selected', 'wp-marketing-automations-pro' ) );
}
$user_id = $this->data['user_id'];
$user = get_userdata( $user_id );
if ( false === $user ) {
return $this->skipped_response( __( 'User does not exists', 'wp-marketing-automations-pro' ) );
}
ld_update_group_access( $user_id, $group_id );
return $this->success_message( 'User added in group.' );
}
public function get_fields_schema() {
return [
[
"id" => 'group',
"label" => __( 'Group', 'wp-marketing-automations-pro' ),
"type" => 'custom_search',
'autocompleterOption' => [
'path' => 'ld_groups',
'slug' => 'ld_groups',
'labelText' => 'group'
],
"allowFreeTextSearch" => false,
"required" => true,
"errorMsg" => __( "Group 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['group'] ) || empty( $data['group'] ) ) {
return '';
}
$groups = [];
foreach ( $data['group'] as $group ) {
if ( ! isset( $group['name'] ) || empty( $group['name'] ) ) {
continue;
}
$groups[] = $group['name'];
}
return $groups;
}
}
/**
* Register this action. Registering the action will make it eligible to see it on single automation screen in select actions dropdown.
*/
return 'BWFAN_LD_Add_User_To_Group';

View File

@@ -0,0 +1,193 @@
<?php
final class BWFAN_LD_Enroll_User_Into_Course extends BWFAN_Action {
private static $ins = null;
protected function __construct() {
$this->action_name = __( 'Enroll User into Course(s)', 'wp-marketing-automations-pro' );
$this->action_desc = __( 'This action enrolls a user into a selected courses', 'wp-marketing-automations-pro' );
$this->required_fields = array( 'user_id', 'courses' );
$this->action_priority = 5;
$this->support_v2 = true;
}
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-course-search', function (e) {
var temp_courses = {};
var course_data = $(this).select2('data');
course_data.forEach(function (item) {
temp_courses[item.id] = item.text;
});
$(this).parent().find('.bwfan_searched_course_name').val(JSON.stringify(temp_courses));
});
});
</script>
<script type="text/html" id="tmpl-action-<?php esc_attr_e( $this->get_slug() ); ?>">
<#
searched_courses = (_.has(data.actionSavedData, 'data') && _.has(data.actionSavedData.data, 'searched_courses')) ? data.actionSavedData.data.searched_courses : '';
selected_courses = (_.has(data.actionSavedData, 'data') && _.has(data.actionSavedData.data, 'courses')) ? data.actionSavedData.data.courses : {};
#>
<div class="bwfan-input-form clearfix">
<label for="" class="bwfan-label-title"><?php esc_html_e( 'Select Courses', 'wp-marketing-automations-pro' ); ?></label>
<select required id="" data-search="sfwd-courses" data-search-text="<?php esc_attr_e( 'Select Course', 'wp-marketing-automations-pro' ); ?>" class="bwfan-select2ajax-single bwfan-course-search bwfan-input-wrapper" name="bwfan[{{data.action_id}}][data][courses][]" multiple>
<#
if(_.size(searched_courses) >0) {
temp_selected_course = JSON.parse(searched_courses);
_.each( selected_courses, function( v ){
#>
<option value="{{v}}" selected>{{temp_selected_course[v]}}</option>
<#
})
}
#>
</select>
<input type="hidden" class="bwfan_searched_course_name" name="bwfan[{{data.action_id}}][data][searched_courses]" value="{{searched_courses}}"/>
</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(
'courses' => $task_meta['data']['courses'],
'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 ) {
$data_to_set = array();
$data_to_set['user_id'] = isset( $step_data['user_id'] ) ? $step_data['user_id'] : 0;
$data_to_set['courses'] = isset( $step_data['courses'] ) && is_array( $step_data['courses'] ) ? array_column( $step_data['courses'], 'id' ) : [];
if ( empty( $data_to_set['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 ) : '';
$data_to_set['user_id'] = $user instanceof WP_User ? $user->ID : 0;
}
return $data_to_set;
}
/**
* Execute the current action.
* Return 3 for successful execution , 4 for permanent failure.
*
* @param $action_data
*
* @return array
*/
public function execute_action( $action_data ) {
$this->set_data( $action_data['processed_data'] );
$result = $this->process();
if ( true === $result ) {
return array(
'status' => 3,
);
}
return array(
'status' => 4,
'message' => ( is_array( $result ) && isset( $result['bwfan_response'] ) ) ? $result['bwfan_response'] : __( 'User could not be enrolled in the course.', 'wp-marketing-automations-pro' ),
);
}
/**
* Process and do the actual processing for the current action.
* This function is present in every action class.
*/
public function process() {
$is_required_fields_present = $this->check_fields( $this->data, $this->required_fields );
if ( false === $is_required_fields_present ) {
return $this->show_fields_error();
}
foreach ( $this->data['courses'] as $course_id ) {
ld_update_course_access( $this->data['user_id'], $course_id );
}
return true;
}
public function process_v2() {
if ( empty( $this->data['courses'] ) && ! is_array( $this->data['courses'] ) ) {
return $this->skipped_response( __( 'Courses not selected', 'wp-marketing-automations-pro' ) );
}
foreach ( $this->data['courses'] as $course_id ) {
ld_update_course_access( $this->data['user_id'], $course_id );
}
return $this->success_message( 'User added in Courses.' );
}
public function get_fields_schema() {
return [
[
"id" => 'courses',
"label" => __( 'Select Courses', 'wp-marketing-automations-pro' ),
"type" => 'custom_search',
'autocompleterOption' => [
'path' => 'ld_courses',
'slug' => 'ld_courses',
'labelText' => 'plan'
],
"allowFreeTextSearch" => false,
"required" => true,
"errorMsg" => __( "Course is required", 'wp-marketing-automations-pro' ),
],
];
}
public function get_desc_text( $data ) {
$data = json_decode( wp_json_encode( $data ), true );
if ( ! isset( $data['courses'] ) || empty( $data['courses'] ) ) {
return '';
}
$courses = [];
foreach ( $data['courses'] as $course ) {
if ( ! isset( $course['name'] ) || empty( $course['name'] ) ) {
continue;
}
$courses[] = $course['name'];
}
return $courses;
}
}
/**
* Register this action. Registering the action will make it eligible to see it on single automation screen in select actions dropdown.
*/
return 'BWFAN_LD_Enroll_User_Into_Course';

View File

@@ -0,0 +1,193 @@
<?php
final class BWFAN_LD_Remove_User_From_Course extends BWFAN_Action {
private static $ins = null;
protected function __construct() {
$this->action_name = __( 'Remove User from Course(s)', 'wp-marketing-automations-pro' );
$this->action_desc = __( 'This action removes a user from a selected courses', 'wp-marketing-automations-pro' );
$this->required_fields = array( 'user_id', 'courses' );
$this->action_priority = 10;
$this->support_v2 = true;
}
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-course-search', function (e) {
var temp_courses = {};
var course_data = $(this).select2('data');
course_data.forEach(function (item) {
temp_courses[item.id] = item.text;
});
$(this).parent().find('.bwfan_searched_course_name').val(JSON.stringify(temp_courses));
});
});
</script>
<script type="text/html" id="tmpl-action-<?php esc_attr_e( $this->get_slug() ); ?>">
<#
searched_courses = (_.has(data.actionSavedData, 'data') && _.has(data.actionSavedData.data, 'searched_courses')) ? data.actionSavedData.data.searched_courses : '';
selected_courses = (_.has(data.actionSavedData, 'data') && _.has(data.actionSavedData.data, 'courses')) ? data.actionSavedData.data.courses : {};
#>
<div class="bwfan-input-form clearfix">
<label for="" class="bwfan-label-title"><?php esc_html_e( 'Select Courses', 'wp-marketing-automations-pro' ); ?></label>
<select required id="" data-search="sfwd-courses" data-search-text="<?php esc_attr_e( 'Select Course', 'wp-marketing-automations-pro' ); ?>" class="bwfan-select2ajax-single bwfan-course-search bwfan-input-wrapper" name="bwfan[{{data.action_id}}][data][courses][]" multiple>
<#
if(_.size(searched_courses) >0) {
temp_selected_course = JSON.parse(searched_courses);
_.each( selected_courses, function( v ){
#>
<option value="{{v}}" selected>{{temp_selected_course[v]}}</option>
<#
})
}
#>
</select>
<input type="hidden" class="bwfan_searched_course_name" name="bwfan[{{data.action_id}}][data][searched_courses]" value="{{searched_courses}}"/>
</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(
'courses' => $task_meta['data']['courses'],
'user_id' => $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 ) {
$data_to_set = array();
$data_to_set['user_id'] = isset( $step_data['user_id'] ) ? $step_data['user_id'] : 0;
$data_to_set['courses'] = isset( $step_data['courses'] ) && is_array( $step_data['courses'] ) ? array_column( $step_data['courses'], 'id' ) : [];
if ( empty( $data_to_set['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 ) : '';
$data_to_set['user_id'] = $user instanceof WP_User ? $user->ID : 0;
}
return $data_to_set;
}
/**
* Execute the current action.
* Return 3 for successful execution , 4 for permanent failure.
*
* @param $action_data
*
* @return array
*/
public function execute_action( $action_data ) {
$this->set_data( $action_data['processed_data'] );
$result = $this->process();
if ( true === $result ) {
return array(
'status' => 3,
);
}
return array(
'status' => 4,
'message' => ( is_array( $result ) && isset( $result['bwfan_response'] ) ) ? $result['bwfan_response'] : __( 'User could not be removed from the course.', 'wp-marketing-automations-pro' ),
);
}
/**
* Process and do the actual processing for the current action.
* This function is present in every action class.
*/
public function process() {
$is_required_fields_present = $this->check_fields( $this->data, $this->required_fields );
if ( false === $is_required_fields_present ) {
return $this->show_fields_error();
}
foreach ( $this->data['courses'] as $course_id ) {
ld_update_course_access( $this->data['user_id'], $course_id, true );
}
return true;
}
public function process_v2() {
if ( empty( $this->data['courses'] ) && ! is_array( $this->data['courses'] ) ) {
return $this->skipped_response( __( 'Courses not selected', 'wp-marketing-automations-pro' ) );
}
foreach ( $this->data['courses'] as $course_id ) {
ld_update_course_access( $this->data['user_id'], $course_id, true );
}
return $this->success_message( 'User removed from Course(s).' );
}
public function get_fields_schema() {
return [
[
"id" => 'courses',
"label" => __( 'Select Courses', 'wp-marketing-automations-pro' ),
"type" => 'custom_search',
'autocompleterOption' => [
'path' => 'ld_courses',
'slug' => 'ld_courses',
'labelText' => 'plan'
],
"allowFreeTextSearch" => false,
"required" => true,
"errorMsg" => __( "Course is required", 'wp-marketing-automations-pro' ),
],
];
}
public function get_desc_text( $data ) {
$data = json_decode( wp_json_encode( $data ), true );
if ( ! isset( $data['courses'] ) || empty( $data['courses'] ) ) {
return '';
}
$courses = [];
foreach ( $data['courses'] as $course ) {
if ( ! isset( $course['name'] ) || empty( $course['name'] ) ) {
continue;
}
$courses[] = $course['name'];
}
return $courses;
}
}
/**
* Register this action. Registering the action will make it eligible to see it on single automation screen in select actions dropdown.
*/
return 'BWFAN_LD_Remove_User_From_Course';

View File

@@ -0,0 +1,224 @@
<?php
final class BWFAN_LD_Add_User_From_Group extends BWFAN_Action {
private static $ins = null;
protected function __construct() {
$this->action_name = __( 'Remove User from Group', 'wp-marketing-automations-pro' );
$this->action_desc = __( 'This action removed a user from a selected group', 'wp-marketing-automations-pro' );
$this->required_fields = array( 'user_id', 'group_id' );
$this->action_priority = 20;
$this->support_v2 = true;
}
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
/**
* Localize data for html fields for the current action.
*/
public function admin_enqueue_assets() {
if ( BWFAN_Common::is_load_admin_assets( 'automation' ) ) {
$data = $this->get_view_data();
BWFAN_Core()->admin->set_actions_js_data( $this->get_class_slug(), 'groups', $data );
}
}
public function get_view_data() {
$groups = get_posts( array(
'post_type' => 'groups',
'posts_per_page' => - 1,
'status' => 'publish',
'suppress_filters' => false
) );
$group_array = array();
foreach ( $groups as $group ) {
$group_array[ $group->ID ] = $group->post_title;
}
return $group_array;
}
/**
* 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_group = (_.has(data.actionSavedData, 'data') && _.has(data.actionSavedData.data, 'group')) ? data.actionSavedData.data.group : '';
#>
<div class="bwfan-<?php echo esc_html__( $this->get_slug() ); ?>">
<label for="" class="bwfan-label-title"><?php echo esc_html__( 'Group', 'wp-marketing-automations-pro' ); ?></label>
<select required id="" class="bwfan-input-wrapper" name="bwfan[{{data.action_id}}][data][group]">
<option value=""><?php echo esc_html__( 'Choose any Group', 'wp-marketing-automations-pro' ); ?></option>
<#
if(_.has(data.actionFieldsOptions, 'groups') && _.isObject(data.actionFieldsOptions.groups) ) {
_.each( data.actionFieldsOptions.groups, function( value, key ){
selected = (key == selected_group) ? 'selected' : '';
#>
<option value="{{key}}" {{selected}}>{{value}}</option>
<# })
}
#>
</select>
<div class="clearfix bwfan_field_desc bwfan-mb20">Select the group from which you want to remove user</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['user_id'] = $task_meta['global']['user_id'];
$data_to_set['group_id'] = $task_meta['data']['group'];
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 ) {
$data_to_set = array();
$data_to_set['user_id'] = isset( $step_data['user_id'] ) ? $step_data['user_id'] : 0;
$data_to_set['group_id'] = isset( $step_data['group'][0]['id'] ) ? $step_data['group'][0]['id'] : 0;
if ( empty( $data_to_set['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 ) : '';
$data_to_set['user_id'] = $user instanceof WP_User ? $user->ID : 0;
}
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 a group'
);
}
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();
}
$group_id = absint( $this->data['group_id'] );
if ( empty( $group_id ) ) {
return array(
'status' => 4,
'message' => __( 'Group was not selected', 'wp-marketing-automations-pro' ),
);
}
$user_id = $this->data['user_id'];
$user = get_userdata( $user_id );
if ( false === $user ) {
return array(
'status' => 4,
'message' => __( 'User does not exists', 'wp-marketing-automations-pro' ),
);
}
ld_update_group_access( $user_id, $group_id, true );
return true;
}
public function process_v2() {
$group_id = absint( $this->data['group_id'] );
if ( empty( $group_id ) ) {
return $this->skipped_response( __( 'Group was not selected', 'wp-marketing-automations-pro' ) );
}
$user_id = $this->data['user_id'];
$user = get_userdata( $user_id );
if ( false === $user ) {
return $this->skipped_response( __( 'User does not exists', 'wp-marketing-automations-pro' ) );
}
ld_update_group_access( $user_id, $group_id, true );
return $this->success_message( 'User removed from group.' );
}
public function get_fields_schema() {
return [
[
"id" => 'group',
"label" => __( 'Group', 'wp-marketing-automations-pro' ),
"type" => 'custom_search',
'autocompleterOption' => [
'path' => 'ld_groups',
'slug' => 'ld_groups',
'labelText' => 'group'
],
"allowFreeTextSearch" => false,
"required" => true,
"errorMsg" => __( "Group 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['group'] ) || empty( $data['group'] ) ) {
return '';
}
$groups = [];
foreach ( $data['group'] as $group ) {
if ( ! isset( $group['name'] ) || empty( $group['name'] ) ) {
continue;
}
$groups[] = $group['name'];
}
return $groups;
}
}
/**
* Register this action. Registering the action will make it eligible to see it on single automation screen in select actions dropdown.
*/
return 'BWFAN_LD_Add_User_From_Group';

View File

@@ -0,0 +1,224 @@
<?php
final class BWFAN_LD_Reset_Course_Progress extends BWFAN_Action {
private static $ins = null;
protected function __construct() {
$this->action_name = __( 'Reset Course Progress', 'wp-marketing-automations-pro' );
$this->action_desc = __( 'This action resets the course progress of a user', 'wp-marketing-automations-pro' );
$this->required_fields = array( 'user_id', 'course_id' );
$this->action_priority = 30;
$this->support_v2 = true;
}
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
/**
* Localize data for html fields for the current action.
*/
public function admin_enqueue_assets() {
if ( BWFAN_Common::is_load_admin_assets( 'automation' ) ) {
$data = $this->get_view_data();
BWFAN_Core()->admin->set_actions_js_data( $this->get_class_slug(), 'courses', $data );
}
}
public function get_view_data() {
if ( ! function_exists( 'learndash_get_courses_count' ) ) {
return array();
}
/** @var WP_Query $courses */
$courses = learndash_get_courses_count( array(), '' );
$course_array = [];
foreach ( $courses->posts as $course_id ) {
$course_array[ $course_id ] = get_the_title( $course_id );
}
return $course_array;
}
/**
* 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_course = (_.has(data.actionSavedData, 'data') && _.has(data.actionSavedData.data, 'course')) ? data.actionSavedData.data.course : '';
#>
<div class="bwfan-<?php echo esc_html__( $this->get_slug() ); ?>">
<label for="" class="bwfan-label-title"><?php echo esc_html__( 'Course', 'wp-marketing-automations-pro' ); ?></label>
<select required id="" class="bwfan-input-wrapper" name="bwfan[{{data.action_id}}][data][course]">
<option value=""><?php echo esc_html__( 'Choose any Course', 'wp-marketing-automations-pro' ); ?></option>
<#
if(_.has(data.actionFieldsOptions, 'courses') && _.isObject(data.actionFieldsOptions.courses) ) {
_.each( data.actionFieldsOptions.courses, function( value, key ){
selected = (key == selected_course) ? 'selected' : '';
#>
<option value="{{key}}" {{selected}}>{{value}}</option>
<# })
}
#>
</select>
<div class="clearfix bwfan_field_desc bwfan-mb20">Select the course which you want to reset the progress from</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['user_id'] = $task_meta['global']['user_id'];
$data_to_set['course_id'] = $task_meta['data']['course'];
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 ) {
$data_to_set = array();
$data_to_set['user_id'] = isset( $step_data['user_id'] ) ? $step_data['user_id'] : 0;
$data_to_set['course_id'] = isset( $step_data['course'][0]['id'] ) ? $step_data['course'][0]['id'] : 0;
if ( empty( $data_to_set['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 ) : '';
$data_to_set['user_id'] = $user instanceof WP_User ? $user->ID : 0;
}
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' => 'Course Progress Reset Done'
);
}
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();
}
$course_id = absint( $this->data['course_id'] );
if ( empty( $course_id ) ) {
return array(
'status' => 4,
'message' => __( 'Course was not selected', 'wp-marketing-automations-pro' ),
);
}
$user_id = $this->data['user_id'];
$user = get_userdata( $user_id );
if ( false === $user ) {
return array(
'status' => 4,
'message' => __( 'User does not exists', 'wp-marketing-automations-pro' ),
);
}
learndash_delete_course_progress( $course_id, $user_id );
return true;
}
public function process_v2() {
$course_id = absint( $this->data['course_id'] );
if ( empty( $course_id ) ) {
return $this->skipped_response( __( 'Course was not selected', 'wp-marketing-automations-pro' ) );
}
$user_id = $this->data['user_id'];
$user = get_userdata( $user_id );
if ( false === $user ) {
return $this->skipped_response( __( 'User does not exists', 'wp-marketing-automations-pro' ) );
}
learndash_delete_course_progress( $course_id, $user_id );
return $this->success_message( __( 'Course reset successfully.', 'wp-marketing-automations-pro' ) );
}
public function get_fields_schema() {
return [
[
"id" => 'course',
"label" => __( 'Select Course', 'wp-marketing-automations-pro' ),
"type" => 'custom_search',
'autocompleterOption' => [
'path' => 'ld_courses',
'slug' => 'ld_courses',
'labelText' => 'plan'
],
"allowFreeTextSearch" => false,
"required" => true,
"errorMsg" => __( "Course 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['courses'] ) || empty( $data['courses'] ) ) {
return '';
}
$courses = [];
foreach ( $data['courses'] as $course ) {
if ( ! isset( $course['name'] ) || empty( $course['name'] ) ) {
continue;
}
$courses[] = $course['name'];
}
return $courses;
}
}
/**
* Register this action. Registering the action will make it eligible to see it on single automation screen in select actions dropdown.
*/
return 'BWFAN_LD_Reset_Course_Progress';

View File

@@ -0,0 +1,225 @@
<?php
final class BWFAN_LD_Reset_Quiz_Attempts extends BWFAN_Action {
private static $ins = null;
protected function __construct() {
$this->action_name = __( 'Reset Quiz Attempts', 'wp-marketing-automations-pro' );
$this->action_desc = __( 'This action resets a user quiz attempt count', 'wp-marketing-automations-pro' );
$this->required_fields = array( 'user_id', 'quiz_id' );
$this->action_priority = 35;
$this->support_v2 = true;
}
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
/**
* Localize data for html fields for the current action.
*/
public function admin_enqueue_assets() {
if ( BWFAN_Common::is_load_admin_assets( 'automation' ) ) {
$data = $this->get_view_data();
BWFAN_Core()->admin->set_actions_js_data( $this->get_class_slug(), 'quizzes', $data );
}
}
public function get_view_data() {
$quizzes = get_posts( array(
'post_type' => 'sfwd-quiz',
'posts_per_page' => - 1,
'status' => 'publish',
'suppress_filters' => false
) );
$quiz_array = array();
foreach ( $quizzes as $quiz ) {
$quiz_array[ $quiz->ID ] = $quiz->post_title;
}
return $quiz_array;
}
/**
* 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_quiz = (_.has(data.actionSavedData, 'data') && _.has(data.actionSavedData.data, 'quiz')) ? data.actionSavedData.data.quiz : '';
#>
<div class="bwfan-<?php echo esc_html__( $this->get_slug() ); ?>">
<label for="" class="bwfan-label-title"><?php echo esc_html__( 'Quiz', 'wp-marketing-automations-pro' ); ?></label>
<select required id="" class="bwfan-input-wrapper" name="bwfan[{{data.action_id}}][data][quiz]">
<option value=""><?php echo esc_html__( 'Choose any Quiz', 'wp-marketing-automations-pro' ); ?></option>
<#
if(_.has(data.actionFieldsOptions, 'quizzes') && _.isObject(data.actionFieldsOptions.quizzes) ) {
_.each( data.actionFieldsOptions.quizzes, function( value, key ){
selected = (key == selected_quiz) ? 'selected' : '';
#>
<option value="{{key}}" {{selected}}>{{value}}</option>
<# })
}
#>
</select>
<div class="clearfix bwfan_field_desc bwfan-mb20">Select the quiz for which you want to reset the attempts of</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['user_id'] = $task_meta['global']['user_id'];
$data_to_set['quiz_id'] = $task_meta['data']['quiz'];
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 ) {
$data_to_set = array();
$data_to_set['user_id'] = isset( $step_data['user_id'] ) ? $step_data['user_id'] : 0;
$data_to_set['quiz_id'] = isset( $step_data['quiz'][0]['id'] ) ? $step_data['quiz'][0]['id'] : 0;
if ( empty( $data_to_set['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 ) : '';
$data_to_set['user_id'] = $user instanceof WP_User ? $user->ID : 0;
}
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' => 'Quiz Attempts Reset Done'
);
}
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();
}
$quiz_id = absint( $this->data['quiz_id'] );
if ( empty( $quiz_id ) ) {
return array(
'status' => 4,
'message' => __( 'Quiz was not selected', 'wp-marketing-automations-pro' ),
);
}
$user_id = $this->data['user_id'];
$user = get_userdata( $user_id );
if ( false === $user ) {
return array(
'status' => 4,
'message' => __( 'User does not exists', 'wp-marketing-automations-pro' ),
);
}
learndash_remove_user_quiz_attempt( $user_id, array( 'quiz' => $quiz_id ) );
return true;
}
public function process_v2() {
$quiz_id = absint( $this->data['quiz_id'] );
if ( empty( $quiz_id ) ) {
return $this->skipped_response( __( 'Course was not selected', 'wp-marketing-automations-pro' ) );
}
$user_id = $this->data['user_id'];
$user = get_userdata( $user_id );
if ( false === $user ) {
return $this->skipped_response( __( 'User does not exists', 'wp-marketing-automations-pro' ) );
}
learndash_remove_user_quiz_attempt( $user_id, array( 'quiz' => $quiz_id ) );
return $this->success_message( __( 'Quiz attempt reset successfully.', 'wp-marketing-automations-pro' ) );
}
public function get_fields_schema() {
return [
[
"id" => 'quiz',
"label" => __( 'Quiz', 'wp-marketing-automations-pro' ),
"type" => 'custom_search',
'autocompleterOption' => [
'path' => 'ld_quiz',
'slug' => 'ld_quiz',
'labelText' => 'quiz'
],
"allowFreeTextSearch" => false,
"required" => true,
"errorMsg" => __( "Quiz is required", 'wp-marketing-automations-pro' ),
"multiple" => false,
"description" => __( "Select the quiz for which you want to reset the attempts of", 'wp-marketing-automations-pro' )
],
];
}
public function get_desc_text( $data ) {
$data = json_decode( wp_json_encode( $data ), true );
if ( ! isset( $data['quiz'] ) || empty( $data['quiz'] ) ) {
return '';
}
$quizzes = [];
foreach ( $data['quiz'] as $quiz ) {
if ( ! isset( $quiz['name'] ) || empty( $quiz['name'] ) ) {
continue;
}
$quizzes[] = $quiz['name'];
}
return $quizzes;
}
}
/**
* Register this action. Registering the action will make it eligible to see it on single automation screen in select actions dropdown.
*/
return 'BWFAN_LD_Reset_Quiz_Attempts';

View File

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