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,70 @@
<?php
class BWFCRM_Api_Create_Audience extends BWFCRM_API_Base {
public static $ins;
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::CREATABLE;
$this->route = '/audience';
$this->response_code = 200;
}
public function default_args_values() {
$args = array(
'name' => '',
'data' => [],
);
return $args;
}
public function process_api_call() {
$name = $this->get_sanitized_arg( 'name', 'text_field', $this->args['name'] );
if ( empty( $name ) ) {
$this->response_code = 400;
$response = __( 'Name is mandatory', 'wp-marketing-automations-pro' );
return $this->error_response( $response );
}
if ( empty( $this->args['data'] ) || ( is_array( $this->args['data'] ) && empty( $this->args['data']['filters'] ) ) ) {
$this->response_code = 400;
$response = __( 'Filters are mandatory.', 'wp-marketing-automations-pro' );
return $this->error_response( $response );
}
$audience = new BWFCRM_Audience();
$already_exists = $audience->check_audience_is_exists( $name );
if ( absint( $already_exists ) > 0 ) {
$name = "$name - $already_exists";
}
$create_time = current_time( 'mysql', 1 );
$audience->set_audience( 0, $name, $this->args['data'], $create_time, $create_time );
$audience->save();
if ( empty( $audience->get_id() ) ) {
$this->response_code = 500;
return $this->error_response( '', $audience );
}
$audience_data = $audience->get_array();
return $this->success_response( $audience_data, __( 'Audience created', 'wp-marketing-automations-pro' ) );
}
}
BWFCRM_API_Loader::register( 'BWFCRM_Api_Create_Audience' );

View File

@@ -0,0 +1,65 @@
<?php
class BWFCRM_Api_Delete_Audience extends BWFCRM_API_Base {
public static $ins;
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::DELETABLE;
$this->route = '/audience/(?P<audience_id>[\\d]+)';
}
public function default_args_values() {
return array( 'audience_id' => '' );
}
public function process_api_call() {
$audience_id = $this->get_sanitized_arg( 'audience_id', 'key' );
if ( empty( $audience_id ) ) {
$this->response_code = 404;
$response = __( 'Audience ID is mandatory', 'wp-marketing-automations-pro' );
return $this->error_response( $response );
}
/** if the provided id is tag id or not $data */
$audience = new BWFCRM_Audience( $audience_id );
$audience->is_audience_exists();
if ( ! $audience->is_audience_exists() ) {
$this->response_code = 404;
$response = __( "Audience not exist with given ID #" . $audience_id, 'wp-marketing-automations-pro' );
return $this->error_response( $response );
}
$delete_audince = BWFAN_Model_Terms::delete_term( $audience_id );
if ( false === $delete_audince ) {
$this->response_code = 404;
$response = __( 'Unable to delete the Audience', 'wp-marketing-automations-pro' );
return $this->error_response( $response );
}
$this->response_code = 200;
$success_message = __( 'Audience deleted', 'wp-marketing-automations-pro' );
return $this->success_response( [], $success_message );
}
}
BWFCRM_API_Loader::register( 'BWFCRM_Api_Delete_Audience' );

View File

@@ -0,0 +1,62 @@
<?php
class BWFCRM_Api_Get_Audience_By_ID extends BWFCRM_API_Base {
public static $ins;
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::READABLE;
$this->route = '/audience/(?P<audience_id>[\\d]+)';
}
public function default_args_values() {
return array( 'audience_id' => '' );
}
public function process_api_call() {
$audience_id = $this->get_sanitized_arg( 'audience_id', 'key' );
if ( empty( $audience_id ) ) {
$this->response_code = 404;
$response = __( 'Audience ID is mandatory ', 'wp-marketing-automations-pro' );
return $this->error_response( $response );
}
$audience = new BWFCRM_Audience( absint( $audience_id ) );
if ( ! $audience->is_audience_exists() ) {
$this->response_code = 404;
$response = __( "Audience not exist with given ID #" . $audience_id, 'wp-marketing-automations-pro' );
return $this->error_response( $response );
}
$audience_data = $audience->get_array();
if ( empty( $audience_data ) ) {
$this->response_code = 404;
$response = __( 'No audience data found related with audience id:' . $audience_id, 'wp-marketing-automations-pro' );
return $this->error_response( $response );
}
$audience_data['data'] = json_decode( $audience_data['data'] );
$this->response_code = 200;
$success_message = __( 'Audience data found with audience id:' . $audience_id, 'wp-marketing-automations-pro' );
return $this->success_response( $audience_data, $success_message );
}
}
BWFCRM_API_Loader::register( 'BWFCRM_Api_Get_Audience_By_ID' );

View File

@@ -0,0 +1,85 @@
<?php
class BWFCRM_Api_Get_Audience_Contacts_Count extends BWFCRM_API_Base {
public static $ins;
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::READABLE;
$this->route = '/audiences/contacts';
}
public function default_args_values() {
$args = [
'audience_ids' => []
];
return $args;
}
public function process_api_call() {
$audience_ids = $this->get_sanitized_arg( '', 'text_field', $this->args['audience_ids'] );
$data = [];
if ( $audience_ids ) {
foreach ( $audience_ids as $audience_id ) {
$audience = new BWFCRM_Audience( $audience_id );
if ( empty( $audience ) ) {
continue;
}
$audience_data = $audience->get_data();
$audience_data = json_decode( $audience_data, true );
$filters = $audience_data['filters'];
$contacts_count = $this->get_contacts_count( $filters );
$subscribers_count = $this->get_contacts_count( $filters, true );
if ( ! isset( $data[ $audience_id ] ) ) {
$data[ $audience_id ] = [];
}
$data[ $audience_id ]['contact_count'] = is_array( $contacts_count ) && isset( $contacts_count['total_count'] ) ? absint( $contacts_count['total_count'] ) : 0;
$data[ $audience_id ]['subscribers_count'] = is_array( $subscribers_count ) && isset( $subscribers_count['total_count'] ) ? absint( $subscribers_count['total_count'] ) : 0;
}
}
$this->response_code = 200;
return $this->success_response( $data );
}
public function get_contacts_count( $filters, $exclude_unsubscribers = false ) {
$unsubscribed_status = [ 0, 2, 3, 4, 5 ];
/**
* if unverified(0), bounced(2), unsubscribed(3), soft bounced(4) and complaint(5) status available in filter then
* no need to get subscribers count
*/
if ( $exclude_unsubscribers && isset( $filters['status_is'] ) && in_array( absint( $filters['status_is'] ), $unsubscribed_status, true ) ) {
return false;
}
$additional_info = [
'grab_totals' => true,
'only_count' => true,
'customer_data' => false,
];
if ( $exclude_unsubscribers ) {
$filters['status_is'] = 1;
}
return BWFCRM_Contact::get_contacts( '', 0, 5, $filters, $additional_info );
}
}
BWFCRM_API_Loader::register( 'BWFCRM_Api_Get_Audience_Contacts_Count' );

View File

@@ -0,0 +1,73 @@
<?php
class BWFCRM_Api_Get_Audiences extends BWFCRM_API_Base {
public static $ins;
public $audiences = array();
public $total_count = 0;
public $count_data = [];
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::READABLE;
$this->route = '/audiences';
$this->request_args = array(
'search' => array(
'description' => __( 'Search from name', 'wp-marketing-automations-pro' ),
'type' => 'string',
),
'ids' => array(
'description' => __( 'Search from audience ids', 'wp-marketing-automations-pro' ),
'type' => 'string'
),
);
}
public function default_args_values() {
return array( 'ids' => '', 'search' => '' );
}
public function process_api_call() {
/** if isset search param then get the tag by name **/
$search = $this->get_sanitized_arg( 'search', 'text_field' );
$audience_ids = empty( $this->args['ids'] ) ? array() : explode( ',', $this->args['ids'] );
$limit = $this->get_sanitized_arg( 'limit', 'text_field' );
$offset = $this->get_sanitized_arg( 'offset', 'text_field' );
$audiences = BWFAN_Model_Terms::get_terms( 3, $offset, $limit, $search, $audience_ids );
if ( ! is_array( $audiences ) ) {
$audiences = array();
}
$audiences = array_map( function ( $audience ) {
$audience['data'] = json_decode( $audience['data'] );
return $audience;
}, $audiences );
$count = BWFAN_Model_Terms::get_terms_count( 3, $search, $audience_ids );
$this->total_count = $count;
$this->count_data = BWFAN_PRO_Common::get_contact_data_counts();
$this->response_code = 200;
return $this->success_response( $audiences );
}
public function get_result_total_count() {
return $this->total_count;
}
public function get_result_count_data() {
return $this->count_data;
}
}
BWFCRM_API_Loader::register( 'BWFCRM_Api_Get_Audiences' );

View File

@@ -0,0 +1,78 @@
<?php
class BWFCRM_Api_Update_Audience extends BWFCRM_API_Base {
public static $ins;
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::EDITABLE;
$this->route = '/audience/(?P<audience_id>[\\d]+)';
}
public function default_args_values() {
$args = array(
'audience_id' => '',
'name' => '',
'data' => ''
);
return $args;
}
public function process_api_call() {
$audience_id = $this->get_sanitized_arg( 'audience_id', 'text_field' );
if ( empty( $audience_id ) ) {
$this->response_code = 404;
$response = __( "Audience Id is mandatory", 'wp-marketing-automations-pro' );
return $this->error_response( $response );
}
$name = $this->get_sanitized_arg( 'name', 'text_field' );
if ( empty( $name ) ) {
$this->response_code = 404;
$response = __( "Audience name is Mandatory", 'wp-marketing-automations-pro' );
return $this->error_response( $response );
}
/** if the provided id is audience id or not $data */
$audience = new BWFCRM_Audience( absint( $audience_id ) );
if ( ! $audience->is_audience_exists() ) {
$this->response_code = 404;
$response = __( "Audience not exist with given ID #" . $audience_id, 'wp-marketing-automations-pro' );
return $this->error_response( $response );
}
$updated_time = current_time( 'mysql', 1 );
$audience->set_audience( $audience_id, $name, $this->args['data'], '', $updated_time );
$saved = $audience->save();
if ( 0 === $saved ) {
$response = __( 'Unable to update audience with id ' . $audience_id, 'wp-marketing-automations-pro' );
$this->response_code = 400;
return $this->error_response( $response );
}
$response = __( 'Audience updated', 'wp-marketing-automations-pro' );
return $this->success_response( [], $response );
}
}
BWFCRM_API_Loader::register( 'BWFCRM_Api_Update_Audience' );

View File

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