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,473 @@
<?php
/**
* Discount Codes List Table
*
* @package restrict-content-pro
* @copyright Copyright (c) 2019, Restrict Content Pro
* @license GPL2+
* @since 3.1
*/
namespace RCP\Admin;
use \RCP_Discount;
/**
* Class Discount_Codes_Table
*
* @since 3.1
* @package RCP\Admin
*/
class Discount_Codes_Table extends List_Table {
/**
* Constructor.
*
* @since 3.1
* @see WP_List_Table::__construct()
*/
public function __construct() {
parent::__construct( [
'singular' => 'Discount Code',
'plural' => 'Discount Codes',
'ajax' => false,
] );
$this->process_bulk_action();
$this->get_counts();
}
/**
* Get the base URL for the discount codes list table.
*
* @since 3.1
* @return string Base URL.
*/
public function get_base_url() {
$args = array(
'page' => 'rcp-discounts'
);
$discounts_page = add_query_arg( $args, admin_url( 'admin.php' ) );
return $discounts_page;
}
/**
* Retrieve the table columns.
*
* @since 3.1
* @return array
*/
public function get_columns() {
$columns = array(
'cb' => '<input type="checkbox" />',
'name' => __( 'Name', 'rcp' ),
'description' => __( 'Description', 'rcp' ),
'code' => __( 'Code', 'rcp' ),
'membership_levels' => __( 'Membership Level(s)', 'rcp' ),
'amount' => __( 'Amount', 'rcp' ),
'type' => __( 'Type', 'rcp' ),
'status' => __( 'Status', 'rcp' ),
'use_count' => __( 'Uses', 'rcp' ),
'uses_left' => __( 'Uses Left', 'rcp' ),
'expiration' => __( 'Expiration', 'rcp' ),
'one_time' => __( 'One Time', 'rcp' )
);
/*
* Backwards compatibility: add an "extra" column if someone is hooking into the old action to add
* their own column. Everything gets bundled into one column because this is the only way we can realistically
* do it.
*/
if ( has_action( 'rcp_discounts_page_table_header' ) ) {
$columns['custom'] = __( 'Extra', 'rcp' );
}
/**
* Filters the table columns.
*
* @param array $columns
*
* @since 3.1
*/
$columns = apply_filters( 'rcp_discount_codes_list_table_columns', $columns );
return $columns;
}
/**
* Retrieve the sortable columns.
*
* @since 3.1
* @return array
*/
public function get_sortable_columns() {
return array(
'name' => array( 'name', false ),
'code' => array( 'code', false ),
'use_count' => array( 'use_count', false ),
'expiration' => array( 'expiration', false )
);
}
/**
* Gets the name of the primary column.
*
* @since 3.1
* @return string
*/
protected function get_primary_column_name() {
return 'name';
}
/**
* This function renders any other columns in the list table.
*
* @param RCP_Discount $discount Discount code object object.
* @param string $column_name The name of the column
*
* @since 3.1
* @return string Column Name
*/
public function column_default( $discount, $column_name ) {
$value = '';
switch ( $column_name ) {
case 'description' :
$value = $discount->get_description();
break;
case 'code' :
$value = esc_html( $discount->get_code() );
break;
case 'membership_levels' :
$membership_levels = $discount->get_membership_level_ids();
if ( is_array( $membership_levels ) && count( $membership_levels ) > 1 ) {
$value = __( 'Multiple Levels', 'rcp' );
} elseif ( is_array( $membership_levels ) && 1 === count( $membership_levels ) ) {
$value = rcp_get_subscription_name( $membership_levels[0] );
} else {
$value = __( 'All Levels', 'rcp' );
}
break;
case 'amount' :
$value = rcp_discount_sign_filter( $discount->get_amount(), $discount->get_unit() );
break;
case 'type' :
$value = '%' == $discount->get_unit() ? __( 'Percentage', 'rcp' ) : __( 'Flat', 'rcp' );
break;
case 'status' :
if ( rcp_is_discount_not_expired( $discount->get_id() ) ) {
$value = 'active' === $discount->get_status() ? __( 'active', 'rcp' ) : __( 'disabled', 'rcp' );
} else {
$value = __( 'expired', 'rcp' );
}
break;
case 'use_count' :
if ( $discount->get_max_uses() > 0 ) {
$value = absint( $discount->get_use_count() ) . '/' . absint( $discount->get_max_uses() );
} else {
$value = absint( $discount->get_use_count() );
}
break;
case 'uses_left' :
$value = rcp_discount_has_uses_left( $discount->get_id() ) ? __( 'yes', 'rcp' ) : __( 'no', 'rcp' );
break;
case 'expiration' :
$expiration = $discount->get_expiration();
$value = ! empty( $expiration ) ? date_i18n( 'Y-m-d H:i:s', strtotime( $expiration, current_time( 'timestamp' ) ) ) : __( 'none', 'rcp' );
break;
case 'one_time' :
$value = $discount->is_one_time() ? __( 'yes', 'rcp' ) : __( 'no', 'rcp' );
break;
}
/*
* Backwards compatibility: show content of custom columns from old action hook.
*/
if ( 'custom' == $column_name && has_action( 'rcp_discounts_page_table_column' ) ) {
ob_start();
do_action( 'rcp_discounts_page_table_column', $discount->get_id() );
$column_content = ob_get_clean();
$value = wp_strip_all_tags( $column_content );
}
/**
* Filters the column value.
*
* @param string $value Column value.
* @param object $discount Discount code object.
*
* @since 3.1
*/
$value = apply_filters( 'rcp_discount_codes_list_table_column_' . $column_name, $value, $discount );
return $value;
}
/**
* Render the checkbox column.
*
* @param object $discount
*
* @since 3.1
* @return string
*/
public function column_cb( $discount ) {
return sprintf(
'<input type="checkbox" name="%1$s[]" value="%2$s" />',
'discount_id',
$discount->id
);
}
/**
* Render the "Name" column.
*
* @param RCP_Discount $discount
*
* @since 3.1
* @return string
*/
public function column_name( $discount ) {
$edit_discount_url = add_query_arg( 'edit_discount', urlencode( $discount->get_id() ), $this->get_base_url() );
// Edit discount.
$actions = array(
'edit' => '<a href="' . esc_url( $edit_discount_url ) . '">' . __( 'Edit', 'rcp' ) . '</a>',
);
if ( 'active' == $discount->get_status() ) {
// Deactivate discount.
$actions['deactivate'] = '<a href="' . esc_url( wp_nonce_url( add_query_arg( array(
'rcp-action' => 'deactivate_discount',
'discount_id' => urlencode( $discount->get_id() )
), $this->get_base_url() ), 'rcp-deactivate-discount' ) ) . '">' . __( 'Deactivate', 'rcp' ) . '</a>';
} else {
// Activate discount.
$actions['activate'] = '<a href="' . esc_url( wp_nonce_url( add_query_arg( array(
'rcp-action' => 'activate_discount',
'discount_id' => urlencode( $discount->get_id() )
), $this->get_base_url() ), 'rcp-activate-discount' ) ) . '">' . __( 'Activate', 'rcp' ) . '</a>';
}
// Delete discount.
$actions['delete'] = '<span class="trash"><a href="' . esc_url( wp_nonce_url( add_query_arg( array(
'rcp-action' => 'delete_discount_code',
'discount_id' => urlencode( $discount->get_id() )
), $this->get_base_url() ), 'rcp-delete-discount' ) ) . '" class="rcp_delete_discount">' . __( 'Delete', 'rcp' ) . '</a></span>';
// Discount ID.
$actions['discount_id'] = '<span class="id rcp-id-col">' . sprintf( __( 'ID: %d', 'rcp' ), $discount->get_id() ) . '</span>';
/**
* Filters the row actions.
*
* @param array $actions Default actions.
* @param object $discount Discount object.
*
* @since 3.1
*/
$actions = apply_filters( 'rcp_discount_codes_list_table_row_actions', $actions, $discount );
$final = '<strong><a class="row-title" href="' . esc_url( $edit_discount_url ) . '">' . esc_html( $discount->get_name() ) . '</a></strong>';
if ( current_user_can( 'rcp_manage_discounts' ) ) {
$final .= $this->row_actions( $actions );
}
return $final;
}
/**
* Message to be displayed when there are no discount codes.
*
* @since 3.1
* @return void
*/
public function no_items() {
esc_html_e( 'No discount codes found.', 'rcp' );
}
/**
* Retrieve the bulk actions.
*
* @since 3.1
* @return array
*/
public function get_bulk_actions() {
return array(
'activate' => __( 'Activate', 'rcp' ),
'deactivate' => __( 'Deactivate', 'rcp' ),
'delete' => __( 'Permanently Delete', 'rcp' )
);
}
/**
* Process bulk actions.
*
* @since 3.1
* @return void
*/
public function process_bulk_action() {
// Bail if a nonce was not supplied.
if ( ! isset( $_REQUEST['_wpnonce'] ) ) {
return;
}
if ( ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'bulk-discountcodes' ) ) {
return;
}
$ids = wp_parse_id_list( (array) $this->get_request_var( 'discount_id', false ) );
// Bail if no IDs
if ( empty( $ids ) ) {
return;
}
foreach ( $ids as $discount_id ) {
switch ( $this->current_action() ) {
case 'activate':
rcp_update_discount( absint( $discount_id ), array( 'status' => 'active' ) );
break;
case 'deactivate':
rcp_update_discount( absint( $discount_id ), array( 'status' => 'disabled' ) );
break;
case 'delete':
rcp_delete_discount( absint( $discount_id ) );
break;
}
}
$this->show_admin_notice( $this->current_action(), count( $ids ) );
}
/**
* Show admin notice for bulk actions.
*
* @param string $action The action to show the notice for.
* @param int $number Number of objects processed.
*
* @access private
* @since 3.1
* @return void
*/
private function show_admin_notice( $action, $number = 1 ) {
$message = '';
switch ( $action ) {
case 'activate' :
$message = _n( 'Discount code activated.', 'Discount codes activated.', $number, 'rcp' );
break;
case 'deactivate' :
$message = _n( 'Discount code deactivated.', 'Discount codes deactivated.', $number, 'rcp' );
break;
case 'delete' :
$message = _n( 'Discount code deleted.', 'Discount codes deleted.', $number, 'rcp' );
break;
}
if ( empty( $message ) ) {
return;
}
echo '<div class="updated"><p>' . $message . '</p></div>';
}
/**
* Retrieve the discount code counts.
*
* @since 3.1
* @return void
*/
public function get_counts() {
$this->counts = array(
'total' => rcp_count_discounts(),
'active' => rcp_count_discounts( array( 'status' => 'active' ) ),
'inactive' => rcp_count_discounts( array( 'status' => 'disabled' ) )
);
}
/**
* Retrieve discount codes data.
*
* @param bool $count Whether or not to get discount code objects (false) or just count the total number (true).
*
* @since 3.1
* @return RCP_Discount[]|int
*/
public function discounts_data( $count = false ) {
$args = array(
'number' => $this->per_page,
'offset' => $this->get_offset(),
'status' => $this->get_status(),
'search' => $this->get_search(),
'orderby' => $this->get_request_var( 'orderby', 'date_modified' ),
'order' => strtoupper( $this->get_request_var( 'order', 'DESC' ) )
);
// Use `disabled` instead of `inactive`.
if ( 'inactive' === $args['status'] ) {
$args['status'] = 'disabled';
}
if ( $count ) {
return rcp_count_discounts( $args );
}
return rcp_get_discounts( $args );
}
/**
* Setup the final data for the table.
*
* @since 3.1
* @return void
*/
public function prepare_items() {
$columns = $this->get_columns();
$hidden = array();
$sortable = $this->get_sortable_columns();
$this->_column_headers = array( $columns, $hidden, $sortable );
$this->items = $this->discounts_data();
$total = $this->discounts_data( true );
// Setup pagination
$this->set_pagination_args( array(
'total_items' => $total,
'per_page' => $this->per_page,
'total_pages' => ceil( $total / $this->per_page )
) );
}
}

View File

@@ -0,0 +1,217 @@
<?php
/**
* Discount Actions
*
* @package restrict-content-pro
* @subpackage Admin/Discount Actions
* @copyright Copyright (c) 2017, Restrict Content Pro
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
* @since 2.9
*/
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) exit;
/**
* Add a new discount code
*
* @since 2.9
* @return void
*/
function rcp_process_add_discount() {
if ( ! wp_verify_nonce( $_POST['rcp_add_discount_nonce'], 'rcp_add_discount_nonce' ) ) {
wp_die( __( 'Nonce verification failed.', 'rcp' ), __( 'Error', 'rcp' ), array( 'response' => 403 ) );
}
if ( ! current_user_can( 'rcp_manage_discounts' ) ) {
wp_die( __( 'You do not have permission to perform this action.', 'rcp' ), __( 'Error', 'rcp' ), array( 'response' => 403 ) );
}
// Setup data
$data = array(
'name' => sanitize_text_field( wp_unslash( $_POST['name'] ) ),
'description' => wp_kses_post( wp_unslash( $_POST['description'] ) ),
'amount' => sanitize_text_field( $_POST['amount'] ),
'unit' => isset( $_POST['unit'] ) && $_POST['unit'] == '%' ? '%' : 'flat',
'code' => sanitize_text_field( wp_unslash( $_POST['code'] ) ),
'status' => 'active',
'expiration' => sanitize_text_field( $_POST['expiration'] ),
'max_uses' => absint( $_POST['max'] ),
'membership_level_ids' => ( ! empty( $_POST['membership_levels'] ) && is_array( $_POST['membership_levels'] ) ) ? array_map( 'absint', $_POST['membership_levels'] ) : array(),
'one_time' => ! empty( $_POST['one_time'] ) ? 1 : 0
);
$add = rcp_add_discount( $data );
if ( is_wp_error( $add ) ) {
rcp_log( sprintf( 'Error creating new discount code: %s', $add->get_error_message() ), true );
$error_code = ( 'discount' === substr( $add->get_error_code(), 0, 8 ) ) ? $add->get_error_code() : 'discount_' . $add->get_error_code();
$url = add_query_arg( array(
'rcp_message' => urlencode( $error_code ),
'discount_code' => urlencode( strtolower( $data['code'] ) )
), admin_url( 'admin.php?page=rcp-discounts' ) );
} elseif ( $add ) {
rcp_log( sprintf( 'Successfully added discount #%d.', $add ) );
$url = admin_url( 'admin.php?page=rcp-discounts&rcp_message=discount_added' );
} else {
rcp_log( 'Error inserting new discount code into the database.', true );
$url = admin_url( 'admin.php?page=rcp-discounts&rcp_message=discount_not_added' );
}
wp_safe_redirect( $url );
exit;
}
add_action( 'rcp_action_add-discount', 'rcp_process_add_discount' );
/**
* Edit an existing discount code
*
* @since 2.9
* @return void
*/
function rcp_process_edit_discount() {
if ( ! wp_verify_nonce( $_POST['rcp_edit_discount_nonce'], 'rcp_edit_discount_nonce' ) ) {
wp_die( __( 'Nonce verification failed.', 'rcp' ), __( 'Error', 'rcp' ), array( 'response' => 403 ) );
}
if ( ! current_user_can( 'rcp_manage_discounts' ) ) {
wp_die( __( 'You do not have permission to perform this action.', 'rcp' ), __( 'Error', 'rcp' ), array( 'response' => 403 ) );
}
// Setup data
$data = array(
'name' => sanitize_text_field( wp_unslash( $_POST['name'] ) ),
'description' => wp_kses_post( wp_unslash( $_POST['description'] ) ),
'amount' => sanitize_text_field( $_POST['amount'] ),
'unit' => isset( $_POST['unit'] ) && $_POST['unit'] == '%' ? '%' : 'flat',
'code' => sanitize_text_field( wp_unslash( $_POST['code'] ) ),
'status' => 'active' == $_POST['status'] ? 'active' : 'disabled',
'expiration' => sanitize_text_field( $_POST['expiration'] ),
'max_uses' => absint( $_POST['max'] ),
'membership_level_ids' => ( ! empty( $_POST['membership_levels'] ) && is_array( $_POST['membership_levels'] ) ) ? array_map( 'absint', $_POST['membership_levels'] ) : array(),
'one_time' => ! empty( $_POST['one_time'] ) ? 1 : 0,
);
$update = rcp_update_discount( absint( $_POST['discount_id'] ), $data );
if ( is_wp_error( $update ) ) {
rcp_log( sprintf( 'Error updating discount code: %s', $update->get_error_message() ), true );
wp_die( $update );
}
if ( $update ) {
rcp_log( sprintf( 'Successfully edited discount #%d.', $_POST['discount_id'] ) );
$url = admin_url( 'admin.php?page=rcp-discounts&discount-updated=1' );
} else {
rcp_log( sprintf( 'Error editing discount #%d.', $_POST['discount_id'] ), true );
$url = admin_url( 'admin.php?page=rcp-discounts&discount-updated=0' );
}
wp_safe_redirect( $url );
exit;
}
add_action( 'rcp_action_edit-discount', 'rcp_process_edit_discount' );
/**
* Delete a discount code
*
* @since 2.9
* @return void
*/
function rcp_process_delete_discount() {
if ( ! wp_verify_nonce( $_GET['_wpnonce'], 'rcp-delete-discount' ) ) {
wp_die( __( 'Nonce verification failed.', 'rcp' ), __( 'Error', 'rcp' ), array( 'response' => 403 ) );
}
if ( ! current_user_can( 'rcp_manage_discounts' ) ) {
wp_die( __( 'You do not have permission to perform this action.', 'rcp' ), __( 'Error', 'rcp' ), array( 'response' => 403 ) );
}
if ( ! isset( $_GET['discount_id'] ) ) {
wp_die( __( 'Please select a discount.', 'rcp' ), __( 'Error', 'rcp' ), array( 'response' => 400 ) );
}
$discount_id = absint( $_GET['discount_id'] );
rcp_delete_discount( $discount_id );
rcp_log( sprintf( 'Deleted discount #%d.', $discount_id ) );
wp_safe_redirect( add_query_arg( 'rcp_message', 'discount_deleted', 'admin.php?page=rcp-discounts' ) );
exit;
}
add_action( 'rcp_action_delete_discount_code', 'rcp_process_delete_discount' );
/**
* Activate a discount code
*
* @since 2.9
* @return void
*/
function rcp_process_activate_discount() {
if ( ! wp_verify_nonce( $_GET['_wpnonce'], 'rcp-activate-discount' ) ) {
wp_die( __( 'Nonce verification failed.', 'rcp' ), __( 'Error', 'rcp' ), array( 'response' => 403 ) );
}
if ( ! current_user_can( 'rcp_manage_discounts' ) ) {
wp_die( __( 'You do not have permission to perform this action.', 'rcp' ), __( 'Error', 'rcp' ), array( 'response' => 403 ) );
}
if ( ! isset( $_GET['discount_id'] ) ) {
wp_die( __( 'Please select a discount.', 'rcp' ), __( 'Error', 'rcp' ), array( 'response' => 400 ) );
}
$discount_id = absint( $_GET['discount_id'] );
rcp_update_discount( $discount_id, array(
'status' => 'active'
) );
rcp_log( sprintf( 'Successfully activated discount #%d.', $discount_id ) );
wp_safe_redirect( add_query_arg( 'rcp_message', 'discount_activated', 'admin.php?page=rcp-discounts' ) );
exit;
}
add_action( 'rcp_action_activate_discount', 'rcp_process_activate_discount' );
/**
* Deactivate a discount code
*
* @since 2.9
* @return void
*/
function rcp_process_deactivate_discount() {
if ( ! wp_verify_nonce( $_GET['_wpnonce'], 'rcp-deactivate-discount' ) ) {
wp_die( __( 'Nonce verification failed.', 'rcp' ), __( 'Error', 'rcp' ), array( 'response' => 403 ) );
}
if ( ! current_user_can( 'rcp_manage_discounts' ) ) {
wp_die( __( 'You do not have permission to perform this action.', 'rcp' ), __( 'Error', 'rcp' ), array( 'response' => 403 ) );
}
if ( ! isset( $_GET['discount_id'] ) ) {
wp_die( __( 'Please select a discount.', 'rcp' ), __( 'Error', 'rcp' ), array( 'response' => 400 ) );
}
$discount_id = absint( $_GET['discount_id'] );
rcp_update_discount( $discount_id, array(
'status' => 'disabled'
) );
rcp_log( sprintf( 'Successfully deactivated discount #%d.', $discount_id ) );
wp_safe_redirect( add_query_arg( 'rcp_message', 'discount_deactivated', 'admin.php?page=rcp-discounts' ) );
exit;
}
add_action( 'rcp_action_deactivate_discount', 'rcp_process_deactivate_discount' );

View File

@@ -0,0 +1,156 @@
<?php
/**
* Discount Codes Page
*
* @package Restrict Content Pro
* @subpackage Admin/Discount Codes
* @copyright Copyright (c) 2017, Restrict Content Pro
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
*/
/**
* Render the discounts table
*
* @return void
*/
function rcp_discounts_page() {
include_once RCP_PLUGIN_DIR . 'pro/includes/admin/discounts/class-discount-codes-table.php';
$table_class = new \RCP\Admin\Discount_Codes_Table();
$table_class->prepare_items();
do_action( 'stellarwp/telemetry/restrict-content-pro/optin' );
?>
<div class="wrap">
<?php if( isset( $_GET['edit_discount'] ) ) :
include('edit-discount.php');
else : ?>
<h1><?php _e( 'Discount Codes', 'rcp' ); ?></h1>
<form id="rcp-discount-codes-filter" method="GET" action="<?php echo esc_url( add_query_arg( 'page', 'rcp-discounts', admin_url( 'admin.php' ) ) ); ?>">
<input type="hidden" name="page" value="rcp-discounts"/>
<?php
$table_class->views();
$table_class->search_box( __( 'Search discount codes', 'rcp' ), 'rcp-membership-levels' );
$table_class->display();
?>
</form>
<?php do_action( 'rcp_discounts_below_table' ); ?>
<?php if( current_user_can( 'rcp_manage_discounts' ) ) : ?>
<h2><?php _e( 'Add New Discount', 'rcp' ); ?></h2>
<form id="rcp-discounts" action="" method="POST">
<table class="form-table">
<tbody>
<tr class="form-field">
<th scope="row" valign="top">
<label for="rcp-name"><?php _e( 'Name', 'rcp' ); ?></label>
</th>
<td>
<input name="name" id="rcp-name" type="text" value=""/>
<p class="description"><?php _e( 'The name of this discount', 'rcp' ); ?></p>
</td>
</tr>
<tr class="form-field">
<th scope="row" valign="top">
<label for="rcp-description"><?php _e( 'Description', 'rcp' ); ?></label>
</th>
<td>
<textarea name="description" id="rcp-description"></textarea>
<p class="description"><?php _e( 'The description of this discount code', 'rcp' ); ?></p>
</td>
</tr>
<tr class="form-field">
<th scope="row" valign="top">
<label for="rcp-code"><?php _e( 'Code', 'rcp' ); ?></label>
</th>
<td>
<input type="text" id="rcp-code" name="code" value=""/>
<p class="description"><?php _e( 'Enter a code for this discount, such as 10PERCENT. Excluding special characters', 'rcp' ); ?></p>
</td>
</tr>
<tr class="form-field">
<th scope="row" valign="top">
<label for="rcp-unit"><?php _e( 'Type', 'rcp' ); ?></label>
</th>
<td>
<select name="unit" id="rcp-duration-unit">
<option value="%"><?php _e( 'Percentage', 'rcp' ); ?></option>
<option value="flat"><?php _e( 'Flat amount', 'rcp' ); ?></option>
</select>
<p class="description"><?php _e( 'The kind of discount to apply for this discount.', 'rcp' ); ?></p>
</td>
</tr>
<tr class="form-field">
<th scope="row" valign="top">
<label for="rcp-amount"><?php _e( 'Amount', 'rcp' ); ?></label>
</th>
<td>
<input type="text" id="rcp-amount" name="amount" value=""/>
<p class="description"><?php _e( 'The amount of this discount code.', 'rcp' ); ?></p>
</td>
</tr>
<tr class="form-field">
<th scope="row" valign="top">
<label for="rcp-discount-one-time"><?php _e( 'One Time', 'rcp' ); ?></label>
</th>
<td>
<input type="checkbox" value="1" name="one_time" id="rcp-discount-one-time"/>
<span class="description"><?php _e( 'Check this to make this discount only apply to the first payment in a membership. Note one-time discounts cannot be used in conjunction with free trials. When this option is not enabled, the discount code will apply to all payments in a membership instead of just the initial payment.', 'rcp' ); ?></span>
</td>
</tr>
<tr class="form-field">
<th scope="row" valign="top">
<label for="rcp-subscription"><?php _e( 'Membership Levels', 'rcp' ); ?></label>
</th>
<td>
<?php
$levels = rcp_get_membership_levels( array( 'number' => 999 ) );
if( $levels ) {
foreach ( $levels as $level ) : ?>
<input type="checkbox" id="rcp-membership-levels-<?php echo esc_attr( $level->get_id() ); ?>" name="membership_levels[]" value="<?php echo esc_attr( $level->id ) ?>">
<label for="rcp-membership-levels-<?php echo esc_attr( $level->get_id() ); ?>"><?php echo esc_html( $level->get_name() ); ?></label>
<br>
<?php
endforeach;
?>
<p class="description"><?php _e( 'The membership levels this discount code can be used for. Leave blank for all levels.', 'rcp' ); ?></p>
<?php
} else {
echo '<p class="description">' . __( 'No membership levels created yet. This discount will be available to use with all future membership levels.', 'rcp' ) . '</p>';
}
?>
</td>
</tr>
<tr class="form-field">
<th scope="row" valign="top">
<label for="rcp-expiration"><?php _e( 'Expiration date', 'rcp' ); ?></label>
</th>
<td>
<input name="expiration" id="rcp-expiration" type="text" class="rcp-datetimepicker"/>
<p class="description"><?php _e( 'Enter the expiration date for this discount code in the format of yyyy-mm-dd hh:mm:ss. For no expiration, leave blank', 'rcp' ); ?></p>
</td>
</tr>
<tr class="form-field">
<th scope="row" valign="top">
<label for="rcp-max-uses"><?php _e( 'Max Uses', 'rcp' ); ?></label>
</th>
<td>
<input type="text" id="rcp-max-uses" name="max" value=""/>
<p class="description"><?php _e( 'The maximum number of times this discount can be used. Leave blank for unlimited.', 'rcp' ); ?></p>
</td>
</tr>
<?php do_action( 'rcp_add_discount_form' ); ?>
</tbody>
</table>
<p class="submit">
<input type="hidden" name="rcp-action" value="add-discount"/>
<input type="submit" value="<?php _e( 'Add Discount Code', 'rcp' ); ?>" class="button-primary"/>
</p>
<?php wp_nonce_field( 'rcp_add_discount_nonce', 'rcp_add_discount_nonce' ); ?>
</form>
<?php endif; ?>
<?php endif; ?>
</div><!--end wrap-->
<?php
}

View File

@@ -0,0 +1,142 @@
<?php
/**
* Edit Discount Code
*
* @package Restrict Content Pro
* @subpackage Admin/Edit Discount
* @copyright Copyright (c) 2017, Restrict Content Pro
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
*/
$code = rcp_get_discount( urldecode( $_GET['edit_discount'] ) );
?>
<h1>
<?php _e( 'Edit Discount Code:', 'rcp' ); echo ' ' . $code->get_name(); ?>
<a href="<?php echo admin_url( '/admin.php?page=rcp-discounts' ); ?>" class="add-new-h2">
<?php _e( 'Cancel', 'rcp' ); ?>
</a>
</h1>
<form id="rcp-edit-discount" action="" method="post">
<table class="form-table">
<tbody>
<tr class="form-field">
<th scope="row" valign="top">
<label for="rcp-name"><?php _e(' Name', 'rcp' ); ?></label>
</th>
<td>
<input name="name" id="rcp-name" type="text" value="<?php echo esc_html( $code->get_name() ); ?>"/>
<p class="description"><?php _e(' The name of this discount', 'rcp' ); ?></p>
</td>
</tr>
<tr class="form-field">
<th scope="row" valign="top">
<label for="rcp-description"><?php _e(' Description', 'rcp' ); ?></label>
</th>
<td>
<textarea name="description" id="rcp-description"><?php echo esc_html( $code->get_description() ); ?></textarea>
<p class="description"><?php _e(' The description of this discount code', 'rcp' ); ?></p>
</td>
</tr>
<tr class="form-field">
<th scope="row" valign="top">
<label for="rcp-code"><?php _e(' Code', 'rcp' ); ?></label>
</th>
<td>
<input type="text" id="rcp-code" name="code" value="<?php echo esc_attr( $code->get_code() ); ?>"/>
<p class="description"><?php _e(' Enter a code for this discount, such as 10PERCENT. Excluding special characters', 'rcp' ); ?></p>
</td>
</tr>
<tr class="form-field">
<th scope="row" valign="top">
<label for="rcp-unit"><?php _e(' Type', 'rcp' ); ?></label>
</th>
<td>
<select name="unit" id="rcp-unit">
<option value="%" <?php selected( $code->get_unit(), '%' ); ?>><?php _e(' Percentage', 'rcp' ); ?></option>
<option value="flat" <?php selected( $code->get_unit(), 'flat' ); ?>><?php _e(' Flat amount', 'rcp' ); ?></option>
</select>
<p class="description"><?php _e(' The kind of discount to apply for this discount.', 'rcp' ); ?></p>
</td>
</tr>
<tr class="form-field">
<th scope="row" valign="top">
<label for="rcp-amount"><?php _e(' Amount', 'rcp' ); ?></label>
</th>
<td>
<input type="text" id="rcp-amount" name="amount" value="<?php echo esc_attr( $code->get_amount() ); ?>"/>
<p class="description"><?php _e(' The amount of this discount code.', 'rcp' ); ?></p>
</td>
</tr>
<tr class="form-field">
<th scope="row" valign="top">
<label for="rcp-discount-one-time"><?php _e( 'One Time', 'rcp' ); ?></label>
</th>
<td>
<input type="checkbox" value="1" name="one_time" id="rcp-discount-one-time" <?php checked( ! empty( $code->one_time ) ); ?>/>
<span class="description"><?php _e( 'Check this to make this discount only apply to the first payment in a membership. Note one-time discounts cannot be used in conjunction with free trials. When this option is not enabled, the discount code will apply to all payments in a membership instead of just the initial payment.', 'rcp' ); ?></span>
</td>
</tr>
<tr class="form-field">
<th scope="row" valign="top">
<label for="rcp-subscription"><?php _e( 'Membership Levels', 'rcp' ); ?></label>
</th>
<td>
<?php
$levels = rcp_get_membership_levels( array( 'number' => 999 ) );
if( $levels ) {
$current = $code->get_membership_level_ids();
foreach ( $levels as $level ) : ?>
<input type="checkbox" id="rcp-membership-levels-<?php echo esc_attr( $level->get_id() ); ?>" name="membership_levels[]" value="<?php echo esc_attr( $level->get_id() ) ?>" <?php checked( true, in_array( $level->get_id(), $current ) ); ?>>
<label for="rcp-membership-levels-<?php echo esc_attr( $level->get_id() ); ?>"><?php echo esc_html( $level->get_name() ); ?></label>
<br>
<?php
endforeach;
?>
<p class="description"><?php _e( 'The membership levels this discount code can be used for. Leave blank for all levels.', 'rcp' ); ?></p>
<?php
} else {
echo '<p class="description">' . __( 'No membership levels created yet. This discount will be available to use with all future membership levels.', 'rcp' ) . '</p>';
}
?>
</td>
</tr>
<tr valign="top">
<th scope="row" valign="top">
<label for="rcp-expiration"><?php _e(' Expiration date', 'rcp' ); ?></label>
</th>
<td>
<input name="expiration" id="rcp-expiration" type="text" class="rcp-datetimepicker" value="<?php echo empty( $code->get_expiration() ) ? '' : esc_attr( date( 'Y-m-d H:i:s', strtotime( $code->get_expiration(), current_time( 'timestamp' ) ) ) ); ?>"/>
<p class="description"><?php _e(' Enter the expiration date for this discount code in the format of yyyy-mm-dd hh:mm:ss. Leave blank for no expiration', 'rcp' ); ?></p>
</td>
</tr>
<tr class="form-field">
<th scope="row" valign="top">
<label for="rcp-status"><?php _e(' Status', 'rcp' ); ?></label>
</th>
<td>
<select name="status" id="rcp-status">
<option value="active" <?php selected( $code->get_status(), '%' ); ?>><?php _e(' Active', 'rcp' ); ?></option>
<option value="disabled" <?php selected( $code->get_status(), 'disabled' ); ?>><?php _e(' Disabled', 'rcp' ); ?></option>
</select>
<p class="description"><?php _e(' The status of this discount code.', 'rcp' ); ?></p>
</td>
</tr>
<tr class="form-field">
<th scope="row" valign="top">
<label for="rcp-max-uses"><?php _e(' Max Uses', 'rcp' ); ?></label>
</th>
<td>
<input type="text" id="rcp-max-uses" name="max" value="<?php echo esc_attr( absint( $code->get_max_uses() ) ); ?>"/>
<p class="description"><?php _e(' The maximum number of times this discount can be used. Leave blank for unlimited.', 'rcp' ); ?></p>
</td>
</tr>
<?php do_action( 'rcp_edit_discount_form', $code->get_id() ); ?>
</tbody>
</table>
<p class="submit">
<input type="hidden" name="rcp-action" value="edit-discount"/>
<input type="hidden" name="discount_id" value="<?php echo absint( urldecode( $_GET['edit_discount'] ) ); ?>"/>
<input type="submit" value="<?php _e(' Update Discount', 'rcp' ); ?>" class="button-primary"/>
</p>
<?php wp_nonce_field( 'rcp_edit_discount_nonce', 'rcp_edit_discount_nonce' ); ?>
</form>

View File

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

View File

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

View File

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

View File

@@ -0,0 +1,134 @@
<?php
/**
* Report Actions
*
* @package restrict-content-pro
* @copyright Copyright (c) 2019, Sandhills Development, LLC
* @license GPL2+
* @since 3.3
*/
/**
* Get the membership counts report data
*
* @since 3.3
* @return void
*/
function rcp_get_membership_counts_report_data() {
check_ajax_referer( 'rcp_load_reports', 'nonce' );
$membership_level_id = ! empty( $_POST['level_id'] ) ? absint( $_POST['level_id'] ) : 0;
$status = ! empty( $_POST['membership_status'] ) ? $_POST['membership_status'] : '';
$config = array(
'type' => 'line',
'data' => array(
'labels' => array(), // Date intervals
'datasets' => array(
'active' => array(
'label' => __( 'Active Memberships', 'rcp' ),
'backgroundColor' => 'rgba(12, 194, 25, 0.1)',
'borderColor' => 'rgb(12, 194, 25)',
//'fill' => false
),
'expired' => array(
'label' => __( 'Expired Memberships', 'rcp' ),
'backgroundColor' => 'rgba(255, 99, 132, 0.1)',
'borderColor' => 'rgb(255, 99, 132)',
//'fill' => false
),
'cancelled' => array(
'label' => __( 'Cancelled Memberships', 'rcp' ),
'backgroundColor' => 'rgba(178, 178, 178, 0.1)',
'borderColor' => 'rgb(178, 178, 178)',
//'fill' => false
),
'pending' => array(
'label' => __( 'Pending Memberships', 'rcp' ),
'backgroundColor' => 'rgba(59, 168, 245, 0.1)',
'borderColor' => 'rgb(59, 168, 245)',
//'fill' => false
)
)
),
'options' => array(
'scales' => array(
'xAxes' => array(
array(
'ticks' => array(
'autoSkipPadding' => 10,
'maxLabels' => 52
)
)
),
'yAxes' => array(
array(
'ticks' => array(
'min' => 0
)
)
),
)
)
);
if ( ! empty( $status ) ) {
foreach ( $config['data']['datasets'] as $status_key => $status_name ) {
if ( $status_key !== $status ) {
unset( $config['data']['datasets'][ $status_key ] );
}
}
}
$statuses = array_keys( $config['data']['datasets'] );
$dates = rcp_get_report_dates();
$ranges = rcp_get_graph_dates_by_range();
$from = date_create_from_format( 'j n Y', sprintf( '%d %d %d', $dates['day'], $dates['m_start'], $dates['year'] ) );
$to = date_create_from_format( 'j n Y', sprintf( '%d %d %d', $dates['day_end'], $dates['m_end'], $dates['year_end'] ) );
$config['data']['labels'] = $ranges;
$membership_counts_table_name = restrict_content_pro()->membership_counts_table->get_table_name();
global $wpdb;
$where = $wpdb->prepare( "WHERE date_created >= %s AND date_created <= %s", $from->format( 'Y-m-d 00:00:00' ), $to->format( 'Y-m-d 23:59:59' ) );
if ( ! empty( $membership_level_id ) ) {
$where .= $wpdb->prepare( " AND level_id = %d ", $membership_level_id );
}
$query = "SELECT SUM(active_count) AS active, SUM(pending_count) AS pending, SUM(cancelled_count) AS cancelled, SUM(expired_count) AS expired, DATE_FORMAT(date_created, '%Y-%m-%d') as date FROM {$membership_counts_table_name} {$where} GROUP BY date";
$results = $wpdb->get_results( $query );
$formatted_results = array();
foreach ( $results as $result ) {
$formatted_results[ $result->date ] = array(
'active' => $result->active,
'pending' => $result->pending,
'cancelled' => $result->cancelled,
'expired' => $result->expired
);
}
foreach ( $ranges as $range ) {
$exists = false;
if ( array_key_exists( $range, $formatted_results ) ) {
$exists = true;
}
foreach ( $statuses as $status ) {
$config['data']['datasets'][ $status ]['data'][] = $exists ? absint( $formatted_results[ $range ][ $status ] ) : 0;
}
}
$config['data']['datasets'] = array_values( $config['data']['datasets'] );
wp_send_json_success( $config );
exit;
}
add_action( 'wp_ajax_rcp_get_membership_counts_report_data', 'rcp_get_membership_counts_report_data' );