Initial Commit
This commit is contained in:
1533
inc/list-tables/class-base-list-table.php
Normal file
1533
inc/list-tables/class-base-list-table.php
Normal file
File diff suppressed because it is too large
Load Diff
521
inc/list-tables/class-broadcast-list-table.php
Normal file
521
inc/list-tables/class-broadcast-list-table.php
Normal file
@ -0,0 +1,521 @@
|
||||
<?php
|
||||
/**
|
||||
* Broadcast List Table class.
|
||||
*
|
||||
* @package WP_Ultimo
|
||||
* @subpackage List_Table
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\List_Tables;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* Broadcast List Table class.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
class Broadcast_List_Table extends Base_List_Table {
|
||||
|
||||
/**
|
||||
* Holds the query class for the object being listed.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var string
|
||||
*/
|
||||
protected $query_class = '\\WP_Ultimo\\Database\\Broadcasts\\Broadcast_Query';
|
||||
|
||||
/**
|
||||
* Initializes the table.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
parent::__construct(array(
|
||||
'singular' => __('Broadcast', 'wp-ultimo'), // singular name of the listed records
|
||||
'plural' => __('Broadcasts', 'wp-ultimo'), // plural name of the listed records
|
||||
'ajax' => true, // does this table support ajax?
|
||||
'add_new' => array(
|
||||
'url' => wu_get_form_url('add_new_broadcast_message'),
|
||||
'classes' => 'wubox',
|
||||
),
|
||||
));
|
||||
|
||||
} // end __construct;
|
||||
|
||||
/**
|
||||
* Overrides the checkbox column to disable the checkboxes on the email types.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param \WP_Ultimo\Models\Broadcast $item The broadcast object.
|
||||
* @return string
|
||||
*/
|
||||
public function column_cb($item) {
|
||||
|
||||
if ($item->get_type() === 'broadcast_email') {
|
||||
|
||||
return '<input type="checkbox" disabled>';
|
||||
|
||||
} // end if;
|
||||
|
||||
return parent::column_cb($item);
|
||||
|
||||
} // end column_cb;
|
||||
|
||||
/**
|
||||
* Returns the markup for the type column.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param \WP_Ultimo\Models\Broadcast $item The broadcast object.
|
||||
* @return string
|
||||
*/
|
||||
public function column_type($item) {
|
||||
|
||||
$type = $item->get_type();
|
||||
|
||||
$class = 'wu-bg-gray-200';
|
||||
|
||||
if ($type === 'broadcast_email') {
|
||||
|
||||
$label = __('Email', 'wp-ultimo');
|
||||
|
||||
} // end if;
|
||||
|
||||
if ($type === 'broadcast_notice') {
|
||||
|
||||
$status = $item->get_notice_type();
|
||||
|
||||
$label = __('Notice', 'wp-ultimo');
|
||||
|
||||
if ($status === 'info') {
|
||||
|
||||
$class = 'wu-bg-blue-200';
|
||||
|
||||
} elseif ($status === 'success') {
|
||||
|
||||
$class = 'wu-bg-green-200';
|
||||
|
||||
} elseif ($status === 'warning') {
|
||||
|
||||
$class = 'wu-bg-orange-200';
|
||||
|
||||
} elseif ($status === 'error') {
|
||||
|
||||
$class = 'wu-bg-red-200';
|
||||
|
||||
} // end if;
|
||||
|
||||
} // end if;
|
||||
|
||||
return "<span class='wu-py-1 wu-px-2 $class wu-rounded-sm wu-text-gray-700 wu-text-xs wu-font-mono'>{$label}</span>";
|
||||
|
||||
} // end column_type;
|
||||
/**
|
||||
* Displays the name of the broadcast.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param \WP_Ultimo\Models\Broadcast $item The broadcast object.
|
||||
*/
|
||||
public function column_the_content($item): string {
|
||||
|
||||
$title = sprintf('<strong class="wu-block wu-text-gray-700">%s</strong>', $item->get_title()); // phpcs:ignore
|
||||
|
||||
$content = wp_trim_words(wp_strip_all_tags($item->get_content()), 7);
|
||||
|
||||
$url_atts = array(
|
||||
'id' => $item->get_id(),
|
||||
'slug' => $item->get_slug(),
|
||||
'model' => 'broadcast'
|
||||
);
|
||||
|
||||
$actions = array(
|
||||
'edit' => sprintf('<a href="%s">%s</a>', wu_network_admin_url('wp-ultimo-edit-broadcast', $url_atts), __('Edit', 'wp-ultimo')),
|
||||
'delete' => sprintf('<a title="%s" class="wubox" href="%s">%s</a>', __('Delete', 'wp-ultimo'), wu_get_form_url('delete_modal', $url_atts), __('Delete', 'wp-ultimo')),
|
||||
);
|
||||
|
||||
return $title . $content . $this->row_actions($actions);
|
||||
|
||||
} // end column_the_content;
|
||||
|
||||
/**
|
||||
* Displays the target customers of the broadcast.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param \WP_Ultimo\Models\Broadcast $item The broadcast object.
|
||||
* @return string
|
||||
*/
|
||||
public function column_target_customers($item) {
|
||||
|
||||
$targets = wu_get_broadcast_targets($item->get_id(), 'customers');
|
||||
|
||||
$targets = array_filter(array_map('wu_get_customer', $targets));
|
||||
|
||||
$targets_count = count($targets);
|
||||
|
||||
$html = '<div class="wu-p-2 wu-mr-1 wu-flex wu-rounded wu-items-center wu-border wu-border-solid wu-border-gray-300 wu-bg-gray-100 wu-relative wu-overflow-hidden">';
|
||||
|
||||
switch ($targets_count) {
|
||||
case 0:
|
||||
$not_found = __('No customer found', 'wp-ultimo');
|
||||
|
||||
return "<div class='wu-p-2 wu-mr-1 wu-flex wu-rounded wu-items-center wu-border wu-border-solid wu-border-gray-300 wu-bg-gray-100 wu-relative wu-overflow-hidden'>
|
||||
<span class='dashicons dashicons-wu-block wu-text-gray-600 wu-px-1 wu-pr-3'> </span>
|
||||
<div class=''>
|
||||
<span class='wu-block wu-py-3 wu-text-gray-600 wu-text-2xs wu-font-bold wu-uppercase'>{$not_found}</span>
|
||||
</div>
|
||||
</div>";
|
||||
|
||||
break;
|
||||
case 1:
|
||||
$customer = array_pop($targets);
|
||||
|
||||
$url_atts = array(
|
||||
'id' => $customer->get_id(),
|
||||
);
|
||||
|
||||
$customer_link = wu_network_admin_url('wp-ultimo-edit-customer', $url_atts);
|
||||
|
||||
$avatar = get_avatar($customer->get_user_id(), 32, 'identicon', '', array(
|
||||
'force_display' => true,
|
||||
'class' => 'wu-rounded-full wu-border-solid wu-border-1 wu-border-white hover:wu-border-gray-400',
|
||||
));
|
||||
|
||||
$display_name = $customer->get_display_name();
|
||||
|
||||
$id = $customer->get_id();
|
||||
|
||||
$email = $customer->get_email_address();
|
||||
|
||||
$html = "<a href='{$customer_link}' class='wu-p-2 wu-flex wu-flex-grow wu-bg-gray-100 wu-rounded wu-items-center wu-border wu-border-solid wu-border-gray-300'>
|
||||
{$avatar}
|
||||
<div class='wu-pl-2'>
|
||||
<strong class='wu-block'>{$display_name} <small class='wu-font-normal'>(#{$id})</small></strong>
|
||||
<small>{$email}</small>
|
||||
</div>
|
||||
</a>";
|
||||
|
||||
return $html;
|
||||
break;
|
||||
default:
|
||||
foreach ($targets as $key => $target) {
|
||||
|
||||
$customer = $target;
|
||||
|
||||
$tooltip_name = $customer->get_display_name();
|
||||
|
||||
$email = $customer->get_email_address();
|
||||
|
||||
$avatar = get_avatar($email, 32, 'identicon', '', array(
|
||||
'class' => 'wu-rounded-full wu-border-solid wu-border-1 wu-border-white hover:wu-border-gray-400',
|
||||
));
|
||||
|
||||
$url_atts = array(
|
||||
'id' => $customer->get_id(),
|
||||
);
|
||||
|
||||
$customer_link = wu_network_admin_url('wp-ultimo-edit-customer', $url_atts);
|
||||
|
||||
$html .= "<div class='wu-flex wu--mr-4'><a role='tooltip' aria-label='{$tooltip_name}' href='{$customer_link}'>{$avatar}</a></div>";
|
||||
|
||||
} // end foreach;
|
||||
|
||||
if ($targets_count < 7) {
|
||||
|
||||
$modal_atts = array(
|
||||
'action' => 'wu_modal_targets_display',
|
||||
'object_id' => $item->get_id(),
|
||||
'width' => '400',
|
||||
'height' => '360',
|
||||
'target_type' => 'customers',
|
||||
);
|
||||
|
||||
$html .= sprintf('<div class="wu-inline-block wu-mr-2">
|
||||
<a href="%s" title="%s" class="wubox"><span class="wu-ml-6 wu-uppercase wu-text-xs wu-font-bold"> %s %s</span></a>
|
||||
</div>', wu_get_form_url('view_broadcast_targets', $modal_atts), __('Targets', 'wp-ultimo'), $targets_count, __('Targets', 'wp-ultimo'));
|
||||
|
||||
$html .= '</div>';
|
||||
|
||||
return $html;
|
||||
|
||||
} // end if;
|
||||
|
||||
$modal_atts = array(
|
||||
'action' => 'wu_modal_targets_display',
|
||||
'object_id' => $item->get_id(),
|
||||
'width' => '400',
|
||||
'height' => '360',
|
||||
'target_type' => 'customers',
|
||||
);
|
||||
|
||||
$html .= sprintf('<div class="wu-inline-block wu-ml-4">
|
||||
<a href="%s" title="%s" class="wubox"><span class="wu-pl-2 wu-uppercase wu-text-xs wu-font-bold"> %s %s</span></a>
|
||||
</div>', wu_get_form_url('view_broadcast_targets', $modal_atts), __('Targets', 'wp-ultimo'), $targets_count, __('Targets', 'wp-ultimo'));
|
||||
|
||||
$html .= '</div>';
|
||||
|
||||
return $html;
|
||||
|
||||
break;
|
||||
|
||||
} // end switch;
|
||||
|
||||
} // end column_target_customers;
|
||||
|
||||
/**
|
||||
* Displays the target products of the broadcast.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param \WP_Ultimo\Models\Broadcast $item The broadcast object.
|
||||
* @return string
|
||||
*/
|
||||
public function column_target_products($item) {
|
||||
|
||||
$targets = wu_get_broadcast_targets($item->get_id(), 'products');
|
||||
|
||||
$html = '';
|
||||
|
||||
$products = array_filter(array_map('wu_get_product', $targets));
|
||||
|
||||
$product_count = count($products);
|
||||
|
||||
switch ($product_count) {
|
||||
case 0:
|
||||
$not_found = __('No product found', 'wp-ultimo');
|
||||
|
||||
$html = "<div class='wu-p-2 wu-mr-1 wu-flex wu-rounded wu-items-center wu-border wu-border-solid wu-border-gray-300 wu-bg-gray-100 wu-relative wu-overflow-hidden'>
|
||||
<span class='dashicons dashicons-wu-block wu-text-gray-600 wu-px-1 wu-pr-3'> </span>
|
||||
<div class=''>
|
||||
<span class='wu-block wu-py-3 wu-text-gray-600 wu-text-2xs wu-font-bold wu-uppercase'>{$not_found}</span>
|
||||
</div>
|
||||
</div>";
|
||||
break;
|
||||
case 1:
|
||||
$product = array_pop($products);
|
||||
|
||||
$image = $product->get_featured_image('thumbnail');
|
||||
|
||||
if ($image) {
|
||||
|
||||
$image = sprintf('<img class="wu-w-7 wu-h-7 wu-bg-gray-200 wu-rounded-full wu-text-gray-600 wu-flex wu-items-center wu-justify-center wu-border-solid wu-border-1 wu-border-white hover:wu-border-gray-400" src="%s">', esc_attr($image));
|
||||
|
||||
} else {
|
||||
|
||||
$image = '<div class="wu-w-7 wu-h-7 wu-bg-gray-200 wu-rounded-full wu-text-gray-600 wu-flex wu-items-center wu-justify-center wu-border-solid wu-border-1 wu-border-white">
|
||||
<span class="dashicons-wu-image"></span>
|
||||
</div>';
|
||||
|
||||
} // end if;
|
||||
|
||||
$name = $product->get_name();
|
||||
|
||||
$id = $product->get_id();
|
||||
|
||||
$plan_customers = wu_get_membership_customers($product->get_id());
|
||||
|
||||
$customer_count = (int) 0;
|
||||
|
||||
if ($plan_customers) {
|
||||
|
||||
$customer_count = count($plan_customers);
|
||||
|
||||
} // end if;
|
||||
|
||||
$description = sprintf(__('%s customer(s) targeted.', 'wp-ultimo'), $customer_count);
|
||||
|
||||
$url_atts = array(
|
||||
'id' => $product->get_id(),
|
||||
);
|
||||
|
||||
$product_link = wu_network_admin_url('wp-ultimo-edit-product', $url_atts);
|
||||
|
||||
$html = "<a href='{$product_link}' class='wu-p-2 wu-flex wu-flex-grow wu-bg-gray-100 wu-rounded wu-items-center wu-border wu-border-solid wu-border-gray-300'>
|
||||
{$image}
|
||||
<div class='wu-pl-2'>
|
||||
<strong class='wu-block'>{$name} <small class='wu-font-normal'>(#{$id})</small></strong>
|
||||
<small>{$description}</small>
|
||||
</div>
|
||||
</a>";
|
||||
break;
|
||||
|
||||
} // end switch;
|
||||
|
||||
if ($html) {
|
||||
|
||||
return $html;
|
||||
|
||||
} // end if;
|
||||
|
||||
$html = '<div class="wu-p-2 wu-mr-1 wu-flex wu-rounded wu-items-center wu-border wu-border-solid wu-border-gray-300 wu-bg-gray-100 wu-relative wu-overflow-hidden">';
|
||||
|
||||
foreach ($products as $product) {
|
||||
|
||||
$url_atts = array(
|
||||
'id' => $product->get_id(),
|
||||
);
|
||||
|
||||
$product_link = wu_network_admin_url('wp-ultimo-edit-product', $url_atts);
|
||||
|
||||
$product_name = $product->get_name();
|
||||
|
||||
$image = $product->get_featured_image('thumbnail');
|
||||
|
||||
if ($image) {
|
||||
|
||||
$image = sprintf('<img class="wu-w-7 wu-h-7 wu-bg-gray-200 wu-rounded-full wu-text-gray-600 wu-flex wu-items-center wu-justify-center wu-border-solid wu-border-1 wu-border-white hover:wu-border-gray-400" src="%s">', esc_attr($image));
|
||||
|
||||
} else {
|
||||
|
||||
$image = '<div class="wu-w-7 wu-h-7 wu-bg-gray-200 wu-rounded-full wu-text-gray-600 wu-flex wu-items-center wu-justify-center wu-border-solid wu-border-1 wu-border-white hover:wu-border-gray-400">
|
||||
<span class="dashicons-wu-image wu-p-1 wu-rounded-full"></span>
|
||||
</div>';
|
||||
|
||||
} // end if;
|
||||
|
||||
$html .= "<div class='wu-flex wu--mr-4'><a role='tooltip' aria-label='{$product_name}' href='{$product_link}'>{$image}</a></div>";
|
||||
|
||||
} // end foreach;
|
||||
|
||||
if ($product_count > 1 && $product_count < 5) {
|
||||
|
||||
$modal_atts = array(
|
||||
'action' => 'wu_modal_targets_display',
|
||||
'object_id' => $item->get_id(),
|
||||
'width' => '400',
|
||||
'height' => '360',
|
||||
'target_type' => 'products',
|
||||
);
|
||||
|
||||
$html .= sprintf('<div class="wu-inline-block wu-ml-4">
|
||||
<a href="%s" title="%s" class="wubox"><span class="wu-pl-2 wu-uppercase wu-text-xs wu-font-bold"> %s %s</span></a></div>', wu_get_form_url('view_broadcast_targets', $modal_atts), __('Targets', 'wp-ultimo'), $product_count, __('Targets', 'wp-ultimo'));
|
||||
|
||||
$html .= '</div>';
|
||||
|
||||
return $html;
|
||||
|
||||
} // end if;
|
||||
|
||||
$modal_atts = array(
|
||||
'action' => 'wu_modal_targets_display',
|
||||
'object_id' => $item->get_id(),
|
||||
'width' => '400',
|
||||
'height' => '360',
|
||||
'target_type' => 'products',
|
||||
);
|
||||
|
||||
$html .= sprintf('<div class="wu-inline-block wu-ml-4"><a href="%s" title="%s" class="wubox"><span class="wu-pl-2 wu-uppercase wu-text-xs wu-font-bold"> %s %s</span></a></div>', wu_get_form_url('view_broadcast_targets', $modal_atts), __('Targets', 'wp-ultimo'), $product_count, __('Targets', 'wp-ultimo'));
|
||||
|
||||
$html .= '</div>';
|
||||
|
||||
return $html;
|
||||
|
||||
} // end column_target_products;
|
||||
|
||||
/**
|
||||
* Returns the list of columns for this particular List Table.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return array
|
||||
*/
|
||||
public function get_columns() {
|
||||
|
||||
$columns = array(
|
||||
'cb' => '<input type="checkbox" />',
|
||||
'type' => __('Type', 'wp-ultimo'),
|
||||
'the_content' => __('Content', 'wp-ultimo'),
|
||||
'target_customers' => __('Target Customers', 'wp-ultimo'),
|
||||
'target_products' => __('Target Products', 'wp-ultimo'),
|
||||
'date_created' => __('Date', 'wp-ultimo'),
|
||||
'id' => __('ID', 'wp-ultimo'),
|
||||
);
|
||||
|
||||
return $columns;
|
||||
|
||||
} // end get_columns;
|
||||
/**
|
||||
* Returns the filters for this page.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function get_filters(): array {
|
||||
|
||||
return array(
|
||||
'filters' => array(
|
||||
'type' => array(
|
||||
'label' => __('Broadcast Type', 'wp-ultimo'),
|
||||
'options' => array(
|
||||
'broadcast_notice' => __('Email', 'wp-ultimo'),
|
||||
'broadcast_email' => __('Notices', 'wp-ultimo'),
|
||||
),
|
||||
),
|
||||
'status' => array(
|
||||
'label' => __('Notice Type', 'wp-ultimo'),
|
||||
'options' => array(
|
||||
'info' => __('Info - Blue', 'wp-ultimo'),
|
||||
'success' => __('Success - Green', 'wp-ultimo'),
|
||||
'warning' => __('Warning - Yellow', 'wp-ultimo'),
|
||||
'error' => __('Error - Red', 'wp-ultimo'),
|
||||
),
|
||||
),
|
||||
),
|
||||
'date_filters' => array(
|
||||
'date_created' => array(
|
||||
'label' => __('Date', 'wp-ultimo'),
|
||||
'options' => $this->get_default_date_filter_options(),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
} // end get_filters;
|
||||
|
||||
/**
|
||||
* Registers the necessary scripts and styles for this admin page.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
public function register_scripts() {
|
||||
|
||||
parent::register_scripts();
|
||||
|
||||
} // end register_scripts;
|
||||
|
||||
/**
|
||||
* Returns the pre-selected filters on the filter bar.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return array
|
||||
*/
|
||||
public function get_views() {
|
||||
|
||||
return array(
|
||||
'all' => array(
|
||||
'field' => 'status',
|
||||
'url' => add_query_arg('type', 'all'),
|
||||
'label' => __('All Broadcasts', 'wp-ultimo'),
|
||||
'count' => 0,
|
||||
),
|
||||
'broadcast_email' => array(
|
||||
'field' => 'type',
|
||||
'url' => add_query_arg('type', 'broadcast_email'),
|
||||
'label' => __('Emails', 'wp-ultimo'),
|
||||
'count' => 0,
|
||||
),
|
||||
'broadcast_notice' => array(
|
||||
'field' => 'type',
|
||||
'url' => add_query_arg('type', 'broadcast_notice'),
|
||||
'label' => __('Notices', 'wp-ultimo'),
|
||||
'count' => 0,
|
||||
),
|
||||
);
|
||||
|
||||
} // end get_views;
|
||||
|
||||
} // end class Broadcast_List_Table;
|
211
inc/list-tables/class-checkout-form-list-table.php
Normal file
211
inc/list-tables/class-checkout-form-list-table.php
Normal file
@ -0,0 +1,211 @@
|
||||
<?php
|
||||
/**
|
||||
* Checkout_Form List Table class.
|
||||
*
|
||||
* @package WP_Ultimo
|
||||
* @subpackage List_Table
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\List_Tables;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* Checkout_Form List Table class.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
class Checkout_Form_List_Table extends Base_List_Table {
|
||||
|
||||
/**
|
||||
* Holds the query class for the object being listed.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var string
|
||||
*/
|
||||
protected $query_class = '\\WP_Ultimo\\Database\\Checkout_Forms\\Checkout_Form_Query';
|
||||
|
||||
/**
|
||||
* Initializes the table.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
parent::__construct(array(
|
||||
'singular' => __('Checkout Form', 'wp-ultimo'), // singular name of the listed records
|
||||
'plural' => __('Checkout Forms', 'wp-ultimo'), // plural name of the listed records
|
||||
'ajax' => true, // does this table support ajax?
|
||||
'add_new' => array(
|
||||
'url' => wu_get_form_url('add_new_checkout_form'),
|
||||
'classes' => 'wubox',
|
||||
),
|
||||
));
|
||||
|
||||
} // end __construct;
|
||||
/**
|
||||
* Displays the content of the product column.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param WP_Ultimo\Models\Checkout_Form $item Checkout Form object.
|
||||
*/
|
||||
public function column_name($item): string {
|
||||
|
||||
$url_atts = array(
|
||||
'id' => $item->get_id(),
|
||||
'slug' => $item->get_slug(),
|
||||
'model' => 'checkout_form',
|
||||
);
|
||||
|
||||
$title = sprintf('<strong><a href="%s">%s</a></strong>', wu_network_admin_url('wp-ultimo-edit-checkout-form', $url_atts), $item->get_name());
|
||||
|
||||
$actions = array(
|
||||
'edit' => sprintf('<a href="%s">%s</a>', wu_network_admin_url('wp-ultimo-edit-checkout-form', $url_atts), __('Edit', 'wp-ultimo')),
|
||||
'duplicate' => sprintf('<a href="%s">%s</a>', wu_network_admin_url('wp-ultimo-checkout-forms', array('action' => 'duplicate', 'id' => $item->get_id())), __('Duplicate', 'wp-ultimo')),
|
||||
'get_shortcode' => sprintf('<a title="%s" class="wubox" href="%s">%s</a>', __('Shortcode', 'wp-ultimo'), wu_get_form_url('shortcode_checkout', $url_atts), __('Shortcode', 'wp-ultimo')),
|
||||
'delete' => sprintf('<a title="%s" class="wubox" href="%s">%s</a>', __('Delete', 'wp-ultimo'), wu_get_form_url('delete_modal', $url_atts), __('Delete', 'wp-ultimo')),
|
||||
);
|
||||
|
||||
return $title . $this->row_actions($actions);
|
||||
|
||||
} // end column_name;
|
||||
|
||||
/**
|
||||
* Displays the slug of the form.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param WP_Ultimo\Models\Checkout_Form $item Checkout Form object.
|
||||
* @return string
|
||||
*/
|
||||
public function column_slug($item) {
|
||||
|
||||
$slug = $item->get_slug();
|
||||
|
||||
return "<span class='wu-bg-gray-200 wu-text-gray-700 wu-py-1 wu-px-2 wu-rounded-sm wu-text-xs wu-font-mono'>{$slug}</span>";
|
||||
|
||||
} // end column_slug;
|
||||
/**
|
||||
* Displays the number pof steps and fields.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param WP_Ultimo\Models\Checkout_Form $item Checkout Form object.
|
||||
*/
|
||||
public function column_steps($item): string {
|
||||
|
||||
return sprintf(__('%1$d Step(s) and %2$d Field(s)', 'wp-ultimo'), $item->get_step_count(), $item->get_field_count());
|
||||
|
||||
} // end column_steps;
|
||||
/**
|
||||
* Displays the form shortcode.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param WP_Ultimo\Models\Checkout_Form $item Checkout Form object.
|
||||
*/
|
||||
public function column_shortcode($item): string {
|
||||
|
||||
$button = sprintf('
|
||||
<button type="button" data-clipboard-action="copy" data-clipboard-target="#hidden_textarea" class="btn-clipboard" title="%s">
|
||||
<span class="dashicons-wu-copy"></span>
|
||||
</button>', __('Copy to the Clipboard', 'wp-ultimo'));
|
||||
|
||||
return sprintf('<input class="wu-bg-gray-200 wu-border-none wu-text-gray-700 wu-py-1 wu-px-2 wu-rounded-sm wu-text-xs wu-font-mono" value="%s">', esc_attr($item->get_shortcode()), '');
|
||||
|
||||
} // end column_shortcode;
|
||||
|
||||
/**
|
||||
* Handles the bulk processing adding duplication
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
public function process_single_action() {
|
||||
|
||||
$bulk_action = $this->current_action();
|
||||
|
||||
if ($bulk_action === 'duplicate') {
|
||||
|
||||
$checkout_form_id = wu_request('id');
|
||||
|
||||
$checkout_form = wu_get_checkout_form($checkout_form_id);
|
||||
|
||||
if (!$checkout_form) {
|
||||
|
||||
WP_Ultimo()->notices->add(__('Checkout form not found.', 'wp-ultimo'), 'error', 'network-admin');
|
||||
|
||||
return;
|
||||
|
||||
} // end if;
|
||||
|
||||
$new_checkout_form = $checkout_form->duplicate();
|
||||
|
||||
$new_name = sprintf(__('Copy of %s', 'wp-ultimo'), $checkout_form->get_name());
|
||||
|
||||
$new_checkout_form->set_name($new_name);
|
||||
|
||||
$new_checkout_form->set_slug(sanitize_title($new_name));
|
||||
|
||||
$new_checkout_form->set_date_created(wu_get_current_time('mysql', true));
|
||||
|
||||
$result = $new_checkout_form->save();
|
||||
|
||||
if (is_wp_error($result)) {
|
||||
|
||||
WP_Ultimo()->notices->add($result->get_error_message(), 'error', 'network-admin');
|
||||
|
||||
return;
|
||||
|
||||
} // end if;
|
||||
|
||||
$redirect_url = wu_network_admin_url('wp-ultimo-edit-checkout-form', array(
|
||||
'id' => $new_checkout_form->get_id(),
|
||||
'updated' => 1,
|
||||
));
|
||||
|
||||
wp_redirect($redirect_url);
|
||||
|
||||
exit;
|
||||
|
||||
} // end if;
|
||||
|
||||
} // end process_single_action;
|
||||
|
||||
/**
|
||||
* Returns the list of columns for this particular List Table.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return array
|
||||
*/
|
||||
public function get_columns() {
|
||||
|
||||
$columns = array(
|
||||
'cb' => '<input type="checkbox" />',
|
||||
'name' => __('Form Name', 'wp-ultimo'),
|
||||
'slug' => __('Form Slug', 'wp-ultimo'),
|
||||
'steps' => __('Steps', 'wp-ultimo'),
|
||||
'id' => __('ID', 'wp-ultimo'),
|
||||
);
|
||||
|
||||
return $columns;
|
||||
|
||||
} // end get_columns;
|
||||
/**
|
||||
* Returns the filters for this page.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function get_filters(): array {
|
||||
|
||||
return array(
|
||||
'filters' => array(),
|
||||
'date_filters' => array(),
|
||||
);
|
||||
|
||||
} // end get_filters;
|
||||
|
||||
} // end class Checkout_Form_List_Table;
|
366
inc/list-tables/class-customer-list-table.php
Normal file
366
inc/list-tables/class-customer-list-table.php
Normal file
@ -0,0 +1,366 @@
|
||||
<?php
|
||||
/**
|
||||
* Customer List Table class.
|
||||
*
|
||||
* @package WP_Ultimo
|
||||
* @subpackage List_Table
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\List_Tables;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* Customer List Table class.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
class Customer_List_Table extends Base_List_Table {
|
||||
|
||||
/**
|
||||
* Holds the query class for the object being listed.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var string
|
||||
*/
|
||||
protected $query_class = '\\WP_Ultimo\\Database\\Customers\\Customer_Query';
|
||||
|
||||
/**
|
||||
* Initializes the table.
|
||||
*
|
||||
* @param array $args Table attributes.
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function __construct($args = array()) {
|
||||
|
||||
$this->modes = array(
|
||||
'grid' => __('Grid View'),
|
||||
'list' => __('List View'),
|
||||
);
|
||||
|
||||
$args = wp_parse_args($args, array(
|
||||
'singular' => __('Customer', 'wp-ultimo'), // singular name of the listed records
|
||||
'plural' => __('Customers', 'wp-ultimo'), // plural name of the listed records
|
||||
'ajax' => true, // does this table support ajax?
|
||||
'add_new' => array(
|
||||
'url' => wu_get_form_url('add_new_customer'),
|
||||
'classes' => 'wubox',
|
||||
),
|
||||
));
|
||||
|
||||
parent::__construct($args);
|
||||
|
||||
} // end __construct;
|
||||
|
||||
/**
|
||||
* Adds the extra search field when the search element is present.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return array
|
||||
*/
|
||||
public function get_extra_query_fields() {
|
||||
|
||||
$_filter_fields = parent::get_extra_query_fields();
|
||||
|
||||
$search = isset($_GET['s']) ? sanitize_text_field($_GET['s']) : false;
|
||||
|
||||
if (!empty($search)) {
|
||||
|
||||
// Search relevant users
|
||||
$user_ids = get_users(array(
|
||||
'number' => -1,
|
||||
'search' => '*' . $search . '*',
|
||||
'fields' => 'ids',
|
||||
));
|
||||
|
||||
// No results, go back
|
||||
if (empty($user_ids)) {
|
||||
|
||||
return $_filter_fields;
|
||||
|
||||
} // end if;
|
||||
|
||||
// Finally, include these user IDs in the customers query.
|
||||
$_filter_fields['user_id__in'] = $user_ids;
|
||||
|
||||
unset($_filter_fields['search']);
|
||||
|
||||
} // end if;
|
||||
|
||||
$_filter_fields['type'] = 'customer';
|
||||
|
||||
if (wu_request('filter', 'all') === 'vip') {
|
||||
|
||||
$_filter_fields['vip'] = 1;
|
||||
|
||||
} elseif (wu_request('filter', 'all') === 'online') {
|
||||
|
||||
$_filter_fields['last_login_query'] = array(
|
||||
'after' => '-3 minutes',
|
||||
);
|
||||
|
||||
} // end if;
|
||||
|
||||
return $_filter_fields;
|
||||
|
||||
} // end get_extra_query_fields;
|
||||
/**
|
||||
* Displays the content of the name column.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param WP_Ultimo\Models\Customer $item Customer object.
|
||||
*/
|
||||
public function column_name($item): string {
|
||||
|
||||
// Get user info
|
||||
$user = get_user_by('id', $item->get_user_id());
|
||||
|
||||
$url_atts = array(
|
||||
'id' => $item->get_id(),
|
||||
);
|
||||
|
||||
// Check if user exists
|
||||
if (!$user) {
|
||||
|
||||
$actions = array(
|
||||
'delete' => sprintf('<a title="%s" class="wubox" href="%s">%s</a>', __('Delete', 'wp-ultimo'), wu_get_form_url('delete_modal', $url_atts), __('Delete', 'wp-ultimo')),
|
||||
);
|
||||
|
||||
return sprintf('<strong>#%s</strong> - %s', $item->get_user_id(), __('User not found', 'wp-ultimo')) . $this->row_actions($actions);
|
||||
|
||||
} // end if;
|
||||
|
||||
$customer_id = sprintf('<a href="?page=wp-ultimo-edit-customer&id=%s"><strong>#%s</strong></a>', $item->get_id(), $item->get_id());
|
||||
|
||||
$customer_user = sprintf('<a href="%s">%s</a>', wu_network_admin_url('wp-ultimo-edit-customer', array(
|
||||
'id' => $item->get_id(),
|
||||
)), $user->display_name);
|
||||
|
||||
// Concatenate the two blocks
|
||||
$title = "<strong>$customer_user</strong>";
|
||||
|
||||
$desc = sprintf('<a %s href="mailto:%s" class="description wu-ml-1 wu-text-xs">(%s)</a>', wu_tooltip_text(__('Send an email to this customer', 'wp-ultimo')), $user->user_email, $user->user_email);
|
||||
|
||||
// Concatenate switch to url
|
||||
$is_modal_switch_to = \WP_Ultimo\User_Switching::get_instance()->check_user_switching_is_activated() ? '' : 'wubox';
|
||||
|
||||
$url_switch_to = sprintf('<a title="%s" class="%s" href="%s">%s</a>', __('Switch To', 'wp-ultimo'), $is_modal_switch_to, \WP_Ultimo\User_Switching::get_instance()->render($item->get_user_id()), __('Switch To', 'wp-ultimo'));
|
||||
|
||||
$actions = array(
|
||||
'edit' => sprintf('<a href="%s">%s</a>', wu_network_admin_url('wp-ultimo-edit-customer', $url_atts), __('Edit', 'wp-ultimo')),
|
||||
'switch-to' => $item->get_user_id() !== get_current_user_id() ? $url_switch_to : false,
|
||||
'delete' => sprintf(
|
||||
'<a title="%s" class="wubox" href="%s">%s</a>',
|
||||
__('Delete', 'wp-ultimo'),
|
||||
wu_get_form_url(
|
||||
'delete_modal',
|
||||
array(
|
||||
'model' => 'customer',
|
||||
'id' => $item->get_id()
|
||||
)
|
||||
),
|
||||
__('Delete', 'wp-ultimo')
|
||||
),
|
||||
);
|
||||
|
||||
$actions = array_filter($actions);
|
||||
|
||||
return $title . $desc . $this->row_actions($actions);
|
||||
|
||||
} // end column_name;
|
||||
|
||||
/**
|
||||
* Displays the customer photo and special status.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param WP_Ultimo\Models\Customer $item Customer object.
|
||||
* @return string
|
||||
*/
|
||||
public function column_customer_status($item) {
|
||||
|
||||
$html = '<div class="wu-status-container">';
|
||||
|
||||
if ($item->is_vip()) {
|
||||
|
||||
$html .= sprintf('<span class="wu-tag wu-customer-vip">%s</span>', __('VIP', 'wp-ultimo'));
|
||||
|
||||
} // end if;
|
||||
|
||||
$html .= get_avatar($item->get_user_id(), 36, 'identicon', '', array(
|
||||
'force_display' => true,
|
||||
));
|
||||
|
||||
$html .= '</div>';
|
||||
|
||||
return $html;
|
||||
|
||||
} // end column_customer_status;
|
||||
/**
|
||||
* Returns the number of memberships owned by this customer.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @todo: Make this works.
|
||||
* @param WP_Ultimo\Models\Customer $item Customer object.
|
||||
*/
|
||||
public function column_memberships($item): string {
|
||||
|
||||
$subscription_count = count($item->get_memberships());
|
||||
|
||||
$url_atts = array(
|
||||
'customer_id' => $item->get_id(),
|
||||
);
|
||||
|
||||
$actions = array(
|
||||
'view' => sprintf('<a href="%s">%s</a>', wu_network_admin_url('wp-ultimo-memberships', $url_atts), __('View', 'wp-ultimo')),
|
||||
);
|
||||
|
||||
return $subscription_count . $this->row_actions($actions);
|
||||
|
||||
} // end column_memberships;
|
||||
|
||||
/**
|
||||
* Returns the list of columns for this particular List Table.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return array
|
||||
*/
|
||||
public function get_columns() {
|
||||
|
||||
$columns = array(
|
||||
'cb' => '<input type="checkbox" />',
|
||||
'customer_status' => '',
|
||||
'name' => __('Name', 'wp-ultimo'),
|
||||
'last_login' => __('Last Login', 'wp-ultimo'),
|
||||
'date_registered' => __('Customer Since', 'wp-ultimo'),
|
||||
'memberships' => __('Memberships', 'wp-ultimo'),
|
||||
'id' => __('ID', 'wp-ultimo'),
|
||||
);
|
||||
|
||||
return $columns;
|
||||
|
||||
} // end get_columns;
|
||||
|
||||
/**
|
||||
* Handles the item display for grid mode.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param WP_Ultimo\Models\Customer $item The line item being displayed.
|
||||
* @return void
|
||||
*/
|
||||
public function single_row_grid($item) {
|
||||
|
||||
wu_get_template('base/customers/grid-item', array(
|
||||
'item' => $item,
|
||||
'table' => $this,
|
||||
));
|
||||
|
||||
} // end single_row_grid;
|
||||
|
||||
/**
|
||||
* Returns the filters for this page.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function get_filters(): array {
|
||||
|
||||
$filters = $this->get_schema_columns(array(
|
||||
'searchable' => true,
|
||||
'date_query' => true,
|
||||
), 'or');
|
||||
|
||||
$labels = $this->get_columns();
|
||||
|
||||
$filters = array_map(function($item) use ($labels) {
|
||||
|
||||
$label = wu_get_isset($labels, $item->name);
|
||||
$label = $label ? sprintf('%s (%s)', $item->label, $item->name) : $item->name;
|
||||
|
||||
$filter_type = 'text';
|
||||
$rule = 'is';
|
||||
|
||||
if ($item->date_query === true) {
|
||||
|
||||
$filter_type = 'date';
|
||||
$rule = 'is_after';
|
||||
|
||||
} elseif (in_array(strtolower((string) $item->name), array('smallint'), true)) {
|
||||
|
||||
$filter_type = 'bool';
|
||||
$rule = 'is_true';
|
||||
|
||||
} // end if;
|
||||
|
||||
return array(
|
||||
'field' => $item->name,
|
||||
'label' => $label,
|
||||
'type' => $filter_type,
|
||||
'rule' => $rule,
|
||||
'value' => wu_request($item->name, ''),
|
||||
);
|
||||
|
||||
}, $filters);
|
||||
|
||||
return array_values($filters);
|
||||
|
||||
} // end get_filters;
|
||||
|
||||
/**
|
||||
* Returns the pre-selected filters on the filter bar.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return array
|
||||
*/
|
||||
public function get_views() {
|
||||
|
||||
return array(
|
||||
'all' => array(
|
||||
'field' => 'filter',
|
||||
'url' => add_query_arg(array(
|
||||
'filter' => 'all'
|
||||
)),
|
||||
'label' => __('All Customers', 'wp-ultimo'),
|
||||
'count' => 0,
|
||||
),
|
||||
'vip' => array(
|
||||
'field' => 'filter',
|
||||
'url' => add_query_arg('filter', 'vip'),
|
||||
'label' => __('VIP Customers', 'wp-ultimo'),
|
||||
'count' => 0,
|
||||
),
|
||||
'online' => array(
|
||||
'field' => 'filter',
|
||||
'url' => add_query_arg('filter', 'online'),
|
||||
'label' => __('Online Customers', 'wp-ultimo'),
|
||||
'count' => 0,
|
||||
),
|
||||
);
|
||||
|
||||
} // end get_views;
|
||||
|
||||
/**
|
||||
* Displays the last login.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param WP_Ultimo\Models\Customer $item Customer object.
|
||||
* @return string The last login information.
|
||||
*/
|
||||
public function column_last_login($item) {
|
||||
|
||||
if ($item->is_online()) {
|
||||
|
||||
return '<span class="wu-inline-block wu-mr-1 wu-rounded-full wu-h-2 wu-w-2 wu-bg-green-500"></span>' . __('Online', 'wp-ultimo');
|
||||
|
||||
} // end if;
|
||||
|
||||
return $this->_column_datetime($item->get_last_login());
|
||||
|
||||
} // end column_last_login;
|
||||
|
||||
} // end class Customer_List_Table;
|
95
inc/list-tables/class-customers-membership-list-table.php
Normal file
95
inc/list-tables/class-customers-membership-list-table.php
Normal file
@ -0,0 +1,95 @@
|
||||
<?php
|
||||
/**
|
||||
* Customers' Membership List Table class.
|
||||
*
|
||||
* @package WP_Ultimo
|
||||
* @subpackage List_Table
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\List_Tables;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* Membership List Table class.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
class Customers_Membership_List_Table extends Membership_List_Table {
|
||||
|
||||
/**
|
||||
* Returns the list of columns for this particular List Table.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return array
|
||||
*/
|
||||
public function get_columns() {
|
||||
|
||||
$columns = array(
|
||||
'responsive' => '',
|
||||
);
|
||||
|
||||
return $columns;
|
||||
|
||||
} // end get_columns;
|
||||
|
||||
/**
|
||||
* Renders the inside column responsive.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param object $item The item being rendered.
|
||||
* @return void
|
||||
*/
|
||||
public function column_responsive($item) {
|
||||
|
||||
$p = $item->get_plan();
|
||||
|
||||
$expired = strtotime((string) $item->get_date_expiration()) <= time();
|
||||
|
||||
$product_count = 1 + count($item->get_addon_ids());
|
||||
|
||||
$products_list = $p ? sprintf(_n('Contains %s', 'Contains %1$s and %2$s other product(s)', $product_count, 'wp-ultimo'), $p->get_name(), count($item->get_addon_ids())) : ''; // phpcs:ignore
|
||||
|
||||
echo wu_responsive_table_row(array(
|
||||
'id' => $item->get_id(),
|
||||
'title' => $item->get_hash(),
|
||||
'url' => wu_network_admin_url('wp-ultimo-edit-membership', array(
|
||||
'id' => $item->get_id(),
|
||||
)),
|
||||
'status' => $this->column_status($item),
|
||||
), array(
|
||||
'total' => array(
|
||||
'icon' => 'dashicons-wu-shopping-bag1 wu-align-middle wu-mr-1',
|
||||
'label' => __('Payment Total', 'wp-ultimo'),
|
||||
'value' => $item->get_price_description(),
|
||||
),
|
||||
'products' => array(
|
||||
'icon' => 'dashicons-wu-package wu-align-middle wu-mr-1',
|
||||
'label' => __('Products', 'wp-ultimo'),
|
||||
'value' => $products_list,
|
||||
),
|
||||
'gateway' => array(
|
||||
'icon' => 'dashicons-wu-credit-card2 wu-align-middle wu-mr-1',
|
||||
'label' => __('Gateway', 'wp-ultimo'),
|
||||
'value' => wu_slug_to_name($item->get_gateway()),
|
||||
),
|
||||
),
|
||||
array(
|
||||
'date_expiration' => array(
|
||||
'icon' => 'dashicons-wu-calendar1 wu-align-middle wu-mr-1',
|
||||
'label' => __('Expires', 'wp-ultimo'),
|
||||
'value' => sprintf($expired ? __('Expired %s', 'wp-ultimo') : __('Expiring %s', 'wp-ultimo'), wu_human_time_diff(strtotime((string) $item->get_date_expiration()))),
|
||||
),
|
||||
'date_created' => array(
|
||||
'icon' => 'dashicons-wu-calendar1 wu-align-middle wu-mr-1',
|
||||
'label' => __('Created at', 'wp-ultimo'),
|
||||
'value' => sprintf(__('Created %s', 'wp-ultimo'), wu_human_time_diff(strtotime((string) $item->get_date_created()))),
|
||||
),
|
||||
));
|
||||
|
||||
} // end column_responsive;
|
||||
|
||||
} // end class Customers_Membership_List_Table;
|
77
inc/list-tables/class-customers-payment-list-table.php
Normal file
77
inc/list-tables/class-customers-payment-list-table.php
Normal file
@ -0,0 +1,77 @@
|
||||
<?php
|
||||
/**
|
||||
* Customers Payment List Table class.
|
||||
*
|
||||
* @package WP_Ultimo
|
||||
* @subpackage List_Table
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\List_Tables;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* Payment List Table class.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
class Customers_Payment_List_Table extends Payment_List_Table {
|
||||
|
||||
/**
|
||||
* Returns the list of columns for this particular List Table.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return array
|
||||
*/
|
||||
public function get_columns() {
|
||||
|
||||
$columns = array(
|
||||
'responsive' => '',
|
||||
);
|
||||
|
||||
return $columns;
|
||||
|
||||
} // end get_columns;
|
||||
|
||||
/**
|
||||
* Renders the inside column responsive.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param object $item The item being rendered.
|
||||
* @return void
|
||||
*/
|
||||
public function column_responsive($item) {
|
||||
|
||||
echo wu_responsive_table_row(array(
|
||||
'id' => $item->get_id(),
|
||||
'title' => $item->get_hash(),
|
||||
'url' => wu_network_admin_url('wp-ultimo-edit-payment', array(
|
||||
'id' => $item->get_id(),
|
||||
)),
|
||||
'status' => $this->column_status($item),
|
||||
), array(
|
||||
'total' => array(
|
||||
'icon' => 'dashicons-wu-shopping-bag1 wu-align-middle wu-mr-1',
|
||||
'label' => __('Payment Total', 'wp-ultimo'),
|
||||
'value' => wu_format_currency($item->get_total()),
|
||||
),
|
||||
'gateway' => array(
|
||||
'icon' => 'dashicons-wu-credit-card2 wu-align-middle wu-mr-1',
|
||||
'label' => __('Gateway', 'wp-ultimo'),
|
||||
'value' => wu_slug_to_name($item->get_gateway()),
|
||||
),
|
||||
),
|
||||
array(
|
||||
'date_created' => array(
|
||||
'icon' => 'dashicons-wu-calendar1 wu-align-middle wu-mr-1',
|
||||
'label' => '',
|
||||
'value' => sprintf(__('Created %s', 'wp-ultimo'), wu_human_time_diff(strtotime((string) $item->get_date_created()))),
|
||||
),
|
||||
));
|
||||
|
||||
} // end column_responsive;
|
||||
|
||||
} // end class Customers_Payment_List_Table;
|
162
inc/list-tables/class-customers-site-list-table.php
Normal file
162
inc/list-tables/class-customers-site-list-table.php
Normal file
@ -0,0 +1,162 @@
|
||||
<?php
|
||||
/**
|
||||
* Customers Site List Table class.
|
||||
*
|
||||
* @package WP_Ultimo
|
||||
* @subpackage List_Table
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\List_Tables;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* Site List Table class.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
class Customers_Site_List_Table extends Site_List_Table {
|
||||
|
||||
/**
|
||||
* Initializes the table.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
parent::__construct();
|
||||
|
||||
$this->current_mode = 'list';
|
||||
|
||||
} // end __construct;
|
||||
|
||||
/**
|
||||
* Returns the list of columns for this particular List Table.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return array
|
||||
*/
|
||||
public function get_columns() {
|
||||
|
||||
$columns = array(
|
||||
'responsive' => '',
|
||||
);
|
||||
|
||||
return $columns;
|
||||
|
||||
} // end get_columns;
|
||||
|
||||
/**
|
||||
* Renders the inside column responsive.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param object $item The item being rendered.
|
||||
* @return void
|
||||
*/
|
||||
public function column_responsive($item) {
|
||||
|
||||
$m = $item->get_membership();
|
||||
|
||||
$redirect = current_user_can('wu_edit_sites') ? 'wp-ultimo-edit-site' : 'wp-ultimo-sites';
|
||||
|
||||
echo wu_responsive_table_row(array(
|
||||
'id' => $item->get_id(),
|
||||
'title' => $item->get_title(),
|
||||
'url' => wu_network_admin_url($redirect, array(
|
||||
'id' => $item->get_id(),
|
||||
)),
|
||||
'image' => $this->column_featured_image_id($item),
|
||||
'status' => $this->column_type($item),
|
||||
), array(
|
||||
'link' => array(
|
||||
'icon' => 'dashicons-wu-link1 wu-align-middle wu-mr-1',
|
||||
'label' => __('Visit Site', 'wp-ultimo'),
|
||||
'url' => $item->get_active_site_url(),
|
||||
'value' => $item->get_active_site_url(),
|
||||
),
|
||||
'dashboard' => array(
|
||||
'icon' => 'dashicons-wu-browser wu-align-middle wu-mr-1',
|
||||
'label' => __('Go to the Dashboard', 'wp-ultimo'),
|
||||
'value' => __('Dashboard', 'wp-ultimo'),
|
||||
'url' => get_admin_url($item->get_id()),
|
||||
),
|
||||
'membership' => array(
|
||||
'icon' => 'dashicons-wu-rotate-ccw wu-align-middle wu-mr-1',
|
||||
'label' => __('Go to the Membership', 'wp-ultimo'),
|
||||
'value' => $m ? $m->get_hash() : '',
|
||||
'url' => $m ? wu_network_admin_url('wp-ultimo-edit-membership', array(
|
||||
'id' => $m->get_id(),
|
||||
)) : '',
|
||||
),
|
||||
),
|
||||
array(
|
||||
'date_created' => array(
|
||||
'icon' => 'dashicons-wu-calendar1 wu-align-middle wu-mr-1',
|
||||
'label' => '',
|
||||
/* translators: the placeholder is a date */
|
||||
'value' => $item->get_type() === 'pending' ? __('Not Available', 'wp-ultimo') : sprintf(__('Created %s', 'wp-ultimo'), wu_human_time_diff(strtotime((string) $item->get_date_registered()))),
|
||||
),
|
||||
));
|
||||
|
||||
} // end column_responsive;
|
||||
|
||||
/**
|
||||
* Overrides the parent method to add pending sites.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param integer $per_page Number of items to display per page.
|
||||
* @param integer $page_number Current page.
|
||||
* @param boolean $count If we should count records or return the actual records.
|
||||
* @return array
|
||||
*/
|
||||
public function get_items($per_page = 5, $page_number = 1, $count = false) {
|
||||
|
||||
$sites = parent::get_items($per_page, $page_number, $count);
|
||||
|
||||
if ($count) {
|
||||
|
||||
return $sites;
|
||||
|
||||
} // end if;
|
||||
|
||||
$pending_sites = array();
|
||||
|
||||
$page = wu_request('page');
|
||||
|
||||
$id = wu_request('id');
|
||||
|
||||
if (!$id) {
|
||||
|
||||
return $sites;
|
||||
|
||||
} // end if;
|
||||
|
||||
switch ($page) {
|
||||
|
||||
case 'wp-ultimo-edit-membership':
|
||||
$membership = wu_get_membership($id);
|
||||
$pending_sites = $membership && $membership->get_pending_site() ? array($membership->get_pending_site()) : array();
|
||||
break;
|
||||
case 'wp-ultimo-edit-customer':
|
||||
$customer = wu_get_customer($id);
|
||||
$pending_sites = $customer ? $customer->get_pending_sites() : array();
|
||||
break;
|
||||
|
||||
} // end switch;
|
||||
|
||||
foreach ($pending_sites as &$site) {
|
||||
|
||||
$site->set_type('pending');
|
||||
$site->set_blog_id('--');
|
||||
|
||||
} // end foreach;
|
||||
|
||||
return array_merge($pending_sites, $sites);
|
||||
|
||||
} // end get_items;
|
||||
|
||||
} // end class Customers_Site_List_Table;
|
230
inc/list-tables/class-discount-code-list-table.php
Normal file
230
inc/list-tables/class-discount-code-list-table.php
Normal file
@ -0,0 +1,230 @@
|
||||
<?php
|
||||
/**
|
||||
* Discount_Code List Table class.
|
||||
*
|
||||
* @package WP_Ultimo
|
||||
* @subpackage List_Table
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\List_Tables;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* Discount_Code List Table class.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
class Discount_Code_List_Table extends Base_List_Table {
|
||||
|
||||
/**
|
||||
* Holds the query class for the object being listed.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var string
|
||||
*/
|
||||
protected $query_class = '\\WP_Ultimo\\Database\\Discount_Codes\\Discount_Code_Query';
|
||||
|
||||
/**
|
||||
* Initializes the table.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
parent::__construct(array(
|
||||
'singular' => __('Discount Code', 'wp-ultimo'), // singular name of the listed records
|
||||
'plural' => __('Discount Codes', 'wp-ultimo'), // plural name of the listed records
|
||||
'ajax' => true, // does this table support ajax?
|
||||
'add_new' => array(
|
||||
'url' => wu_network_admin_url('wp-ultimo-edit-discount-code'),
|
||||
'classes' => '',
|
||||
),
|
||||
));
|
||||
|
||||
} // end __construct;
|
||||
/**
|
||||
* Displays the content of the name column.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param WP_Ultimo\Models\Discount_Code $item Discount_Code object.
|
||||
*/
|
||||
public function column_name($item): string {
|
||||
|
||||
$url_atts = array(
|
||||
'id' => $item->get_id(),
|
||||
'model' => 'discount_code',
|
||||
);
|
||||
|
||||
$title = sprintf('<a href="%s"><strong>%s</strong></a>', wu_network_admin_url('wp-ultimo-edit-discount-code', $url_atts), $item->get_name());
|
||||
|
||||
$actions = array(
|
||||
'edit' => sprintf('<a href="%s">%s</a>', wu_network_admin_url('wp-ultimo-edit-discount-code', $url_atts), __('Edit', 'wp-ultimo')),
|
||||
'delete' => sprintf(
|
||||
'<a title="%s" class="wubox" href="%s">%s</a>',
|
||||
__('Delete', 'wp-ultimo'),
|
||||
wu_get_form_url(
|
||||
'delete_modal',
|
||||
$url_atts
|
||||
),
|
||||
__('Delete', 'wp-ultimo')
|
||||
),
|
||||
);
|
||||
|
||||
return $title . $this->row_actions($actions);
|
||||
|
||||
} // end column_name;
|
||||
|
||||
/**
|
||||
* Displays the content of the value column.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param WP_Ultimo\Models\Discount_Code $item Discount_Code object.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function column_value($item) {
|
||||
|
||||
if (!$item->get_value()) {
|
||||
|
||||
return __('No Discount', 'wp-ultimo');
|
||||
|
||||
} // end if;
|
||||
|
||||
$value = wu_format_currency($item->get_value());
|
||||
|
||||
if ($item->get_type() === 'percentage') {
|
||||
|
||||
$value = number_format($item->get_value(), 0) . '%';
|
||||
|
||||
} // end if;
|
||||
|
||||
// translators: placeholder is the amount of discount. e.g. 10% or $5.
|
||||
return sprintf(__('%s OFF', 'wp-ultimo'), $value);
|
||||
|
||||
} // end column_value;
|
||||
|
||||
/**
|
||||
* Displays the content of the setup fee value column.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param WP_Ultimo\Models\Discount_Code $item Discount_Code object.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function column_setup_fee_value($item) {
|
||||
|
||||
if (!$item->get_setup_fee_value()) {
|
||||
|
||||
return __('No Discount', 'wp-ultimo');
|
||||
|
||||
} // end if;
|
||||
|
||||
$value = wu_format_currency($item->get_setup_fee_value());
|
||||
|
||||
if ($item->get_setup_fee_type() === 'percentage') {
|
||||
|
||||
$value = number_format($item->get_setup_fee_value()) . '%';
|
||||
|
||||
} // end if;
|
||||
|
||||
// translators: placeholder is the amount of discount. e.g. 10% or $5.
|
||||
return sprintf(__('%s OFF', 'wp-ultimo'), $value);
|
||||
|
||||
} // end column_setup_fee_value;
|
||||
|
||||
/**
|
||||
* Displays the use limitations.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param WP_Ultimo\Models\Discount_Code $item Discount_Code object.
|
||||
* @return string
|
||||
*/
|
||||
public function column_uses($item) {
|
||||
|
||||
// translators: the placeholder is the number of times this coupon was used.
|
||||
$html = sprintf(__('Used %d time(s)', 'wp-ultimo'), $item->get_uses());
|
||||
|
||||
if ($item->get_max_uses() > 0) {
|
||||
|
||||
// translators: the placeholder is the number of times this coupon can be used before becoming inactive.
|
||||
$html .= '<small class="wu-block">' . sprintf(__('Allowed uses: %d', 'wp-ultimo'), $item->get_max_uses()) . '</span>';
|
||||
|
||||
} else {
|
||||
|
||||
$html .= '<small class="wu-block">' . __('No Limits', 'wp-ultimo') . '</span>';
|
||||
|
||||
} // end if;
|
||||
|
||||
return $html;
|
||||
|
||||
} // end column_uses;
|
||||
|
||||
/**
|
||||
* Shows the code as a tag.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param WP_Ultimo\Models\Discount_Code $item Discount_Code object.
|
||||
* @return string
|
||||
*/
|
||||
public function column_coupon_code($item) {
|
||||
|
||||
$code = $item->get_code();
|
||||
|
||||
$html = '<span class="wu-py-1 wu-px-2 wu-rounded-sm wu-text-xs wu-font-mono wu-bg-gray-200 wu-text-gray-700">' . strtoupper((string) $code) . '</span>';
|
||||
|
||||
$valid = $item->is_valid();
|
||||
|
||||
if (is_wp_error($valid)) {
|
||||
|
||||
$html .= sprintf('<small class="wu-block wu-sans" %s>%s</small>', wu_tooltip_text($valid->get_error_message()), __('Inactive', 'wp-ultimo'));
|
||||
|
||||
} // end if;
|
||||
|
||||
return $html;
|
||||
|
||||
} // end column_coupon_code;
|
||||
|
||||
/**
|
||||
* Returns the list of columns for this particular List Table.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return array
|
||||
*/
|
||||
public function get_columns() {
|
||||
|
||||
$columns = array(
|
||||
'cb' => '<input type="checkbox" />',
|
||||
'name' => __('Name', 'wp-ultimo'),
|
||||
'coupon_code' => __('Code', 'wp-ultimo'),
|
||||
'uses' => __('Uses', 'wp-ultimo'),
|
||||
'value' => __('Value', 'wp-ultimo'),
|
||||
'setup_fee_value' => __('Setup Fee Value', 'wp-ultimo'),
|
||||
'date_expiration' => __('Dates', 'wp-ultimo'),
|
||||
);
|
||||
|
||||
return $columns;
|
||||
|
||||
} // end get_columns;
|
||||
/**
|
||||
* Returns the filters for this page.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function get_filters(): array {
|
||||
|
||||
return array(
|
||||
'filters' => array(),
|
||||
'date_filters' => array(),
|
||||
);
|
||||
|
||||
} // end get_filters;
|
||||
|
||||
} // end class Discount_Code_List_Table;
|
239
inc/list-tables/class-domain-list-table.php
Normal file
239
inc/list-tables/class-domain-list-table.php
Normal file
@ -0,0 +1,239 @@
|
||||
<?php
|
||||
/**
|
||||
* Domain List Table class.
|
||||
*
|
||||
* @package WP_Ultimo
|
||||
* @subpackage List_Table
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\List_Tables;
|
||||
|
||||
use \WP_Ultimo\Models\Domain;
|
||||
use WP_Ultimo\Database\Domains\Domain_Stage;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* Domain List Table class.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
class Domain_List_Table extends Base_List_Table {
|
||||
|
||||
/**
|
||||
* Holds the query class for the object being listed.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var string
|
||||
*/
|
||||
protected $query_class = '\\WP_Ultimo\\Database\\Domains\\Domain_Query';
|
||||
|
||||
/**
|
||||
* Initializes the table.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
parent::__construct(array(
|
||||
'singular' => __('Domain', 'wp-ultimo'), // singular name of the listed records
|
||||
'plural' => __('Domains', 'wp-ultimo'), // plural name of the listed records
|
||||
'ajax' => true, // does this table support ajax?
|
||||
'add_new' => array(
|
||||
'url' => wu_get_form_url('add_new_domain'),
|
||||
'classes' => 'wubox',
|
||||
),
|
||||
));
|
||||
|
||||
} // end __construct;
|
||||
|
||||
/**
|
||||
* Adds the extra search field when the search element is present.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return array
|
||||
*/
|
||||
public function get_extra_query_fields() {
|
||||
|
||||
$_filter_fields = parent::get_extra_query_fields();
|
||||
|
||||
if (wu_request('blog_id')) {
|
||||
|
||||
$_filter_fields['blog_id'] = wu_request('blog_id');
|
||||
|
||||
} // end if;
|
||||
|
||||
return $_filter_fields;
|
||||
|
||||
} // end get_extra_query_fields;
|
||||
/**
|
||||
* Displays the content of the domain column.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param WP_Ultimo\Models\Domain $item Domain object.
|
||||
*/
|
||||
public function column_domain($item): string {
|
||||
|
||||
$url_atts = array(
|
||||
'id' => $item->get_id(),
|
||||
'model' => 'domain',
|
||||
);
|
||||
|
||||
$domain = sprintf('<a href="%s">%s</a>', wu_network_admin_url('wp-ultimo-edit-domain', $url_atts), $item->get_domain());
|
||||
|
||||
$html = "<span class='wu-font-mono'><strong>{$domain}</strong></span>";
|
||||
|
||||
$actions = array(
|
||||
'edit' => sprintf('<a href="%s">%s</a>', wu_network_admin_url('wp-ultimo-edit-domain', $url_atts), __('Edit', 'wp-ultimo')),
|
||||
'delete' => sprintf('<a title="%s" class="wubox" href="%s">%s</a>', __('Delete', 'wp-ultimo'), wu_get_form_url('delete_modal', $url_atts), __('Delete', 'wp-ultimo')),
|
||||
);
|
||||
|
||||
return $html . $this->row_actions($actions);
|
||||
|
||||
} // end column_domain;
|
||||
|
||||
/**
|
||||
* Displays the content of the active column.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param WP_Ultimo\Models\Domain $item Domain object.
|
||||
* @return string
|
||||
*/
|
||||
public function column_active($item) {
|
||||
|
||||
return $item->is_active() ? __('Yes', 'wp-ultimo') : __('No', 'wp-ultimo');
|
||||
|
||||
} // end column_active;
|
||||
|
||||
/**
|
||||
* Displays the content of the primary domain column.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param WP_Ultimo\Models\Domain $item Domain object.
|
||||
* @return string
|
||||
*/
|
||||
public function column_primary_domain($item) {
|
||||
|
||||
return $item->is_primary_domain() ? __('Yes', 'wp-ultimo') : __('No', 'wp-ultimo');
|
||||
|
||||
} // end column_primary_domain;
|
||||
|
||||
/**
|
||||
* Displays the content of the secure column.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param WP_Ultimo\Models\Domain $item Domain object.
|
||||
* @return string
|
||||
*/
|
||||
public function column_secure($item) {
|
||||
|
||||
return $item->is_secure() ? __('Yes', 'wp-ultimo') : __('No', 'wp-ultimo');
|
||||
|
||||
} // end column_secure;
|
||||
|
||||
/**
|
||||
* Returns the markup for the stage column.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param \WP_Ultimo\Models\Domain $item The domain being displayed.
|
||||
* @return string
|
||||
*/
|
||||
public function column_stage($item) {
|
||||
|
||||
$label = $item->get_stage_label();
|
||||
|
||||
$class = $item->get_stage_class();
|
||||
|
||||
return "<span class='wu-py-1 wu-px-2 wu-rounded-sm wu-text-xs wu-leading-none wu-font-mono $class'>{$label}</span>";
|
||||
|
||||
} // end column_stage;
|
||||
|
||||
/**
|
||||
* Returns the list of columns for this particular List Table.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return array
|
||||
*/
|
||||
public function get_columns() {
|
||||
|
||||
$columns = array(
|
||||
'cb' => '<input type="checkbox" />',
|
||||
'domain' => __('Domain', 'wp-ultimo'),
|
||||
'stage' => __('Stage', 'wp-ultimo'),
|
||||
'blog_id' => __('Site', 'wp-ultimo'),
|
||||
'active' => __('Active', 'wp-ultimo'),
|
||||
'primary_domain' => __('Primary', 'wp-ultimo'),
|
||||
'secure' => __('HTTPS', 'wp-ultimo'),
|
||||
'id' => __('ID', 'wp-ultimo'),
|
||||
);
|
||||
|
||||
return $columns;
|
||||
|
||||
} // end get_columns;
|
||||
/**
|
||||
* Returns the filters for this page.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function get_filters(): array {
|
||||
|
||||
return array(
|
||||
'filters' => array(
|
||||
|
||||
/**
|
||||
* Active
|
||||
*/
|
||||
'active' => array(
|
||||
'label' => __('Active', 'wp-ultimo'),
|
||||
'options' => array(
|
||||
0 => __('Inactive', 'wp-ultimo'),
|
||||
1 => __('Active', 'wp-ultimo'),
|
||||
),
|
||||
),
|
||||
|
||||
/**
|
||||
* Primay
|
||||
*/
|
||||
'primary_domain' => array(
|
||||
'label' => __('Is Primary', 'wp-ultimo'),
|
||||
'options' => array(
|
||||
0 => __('Not Primary Domain', 'wp-ultimo'),
|
||||
1 => __('Primary Domain', 'wp-ultimo'),
|
||||
),
|
||||
),
|
||||
|
||||
/**
|
||||
* Secure (HTTPS)
|
||||
*/
|
||||
'secure' => array(
|
||||
'label' => __('HTTPS', 'wp-ultimo'),
|
||||
'options' => array(
|
||||
0 => __('Non-HTTPS', 'wp-ultimo'),
|
||||
1 => __('HTTPS', 'wp-ultimo'),
|
||||
),
|
||||
),
|
||||
|
||||
/**
|
||||
* Stage
|
||||
*/
|
||||
'stage' => array(
|
||||
'label' => __('Verification Stage', 'wp-ultimo'),
|
||||
'options' => Domain_Stage::to_array(),
|
||||
),
|
||||
|
||||
),
|
||||
'date_filters' => array(
|
||||
|
||||
),
|
||||
);
|
||||
|
||||
} // end get_filters;
|
||||
|
||||
} // end class Domain_List_Table;
|
372
inc/list-tables/class-email-list-table.php
Normal file
372
inc/list-tables/class-email-list-table.php
Normal file
@ -0,0 +1,372 @@
|
||||
<?php
|
||||
/**
|
||||
* Email List Table class.
|
||||
*
|
||||
* @package WP_Ultimo
|
||||
* @subpackage List_Table
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\List_Tables;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* Email List Table class.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
class Email_List_Table extends Base_List_Table {
|
||||
|
||||
/**
|
||||
* Holds the query class for the object being listed.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var string
|
||||
*/
|
||||
protected $query_class = '\\WP_Ultimo\\Database\\Emails\\Email_Query';
|
||||
|
||||
/**
|
||||
* Initializes the table.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
parent::__construct(array(
|
||||
'singular' => __('Email', 'wp-ultimo'), // singular name of the listed records
|
||||
'plural' => __('Emails', 'wp-ultimo'), // plural name of the listed records
|
||||
'ajax' => true, // does this table support ajax?
|
||||
'add_new' => array(
|
||||
'url' => wu_network_admin_url('wp-ultimo-edit-email'),
|
||||
'classes' => '',
|
||||
),
|
||||
));
|
||||
|
||||
} // end __construct;
|
||||
|
||||
/**
|
||||
* Overrides the parent method to add pending sites.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param integer $per_page Number of items to display per page.
|
||||
* @param integer $page_number Current page.
|
||||
* @param boolean $count If we should count records or return the actual records.
|
||||
* @return array
|
||||
*/
|
||||
public function get_items($per_page = 5, $page_number = 1, $count = false) {
|
||||
|
||||
$query = array(
|
||||
'number' => $per_page,
|
||||
'offset' => ($page_number - 1) * $per_page,
|
||||
'count' => $count,
|
||||
);
|
||||
|
||||
$search = wu_request('s');
|
||||
|
||||
if ($search) {
|
||||
|
||||
$query['search'] = $search;
|
||||
|
||||
} // end if;
|
||||
|
||||
$target = wu_request('target');
|
||||
|
||||
if ($target && $target !== 'all') {
|
||||
|
||||
$query['meta_query'] = array(
|
||||
'type' => array(
|
||||
'key' => 'wu_target',
|
||||
'value' => $target,
|
||||
),
|
||||
);
|
||||
|
||||
} // end if;
|
||||
|
||||
$query = apply_filters("wu_{$this->id}_get_items", $query, $this);
|
||||
|
||||
return wu_get_emails($query);
|
||||
|
||||
} // end get_items;
|
||||
/**
|
||||
* Displays the title of the email.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param \WP_Ultimo\Models\Email $item The email object.
|
||||
*/
|
||||
public function column_title($item): string {
|
||||
|
||||
$url_atts = array(
|
||||
'id' => $item->get_id(),
|
||||
'model' => 'email'
|
||||
);
|
||||
|
||||
$title = sprintf('<a href="%s">%s</a>', wu_network_admin_url('wp-ultimo-edit-email', $url_atts), $item->get_title());
|
||||
|
||||
$target = $item->get_target();
|
||||
|
||||
$title = '<div><strong class="wu-inline-block wu-pr-1">' . $title . '</strong> <span class="wu-bg-gray-200 wu-text-gray-700 wu-py-1 wu-px-2 wu-rounded-sm wu-text-xs wu-font-mono">' . $target . '</span></div>';
|
||||
|
||||
$content = wp_trim_words(wp_strip_all_tags($item->get_content()), 6);
|
||||
|
||||
$actions = array(
|
||||
'edit' => sprintf('<a href="%s">%s</a>', wu_network_admin_url('wp-ultimo-edit-email', $url_atts), __('Edit', 'wp-ultimo')),
|
||||
'duplicate' => sprintf('<a href="%s">%s</a>', wu_network_admin_url('wp-ultimo-edit-email', $url_atts), __('Duplicate', 'wp-ultimo')),
|
||||
'send-test' => sprintf('<a title="%s" class="wubox" href="%s">%s</a>', __('Send Test Email', 'wp-ultimo'), wu_get_form_url('send_new_test', $url_atts), __('Send Test Email', 'wp-ultimo'))
|
||||
);
|
||||
|
||||
$slug = $item->get_slug();
|
||||
|
||||
$default_system_emails = wu_get_default_system_emails();
|
||||
|
||||
if (isset($default_system_emails[$slug])) {
|
||||
|
||||
$actions['reset'] = sprintf('<a title="%s" class="wubox" href="%s">%s</a>', __('Reset', 'wp-ultimo'), wu_get_form_url('reset_confirmation', $url_atts), __('Reset', 'wp-ultimo'));
|
||||
|
||||
} // end if;
|
||||
|
||||
$actions['delete'] = sprintf('<a title="%s" class="wubox" href="%s">%s</a>', __('Delete', 'wp-ultimo'), wu_get_form_url('delete_modal', $url_atts), __('Delete', 'wp-ultimo'));
|
||||
|
||||
return $title . $content . $this->row_actions($actions);
|
||||
|
||||
} // end column_title;
|
||||
|
||||
/**
|
||||
* Displays the event of the email.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param \WP_Ultimo\Models\Email $item The email object.
|
||||
* @return string
|
||||
*/
|
||||
public function column_event($item) {
|
||||
|
||||
$event = $item->get_event();
|
||||
|
||||
return "<span class='wu-bg-gray-200 wu-text-gray-700 wu-py-1 wu-px-2 wu-rounded-sm wu-text-xs wu-font-mono'>{$event}</span>";
|
||||
|
||||
} // end column_event;
|
||||
|
||||
/**
|
||||
* Displays the slug of the email.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param \WP_Ultimo\Models\Email $item The email object.
|
||||
* @return string
|
||||
*/
|
||||
public function column_slug($item) {
|
||||
|
||||
$slug = $item->get_slug();
|
||||
|
||||
return "<span class='wu-bg-gray-200 wu-text-gray-700 wu-py-1 wu-px-2 wu-rounded-sm wu-text-xs wu-font-mono'>{$slug}</span>";
|
||||
|
||||
} // end column_slug;
|
||||
|
||||
/**
|
||||
* Displays if the email is schedule for later send or not.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param \WP_Ultimo\Models\Email $item The email object.
|
||||
* @return string
|
||||
*/
|
||||
public function column_schedule($item) {
|
||||
|
||||
if ($item->has_schedule()) {
|
||||
|
||||
if ($item->get_schedule_type() === 'hours') {
|
||||
|
||||
$time = explode(':', (string) $item->get_send_hours());
|
||||
|
||||
$text = sprintf(__('%1$s hour(s) and %2$s minute(s) after the event.', 'wp-ultimo'), $time[0], $time[1]);
|
||||
|
||||
} elseif ($item->get_schedule_type() === 'days') {
|
||||
|
||||
$text = sprintf(__('%s day(s) after the event.', 'wp-ultimo'), $item->get_send_days());
|
||||
|
||||
} // end if;
|
||||
|
||||
} else {
|
||||
|
||||
$text = __('Sent immediately after the event.', 'wp-ultimo');
|
||||
|
||||
} // end if;
|
||||
|
||||
return $text;
|
||||
|
||||
} // end column_schedule;
|
||||
|
||||
/**
|
||||
* Returns the list of columns for this particular List Table.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return array
|
||||
*/
|
||||
public function get_columns() {
|
||||
|
||||
$columns = array(
|
||||
'cb' => '<input type="checkbox" />',
|
||||
'title' => __('Content', 'wp-ultimo'),
|
||||
'slug' => __('Event', 'wp-ultimo'),
|
||||
'event' => __('slug', 'wp-ultimo'),
|
||||
'schedule' => __('When', 'wp-ultimo'),
|
||||
'id' => __('ID', 'wp-ultimo'),
|
||||
);
|
||||
|
||||
return $columns;
|
||||
|
||||
} // end get_columns;
|
||||
|
||||
/**
|
||||
* Handles the bulk processing adding duplication.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
public function process_single_action() {
|
||||
|
||||
$bulk_action = $this->current_action();
|
||||
|
||||
if ($bulk_action === 'duplicate') {
|
||||
|
||||
$email_id = wu_request('id');
|
||||
|
||||
$email = wu_get_email($email_id);
|
||||
|
||||
if (!$email) {
|
||||
|
||||
WP_Ultimo()->notices->add(__('Email not found.', 'wp-ultimo'), 'error', 'network-admin');
|
||||
|
||||
return;
|
||||
|
||||
} // end if;
|
||||
|
||||
$new_email = $email->duplicate();
|
||||
|
||||
$new_name = sprintf(__('Copy of %s', 'wp-ultimo'), $email->get_name());
|
||||
|
||||
$new_email->set_name($new_name);
|
||||
|
||||
$new_email->set_slug(sanitize_title($new_name));
|
||||
|
||||
$new_email->set_target($email->get_target());
|
||||
|
||||
$new_email->set_style($email->get_style());
|
||||
|
||||
$new_email->set_event($email->get_event());
|
||||
|
||||
if ($email->has_schedule()) {
|
||||
|
||||
$new_email->set_schedule($email->has_schedule());
|
||||
|
||||
if ($email->get_schedule_type() === 'hours') {
|
||||
|
||||
$new_email->set_send_hours($email->get_send_hours());
|
||||
|
||||
} elseif ($email->get_schedule_type() === 'days') {
|
||||
|
||||
$new_email->set_send_days($email->get_send_days());
|
||||
|
||||
} // end if;
|
||||
|
||||
} // end if;
|
||||
|
||||
if ($email->get_custom_sender()) {
|
||||
|
||||
$new_email->set_custom_sender($email->get_custom_sender());
|
||||
|
||||
$new_email->set_custom_sender_name($email->get_custom_sender_name());
|
||||
|
||||
$new_email->set_custom_sender_email($email->get_custom_sender_email());
|
||||
|
||||
} // end if;
|
||||
|
||||
$new_email->set_send_copy_to_admin($email->get_send_copy_to_admin());
|
||||
|
||||
$new_email->set_date_created(wu_get_current_time('mysql', true));
|
||||
|
||||
$result = $new_email->save();
|
||||
|
||||
if (is_wp_error($result)) {
|
||||
|
||||
WP_Ultimo()->notices->add($result->get_error_message(), 'error', 'network-admin');
|
||||
|
||||
return;
|
||||
|
||||
} // end if;
|
||||
|
||||
$redirect_url = wu_network_admin_url('wp-ultimo-edit-email', array(
|
||||
'id' => $new_email->get_id(),
|
||||
'updated' => 1,
|
||||
));
|
||||
|
||||
wp_redirect($redirect_url);
|
||||
|
||||
exit;
|
||||
|
||||
} // end if;
|
||||
|
||||
} // end process_single_action;
|
||||
/**
|
||||
* Returns the filters for this page.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function get_filters(): array {
|
||||
|
||||
return array(
|
||||
'filters' => array(
|
||||
'type' => array(
|
||||
'label' => __('Email Type', 'wp-ultimo'),
|
||||
'options' => array(
|
||||
'email_email' => __('Email', 'wp-ultimo'),
|
||||
'broadcast_email' => __('Notices', 'wp-ultimo'),
|
||||
),
|
||||
),
|
||||
),
|
||||
'date_filters' => array(
|
||||
'date_created' => array(
|
||||
'label' => __('Date', 'wp-ultimo'),
|
||||
'options' => $this->get_default_date_filter_options(),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
} // end get_filters;
|
||||
|
||||
/**
|
||||
* Returns the pre-selected filters on the filter bar.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return array
|
||||
*/
|
||||
public function get_views() {
|
||||
|
||||
return array(
|
||||
'all' => array(
|
||||
'field' => 'target',
|
||||
'url' => add_query_arg('target', 'all'),
|
||||
'label' => __('All Emails', 'wp-ultimo'),
|
||||
'count' => 0,
|
||||
),
|
||||
'admin' => array(
|
||||
'field' => 'target',
|
||||
'url' => add_query_arg('target', 'admin'),
|
||||
'label' => __('Admin Emails', 'wp-ultimo'),
|
||||
'count' => 0,
|
||||
),
|
||||
'customer' => array(
|
||||
'field' => 'target',
|
||||
'url' => add_query_arg('target', 'customer'),
|
||||
'label' => __('Customer Emails', 'wp-ultimo'),
|
||||
'count' => 0,
|
||||
),
|
||||
);
|
||||
|
||||
} // end get_views;
|
||||
|
||||
} // end class Email_List_Table;
|
253
inc/list-tables/class-event-list-table.php
Normal file
253
inc/list-tables/class-event-list-table.php
Normal file
@ -0,0 +1,253 @@
|
||||
<?php
|
||||
/**
|
||||
* Event List Table class.
|
||||
*
|
||||
* @package WP_Ultimo
|
||||
* @subpackage List_Table
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\List_Tables;
|
||||
|
||||
use \WP_Ultimo\Models\Event;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* Event List Table class.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
class Event_List_Table extends Base_List_Table {
|
||||
|
||||
/**
|
||||
* Holds the query class for the object being listed.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var string
|
||||
*/
|
||||
protected $query_class = '\\WP_Ultimo\\Database\\Events\\Event_Query';
|
||||
|
||||
/**
|
||||
* Initializes the table.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
parent::__construct(array(
|
||||
'singular' => __('Event', 'wp-ultimo'), // singular name of the listed records
|
||||
'plural' => __('Events', 'wp-ultimo'), // plural name of the listed records
|
||||
'ajax' => true // does this table support ajax?
|
||||
));
|
||||
|
||||
} // end __construct;
|
||||
|
||||
/**
|
||||
* Returns the markup for the object_type column.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param \WP_Ultimo\Models\Event $item The event being displayed.
|
||||
* @return string
|
||||
*/
|
||||
public function column_object_type($item) {
|
||||
|
||||
$object_type = $item->get_object_type();
|
||||
|
||||
return "<span class='wu-py-1 wu-px-2 wu-bg-gray-200 wu-rounded-sm wu-leading-none wu-text-gray-700 wu-text-xs wu-font-mono'>{$object_type}</span>";
|
||||
|
||||
} // end column_object_type;
|
||||
|
||||
/**
|
||||
* Returns the markup for the initiator column.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param \WP_Ultimo\Models\Event $item The event being displayed.
|
||||
* @return string
|
||||
*/
|
||||
public function column_initiator($item) {
|
||||
|
||||
$object_initiator = $item->get_initiator();
|
||||
|
||||
$object_severity_label = $item->get_severity_label();
|
||||
|
||||
$object_severity_class = $item->get_severity_class();
|
||||
|
||||
$object_label_tooltip = substr($object_severity_label, 0, 1);
|
||||
|
||||
if ($object_initiator === 'system') {
|
||||
|
||||
$avatar = '<span class="dashicons-wu-tools wu-text-gray-700 wu-text-xl"></span>';
|
||||
|
||||
$system_text = ucfirst($object_initiator);
|
||||
|
||||
// phpcs:disable
|
||||
$html = "<div class='wu-table-card wu-text-gray-700 wu-p-2 wu-flex wu-flex-grow wu-rounded wu-items-center wu-border wu-border-solid wu-border-gray-300'>
|
||||
<div class='wu-flex wu-relative wu-h-7 wu-w-7 wu-rounded-full wu-ring-2 wu-ring-white wu-bg-gray-300 wu-items-center wu-justify-center wu-mr-3'>
|
||||
{$avatar}
|
||||
|
||||
<span role='tooltip' aria-label='{$object_initiator} - {$object_severity_label}' class='wu-absolute wu-rounded-full wu--mb-2 wu-flex wu-items-center wu-justify-center wu-font-mono wu-bottom-0 wu-right-0 wu-font-bold wu-h-4 wu-w-4 wu-uppercase wu-text-2xs wu-border-solid wu-border-2 wu-border-white {$object_severity_class}'>{$object_label_tooltip}</span>
|
||||
|
||||
</div>
|
||||
<div class=''>
|
||||
<strong class='wu-block'>{$system_text}</strong>
|
||||
<small>" . __('Automatically started', 'wp-ultimo') . "</small>
|
||||
</div>
|
||||
</div>";
|
||||
// phpcs:enable
|
||||
|
||||
} elseif ($object_initiator === 'manual') {
|
||||
|
||||
$avatar = get_avatar($item->get_author_id(), 32, 'identicon', '', array(
|
||||
'force_display' => true,
|
||||
'class' => 'wu-rounded-full',
|
||||
));
|
||||
|
||||
$display_name = $item->get_author_display_name();
|
||||
|
||||
$id = $item->get_author_id();
|
||||
|
||||
$url_atts = array(
|
||||
'id' => $item->get_author_id(),
|
||||
);
|
||||
|
||||
$initiator_link = wu_network_admin_url('wp-ultimo-edit-customer', $url_atts);
|
||||
|
||||
$email = $item->get_author_email_address();
|
||||
|
||||
$html = "<a href='{$initiator_link}' class='wu-table-card wu-text-gray-700 wu-flex wu-p-2 wu-flex-grow wu-rounded wu-items-center wu-border wu-border-solid wu-border-gray-300'>
|
||||
|
||||
<div class='wu-flex wu-relative wu-rounded-full wu-ring-2 wu-ring-white wu-items-center wu-justify-center'>
|
||||
|
||||
{$avatar}
|
||||
|
||||
<span role='tooltip' aria-label='{$object_initiator} - {$object_severity_label}' class='wu-absolute wu-rounded-full wu--mb-2 wu-flex wu-items-center wu-justify-center wu-font-mono wu-bottom-0 wu-right-0 wu-font-bold wu-h-4 wu-w-4 wu-uppercase wu-text-2xs wu-border-solid wu-border-2 wu-border-white {$object_severity_class}'>{$object_label_tooltip}</span>
|
||||
|
||||
</div>
|
||||
|
||||
<div class='wu-pl-2'>
|
||||
<strong class='wu-block'> {$display_name} <small class='wu-font-normal'>(#{$id})</small></strong>
|
||||
<small>{$email}</small>
|
||||
</div>
|
||||
</a>";
|
||||
|
||||
} else {
|
||||
|
||||
$not_found = __('No initiator found', 'wp-ultimo');
|
||||
|
||||
$html = "<div class='wu-table-card wu-text-gray-700 wu-py-1 wu-px-2 wu-flex wu-flex-grow wu-rounded wu-items-center wu-border wu-border-solid wu-border-gray-300 wu-relative wu-overflow-hidden'>
|
||||
<span class='dashicons dashicons-wu-block wu-text-gray-600 wu-px-1 wu-pr-3'> </span>
|
||||
<div class='wu-pl-2'>
|
||||
<span class='wu-block wu-py-3 wu-text-gray-600 wu-text-2xs wu-font-bold wu-uppercase'>{$not_found}</span>
|
||||
</div>
|
||||
</div>";
|
||||
|
||||
} // end if;
|
||||
|
||||
return $html;
|
||||
|
||||
} // end column_initiator;
|
||||
|
||||
/**
|
||||
* Returns the markup for the initiator column.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param \WP_Ultimo\Models\Event $item The event being displayed.
|
||||
* @return string
|
||||
*/
|
||||
public function column_slug($item) {
|
||||
|
||||
$object_slug = $item->get_slug();
|
||||
|
||||
return "<span class='wu-py-1 wu-px-2 wu-bg-gray-200 wu-rounded-sm wu-text-gray-700 wu-text-xs wu-font-mono'>{$object_slug}</span>";
|
||||
|
||||
} // end column_slug;
|
||||
/**
|
||||
* Returns the markup for the message column.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param \WP_Ultimo\Models\Event $item The event being displayed.
|
||||
*/
|
||||
public function column_message($item): string {
|
||||
|
||||
$message = wp_trim_words($item->get_message(), 13);
|
||||
|
||||
$url_atts = array(
|
||||
'id' => $item->get_id(),
|
||||
'model' => 'event'
|
||||
);
|
||||
|
||||
$actions = array(
|
||||
'view' => sprintf('<a href="%s">%s</a>', wu_network_admin_url('wp-ultimo-view-event', $url_atts), __('View', 'wp-ultimo')),
|
||||
'delete' => sprintf(
|
||||
'<a title="%s" class="wubox" href="%s">%s</a>',
|
||||
__('Delete', 'wp-ultimo'),
|
||||
wu_get_form_url(
|
||||
'delete_modal',
|
||||
$url_atts
|
||||
),
|
||||
__('Delete', 'wp-ultimo')
|
||||
),
|
||||
);
|
||||
|
||||
return $message . $this->row_actions($actions);
|
||||
|
||||
} // end column_message;
|
||||
|
||||
/**
|
||||
* Returns the list of columns for this particular List Table.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return array
|
||||
*/
|
||||
public function get_columns() {
|
||||
|
||||
$columns = array(
|
||||
'cb' => '<input type="checkbox" />',
|
||||
'initiator' => __('Initiator', 'wp-ultimo'),
|
||||
'message' => __('Event Message', 'wp-ultimo'),
|
||||
'slug' => __('SLug', 'wp-ultimo'),
|
||||
'object_type' => __('Type', 'wp-ultimo'),
|
||||
'date_created' => __('Created at', 'wp-ultimo'),
|
||||
'id' => __('ID', 'wp-ultimo'),
|
||||
);
|
||||
|
||||
return apply_filters('wu_events_list_table_get_columns', $columns, $this);
|
||||
|
||||
} // end get_columns;
|
||||
/**
|
||||
* Returns the filters for this page.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function get_filters(): array {
|
||||
|
||||
return array(
|
||||
'filters' => array(
|
||||
'severity' => array(
|
||||
'label' => __('Severity', 'wp-ultimo'),
|
||||
'options' => array(
|
||||
Event::SEVERITY_SUCCESS => __('Success', 'wp-ultimo'),
|
||||
Event::SEVERITY_NEUTRAL => __('Neutral', 'wp-ultimo'),
|
||||
Event::SEVERITY_INFO => __('Info', 'wp-ultimo'),
|
||||
Event::SEVERITY_WARNING => __('Warning', 'wp-ultimo'),
|
||||
Event::SEVERITY_FATAL => __('Fatal', 'wp-ultimo'),
|
||||
),
|
||||
),
|
||||
),
|
||||
'date_filters' => array(
|
||||
'date_created' => array(
|
||||
'label' => __('Created At', 'wp-ultimo'),
|
||||
'options' => $this->get_default_date_filter_options(),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
} // end get_filters;
|
||||
|
||||
} // end class Event_List_Table;
|
99
inc/list-tables/class-inside-events-list-table.php
Normal file
99
inc/list-tables/class-inside-events-list-table.php
Normal file
@ -0,0 +1,99 @@
|
||||
<?php
|
||||
/**
|
||||
* Customers Site List Table class.
|
||||
*
|
||||
* @package WP_Ultimo
|
||||
* @subpackage List_Table
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\List_Tables;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* Site List Table class.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
class Inside_Events_List_Table extends Event_List_Table {
|
||||
|
||||
/**
|
||||
* Returns the list of columns for this particular List Table.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return array
|
||||
*/
|
||||
public function get_columns() {
|
||||
|
||||
$columns = array(
|
||||
'responsive' => '',
|
||||
);
|
||||
|
||||
return $columns;
|
||||
|
||||
} // end get_columns;
|
||||
|
||||
/**
|
||||
* Renders the inside column responsive.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param object $item The item being rendered.
|
||||
* @return void
|
||||
*/
|
||||
public function column_responsive($item) {
|
||||
|
||||
$first_row = array(
|
||||
'id' => array(
|
||||
'icon' => 'dashicons-wu-hash wu-align-middle wu-mr-1',
|
||||
'label' => __('Event ID', 'wp-ultimo'),
|
||||
'value' => $item->get_id(),
|
||||
),
|
||||
'slug' => array(
|
||||
'icon' => 'dashicons-wu-bookmark1 wu-align-middle wu-mr-1',
|
||||
'label' => __('Event Type', 'wp-ultimo'),
|
||||
'value' => wu_slug_to_name($item->get_slug()),
|
||||
),
|
||||
);
|
||||
|
||||
$object_initiator = $item->get_initiator();
|
||||
|
||||
if ($object_initiator === 'system') {
|
||||
|
||||
$value = sprintf('<span class="dashicons-wu-wp-ultimo wu-align-middle wu-mr-1 wu-text-lg"></span><span class="wu-text-gray-600">%s</span>', __('Automatically processed by WP Ultimo', 'wp-ultimo'));
|
||||
|
||||
} elseif ($object_initiator === 'manual') {
|
||||
|
||||
$avatar = get_avatar($item->get_author_id(), 16, 'identicon', '', array(
|
||||
'force_display' => true,
|
||||
'class' => 'wu-rounded-full wu-mr-1 wu-align-text-bottom',
|
||||
));
|
||||
|
||||
$display_name = $item->get_author_display_name();
|
||||
|
||||
$value = sprintf('<span class="wu-text-gray-600">%s%s</span>', $avatar, $display_name);
|
||||
|
||||
} // end if;
|
||||
|
||||
echo wu_responsive_table_row(array(
|
||||
'id' => '',
|
||||
'title' => sprintf('<span class="wu-font-normal">%s</span>', wp_trim_words($item->get_message(), 15)),
|
||||
'url' => wu_network_admin_url('wp-ultimo-view-event', array(
|
||||
'id' => $item->get_id(),
|
||||
)),
|
||||
'status' => $value,
|
||||
),
|
||||
$first_row,
|
||||
array(
|
||||
'date_created' => array(
|
||||
'icon' => 'dashicons-wu-calendar1 wu-align-middle wu-mr-1',
|
||||
'label' => '',
|
||||
'value' => sprintf(__('Processed %s', 'wp-ultimo'), wu_human_time_diff($item->get_date_created(), '-1 day')),
|
||||
),
|
||||
));
|
||||
|
||||
} // end column_responsive;
|
||||
|
||||
} // end class Inside_Events_List_Table;
|
250
inc/list-tables/class-line-item-list-table.php
Normal file
250
inc/list-tables/class-line-item-list-table.php
Normal file
@ -0,0 +1,250 @@
|
||||
<?php
|
||||
/**
|
||||
* Payment List Table class.
|
||||
*
|
||||
* @package WP_Ultimo
|
||||
* @subpackage List_Table
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\List_Tables;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* Payment List Table class.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
class Line_Item_List_Table extends Payment_List_Table {
|
||||
|
||||
/**
|
||||
* Holds the query class for the object being listed.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var string
|
||||
*/
|
||||
protected $query_class = '\\WP_Ultimo\\Database\\Payments\\Payment_Query';
|
||||
|
||||
/**
|
||||
* Initializes the table.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
parent::__construct(array(
|
||||
'singular' => __('Line Item', 'wp-ultimo'), // singular name of the listed records
|
||||
'plural' => __('Line Items', 'wp-ultimo'), // plural name of the listed records
|
||||
'ajax' => true // does this table support ajax?
|
||||
));
|
||||
|
||||
} // end __construct;
|
||||
|
||||
/**
|
||||
* Get the payment object.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return \WP_Ultimo\Models\Payment
|
||||
*/
|
||||
public function get_payment() {
|
||||
|
||||
$payment_id = wu_request('id');
|
||||
|
||||
return wu_get_payment($payment_id);
|
||||
|
||||
} // end get_payment;
|
||||
|
||||
/**
|
||||
* Overrides the parent get_items to add a total line.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param integer $per_page Items per page. This gets overridden as well.
|
||||
* @param integer $page_number The page number.
|
||||
* @param boolean $count Return as count or not.
|
||||
* @return array
|
||||
*/
|
||||
public function get_items($per_page = 5, $page_number = 1, $count = false) {
|
||||
|
||||
$payment = $this->get_payment();
|
||||
|
||||
$items = $payment->get_line_items();
|
||||
|
||||
if ($count) {
|
||||
|
||||
return count($items);
|
||||
|
||||
} // end if;
|
||||
|
||||
return $items;
|
||||
|
||||
} // end get_items;
|
||||
|
||||
/**
|
||||
* Displays the name of the product and description being hired.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param \WP_Ultimo\Checkout\Line_Item $item Payment object.
|
||||
* @return string
|
||||
*/
|
||||
public function column_service($item) {
|
||||
|
||||
if (!$item) {
|
||||
|
||||
return '--';
|
||||
|
||||
} // end if;
|
||||
|
||||
$url_atts = array(
|
||||
'id' => $this->get_payment()->get_id(),
|
||||
'line_item_id' => $item->get_id(),
|
||||
);
|
||||
|
||||
$actions = array(
|
||||
'edit' => sprintf('<a title="%s" class="wubox" href="%s">%s</a>', __('Edit Item', 'wp-ultimo'), wu_get_form_url('edit_line_item', $url_atts), __('Edit', 'wp-ultimo')),
|
||||
'delete' => sprintf('<a title="%s" class="wubox" href="%s">%s</a>', __('Delete Item', 'wp-ultimo'), wu_get_form_url('delete_line_item', $url_atts), __('Delete', 'wp-ultimo')),
|
||||
);
|
||||
|
||||
$html = sprintf('<span class="wu-block wu-text-gray-700">%s</span>', $item->get_title());
|
||||
|
||||
$html .= sprintf('<span class="wu-block wu-text-gray-600 wu-text-xs">%s</span>', $item->get_description());
|
||||
|
||||
return $html . $this->row_actions($actions);
|
||||
|
||||
} // end column_service;
|
||||
|
||||
/**
|
||||
* Displays the tax rate for the item.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param \WP_Ultimo\Models\Payment $item Payment object.
|
||||
* @return string
|
||||
*/
|
||||
public function column_unit_price($item) {
|
||||
|
||||
$html = wu_format_currency($item->get_unit_price());
|
||||
|
||||
$quantity = sprintf(__('Quantity: %s', 'wp-ultimo'), $item->get_quantity()); // phpcs:ignore
|
||||
|
||||
return $html . sprintf('<small class="wu-block">%s</small>', $quantity);
|
||||
|
||||
} // end column_unit_price;
|
||||
|
||||
/**
|
||||
* Displays the tax rate for the item.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param \WP_Ultimo\Models\Payment $item Payment object.
|
||||
* @return string
|
||||
*/
|
||||
public function column_tax_total($item) {
|
||||
|
||||
$html = wu_format_currency($item->get_tax_total());
|
||||
|
||||
$tax_rate = '';
|
||||
|
||||
if ($item->get_tax_type() === 'percentage' && $item->get_tax_rate()) {
|
||||
|
||||
$tax_rate = $item->get_tax_rate() . '%';
|
||||
|
||||
} // end if;
|
||||
|
||||
$tax_label = $item->get_tax_rate() ? ($item->get_tax_label() ? $item->get_tax_label() : __('Tax Applied', 'wp-ultimo')) : __('No Taxes Applied', 'wp-ultimo');
|
||||
|
||||
return $html . sprintf('<small class="wu-block">%s (%s)</small>', $tax_rate, $tax_label);
|
||||
|
||||
} // end column_tax_total;
|
||||
|
||||
/**
|
||||
* Displays the tax rate for the item.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param \WP_Ultimo\Models\Payment $item Payment object.
|
||||
* @return string
|
||||
*/
|
||||
public function column_discounts_total($item) {
|
||||
|
||||
$html = wu_format_currency($item->get_discount_total());
|
||||
|
||||
$tax_rate = '';
|
||||
|
||||
if ($item->get_discount_type() === 'percentage' && $item->get_discount_rate()) {
|
||||
|
||||
$tax_rate = $item->get_discount_rate() . '%';
|
||||
|
||||
} // end if;
|
||||
|
||||
$tax_label = $item->get_discount_rate() ? ($item->get_discount_label() ? $item->get_discount_label() : __('Discount', 'wp-ultimo')) : __('No discount', 'wp-ultimo');
|
||||
|
||||
return $html . sprintf('<small class="wu-block">%s (%s)</small>', $tax_rate, $tax_label);
|
||||
|
||||
} // end column_discounts_total;
|
||||
|
||||
/**
|
||||
* Displays the total column.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param \WP_Ultimo\Models\Payment $item Payment object.
|
||||
* @return string
|
||||
*/
|
||||
public function column_total($item) {
|
||||
|
||||
return wu_format_currency($item->get_total());
|
||||
|
||||
} // end column_total;
|
||||
|
||||
/**
|
||||
* Displays the subtotal column.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param \WP_Ultimo\Models\Payment $item Payment object.
|
||||
* @return string
|
||||
*/
|
||||
public function column_subtotal($item) {
|
||||
|
||||
return wu_format_currency($item->get_subtotal());
|
||||
|
||||
} // end column_subtotal;
|
||||
|
||||
/**
|
||||
* Returns the list of columns for this particular List Table.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return array
|
||||
*/
|
||||
public function get_columns() {
|
||||
|
||||
$columns = array(
|
||||
'service' => __('Service', 'wp-ultimo'),
|
||||
'unit_price' => __('Unit Price', 'wp-ultimo'),
|
||||
'discounts_total' => __('discounts', 'wp-ultimo'),
|
||||
'subtotal' => __('Subtotal', 'wp-ultimo'),
|
||||
'tax_total' => __('Taxes', 'wp-ultimo'),
|
||||
'total' => __('Total', 'wp-ultimo'),
|
||||
);
|
||||
|
||||
return $columns;
|
||||
|
||||
} // end get_columns;
|
||||
|
||||
/**
|
||||
* Leaves no sortable items on the columns.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return array
|
||||
*/
|
||||
public function get_sortable_columns() {
|
||||
|
||||
return array();
|
||||
|
||||
} // end get_sortable_columns;
|
||||
|
||||
} // end class Line_Item_List_Table;
|
164
inc/list-tables/class-membership-line-item-list-table.php
Normal file
164
inc/list-tables/class-membership-line-item-list-table.php
Normal file
@ -0,0 +1,164 @@
|
||||
<?php
|
||||
/**
|
||||
* Payment List Table class.
|
||||
*
|
||||
* @package WP_Ultimo
|
||||
* @subpackage List_Table
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\List_Tables;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* Payment List Table class.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
class Membership_Line_Item_List_Table extends Product_List_Table {
|
||||
|
||||
/**
|
||||
* Returns the list of columns for this particular List Table.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return array
|
||||
*/
|
||||
public function get_columns() {
|
||||
|
||||
$columns = array(
|
||||
'responsive' => '',
|
||||
);
|
||||
|
||||
return $columns;
|
||||
|
||||
} // end get_columns;
|
||||
|
||||
/**
|
||||
* Overrides the parent get_items to add a total line.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param integer $per_page Items per page. This gets overridden as well.
|
||||
* @param integer $page_number The page number.
|
||||
* @param boolean $count Return as count or not.
|
||||
* @return array
|
||||
*/
|
||||
public function get_items($per_page = 5, $page_number = 1, $count = false) {
|
||||
|
||||
$membership = wu_get_membership(wu_request('id'));
|
||||
|
||||
$products = $membership->get_all_products();
|
||||
|
||||
if ($count) {
|
||||
|
||||
return count($products);
|
||||
|
||||
} // end if;
|
||||
|
||||
return $products;
|
||||
|
||||
} // end get_items;
|
||||
|
||||
/**
|
||||
* Renders the inside column responsive.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param object $item The item being rendered.
|
||||
* @return void
|
||||
*/
|
||||
public function column_responsive($item) {
|
||||
|
||||
$quantity = $item['quantity'];
|
||||
|
||||
$membership_id = wu_request('id');
|
||||
|
||||
$item = $item['product'];
|
||||
|
||||
if (!$item) {
|
||||
|
||||
echo wu_responsive_table_row(array(
|
||||
'url' => false,
|
||||
'id' => 'not-found',
|
||||
'title' => __('Product not found', 'wp-ultimo'),
|
||||
'status' => '',
|
||||
'image' => $this->column_featured_image_id(new \WP_Ultimo\Models\Product()),
|
||||
), array(
|
||||
'quantity' => array(
|
||||
'icon' => 'dashicons-wu-package wu-align-middle wu-mr-1',
|
||||
'label' => __('Quantity', 'wp-ultimo'),
|
||||
'value' => sprintf(__('x%d', 'wp-ultimo'), $quantity),
|
||||
),
|
||||
));
|
||||
|
||||
return;
|
||||
|
||||
} // end if;
|
||||
|
||||
$first_row = array(
|
||||
'quantity' => array(
|
||||
'icon' => 'dashicons-wu-package wu-align-middle wu-mr-1',
|
||||
'label' => __('Quantity', 'wp-ultimo'),
|
||||
'value' => sprintf(__('x%d', 'wp-ultimo'), $quantity),
|
||||
),
|
||||
'total' => array(
|
||||
'icon' => 'dashicons-wu-shopping-bag1 wu-align-middle wu-mr-1',
|
||||
'label' => __('Price description', 'wp-ultimo'),
|
||||
'value' => $item->get_price_description(),
|
||||
),
|
||||
);
|
||||
|
||||
$second_row = array(
|
||||
'slug' => array(
|
||||
'icon' => 'dashicons-wu-bookmark1 wu-align-middle wu-mr-1',
|
||||
'label' => __('Product Slug', 'wp-ultimo'),
|
||||
'value' => $item->get_slug(),
|
||||
),
|
||||
);
|
||||
|
||||
if ($item->get_type() === 'plan') {
|
||||
|
||||
$first_row['change'] = array(
|
||||
'wrapper_classes' => 'wubox',
|
||||
'icon' => 'dashicons-wu-edit1 wu-align-middle wu-mr-1',
|
||||
'label' => '',
|
||||
'value' => __('Upgrade or Downgrade', 'wp-ultimo'),
|
||||
'url' => wu_get_form_url('change_membership_plan', array(
|
||||
'id' => $membership_id,
|
||||
'product_id' => $item->get_id(),
|
||||
)),
|
||||
);
|
||||
|
||||
} else {
|
||||
|
||||
$first_row['remove'] = array(
|
||||
'wrapper_classes' => 'wu-text-red-500 wubox',
|
||||
'icon' => 'dashicons-wu-trash-2 wu-align-middle wu-mr-1',
|
||||
'label' => '',
|
||||
'value' => __('Remove', 'wp-ultimo'),
|
||||
'url' => wu_get_form_url('remove_membership_product', array(
|
||||
'id' => $membership_id,
|
||||
'product_id' => $item->get_id(),
|
||||
)),
|
||||
);
|
||||
|
||||
} // end if;
|
||||
|
||||
echo wu_responsive_table_row(array(
|
||||
'id' => $item->get_id(),
|
||||
'title' => $item->get_name(),
|
||||
'url' => wu_network_admin_url('wp-ultimo-edit-product', array(
|
||||
'id' => $item->get_id(),
|
||||
)),
|
||||
'image' => $this->column_featured_image_id($item),
|
||||
'status' => $this->column_type($item),
|
||||
),
|
||||
$first_row,
|
||||
$second_row
|
||||
);
|
||||
|
||||
} // end column_responsive;
|
||||
|
||||
} // end class Membership_Line_Item_List_Table;
|
298
inc/list-tables/class-membership-list-table-widget.php
Normal file
298
inc/list-tables/class-membership-list-table-widget.php
Normal file
@ -0,0 +1,298 @@
|
||||
<?php
|
||||
/**
|
||||
* Membership List Table Widget class.
|
||||
*
|
||||
* @package WP_Ultimo
|
||||
* @subpackage List_Table
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\List_Tables;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
use \WP_Ultimo\Helpers\Hash;
|
||||
|
||||
/**
|
||||
* Membership List Table class.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
class Membership_List_Table_Widget extends Base_List_Table {
|
||||
|
||||
/**
|
||||
* Holds the query class for the object being listed.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var string
|
||||
*/
|
||||
protected $query_class = '\\WP_Ultimo\\Database\\Memberships\\Membership_Query';
|
||||
|
||||
/**
|
||||
* Initializes the table.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
parent::__construct(array(
|
||||
'singular' => __('Membership', 'wp-ultimo'), // singular name of the listed records
|
||||
'plural' => __('Memberships', 'wp-ultimo'), // plural name of the listed records
|
||||
'ajax' => true // does this table support ajax?
|
||||
));
|
||||
|
||||
} // end __construct;
|
||||
|
||||
/**
|
||||
* Uses the query class to return the items to be displayed.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param integer $per_page Number of items to display per page.
|
||||
* @param integer $page_number Current page.
|
||||
* @param boolean $count If we should count records or return the actual records.
|
||||
* @return array
|
||||
*/
|
||||
public function get_items($per_page = 5, $page_number = 1, $count = false) {
|
||||
|
||||
$query_class = new $this->query_class();
|
||||
|
||||
$query_args = array(
|
||||
'number' => 5,
|
||||
'offset' => 1,
|
||||
'orderby' => wu_request('orderby', 'date_created'),
|
||||
'order' => wu_request('order', 'DESC'),
|
||||
'search' => wu_request('s', false),
|
||||
'count' => $count,
|
||||
);
|
||||
|
||||
/**
|
||||
* Accounts for hashes
|
||||
*/
|
||||
if (isset($query_args['search']) && strlen((string) $query_args['search']) === Hash::LENGTH) {
|
||||
|
||||
$item_id = Hash::decode($query_args['search']);
|
||||
|
||||
if ($item_id) {
|
||||
|
||||
unset($query_args['search']);
|
||||
|
||||
$query_args['id'] = $item_id;
|
||||
|
||||
} // end if;
|
||||
|
||||
} // end if;
|
||||
|
||||
$query_args = array_merge($query_args, $this->get_extra_query_fields());
|
||||
|
||||
$query_args = apply_filters("wu_{$this->id}_get_items", $query_args, $this);
|
||||
|
||||
$function_name = 'wu_get_' . $query_class->get_plural_name();
|
||||
|
||||
if (function_exists($function_name)) {
|
||||
|
||||
$query = $function_name($query_args);
|
||||
|
||||
} else {
|
||||
|
||||
$query = $query_class->query($query_args);
|
||||
|
||||
} // end if;
|
||||
|
||||
return $query;
|
||||
|
||||
} // end get_items;
|
||||
|
||||
/**
|
||||
* Adds the extra search field when the search element is present.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return array
|
||||
*/
|
||||
public function get_extra_query_fields() {
|
||||
|
||||
$_filter_fields = parent::get_extra_query_fields();
|
||||
|
||||
$search = isset($_GET['s']) ? sanitize_text_field($_GET['s']) : false;
|
||||
|
||||
$_filter_fields['customer_id'] = wu_request('customer_id');
|
||||
|
||||
return $_filter_fields;
|
||||
|
||||
} // end get_extra_query_fields;
|
||||
/**
|
||||
* Displays the membership reference code.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param WP_Ultimo\Models\Membership $item Membership object.
|
||||
*/
|
||||
public function column_hash($item): string {
|
||||
|
||||
$url_atts = array(
|
||||
'id' => $item->get_id(),
|
||||
);
|
||||
|
||||
$code = sprintf('<a href="%s">%s</a>', wu_network_admin_url('wp-ultimo-edit-membership', $url_atts), $item->get_hash());
|
||||
|
||||
$actions = array(
|
||||
'edit' => sprintf('<a href="%s">%s</a>', wu_network_admin_url('wp-ultimo-edit-membership', $url_atts), __('Edit', 'wp-ultimo')),
|
||||
'delete' => sprintf('<a href="%s">%s</a>', '', __('Delete', 'wp-ultimo')),
|
||||
);
|
||||
|
||||
$html = "<span class='wu-font-mono'><strong>{$code}</strong></span>";
|
||||
|
||||
return $html . $this->row_actions($actions);
|
||||
|
||||
} // end column_hash;
|
||||
|
||||
/**
|
||||
* Displays the status of the membership.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param WP_Ultimo\Models\Membership $item Membership object.
|
||||
* @return string
|
||||
*/
|
||||
public function column_status($item) {
|
||||
|
||||
$label = $item->get_status_label();
|
||||
|
||||
$class = $item->get_status_class();
|
||||
|
||||
return "<span class='wu-bg-gray-200 wu-text-gray-700 wu-py-1 wu-px-2 wu-rounded-sm wu-text-xs wu-font-mono $class'>{$label}</span>";
|
||||
|
||||
} // end column_status;
|
||||
|
||||
/**
|
||||
* Displays the price of the membership.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param WP_Ultimo\Models\Membership $item Membership object.
|
||||
* @return string
|
||||
*/
|
||||
public function column_amount($item) {
|
||||
|
||||
if (empty($item->get_amount())) {
|
||||
|
||||
return __('Free', 'wp-ultimo');
|
||||
|
||||
} // end if;
|
||||
|
||||
$amount = wu_format_currency($item->get_amount(), $item->get_currency());
|
||||
|
||||
if ($item->is_recurring()) {
|
||||
|
||||
$duration = $item->get_duration();
|
||||
|
||||
$message = sprintf(
|
||||
// translators: %1$s is the formatted price, %2$s the duration, and %3$s the duration unit (day, week, month, etc)
|
||||
_n('every %2$s', 'every %1$s %2$s', $duration, 'wp-ultimo'), // phpcs:ignore
|
||||
$duration,
|
||||
$item->get_duration_unit()
|
||||
);
|
||||
|
||||
if (!$item->is_forever_recurring()) {
|
||||
|
||||
$billing_cycles_message = sprintf(
|
||||
// translators: %s is the number of billing cycles.
|
||||
_n('for %s cycle', 'for %s cycles', $item->get_billing_cycles(), 'wp-ultimo'),
|
||||
$item->get_billing_cycles()
|
||||
);
|
||||
|
||||
$message .= ' ' . $billing_cycles_message;
|
||||
|
||||
} // end if;
|
||||
|
||||
} else {
|
||||
|
||||
$message = __('one time payment', 'wp-ultimo');
|
||||
|
||||
} // end if;
|
||||
|
||||
return sprintf('%s<br><small>%s</small>', $amount, $message);
|
||||
|
||||
} // end column_amount;
|
||||
|
||||
/**
|
||||
* Displays the customer of the membership.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param WP_Ultimo\Models\Membership $item Membership object.
|
||||
* @return string
|
||||
*/
|
||||
public function column_customer($item) {
|
||||
|
||||
$customer = $item->get_customer();
|
||||
|
||||
if (!$customer) {
|
||||
|
||||
$not_found = __('No customer found', 'wp-ultimo');
|
||||
|
||||
return "<div class='wu-py-1 wu-px-2 wu-flex-grow wu-block wu-rounded wu-items-center wu-border wu-border-solid wu-border-gray-300 wu-bg-gray-100 wu-relative wu-overflow-hidden'>
|
||||
<span class='dashicons dashicons-wu-block wu-text-gray-600 wu-px-1 wu-pr-3'> </span>
|
||||
<div class=''>
|
||||
<span class='wu-block wu-py-3 wu-text-gray-600 wu-text-2xs wu-font-bold wu-uppercase'>{$not_found}</span>
|
||||
</div>
|
||||
</div>";
|
||||
|
||||
} // end if;
|
||||
|
||||
$url_atts = array(
|
||||
'id' => $customer->get_id(),
|
||||
);
|
||||
|
||||
$avatar = get_avatar($customer->get_user_id(), 32, 'identicon', '', array(
|
||||
'force_display' => true,
|
||||
'class' => 'wu-rounded-full wu-mr-2',
|
||||
));
|
||||
|
||||
$display_name = $customer->get_display_name();
|
||||
|
||||
$id = $customer->get_id();
|
||||
|
||||
$email = $customer->get_email_address();
|
||||
|
||||
$customer_link = wu_network_admin_url('wp-ultimo-edit-customer', $url_atts);
|
||||
|
||||
$html = "<a href='{$customer_link}' class='wu-p-1 wu-flex-grow wu-bg-gray-100 wu-block wu-rounded wu-items-center wu-border wu-border-solid wu-border-gray-300'>
|
||||
<div class=''>
|
||||
<strong class='wu-block'>{$display_name} <small class='wu-font-normal'>(#{$id})</small></strong>
|
||||
|
||||
</div>
|
||||
</a>";
|
||||
|
||||
return $html;
|
||||
|
||||
} // end column_customer;
|
||||
|
||||
/**
|
||||
* Returns the list of columns for this particular List Table.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return array
|
||||
*/
|
||||
public function get_columns() {
|
||||
|
||||
$columns = array(
|
||||
'hash' => __('Ref.', 'wp-ultimo'),
|
||||
'status' => __('Status', 'wp-ultimo'),
|
||||
'customer' => __('Customer', 'wp-ultimo'),
|
||||
'amount' => __('Price', 'wp-ultimo'),
|
||||
);
|
||||
|
||||
return $columns;
|
||||
|
||||
} // end get_columns;
|
||||
/**
|
||||
* Overrides the parent method to include the custom ajax functionality for WP Ultimo.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
public function _js_vars() {} // end _js_vars;
|
||||
|
||||
} // end class Membership_List_Table_Widget;
|
343
inc/list-tables/class-membership-list-table.php
Normal file
343
inc/list-tables/class-membership-list-table.php
Normal file
@ -0,0 +1,343 @@
|
||||
<?php
|
||||
/**
|
||||
* Membership List Table class.
|
||||
*
|
||||
* @package WP_Ultimo
|
||||
* @subpackage List_Table
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\List_Tables;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* Membership List Table class.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
class Membership_List_Table extends Base_List_Table {
|
||||
|
||||
/**
|
||||
* Holds the query class for the object being listed.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var string
|
||||
*/
|
||||
protected $query_class = '\\WP_Ultimo\\Database\\Memberships\\Membership_Query';
|
||||
|
||||
/**
|
||||
* Initializes the table.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
parent::__construct(array(
|
||||
'singular' => __('Membership', 'wp-ultimo'), // singular name of the listed records
|
||||
'plural' => __('Memberships', 'wp-ultimo'), // plural name of the listed records
|
||||
'ajax' => true, // does this table support ajax?
|
||||
'add_new' => array(
|
||||
'url' => wu_get_form_url('add_new_membership'),
|
||||
'classes' => 'wubox',
|
||||
),
|
||||
));
|
||||
|
||||
} // end __construct;
|
||||
|
||||
/**
|
||||
* Adds the extra search field when the search element is present.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return array
|
||||
*/
|
||||
public function get_extra_query_fields() {
|
||||
|
||||
$_filter_fields = parent::get_extra_query_fields();
|
||||
|
||||
$search = isset($_GET['s']) ? sanitize_text_field($_GET['s']) : false;
|
||||
|
||||
$_filter_fields['customer_id'] = wu_request('customer_id');
|
||||
|
||||
return $_filter_fields;
|
||||
|
||||
} // end get_extra_query_fields;
|
||||
|
||||
/**
|
||||
* Displays the membership reference code.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param WP_Ultimo\Models\Membership $item Membership object.
|
||||
* @return string
|
||||
*/
|
||||
public function column_hash($item) {
|
||||
|
||||
$url_atts = array(
|
||||
'id' => $item->get_id(),
|
||||
'model' => 'membership',
|
||||
);
|
||||
|
||||
$code = sprintf('<a href="%s">%s</a>', wu_network_admin_url('wp-ultimo-edit-membership', $url_atts), $item->get_hash());
|
||||
|
||||
$actions = array(
|
||||
'edit' => sprintf('<a href="%s">%s</a>', wu_network_admin_url('wp-ultimo-edit-membership', $url_atts), __('Edit', 'wp-ultimo')),
|
||||
'delete' => sprintf(
|
||||
'<a title="%s" class="wubox" href="%s">%s</a>',
|
||||
__('Delete', 'wp-ultimo'),
|
||||
wu_get_form_url(
|
||||
'delete_modal',
|
||||
$url_atts
|
||||
),
|
||||
__('Delete', 'wp-ultimo')
|
||||
),
|
||||
);
|
||||
|
||||
$html = "<span class='wu-font-mono'><strong>{$code}</strong></span>";
|
||||
|
||||
return $html . $this->row_actions($actions);
|
||||
|
||||
} // end column_hash;
|
||||
|
||||
/**
|
||||
* Displays the status of the membership.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param WP_Ultimo\Models\Membership $item Membership object.
|
||||
* @return string
|
||||
*/
|
||||
public function column_status($item) {
|
||||
|
||||
$label = $item->get_status_label();
|
||||
|
||||
$class = $item->get_status_class();
|
||||
|
||||
$html = "<span class='wu-bg-gray-200 wu-leading-none wu-text-gray-700 wu-py-1 wu-px-2 wu-rounded-sm wu-text-xs wu-font-mono $class'>{$label}</span>";
|
||||
|
||||
return $html;
|
||||
|
||||
} // end column_status;
|
||||
|
||||
/**
|
||||
* Displays the price of the membership.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param WP_Ultimo\Models\Membership $item Membership object.
|
||||
* @return string
|
||||
*/
|
||||
public function column_amount($item) {
|
||||
|
||||
if (empty($item->get_amount()) && empty($item->get_initial_amount())) {
|
||||
|
||||
return __('Free', 'wp-ultimo');
|
||||
|
||||
} // end if;
|
||||
|
||||
if ($item->is_recurring()) {
|
||||
|
||||
$amount = wu_format_currency($item->get_amount(), $item->get_currency());
|
||||
|
||||
$duration = $item->get_duration();
|
||||
|
||||
$message = sprintf(
|
||||
// translators: %1$s is the formatted price, %2$s the duration, and %3$s the duration unit (day, week, month, etc)
|
||||
_n('every %2$s', 'every %1$s %2$s', $duration, 'wp-ultimo'), // phpcs:ignore
|
||||
$duration,
|
||||
$item->get_duration_unit()
|
||||
);
|
||||
|
||||
if (!$item->is_forever_recurring()) {
|
||||
|
||||
$billing_cycles_message = sprintf(
|
||||
// translators: %s is the number of billing cycles.
|
||||
_n('for %s cycle', 'for %s cycles', $item->get_billing_cycles(), 'wp-ultimo'),
|
||||
$item->get_billing_cycles()
|
||||
);
|
||||
|
||||
$message .= ' ' . $billing_cycles_message;
|
||||
|
||||
} // end if;
|
||||
|
||||
} else {
|
||||
|
||||
$amount = wu_format_currency($item->get_initial_amount(), $item->get_currency());
|
||||
|
||||
$message = __('one time payment', 'wp-ultimo');
|
||||
|
||||
} // end if;
|
||||
|
||||
return sprintf('%s<br><small>%s</small>', $amount, $message);
|
||||
|
||||
} // end column_amount;
|
||||
|
||||
/**
|
||||
* Returns the list of columns for this particular List Table.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return array
|
||||
*/
|
||||
public function get_columns() {
|
||||
|
||||
$columns = array(
|
||||
'cb' => '<input type="checkbox" />',
|
||||
'hash' => wu_tooltip(__('Reference Code', 'wp-ultimo'), 'dashicons-wu-hash wu-text-xs'),
|
||||
'status' => __('Status', 'wp-ultimo'),
|
||||
'customer' => __('Customer', 'wp-ultimo'),
|
||||
'product' => __('Product', 'wp-ultimo'),
|
||||
'amount' => __('Price', 'wp-ultimo'),
|
||||
// 'sites' => __('Sites', 'wp-ultimo'),
|
||||
'date_created' => __('Created at', 'wp-ultimo'),
|
||||
'date_expiration' => __('Expiration', 'wp-ultimo'),
|
||||
'id' => __('ID', 'wp-ultimo'),
|
||||
);
|
||||
|
||||
return $columns;
|
||||
|
||||
} // end get_columns;
|
||||
|
||||
/**
|
||||
* Handles the default displaying of datetime columns.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param self $item The membership.
|
||||
* @return string
|
||||
*/
|
||||
public function column_date_expiration($item) {
|
||||
|
||||
$date = $item->get_date_expiration();
|
||||
|
||||
if (empty($date) || $date === '0000-00-00 00:00:00') {
|
||||
|
||||
return sprintf('<span>%s</span><br><small>%s</small>', __('Lifetime', 'wp-ultimo'), __('It never expires', 'wp-ultimo'));
|
||||
|
||||
} // end if;
|
||||
|
||||
if (!wu_validate_date($date)) {
|
||||
|
||||
return __('--', 'wp-ultimo');
|
||||
|
||||
} // end if;
|
||||
|
||||
$time = strtotime(get_date_from_gmt($date));
|
||||
|
||||
$formatted_value = date_i18n(get_option('date_format'), $time);
|
||||
|
||||
$placeholder = wu_get_current_time('timestamp') > $time ? __('%s ago', 'wp-ultimo') : __('In %s', 'wp-ultimo'); // phpcs:ignore
|
||||
|
||||
$text = $formatted_value . sprintf('<br><small>%s</small>', sprintf($placeholder, human_time_diff($time)));
|
||||
|
||||
return sprintf('<span %s>%s</span>', wu_tooltip_text(date_i18n('Y-m-d H:i:s', $time)), $text);
|
||||
|
||||
} // end column_date_expiration;
|
||||
|
||||
/**
|
||||
* Returns the filters for this page.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function get_filters(): array {
|
||||
|
||||
$membership_status = new \WP_Ultimo\Database\Memberships\Membership_Status();
|
||||
|
||||
return array(
|
||||
'filters' => array(
|
||||
|
||||
/**
|
||||
* Status
|
||||
*/
|
||||
'status' => array(
|
||||
'label' => __( 'Status', 'wp-ultimo' ),
|
||||
'options' => $membership_status::to_array(),
|
||||
),
|
||||
|
||||
),
|
||||
'date_filters' => array(
|
||||
|
||||
/**
|
||||
* Created At
|
||||
*/
|
||||
'date_created' => array(
|
||||
'label' => __('Created At', 'wp-ultimo'),
|
||||
'options' => $this->get_default_date_filter_options(),
|
||||
),
|
||||
|
||||
/**
|
||||
* Expiration Date
|
||||
*/
|
||||
'date_expiration' => array(
|
||||
'label' => __('Expiration Date', 'wp-ultimo'),
|
||||
'options' => $this->get_default_date_filter_options(),
|
||||
),
|
||||
|
||||
/**
|
||||
* Renewal Date
|
||||
*/
|
||||
'date_renewed' => array(
|
||||
'label' => __('Renewal Date', 'wp-ultimo'),
|
||||
'options' => $this->get_default_date_filter_options(),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
} // end get_filters;
|
||||
|
||||
/**
|
||||
* Returns the pre-selected filters on the filter bar.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return array
|
||||
*/
|
||||
public function get_views() {
|
||||
|
||||
return array(
|
||||
'all' => array(
|
||||
'field' => 'status',
|
||||
'url' => add_query_arg('status', 'all'),
|
||||
'label' => __('All Memberships', 'wp-ultimo'),
|
||||
'count' => 0,
|
||||
),
|
||||
'active' => array(
|
||||
'field' => 'status',
|
||||
'url' => add_query_arg('status', 'active'),
|
||||
'label' => __('Active', 'wp-ultimo'),
|
||||
'count' => 0,
|
||||
),
|
||||
'trialing' => array(
|
||||
'field' => 'status',
|
||||
'url' => add_query_arg('status', 'trialing'),
|
||||
'label' => __('Trialing', 'wp-ultimo'),
|
||||
'count' => 0,
|
||||
),
|
||||
'pending' => array(
|
||||
'field' => 'status',
|
||||
'url' => add_query_arg('status', 'pending'),
|
||||
'label' => __('Pending', 'wp-ultimo'),
|
||||
'count' => 0,
|
||||
),
|
||||
'on-hold' => array(
|
||||
'field' => 'status',
|
||||
'url' => add_query_arg('status', 'on-hold'),
|
||||
'label' => __('On Hold', 'wp-ultimo'),
|
||||
'count' => 0,
|
||||
),
|
||||
'expired' => array(
|
||||
'field' => 'status',
|
||||
'url' => add_query_arg('status', 'expired'),
|
||||
'label' => __('Expired', 'wp-ultimo'),
|
||||
'count' => 0,
|
||||
),
|
||||
'cancelled' => array(
|
||||
'field' => 'status',
|
||||
'url' => add_query_arg('status', 'cancelled'),
|
||||
'label' => __('Cancelled', 'wp-ultimo'),
|
||||
'count' => 0,
|
||||
),
|
||||
);
|
||||
|
||||
} // end get_views;
|
||||
|
||||
} // end class Membership_List_Table;
|
82
inc/list-tables/class-memberships-site-list-table.php
Normal file
82
inc/list-tables/class-memberships-site-list-table.php
Normal file
@ -0,0 +1,82 @@
|
||||
<?php
|
||||
/**
|
||||
* Customers Site List Table class.
|
||||
*
|
||||
* @package WP_Ultimo
|
||||
* @subpackage List_Table
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\List_Tables;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* Site List Table class.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
class Memberships_Site_List_Table extends Customers_Site_List_Table {
|
||||
|
||||
/**
|
||||
* Returns the list of columns for this particular List Table.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return array
|
||||
*/
|
||||
public function get_columns() {
|
||||
|
||||
$columns = array(
|
||||
'responsive' => '',
|
||||
);
|
||||
|
||||
return $columns;
|
||||
|
||||
} // end get_columns;
|
||||
|
||||
/**
|
||||
* Renders the inside column responsive.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param object $item The item being rendered.
|
||||
* @return void
|
||||
*/
|
||||
public function column_responsive($item) {
|
||||
|
||||
$redirect = current_user_can('wu_edit_sites') ? 'wp-ultimo-edit-site' : 'wp-ultimo-sites';
|
||||
|
||||
echo wu_responsive_table_row(array(
|
||||
'id' => $item->get_id(),
|
||||
'title' => $item->get_title(),
|
||||
'url' => wu_network_admin_url($redirect, array(
|
||||
'id' => $item->get_id(),
|
||||
)),
|
||||
'image' => $this->column_featured_image_id($item),
|
||||
'status' => $this->column_type($item),
|
||||
), array(
|
||||
'link' => array(
|
||||
'icon' => 'dashicons-wu-link1 wu-align-middle wu-mr-1',
|
||||
'label' => __('Visit Site', 'wp-ultimo'),
|
||||
'value' => __('Homepage', 'wp-ultimo'),
|
||||
'url' => $item->get_active_site_url(),
|
||||
),
|
||||
'dashboard' => array(
|
||||
'icon' => 'dashicons-wu-browser wu-align-middle wu-mr-1',
|
||||
'label' => __('Go to the Dashboard', 'wp-ultimo'),
|
||||
'value' => __('Dashboard', 'wp-ultimo'),
|
||||
'url' => get_admin_url($item->get_id()),
|
||||
),
|
||||
),
|
||||
array(
|
||||
'date_created' => array(
|
||||
'icon' => 'dashicons-wu-calendar1 wu-align-middle wu-mr-1',
|
||||
'label' => '',
|
||||
'value' => $item->get_type() === 'pending' ? __('Not Available', 'wp-ultimo') : sprintf(__('Created %s', 'wp-ultimo'), wu_human_time_diff(strtotime((string) $item->get_date_registered()))),
|
||||
),
|
||||
));
|
||||
|
||||
} // end column_responsive;
|
||||
|
||||
} // end class Memberships_Site_List_Table;
|
157
inc/list-tables/class-payment-line-item-list-table.php
Normal file
157
inc/list-tables/class-payment-line-item-list-table.php
Normal file
@ -0,0 +1,157 @@
|
||||
<?php
|
||||
/**
|
||||
* Payment List Table class.
|
||||
*
|
||||
* @package WP_Ultimo
|
||||
* @subpackage List_Table
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\List_Tables;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* Payment List Table class.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
class Payment_Line_Item_List_Table extends Line_Item_List_Table {
|
||||
|
||||
/**
|
||||
* Returns the list of columns for this particular List Table.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return array
|
||||
*/
|
||||
public function get_columns() {
|
||||
|
||||
$columns = array(
|
||||
'responsive' => '',
|
||||
);
|
||||
|
||||
return $columns;
|
||||
|
||||
} // end get_columns;
|
||||
|
||||
/**
|
||||
* Renders the inside column responsive.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param object $item The item being rendered.
|
||||
* @return void
|
||||
*/
|
||||
public function column_responsive($item) {
|
||||
|
||||
$product = $item->get_product();
|
||||
|
||||
$first_row = array(
|
||||
'quantity' => array(
|
||||
'icon' => 'dashicons-wu-package wu-align-middle wu-mr-1',
|
||||
'label' => __('Quantity', 'wp-ultimo'),
|
||||
'value' => sprintf(__('x%d', 'wp-ultimo'), $item->get_quantity()),
|
||||
),
|
||||
'unit_price' => array(
|
||||
'icon' => 'dashicons-wu-info1 wu-align-middle wu-mr-1',
|
||||
'label' => __('Unit Price', 'wp-ultimo'),
|
||||
'value' => wu_format_currency($item->get_unit_price()),
|
||||
),
|
||||
);
|
||||
|
||||
$second_row = array();
|
||||
|
||||
$url_atts = array(
|
||||
'id' => $this->get_payment()->get_id(),
|
||||
'line_item_id' => $item->get_id(),
|
||||
);
|
||||
|
||||
$second_row['change'] = array(
|
||||
'wrapper_classes' => 'wubox',
|
||||
'icon' => 'dashicons-wu-edit1 wu-align-middle wu-mr-1',
|
||||
'label' => '',
|
||||
'value' => __('Edit', 'wp-ultimo'),
|
||||
'url' => wu_get_form_url('edit_line_item', $url_atts),
|
||||
);
|
||||
|
||||
$second_row['remove'] = array(
|
||||
'wrapper_classes' => 'wu-text-red-500 wubox',
|
||||
'icon' => 'dashicons-wu-trash-2 wu-align-middle wu-mr-1',
|
||||
'label' => '',
|
||||
'value' => __('Remove', 'wp-ultimo'),
|
||||
'url' => wu_get_form_url('delete_line_item', $url_atts),
|
||||
);
|
||||
|
||||
/*
|
||||
* Adds discounts
|
||||
*/
|
||||
if ($item->get_discount_total()) {
|
||||
|
||||
if ($item->get_discount_type() === 'percentage' && $item->get_discount_rate()) {
|
||||
|
||||
$tax_rate = $item->get_discount_rate() . '%';
|
||||
|
||||
} // end if;
|
||||
|
||||
$tax_label = $item->get_discount_rate() ? ($item->get_discount_label() ? $item->get_discount_label() : __('Discount', 'wp-ultimo')) : __('No discount', 'wp-ultimo');
|
||||
|
||||
$tooltip = sprintf('%s (%s)', $tax_rate, $tax_label);
|
||||
|
||||
$first_row['discounts_total'] = array(
|
||||
'icon' => 'dashicons-wu-percent wu-align-middle wu-mr-1',
|
||||
'label' => $tooltip,
|
||||
'value' => sprintf(__('Discounts: %s', 'wp-ultimo'), wu_format_currency($item->get_discount_total())),
|
||||
);
|
||||
|
||||
} // end if;
|
||||
|
||||
$first_row['subtotal'] = array(
|
||||
'icon' => 'dashicons-wu-info1 wu-align-middle wu-mr-1',
|
||||
'label' => '',
|
||||
'value' => sprintf(__('Subtotal: %s', 'wp-ultimo'), wu_format_currency($item->get_subtotal())),
|
||||
);
|
||||
|
||||
/*
|
||||
* Adds Taxes
|
||||
*/
|
||||
if ($item->get_tax_total()) {
|
||||
|
||||
if ($item->get_tax_type() === 'percentage' && $item->get_tax_rate()) {
|
||||
|
||||
$tax_rate = $item->get_tax_rate() . '%';
|
||||
|
||||
} // end if;
|
||||
|
||||
$tax_label = $item->get_tax_rate() ? ($item->get_tax_label() ? $item->get_tax_label() : __('Tax Applied', 'wp-ultimo')) : __('No Taxes Applied', 'wp-ultimo');
|
||||
|
||||
$tooltip = sprintf('%s (%s)', $tax_rate, $tax_label);
|
||||
|
||||
$first_row['tax_total'] = array(
|
||||
'icon' => 'dashicons-wu-percent wu-align-middle wu-mr-1',
|
||||
'label' => $tooltip,
|
||||
'value' => sprintf(__('Taxes: %s', 'wp-ultimo'), wu_format_currency($item->get_tax_total())),
|
||||
);
|
||||
|
||||
} // end if;
|
||||
|
||||
$first_row['description'] = array(
|
||||
'icon' => 'dashicons-wu-file-text wu-align-middle wu-mr-1',
|
||||
'label' => __('Item Description', 'wp-ultimo'),
|
||||
'value' => $item->get_description(),
|
||||
);
|
||||
|
||||
echo wu_responsive_table_row(array(
|
||||
'id' => '',
|
||||
'title' => $item->get_title(),
|
||||
'url' => '',
|
||||
'image' => '',
|
||||
'status' => sprintf('<span class="wu-text-sm wu-font-medium wu-text-gray-700">%s</span>', wu_format_currency($item->get_total())),
|
||||
),
|
||||
$first_row,
|
||||
$second_row
|
||||
);
|
||||
|
||||
} // end column_responsive;
|
||||
|
||||
} // end class Payment_Line_Item_List_Table;
|
253
inc/list-tables/class-payment-list-table-widget.php
Normal file
253
inc/list-tables/class-payment-list-table-widget.php
Normal file
@ -0,0 +1,253 @@
|
||||
<?php
|
||||
/**
|
||||
* Payment List Table class.
|
||||
*
|
||||
* @package WP_Ultimo
|
||||
* @subpackage List_Table
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\List_Tables;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
use \WP_Ultimo\Helpers\Hash;
|
||||
|
||||
/**
|
||||
* Payment List Table class.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
class Payment_List_Table_Widget extends Base_List_Table {
|
||||
|
||||
/**
|
||||
* Holds the query class for the object being listed.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var string
|
||||
*/
|
||||
protected $query_class = '\\WP_Ultimo\\Database\\Payments\\Payment_Query';
|
||||
|
||||
/**
|
||||
* Initializes the table.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
parent::__construct(array(
|
||||
'singular' => __('Payment', 'wp-ultimo'), // singular name of the listed records
|
||||
'plural' => __('Payments', 'wp-ultimo'), // plural name of the listed records
|
||||
'ajax' => true // does this table support ajax?
|
||||
));
|
||||
|
||||
} // end __construct;
|
||||
|
||||
/**
|
||||
* Uses the query class to return the items to be displayed.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param integer $per_page Number of items to display per page.
|
||||
* @param integer $page_number Current page.
|
||||
* @param boolean $count If we should count records or return the actual records.
|
||||
* @return array
|
||||
*/
|
||||
public function get_items($per_page = 5, $page_number = 1, $count = false) {
|
||||
|
||||
$query_class = new $this->query_class();
|
||||
|
||||
$query_args = array(
|
||||
'number' => 5,
|
||||
'offset' => 1,
|
||||
'orderby' => wu_request('orderby', 'date_created'),
|
||||
'order' => wu_request('order', 'DESC'),
|
||||
'search' => wu_request('s', false),
|
||||
'count' => $count,
|
||||
);
|
||||
|
||||
/**
|
||||
* Accounts for hashes
|
||||
*/
|
||||
if (isset($query_args['search']) && strlen((string) $query_args['search']) === Hash::LENGTH) {
|
||||
|
||||
$item_id = Hash::decode($query_args['search']);
|
||||
|
||||
if ($item_id) {
|
||||
|
||||
unset($query_args['search']);
|
||||
|
||||
$query_args['id'] = $item_id;
|
||||
|
||||
} // end if;
|
||||
|
||||
} // end if;
|
||||
|
||||
$query_args = array_merge($query_args, $this->get_extra_query_fields());
|
||||
|
||||
$query_args = apply_filters("wu_{$this->id}_get_items", $query_args, $this);
|
||||
|
||||
$function_name = 'wu_get_' . $query_class->get_plural_name();
|
||||
|
||||
if (function_exists($function_name)) {
|
||||
|
||||
$query = $function_name($query_args);
|
||||
|
||||
} else {
|
||||
|
||||
$query = $query_class->query($query_args);
|
||||
|
||||
} // end if;
|
||||
|
||||
return $query;
|
||||
|
||||
} // end get_items;
|
||||
/**
|
||||
* Displays the payment reference code.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param WP_Ultimo\Models\Payment $item Payment object.
|
||||
*/
|
||||
public function column_hash($item): string {
|
||||
|
||||
$url_atts = array(
|
||||
'id' => $item->get_id(),
|
||||
);
|
||||
|
||||
$code = sprintf('<a href="%s">%s</a>', wu_network_admin_url('wp-ultimo-edit-payment', $url_atts), $item->get_hash());
|
||||
|
||||
$actions = array(
|
||||
'edit' => sprintf('<a href="%s">%s</a>', wu_network_admin_url('wp-ultimo-edit-payment', $url_atts), __('Edit', 'wp-ultimo')),
|
||||
'delete' => sprintf('<a href="%s">%s</a>', '', __('Delete', 'wp-ultimo')),
|
||||
);
|
||||
|
||||
$html = "<span class='wu-font-mono'><strong>{$code}</strong></span>";
|
||||
|
||||
return $html . $this->row_actions($actions);
|
||||
|
||||
} // end column_hash;
|
||||
|
||||
/**
|
||||
* Displays the membership photo and special status.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param WP_Ultimo\Models\Payment $item Payment object.
|
||||
* @return string
|
||||
*/
|
||||
public function column_status($item) {
|
||||
|
||||
$label = $item->get_status_label();
|
||||
|
||||
$class = $item->get_status_class();
|
||||
|
||||
return "<span class='wu-bg-gray-200 wu-text-gray-700 wu-py-1 wu-px-2 wu-rounded-sm wu-text-xs wu-font-mono $class'>{$label}</span>";
|
||||
|
||||
} // end column_status;
|
||||
|
||||
|
||||
/**
|
||||
* Displays the customer of the membership.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param WP_Ultimo\Models\Membership $item Membership object.
|
||||
* @return string
|
||||
*/
|
||||
public function column_customer($item) {
|
||||
|
||||
$customer = $item->get_customer();
|
||||
|
||||
if (!$customer) {
|
||||
|
||||
$not_found = __('No customer found', 'wp-ultimo');
|
||||
|
||||
return "<div class='wu-py-1 wu-px-2 wu-flex wu-flex-grow wu-rounded wu-items-center wu-border wu-border-solid wu-border-gray-300 wu-bg-gray-100 wu-relative wu-overflow-hidden'>
|
||||
<span class='dashicons dashicons-wu-block wu-text-gray-600 wu-px-1 wu-pr-3'> </span>
|
||||
<div class=''>
|
||||
<span class='wu-block wu-py-3 wu-text-gray-600 wu-text-2xs wu-font-bold wu-uppercase'>{$not_found}</span>
|
||||
</div>
|
||||
</div>";
|
||||
|
||||
} // end if;
|
||||
|
||||
$url_atts = array(
|
||||
'id' => $customer->get_id(),
|
||||
);
|
||||
|
||||
$avatar = get_avatar($customer->get_user_id(), 32, 'identicon', '', array(
|
||||
'force_display' => true,
|
||||
'class' => 'wu-rounded-full wu-mr-2',
|
||||
));
|
||||
|
||||
$display_name = $customer->get_display_name();
|
||||
|
||||
$id = $customer->get_id();
|
||||
|
||||
$email = $customer->get_email_address();
|
||||
|
||||
$customer_link = wu_network_admin_url('wp-ultimo-edit-customer', $url_atts);
|
||||
|
||||
$html = "<a href='{$customer_link}' class='wu-p-1 wu-flex wu-flex-grow wu-bg-gray-100 wu-rounded wu-items-center wu-border wu-border-solid wu-border-gray-300'>
|
||||
<div class=''>
|
||||
<strong class='wu-block'>{$display_name} <small class='wu-font-normal'>(#{$id})</small></strong>
|
||||
|
||||
</div>
|
||||
</a>";
|
||||
|
||||
return $html;
|
||||
|
||||
} // end column_customer;
|
||||
/**
|
||||
* Displays the column for the total amount of the payment.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param WP_Ultimo\Models\Payment $item Payment object.
|
||||
*/
|
||||
public function column_total($item): string {
|
||||
|
||||
$gateway = wu_slug_to_name($item->get_gateway());
|
||||
|
||||
return wu_format_currency($item->get_total()) . "<small class='wu-block'>{$gateway}</small>";
|
||||
|
||||
} // end column_total;
|
||||
|
||||
/**
|
||||
* Returns the list of columns for this particular List Table.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return array
|
||||
*/
|
||||
public function get_columns() {
|
||||
|
||||
$columns = array(
|
||||
'hash' => __('Ref.', 'wp-ultimo'),
|
||||
'customer' => __('Customer', 'wp-ultimo'),
|
||||
'total' => __('Total', 'wp-ultimo'),
|
||||
'date_created' => __('Created at', 'wp-ultimo'),
|
||||
);
|
||||
|
||||
return $columns;
|
||||
|
||||
} // end get_columns;
|
||||
|
||||
/**
|
||||
* Returns the filters for this page.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return void.
|
||||
*/
|
||||
public function get_filters() {} // end get_filters;
|
||||
|
||||
/**
|
||||
* Overrides the parent method to include the custom ajax functionality for WP Ultimo.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
public function _js_vars() {} // end _js_vars;
|
||||
|
||||
} // end class Payment_List_Table_Widget;
|
300
inc/list-tables/class-payment-list-table.php
Normal file
300
inc/list-tables/class-payment-list-table.php
Normal file
@ -0,0 +1,300 @@
|
||||
<?php
|
||||
/**
|
||||
* Payment List Table class.
|
||||
*
|
||||
* @package WP_Ultimo
|
||||
* @subpackage List_Table
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\List_Tables;
|
||||
|
||||
use \WP_Ultimo\Database\Payments\Payment_Status;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* Payment List Table class.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
class Payment_List_Table extends Base_List_Table {
|
||||
|
||||
/**
|
||||
* Holds the query class for the object being listed.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var string
|
||||
*/
|
||||
protected $query_class = '\\WP_Ultimo\\Database\\Payments\\Payment_Query';
|
||||
|
||||
/**
|
||||
* Initializes the table.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
parent::__construct(array(
|
||||
'singular' => __('Payment', 'wp-ultimo'),
|
||||
'plural' => __('Payments', 'wp-ultimo'),
|
||||
'ajax' => true,
|
||||
'add_new' => array(
|
||||
'url' => wu_get_form_url('add_new_payment'),
|
||||
'classes' => 'wubox',
|
||||
),
|
||||
));
|
||||
|
||||
} // end __construct;
|
||||
|
||||
/**
|
||||
* Adds the extra search field when the search element is present.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return array
|
||||
*/
|
||||
public function get_extra_query_fields() {
|
||||
|
||||
$_filter_fields = parent::get_extra_query_fields();
|
||||
|
||||
$search = isset($_GET['s']) ? sanitize_text_field($_GET['s']) : false;
|
||||
|
||||
$_filter_fields['membership_id'] = wu_request('membership_id', false);
|
||||
|
||||
$_filter_fields['customer_id'] = wu_request('customer_id', false);
|
||||
|
||||
$_filter_fields['parent_id__in'] = array('0', 0, '', null);
|
||||
|
||||
return $_filter_fields;
|
||||
|
||||
} // end get_extra_query_fields;
|
||||
|
||||
/**
|
||||
* Displays the payment reference code.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param WP_Ultimo\Models\Payment $item Payment object.
|
||||
* @return string
|
||||
*/
|
||||
public function column_hash($item) {
|
||||
|
||||
$url_atts = array(
|
||||
'id' => $item->get_id(),
|
||||
);
|
||||
|
||||
$code = sprintf('<a href="%s">%s</a>', wu_network_admin_url('wp-ultimo-edit-payment', $url_atts), $item->get_hash());
|
||||
|
||||
$actions = array(
|
||||
'edit' => sprintf('<a href="%s">%s</a>', wu_network_admin_url('wp-ultimo-edit-payment', $url_atts), __('Edit', 'wp-ultimo')),
|
||||
'delete' => sprintf(
|
||||
'<a title="%s" class="wubox" href="%s">%s</a>',
|
||||
__('Delete', 'wp-ultimo'),
|
||||
wu_get_form_url(
|
||||
'delete_modal',
|
||||
array(
|
||||
'model' => 'payment',
|
||||
'id' => $item->get_id()
|
||||
)
|
||||
),
|
||||
__('Delete', 'wp-ultimo')
|
||||
),
|
||||
);
|
||||
|
||||
$html = "<span class='wu-font-mono'><strong>{$code}</strong></span>";
|
||||
|
||||
return $html . $this->row_actions($actions);
|
||||
|
||||
} // end column_hash;
|
||||
|
||||
/**
|
||||
* Displays the membership photo and special status.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param WP_Ultimo\Models\Payment $item Payment object.
|
||||
* @return string
|
||||
*/
|
||||
public function column_status($item) {
|
||||
|
||||
$label = $item->get_status_label();
|
||||
|
||||
$class = $item->get_status_class();
|
||||
|
||||
return "<span class='wu-bg-gray-200 wu-text-gray-700 wu-py-1 wu-px-2 wu-inline-block wu-leading-none wu-rounded-sm wu-text-xs wu-font-mono $class'>{$label}</span>";
|
||||
|
||||
} // end column_status;
|
||||
|
||||
/**
|
||||
* Returns the number of subscriptions owned by this membership.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param WP_Ultimo\Models\Payment $item Payment object.
|
||||
* @return string
|
||||
*/
|
||||
public function column_product($item) {
|
||||
|
||||
$product = $item->get_product();
|
||||
|
||||
if (!$product) {
|
||||
|
||||
return __('No product found', 'wp-ultimo');
|
||||
|
||||
} // end if;
|
||||
|
||||
$url_atts = array(
|
||||
'product_id' => $product->get_id(),
|
||||
);
|
||||
|
||||
$actions = array(
|
||||
'view' => sprintf('<a href="%s">%s</a>', wu_network_admin_url('wp-ultimo-edit-product', $url_atts), __('View', 'wp-ultimo')),
|
||||
);
|
||||
|
||||
$html = $product->get_name();
|
||||
|
||||
return $html . $this->row_actions($actions);
|
||||
|
||||
} // end column_product;
|
||||
|
||||
/**
|
||||
* Displays the column for the total amount of the payment.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param WP_Ultimo\Models\Payment $item Payment object.
|
||||
* @return string
|
||||
*/
|
||||
public function column_total($item) {
|
||||
|
||||
$gateway = wu_slug_to_name($item->get_gateway());
|
||||
|
||||
return wu_format_currency($item->get_total()) . "<small class='wu-block'>{$gateway}</small>";
|
||||
|
||||
} // end column_total;
|
||||
|
||||
/**
|
||||
* Returns the list of columns for this particular List Table.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return array
|
||||
*/
|
||||
public function get_columns() {
|
||||
|
||||
$columns = array(
|
||||
'cb' => '<input type="checkbox" />',
|
||||
'hash' => wu_tooltip(__('Reference Code', 'wp-ultimo'), 'dashicons-wu-hash wu-text-xs'),
|
||||
'status' => __('Status', 'wp-ultimo'),
|
||||
'customer' => __('Customer', 'wp-ultimo'),
|
||||
'membership' => __('Membership', 'wp-ultimo'),
|
||||
'total' => __('Total', 'wp-ultimo'),
|
||||
'date_created' => __('Created at', 'wp-ultimo'),
|
||||
'id' => __('ID', 'wp-ultimo'),
|
||||
);
|
||||
|
||||
return $columns;
|
||||
|
||||
} // end get_columns;
|
||||
|
||||
/**
|
||||
* Returns the filters for this page.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function get_filters(): array {
|
||||
|
||||
return array(
|
||||
'filters' => array(
|
||||
|
||||
/**
|
||||
* Status
|
||||
*/
|
||||
'status' => array(
|
||||
'label' => __( 'Status', 'wp-ultimo' ),
|
||||
'options' => array(
|
||||
'pending' => __( 'Pending', 'wp-ultimo' ),
|
||||
'completed' => __( 'Completed', 'wp-ultimo' ),
|
||||
'refund' => __( 'Refund', 'wp-ultimo' ),
|
||||
'partial' => __( 'Partial', 'wp-ultimo' ),
|
||||
'failed' => __( 'Failed', 'wp-ultimo' ),
|
||||
),
|
||||
),
|
||||
|
||||
/**
|
||||
* Gateway
|
||||
*/
|
||||
'gateway' => array(
|
||||
'label' => __( 'Gateway', 'wp-ultimo' ),
|
||||
'options' => array(
|
||||
'free' => __( 'Free', 'wp-ultimo' ),
|
||||
'manual' => __( 'Manual', 'wp-ultimo' ),
|
||||
'paypal' => __( 'Paypal', 'wp-ultimo' ),
|
||||
'stripe' => __( 'Stripe', 'wp-ultimo' ),
|
||||
),
|
||||
),
|
||||
),
|
||||
'date_filters' => array(
|
||||
|
||||
/**
|
||||
* Created At
|
||||
*/
|
||||
'date_created' => array(
|
||||
'label' => __( 'Created At', 'wp-ultimo' ),
|
||||
'options' => $this->get_default_date_filter_options(),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
} // end get_filters;
|
||||
|
||||
/**
|
||||
* Returns the pre-selected filters on the filter bar.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return array
|
||||
*/
|
||||
public function get_views() {
|
||||
|
||||
return array(
|
||||
'all' => array(
|
||||
'field' => 'status',
|
||||
'url' => add_query_arg('status', 'all'),
|
||||
'label' => __('All Payments', 'wp-ultimo'),
|
||||
'count' => 0,
|
||||
),
|
||||
Payment_Status::COMPLETED() => array(
|
||||
'field' => 'status',
|
||||
'url' => add_query_arg('status', Payment_Status::COMPLETED()),
|
||||
'label' => __('Completed', 'wp-ultimo'),
|
||||
'count' => 0,
|
||||
),
|
||||
Payment_Status::PENDING() => array(
|
||||
'field' => 'status',
|
||||
'url' => add_query_arg('status', Payment_Status::PENDING()),
|
||||
'label' => __('Pending', 'wp-ultimo'),
|
||||
'count' => 0,
|
||||
),
|
||||
Payment_Status::PARTIAL_REFUND() => array(
|
||||
'field' => 'status',
|
||||
'url' => add_query_arg('status', Payment_Status::PARTIAL_REFUND()),
|
||||
'label' => __('Partially Refunded', 'wp-ultimo'),
|
||||
'count' => 0,
|
||||
),
|
||||
Payment_Status::REFUND() => array(
|
||||
'field' => 'status',
|
||||
'url' => add_query_arg('status', Payment_Status::REFUND()),
|
||||
'label' => __('Refunded', 'wp-ultimo'),
|
||||
'count' => 0,
|
||||
),
|
||||
Payment_Status::FAILED() => array(
|
||||
'field' => 'status',
|
||||
'url' => add_query_arg('status', Payment_Status::FAILED()),
|
||||
'label' => __('Failed', 'wp-ultimo'),
|
||||
'count' => 0,
|
||||
),
|
||||
);
|
||||
|
||||
} // end get_views;
|
||||
|
||||
} // end class Payment_List_Table;
|
343
inc/list-tables/class-product-list-table.php
Normal file
343
inc/list-tables/class-product-list-table.php
Normal file
@ -0,0 +1,343 @@
|
||||
<?php
|
||||
/**
|
||||
* Product List Table class.
|
||||
*
|
||||
* @package WP_Ultimo
|
||||
* @subpackage List_Table
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\List_Tables;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* Product List Table class.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
class Product_List_Table extends Base_List_Table {
|
||||
|
||||
/**
|
||||
* Holds the query class for the object being listed.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var string
|
||||
*/
|
||||
protected $query_class = '\\WP_Ultimo\\Database\\Products\\Product_Query';
|
||||
|
||||
/**
|
||||
* Initializes the table.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
parent::__construct(array(
|
||||
'singular' => __('Product', 'wp-ultimo'), // singular name of the listed records
|
||||
'plural' => __('Products', 'wp-ultimo'), // plural name of the listed records
|
||||
'ajax' => true, // does this table support ajax?
|
||||
'add_new' => array(
|
||||
'url' => wu_network_admin_url('wp-ultimo-edit-product'),
|
||||
'classes' => '',
|
||||
),
|
||||
));
|
||||
|
||||
} // end __construct;
|
||||
|
||||
/**
|
||||
* Displays the content of the product column.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param WP_Ultimo\Models\Product $item Product object.
|
||||
* @return string
|
||||
*/
|
||||
public function column_name($item) {
|
||||
|
||||
$url_atts = array(
|
||||
'id' => $item->get_id(),
|
||||
'model' => 'product'
|
||||
);
|
||||
|
||||
$title = sprintf('<a href="%s">%s</a>', wu_network_admin_url('wp-ultimo-edit-product', $url_atts), $item->get_name());
|
||||
|
||||
// Concatenate the two blocks
|
||||
$title = "<strong>$title</strong>";
|
||||
|
||||
$actions = array(
|
||||
'edit' => sprintf('<a href="%s">%s</a>', wu_network_admin_url('wp-ultimo-edit-product', $url_atts), __('Edit', 'wp-ultimo')),
|
||||
'duplicate' => sprintf('<a href="%s">%s</a>', wu_network_admin_url('wp-ultimo-products', array('action' => 'duplicate', 'id' => $item->get_id())), __('Duplicate', 'wp-ultimo')),
|
||||
'delete' => sprintf('<a title="%s" class="wubox" href="%s">%s</a>', __('Delete', 'wp-ultimo'), wu_get_form_url('delete_modal', $url_atts), __('Delete', 'wp-ultimo')),
|
||||
);
|
||||
|
||||
return $title . $this->row_actions($actions);
|
||||
|
||||
} // end column_name;
|
||||
|
||||
/**
|
||||
* Displays the type of the product.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param WP_Ultimo\Models\Product $item Product object.
|
||||
* @return string
|
||||
*/
|
||||
public function column_type($item) {
|
||||
|
||||
$label = $item->get_type_label();
|
||||
|
||||
$class = $item->get_type_class();
|
||||
|
||||
return "<span class='wu-bg-gray-200 wu-text-gray-700 wu-leading-none wu-py-1 wu-px-2 wu-rounded-sm wu-text-xs wu-font-mono $class'>{$label}</span>";
|
||||
|
||||
} // end column_type;
|
||||
|
||||
/**
|
||||
* Displays the slug of the product.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param WP_Ultimo\Models\Product $item Product object.
|
||||
* @return string
|
||||
*/
|
||||
public function column_slug($item) {
|
||||
|
||||
$slug = $item->get_slug();
|
||||
|
||||
return "<span class='wu-bg-gray-200 wu-text-gray-700 wu-leading-none wu-py-1 wu-px-2 wu-rounded-sm wu-text-xs wu-font-mono'>{$slug}</span>";
|
||||
|
||||
} // end column_slug;
|
||||
|
||||
/**
|
||||
* Displays the price of the product.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param WP_Ultimo\Models\Product $item Product object.
|
||||
* @return string
|
||||
*/
|
||||
public function column_amount($item) {
|
||||
|
||||
if ($item->get_pricing_type() === 'contact_us') {
|
||||
|
||||
return __('None', 'wp-ultimo') . sprintf('<br><small>%s</small>', __('Requires contact', 'wp-ultimo'));
|
||||
|
||||
} // end if;
|
||||
|
||||
if (empty($item->get_amount())) {
|
||||
|
||||
return __('Free', 'wp-ultimo');
|
||||
|
||||
} // end if;
|
||||
|
||||
$amount = wu_format_currency($item->get_amount(), $item->get_currency());
|
||||
|
||||
if ($item->is_recurring()) {
|
||||
|
||||
$duration = $item->get_duration();
|
||||
|
||||
$message = sprintf(
|
||||
// translators: %1$s is the formatted price, %2$s the duration, and %3$s the duration unit (day, week, month, etc)
|
||||
_n('every %2$s', 'every %1$s %2$s', $duration, 'wp-ultimo'), // phpcs:ignore
|
||||
$duration,
|
||||
$item->get_duration_unit()
|
||||
);
|
||||
|
||||
if (!$item->is_forever_recurring()) {
|
||||
|
||||
$billing_cycles_message = sprintf(
|
||||
// translators: %s is the number of billing cycles.
|
||||
_n('for %s cycle', 'for %s cycles', $item->get_billing_cycles(), 'wp-ultimo'),
|
||||
$item->get_billing_cycles()
|
||||
);
|
||||
|
||||
$message .= ' ' . $billing_cycles_message;
|
||||
|
||||
} // end if;
|
||||
|
||||
} else {
|
||||
|
||||
$message = __('one time payment', 'wp-ultimo');
|
||||
|
||||
} // end if;
|
||||
|
||||
return sprintf('%s<br><small>%s</small>', $amount, $message);
|
||||
|
||||
} // end column_amount;
|
||||
|
||||
/**
|
||||
* Displays the setup fee of the product.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param WP_Ultimo\Models\Product $item Product object.
|
||||
* @return string
|
||||
*/
|
||||
public function column_setup_fee($item) {
|
||||
|
||||
if ($item->get_pricing_type() === 'contact_us') {
|
||||
|
||||
return __('None', 'wp-ultimo') . sprintf('<br><small>%s</small>', __('Requires contact', 'wp-ultimo'));
|
||||
|
||||
} // end if;
|
||||
|
||||
if (!$item->has_setup_fee()) {
|
||||
|
||||
return __('No Setup Fee', 'wp-ultimo');
|
||||
|
||||
} // end if;
|
||||
|
||||
return wu_format_currency($item->get_setup_fee(), $item->get_currency());
|
||||
|
||||
} // end column_setup_fee;
|
||||
|
||||
/**
|
||||
* Handles the bulk processing adding duplication.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
public function process_single_action() {
|
||||
|
||||
$bulk_action = $this->current_action();
|
||||
|
||||
if ($bulk_action === 'duplicate') {
|
||||
|
||||
$product = wu_request('id');
|
||||
|
||||
$product = wu_get_product($product);
|
||||
|
||||
if (!$product) {
|
||||
|
||||
WP_Ultimo()->notices->add(__('Product not found.', 'wp-ultimo'), 'error', 'network-admin');
|
||||
|
||||
return;
|
||||
|
||||
} // end if;
|
||||
|
||||
$new_product = $product->duplicate();
|
||||
|
||||
$new_name = sprintf(__('Copy of %s', 'wp-ultimo'), $product->get_name());
|
||||
|
||||
$new_product->set_name($new_name);
|
||||
|
||||
$new_product->set_slug(sanitize_title($new_name . '-' . time()));
|
||||
|
||||
$new_product->set_date_created(wu_get_current_time('mysql', true));
|
||||
|
||||
$result = $new_product->save();
|
||||
|
||||
if (is_wp_error($result)) {
|
||||
|
||||
WP_Ultimo()->notices->add($result->get_error_message(), 'error', 'network-admin');
|
||||
|
||||
return;
|
||||
|
||||
} // end if;
|
||||
|
||||
$redirect_url = wu_network_admin_url('wp-ultimo-edit-product', array(
|
||||
'id' => $new_product->get_id(),
|
||||
'updated' => 1,
|
||||
));
|
||||
|
||||
wp_redirect($redirect_url);
|
||||
|
||||
exit;
|
||||
|
||||
} // end if;
|
||||
|
||||
} // end process_single_action;
|
||||
|
||||
/**
|
||||
* Returns the list of columns for this particular List Table.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return array
|
||||
*/
|
||||
public function get_columns() {
|
||||
|
||||
$columns = array(
|
||||
'cb' => '<input type="checkbox" />',
|
||||
'featured_image_id' => '<span class="dashicons-wu-image"></span>',
|
||||
'name' => __('Name', 'wp-ultimo'),
|
||||
'type' => __('Type', 'wp-ultimo'),
|
||||
'slug' => __('Slug', 'wp-ultimo'),
|
||||
'amount' => __('Price', 'wp-ultimo'),
|
||||
'setup_fee' => __('Setup Fee', 'wp-ultimo'),
|
||||
'id' => __('ID', 'wp-ultimo'),
|
||||
);
|
||||
|
||||
return $columns;
|
||||
|
||||
} // end get_columns;
|
||||
|
||||
/**
|
||||
* Handles the item display for grid mode.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param WP_Ultimo\Models\Product $item The line item being displayed.
|
||||
* @return void
|
||||
*/
|
||||
public function single_row_grid($item) {
|
||||
|
||||
wu_get_template('base/products/grid-item', array(
|
||||
'item' => $item,
|
||||
'table' => $this,
|
||||
));
|
||||
|
||||
} // end single_row_grid;
|
||||
|
||||
/**
|
||||
* Returns the filters for this page.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function get_filters(): array {
|
||||
|
||||
return array(
|
||||
'filters' => array(),
|
||||
);
|
||||
|
||||
} // end get_filters;
|
||||
|
||||
/**
|
||||
* Returns the pre-selected filters on the filter bar.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return array
|
||||
*/
|
||||
public function get_views() {
|
||||
|
||||
return array(
|
||||
'all' => array(
|
||||
'field' => 'type',
|
||||
'url' => add_query_arg('type', 'all'),
|
||||
'label' => __('All Products', 'wp-ultimo'),
|
||||
'count' => 0,
|
||||
),
|
||||
'plan' => array(
|
||||
'field' => 'type',
|
||||
'url' => add_query_arg('type', 'plan'),
|
||||
'label' => __('Plans', 'wp-ultimo'),
|
||||
'count' => 0,
|
||||
),
|
||||
'package' => array(
|
||||
'field' => 'type',
|
||||
'url' => add_query_arg('type', 'package'),
|
||||
'label' => __('Packages', 'wp-ultimo'),
|
||||
'count' => 0,
|
||||
),
|
||||
'service' => array(
|
||||
'field' => 'type',
|
||||
'url' => add_query_arg('type', 'service'),
|
||||
'label' => __('Services', 'wp-ultimo'),
|
||||
'count' => 0,
|
||||
),
|
||||
);
|
||||
|
||||
} // end get_views;
|
||||
|
||||
} // end class Product_List_Table;
|
102
inc/list-tables/class-site-customer-list-table.php
Normal file
102
inc/list-tables/class-site-customer-list-table.php
Normal file
@ -0,0 +1,102 @@
|
||||
<?php
|
||||
/**
|
||||
* Customers' Membership List Table class.
|
||||
*
|
||||
* @package WP_Ultimo
|
||||
* @subpackage List_Table
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\List_Tables;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* Membership List Table class.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
class Site_Customer_List_Table extends Customer_List_Table {
|
||||
|
||||
/**
|
||||
* Initializes the table.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
parent::__construct();
|
||||
|
||||
$this->current_mode = 'list';
|
||||
|
||||
} // end __construct;
|
||||
|
||||
/**
|
||||
* Returns the list of columns for this particular List Table.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return array
|
||||
*/
|
||||
public function get_columns() {
|
||||
|
||||
$columns = array(
|
||||
'responsive' => '',
|
||||
);
|
||||
|
||||
return $columns;
|
||||
|
||||
} // end get_columns;
|
||||
|
||||
/**
|
||||
* Renders the inside column responsive.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param object $item The item being rendered.
|
||||
* @return void
|
||||
*/
|
||||
public function column_responsive($item) {
|
||||
|
||||
$last_login = sprintf(__('Last login %s', 'wp-ultimo'), wu_human_time_diff(strtotime((string) $item->get_last_login())));
|
||||
|
||||
if ($item->is_online()) {
|
||||
|
||||
$last_login = '<span class="wu-inline-block wu-mr-1 wu-rounded-full wu-h-2 wu-w-2 wu-bg-green-500"></span>' . __('Online', 'wp-ultimo');
|
||||
|
||||
} // end if;
|
||||
|
||||
echo wu_responsive_table_row(array(
|
||||
'id' => $item->get_id(),
|
||||
'title' => $item->get_display_name(),
|
||||
'url' => wu_network_admin_url('wp-ultimo-edit-customer', array(
|
||||
'id' => $item->get_id(),
|
||||
)),
|
||||
'image' => get_avatar($item->get_user_id(), 36, 'identicon', '', array(
|
||||
'force_display' => true,
|
||||
'class' => 'wu-rounded-full',
|
||||
)),
|
||||
'status' => $this->column_status($item),
|
||||
), array(
|
||||
'total' => array(
|
||||
'icon' => 'dashicons-wu-at-sign wu-align-middle wu-mr-1',
|
||||
'label' => __('Email Address', 'wp-ultimo'),
|
||||
'value' => $item->get_email_address(),
|
||||
),
|
||||
),
|
||||
array(
|
||||
'date_expiration' => array(
|
||||
'icon' => $item->is_online() === false ? 'dashicons-wu-calendar1 wu-align-middle wu-mr-1' : '',
|
||||
'label' => __('Last Login', 'wp-ultimo'),
|
||||
'value' => $last_login,
|
||||
),
|
||||
'date_created' => array(
|
||||
'icon' => 'dashicons-wu-calendar1 wu-align-middle wu-mr-1',
|
||||
'label' => '',
|
||||
'value' => sprintf(__('Registered %s', 'wp-ultimo'), wu_human_time_diff(strtotime((string) $item->get_date_registered()))),
|
||||
),
|
||||
));
|
||||
|
||||
} // end column_responsive;
|
||||
|
||||
} // end class Site_Customer_List_Table;
|
451
inc/list-tables/class-site-list-table.php
Normal file
451
inc/list-tables/class-site-list-table.php
Normal file
@ -0,0 +1,451 @@
|
||||
<?php
|
||||
/**
|
||||
* Site List Table class.
|
||||
*
|
||||
* @package WP_Ultimo
|
||||
* @subpackage List_Table
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\List_Tables;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* Site List Table class.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
class Site_List_Table extends Base_List_Table {
|
||||
|
||||
/**
|
||||
* Holds the query class for the object being listed.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var string
|
||||
*/
|
||||
protected $query_class = '\\WP_Ultimo\\Database\\Sites\\Site_Query';
|
||||
|
||||
/**
|
||||
* Initializes the table.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
$this->modes = array(
|
||||
'grid' => __('Grid View'),
|
||||
'list' => __('List View'),
|
||||
);
|
||||
|
||||
parent::__construct(array(
|
||||
'singular' => __('Site', 'wp-ultimo'), // singular name of the listed records
|
||||
'plural' => __('Sites', 'wp-ultimo'), // plural name of the listed records
|
||||
'ajax' => true, // does this table support ajax?
|
||||
'add_new' => array(
|
||||
'url' => wu_get_form_url('add_new_site'),
|
||||
'classes' => 'wubox',
|
||||
),
|
||||
));
|
||||
|
||||
} // end __construct;
|
||||
|
||||
/**
|
||||
* Overrides the parent method to add pending sites.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param integer $per_page Number of items to display per page.
|
||||
* @param integer $page_number Current page.
|
||||
* @param boolean $count If we should count records or return the actual records.
|
||||
* @return array
|
||||
*/
|
||||
public function get_items($per_page = 5, $page_number = 1, $count = false) {
|
||||
|
||||
$type = wu_request('type');
|
||||
|
||||
if ($type === 'pending') {
|
||||
|
||||
$pending_sites = \WP_Ultimo\Models\Site::get_all_by_type('pending');
|
||||
|
||||
return $count ? count($pending_sites) : $pending_sites;
|
||||
|
||||
} // end if;
|
||||
|
||||
$query = array(
|
||||
'number' => $per_page,
|
||||
'offset' => ($page_number - 1) * $per_page,
|
||||
'count' => $count,
|
||||
'search' => wu_request('s'),
|
||||
);
|
||||
|
||||
if ($type && $type !== 'all') {
|
||||
|
||||
$query['meta_query'] = array(
|
||||
'type' => array(
|
||||
'key' => 'wu_type',
|
||||
'value' => $type,
|
||||
),
|
||||
);
|
||||
|
||||
} // end if;
|
||||
|
||||
$query = apply_filters("wu_{$this->id}_get_items", $query, $this);
|
||||
|
||||
return wu_get_sites($query);
|
||||
|
||||
} // end get_items;
|
||||
/**
|
||||
* Render the bulk edit checkbox.
|
||||
*
|
||||
* @param WP_Ultimo\Models\Site $item Site object.
|
||||
*/
|
||||
public function column_cb($item): string {
|
||||
|
||||
if ($item->get_type() === 'pending') {
|
||||
|
||||
return sprintf('<input type="checkbox" name="bulk-delete[]" value="%s" />', $item->get_membership_id());
|
||||
|
||||
} // end if;
|
||||
|
||||
return sprintf('<input type="checkbox" name="bulk-delete[]" value="%s" />', $item->get_id());
|
||||
|
||||
} // end column_cb;
|
||||
/**
|
||||
* Displays the content of the name column.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param WP_Ultimo\Models\Site $item Site object.
|
||||
*/
|
||||
public function column_path($item): string {
|
||||
|
||||
$url_atts = array(
|
||||
'id' => $item->get_id(),
|
||||
'model' => 'site'
|
||||
);
|
||||
|
||||
$title = $item->get_title();
|
||||
|
||||
$title = sprintf('<a href="%s">%s</a>', wu_network_admin_url('wp-ultimo-edit-site', $url_atts), $item->get_title());
|
||||
|
||||
// Concatenate the two blocks
|
||||
$title = "<strong>$title</strong>";
|
||||
|
||||
$actions = array(
|
||||
'edit' => sprintf('<a href="%s">%s</a>', wu_network_admin_url('wp-ultimo-edit-site', $url_atts), __('Edit', 'wp-ultimo')),
|
||||
'duplicate' => sprintf(
|
||||
'<a title="%s" class="wubox" href="%s">%s</a>',
|
||||
__('Duplicate Site', 'wp-ultimo'),
|
||||
wu_get_form_url(
|
||||
'add_new_site',
|
||||
$url_atts
|
||||
),
|
||||
__('Duplicate', 'wp-ultimo')
|
||||
),
|
||||
'delete' => sprintf(
|
||||
'<a title="%s" class="wubox" href="%s">%s</a>',
|
||||
__('Delete', 'wp-ultimo'),
|
||||
wu_get_form_url(
|
||||
'delete_modal',
|
||||
$url_atts
|
||||
),
|
||||
__('Delete', 'wp-ultimo')
|
||||
),
|
||||
);
|
||||
|
||||
if ($item->get_type() === 'pending') {
|
||||
|
||||
$actions = array(
|
||||
'duplicate' => sprintf(
|
||||
'<a title="%s" class="wubox" href="%s">%s</a>',
|
||||
__('Publish Site', 'wp-ultimo'),
|
||||
wu_get_form_url(
|
||||
'publish_pending_site', array('membership_id' => $item->get_membership_id())
|
||||
),
|
||||
__('Publish', 'wp-ultimo')
|
||||
),
|
||||
'delete' => sprintf(
|
||||
'<a title="%s" class="wubox" href="%s">%s</a>',
|
||||
__('Delete', 'wp-ultimo'),
|
||||
wu_get_form_url(
|
||||
'delete_modal',
|
||||
array(
|
||||
'id' => $item->get_membership_id(),
|
||||
'model' => 'membership_meta_pending_site',
|
||||
'redirect_to' => urlencode((string) wu_network_admin_url('wp-ultimo-sites', array(
|
||||
'type' => 'pending',
|
||||
'page' => wu_request('page', 1),
|
||||
))),
|
||||
)
|
||||
),
|
||||
__('Delete', 'wp-ultimo')
|
||||
),
|
||||
);
|
||||
|
||||
} // end if;
|
||||
|
||||
return $title . sprintf('<span class="wu-block">%s</span>', make_clickable($item->get_active_site_url())) . $this->row_actions($actions);
|
||||
|
||||
} // end column_path;
|
||||
/**
|
||||
* Returns the date of the customer registration.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param WP_Ultimo\Models\Site $item Site object.
|
||||
*/
|
||||
public function column_date_registered($item): string {
|
||||
|
||||
$time = strtotime((string) $item->get_last_login(false));
|
||||
|
||||
return $item->get_date_registered() . sprintf('<br><small>%s</small>', human_time_diff($time));
|
||||
|
||||
} // end column_date_registered;
|
||||
|
||||
/**
|
||||
* Returns the blog_id.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param WP_Ultimo\Models\Site $item Site object.
|
||||
* @return string
|
||||
*/
|
||||
public function column_blog_id($item) {
|
||||
|
||||
return $item->get_type() === \WP_Ultimo\Database\Sites\Site_Type::PENDING ? '--' : $item->get_blog_id();
|
||||
|
||||
} // end column_blog_id;
|
||||
|
||||
/**
|
||||
* Displays the type of the site.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param WP_Ultimo\Models\Site $item Site object.
|
||||
* @return string
|
||||
*/
|
||||
public function column_type($item) {
|
||||
|
||||
$label = $item->get_type_label();
|
||||
|
||||
$class = $item->get_type_class();
|
||||
|
||||
return "<span class='wu-bg-gray-200 wu-py-1 wu-px-2 wu-leading-none wu-rounded-sm wu-text-xs wu-font-mono $class'>{$label}</span>";
|
||||
|
||||
} // end column_type;
|
||||
/**
|
||||
* Column for the domains associated with this site.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param WP_Ultimo\Models\Site $item Site object.
|
||||
*/
|
||||
public function column_domains($item): string {
|
||||
|
||||
$domain = wu_get_domains(array(
|
||||
'blog_id' => $item->get_id(),
|
||||
'count' => true,
|
||||
));
|
||||
|
||||
$url_atts = array(
|
||||
'blog_id' => $item->get_id(),
|
||||
);
|
||||
|
||||
$actions = array(
|
||||
'view' => sprintf('<a href="%s">%s</a>', wu_network_admin_url('wp-ultimo-domains', $url_atts), __('View', 'wp-ultimo')),
|
||||
);
|
||||
|
||||
return $domain . $this->row_actions($actions);
|
||||
|
||||
} // end column_domains;
|
||||
|
||||
/**
|
||||
* Returns the list of columns for this particular List Table.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return array
|
||||
*/
|
||||
public function get_columns() {
|
||||
|
||||
$columns = array(
|
||||
'cb' => '<input type="checkbox" />',
|
||||
'featured_image_id' => '<span class="dashicons-wu-image"></span>',
|
||||
'path' => __('URL', 'wp-ultimo'),
|
||||
'type' => __('Type', 'wp-ultimo'),
|
||||
'customer' => __('Customer', 'wp-ultimo'),
|
||||
'membership' => __('Membership', 'wp-ultimo'),
|
||||
'domains' => __('Domains', 'wp-ultimo'),
|
||||
'blog_id' => __('ID', 'wp-ultimo'),
|
||||
);
|
||||
|
||||
return $columns;
|
||||
|
||||
} // end get_columns;
|
||||
|
||||
/**
|
||||
* Renders the customer card for grid mode.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param WP_Ultimo\Models\Customer $item The customer being shown.
|
||||
* @return void
|
||||
*/
|
||||
public function single_row_grid($item) {
|
||||
|
||||
wu_get_template('base/sites/grid-item', array(
|
||||
'item' => $item,
|
||||
'list_table' => $this,
|
||||
));
|
||||
|
||||
} // end single_row_grid;
|
||||
/**
|
||||
* Returns the filters for this page.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function get_filters(): array {
|
||||
|
||||
return array(
|
||||
'filters' => array(
|
||||
'vip' => array(
|
||||
'label' => __('VIP Status', 'wp-ultimo'),
|
||||
'options' => array(
|
||||
'0' => __('Regular Sites', 'wp-ultimo'),
|
||||
'1' => __('VIP Sites', 'wp-ultimo'),
|
||||
),
|
||||
),
|
||||
),
|
||||
'date_filters' => array(
|
||||
'last_login' => array(
|
||||
'label' => __('Last Login', 'wp-ultimo'),
|
||||
'options' => $this->get_default_date_filter_options(),
|
||||
),
|
||||
'date_registered' => array(
|
||||
'label' => __('Site Since', 'wp-ultimo'),
|
||||
'options' => $this->get_default_date_filter_options(),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
} // end get_filters;
|
||||
|
||||
/**
|
||||
* Returns the pre-selected filters on the filter bar.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return array
|
||||
*/
|
||||
public function get_views() {
|
||||
|
||||
return array(
|
||||
'all' => array(
|
||||
'field' => 'type',
|
||||
'url' => add_query_arg('type', 'all'),
|
||||
'label' => __('All Sites', 'wp-ultimo'),
|
||||
'count' => 0,
|
||||
),
|
||||
'customer_owned' => array(
|
||||
'field' => 'type',
|
||||
'url' => add_query_arg('type', 'customer_owned'),
|
||||
'label' => __('Customer-Owned', 'wp-ultimo'),
|
||||
'count' => 0,
|
||||
),
|
||||
'site_template' => array(
|
||||
'field' => 'type',
|
||||
'url' => add_query_arg('type', 'site_template'),
|
||||
'label' => __('Templates', 'wp-ultimo'),
|
||||
'count' => 0,
|
||||
),
|
||||
'pending' => array(
|
||||
'field' => 'type',
|
||||
'url' => add_query_arg('type', 'pending'),
|
||||
'label' => __('Pending', 'wp-ultimo'),
|
||||
'count' => 0,
|
||||
),
|
||||
);
|
||||
|
||||
} // end get_views;
|
||||
|
||||
/**
|
||||
* Returns an associative array containing the bulk action
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_bulk_actions() {
|
||||
|
||||
$actions = array(
|
||||
'screenshot' => __('Take Screenshot', 'wp-ultimo'),
|
||||
);
|
||||
|
||||
$actions[wu_request('type', 'all') === 'pending' ? 'delete-pending' : 'delete'] = __('Delete', 'wp-ultimo');
|
||||
|
||||
return $actions;
|
||||
|
||||
} // end get_bulk_actions;
|
||||
|
||||
/**
|
||||
* Handles the bulk processing.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
public function process_single_action() {
|
||||
|
||||
$action = $this->current_action();
|
||||
|
||||
if ($action === 'duplicate') {
|
||||
|
||||
$site_id = wu_request('id');
|
||||
|
||||
$site = wu_get_site($site_id);
|
||||
|
||||
if (!$site) {
|
||||
|
||||
WP_Ultimo()->notices->add(__('Site not found.', 'wp-ultimo'), 'error', 'network-admin');
|
||||
|
||||
return;
|
||||
|
||||
} // end if;
|
||||
|
||||
$new_site = $site->duplicate();
|
||||
|
||||
$new_name = sprintf(__('Copy of %s', 'wp-ultimo'), $new_site->get_title());
|
||||
|
||||
$new_path = sprintf('%s%s', trim((string) $new_site->get_path(), '/'), 'copy');
|
||||
|
||||
$new_site->set_template_id($new_site->get_blog_id());
|
||||
|
||||
$new_site->set_blog_id(0);
|
||||
|
||||
$new_site->get_title($new_name);
|
||||
|
||||
$new_site->set_path($new_path);
|
||||
|
||||
$new_site->site_date_registered(wu_get_current_time('mysql', true));
|
||||
|
||||
$result = $new_site->save();
|
||||
|
||||
if (is_wp_error($result)) {
|
||||
|
||||
WP_Ultimo()->notices->add($result->get_error_message(), 'error', 'network-admin');
|
||||
|
||||
return;
|
||||
|
||||
} // end if;
|
||||
|
||||
$redirect_url = wu_network_admin_url('wp-ultimo-edit-site', array(
|
||||
'id' => $new_site->get_id(),
|
||||
'updated' => 1,
|
||||
));
|
||||
|
||||
wp_redirect($redirect_url);
|
||||
|
||||
exit;
|
||||
|
||||
} // end if;
|
||||
|
||||
} // end process_single_action;
|
||||
|
||||
} // end class Site_List_Table;
|
78
inc/list-tables/class-sites-domain-list-table.php
Normal file
78
inc/list-tables/class-sites-domain-list-table.php
Normal file
@ -0,0 +1,78 @@
|
||||
<?php
|
||||
/**
|
||||
* Domain List Table class.
|
||||
*
|
||||
* @package WP_Ultimo
|
||||
* @subpackage List_Table
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\List_Tables;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* Domain List Table class.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
class Sites_Domain_List_Table extends Domain_List_Table {
|
||||
|
||||
/**
|
||||
* Returns the list of columns for this particular List Table.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return array
|
||||
*/
|
||||
public function get_columns() {
|
||||
|
||||
$columns = array(
|
||||
'responsive' => '',
|
||||
);
|
||||
|
||||
return $columns;
|
||||
|
||||
} // end get_columns;
|
||||
|
||||
/**
|
||||
* Renders the inside column responsive.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param object $item The item being rendered.
|
||||
* @return void
|
||||
*/
|
||||
public function column_responsive($item) {
|
||||
|
||||
echo wu_responsive_table_row(array(
|
||||
'id' => $item->get_id(),
|
||||
'title' => strtolower((string) $item->get_domain()),
|
||||
'url' => wu_network_admin_url('wp-ultimo-edit-domain', array(
|
||||
'id' => $item->get_id(),
|
||||
)),
|
||||
'status' => $this->column_stage($item),
|
||||
), array(
|
||||
'primary' => array(
|
||||
'icon' => $item->is_primary_domain() ? 'dashicons-wu-filter_1 wu-align-text-bottom wu-mr-1' : 'dashicons-wu-plus-square wu-align-text-bottom wu-mr-1',
|
||||
'label' => '',
|
||||
'value' => $item->is_primary_domain() ? __('Primary', 'wp-ultimo') : __('Alias', 'wp-ultimo'),
|
||||
),
|
||||
'secure' => array(
|
||||
'wrapper_classes' => $item->is_secure() ? 'wu-text-green-500' : '',
|
||||
'icon' => $item->is_secure() ? 'dashicons-wu-lock1 wu-align-text-bottom wu-mr-1' : 'dashicons-wu-lock1 wu-align-text-bottom wu-mr-1',
|
||||
'label' => '',
|
||||
'value' => $item->is_secure() ? __('Secure (HTTPS)', 'wp-ultimo') : __('Not Secure (HTTP)', 'wp-ultimo'),
|
||||
),
|
||||
),
|
||||
array(
|
||||
'date_created' => array(
|
||||
'icon' => 'dashicons-wu-calendar1 wu-align-middle wu-mr-1',
|
||||
'label' => '',
|
||||
'value' => sprintf(__('Created %s', 'wp-ultimo'), wu_human_time_diff(strtotime((string) $item->get_date_created()))),
|
||||
),
|
||||
));
|
||||
|
||||
} // end column_responsive;
|
||||
|
||||
} // end class Sites_Domain_List_Table;
|
194
inc/list-tables/class-webhook-list-table.php
Normal file
194
inc/list-tables/class-webhook-list-table.php
Normal file
@ -0,0 +1,194 @@
|
||||
<?php
|
||||
/**
|
||||
* Webhook List Table class.
|
||||
*
|
||||
* @package WP_Ultimo
|
||||
* @subpackage List_Table
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\List_Tables;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* Webhook List Table class.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
class Webhook_List_Table extends Base_List_Table {
|
||||
|
||||
/**
|
||||
* Holds the query class for the object being listed.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var string
|
||||
*/
|
||||
protected $query_class = '\\WP_Ultimo\\Database\\Webhooks\\Webhook_Query';
|
||||
|
||||
/**
|
||||
* Initializes the table.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
parent::__construct(array(
|
||||
'singular' => __('Webhook', 'wp-ultimo'), // singular name of the listed records
|
||||
'plural' => __('Webhooks', 'wp-ultimo'), // plural name of the listed records
|
||||
'ajax' => true, // does this table support ajax?
|
||||
'add_new' => array(
|
||||
'url' => wu_get_form_url('add_new_webhook_modal'),
|
||||
'classes' => 'wubox',
|
||||
),
|
||||
));
|
||||
} // end __construct;
|
||||
/**
|
||||
* Displays the content of the name column.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param WP_Ultimo\Models\Webhook $item Webhook object.
|
||||
*/
|
||||
public function column_name($item): string {
|
||||
|
||||
$url_atts = array(
|
||||
'id' => $item->get_id(),
|
||||
'model' => 'webhook',
|
||||
);
|
||||
|
||||
$title = sprintf('<a href="%s"><strong>%s</strong></a>
|
||||
<span data-loading="wu_action_button_loading_%s" id="wu_action_button_loading" class="wu-blinking-animation wu-text-gray-600 wu-my-1 wu-text-2xs wu-uppercase wu-font-semibold hidden" >%s</span>', wu_network_admin_url('wp-ultimo-edit-webhook', $url_atts), $item->get_name(), $item->get_id(), __('Sending Test..', 'wp-ultimo'));
|
||||
|
||||
$actions = array(
|
||||
'edit' => sprintf('<a href="%s">%s</a>', wu_network_admin_url('wp-ultimo-edit-webhook', $url_atts), __('Edit', 'wp-ultimo')),
|
||||
'test' => sprintf('<a id="action_button" data-title="' . $item->get_name() . '" data-page="list" data-action="wu_send_test_event" data-event="' . $item->get_event() . '" data-object="' . $item->get_id() . '" data-url="%s" href="">%s</a>', $item->get_webhook_url(), __('Send Test', 'wp-ultimo')),
|
||||
'delete' => sprintf(
|
||||
'<a title="%s" class="wubox" href="%s">%s</a>',
|
||||
__('Delete', 'wp-ultimo'),
|
||||
wu_get_form_url(
|
||||
'delete_modal',
|
||||
$url_atts
|
||||
),
|
||||
__('Delete', 'wp-ultimo')
|
||||
),
|
||||
);
|
||||
|
||||
return $title . $this->row_actions($actions);
|
||||
|
||||
} // end column_name;
|
||||
|
||||
/**
|
||||
* Displays the content of the webhook url column.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param WP_Ultimo\Models\Webhook $item Webhook object.
|
||||
* @return string
|
||||
*/
|
||||
public function column_webhook_url($item) {
|
||||
|
||||
$trimmed_url = mb_strimwidth((string) $item->get_webhook_url(), 0, 50, '...');
|
||||
|
||||
return "<span class='wu-py-1 wu-px-2 wu-bg-gray-200 wu-rounded-sm wu-text-gray-700 wu-text-xs wu-font-mono'>{$trimmed_url}</span>";
|
||||
|
||||
} // end column_webhook_url;
|
||||
|
||||
/**
|
||||
* Displays the content of the event column.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param WP_Ultimo\Models\Webhook $item Webhook object.
|
||||
* @return string
|
||||
*/
|
||||
public function column_event($item) {
|
||||
|
||||
$event = $item->get_event();
|
||||
|
||||
return "<span class='wu-py-1 wu-px-2 wu-bg-gray-200 wu-rounded-sm wu-text-gray-700 wu-text-xs wu-font-mono'>{$event}</span>";
|
||||
|
||||
} // end column_event;
|
||||
/**
|
||||
* Displays the content of the count column.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param WP_Ultimo\Models\Webhook $item Webhook object.
|
||||
*/
|
||||
public function column_count($item): string {
|
||||
|
||||
$count = $item->get_count();
|
||||
|
||||
$actions = array(
|
||||
'edit' => sprintf('<a href="%s">%s</a>', '', __('See Events', 'wp-ultimo')),
|
||||
);
|
||||
|
||||
return $count . $this->row_actions($actions);
|
||||
|
||||
} // end column_count;
|
||||
/**
|
||||
* Displays the content of the integration column.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param WP_Ultimo\Models\Webhook $item Webhook object.
|
||||
*/
|
||||
public function column_integration($item): string {
|
||||
|
||||
return ucwords(str_replace(array('_', '-'), ' ', (string) $item->get_integration()));
|
||||
|
||||
} // end column_integration;
|
||||
|
||||
/**
|
||||
* Displays the content of the active column.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param WP_Ultimo\Models\Webhook $item Webhook object.
|
||||
* @return string
|
||||
*/
|
||||
public function column_active($item) {
|
||||
|
||||
return $item->is_active() ? __('Yes', 'wp-ultimo') : __('No', 'wp-ultimo');
|
||||
|
||||
} // end column_active;
|
||||
|
||||
/**
|
||||
* Returns the list of columns for this particular List Table.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return array
|
||||
*/
|
||||
public function get_columns() {
|
||||
|
||||
$columns = array(
|
||||
'cb' => '<input type="checkbox" />',
|
||||
'name' => __('Name', 'wp-ultimo'),
|
||||
'webhook_url' => __('Target URL', 'wp-ultimo'),
|
||||
'event' => __('Trigger Event', 'wp-ultimo'),
|
||||
'event_count' => __('Count', 'wp-ultimo'),
|
||||
'integration' => __('Integration', 'wp-ultimo'),
|
||||
'active' => __('Active', 'wp-ultimo'),
|
||||
'id' => __('ID', 'wp-ultimo'),
|
||||
);
|
||||
|
||||
return $columns;
|
||||
|
||||
} // end get_columns;
|
||||
/**
|
||||
* Returns the filters for this page.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function get_filters(): array {
|
||||
|
||||
return array(
|
||||
'filters' => array(),
|
||||
'date_filters' => array(),
|
||||
);
|
||||
|
||||
} // end get_filters;
|
||||
|
||||
} // end class Webhook_List_Table;
|
58
inc/list-tables/customer-panel/class-invoice-list-table.php
Normal file
58
inc/list-tables/customer-panel/class-invoice-list-table.php
Normal file
@ -0,0 +1,58 @@
|
||||
<?php
|
||||
/**
|
||||
* Customers Payment List Table class.
|
||||
*
|
||||
* @package WP_Ultimo
|
||||
* @subpackage List_Table
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\List_Tables\Customer_Panel;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
use WP_Ultimo\List_Tables\Payment_List_Table as Parent_Payment_List_Table;
|
||||
|
||||
/**
|
||||
* Payment List Table class.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
class Invoice_List_Table extends Parent_Payment_List_Table {
|
||||
|
||||
/**
|
||||
* Returns the list of columns for this particular List Table.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return array
|
||||
*/
|
||||
public function get_columns() {
|
||||
|
||||
$columns = array(
|
||||
'hash' => __('Code', 'wp-ultimo'),
|
||||
'status' => __('Status', 'wp-ultimo'),
|
||||
'total' => __('Total', 'wp-ultimo'),
|
||||
'date_created' => __('Created at', 'wp-ultimo'),
|
||||
);
|
||||
|
||||
return $columns;
|
||||
|
||||
} // end get_columns;
|
||||
|
||||
/**
|
||||
* Clears the bulk actions.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param string $which Top or bottom.
|
||||
* @return array
|
||||
*/
|
||||
public function bulk_actions($which = '') {
|
||||
|
||||
return array();
|
||||
|
||||
} // end bulk_actions;
|
||||
|
||||
} // end class Invoice_List_Table;
|
||||
|
98
inc/list-tables/customer-panel/class-product-list-table.php
Normal file
98
inc/list-tables/customer-panel/class-product-list-table.php
Normal file
@ -0,0 +1,98 @@
|
||||
<?php
|
||||
/**
|
||||
* Customers Site List Table class.
|
||||
*
|
||||
* @package WP_Ultimo
|
||||
* @subpackage List_Table
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\List_Tables\Customer_Panel;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
use WP_Ultimo\List_Tables\Product_List_Table as Parent_Product_List_Table;
|
||||
|
||||
/**
|
||||
* Product List Table class.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
class Product_List_Table extends Parent_Product_List_Table {
|
||||
|
||||
/**
|
||||
* Initializes the table.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
parent::__construct();
|
||||
|
||||
$this->modes = array(
|
||||
'grid' => __('Grid View'),
|
||||
);
|
||||
|
||||
$this->current_mode = 'grid';
|
||||
|
||||
} // end __construct;
|
||||
|
||||
/**
|
||||
* Returns the list of columns for this particular List Table.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return array
|
||||
*/
|
||||
public function get_columns() {
|
||||
|
||||
return array();
|
||||
|
||||
} // end get_columns;
|
||||
|
||||
/**
|
||||
* Resets the filters.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function get_filters(): array {
|
||||
|
||||
return array(
|
||||
'filters' => array(),
|
||||
'date_filters' => array(),
|
||||
);
|
||||
|
||||
} // end get_filters;
|
||||
|
||||
/**
|
||||
* Resets bulk actions.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param string $which Top or bottom.
|
||||
* @return array
|
||||
*/
|
||||
public function bulk_actions($which = '') {
|
||||
|
||||
return array();
|
||||
|
||||
} // end bulk_actions;
|
||||
|
||||
/**
|
||||
* Renders the customer card for grid mode.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param WP_Ultimo\Models\Customer $item The customer being shown.
|
||||
* @return void
|
||||
*/
|
||||
public function single_row_grid($item) {
|
||||
|
||||
wu_get_template('base/products/grid-item', array(
|
||||
'item' => $item,
|
||||
'list_table' => $this,
|
||||
));
|
||||
|
||||
} // end single_row_grid;
|
||||
|
||||
} // end class Product_List_Table;
|
119
inc/list-tables/customer-panel/class-site-list-table.php
Normal file
119
inc/list-tables/customer-panel/class-site-list-table.php
Normal file
@ -0,0 +1,119 @@
|
||||
<?php
|
||||
/**
|
||||
* Customers Site List Table class.
|
||||
*
|
||||
* @package WP_Ultimo
|
||||
* @subpackage List_Table
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\List_Tables\Customer_Panel;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
use WP_Ultimo\List_Tables\Site_List_Table as Parent_Site_List_Table;
|
||||
|
||||
/**
|
||||
* Site List Table class.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
class Site_List_Table extends Parent_Site_List_Table {
|
||||
|
||||
/**
|
||||
* Initializes the table.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
parent::__construct();
|
||||
|
||||
$this->modes = array(
|
||||
'grid' => __('Grid View'),
|
||||
);
|
||||
|
||||
$this->current_mode = 'grid';
|
||||
|
||||
} // end __construct;
|
||||
|
||||
/**
|
||||
* Returns the list of columns for this particular List Table.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return array
|
||||
*/
|
||||
public function get_columns() {
|
||||
|
||||
return array();
|
||||
|
||||
} // end get_columns;
|
||||
|
||||
/**
|
||||
* Clears filters.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function get_filters(): array {
|
||||
|
||||
return array(
|
||||
'filters' => array(),
|
||||
'date_filters' => array(),
|
||||
);
|
||||
|
||||
} // end get_filters;
|
||||
|
||||
/**
|
||||
* Clears views.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return array
|
||||
*/
|
||||
public function get_views() {
|
||||
|
||||
return array(
|
||||
'all' => array(
|
||||
'field' => 'type',
|
||||
'url' => add_query_arg('type', 'all'),
|
||||
'label' => __('Your Sites', 'wp-ultimo'),
|
||||
'count' => 0,
|
||||
),
|
||||
);
|
||||
|
||||
} // end get_views;
|
||||
|
||||
/**
|
||||
* Get the extra fields based on the request.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return array
|
||||
*/
|
||||
public function get_extra_fields() {
|
||||
|
||||
$customer = wu_get_current_customer();
|
||||
|
||||
if (!$customer) {
|
||||
|
||||
return array(
|
||||
'blog_id__in' => array('null_id'), // pass absurd value to make sure the query returns nothing.
|
||||
);
|
||||
|
||||
} // end if;
|
||||
|
||||
$fields = parent::get_extra_fields();
|
||||
|
||||
$fields = array(
|
||||
'meta_query' => array(
|
||||
'customer_id' => array(
|
||||
'key' => 'wu_customer_id',
|
||||
'value' => $customer->get_id(),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
return $fields;
|
||||
|
||||
} // end get_extra_fields;
|
||||
|
||||
} // end class Site_List_Table;
|
Reference in New Issue
Block a user