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,350 @@
<?php
#[AllowDynamicProperties]
final class BWFAN_WCM_Membership_Created extends BWFAN_Event {
private static $instance = null;
/** @var WC_Memberships_Membership_Plan $membership_plan */
public $membership_plan = null;
/** @var WC_Memberships_User_Membership $user_membership */
public $user_membership = null;
public $admin_membership = null;
public function __construct() {
$this->event_name = esc_html__( 'Membership Created', 'wp-marketing-automations-pro' );
$this->event_desc = esc_html__( 'This event runs after a WooCommerce membership is created.', 'wp-marketing-automations-pro' );
$this->optgroup_label = esc_html__( 'Membership', 'wp-marketing-automations-pro' );
$this->support_lang = true;
$this->priority = 25;
$this->event_merge_tag_groups = [ 'wc_membership', 'bwf_contact' ];
$this->event_rule_groups = array(
'wc_member',
'bwf_contact_segments',
'bwf_contact',
'bwf_contact_fields',
'bwf_contact_user',
'bwf_contact_wc',
'bwf_contact_geo',
'bwf_engagement',
'bwf_broadcast'
);
$this->v2 = true;
}
public static function get_instance() {
if ( null === self::$instance ) {
self::$instance = new self();
}
return self::$instance;
}
public function load_hooks() {
/** allow */
add_action( 'wc_memberships_user_membership_created', [ $this, 'membership_created_triggered' ], 20, 2 );
add_filter( 'bwfan_before_making_logs', array( $this, 'check_if_bulk_process_executing' ), 10, 1 );
/** for checking if the membership created via admin */
if ( is_admin() ) {
add_action( 'transition_post_status', [ $this, 'transition_post_status' ], 50, 3 );
}
}
/** for handling membership created from the admin screen
*
* @param $new_status
* @param $old_status
* @param \WP_Post $post
*/
function transition_post_status( $new_status, $old_status, $post ) {
if ( $old_status === 'auto-draft' && $post->post_type === 'wc_user_membership' ) {
// don't trigger now as post transition happens before data is saved
$this->admin_membership = $post->ID;
add_action( 'wc_memberships_user_membership_saved', [ $this, 'membership_created_via_admin' ], 100, 2 );
}
}
/**
* @param \WC_Memberships_Membership_Plan $plan
* @param $args
*/
function membership_created_via_admin( $membership_plan, $user_membership_data ) {
// check the created membership is a match
if ( $this->admin_membership == $user_membership_data['user_membership_id'] ) {
$this->membership_created_triggered( $membership_plan, $user_membership_data );
}
}
public function membership_created_triggered( $membership_plan, $user_membership_data ) {
/** checked if user id available */
if ( empty( $user_membership_data['user_id'] ) ) {
return;
}
/** check if membership plan available */
if ( ! $membership_plan instanceof WC_Memberships_Membership_Plan ) {
return;
}
$membership_plan_id = $membership_plan->get_id();
/** if the membership update then return */
if ( false === $user_membership_data['is_update'] || ! empty( $this->admin_membership ) ) {
$user_membership_id = $user_membership_data['user_membership_id'];
$this->process( $membership_plan_id, $user_membership_id );
$this->admin_membership = null;
}
}
/**
* Make the required data for the current event and send it asynchronously.
*
* @param $membership_plan_id
* @param $user_membership_id
*/
public function process( $membership_plan_id, $user_membership_id ) {
$data = $this->get_default_data();
$data['membership_plan_id'] = $membership_plan_id;
$data['user_membership_id'] = $user_membership_id;
$this->send_async_call( $data );
}
public function pre_executable_actions( $automation_data ) {
if ( $this->user_membership instanceof WC_Memberships_User_Membership ) {
BWFAN_Core()->rules->setRulesData( $this->user_membership->get_id(), 'wc_user_membership_id' );
BWFAN_Core()->rules->setRulesData( $this->user_membership->get_user()->get( 'user_email' ), 'email' );
BWFAN_Core()->rules->setRulesData( $this->user_membership->get_user_id(), 'user_id' );
}
if ( $this->membership_plan instanceof WC_Memberships_Membership_Plan ) {
BWFAN_Core()->rules->setRulesData( $this->membership_plan->get_id(), 'wc_membership_plan_id' );
}
}
/**
* Capture the async data for thes if the task has to be executed or not.
*
* @return array|bool
*/
public function capture_async_data() {
if ( ! function_exists( 'wc_memberships_get_membership_plan' ) || ! function_exists( 'wc_memberships_get_user_membership' ) ) {
return false;
}
$membership_plan_id = BWFAN_Common::$events_async_data['membership_plan_id'];
$user_membership_id = BWFAN_Common::$events_async_data['user_membership_id'];
$membership_plan = wc_memberships_get_membership_plan( $membership_plan_id );
$user_membership = wc_memberships_get_user_membership( $user_membership_id );
$this->membership_plan = $membership_plan;
$this->user_membership = $user_membership;
$this->run_automations();
}
public function get_email_event() {
if ( $this->user_membership instanceof WC_Memberships_User_Membership ) {
$user = $this->user_membership->get_user();
return ! empty( $user ) ? $user->user_email : false;
}
return false;
}
public function get_user_id_event() {
return $this->user_membership instanceof WC_Memberships_User_Membership ? $this->user_membership->get_user_id() : false;
}
/**
* Recalculate action's execution time with respect to order date.
* eg.
* today is 22 jan.
* order was placed on 17 jan.
* user set an email to send after 10 days of order placing.
* user setup the sync process.
* email should be sent on 27 Jan as the order date was 17 jan.
*
* @param $actions
*
* @return mixed
* @throws Exception
*/
public function recalculate_actions_time( $actions ) {
$membership_date = $this->user_membership->get_start_date();
$membership_date = DateTime::createFromFormat( 'Y-m-d H:i:s', $membership_date );
$actions = $this->calculate_actions_time( $actions, $membership_date );
return $actions;
}
/**
* 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']['wc_user_membership_id'] = is_object( $this->user_membership ) ? $this->user_membership->get_id() : '';
$data_to_send['global']['wc_membership_plan_id'] = is_object( $this->membership_plan ) ? $this->membership_plan->get_id() : '';
$data_to_send['global']['email'] = is_object( $this->user_membership ) ? $this->user_membership->get_user()->get( 'user_email' ) : '';
$data_to_send['global']['user_id'] = is_object( $this->user_membership ) ? $this->user_membership->get_user_id() : '';
return $data_to_send;
}
/**
* Set global data for all the merge tags which are supported by this event.
*
* @param $task_meta
*/
public function set_merge_tags_data( $task_meta ) {
$get_data = BWFAN_Merge_Tag_Loader::get_data( 'wc_user_membership_id' );
if ( ( empty( $get_data ) || intval( $get_data ) !== intval( $task_meta['global']['wc_user_membership_id'] ) ) && function_exists( 'wc_memberships_get_user_membership' ) ) {
$set_data = array(
'wc_user_membership_id' => $task_meta['global']['wc_user_membership_id'],
'wc_membership_plan_id' => $task_meta['global']['wc_membership_plan_id'],
'email' => $task_meta['global']['email'],
'user_id' => $task_meta['global']['user_id'],
);
BWFAN_Merge_Tag_Loader::set_data( $set_data );
}
}
/**
* 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__( 'Membership ID:', 'wp-marketing-automations-pro' ); ?> </strong>
<a target="_blank" href="<?php echo get_edit_post_link( $global_data['wc_user_membership_id'] ); //phpcs:ignore WordPress.Security.EscapeOutput ?>"><?php echo esc_html__( '#' . $global_data['wc_user_membership_id'] ); ?></a>
</li>
<li>
<strong><?php echo esc_html__( 'Selected Membership Plan ID:', 'wp-marketing-automations-pro' ); ?> </strong>
<a target="_blank" href="<?php echo get_edit_post_link( $global_data['wc_membership_plan_id'] ); //phpcs:ignore WordPress.Security.EscapeOutput ?>"><?php echo esc_html__( '#' . $global_data['wc_membership_plan_id'] ); ?></a>
</li>
<li>
<strong><?php echo esc_html__( 'Membership User Email:', 'wp-marketing-automations-pro' ); ?> </strong>
<?php echo esc_html__( $global_data['email'] ); ?>
</li>
<?php
return ob_get_clean();
}
public function validate_v2_event_settings( $automation_data ) {
$current_automation_event_meta = $automation_data['event_meta'];
$current_membership_contains = isset( $current_automation_event_meta['membership-contains'] ) ? $current_automation_event_meta['membership-contains'] : 'any';
if ( 'any' === $current_membership_contains ) {
return true;
}
/** Specific membership case */
$selected_memberships = is_array( $automation_data['event_meta']['memberships'] ) ? array_map( 'intval', array_column( $automation_data['event_meta']['memberships'], 'id' ) ) : [];
return ! empty( $selected_memberships ) && in_array( intval( $automation_data['membership_plan_id'] ), $selected_memberships, true );
}
/**
* Capture the async data for the current event.
*
* @return array|bool
*/
public function capture_v2_data( $automation_data ) {
if ( ! function_exists( 'wc_memberships_get_membership_plan' ) || ! function_exists( 'wc_memberships_get_user_membership' ) ) {
return false;
}
$this->membership_plan_id = BWFAN_Common::$events_async_data['membership_plan_id'];
$this->user_membership_id = BWFAN_Common::$events_async_data['user_membership_id'];
$this->membership_plan = wc_memberships_get_membership_plan( $this->membership_plan_id );
$this->user_membership = wc_memberships_get_user_membership( $this->user_membership_id );
$automation_data['membership_plan'] = $this->membership_plan;
$automation_data['user_membership'] = $this->user_membership;
$automation_data['wc_user_membership_id'] = $this->user_membership_id;
return $automation_data;
}
public function get_fields_schema() {
return [
[
'id' => 'membership-contains',
'label' => __( 'Membership Contains', 'wp-marketing-automations-pro' ),
'type' => 'radio',
'options' => [
[
'label' => __( 'Any Membership', 'wp-marketing-automations-pro' ),
'value' => 'any'
],
[
'label' => __( 'Specific Memberships', 'wp-marketing-automations-pro' ),
'value' => 'selected_membership'
]
],
"class" => 'bwfan-input-wrapper',
"tip" => "",
"required" => true,
"description" => ""
],
[
'id' => 'memberships',
'label' => __( 'Select Memberships', 'wp-marketing-automations-pro' ),
'type' => 'custom_search',
'autocompleterOption' => [
'path' => 'wcm_plans',
'slug' => 'wcm_plans',
'labelText' => 'wcm_plans'
],
'class' => '',
'placeholder' => '',
'required' => true,
'toggler' => [
'fields' => [
[
'id' => 'membership-contains',
'value' => 'selected_membership',
]
]
],
],
];
}
/** set default values */
public function get_default_values() {
return [
'membership-contains' => 'any',
];
}
}
/**
* Register this event to a source.
* This will show the current event in dropdown in single automation screen.
*/
if ( bwfan_is_woocommerce_active() && bwfan_is_woocommerce_membership_active() ) {
return 'BWFAN_WCM_Membership_Created';
}

View File

@@ -0,0 +1,368 @@
<?php
#[AllowDynamicProperties]
final class BWFAN_WCM_Status_Changed extends BWFAN_Event {
private static $instance = null;
/** @var WC_Memberships_User_Membership $user_membership */
public $user_membership = null;
/** @var string $user_membership */
public $to_status = null;
public $from_status = null;
public $plan_id = null;
public function __construct() {
$this->event_name = esc_html__( 'Membership Status Changed', 'wp-marketing-automations-pro' );
$this->event_desc = esc_html__( 'This event runs after a WooCommerce membership status is changed.', 'wp-marketing-automations-pro' );
$this->optgroup_label = esc_html__( 'Membership', 'wp-marketing-automations-pro' );
$this->priority = 25;
$this->event_merge_tag_groups = [ 'wc_membership', 'bwf_contact' ];
$this->event_rule_groups = array(
'wc_member',
'bwf_contact_segments',
'bwf_contact',
'bwf_contact_fields',
'bwf_contact_user',
'bwf_contact_wc',
'bwf_contact_geo',
'bwf_engagement',
'bwf_broadcast'
);
$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( 'wc_memberships_user_membership_status_changed', [ $this, 'membership_status_changed_triggered' ], 20, 3 );
}
public function get_view_data() {
$statuses = wc_memberships_get_user_membership_statuses( false, false );
$statuses_to_return = array_map( function ( $status ) {
return [ $status => wc_memberships_get_user_membership_status_name( $status ) ];
}, $statuses );
return array_merge( ...$statuses_to_return );
}
/**
* Membership status changed triggered
*
* @param WC_Memberships_User_Membership $user_membership
* @param string $new_status
* @param string $old_status
*/
public function membership_status_changed_triggered( $user_membership, $old_status, $new_status ) {
if ( ! $user_membership instanceof WC_Memberships_User_Membership ) {
return;
}
$plan_id = $user_membership->plan_id;
$membership_id = $user_membership->get_id();
$to = $new_status;
$from_status = $old_status;
$this->process( $plan_id, $membership_id, $to, $from_status );
}
/**
* Make the required data for the current event and send it asynchronously.
*
* @param $plan_id
* @param int $membership_id
* @param $to_status
* @param $from_status
*/
public function process( $plan_id, $membership_id, $to_status, $from_status ) {
$data = $this->get_default_data();
$data['plan_id'] = $plan_id;
$data['user_membership_id'] = $membership_id;
$data['to_status'] = $to_status;
$data['from_status'] = $from_status;
$this->send_async_call( $data );
}
/**
* Capture the async data for these if the task has to be executed or not.
*
* @return array|bool
*/
public function capture_async_data() {
if ( ! function_exists( 'wc_memberships_get_user_membership' ) ) {
return false;
}
$plan_id = BWFAN_Common::$events_async_data['plan_id'];
$membership_id = BWFAN_Common::$events_async_data['user_membership_id'];
$to_status = BWFAN_Common::$events_async_data['to_status'];
$from_status = BWFAN_Common::$events_async_data['from_status'];
$user_membership = wc_memberships_get_user_membership( $membership_id );
$this->plan_id = $plan_id;
$this->user_membership = $user_membership;
$this->to_status = $to_status;
$this->from_status = $from_status;
return $this->run_automations();
}
public function get_email_event() {
if ( $this->user_membership instanceof WC_Memberships_User_Membership ) {
$user = $this->user_membership->get_user();
return ! empty( $user ) ? $user->user_email : false;
}
return false;
}
public function get_user_id_event() {
return $this->user_membership instanceof WC_Memberships_User_Membership ? $this->user_membership->get_user_id() : 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']['wc_user_membership_id'] = $this->user_membership instanceof WC_Memberships_User_Membership ? $this->user_membership->get_id() : '';
$data_to_send['global']['email'] = $this->user_membership instanceof WC_Memberships_User_Membership ? $this->user_membership->get_user()->get( 'user_email' ) : '';
$data_to_send['global']['user_id'] = $this->user_membership instanceof WC_Memberships_User_Membership ? $this->user_membership->get_user_id() : '';
$data_to_send['global']['wc_user_membership_status'] = ! empty( $this->status ) ? $this->status : '';
return $data_to_send;
}
public function pre_executable_actions( $automation_data ) {
if ( function_exists( 'wc_memberships_get_user_membership' ) && $this->user_membership instanceof WC_Memberships_User_Membership ) {
BWFAN_Core()->rules->setRulesData( $this->user_membership->get_id(), 'wc_user_membership_id' );
BWFAN_Core()->rules->setRulesData( $this->user_membership->get_user()->get( 'user_email' ), 'email' );
BWFAN_Core()->rules->setRulesData( $this->user_membership->get_user_id(), 'user_id' );
}
if ( ! empty( $this->status ) ) {
BWFAN_Core()->rules->setRulesData( $this->status, 'wc_user_membership_status' );
}
}
/**
* 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( 'wc_user_membership_id' );
if ( ( empty( $get_data ) || intval( $get_data ) !== intval( $task_meta['global']['wc_user_membership_id'] ) ) && function_exists( 'wc_memberships_get_user_membership' ) ) {
$set_data = array(
'wc_user_membership_id' => $task_meta['global']['wc_user_membership_id'],
'email' => $task_meta['global']['email'],
'user_id' => $task_meta['global']['user_id'],
'wc_user_membership_status' => $task_meta['global']['wc_user_membership_status'],
);
BWFAN_Merge_Tag_Loader::set_data( $set_data );
}
}
/**
* 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__( 'Membership ID:', 'wp-marketing-automations-pro' ); ?> </strong>
<a target="_blank"
href="<?php echo get_edit_post_link( $global_data['wc_user_membership_id'] ); //phpcs:ignore WordPress.Security.EscapeOutput
?>"><?php echo esc_html__( '#' . $global_data['wc_user_membership_id'] ); ?></a>
</li>
<li>
<strong><?php echo esc_html__( 'New Status:', 'wp-marketing-automations-pro' ); ?> </strong>
<?php echo esc_html__( $global_data['wc_user_membership_status'] ); ?>
</li>
<li>
<strong><?php echo esc_html__( 'Membership User Email:', 'wp-marketing-automations-pro' ); ?> </strong>
<?php echo esc_html__( $global_data['email'] ); ?>
</li>
<?php
return ob_get_clean();
}
/**
* validate v2 event settings
* @return bool
*/
public function validate_v2_event_settings( $automation_data ) {
$current_automation_event_meta = $automation_data['event_meta'];
$current_status_to = isset( $current_automation_event_meta['to'] ) ? $current_automation_event_meta['to'] : 'any';
$current_status_from = isset( $current_automation_event_meta['from'] ) ? $current_automation_event_meta['from'] : 'any';
$current_membership_contains = isset( $current_automation_event_meta['membership-contains'] ) ? $current_automation_event_meta['membership-contains'] : 'any';
/** from any to any status any membership */
if ( ( 'any' === $current_status_from && 'any' === $current_status_to ) && ( empty( $current_membership_contains ) || 'any' === $current_membership_contains ) ) {
return true;
}
/** Specific membership case */
if ( 'selected_membership' === $current_membership_contains ) {
$get_selected_memberships = $automation_data['event_meta']['memberships'];
$memberships_selected = array_column( $get_selected_memberships, 'id' );
if ( empty( $memberships_selected ) || ! in_array( $automation_data['plan_id'], $memberships_selected, true ) ) {
return false;
}
}
/** if from status is any */
if ( 'any' === $current_status_from ) {
return ( 'any' === $current_status_to || ( $automation_data['to_status'] === $current_status_to ) );
}
/** if to status is any */
if ( 'any' === $current_status_to ) {
return ( $automation_data['from_status'] === $current_status_from );
}
/** selected from status to selected to status */
return ( ( $automation_data['from_status'] === $current_status_from ) && ( $automation_data['to_status'] === $current_status_to ) );
}
/**
* Capture the async data for the current event.
*
* @return array|bool
*/
public function capture_v2_data( $automation_data ) {
if ( ! function_exists( 'wc_memberships_get_user_membership' ) ) {
return false;
}
$this->user_membership_id = BWFAN_Common::$events_async_data['user_membership_id'];
$to_status = BWFAN_Common::$events_async_data['to_status'];
$from_status = BWFAN_Common::$events_async_data['from_status'];
$user_membership = wc_memberships_get_user_membership( $this->user_membership_id );
$this->user_membership = $user_membership;
$this->to_status = $to_status;
$this->from_status = $from_status;
$automation_data['user_membership'] = $this->user_membership;
$automation_data['to_status'] = $this->to_status;
$automation_data['from_status'] = $this->from_status;
$automation_data['wc_user_membership_id'] = $this->user_membership_id;
return $automation_data;
}
public function get_fields_schema() {
$default = [
'any' => 'Any'
];
$status = array_replace( $default, $this->get_view_data() );
$status = BWFAN_Common::prepared_field_options( $status );
return [
[
'id' => 'from',
'type' => 'wp_select',
'options' => $status,
'placeholder' => __( 'Select Status', 'wp-marketing-automations-pro' ),
'label' => __( 'From Status', 'wp-marketing-automations-pro' ),
"class" => 'bwfan-input-wrapper bwf-3-col-item',
"required" => false,
"description" => ""
],
[
'id' => 'to',
'type' => 'wp_select',
'options' => $status,
'label' => __( 'To Status', 'wp-marketing-automations-pro' ),
'placeholder' => __( 'Select Status', 'wp-marketing-automations-pro' ),
"class" => 'bwfan-input-wrapper bwf-3-col-item',
"required" => false,
"description" => ""
],
[
'id' => 'membership-contains',
'label' => __( 'Memberships Contains', 'wp-marketing-automations-pro' ),
'type' => 'radio',
'options' => [
[
'label' => __( 'Specific Memberships', 'wp-marketing-automations-pro' ),
'value' => 'selected_membership'
],
[
'label' => __( 'Any Memberships', 'wp-marketing-automations-pro' ),
'value' => 'any'
],
],
"class" => 'bwfan-input-wrapper',
"tip" => "",
"required" => false,
"description" => ""
],
[
'id' => 'memberships',
'label' => __( 'Select Memberships', 'wp-marketing-automations-pro' ),
'type' => 'custom_search',
'autocompleterOption' => [
'path' => 'wcm_plans',
'slug' => 'wcm_plans',
'labelText' => 'wcm_plans'
],
'class' => '',
'placeholder' => '',
'required' => true,
'toggler' => [
'fields' => [
[
'id' => 'membership-contains',
'value' => 'selected_membership',
]
]
],
],
];
}
/** set default values */
public function get_default_values() {
return [
'from' => 'any',
'to' => 'any',
'membership-contains' => 'selected_membership',
];
}
}
/**
* Register this event to a source.
* This will show the current event in dropdown in single automation screen.
*/
if ( bwfan_is_woocommerce_active() && bwfan_is_woocommerce_membership_active() ) {
return 'BWFAN_WCM_Status_Changed';
}

View File

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