Use new code style

This commit is contained in:
David Stone
2025-02-07 19:02:33 -07:00
parent 0181024ae1
commit 8433379d90
672 changed files with 37107 additions and 45249 deletions

View File

@ -36,8 +36,7 @@ class Dashboard_Taxes_Tab {
add_filter('wu_dashboard_filter_bar', array($this, 'add_tab'));
add_action('wu_dashboard_taxes_widgets', array($this, 'register_widgets'), 10, 3);
} // end __construct;
}
/**
* Checks if tax support is enabled or not.
@ -48,8 +47,7 @@ class Dashboard_Taxes_Tab {
protected function is_enabled() {
return wu_get_setting('enable_taxes');
} // end is_enabled;
}
/**
* Add_tab to dashboard
@ -68,8 +66,7 @@ class Dashboard_Taxes_Tab {
);
return $dashboard_filters;
} // end add_tab;
}
/**
* Renders the disabled message, if taxes are not enabled.
@ -79,16 +76,20 @@ class Dashboard_Taxes_Tab {
*/
public function disabled_message() {
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',
)),
));
} // end disabled_message;
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',
)
),
)
);
}
/**
* Adds a back link to the taxes without tax.
@ -109,8 +110,7 @@ class Dashboard_Taxes_Tab {
);
return array_merge($back_link, $links);
} // end add_back_link;
}
/**
* Register_widgets
@ -134,8 +134,7 @@ class Dashboard_Taxes_Tab {
/*
* Displays an empty page with the option to activate tax support.
*/
if (!$this->is_enabled()) {
if ( ! $this->is_enabled()) {
add_filter('wu_dashboard_display_filter', '__return_false');
add_filter('wu_dashboard_display_widgets', '__return_false');
@ -145,8 +144,7 @@ class Dashboard_Taxes_Tab {
add_filter('wu_page_get_title_links', array($this, 'add_back_link'));
return;
} // end if;
}
$this->dashboard_page = $dashboard_page;
@ -157,8 +155,7 @@ class Dashboard_Taxes_Tab {
add_meta_box('wp-ultimo-taxes-by-day', __('Taxes by Day', 'wp-ultimo'), array($this, 'output_widget_taxes_by_day'), $screen->id, 'side', 'high');
$this->register_scripts();
} // end register_widgets;
}
/**
* Registers the necessary scripts to handle the tax graph.
@ -181,7 +178,7 @@ class Dashboard_Taxes_Tab {
'september' => array(),
'october' => array(),
'november' => array(),
'december' => array()
'december' => array(),
);
$data = wu_calculate_taxes_by_month();
@ -189,38 +186,39 @@ class Dashboard_Taxes_Tab {
$index = 1;
foreach ($payments_per_month as &$month) {
$month = $data[ $index ];
$month = $data[$index];
$index++;
} // end foreach;
++$index;
}
$month_list = array();
$current_year = date_i18n('Y');
for ($i = 1; $i <= 12; $i++) {
$month_list[] = date_i18n('M y', mktime(0, 0,0,$i,1, $current_year));
$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_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(
'net_profit_label' => __('Net Profit', 'wp-ultimo'),
'taxes_label' => __('Taxes Collected', 'wp-ultimo'),
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(
'net_profit_label' => __('Net Profit', 'wp-ultimo'),
'taxes_label' => __('Taxes Collected', 'wp-ultimo'),
),
)
));
);
wp_enqueue_script('wu-tax-stats');
} // end register_scripts;
}
/**
* Renders the tax graph.
@ -231,8 +229,7 @@ class Dashboard_Taxes_Tab {
public function output_widget_taxes() {
wu_get_template('dashboard-statistics/widget-tax-graph');
} // end output_widget_taxes;
}
/**
* Renders the taxes by rate widget.
@ -244,12 +241,14 @@ class Dashboard_Taxes_Tab {
$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,
));
} // end output_widget_taxes_by_rate;
wu_get_template(
'dashboard-statistics/widget-tax-by-code',
array(
'taxes_by_rate' => $taxes_by_rate,
'page' => $this->dashboard_page,
)
);
}
/**
* Renders the taxes by date widget.
@ -261,11 +260,12 @@ class Dashboard_Taxes_Tab {
$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,
));
} // end output_widget_taxes_by_day;
} // end class Dashboard_Taxes_Tab;
wu_get_template(
'dashboard-statistics/widget-tax-by-day',
array(
'taxes_by_day' => $taxes_by_day,
'page' => $this->dashboard_page,
)
);
}
}

View File

@ -33,65 +33,62 @@ class Tax {
add_action('wu_page_wp-ultimo-settings_load', array($this, 'add_sidebar_widget'));
if ($this->is_enabled()) {
add_action('wp_ultimo_admin_pages', array($this, 'add_admin_page'));
add_action('wp_ajax_wu_get_tax_rates', array($this, 'serve_taxes_rates_via_ajax'));
add_action('wp_ajax_wu_save_tax_rates', array($this, 'save_taxes_rates'));
add_action('wu_before_search_models', function() {
add_action(
'wu_before_search_models',
function () {
$model = wu_request('model', 'state');
$model = wu_request('model', 'state');
$country = wu_request('country', 'not-present');
$country = wu_request('country', 'not-present');
if ($country === 'not-present') {
if ($country === 'not-present') {
return;
}
return;
if ($model === 'state') {
$results = wu_get_country_states($country, 'slug', 'name');
} elseif ($model === 'city') {
$states = explode(',', (string) wu_request('state', ''));
} // end if;
$results = wu_get_country_cities($country, $states, 'slug', 'name');
}
if ($model === 'state') {
$query = wu_request(
'query',
array(
'search' => 'searching....',
)
);
$results = wu_get_country_states($country, 'slug', 'name');
$s = trim((string) wu_get_isset($query, 'search', 'searching...'), '*');
} elseif ($model === 'city') {
$filtered = array();
$states = explode(',', (string) wu_request('state', ''));
if ( ! empty($s)) {
$filtered = \Arrch\Arrch::find(
$results,
array(
'sort_key' => 'name',
'where' => array(
array(array('slug', 'name'), '~', $s),
),
)
);
}
$results = wu_get_country_cities($country, $states, 'slug', 'name');
wp_send_json(array_values($filtered));
} // end if;
$query = wu_request('query', array(
'search' => 'searching....',
));
$s = trim((string) wu_get_isset($query, 'search', 'searching...'), '*');
$filtered = array();
if (!empty($s)) {
$filtered = \Arrch\Arrch::find($results, array(
'sort_key' => 'name',
'where' => array(
array(array('slug', 'name'), '~', $s),
),
));
} // end if;
wp_send_json(array_values($filtered));
exit;
});
} // end if;
} // end init;
exit;
}
);
}
}
/**
* Register tax settings.
@ -101,31 +98,41 @@ class Tax {
*/
public function add_settings() {
wu_register_settings_section('taxes', array(
'title' => __('Taxes', 'wp-ultimo'),
'desc' => __('Taxes', 'wp-ultimo'),
'icon' => 'dashicons-wu-percent',
'order' => 55,
));
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',
'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(
'enable_taxes' => 1,
),
));
} // end add_settings;
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(
'enable_taxes' => 1,
),
)
);
}
/**
* Adds the sidebar widget.
@ -135,12 +142,14 @@ class Tax {
*/
public function add_sidebar_widget() {
wu_register_settings_side_panel('taxes', array(
'title' => __('Tax Rates', 'wp-ultimo'),
'render' => array($this, 'render_taxes_side_panel'),
));
} // end add_sidebar_widget;
wu_register_settings_side_panel(
'taxes',
array(
'title' => __('Tax Rates', 'wp-ultimo'),
'render' => array($this, 'render_taxes_side_panel'),
)
);
}
/**
* Checks if this functionality is available and should be loaded.
@ -153,8 +162,7 @@ class Tax {
$is_enabled = wu_get_setting('enable_taxes', false);
return apply_filters('wu_enable_taxes', $is_enabled);
} // end is_enabled;
}
/**
* Adds the Tax Rate edit admin screen.
@ -164,9 +172,8 @@ class Tax {
*/
public function add_admin_page() {
new \WP_Ultimo\Admin_Pages\Tax_Rates_Admin_Page;
} // end add_admin_page;
new \WP_Ultimo\Admin_Pages\Tax_Rates_Admin_Page();
}
/**
* Returns the Tax Rate Types available in the platform; Filterable
@ -176,11 +183,13 @@ class Tax {
*/
public function get_tax_rate_types() {
return apply_filters('wu_get_tax_rate_types', array(
'regular' => __('Regular', 'wp-ultimo')
));
} // end get_tax_rate_types;
return apply_filters(
'wu_get_tax_rate_types',
array(
'regular' => __('Regular', 'wp-ultimo'),
)
);
}
/**
* Returns the default elements of a tax rate.
@ -204,8 +213,7 @@ class Tax {
);
return apply_filters('wu_get_tax_rate_defaults', $defaults);
} // end get_tax_rate_defaults;
}
/**
* Returns the registered tax rates.
@ -217,44 +225,43 @@ class Tax {
*/
public function get_tax_rates($fetch_state_options = false) {
$tax_rates_categories = wu_get_option('tax_rates', array(
'default' => array(
'name' => __('Default', 'wp-ultimo'),
'rates' => array(),
),
));
$tax_rates_categories = wu_get_option(
'tax_rates',
array(
'default' => array(
'name' => __('Default', 'wp-ultimo'),
'rates' => array(),
),
)
);
if (!isset($tax_rates_categories['default'])) {
if ( ! isset($tax_rates_categories['default'])) {
/**
* We need to make sure the default category is always present.
*/
$default = array_shift($tax_rates_categories);
$tax_rates_categories = array_merge(array('default' => $default), $tax_rates_categories);
} // end if;
}
foreach ($tax_rates_categories as &$tax_rate_category) {
$tax_rate_category['rates'] = array_map(
function ($rate) use ($fetch_state_options) {
$tax_rate_category['rates'] = array_map(function($rate) use ($fetch_state_options) {
if ($fetch_state_options) {
$rate['state_options'] = wu_get_country_states($rate['country'], 'slug', 'name');
}
if ($fetch_state_options) {
$rate['tax_rate'] = is_numeric($rate['tax_rate']) ? $rate['tax_rate'] : 0;
$rate['state_options'] = wu_get_country_states($rate['country'], 'slug', 'name');
} // end if;
$rate['tax_rate'] = is_numeric($rate['tax_rate']) ? $rate['tax_rate'] : 0;
return wp_parse_args($rate, $this->get_tax_rate_defaults());
}, $tax_rate_category['rates']);
} // end foreach;
return wp_parse_args($rate, $this->get_tax_rate_defaults());
},
$tax_rate_category['rates']
);
}
return apply_filters('wu_get_tax_rates', $tax_rates_categories, $fetch_state_options);
} // end get_tax_rates;
}
/**
* Retrieves the tax rates to serve via ajax.
@ -267,14 +274,11 @@ class Tax {
$tax_rates = array();
if (current_user_can('read_tax_rates')) {
$tax_rates = $this->get_tax_rates(true);
} // end if;
}
wp_send_json_success((object) $tax_rates);
} // end serve_taxes_rates_via_ajax;
}
/**
* Handles the saving of new tax rates.
@ -284,61 +288,60 @@ class Tax {
*/
public function save_taxes_rates() {
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')
));
} // end if;
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;
if (!$tax_rates) {
wp_send_json(array(
'code' => 'tax-rates-not-found',
'message' => __('No tax rates present in the request', 'wp-ultimo')
));
} // end if;
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();
foreach ($tax_rates as $tax_rate_slug => $tax_rate) {
if (!isset($tax_rate['rates'])) {
if ( ! isset($tax_rate['rates'])) {
continue;
}
} // end if;
$tax_rate['rates'] = array_map(
function ($item) {
$tax_rate['rates'] = array_map(function($item) {
unset($item['selected']);
unset($item['selected']);
unset($item['state_options']);
unset($item['state_options']);
return $item;
},
$tax_rate['rates']
);
return $item;
}, $tax_rate['rates']);
$treated_tax_rates[strtolower(sanitize_title($tax_rate_slug))] = $tax_rate;
} // end foreach;
$treated_tax_rates[ strtolower(sanitize_title($tax_rate_slug)) ] = $tax_rate;
}
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'))),
));
} // end save_taxes_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'))),
)
);
}
/**
* Render the tax side panel.
@ -409,7 +412,5 @@ class Tax {
});
</script>
<?php // phpcs:enable
} // end render_taxes_side_panel;
} // end class Tax;
}
}