Use PHP 7.4 featers and PHP 8 polyfills
This commit is contained in:
@ -33,9 +33,9 @@ class Dashboard_Taxes_Tab {
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
add_filter('wu_dashboard_filter_bar', array($this, 'add_tab'));
|
||||
add_filter('wu_dashboard_filter_bar', [$this, 'add_tab']);
|
||||
|
||||
add_action('wu_dashboard_taxes_widgets', array($this, 'register_widgets'), 10, 3);
|
||||
add_action('wu_dashboard_taxes_widgets', [$this, 'register_widgets'], 10, 3);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -58,12 +58,12 @@ class Dashboard_Taxes_Tab {
|
||||
*/
|
||||
public function add_tab($dashboard_filters) {
|
||||
|
||||
$dashboard_filters['taxes'] = array(
|
||||
$dashboard_filters['taxes'] = [
|
||||
'field' => 'type',
|
||||
'label' => __('Taxes', 'wp-ultimo'),
|
||||
'url' => add_query_arg('tab', 'taxes'),
|
||||
'count' => 0,
|
||||
);
|
||||
];
|
||||
|
||||
return $dashboard_filters;
|
||||
}
|
||||
@ -74,20 +74,20 @@ class Dashboard_Taxes_Tab {
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
public function disabled_message() {
|
||||
public function disabled_message(): void {
|
||||
|
||||
echo wu_render_empty_state(
|
||||
array(
|
||||
[
|
||||
'message' => __('You do not have tax support enabled yet...'),
|
||||
'sub_message' => __('If you need to collect taxes, you\'ll be glad to hear that WP Multisite WaaS offers tax support!'),
|
||||
'link_label' => __('Enable Tax Support', 'wp-ultimo'),
|
||||
'link_url' => wu_network_admin_url(
|
||||
'wp-ultimo-settings',
|
||||
array(
|
||||
[
|
||||
'tab' => 'taxes',
|
||||
)
|
||||
]
|
||||
),
|
||||
)
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
@ -101,13 +101,13 @@ class Dashboard_Taxes_Tab {
|
||||
*/
|
||||
public function add_back_link($links) {
|
||||
|
||||
$back_link = array(
|
||||
array(
|
||||
$back_link = [
|
||||
[
|
||||
'url' => wu_network_admin_url('wp-ultimo'),
|
||||
'label' => __('Go Back', 'wp-ultimo'),
|
||||
'icon' => 'wu-reply',
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
|
||||
return array_merge($back_link, $links);
|
||||
}
|
||||
@ -122,7 +122,7 @@ class Dashboard_Taxes_Tab {
|
||||
* @param \WP_Ultimo\Admin_Pages\Dashboard_Admin_Page $dashboard_page Name of selected tab.
|
||||
* @return void
|
||||
*/
|
||||
public function register_widgets($tab, $screen, $dashboard_page) {
|
||||
public function register_widgets($tab, $screen, $dashboard_page): void {
|
||||
|
||||
/**
|
||||
* Set the dashboard page as a property
|
||||
@ -139,20 +139,20 @@ class Dashboard_Taxes_Tab {
|
||||
|
||||
add_filter('wu_dashboard_display_widgets', '__return_false');
|
||||
|
||||
add_action('wu_dash_before_metaboxes', array($this, 'disabled_message'));
|
||||
add_action('wu_dash_before_metaboxes', [$this, 'disabled_message']);
|
||||
|
||||
add_filter('wu_page_get_title_links', array($this, 'add_back_link'));
|
||||
add_filter('wu_page_get_title_links', [$this, 'add_back_link']);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->dashboard_page = $dashboard_page;
|
||||
|
||||
add_meta_box('wp-ultimo-taxes', __('Taxes', 'wp-ultimo'), array($this, 'output_widget_taxes'), $screen->id, 'full', 'high');
|
||||
add_meta_box('wp-ultimo-taxes', __('Taxes', 'wp-ultimo'), [$this, 'output_widget_taxes'], $screen->id, 'full', 'high');
|
||||
|
||||
add_meta_box('wp-ultimo-taxes-by-rate', __('Taxes by Code', 'wp-ultimo'), array($this, 'output_widget_taxes_by_rate'), $screen->id, 'normal', 'high');
|
||||
add_meta_box('wp-ultimo-taxes-by-rate', __('Taxes by Code', 'wp-ultimo'), [$this, 'output_widget_taxes_by_rate'], $screen->id, 'normal', 'high');
|
||||
|
||||
add_meta_box('wp-ultimo-taxes-by-day', __('Taxes by Day', 'wp-ultimo'), array($this, 'output_widget_taxes_by_day'), $screen->id, 'side', 'high');
|
||||
add_meta_box('wp-ultimo-taxes-by-day', __('Taxes by Day', 'wp-ultimo'), [$this, 'output_widget_taxes_by_day'], $screen->id, 'side', 'high');
|
||||
|
||||
$this->register_scripts();
|
||||
}
|
||||
@ -164,22 +164,22 @@ class Dashboard_Taxes_Tab {
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
public function register_scripts() {
|
||||
public function register_scripts(): void {
|
||||
|
||||
$payments_per_month = array(
|
||||
'january' => array(),
|
||||
'february' => array(),
|
||||
'march' => array(),
|
||||
'april' => array(),
|
||||
'may' => array(),
|
||||
'june' => array(),
|
||||
'july' => array(),
|
||||
'august' => array(),
|
||||
'september' => array(),
|
||||
'october' => array(),
|
||||
'november' => array(),
|
||||
'december' => array(),
|
||||
);
|
||||
$payments_per_month = [
|
||||
'january' => [],
|
||||
'february' => [],
|
||||
'march' => [],
|
||||
'april' => [],
|
||||
'may' => [],
|
||||
'june' => [],
|
||||
'july' => [],
|
||||
'august' => [],
|
||||
'september' => [],
|
||||
'october' => [],
|
||||
'november' => [],
|
||||
'december' => [],
|
||||
];
|
||||
|
||||
$data = wu_calculate_taxes_by_month();
|
||||
|
||||
@ -191,7 +191,7 @@ class Dashboard_Taxes_Tab {
|
||||
++$index;
|
||||
}
|
||||
|
||||
$month_list = array();
|
||||
$month_list = [];
|
||||
|
||||
$current_year = date_i18n('Y');
|
||||
|
||||
@ -199,22 +199,22 @@ class Dashboard_Taxes_Tab {
|
||||
$month_list[] = date_i18n('M y', mktime(0, 0, 0, $i, 1, $current_year));
|
||||
}
|
||||
|
||||
wp_register_script('wu-tax-stats', wu_get_asset('tax-statistics.js', 'js'), array('jquery', 'wu-functions', 'wu-ajax-list-table', 'moment', 'wu-block-ui', 'dashboard', 'wu-apex-charts', 'wu-vue-apex-charts'), wu_get_version(), true);
|
||||
wp_register_script('wu-tax-stats', wu_get_asset('tax-statistics.js', 'js'), ['jquery', 'wu-functions', 'wu-ajax-list-table', 'moment', 'wu-block-ui', 'dashboard', 'wu-apex-charts', 'wu-vue-apex-charts'], wu_get_version(), true);
|
||||
|
||||
wp_localize_script(
|
||||
'wu-tax-stats',
|
||||
'wu_tax_statistics_vars',
|
||||
array(
|
||||
[
|
||||
'data' => $payments_per_month,
|
||||
'start_date' => date_i18n('Y-m-d', strtotime((string) wu_request('start_date', '-1 month'))),
|
||||
'end_date' => date_i18n('Y-m-d', strtotime((string) wu_request('end_date', 'tomorrow'))),
|
||||
'today' => date_i18n('Y-m-d', strtotime('tomorrow')),
|
||||
'month_list' => $month_list,
|
||||
'i18n' => array(
|
||||
'i18n' => [
|
||||
'net_profit_label' => __('Net Profit', 'wp-ultimo'),
|
||||
'taxes_label' => __('Taxes Collected', 'wp-ultimo'),
|
||||
),
|
||||
)
|
||||
],
|
||||
]
|
||||
);
|
||||
|
||||
wp_enqueue_script('wu-tax-stats');
|
||||
@ -226,7 +226,7 @@ class Dashboard_Taxes_Tab {
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
public function output_widget_taxes() {
|
||||
public function output_widget_taxes(): void {
|
||||
|
||||
wu_get_template('dashboard-statistics/widget-tax-graph');
|
||||
}
|
||||
@ -237,16 +237,16 @@ class Dashboard_Taxes_Tab {
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
public function output_widget_taxes_by_rate() {
|
||||
public function output_widget_taxes_by_rate(): void {
|
||||
|
||||
$taxes_by_rate = wu_calculate_taxes_by_rate($this->dashboard_page->start_date, $this->dashboard_page->end_date);
|
||||
|
||||
wu_get_template(
|
||||
'dashboard-statistics/widget-tax-by-code',
|
||||
array(
|
||||
[
|
||||
'taxes_by_rate' => $taxes_by_rate,
|
||||
'page' => $this->dashboard_page,
|
||||
)
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
@ -256,16 +256,16 @@ class Dashboard_Taxes_Tab {
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
public function output_widget_taxes_by_day() {
|
||||
public function output_widget_taxes_by_day(): void {
|
||||
|
||||
$taxes_by_day = wu_calculate_taxes_by_day($this->dashboard_page->start_date, $this->dashboard_page->end_date);
|
||||
|
||||
wu_get_template(
|
||||
'dashboard-statistics/widget-tax-by-day',
|
||||
array(
|
||||
[
|
||||
'taxes_by_day' => $taxes_by_day,
|
||||
'page' => $this->dashboard_page,
|
||||
)
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -26,18 +26,18 @@ class Tax {
|
||||
*
|
||||
* @since 1.9.0
|
||||
*/
|
||||
public function init() {
|
||||
public function init(): void {
|
||||
|
||||
add_action('init', array($this, 'add_settings'));
|
||||
add_action('init', [$this, 'add_settings']);
|
||||
|
||||
add_action('wu_page_wp-ultimo-settings_load', array($this, 'add_sidebar_widget'));
|
||||
add_action('wu_page_wp-ultimo-settings_load', [$this, 'add_sidebar_widget']);
|
||||
|
||||
if ($this->is_enabled()) {
|
||||
add_action('wp_ultimo_admin_pages', array($this, 'add_admin_page'));
|
||||
add_action('wp_ultimo_admin_pages', [$this, 'add_admin_page']);
|
||||
|
||||
add_action('wp_ajax_wu_get_tax_rates', array($this, 'serve_taxes_rates_via_ajax'));
|
||||
add_action('wp_ajax_wu_get_tax_rates', [$this, 'serve_taxes_rates_via_ajax']);
|
||||
|
||||
add_action('wp_ajax_wu_save_tax_rates', array($this, 'save_taxes_rates'));
|
||||
add_action('wp_ajax_wu_save_tax_rates', [$this, 'save_taxes_rates']);
|
||||
|
||||
add_action(
|
||||
'wu_before_search_models',
|
||||
@ -61,24 +61,24 @@ class Tax {
|
||||
|
||||
$query = wu_request(
|
||||
'query',
|
||||
array(
|
||||
[
|
||||
'search' => 'searching....',
|
||||
)
|
||||
]
|
||||
);
|
||||
|
||||
$s = trim((string) wu_get_isset($query, 'search', 'searching...'), '*');
|
||||
|
||||
$filtered = array();
|
||||
$filtered = [];
|
||||
|
||||
if ( ! empty($s)) {
|
||||
$filtered = \Arrch\Arrch::find(
|
||||
$results,
|
||||
array(
|
||||
[
|
||||
'sort_key' => 'name',
|
||||
'where' => array(
|
||||
array(array('slug', 'name'), '~', $s),
|
||||
),
|
||||
)
|
||||
'where' => [
|
||||
[['slug', 'name'], '~', $s],
|
||||
],
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
@ -96,41 +96,41 @@ class Tax {
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
public function add_settings() {
|
||||
public function add_settings(): void {
|
||||
|
||||
wu_register_settings_section(
|
||||
'taxes',
|
||||
array(
|
||||
[
|
||||
'title' => __('Taxes', 'wp-ultimo'),
|
||||
'desc' => __('Taxes', 'wp-ultimo'),
|
||||
'icon' => 'dashicons-wu-percent',
|
||||
'order' => 55,
|
||||
)
|
||||
]
|
||||
);
|
||||
|
||||
wu_register_settings_field(
|
||||
'taxes',
|
||||
'enable_taxes',
|
||||
array(
|
||||
[
|
||||
'title' => __('Enable Taxes', 'wp-ultimo'),
|
||||
'desc' => __('Enable this option to be able to collect sales taxes on your network payments.', 'wp-ultimo'),
|
||||
'type' => 'toggle',
|
||||
'default' => 0,
|
||||
)
|
||||
]
|
||||
);
|
||||
|
||||
wu_register_settings_field(
|
||||
'taxes',
|
||||
'inclusive_tax',
|
||||
array(
|
||||
[
|
||||
'title' => __('Inclusive Tax', 'wp-ultimo'),
|
||||
'desc' => __('Enable this option if your prices include taxes. In that case, WP Multisite WaaS will calculate the included tax instead of adding taxes to the price.', 'wp-ultimo'),
|
||||
'type' => 'toggle',
|
||||
'default' => 0,
|
||||
'require' => array(
|
||||
'require' => [
|
||||
'enable_taxes' => 1,
|
||||
),
|
||||
)
|
||||
],
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
@ -140,14 +140,14 @@ class Tax {
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
public function add_sidebar_widget() {
|
||||
public function add_sidebar_widget(): void {
|
||||
|
||||
wu_register_settings_side_panel(
|
||||
'taxes',
|
||||
array(
|
||||
[
|
||||
'title' => __('Tax Rates', 'wp-ultimo'),
|
||||
'render' => array($this, 'render_taxes_side_panel'),
|
||||
)
|
||||
'render' => [$this, 'render_taxes_side_panel'],
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
@ -170,7 +170,7 @@ class Tax {
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
public function add_admin_page() {
|
||||
public function add_admin_page(): void {
|
||||
|
||||
new \WP_Ultimo\Admin_Pages\Tax_Rates_Admin_Page();
|
||||
}
|
||||
@ -185,9 +185,9 @@ class Tax {
|
||||
|
||||
return apply_filters(
|
||||
'wu_get_tax_rate_types',
|
||||
array(
|
||||
[
|
||||
'regular' => __('Regular', 'wp-ultimo'),
|
||||
)
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
@ -199,7 +199,7 @@ class Tax {
|
||||
*/
|
||||
public function get_tax_rate_defaults() {
|
||||
|
||||
$defaults = array(
|
||||
$defaults = [
|
||||
'id' => uniqid(),
|
||||
'title' => __('Tax Rate', 'wp-ultimo'),
|
||||
'country' => '',
|
||||
@ -210,7 +210,7 @@ class Tax {
|
||||
'priority' => 10,
|
||||
'compound' => false,
|
||||
'type' => 'regular',
|
||||
);
|
||||
];
|
||||
|
||||
return apply_filters('wu_get_tax_rate_defaults', $defaults);
|
||||
}
|
||||
@ -227,12 +227,12 @@ class Tax {
|
||||
|
||||
$tax_rates_categories = wu_get_option(
|
||||
'tax_rates',
|
||||
array(
|
||||
'default' => array(
|
||||
[
|
||||
'default' => [
|
||||
'name' => __('Default', 'wp-ultimo'),
|
||||
'rates' => array(),
|
||||
),
|
||||
)
|
||||
'rates' => [],
|
||||
],
|
||||
]
|
||||
);
|
||||
|
||||
if ( ! isset($tax_rates_categories['default'])) {
|
||||
@ -241,7 +241,7 @@ class Tax {
|
||||
*/
|
||||
$default = array_shift($tax_rates_categories);
|
||||
|
||||
$tax_rates_categories = array_merge(array('default' => $default), $tax_rates_categories);
|
||||
$tax_rates_categories = array_merge(['default' => $default], $tax_rates_categories);
|
||||
}
|
||||
|
||||
foreach ($tax_rates_categories as &$tax_rate_category) {
|
||||
@ -269,9 +269,9 @@ class Tax {
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
public function serve_taxes_rates_via_ajax() {
|
||||
public function serve_taxes_rates_via_ajax(): void {
|
||||
|
||||
$tax_rates = array();
|
||||
$tax_rates = [];
|
||||
|
||||
if (current_user_can('read_tax_rates')) {
|
||||
$tax_rates = $this->get_tax_rates(true);
|
||||
@ -286,31 +286,31 @@ class Tax {
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
public function save_taxes_rates() {
|
||||
public function save_taxes_rates(): void {
|
||||
|
||||
if ( ! check_ajax_referer('wu_tax_editing')) {
|
||||
wp_send_json(
|
||||
array(
|
||||
[
|
||||
'code' => 'not-enough-permissions',
|
||||
'message' => __('You don\'t have permission to alter tax rates', 'wp-ultimo'),
|
||||
)
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
$data = json_decode(file_get_contents('php://input'), true);
|
||||
|
||||
$tax_rates = isset($data['tax_rates']) ? $data['tax_rates'] : false;
|
||||
$tax_rates = $data['tax_rates'] ?? false;
|
||||
|
||||
if ( ! $tax_rates) {
|
||||
wp_send_json(
|
||||
array(
|
||||
[
|
||||
'code' => 'tax-rates-not-found',
|
||||
'message' => __('No tax rates present in the request', 'wp-ultimo'),
|
||||
)
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
$treated_tax_rates = array();
|
||||
$treated_tax_rates = [];
|
||||
|
||||
foreach ($tax_rates as $tax_rate_slug => $tax_rate) {
|
||||
if ( ! isset($tax_rate['rates'])) {
|
||||
@ -335,11 +335,11 @@ class Tax {
|
||||
wu_save_option('tax_rates', $treated_tax_rates);
|
||||
|
||||
wp_send_json(
|
||||
array(
|
||||
[
|
||||
'code' => 'success',
|
||||
'message' => __('Tax Rates successfully updated!', 'wp-ultimo'),
|
||||
'tax_category' => strtolower(sanitize_title(wu_get_isset($data, 'tax_category', 'default'))),
|
||||
)
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
@ -349,7 +349,7 @@ class Tax {
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
public function render_taxes_side_panel() {
|
||||
public function render_taxes_side_panel(): void {
|
||||
?>
|
||||
|
||||
<div id="wu-taxes-side-panel" class="wu-widget-inset">
|
||||
@ -361,7 +361,7 @@ class Tax {
|
||||
</span>
|
||||
|
||||
<div class="wu-py-2">
|
||||
<img class="wu-w-full" alt="<?php esc_attr_e('Manage Tax Rates', 'wp-ultimo'); ?>" src="<?php echo wu_get_asset('sidebar/invoices.png'); ?>">
|
||||
<img class="wu-w-full" alt="<?php esc_attr_e('Manage Tax Rates', 'wp-ultimo'); ?>" src="<?php echo wu_get_asset('sidebar/invoices.webp'); ?>">
|
||||
</div>
|
||||
|
||||
<p class="wu-text-gray-600 wu-p-0 wu-m-0">
|
||||
|
Reference in New Issue
Block a user