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

@ -19,19 +19,21 @@ defined('ABSPATH') || exit;
*/
function wu_render_empty_state($args = array()) {
$args = wp_parse_args($args, array(
'message' => __('This is not yet available...'),
'sub_message' => __('We\'re still working on this part of the product.'),
'link_label' => __('← Go Back', 'wp-ultimo'),
'link_url' => 'javascript:history.go(-1)',
'link_classes' => '',
'link_icon' => '',
'display_background_image' => true,
));
$args = wp_parse_args(
$args,
array(
'message' => __('This is not yet available...'),
'sub_message' => __('We\'re still working on this part of the product.'),
'link_label' => __('← Go Back', 'wp-ultimo'),
'link_url' => 'javascript:history.go(-1)',
'link_classes' => '',
'link_icon' => '',
'display_background_image' => true,
)
);
return wu_get_template_contents('base/empty-state', $args);
} // end wu_render_empty_state;
}
/**
* Checks if should use wrap container or not based on user setting.
@ -41,8 +43,7 @@ function wu_render_empty_state($args = array()) {
function wu_wrap_use_container() {
echo get_user_setting('wu_use_container', false) ? 'admin-lg:wu-container admin-lg:wu-mx-auto' : '';
} // end wu_wrap_use_container;
}
/**
* Renders the responsive table single-line.
@ -56,14 +57,16 @@ function wu_wrap_use_container() {
*/
function wu_responsive_table_row($args = array(), $first_row = array(), $second_row = array()) {
$args = wp_parse_args($args, array(
'id' => '',
'title' => __('No Title', 'wp-ultimo'),
'url' => '#',
'status' => '',
'image' => '',
));
$args = wp_parse_args(
$args,
array(
'id' => '',
'title' => __('No Title', 'wp-ultimo'),
'url' => '#',
'status' => '',
'image' => '',
)
);
return wu_get_template_contents('base/responsive-table-row', compact('args', 'first_row', 'second_row'));
} // end wu_responsive_table_row;
}

View File

@ -9,7 +9,7 @@
// Exit if accessed directly
defined('ABSPATH') || exit;
use \WP_Ultimo\Helpers\Arr;
use WP_Ultimo\Helpers\Arr;
/**
* Turns a multi-dimensional array into a flat array.
@ -24,21 +24,20 @@ function wu_array_flatten($array, $indexes = false) {
$return = array();
array_walk_recursive($array, function($x, $index) use (&$return, $indexes) {
array_walk_recursive(
$array,
function ($x, $index) use (&$return, $indexes) {
if ($indexes) {
if ($indexes) {
$return[] = $index;
}
$return[] = $index;
} // end if;
$return[] = $x;
});
$return[] = $x;
}
);
return $return;
} // end wu_array_flatten;
}
/**
* Copy from http://www.php.net/manual/en/function.array-merge-recursive.php#92195
@ -74,30 +73,17 @@ function wu_array_merge_recursive_distinct(array &$array1, array &$array2, $shou
$merged = $array1;
foreach ($array2 as $key => &$value) {
if (is_array($value) && isset($merged[$key]) && is_array($merged[$key])) {
$merged[$key] = wu_array_merge_recursive_distinct($merged[$key], $value, $should_sum);
if (is_array($value) && isset($merged[ $key ]) && is_array($merged[ $key ])) {
$merged[ $key ] = wu_array_merge_recursive_distinct($merged[ $key ], $value, $should_sum);
} elseif (isset($merged[ $key ]) && is_numeric($merged[ $key ]) && is_numeric($value) && $should_sum) {
$merged[ $key ] = ((int) $merged[ $key ]) + $value;
} else {
if (isset($merged[$key]) && is_numeric($merged[$key]) && is_numeric($value) && $should_sum) {
$merged[$key] = ((int) $merged[$key]) + $value;
} else {
$merged[$key] = $value;
} // end if;
} // end if;
} // end foreach;
$merged[ $key ] = $value;
}
}
return $merged;
} // end wu_array_merge_recursive_distinct;
}
/**
* Compares two arrays and returns the diff, recursively.
@ -121,40 +107,25 @@ function wu_array_recursive_diff($array1, $array2, $to_keep = array()) {
$array2 = (array) $array2;
foreach ($array1 as $key => $value) {
if (array_key_exists($key, $array2)) {
if (is_array($value)) {
$array_recursive_diff = wu_array_recursive_diff($value, $array2[$key], $to_keep);
$array_recursive_diff = wu_array_recursive_diff($value, $array2[ $key ], $to_keep);
if (count($array_recursive_diff)) {
$arr_return[ $key ] = $array_recursive_diff;
}
} elseif ((! is_null($value) && $value != $array2[ $key ]) || ($value && $array2[ $key ] && in_array($key, $to_keep, true))) {
// phpcs:ignore
$arr_return[$key] = $array_recursive_diff;
} // end if;
} else {
if ((!is_null($value) && $value != $array2[$key]) || ($value && $array2[$key] && in_array($key, $to_keep, true))) { // phpcs:ignore
$arr_return[$key] = $value;
} // end if;
} // end if;
$arr_return[ $key ] = $value;
}
} else {
$arr_return[$key] = $value;
} // end if;
} // end foreach;
$arr_return[ $key ] = $value;
}
}
return $arr_return;
} // end wu_array_recursive_diff;
}
/**
* Array map implementation to deal with keys.
*
@ -170,8 +141,7 @@ function wu_array_map_keys($callable, $array): array {
$keys = array_map($callable, $keys);
return array_combine($keys, $array);
} // end wu_array_map_keys;
}
/**
* Converts a key => value array into an array of objects with key and value entries.
@ -208,17 +178,14 @@ function wu_key_map_to_array($assoc_array, $key_name = 'id', $value_name = 'valu
$results = array();
foreach ($assoc_array as $key => &$value) {
$results[] = array(
$key_name => $key,
$value_name => $value,
);
} // end foreach;
}
return $results;
} // end wu_key_map_to_array;
}
/**
* Find a value inside an array by a particular key or property.
@ -236,8 +203,7 @@ function wu_key_map_to_array($assoc_array, $key_name = 'id', $value_name = 'valu
function wu_array_find_by($array, $property, $expected, $flag = 0) {
return Arr::filter_by_property($array, $property, $expected, $flag);
} // end wu_array_find_by;
}
/**
* Finds all the values inside an array by a particular key or property.
@ -254,8 +220,7 @@ function wu_array_find_by($array, $property, $expected, $flag = 0) {
function wu_array_find_all_by($array, $property, $expected) {
return wu_array_find_by($array, $property, $expected, Arr::RESULTS_ALL);
} // end wu_array_find_all_by;
}
/**
* Finds the first value inside an array by a particular key or property.
@ -272,8 +237,7 @@ function wu_array_find_all_by($array, $property, $expected) {
function wu_array_find_first_by($array, $property, $expected) {
return wu_array_find_by($array, $property, $expected, Arr::RESULTS_FIRST);
} // end wu_array_find_first_by;
}
/**
* Finds the last value inside an array by a particular key or property.
@ -290,5 +254,4 @@ function wu_array_find_first_by($array, $property, $expected) {
function wu_array_find_last_by($array, $property, $expected) {
return wu_array_find_by($array, $property, $expected, Arr::RESULTS_LAST);
} // end wu_array_find_last_by;
}

View File

@ -21,12 +21,9 @@ defined('ABSPATH') || exit;
*/
function wu_get_asset($asset, $assets_dir = 'img', $base_dir = 'assets') {
if (!defined('SCRIPT_DEBUG') || !SCRIPT_DEBUG) {
if ( ! defined('SCRIPT_DEBUG') || ! SCRIPT_DEBUG) {
$asset = preg_replace('/(?<!\.min)(\.js|\.css)/', '.min$1', $asset);
} // end if;
}
return wu_url("$base_dir/$assets_dir/$asset");
} // end wu_get_asset;
}

View File

@ -9,7 +9,7 @@
// Exit if accessed directly
defined('ABSPATH') || exit;
use \WP_Ultimo\Models\Broadcast;
use WP_Ultimo\Models\Broadcast;
/**
* Queries broadcast.
@ -21,15 +21,12 @@ use \WP_Ultimo\Models\Broadcast;
*/
function wu_get_broadcasts($query = array()) {
if (!isset($query['type__in'])) {
if ( ! isset($query['type__in'])) {
$query['type__in'] = array('broadcast_email', 'broadcast_notice');
} // end if;
}
return \WP_Ultimo\Models\Broadcast::query($query);
} // end wu_get_broadcasts;
}
/**
* Returns a single broadcast defined by a particular column and value.
@ -45,10 +42,8 @@ function wu_get_broadcast_by($column, $value) {
$first_attempt = \WP_Ultimo\Models\Broadcast::get_by($column, $value);
if ($first_attempt) {
return $first_attempt;
} // end if;
}
$query = array(
'number' => 1,
@ -64,9 +59,8 @@ function wu_get_broadcast_by($column, $value) {
$results = \WP_Ultimo\Models\Broadcast::query($query);
return !empty($results) ? array_pop($results) : false;
} // end wu_get_broadcast_by;
return ! empty($results) ? array_pop($results) : false;
}
/**
* Gets a broadcast on the ID.
@ -79,8 +73,7 @@ function wu_get_broadcast_by($column, $value) {
function wu_get_broadcast($broadcast_id) {
return \WP_Ultimo\Models\Broadcast::get_by_id($broadcast_id);
} // end wu_get_broadcast;
}
/**
* Gets a broadcast on the ID.
@ -97,19 +90,14 @@ function wu_get_broadcast_targets($broadcast_id, $type) {
$targets = $object->get_message_targets();
if (is_array($targets[$type])) {
return $targets[$type];
} elseif (is_string($targets[$type])) {
return explode(',', $targets[$type]);
} // end if;
if (is_array($targets[ $type ])) {
return $targets[ $type ];
} elseif (is_string($targets[ $type ])) {
return explode(',', $targets[ $type ]);
}
return array();
} // end wu_get_broadcast_targets;
}
/**
* Creates a new broadcast.
@ -123,23 +111,25 @@ function wu_get_broadcast_targets($broadcast_id, $type) {
*/
function wu_create_broadcast($broadcast_data) {
$broadcast_data = wp_parse_args($broadcast_data, array(
'type' => 'broadcast_notice',
'notice_type' => 'success',
'date_created' => wu_get_current_time('mysql', true),
'date_modified' => wu_get_current_time('mysql', true),
'migrated_from_id' => 0,
'skip_validation' => false,
'message_targets' => array(
'customers' => array(),
'products' => array(),
),
));
$broadcast_data = wp_parse_args(
$broadcast_data,
array(
'type' => 'broadcast_notice',
'notice_type' => 'success',
'date_created' => wu_get_current_time('mysql', true),
'date_modified' => wu_get_current_time('mysql', true),
'migrated_from_id' => 0,
'skip_validation' => false,
'message_targets' => array(
'customers' => array(),
'products' => array(),
),
)
);
$broadcast = new Broadcast($broadcast_data);
$saved = $broadcast->save();
return is_wp_error($saved) ? $saved : $broadcast;
} // end wu_create_broadcast;
}

View File

@ -9,8 +9,8 @@
// Exit if accessed directly
defined('ABSPATH') || exit;
use \WP_Ultimo\Checkout\Checkout;
use \WP_Ultimo\Models\Checkout_Form;
use WP_Ultimo\Checkout\Checkout;
use WP_Ultimo\Models\Checkout_Form;
/**
* Returns a checkout_form.
@ -23,8 +23,7 @@ use \WP_Ultimo\Models\Checkout_Form;
function wu_get_checkout_form($checkout_form_id) {
return \WP_Ultimo\Models\Checkout_Form::get_by_id($checkout_form_id);
} // end wu_get_checkout_form;
}
/**
* Queries checkout_forms.
@ -37,8 +36,7 @@ function wu_get_checkout_form($checkout_form_id) {
function wu_get_checkout_forms($query = array()) {
return \WP_Ultimo\Models\Checkout_Form::query($query);
} // end wu_get_checkout_forms;
}
/**
* Returns a checkout_form based on slug.
*
@ -59,40 +57,33 @@ function wu_get_checkout_form_by_slug($checkout_form_slug) {
* @see wu_checkout_form_membership_change_form_fields filter.
*/
if ($checkout_form_slug === 'wu-checkout') {
$checkout_form = new \WP_Ultimo\Models\Checkout_Form;
$checkout_form = new \WP_Ultimo\Models\Checkout_Form();
$checkout_fields = Checkout_Form::membership_change_form_fields();
$checkout_form->set_settings($checkout_fields);
return $checkout_form;
} elseif ($checkout_form_slug === 'wu-add-new-site') {
$checkout_form = new \WP_Ultimo\Models\Checkout_Form;
$checkout_form = new \WP_Ultimo\Models\Checkout_Form();
$checkout_fields = Checkout_Form::add_new_site_form_fields();
$checkout_form->set_settings($checkout_fields);
return $checkout_form;
} elseif ($checkout_form_slug === 'wu-finish-checkout') {
$checkout_form = new \WP_Ultimo\Models\Checkout_Form;
$checkout_form = new \WP_Ultimo\Models\Checkout_Form();
$checkout_fields = Checkout_Form::finish_checkout_form_fields();
$checkout_form->set_settings($checkout_fields);
return $checkout_form;
} // end if;
}
return \WP_Ultimo\Models\Checkout_Form::get_by('slug', $checkout_form_slug);
} // end wu_get_checkout_form_by_slug;
}
/**
* Creates a new checkout form.
*
@ -103,22 +94,24 @@ function wu_get_checkout_form_by_slug($checkout_form_slug) {
*/
function wu_create_checkout_form($checkout_form_data) {
$checkout_form_data = wp_parse_args($checkout_form_data, array(
'name' => false,
'slug' => false,
'settings' => array(),
'allowed_countries' => array(),
'date_created' => wu_get_current_time('mysql', true),
'date_modified' => wu_get_current_time('mysql', true),
));
$checkout_form_data = wp_parse_args(
$checkout_form_data,
array(
'name' => false,
'slug' => false,
'settings' => array(),
'allowed_countries' => array(),
'date_created' => wu_get_current_time('mysql', true),
'date_modified' => wu_get_current_time('mysql', true),
)
);
$checkout_form = new Checkout_Form($checkout_form_data);
$saved = $checkout_form->save();
return is_wp_error($saved) ? $saved : $checkout_form;
} // end wu_create_checkout_form;
}
/**
* Returns a list of all the available domain options in all registered forms.
@ -133,46 +126,35 @@ function wu_get_available_domain_options() {
$main_form = wu_get_checkout_form_by_slug('main-form');
if ($main_form) {
$fields = $main_form->get_all_fields_by_type('site_url');
} else {
$forms = wu_get_checkout_forms(array(
'number' => 1,
));
$forms = wu_get_checkout_forms(
array(
'number' => 1,
)
);
if ($forms) {
$fields = $forms[0]->get_all_fields_by_type('site_url');
} // end if;
} // end if;
}
}
$domain_options = array();
if ($fields) {
foreach ($fields as $field) {
$available_domains = isset($field['available_domains']) ? $field['available_domains'] : '';
$field_domain_options = explode(PHP_EOL, (string) $available_domains);
if (isset($field['enable_domain_selection']) && $field['enable_domain_selection'] && $field_domain_options) {
$domain_options = array_merge($domain_options, $field_domain_options);
} // end if;
} // end foreach;
} // end if;
}
}
}
return $domain_options;
} // end wu_get_available_domain_options;
}
/**
* Check if the field is preselected in request.
@ -187,11 +169,10 @@ function wu_is_form_field_pre_selected($field_slug) {
$pre_selected = $checkout->request_or_session('pre_selected', array());
$from_request = stripslashes_deep(wu_get_isset($_GET, $field_slug)) || isset($pre_selected[$field_slug]);
$from_request = stripslashes_deep(wu_get_isset($_GET, $field_slug)) || isset($pre_selected[ $field_slug ]);
return wu_request('wu_preselected') === $field_slug || $from_request;
} // end wu_is_form_field_pre_selected;
}
/**
* Get the request arg slug from a field.
@ -203,20 +184,15 @@ function wu_is_form_field_pre_selected($field_slug) {
function wu_form_field_request_arg($field) {
if ($field['type'] === 'template_selection') {
return 'template_id';
} // end if;
}
if ($field['type'] === 'pricing_table') {
return 'products';
} // end if;
}
return $field['id'];
} // end wu_form_field_request_arg;
}
/**
* Check if the field should be hidden in form
@ -230,5 +206,4 @@ function wu_should_hide_form_field($field) {
$hide_preselect = (bool) (int) wu_get_isset($field, "hide_{$field['type']}_when_pre_selected");
return $hide_preselect && wu_is_form_field_pre_selected(wu_form_field_request_arg($field));
} // end wu_should_hide_form_field;
}

View File

@ -9,7 +9,7 @@
// Exit if accessed directly
defined('ABSPATH') || exit;
use \WP_Ultimo\Managers\Signup_Fields_Manager;
use WP_Ultimo\Managers\Signup_Fields_Manager;
/**
* Needs to be removed.
@ -22,15 +22,12 @@ function wu_errors() {
global $wu_errors;
if (!is_wp_error($wu_errors)) {
if ( ! is_wp_error($wu_errors)) {
$wu_errors = new \WP_Error();
} // end if;
}
return $wu_errors;
} // end wu_errors;
}
/**
* Generate an idempotency key.
@ -57,8 +54,7 @@ function wu_stripe_generate_idempotency_key($args, $context = 'new') {
$idempotency_key = apply_filters('wu_stripe_generate_idempotency_key', $idempotency_key, $args, $context);
return $idempotency_key;
} // end wu_stripe_generate_idempotency_key;
}
/**
* Loops through the signup field types to return the checkout fields.
@ -75,31 +71,22 @@ function wu_create_checkout_fields($fields = array()) {
$actual_fields = array();
// Extra check to prevent error messages from being displayed.
if (!is_array($fields)) {
if ( ! is_array($fields)) {
$fields = array();
} // end if;
}
foreach ($fields as $field) {
$type = $field['type'];
if (!wu_get_isset($field_types, $type)) {
if ( ! wu_get_isset($field_types, $type)) {
continue;
} // end if;
}
try {
$field_class = new $field_types[$type]();
$field_class = new $field_types[ $type ]();
} catch (\Throwable $exception) {
continue;
} // end try;
}
$field = wp_parse_args($field, $field_class->defaults());
@ -111,20 +98,14 @@ function wu_create_checkout_fields($fields = array()) {
$visibility = wu_get_isset($field, 'logged', 'always');
if ($visibility !== 'always') {
if ($visibility === 'guests_only' && is_user_logged_in()) {
continue;
}
} // end if;
if ($visibility === 'logged_only' && !is_user_logged_in()) {
if ($visibility === 'logged_only' && ! is_user_logged_in()) {
continue;
} // end if;
} // end if;
}
}
/*
* Pass the attributes down to the field class.
@ -134,10 +115,13 @@ function wu_create_checkout_fields($fields = array()) {
/*
* Makes sure we have default indexes.
*/
$field = wp_parse_args($field, array(
'element_classes' => '',
'classes' => '',
));
$field = wp_parse_args(
$field,
array(
'element_classes' => '',
'classes' => '',
)
);
$field_array = $field_class->to_fields_array($field);
@ -150,12 +134,10 @@ function wu_create_checkout_fields($fields = array()) {
do_action("wu_checkout_add_field_{$field_class->get_type()}", $field_array);
$actual_fields = array_merge($actual_fields, $field_array);
} // end foreach;
}
return $actual_fields;
} // end wu_create_checkout_fields;
}
/**
* Returns the URL for the registration page.
@ -170,31 +152,28 @@ function wu_get_registration_url($path = false) {
$url = $checkout_pages->get_page_url('register');
if (!$url) {
if ( ! $url) {
/**
* Just to be extra sure, we try to fetch the URL
* for a main site page that has the registration slug.
*/
$url = wu_switch_blog_and_run(function() {
$url = wu_switch_blog_and_run(
function () {
$maybe_register_page = get_page_by_path('register');
if ($maybe_register_page && has_shortcode($maybe_register_page->post_content, 'wu_checkout')) {
return get_the_permalink($maybe_register_page->ID);
$maybe_register_page = get_page_by_path('register');
if ($maybe_register_page && has_shortcode($maybe_register_page->post_content, 'wu_checkout')) {
return get_the_permalink($maybe_register_page->ID);
}
}
});
);
return $url ?? '#no-registration-url';
} // end if;
}
return $url . $path;
} // end wu_get_registration_url;
}
/**
* Returns the URL for the login page.
*
@ -207,15 +186,12 @@ function wu_get_login_url($path = false): string {
$url = $checkout_pages->get_page_url('login');
if (!$url) {
if ( ! $url) {
return '#no-login-url';
} // end if;
}
return $url . $path;
} // end wu_get_login_url;
}
/**
* Checks if we allow for multiple memberships.
@ -227,8 +203,7 @@ function wu_get_login_url($path = false): string {
function wu_multiple_memberships_enabled() {
return wu_get_setting('enable_multiple_memberships', true);
} // end wu_multiple_memberships_enabled;
}
/**
* Get the number of days in a billing cycle.
@ -246,26 +221,25 @@ function wu_get_days_in_cycle($duration_unit, $duration) {
$days_in_cycle = 0;
switch ($duration_unit) {
case 'day':
$days_in_cycle = $duration;
break;
case 'week':
$days_in_cycle = $duration * 7;
break;
case 'month':
$days_in_cycle = $duration * 30.4375;
break;
case 'year':
$days_in_cycle = $duration * 365.25;
break;
default:
$days_in_cycle = $days_in_cycle;
break;
} // end switch;
case 'day':
$days_in_cycle = $duration;
break;
case 'week':
$days_in_cycle = $duration * 7;
break;
case 'month':
$days_in_cycle = $duration * 30.4375;
break;
case 'year':
$days_in_cycle = $duration * 365.25;
break;
default:
$days_in_cycle = $days_in_cycle;
break;
}
return $days_in_cycle;
} // end wu_get_days_in_cycle;
}
/**
* Register a new field type.
@ -283,15 +257,16 @@ function wu_get_days_in_cycle($duration_unit, $duration) {
*/
function wu_register_field_type($field_type_id, $field_type_class_name) {
add_filter('wu_checkout_field_types', function($field_types) use ($field_type_id, $field_type_class_name) {
add_filter(
'wu_checkout_field_types',
function ($field_types) use ($field_type_id, $field_type_class_name) {
$field_types[$field_type_id] = $field_type_class_name;
$field_types[ $field_type_id ] = $field_type_class_name;
return $field_types;
});
} // end wu_register_field_type;
return $field_types;
}
);
}
/**
* Register a new field template for a field type.
@ -311,16 +286,17 @@ function wu_register_field_type($field_type_id, $field_type_class_name) {
*/
function wu_register_field_template($field_type, $field_template_id, $field_template_class_name) {
add_filter('wu_checkout_field_templates', function($field_templates) use ($field_type, $field_template_id, $field_template_class_name) {
add_filter(
'wu_checkout_field_templates',
function ($field_templates) use ($field_type, $field_template_id, $field_template_class_name) {
$field_templates_for_field_type = wu_get_isset($field_templates, $field_type, array());
$field_templates_for_field_type = wu_get_isset($field_templates, $field_type, array());
$field_templates_for_field_type[$field_template_id] = $field_template_class_name;
$field_templates_for_field_type[ $field_template_id ] = $field_template_class_name;
$field_templates[$field_type] = $field_templates_for_field_type;
$field_templates[ $field_type ] = $field_templates_for_field_type;
return $field_templates;
});
} // end wu_register_field_template;
return $field_templates;
}
);
}

View File

@ -14,7 +14,7 @@
// Exit if accessed directly
defined('ABSPATH') || exit;
use \Mexitek\PHPColors\Color;
use Mexitek\PHPColors\Color;
/**
* Returns a Color object.
@ -27,18 +27,13 @@ use \Mexitek\PHPColors\Color;
function wu_color($hex) {
try {
$color = new Color($hex);
} catch (Exception $exception) {
$color = new Color('#f9f9f9');
} // end try;
}
return $color;
} // end wu_color;
}
/**
* Gets a random color for the progress bar.
@ -61,5 +56,4 @@ function wu_get_random_color($index) {
);
return wu_get_isset($colors, $index, $colors[ rand(0, count($colors) - 1) ]);
} // end wu_get_random_color;
}

View File

@ -17,259 +17,261 @@ defined('ABSPATH') || exit;
*/
function wu_get_countries() {
return apply_filters('wu_get_countries', array(
'AF' => __('Afghanistan', 'wp-ultimo-locations'),
'AX' => __('&#197;land Islands', 'wp-ultimo-locations'),
'AL' => __('Albania', 'wp-ultimo-locations'),
'DZ' => __('Algeria', 'wp-ultimo-locations'),
'AS' => __('American Samoa', 'wp-ultimo-locations'),
'AD' => __('Andorra', 'wp-ultimo-locations'),
'AO' => __('Angola', 'wp-ultimo-locations'),
'AI' => __('Anguilla', 'wp-ultimo-locations'),
'AQ' => __('Antarctica', 'wp-ultimo-locations'),
'AG' => __('Antigua and Barbuda', 'wp-ultimo-locations'),
'AR' => __('Argentina', 'wp-ultimo-locations'),
'AM' => __('Armenia', 'wp-ultimo-locations'),
'AW' => __('Aruba', 'wp-ultimo-locations'),
'AU' => __('Australia', 'wp-ultimo-locations'),
'AT' => __('Austria', 'wp-ultimo-locations'),
'AZ' => __('Azerbaijan', 'wp-ultimo-locations'),
'BS' => __('Bahamas', 'wp-ultimo-locations'),
'BH' => __('Bahrain', 'wp-ultimo-locations'),
'BD' => __('Bangladesh', 'wp-ultimo-locations'),
'BB' => __('Barbados', 'wp-ultimo-locations'),
'BY' => __('Belarus', 'wp-ultimo-locations'),
'BE' => __('Belgium', 'wp-ultimo-locations'),
'PW' => __('Belau', 'wp-ultimo-locations'),
'BZ' => __('Belize', 'wp-ultimo-locations'),
'BJ' => __('Benin', 'wp-ultimo-locations'),
'BM' => __('Bermuda', 'wp-ultimo-locations'),
'BT' => __('Bhutan', 'wp-ultimo-locations'),
'BO' => __('Bolivia', 'wp-ultimo-locations'),
'BQ' => __('Bonaire, Saint Eustatius and Saba', 'wp-ultimo-locations'),
'BA' => __('Bosnia and Herzegovina', 'wp-ultimo-locations'),
'BW' => __('Botswana', 'wp-ultimo-locations'),
'BV' => __('Bouvet Island', 'wp-ultimo-locations'),
'BR' => __('Brazil', 'wp-ultimo-locations'),
'IO' => __('British Indian Ocean Territory', 'wp-ultimo-locations'),
'VG' => __('British Virgin Islands', 'wp-ultimo-locations'),
'BN' => __('Brunei', 'wp-ultimo-locations'),
'BG' => __('Bulgaria', 'wp-ultimo-locations'),
'BF' => __('Burkina Faso', 'wp-ultimo-locations'),
'BI' => __('Burundi', 'wp-ultimo-locations'),
'KH' => __('Cambodia', 'wp-ultimo-locations'),
'CM' => __('Cameroon', 'wp-ultimo-locations'),
'CA' => __('Canada', 'wp-ultimo-locations'),
'CV' => __('Cape Verde', 'wp-ultimo-locations'),
'KY' => __('Cayman Islands', 'wp-ultimo-locations'),
'CF' => __('Central African Republic', 'wp-ultimo-locations'),
'TD' => __('Chad', 'wp-ultimo-locations'),
'CL' => __('Chile', 'wp-ultimo-locations'),
'CN' => __('China', 'wp-ultimo-locations'),
'CX' => __('Christmas Island', 'wp-ultimo-locations'),
'CC' => __('Cocos (Keeling) Islands', 'wp-ultimo-locations'),
'CO' => __('Colombia', 'wp-ultimo-locations'),
'KM' => __('Comoros', 'wp-ultimo-locations'),
'CG' => __('Congo (Brazzaville)', 'wp-ultimo-locations'),
'CD' => __('Congo (Kinshasa)', 'wp-ultimo-locations'),
'CK' => __('Cook Islands', 'wp-ultimo-locations'),
'CR' => __('Costa Rica', 'wp-ultimo-locations'),
'HR' => __('Croatia', 'wp-ultimo-locations'),
'CU' => __('Cuba', 'wp-ultimo-locations'),
'CW' => __('Cura&ccedil;ao', 'wp-ultimo-locations'),
'CY' => __('Cyprus', 'wp-ultimo-locations'),
'CZ' => __('Czech Republic', 'wp-ultimo-locations'),
'DK' => __('Denmark', 'wp-ultimo-locations'),
'DJ' => __('Djibouti', 'wp-ultimo-locations'),
'DM' => __('Dominica', 'wp-ultimo-locations'),
'DO' => __('Dominican Republic', 'wp-ultimo-locations'),
'EC' => __('Ecuador', 'wp-ultimo-locations'),
'EG' => __('Egypt', 'wp-ultimo-locations'),
'SV' => __('El Salvador', 'wp-ultimo-locations'),
'GQ' => __('Equatorial Guinea', 'wp-ultimo-locations'),
'ER' => __('Eritrea', 'wp-ultimo-locations'),
'EE' => __('Estonia', 'wp-ultimo-locations'),
'ET' => __('Ethiopia', 'wp-ultimo-locations'),
'FK' => __('Falkland Islands', 'wp-ultimo-locations'),
'FO' => __('Faroe Islands', 'wp-ultimo-locations'),
'FJ' => __('Fiji', 'wp-ultimo-locations'),
'FI' => __('Finland', 'wp-ultimo-locations'),
'FR' => __('France', 'wp-ultimo-locations'),
'GF' => __('French Guiana', 'wp-ultimo-locations'),
'PF' => __('French Polynesia', 'wp-ultimo-locations'),
'TF' => __('French Southern Territories', 'wp-ultimo-locations'),
'GA' => __('Gabon', 'wp-ultimo-locations'),
'GM' => __('Gambia', 'wp-ultimo-locations'),
'GE' => __('Georgia', 'wp-ultimo-locations'),
'DE' => __('Germany', 'wp-ultimo-locations'),
'GH' => __('Ghana', 'wp-ultimo-locations'),
'GI' => __('Gibraltar', 'wp-ultimo-locations'),
'GR' => __('Greece', 'wp-ultimo-locations'),
'GL' => __('Greenland', 'wp-ultimo-locations'),
'GD' => __('Grenada', 'wp-ultimo-locations'),
'GP' => __('Guadeloupe', 'wp-ultimo-locations'),
'GU' => __('Guam', 'wp-ultimo-locations'),
'GT' => __('Guatemala', 'wp-ultimo-locations'),
'GG' => __('Guernsey', 'wp-ultimo-locations'),
'GN' => __('Guinea', 'wp-ultimo-locations'),
'GW' => __('Guinea-Bissau', 'wp-ultimo-locations'),
'GY' => __('Guyana', 'wp-ultimo-locations'),
'HT' => __('Haiti', 'wp-ultimo-locations'),
'HM' => __('Heard Island and McDonald Islands', 'wp-ultimo-locations'),
'HN' => __('Honduras', 'wp-ultimo-locations'),
'HK' => __('Hong Kong', 'wp-ultimo-locations'),
'HU' => __('Hungary', 'wp-ultimo-locations'),
'IS' => __('Iceland', 'wp-ultimo-locations'),
'IN' => __('India', 'wp-ultimo-locations'),
'ID' => __('Indonesia', 'wp-ultimo-locations'),
'IR' => __('Iran', 'wp-ultimo-locations'),
'IQ' => __('Iraq', 'wp-ultimo-locations'),
'IE' => __('Ireland', 'wp-ultimo-locations'),
'IM' => __('Isle of Man', 'wp-ultimo-locations'),
'IL' => __('Israel', 'wp-ultimo-locations'),
'IT' => __('Italy', 'wp-ultimo-locations'),
'CI' => __('Ivory Coast', 'wp-ultimo-locations'),
'JM' => __('Jamaica', 'wp-ultimo-locations'),
'JP' => __('Japan', 'wp-ultimo-locations'),
'JE' => __('Jersey', 'wp-ultimo-locations'),
'JO' => __('Jordan', 'wp-ultimo-locations'),
'KZ' => __('Kazakhstan', 'wp-ultimo-locations'),
'KE' => __('Kenya', 'wp-ultimo-locations'),
'KI' => __('Kiribati', 'wp-ultimo-locations'),
'KW' => __('Kuwait', 'wp-ultimo-locations'),
'KG' => __('Kyrgyzstan', 'wp-ultimo-locations'),
'LA' => __('Laos', 'wp-ultimo-locations'),
'LV' => __('Latvia', 'wp-ultimo-locations'),
'LB' => __('Lebanon', 'wp-ultimo-locations'),
'LS' => __('Lesotho', 'wp-ultimo-locations'),
'LR' => __('Liberia', 'wp-ultimo-locations'),
'LY' => __('Libya', 'wp-ultimo-locations'),
'LI' => __('Liechtenstein', 'wp-ultimo-locations'),
'LT' => __('Lithuania', 'wp-ultimo-locations'),
'LU' => __('Luxembourg', 'wp-ultimo-locations'),
'MO' => __('Macao S.A.R., China', 'wp-ultimo-locations'),
'MK' => __('Macedonia', 'wp-ultimo-locations'),
'MG' => __('Madagascar', 'wp-ultimo-locations'),
'MW' => __('Malawi', 'wp-ultimo-locations'),
'MY' => __('Malaysia', 'wp-ultimo-locations'),
'MV' => __('Maldives', 'wp-ultimo-locations'),
'ML' => __('Mali', 'wp-ultimo-locations'),
'MT' => __('Malta', 'wp-ultimo-locations'),
'MH' => __('Marshall Islands', 'wp-ultimo-locations'),
'MQ' => __('Martinique', 'wp-ultimo-locations'),
'MR' => __('Mauritania', 'wp-ultimo-locations'),
'MU' => __('Mauritius', 'wp-ultimo-locations'),
'YT' => __('Mayotte', 'wp-ultimo-locations'),
'MX' => __('Mexico', 'wp-ultimo-locations'),
'FM' => __('Micronesia', 'wp-ultimo-locations'),
'MD' => __('Moldova', 'wp-ultimo-locations'),
'MC' => __('Monaco', 'wp-ultimo-locations'),
'MN' => __('Mongolia', 'wp-ultimo-locations'),
'ME' => __('Montenegro', 'wp-ultimo-locations'),
'MS' => __('Montserrat', 'wp-ultimo-locations'),
'MA' => __('Morocco', 'wp-ultimo-locations'),
'MZ' => __('Mozambique', 'wp-ultimo-locations'),
'MM' => __('Myanmar', 'wp-ultimo-locations'),
'NA' => __('Namibia', 'wp-ultimo-locations'),
'NR' => __('Nauru', 'wp-ultimo-locations'),
'NP' => __('Nepal', 'wp-ultimo-locations'),
'NL' => __('Netherlands', 'wp-ultimo-locations'),
'NC' => __('New Caledonia', 'wp-ultimo-locations'),
'NZ' => __('New Zealand', 'wp-ultimo-locations'),
'NI' => __('Nicaragua', 'wp-ultimo-locations'),
'NE' => __('Niger', 'wp-ultimo-locations'),
'NG' => __('Nigeria', 'wp-ultimo-locations'),
'NU' => __('Niue', 'wp-ultimo-locations'),
'NF' => __('Norfolk Island', 'wp-ultimo-locations'),
'MP' => __('Northern Mariana Islands', 'wp-ultimo-locations'),
'KP' => __('North Korea', 'wp-ultimo-locations'),
'NO' => __('Norway', 'wp-ultimo-locations'),
'OM' => __('Oman', 'wp-ultimo-locations'),
'PK' => __('Pakistan', 'wp-ultimo-locations'),
'PS' => __('Palestinian Territory', 'wp-ultimo-locations'),
'PA' => __('Panama', 'wp-ultimo-locations'),
'PG' => __('Papua New Guinea', 'wp-ultimo-locations'),
'PY' => __('Paraguay', 'wp-ultimo-locations'),
'PE' => __('Peru', 'wp-ultimo-locations'),
'PH' => __('Philippines', 'wp-ultimo-locations'),
'PN' => __('Pitcairn', 'wp-ultimo-locations'),
'PL' => __('Poland', 'wp-ultimo-locations'),
'PT' => __('Portugal', 'wp-ultimo-locations'),
'PR' => __('Puerto Rico', 'wp-ultimo-locations'),
'QA' => __('Qatar', 'wp-ultimo-locations'),
'RE' => __('Reunion', 'wp-ultimo-locations'),
'RO' => __('Romania', 'wp-ultimo-locations'),
'RU' => __('Russia', 'wp-ultimo-locations'),
'RW' => __('Rwanda', 'wp-ultimo-locations'),
'BL' => __('Saint Barth&eacute;lemy', 'wp-ultimo-locations'),
'SH' => __('Saint Helena', 'wp-ultimo-locations'),
'KN' => __('Saint Kitts and Nevis', 'wp-ultimo-locations'),
'LC' => __('Saint Lucia', 'wp-ultimo-locations'),
'MF' => __('Saint Martin (French part)', 'wp-ultimo-locations'),
'SX' => __('Saint Martin (Dutch part)', 'wp-ultimo-locations'),
'PM' => __('Saint Pierre and Miquelon', 'wp-ultimo-locations'),
'VC' => __('Saint Vincent and the Grenadines', 'wp-ultimo-locations'),
'SM' => __('San Marino', 'wp-ultimo-locations'),
'ST' => __('S&atilde;o Tom&eacute; and Pr&iacute;ncipe', 'wp-ultimo-locations'),
'SA' => __('Saudi Arabia', 'wp-ultimo-locations'),
'SN' => __('Senegal', 'wp-ultimo-locations'),
'RS' => __('Serbia', 'wp-ultimo-locations'),
'SC' => __('Seychelles', 'wp-ultimo-locations'),
'SL' => __('Sierra Leone', 'wp-ultimo-locations'),
'SG' => __('Singapore', 'wp-ultimo-locations'),
'SK' => __('Slovakia', 'wp-ultimo-locations'),
'SI' => __('Slovenia', 'wp-ultimo-locations'),
'SB' => __('Solomon Islands', 'wp-ultimo-locations'),
'SO' => __('Somalia', 'wp-ultimo-locations'),
'ZA' => __('South Africa', 'wp-ultimo-locations'),
'GS' => __('South Georgia/Sandwich Islands', 'wp-ultimo-locations'),
'KR' => __('South Korea', 'wp-ultimo-locations'),
'SS' => __('South Sudan', 'wp-ultimo-locations'),
'ES' => __('Spain', 'wp-ultimo-locations'),
'LK' => __('Sri Lanka', 'wp-ultimo-locations'),
'SD' => __('Sudan', 'wp-ultimo-locations'),
'SR' => __('Suriname', 'wp-ultimo-locations'),
'SJ' => __('Svalbard and Jan Mayen', 'wp-ultimo-locations'),
'SZ' => __('Swaziland', 'wp-ultimo-locations'),
'SE' => __('Sweden', 'wp-ultimo-locations'),
'CH' => __('Switzerland', 'wp-ultimo-locations'),
'SY' => __('Syria', 'wp-ultimo-locations'),
'TW' => __('Taiwan', 'wp-ultimo-locations'),
'TJ' => __('Tajikistan', 'wp-ultimo-locations'),
'TZ' => __('Tanzania', 'wp-ultimo-locations'),
'TH' => __('Thailand', 'wp-ultimo-locations'),
'TL' => __('Timor-Leste', 'wp-ultimo-locations'),
'TG' => __('Togo', 'wp-ultimo-locations'),
'TK' => __('Tokelau', 'wp-ultimo-locations'),
'TO' => __('Tonga', 'wp-ultimo-locations'),
'TT' => __('Trinidad and Tobago', 'wp-ultimo-locations'),
'TN' => __('Tunisia', 'wp-ultimo-locations'),
'TR' => __('Turkey', 'wp-ultimo-locations'),
'TM' => __('Turkmenistan', 'wp-ultimo-locations'),
'TC' => __('Turks and Caicos Islands', 'wp-ultimo-locations'),
'TV' => __('Tuvalu', 'wp-ultimo-locations'),
'UG' => __('Uganda', 'wp-ultimo-locations'),
'UA' => __('Ukraine', 'wp-ultimo-locations'),
'AE' => __('United Arab Emirates', 'wp-ultimo-locations'),
'GB' => __('United Kingdom (UK)', 'wp-ultimo-locations'),
'US' => __('United States (US)', 'wp-ultimo-locations'),
'UM' => __('United States (US) Minor Outlying Islands', 'wp-ultimo-locations'),
'VI' => __('United States (US) Virgin Islands', 'wp-ultimo-locations'),
'UY' => __('Uruguay', 'wp-ultimo-locations'),
'UZ' => __('Uzbekistan', 'wp-ultimo-locations'),
'VU' => __('Vanuatu', 'wp-ultimo-locations'),
'VA' => __('Vatican', 'wp-ultimo-locations'),
'VE' => __('Venezuela', 'wp-ultimo-locations'),
'VN' => __('Vietnam', 'wp-ultimo-locations'),
'WF' => __('Wallis and Futuna', 'wp-ultimo-locations'),
'EH' => __('Western Sahara', 'wp-ultimo-locations'),
'WS' => __('Samoa', 'wp-ultimo-locations'),
'YE' => __('Yemen', 'wp-ultimo-locations'),
'ZM' => __('Zambia', 'wp-ultimo-locations'),
'ZW' => __('Zimbabwe', 'wp-ultimo-locations'),
));
} // end wu_get_countries;
return apply_filters(
'wu_get_countries',
array(
'AF' => __('Afghanistan', 'wp-ultimo-locations'),
'AX' => __('&#197;land Islands', 'wp-ultimo-locations'),
'AL' => __('Albania', 'wp-ultimo-locations'),
'DZ' => __('Algeria', 'wp-ultimo-locations'),
'AS' => __('American Samoa', 'wp-ultimo-locations'),
'AD' => __('Andorra', 'wp-ultimo-locations'),
'AO' => __('Angola', 'wp-ultimo-locations'),
'AI' => __('Anguilla', 'wp-ultimo-locations'),
'AQ' => __('Antarctica', 'wp-ultimo-locations'),
'AG' => __('Antigua and Barbuda', 'wp-ultimo-locations'),
'AR' => __('Argentina', 'wp-ultimo-locations'),
'AM' => __('Armenia', 'wp-ultimo-locations'),
'AW' => __('Aruba', 'wp-ultimo-locations'),
'AU' => __('Australia', 'wp-ultimo-locations'),
'AT' => __('Austria', 'wp-ultimo-locations'),
'AZ' => __('Azerbaijan', 'wp-ultimo-locations'),
'BS' => __('Bahamas', 'wp-ultimo-locations'),
'BH' => __('Bahrain', 'wp-ultimo-locations'),
'BD' => __('Bangladesh', 'wp-ultimo-locations'),
'BB' => __('Barbados', 'wp-ultimo-locations'),
'BY' => __('Belarus', 'wp-ultimo-locations'),
'BE' => __('Belgium', 'wp-ultimo-locations'),
'PW' => __('Belau', 'wp-ultimo-locations'),
'BZ' => __('Belize', 'wp-ultimo-locations'),
'BJ' => __('Benin', 'wp-ultimo-locations'),
'BM' => __('Bermuda', 'wp-ultimo-locations'),
'BT' => __('Bhutan', 'wp-ultimo-locations'),
'BO' => __('Bolivia', 'wp-ultimo-locations'),
'BQ' => __('Bonaire, Saint Eustatius and Saba', 'wp-ultimo-locations'),
'BA' => __('Bosnia and Herzegovina', 'wp-ultimo-locations'),
'BW' => __('Botswana', 'wp-ultimo-locations'),
'BV' => __('Bouvet Island', 'wp-ultimo-locations'),
'BR' => __('Brazil', 'wp-ultimo-locations'),
'IO' => __('British Indian Ocean Territory', 'wp-ultimo-locations'),
'VG' => __('British Virgin Islands', 'wp-ultimo-locations'),
'BN' => __('Brunei', 'wp-ultimo-locations'),
'BG' => __('Bulgaria', 'wp-ultimo-locations'),
'BF' => __('Burkina Faso', 'wp-ultimo-locations'),
'BI' => __('Burundi', 'wp-ultimo-locations'),
'KH' => __('Cambodia', 'wp-ultimo-locations'),
'CM' => __('Cameroon', 'wp-ultimo-locations'),
'CA' => __('Canada', 'wp-ultimo-locations'),
'CV' => __('Cape Verde', 'wp-ultimo-locations'),
'KY' => __('Cayman Islands', 'wp-ultimo-locations'),
'CF' => __('Central African Republic', 'wp-ultimo-locations'),
'TD' => __('Chad', 'wp-ultimo-locations'),
'CL' => __('Chile', 'wp-ultimo-locations'),
'CN' => __('China', 'wp-ultimo-locations'),
'CX' => __('Christmas Island', 'wp-ultimo-locations'),
'CC' => __('Cocos (Keeling) Islands', 'wp-ultimo-locations'),
'CO' => __('Colombia', 'wp-ultimo-locations'),
'KM' => __('Comoros', 'wp-ultimo-locations'),
'CG' => __('Congo (Brazzaville)', 'wp-ultimo-locations'),
'CD' => __('Congo (Kinshasa)', 'wp-ultimo-locations'),
'CK' => __('Cook Islands', 'wp-ultimo-locations'),
'CR' => __('Costa Rica', 'wp-ultimo-locations'),
'HR' => __('Croatia', 'wp-ultimo-locations'),
'CU' => __('Cuba', 'wp-ultimo-locations'),
'CW' => __('Cura&ccedil;ao', 'wp-ultimo-locations'),
'CY' => __('Cyprus', 'wp-ultimo-locations'),
'CZ' => __('Czech Republic', 'wp-ultimo-locations'),
'DK' => __('Denmark', 'wp-ultimo-locations'),
'DJ' => __('Djibouti', 'wp-ultimo-locations'),
'DM' => __('Dominica', 'wp-ultimo-locations'),
'DO' => __('Dominican Republic', 'wp-ultimo-locations'),
'EC' => __('Ecuador', 'wp-ultimo-locations'),
'EG' => __('Egypt', 'wp-ultimo-locations'),
'SV' => __('El Salvador', 'wp-ultimo-locations'),
'GQ' => __('Equatorial Guinea', 'wp-ultimo-locations'),
'ER' => __('Eritrea', 'wp-ultimo-locations'),
'EE' => __('Estonia', 'wp-ultimo-locations'),
'ET' => __('Ethiopia', 'wp-ultimo-locations'),
'FK' => __('Falkland Islands', 'wp-ultimo-locations'),
'FO' => __('Faroe Islands', 'wp-ultimo-locations'),
'FJ' => __('Fiji', 'wp-ultimo-locations'),
'FI' => __('Finland', 'wp-ultimo-locations'),
'FR' => __('France', 'wp-ultimo-locations'),
'GF' => __('French Guiana', 'wp-ultimo-locations'),
'PF' => __('French Polynesia', 'wp-ultimo-locations'),
'TF' => __('French Southern Territories', 'wp-ultimo-locations'),
'GA' => __('Gabon', 'wp-ultimo-locations'),
'GM' => __('Gambia', 'wp-ultimo-locations'),
'GE' => __('Georgia', 'wp-ultimo-locations'),
'DE' => __('Germany', 'wp-ultimo-locations'),
'GH' => __('Ghana', 'wp-ultimo-locations'),
'GI' => __('Gibraltar', 'wp-ultimo-locations'),
'GR' => __('Greece', 'wp-ultimo-locations'),
'GL' => __('Greenland', 'wp-ultimo-locations'),
'GD' => __('Grenada', 'wp-ultimo-locations'),
'GP' => __('Guadeloupe', 'wp-ultimo-locations'),
'GU' => __('Guam', 'wp-ultimo-locations'),
'GT' => __('Guatemala', 'wp-ultimo-locations'),
'GG' => __('Guernsey', 'wp-ultimo-locations'),
'GN' => __('Guinea', 'wp-ultimo-locations'),
'GW' => __('Guinea-Bissau', 'wp-ultimo-locations'),
'GY' => __('Guyana', 'wp-ultimo-locations'),
'HT' => __('Haiti', 'wp-ultimo-locations'),
'HM' => __('Heard Island and McDonald Islands', 'wp-ultimo-locations'),
'HN' => __('Honduras', 'wp-ultimo-locations'),
'HK' => __('Hong Kong', 'wp-ultimo-locations'),
'HU' => __('Hungary', 'wp-ultimo-locations'),
'IS' => __('Iceland', 'wp-ultimo-locations'),
'IN' => __('India', 'wp-ultimo-locations'),
'ID' => __('Indonesia', 'wp-ultimo-locations'),
'IR' => __('Iran', 'wp-ultimo-locations'),
'IQ' => __('Iraq', 'wp-ultimo-locations'),
'IE' => __('Ireland', 'wp-ultimo-locations'),
'IM' => __('Isle of Man', 'wp-ultimo-locations'),
'IL' => __('Israel', 'wp-ultimo-locations'),
'IT' => __('Italy', 'wp-ultimo-locations'),
'CI' => __('Ivory Coast', 'wp-ultimo-locations'),
'JM' => __('Jamaica', 'wp-ultimo-locations'),
'JP' => __('Japan', 'wp-ultimo-locations'),
'JE' => __('Jersey', 'wp-ultimo-locations'),
'JO' => __('Jordan', 'wp-ultimo-locations'),
'KZ' => __('Kazakhstan', 'wp-ultimo-locations'),
'KE' => __('Kenya', 'wp-ultimo-locations'),
'KI' => __('Kiribati', 'wp-ultimo-locations'),
'KW' => __('Kuwait', 'wp-ultimo-locations'),
'KG' => __('Kyrgyzstan', 'wp-ultimo-locations'),
'LA' => __('Laos', 'wp-ultimo-locations'),
'LV' => __('Latvia', 'wp-ultimo-locations'),
'LB' => __('Lebanon', 'wp-ultimo-locations'),
'LS' => __('Lesotho', 'wp-ultimo-locations'),
'LR' => __('Liberia', 'wp-ultimo-locations'),
'LY' => __('Libya', 'wp-ultimo-locations'),
'LI' => __('Liechtenstein', 'wp-ultimo-locations'),
'LT' => __('Lithuania', 'wp-ultimo-locations'),
'LU' => __('Luxembourg', 'wp-ultimo-locations'),
'MO' => __('Macao S.A.R., China', 'wp-ultimo-locations'),
'MK' => __('Macedonia', 'wp-ultimo-locations'),
'MG' => __('Madagascar', 'wp-ultimo-locations'),
'MW' => __('Malawi', 'wp-ultimo-locations'),
'MY' => __('Malaysia', 'wp-ultimo-locations'),
'MV' => __('Maldives', 'wp-ultimo-locations'),
'ML' => __('Mali', 'wp-ultimo-locations'),
'MT' => __('Malta', 'wp-ultimo-locations'),
'MH' => __('Marshall Islands', 'wp-ultimo-locations'),
'MQ' => __('Martinique', 'wp-ultimo-locations'),
'MR' => __('Mauritania', 'wp-ultimo-locations'),
'MU' => __('Mauritius', 'wp-ultimo-locations'),
'YT' => __('Mayotte', 'wp-ultimo-locations'),
'MX' => __('Mexico', 'wp-ultimo-locations'),
'FM' => __('Micronesia', 'wp-ultimo-locations'),
'MD' => __('Moldova', 'wp-ultimo-locations'),
'MC' => __('Monaco', 'wp-ultimo-locations'),
'MN' => __('Mongolia', 'wp-ultimo-locations'),
'ME' => __('Montenegro', 'wp-ultimo-locations'),
'MS' => __('Montserrat', 'wp-ultimo-locations'),
'MA' => __('Morocco', 'wp-ultimo-locations'),
'MZ' => __('Mozambique', 'wp-ultimo-locations'),
'MM' => __('Myanmar', 'wp-ultimo-locations'),
'NA' => __('Namibia', 'wp-ultimo-locations'),
'NR' => __('Nauru', 'wp-ultimo-locations'),
'NP' => __('Nepal', 'wp-ultimo-locations'),
'NL' => __('Netherlands', 'wp-ultimo-locations'),
'NC' => __('New Caledonia', 'wp-ultimo-locations'),
'NZ' => __('New Zealand', 'wp-ultimo-locations'),
'NI' => __('Nicaragua', 'wp-ultimo-locations'),
'NE' => __('Niger', 'wp-ultimo-locations'),
'NG' => __('Nigeria', 'wp-ultimo-locations'),
'NU' => __('Niue', 'wp-ultimo-locations'),
'NF' => __('Norfolk Island', 'wp-ultimo-locations'),
'MP' => __('Northern Mariana Islands', 'wp-ultimo-locations'),
'KP' => __('North Korea', 'wp-ultimo-locations'),
'NO' => __('Norway', 'wp-ultimo-locations'),
'OM' => __('Oman', 'wp-ultimo-locations'),
'PK' => __('Pakistan', 'wp-ultimo-locations'),
'PS' => __('Palestinian Territory', 'wp-ultimo-locations'),
'PA' => __('Panama', 'wp-ultimo-locations'),
'PG' => __('Papua New Guinea', 'wp-ultimo-locations'),
'PY' => __('Paraguay', 'wp-ultimo-locations'),
'PE' => __('Peru', 'wp-ultimo-locations'),
'PH' => __('Philippines', 'wp-ultimo-locations'),
'PN' => __('Pitcairn', 'wp-ultimo-locations'),
'PL' => __('Poland', 'wp-ultimo-locations'),
'PT' => __('Portugal', 'wp-ultimo-locations'),
'PR' => __('Puerto Rico', 'wp-ultimo-locations'),
'QA' => __('Qatar', 'wp-ultimo-locations'),
'RE' => __('Reunion', 'wp-ultimo-locations'),
'RO' => __('Romania', 'wp-ultimo-locations'),
'RU' => __('Russia', 'wp-ultimo-locations'),
'RW' => __('Rwanda', 'wp-ultimo-locations'),
'BL' => __('Saint Barth&eacute;lemy', 'wp-ultimo-locations'),
'SH' => __('Saint Helena', 'wp-ultimo-locations'),
'KN' => __('Saint Kitts and Nevis', 'wp-ultimo-locations'),
'LC' => __('Saint Lucia', 'wp-ultimo-locations'),
'MF' => __('Saint Martin (French part)', 'wp-ultimo-locations'),
'SX' => __('Saint Martin (Dutch part)', 'wp-ultimo-locations'),
'PM' => __('Saint Pierre and Miquelon', 'wp-ultimo-locations'),
'VC' => __('Saint Vincent and the Grenadines', 'wp-ultimo-locations'),
'SM' => __('San Marino', 'wp-ultimo-locations'),
'ST' => __('S&atilde;o Tom&eacute; and Pr&iacute;ncipe', 'wp-ultimo-locations'),
'SA' => __('Saudi Arabia', 'wp-ultimo-locations'),
'SN' => __('Senegal', 'wp-ultimo-locations'),
'RS' => __('Serbia', 'wp-ultimo-locations'),
'SC' => __('Seychelles', 'wp-ultimo-locations'),
'SL' => __('Sierra Leone', 'wp-ultimo-locations'),
'SG' => __('Singapore', 'wp-ultimo-locations'),
'SK' => __('Slovakia', 'wp-ultimo-locations'),
'SI' => __('Slovenia', 'wp-ultimo-locations'),
'SB' => __('Solomon Islands', 'wp-ultimo-locations'),
'SO' => __('Somalia', 'wp-ultimo-locations'),
'ZA' => __('South Africa', 'wp-ultimo-locations'),
'GS' => __('South Georgia/Sandwich Islands', 'wp-ultimo-locations'),
'KR' => __('South Korea', 'wp-ultimo-locations'),
'SS' => __('South Sudan', 'wp-ultimo-locations'),
'ES' => __('Spain', 'wp-ultimo-locations'),
'LK' => __('Sri Lanka', 'wp-ultimo-locations'),
'SD' => __('Sudan', 'wp-ultimo-locations'),
'SR' => __('Suriname', 'wp-ultimo-locations'),
'SJ' => __('Svalbard and Jan Mayen', 'wp-ultimo-locations'),
'SZ' => __('Swaziland', 'wp-ultimo-locations'),
'SE' => __('Sweden', 'wp-ultimo-locations'),
'CH' => __('Switzerland', 'wp-ultimo-locations'),
'SY' => __('Syria', 'wp-ultimo-locations'),
'TW' => __('Taiwan', 'wp-ultimo-locations'),
'TJ' => __('Tajikistan', 'wp-ultimo-locations'),
'TZ' => __('Tanzania', 'wp-ultimo-locations'),
'TH' => __('Thailand', 'wp-ultimo-locations'),
'TL' => __('Timor-Leste', 'wp-ultimo-locations'),
'TG' => __('Togo', 'wp-ultimo-locations'),
'TK' => __('Tokelau', 'wp-ultimo-locations'),
'TO' => __('Tonga', 'wp-ultimo-locations'),
'TT' => __('Trinidad and Tobago', 'wp-ultimo-locations'),
'TN' => __('Tunisia', 'wp-ultimo-locations'),
'TR' => __('Turkey', 'wp-ultimo-locations'),
'TM' => __('Turkmenistan', 'wp-ultimo-locations'),
'TC' => __('Turks and Caicos Islands', 'wp-ultimo-locations'),
'TV' => __('Tuvalu', 'wp-ultimo-locations'),
'UG' => __('Uganda', 'wp-ultimo-locations'),
'UA' => __('Ukraine', 'wp-ultimo-locations'),
'AE' => __('United Arab Emirates', 'wp-ultimo-locations'),
'GB' => __('United Kingdom (UK)', 'wp-ultimo-locations'),
'US' => __('United States (US)', 'wp-ultimo-locations'),
'UM' => __('United States (US) Minor Outlying Islands', 'wp-ultimo-locations'),
'VI' => __('United States (US) Virgin Islands', 'wp-ultimo-locations'),
'UY' => __('Uruguay', 'wp-ultimo-locations'),
'UZ' => __('Uzbekistan', 'wp-ultimo-locations'),
'VU' => __('Vanuatu', 'wp-ultimo-locations'),
'VA' => __('Vatican', 'wp-ultimo-locations'),
'VE' => __('Venezuela', 'wp-ultimo-locations'),
'VN' => __('Vietnam', 'wp-ultimo-locations'),
'WF' => __('Wallis and Futuna', 'wp-ultimo-locations'),
'EH' => __('Western Sahara', 'wp-ultimo-locations'),
'WS' => __('Samoa', 'wp-ultimo-locations'),
'YE' => __('Yemen', 'wp-ultimo-locations'),
'ZM' => __('Zambia', 'wp-ultimo-locations'),
'ZW' => __('Zimbabwe', 'wp-ultimo-locations'),
)
);
}
/**
* Returns the list of countries with an additional empty state option.
@ -279,11 +281,13 @@ function wu_get_countries() {
*/
function wu_get_countries_as_options() {
return array_merge(array(
'' => __('Select Country', 'wp-ultimo'),
), wu_get_countries());
} // end wu_get_countries_as_options;
return array_merge(
array(
'' => __('Select Country', 'wp-ultimo'),
),
wu_get_countries()
);
}
/**
* Returns the country object.
@ -302,14 +306,11 @@ function wu_get_country($country_code, $name = null, $fallback_attributes = arra
$country_class = "\\WP_Ultimo\\Country\\Country_{$country_code}";
if (class_exists($country_class)) {
return $country_class::get_instance();
} // end if;
}
return \WP_Ultimo\Country\Country_Default::build($country_code, $name, $fallback_attributes);
} // end wu_get_country;
}
/**
* Get the state list for a country.
@ -330,28 +331,21 @@ function wu_get_country_states($country_code, $key_name = 'id', $value_name = 'v
$cache = wu_get_isset($state_options, $country_code, false);
if ($cache) {
$options = $cache;
} else {
$country = wu_get_country($country_code);
$state_options[$country_code] = $country->get_states_as_options(false);
$state_options[ $country_code ] = $country->get_states_as_options(false);
$options = $state_options[$country_code];
} // end if;
$options = $state_options[ $country_code ];
}
if (empty($key_name)) {
return $options;
} // end if;
}
return wu_key_map_to_array($options, $key_name, $value_name);
} // end wu_get_country_states;
}
/**
* Get cities for a collection of states of a country.
@ -373,34 +367,25 @@ function wu_get_country_cities($country_code, $states, $key_name = 'id', $value_
$options = array();
foreach ($states as $state_code) {
$cache = wu_get_isset($city_options, $state_code, false);
if ($cache) {
$options = array_merge($options, $cache);
} else {
$country = wu_get_country($country_code);
$city_options[$state_code] = $country->get_cities_as_options($state_code, false);
$city_options[ $state_code ] = $country->get_cities_as_options($state_code, false);
$options = array_merge($options, $city_options[$state_code]);
} // end if;
} // end foreach;
$options = array_merge($options, $city_options[ $state_code ]);
}
}
if (empty($key_name)) {
return $options;
} // end if;
}
return wu_key_map_to_array($options, $key_name, $value_name);
} // end wu_get_country_cities;
}
/**
* Returns the country name for a given country code.
@ -415,8 +400,7 @@ function wu_get_country_name($country_code) {
$country_name = wu_get_isset(wu_get_countries(), $country_code, __('Not found', 'wp-ultimo'));
return apply_filters('wu_get_country_name', $country_name, $country_code);
} // end wu_get_country_name;
}
/**
* Get the list of countries and counts based on customers.
@ -437,12 +421,10 @@ function wu_get_countries_of_customers($count = 10, $start_date = false, $end_da
$date_query = '';
if ($start_date || $end_date) {
$date_query = 'AND c.date_registered >= %s AND c.date_registered <= %s';
$date_query = $wpdb->prepare($date_query, $start_date . ' 00:00:00', $end_date . " 23:59:59"); // phpcs:ignore
} // end if;
}
$query = "
SELECT m.meta_value as country, COUNT(distinct c.id) as count
@ -462,14 +444,11 @@ function wu_get_countries_of_customers($count = 10, $start_date = false, $end_da
$countries = array();
foreach ($results as $result) {
$countries[$result->country] = $result->count;
} // end foreach;
$countries[ $result->country ] = $result->count;
}
return $countries;
} // end wu_get_countries_of_customers;
}
/**
* Get the list of countries and counts based on customers.
@ -493,20 +472,16 @@ function wu_get_states_of_customers($country_code, $count = 100, $start_date = f
$date_query = '';
if ($start_date || $end_date) {
$date_query = 'AND c.date_registered >= %s AND c.date_registered <= %s';
$date_query = $wpdb->prepare($date_query, $start_date . ' 00:00:00', $end_date . " 23:59:59"); // phpcs:ignore
} // end if;
}
$states = wu_get_country_states('BR', false);
if (empty($states)) {
return array();
} // end if;
}
$states_in = implode("','", array_keys($states));
@ -526,21 +501,16 @@ function wu_get_states_of_customers($country_code, $count = 100, $start_date = f
$results = $wpdb->get_results($query); // phpcs:ignore
if (empty($results)) {
return array();
} // end if;
}
$_states = array();
foreach ($results as $result) {
$final_label = sprintf('%s (%s)', $states[ $result->state ], $result->state);
$final_label = sprintf('%s (%s)', $states[$result->state], $result->state);
$_states[$final_label] = absint($result->count);
} // end foreach;
$_states[ $final_label ] = absint($result->count);
}
return $_states;
} // end wu_get_states_of_customers;
}

View File

@ -16,61 +16,63 @@ defined('ABSPATH') || exit;
*/
function wu_get_currencies(): array {
$currencies = apply_filters('wu_currencies', array(
'AED' => __('United Arab Emirates Dirham', 'wp-ultimo'),
'ARS' => __('Argentine Peso', 'wp-ultimo'),
'AUD' => __('Australian Dollars', 'wp-ultimo'),
'BDT' => __('Bangladeshi Taka', 'wp-ultimo'),
'BRL' => __('Brazilian Real', 'wp-ultimo'),
'BGN' => __('Bulgarian Lev', 'wp-ultimo'),
'CAD' => __('Canadian Dollars', 'wp-ultimo'),
'CLP' => __('Chilean Peso', 'wp-ultimo'),
'CNY' => __('Chinese Yuan', 'wp-ultimo'),
'COP' => __('Colombian Peso', 'wp-ultimo'),
'CZK' => __('Czech Koruna', 'wp-ultimo'),
'DKK' => __('Danish Krone', 'wp-ultimo'),
'DOP' => __('Dominican Peso', 'wp-ultimo'),
'EUR' => __('Euros', 'wp-ultimo'),
'HKD' => __('Hong Kong Dollar', 'wp-ultimo'),
'HRK' => __('Croatia kuna', 'wp-ultimo'),
'HUF' => __('Hungarian Forint', 'wp-ultimo'),
'ISK' => __('Icelandic krona', 'wp-ultimo'),
'IDR' => __('Indonesia Rupiah', 'wp-ultimo'),
'INR' => __('Indian Rupee', 'wp-ultimo'),
'NPR' => __('Nepali Rupee', 'wp-ultimo'),
'ILS' => __('Israeli Shekel', 'wp-ultimo'),
'JPY' => __('Japanese Yen', 'wp-ultimo'),
'KES' => __('Kenyan Shilling', 'wp-ultimo'),
'KIP' => __('Lao Kip', 'wp-ultimo'),
'KRW' => __('South Korean Won', 'wp-ultimo'),
'MYR' => __('Malaysian Ringgits', 'wp-ultimo'),
'MXN' => __('Mexican Peso', 'wp-ultimo'),
'NGN' => __('Nigerian Naira', 'wp-ultimo'),
'NOK' => __('Norwegian Krone', 'wp-ultimo'),
'NZD' => __('New Zealand Dollar', 'wp-ultimo'),
'PYG' => __('Paraguayan Guaraní', 'wp-ultimo'),
'PHP' => __('Philippine Pesos', 'wp-ultimo'),
'PLN' => __('Polish Zloty', 'wp-ultimo'),
'GBP' => __('Pounds Sterling', 'wp-ultimo'),
'RON' => __('Romanian Leu', 'wp-ultimo'),
'RUB' => __('Russian Ruble', 'wp-ultimo'),
'SGD' => __('Singapore Dollar', 'wp-ultimo'),
'ZAR' => __('South African rand', 'wp-ultimo'),
'SAR' => __('Saudi Riyal', 'wp-ultimo'),
'SEK' => __('Swedish Krona', 'wp-ultimo'),
'CHF' => __('Swiss Franc', 'wp-ultimo'),
'TWD' => __('Taiwan New Dollars', 'wp-ultimo'),
'THB' => __('Thai Baht', 'wp-ultimo'),
'TRY' => __('Turkish Lira', 'wp-ultimo'),
'UAH' => __('Ukrainian Hryvnia', 'wp-ultimo'),
'USD' => __('US Dollars', 'wp-ultimo'),
'VND' => __('Vietnamese Dong', 'wp-ultimo'),
'EGP' => __('Egyptian Pound', 'wp-ultimo'),
));
$currencies = apply_filters(
'wu_currencies',
array(
'AED' => __('United Arab Emirates Dirham', 'wp-ultimo'),
'ARS' => __('Argentine Peso', 'wp-ultimo'),
'AUD' => __('Australian Dollars', 'wp-ultimo'),
'BDT' => __('Bangladeshi Taka', 'wp-ultimo'),
'BRL' => __('Brazilian Real', 'wp-ultimo'),
'BGN' => __('Bulgarian Lev', 'wp-ultimo'),
'CAD' => __('Canadian Dollars', 'wp-ultimo'),
'CLP' => __('Chilean Peso', 'wp-ultimo'),
'CNY' => __('Chinese Yuan', 'wp-ultimo'),
'COP' => __('Colombian Peso', 'wp-ultimo'),
'CZK' => __('Czech Koruna', 'wp-ultimo'),
'DKK' => __('Danish Krone', 'wp-ultimo'),
'DOP' => __('Dominican Peso', 'wp-ultimo'),
'EUR' => __('Euros', 'wp-ultimo'),
'HKD' => __('Hong Kong Dollar', 'wp-ultimo'),
'HRK' => __('Croatia kuna', 'wp-ultimo'),
'HUF' => __('Hungarian Forint', 'wp-ultimo'),
'ISK' => __('Icelandic krona', 'wp-ultimo'),
'IDR' => __('Indonesia Rupiah', 'wp-ultimo'),
'INR' => __('Indian Rupee', 'wp-ultimo'),
'NPR' => __('Nepali Rupee', 'wp-ultimo'),
'ILS' => __('Israeli Shekel', 'wp-ultimo'),
'JPY' => __('Japanese Yen', 'wp-ultimo'),
'KES' => __('Kenyan Shilling', 'wp-ultimo'),
'KIP' => __('Lao Kip', 'wp-ultimo'),
'KRW' => __('South Korean Won', 'wp-ultimo'),
'MYR' => __('Malaysian Ringgits', 'wp-ultimo'),
'MXN' => __('Mexican Peso', 'wp-ultimo'),
'NGN' => __('Nigerian Naira', 'wp-ultimo'),
'NOK' => __('Norwegian Krone', 'wp-ultimo'),
'NZD' => __('New Zealand Dollar', 'wp-ultimo'),
'PYG' => __('Paraguayan Guaraní', 'wp-ultimo'),
'PHP' => __('Philippine Pesos', 'wp-ultimo'),
'PLN' => __('Polish Zloty', 'wp-ultimo'),
'GBP' => __('Pounds Sterling', 'wp-ultimo'),
'RON' => __('Romanian Leu', 'wp-ultimo'),
'RUB' => __('Russian Ruble', 'wp-ultimo'),
'SGD' => __('Singapore Dollar', 'wp-ultimo'),
'ZAR' => __('South African rand', 'wp-ultimo'),
'SAR' => __('Saudi Riyal', 'wp-ultimo'),
'SEK' => __('Swedish Krona', 'wp-ultimo'),
'CHF' => __('Swiss Franc', 'wp-ultimo'),
'TWD' => __('Taiwan New Dollars', 'wp-ultimo'),
'THB' => __('Thai Baht', 'wp-ultimo'),
'TRY' => __('Turkish Lira', 'wp-ultimo'),
'UAH' => __('Ukrainian Hryvnia', 'wp-ultimo'),
'USD' => __('US Dollars', 'wp-ultimo'),
'VND' => __('Vietnamese Dong', 'wp-ultimo'),
'EGP' => __('Egyptian Pound', 'wp-ultimo'),
)
);
return array_unique($currencies);
} // end wu_get_currencies;
}
/**
* Gets the currency symbol of a currency.
@ -82,147 +84,144 @@ function wu_get_currencies(): array {
*/
function wu_get_currency_symbol($currency = '') {
if (!$currency) {
if ( ! $currency) {
$currency = wu_get_setting('currency_symbol');
} switch ($currency) {
case 'AED':
$currency_symbol = 'د.إ';
break;
case 'AUD':
case 'ARS':
case 'CAD':
case 'CLP':
case 'COP':
case 'HKD':
case 'MXN':
case 'NZD':
case 'SGD':
case 'USD':
$currency_symbol = '$';
break;
case 'BDT':
$currency_symbol = '৳&nbsp;';
break;
case 'BGN':
$currency_symbol = 'лв.';
break;
case 'BRL':
$currency_symbol = 'R$';
break;
case 'CHF':
$currency_symbol = 'CHF';
break;
case 'CNY':
case 'JPY':
case 'RMB':
$currency_symbol = '&yen;';
break;
case 'CZK':
$currency_symbol = 'Kč';
break;
case 'DKK':
$currency_symbol = 'DKK';
break;
case 'DOP':
$currency_symbol = 'RD$';
break;
case 'EGP':
$currency_symbol = 'EGP';
break;
case 'EUR':
$currency_symbol = '&euro;';
break;
case 'GBP':
$currency_symbol = '&pound;';
break;
case 'HRK':
$currency_symbol = 'Kn';
break;
case 'HUF':
$currency_symbol = 'Ft';
break;
case 'IDR':
$currency_symbol = 'Rp';
break;
case 'ILS':
$currency_symbol = '₪';
break;
case 'INR':
$currency_symbol = 'Rs.';
break;
case 'ISK':
$currency_symbol = 'Kr.';
break;
case 'KES':
$currency_symbol = 'KSh';
break;
case 'KIP':
$currency_symbol = '₭';
break;
case 'KRW':
$currency_symbol = '₩';
break;
case 'MYR':
$currency_symbol = 'RM';
break;
case 'NGN':
$currency_symbol = '₦';
break;
case 'NOK':
$currency_symbol = 'kr';
break;
case 'NPR':
$currency_symbol = 'Rs.';
break;
case 'PHP':
$currency_symbol = '₱';
break;
case 'PLN':
$currency_symbol = 'zł';
break;
case 'PYG':
$currency_symbol = '₲';
break;
case 'RON':
$currency_symbol = 'lei';
break;
case 'RUB':
$currency_symbol = 'руб.';
break;
case 'SEK':
$currency_symbol = 'kr';
break;
case 'THB':
$currency_symbol = '฿';
break;
case 'TRY':
$currency_symbol = '₺';
break;
case 'TWD':
$currency_symbol = 'NT$';
break;
case 'UAH':
$currency_symbol = '₴';
break;
case 'VND':
$currency_symbol = '₫';
break;
case 'ZAR':
$currency_symbol = 'R';
break;
case 'SAR':
$currency_symbol = 'ر.س';
break;
default:
$currency_symbol = $currency;
break;
} // end switch;
case 'AED':
$currency_symbol = 'د.إ';
break;
case 'AUD':
case 'ARS':
case 'CAD':
case 'CLP':
case 'COP':
case 'HKD':
case 'MXN':
case 'NZD':
case 'SGD':
case 'USD':
$currency_symbol = '$';
break;
case 'BDT':
$currency_symbol = '৳&nbsp;';
break;
case 'BGN':
$currency_symbol = 'лв.';
break;
case 'BRL':
$currency_symbol = 'R$';
break;
case 'CHF':
$currency_symbol = 'CHF';
break;
case 'CNY':
case 'JPY':
case 'RMB':
$currency_symbol = '&yen;';
break;
case 'CZK':
$currency_symbol = 'Kč';
break;
case 'DKK':
$currency_symbol = 'DKK';
break;
case 'DOP':
$currency_symbol = 'RD$';
break;
case 'EGP':
$currency_symbol = 'EGP';
break;
case 'EUR':
$currency_symbol = '&euro;';
break;
case 'GBP':
$currency_symbol = '&pound;';
break;
case 'HRK':
$currency_symbol = 'Kn';
break;
case 'HUF':
$currency_symbol = 'Ft';
break;
case 'IDR':
$currency_symbol = 'Rp';
break;
case 'ILS':
$currency_symbol = '₪';
break;
case 'INR':
$currency_symbol = 'Rs.';
break;
case 'ISK':
$currency_symbol = 'Kr.';
break;
case 'KES':
$currency_symbol = 'KSh';
break;
case 'KIP':
$currency_symbol = '₭';
break;
case 'KRW':
$currency_symbol = '₩';
break;
case 'MYR':
$currency_symbol = 'RM';
break;
case 'NGN':
$currency_symbol = '₦';
break;
case 'NOK':
$currency_symbol = 'kr';
break;
case 'NPR':
$currency_symbol = 'Rs.';
break;
case 'PHP':
$currency_symbol = '₱';
break;
case 'PLN':
$currency_symbol = 'zł';
break;
case 'PYG':
$currency_symbol = '₲';
break;
case 'RON':
$currency_symbol = 'lei';
break;
case 'RUB':
$currency_symbol = 'руб.';
break;
case 'SEK':
$currency_symbol = 'kr';
break;
case 'THB':
$currency_symbol = '฿';
break;
case 'TRY':
$currency_symbol = '₺';
break;
case 'TWD':
$currency_symbol = 'NT$';
break;
case 'UAH':
$currency_symbol = '₴';
break;
case 'VND':
$currency_symbol = '₫';
break;
case 'ZAR':
$currency_symbol = 'R';
break;
case 'SAR':
$currency_symbol = 'ر.س';
break;
default:
$currency_symbol = $currency;
break;
}
return apply_filters('wu_currency_symbol', $currency_symbol, $currency);
} // end wu_get_currency_symbol;
}
/**
* Formats a value into our defined format
@ -250,13 +249,16 @@ function wu_format_currency($value, $currency = null, $format = null, $thousands
// Remove invalid args
$args = array_filter($args);
$atts = wp_parse_args($args, array(
'currency' => wu_get_setting('currency_symbol'),
'format' => wu_get_setting('currency_position'),
'thousands_sep' => wu_get_setting('thousand_separator'),
'decimal_sep' => wu_get_setting('decimal_separator'),
'precision' => (int) wu_get_setting('precision', 2),
));
$atts = wp_parse_args(
$args,
array(
'currency' => wu_get_setting('currency_symbol'),
'format' => wu_get_setting('currency_position'),
'thousands_sep' => wu_get_setting('thousand_separator'),
'decimal_sep' => wu_get_setting('decimal_separator'),
'precision' => (int) wu_get_setting('precision', 2),
)
);
$currency_symbol = wu_get_currency_symbol($atts['currency']);
@ -266,8 +268,7 @@ function wu_format_currency($value, $currency = null, $format = null, $thousands
$format = str_replace('%s', $currency_symbol, $format);
return apply_filters('wu_format_currency', $format, $currency_symbol, $value);
} // end wu_format_currency;
}
/**
* Determines if WP Multisite WaaS is using a zero-decimal currency.
@ -298,8 +299,7 @@ function wu_is_zero_decimal_currency($currency = 'USD') {
);
return apply_filters('wu_is_zero_decimal_currency', in_array($currency, $zero_dec_currencies, true));
} // end wu_is_zero_decimal_currency;
}
/**
* Sets the number of decimal places based on the currency.
@ -315,14 +315,11 @@ function wu_currency_decimal_filter($decimals = 2) {
$currency = 'USD';
if (wu_is_zero_decimal_currency($currency)) {
$decimals = 0;
} // end if;
}
return apply_filters('wu_currency_decimal_filter', $decimals, $currency);
} // end wu_currency_decimal_filter;
}
/**
* Returns the multiplier for the currency. Most currencies are multiplied by 100.
@ -338,5 +335,4 @@ function wu_stripe_get_currency_multiplier($currency = 'USD') {
$multiplier = (wu_is_zero_decimal_currency($currency)) ? 1 : 100;
return apply_filters('wu_stripe_get_currency_multiplier', $multiplier, $currency);
} // end wu_stripe_get_currency_multiplier;
}

View File

@ -9,7 +9,7 @@
// Exit if accessed directly
defined('ABSPATH') || exit;
use \WP_Ultimo\Models\Customer;
use WP_Ultimo\Models\Customer;
/**
* Returns a customer.
@ -22,8 +22,7 @@ use \WP_Ultimo\Models\Customer;
function wu_get_customer($customer_id) {
return \WP_Ultimo\Models\Customer::get_by_id($customer_id);
} // end wu_get_customer;
}
/**
* Returns a single customer defined by a particular column and value.
*
@ -36,8 +35,7 @@ function wu_get_customer($customer_id) {
function wu_get_customer_by($column, $value) {
return \WP_Ultimo\Models\Customer::get_by($column, $value);
} // end wu_get_customer_by;
}
/**
* Gets a customer based on the hash.
*
@ -49,8 +47,7 @@ function wu_get_customer_by($column, $value) {
function wu_get_customer_by_hash($hash) {
return \WP_Ultimo\Models\Customer::get_by_hash($hash);
} // end wu_get_customer_by_hash;
}
/**
* Queries customers.
@ -62,24 +59,22 @@ function wu_get_customer_by_hash($hash) {
*/
function wu_get_customers($query = array()) {
if (!empty($query['search'])) {
$user_ids = get_users(array(
'blog_id' => 0,
'number' => -1,
'search' => '*' . $query['search'] . '*',
'fields' => 'ids',
));
if (!empty($user_ids)) {
if ( ! empty($query['search'])) {
$user_ids = get_users(
array(
'blog_id' => 0,
'number' => -1,
'search' => '*' . $query['search'] . '*',
'fields' => 'ids',
)
);
if ( ! empty($user_ids)) {
$query['user_id__in'] = $user_ids;
unset($query['search']);
} // end if;
} // end if;
}
}
/*
* Force search limit to customers only.
@ -87,8 +82,7 @@ function wu_get_customers($query = array()) {
$query['type'] = 'customer';
return \WP_Ultimo\Models\Customer::query($query);
} // end wu_get_customers;
}
/**
* Returns a customer based on user_id.
*
@ -100,8 +94,7 @@ function wu_get_customers($query = array()) {
function wu_get_customer_by_user_id($user_id) {
return \WP_Ultimo\Models\Customer::get_by('user_id', $user_id);
} // end wu_get_customer_by_user_id;
}
/**
* Returns the current customer.
*
@ -111,8 +104,7 @@ function wu_get_customer_by_user_id($user_id) {
function wu_get_current_customer() {
return wu_get_customer_by_user_id(get_current_user_id());
} // end wu_get_current_customer;
}
/**
* Creates a new customer.
*
@ -126,82 +118,70 @@ function wu_get_current_customer() {
*/
function wu_create_customer($customer_data) {
$customer_data = wp_parse_args($customer_data, array(
'user_id' => false,
'email' => false,
'username' => false,
'password' => false,
'vip' => false,
'ip' => false,
'email_verification' => 'none',
'meta' => array(),
'date_registered' => wu_get_current_time('mysql', true),
'date_modified' => wu_get_current_time('mysql', true),
'last_login' => wu_get_current_time('mysql', true),
'signup_form' => 'by-admin',
'billing_address' => array(),
));
$customer_data = wp_parse_args(
$customer_data,
array(
'user_id' => false,
'email' => false,
'username' => false,
'password' => false,
'vip' => false,
'ip' => false,
'email_verification' => 'none',
'meta' => array(),
'date_registered' => wu_get_current_time('mysql', true),
'date_modified' => wu_get_current_time('mysql', true),
'last_login' => wu_get_current_time('mysql', true),
'signup_form' => 'by-admin',
'billing_address' => array(),
)
);
$user = get_user_by('email', $customer_data['email']);
if (!$user) {
if ( ! $user) {
$user = get_user_by('ID', $customer_data['user_id']);
}
} // end if;
if (!$user) {
if ( ! $user) {
if ($customer_data['password']) {
$user_id = wpmu_create_user($customer_data['username'], $customer_data['password'], $customer_data['email']);
} else {
$user_id = register_new_user($customer_data['username'], $customer_data['email']);
} // end if;
}
if (is_wp_error($user_id)) {
return $user_id;
} // end if;
}
if ($user_id === false) {
return new \WP_Error('user', __('We were not able to create a new user with the provided username and email address combination.', 'wp-ultimo'), $customer_data);
} // end if;
}
} else {
$user_id = $user->ID;
}
} // end if;
if (!get_userdata($user_id)) {
if ( ! get_userdata($user_id)) {
return new \WP_Error('user_id', __('We were not able to find a user with the given user_id.', 'wp-ultimo'), $customer_data);
}
} // end if;
$customer = new Customer(array(
'user_id' => $user_id,
'email_verification' => $customer_data['email_verification'],
'meta' => $customer_data['meta'],
'date_registered' => $customer_data['date_registered'],
'signup_form' => $customer_data['signup_form'],
'billing_address' => $customer_data['billing_address'],
'last_login' => $customer_data['last_login'],
'type' => 'customer',
));
$customer = new Customer(
array(
'user_id' => $user_id,
'email_verification' => $customer_data['email_verification'],
'meta' => $customer_data['meta'],
'date_registered' => $customer_data['date_registered'],
'signup_form' => $customer_data['signup_form'],
'billing_address' => $customer_data['billing_address'],
'last_login' => $customer_data['last_login'],
'type' => 'customer',
)
);
$saved = $customer->save();
return is_wp_error($saved) ? $saved : $customer;
} // end wu_create_customer;
}
/**
* Get the customer meta types available.
@ -223,20 +203,16 @@ function wu_get_customer_meta_types($form_slugs = false) {
);
if (is_array($form_slugs)) {
$query['slug__in'] = (array) $form_slugs;
} // end if;
}
$forms = wu_get_checkout_forms($query);
foreach ($forms as $form) {
$customer_meta_fields = $form->get_all_meta_fields('customer_meta');
foreach ($customer_meta_fields as $customer_meta_field) {
$meta_keys[$customer_meta_field['id']] = array(
$meta_keys[ $customer_meta_field['id'] ] = array(
'type' => $customer_meta_field['type'],
'title' => $customer_meta_field['name'],
'description' => wu_get_isset($customer_meta_field, 'description', ''),
@ -249,14 +225,11 @@ function wu_get_customer_meta_types($form_slugs = false) {
'value' => '',
'exists' => false,
);
} // end foreach;
} // end foreach;
}
}
return $meta_keys;
} // end wu_get_customer_meta_types;
}
/**
* Returns all the meta data keys present on a customer.
@ -275,38 +248,33 @@ function wu_get_all_customer_meta($customer_id, $include_unset = true) {
$customer = wu_get_customer($customer_id);
if ($include_unset) {
$form_slugs = $customer ? array($customer->get_signup_form()) : false;
$all_meta = array_merge($all_meta, wu_get_customer_meta_types($form_slugs));
}
} // end if;
if (!$customer) {
if ( ! $customer) {
return $all_meta;
} // end if;
}
$meta_keys = $customer->get_meta('wu_custom_meta_keys');
if ($meta_keys) {
$meta_keys = array_map(
function ($item) {
$meta_keys = array_map(function($item) {
$item['exists'] = true;
$item['exists'] = true;
return $item;
}, $meta_keys);
return $item;
},
$meta_keys
);
$all_meta = wu_array_merge_recursive_distinct($all_meta, $meta_keys);
} // end if;
}
return $all_meta;
} // end wu_get_all_customer_meta;
}
/**
* Returns a customer meta.
@ -323,15 +291,12 @@ function wu_get_customer_meta($customer_id, $meta_key, $default = false, $single
$customer = wu_get_customer($customer_id);
if (!$customer) {
if ( ! $customer) {
return $default;
} // end if;
}
return $customer->get_meta($meta_key, $default, $single);
} // end wu_get_customer_meta;
}
/**
* Updates a customer meta.
@ -353,30 +318,28 @@ function wu_update_customer_meta($customer_id, $key, $value, $type = null, $titl
$customer = wu_get_customer($customer_id);
if (!$customer) {
if ( ! $customer) {
return false;
} // end if;
}
if ($type) {
$custom_keys = $customer->get_meta('wu_custom_meta_keys', array());
$custom_keys = array_merge($custom_keys, array(
$key => array(
'type' => $type,
'title' => $title,
),
));
$custom_keys = array_merge(
$custom_keys,
array(
$key => array(
'type' => $type,
'title' => $title,
),
)
);
$customer->update_meta('wu_custom_meta_keys', $custom_keys);
} // end if;
}
return $customer->update_meta($key, $value);
} // end wu_update_customer_meta;
}
/**
* Deletes a customer meta with a custom type field.
@ -391,25 +354,20 @@ function wu_delete_customer_meta($customer_id, $meta_key) {
$customer = wu_get_customer($customer_id);
if (!$customer) {
if ( ! $customer) {
return false;
} // end if;
}
$custom_keys = $customer->get_meta('wu_custom_meta_keys', array());
if (isset($custom_keys[$meta_key])) {
unset($custom_keys[$meta_key]);
if (isset($custom_keys[ $meta_key ])) {
unset($custom_keys[ $meta_key ]);
$customer->update_meta('wu_custom_meta_keys', $custom_keys);
} // end if;
}
return (bool) $customer->delete_meta($meta_key);
} // end wu_delete_customer_meta;
}
/**
* Searches for a existing gateway customer among the customer memberships.
@ -422,16 +380,17 @@ function wu_delete_customer_meta($customer_id, $meta_key) {
*/
function wu_get_customer_gateway_id($customer_id, $allowed_gateways = array()) {
$memberships = wu_get_memberships(array(
'customer_id' => absint($customer_id),
'gateway__in' => $allowed_gateways,
'number' => 1,
'gateway_customer_id__not_in' => array(''),
));
$memberships = wu_get_memberships(
array(
'customer_id' => absint($customer_id),
'gateway__in' => $allowed_gateways,
'number' => 1,
'gateway_customer_id__not_in' => array(''),
)
);
return !empty($memberships) ? $memberships[0]->get_gateway_customer_id() : '';
} // end wu_get_customer_gateway_id;
return ! empty($memberships) ? $memberships[0]->get_gateway_customer_id() : '';
}
/**
* Create a unique username for a new customer based on the email address passed.
@ -452,23 +411,18 @@ function wu_username_from_email($email, $new_user_args = array(), $suffix = '')
$username_parts = array();
if (isset($new_user_args['first_name'])) {
$username_parts[] = sanitize_user($new_user_args['first_name'], true);
} // end if;
}
if (isset($new_user_args['last_name'])) {
$username_parts[] = sanitize_user($new_user_args['last_name'], true);
} // end if;
}
// Remove empty parts.
$username_parts = array_filter($username_parts);
// If there are no parts, e.g. name had unicode chars, or was not provided, fallback to email.
if (empty($username_parts)) {
$email_parts = explode('@', $email);
$email_username = $email_parts[0];
@ -485,26 +439,21 @@ function wu_username_from_email($email, $new_user_args = array(), $suffix = '')
// Get the domain part, minus the dot.
$email_username = strtok($email_parts[1], '.');
} // end if;
}
$username_parts[] = sanitize_user($email_username, true);
} // end if;
}
$username = strtolower(implode('', $username_parts));
if ($suffix) {
$username .= $suffix;
} // end if;
}
$illegal_logins = (array) apply_filters('illegal_user_logins', array()); // phpcs:ignore
// Stop illegal logins and generate a new random username.
if (in_array(strtolower($username), array_map('strtolower', $illegal_logins), true)) {
$new_args = array();
/**
@ -525,17 +474,15 @@ function wu_username_from_email($email, $new_user_args = array(), $suffix = '')
);
return wu_username_from_email($email, $new_args, $suffix);
} // end if;
}
if (username_exists($username)) {
// Generate something unique to append to the username in case of a conflict with another user.
$suffix = '-' . zeroise(wp_rand(0, 9999), 4);
return wu_username_from_email( $email, $new_user_args, $suffix );
} // end if;
return wu_username_from_email($email, $new_user_args, $suffix);
}
/**
* Filter new customer username.
@ -547,5 +494,4 @@ function wu_username_from_email($email, $new_user_args = array(), $suffix = '')
* @param string $suffix Append string to username to make it unique.
*/
return apply_filters('wu_username_from_email', $username, $email, $new_user_args, $suffix);
} // end wu_username_from_email;
}

View File

@ -28,13 +28,8 @@ function wu_drop_tables() {
$except = apply_filters('wu_drop_tables_except', $except);
foreach ($tables as $table) {
if (!in_array($table->name, $except, true)) {
if ( ! in_array($table->name, $except, true)) {
$table->uninstall();
} // end if;
} // end foreach;
} // end wu_drop_tables;
}
}
}

View File

@ -21,28 +21,19 @@ defined('ABSPATH') || exit;
function wu_validate_date($date, $format = 'Y-m-d H:i:s') {
if (is_null($date)) {
return true;
} elseif (!$date) {
} elseif ( ! $date) {
return false;
} // end if;
}
try {
$d = \DateTime::createFromFormat($format, $date);
} catch (\Throwable $exception) {
return false;
} // end try;
}
return $d && $d->format($format) === $date;
} // end wu_validate_date;
}
/**
* Returns a Carbon object to deal with dates in a more compelling way.
@ -59,13 +50,12 @@ function wu_validate_date($date, $format = 'Y-m-d H:i:s') {
*/
function wu_date($date = false) {
if (!wu_validate_date($date)) {
if ( ! wu_validate_date($date)) {
$date = date_i18n('Y-m-d H:i:s');
}
return \DateTime::createFromFormat('Y-m-d H:i:s', $date);
} // end wu_date;
}
/**
* Returns how many days ago the first date was in relation to the second date.
@ -87,8 +77,7 @@ function wu_get_days_ago($date_1, $date_2 = false) {
$dateIntervar = $datetime_1->diff($datetime_2, false);
return - $dateIntervar->days;
} // end wu_get_days_ago;
}
/**
* Returns the current time from the network
@ -106,8 +95,7 @@ function wu_get_current_time($type = 'mysql', $gmt = false) {
restore_current_blog();
return $time;
} // end wu_get_current_time;
}
/**
* Returns a more user friendly version of the duration unit string.
@ -123,23 +111,22 @@ function wu_filter_duration_unit($unit, $length) {
$new_unit = '';
switch ($unit) {
case 'day':
$new_unit = $length > 1 ? __('Days', 'wp-ultimo') : __('Day', 'wp-ultimo');
break;
case 'month':
$new_unit = $length > 1 ? __('Months', 'wp-ultimo') : __('Month', 'wp-ultimo');
break;
case 'year':
$new_unit = $length > 1 ? __('Years', 'wp-ultimo') : __('Year', 'wp-ultimo');
break;
default:
$new_unit = $new_unit;
break;
}
case 'day':
$new_unit = $length > 1 ? __('Days', 'wp-ultimo') : __('Day', 'wp-ultimo');
break;
case 'month':
$new_unit = $length > 1 ? __('Months', 'wp-ultimo') : __('Month', 'wp-ultimo');
break;
case 'year':
$new_unit = $length > 1 ? __('Years', 'wp-ultimo') : __('Year', 'wp-ultimo');
break;
default:
$new_unit = $new_unit;
break;
}
return $new_unit;
} // end wu_filter_duration_unit;
}
/**
* Get the human time diff.
*
@ -159,20 +146,16 @@ function wu_human_time_diff($from, $limit = '-5 days', $to = false): string {
// translators: %s: date.
return sprintf(__('on %s', 'wp-ultimo'), date_i18n(get_option('date_format'), $timestamp_from));
} // end if;
}
if ($to === false) {
$to = wu_get_current_time('timestamp'); // phpcs:ignore
} // end if;
}
$placeholder = wu_get_current_time('timestamp') > $timestamp_from ? __('%s ago', 'wp-ultimo') : __('In %s', 'wp-ultimo'); // phpcs:ignore
return sprintf($placeholder, human_time_diff($timestamp_from, $to));
} // end wu_human_time_diff;
}
/**
* Converts php DateTime format to Javascript Moment format.
@ -227,11 +210,8 @@ function wu_convert_php_date_format_to_moment_js_format($php_date_format): strin
// Converts escaped characters.
foreach ($replacements as $from => $to) {
$replacements['\\' . $from] = '[' . $from . ']';
} // end foreach;
$replacements[ '\\' . $from ] = '[' . $from . ']';
}
return strtr($php_date_format, $replacements);
} // end wu_convert_php_date_format_to_moment_js_format;
}

View File

@ -17,13 +17,12 @@ defined('ABSPATH') || exit;
*/
function wu_try_unlimited_server_limits() {
// Disable memory_limit by setting it to minus 1.
// Disable memory_limit by setting it to minus 1.
@ini_set('memory_limit', '-1'); // phpcs:ignore
// Disable the time limit by setting it to 0.
// Disable the time limit by setting it to 0.
@set_time_limit(0); // phpcs:ignore
} // end wu_try_unlimited_server_limits;
}
/**
* Custom error handler for memory leaks
@ -40,5 +39,4 @@ function wu_setup_memory_limit_trap($return_type = 'plain') {
$trap->set_return_type($return_type);
$trap->setup();
} // end wu_setup_memory_limit_trap;
}

View File

@ -9,7 +9,7 @@
// Exit if accessed directly
defined('ABSPATH') || exit;
use \WP_Ultimo\Models\Discount_Code;
use WP_Ultimo\Models\Discount_Code;
/**
* Returns a discount code object searching by the code.
@ -22,8 +22,7 @@ use \WP_Ultimo\Models\Discount_Code;
function wu_get_discount_code_by_code($coupon_code) {
return \WP_Ultimo\Models\Discount_Code::get_by('code', $coupon_code);
} // end wu_get_discount_code_by_code;
}
/**
* Gets a discount code based on the ID.
*
@ -35,8 +34,7 @@ function wu_get_discount_code_by_code($coupon_code) {
function wu_get_discount_code($discount_code_id) {
return \WP_Ultimo\Models\Discount_Code::get_by_id($discount_code_id);
} // end wu_get_discount_code;
}
/**
* Queries discount codes.
@ -49,8 +47,7 @@ function wu_get_discount_code($discount_code_id) {
function wu_get_discount_codes($query = array()) {
return \WP_Ultimo\Models\Discount_Code::query($query);
} // end wu_get_discount_codes;
}
/**
* Calculates the discounted price after running it through the discount code.
*
@ -65,24 +62,17 @@ function wu_get_discount_codes($query = array()) {
function wu_get_discounted_price($base_price, $amount, $type, $format = true) {
if ($type === 'percentage') {
$discounted_price = $base_price - ($base_price * ($amount / 100));
} elseif ($type === 'absolute') {
$discounted_price = $base_price - $amount;
}
} // end if;
if (!$format) {
if ( ! $format) {
return $discounted_price;
} // end if;
}
return number_format((float) $discounted_price, 2);
} // end wu_get_discounted_price;
}
/**
* Creates a new discount code.
*
@ -95,24 +85,26 @@ function wu_get_discounted_price($base_price, $amount, $type, $format = true) {
*/
function wu_create_discount_code($discount_code_data) {
$discount_code_data = wp_parse_args($discount_code_data, array(
'max_uses' => true,
'name' => false,
'code' => false,
'value' => false,
'setup_fee_value' => false,
'start_date' => false,
'active' => true,
'expiration_date' => false,
'date_created' => wu_get_current_time('mysql', true),
'date_modified' => wu_get_current_time('mysql', true),
'skip_validation' => false,
));
$discount_code_data = wp_parse_args(
$discount_code_data,
array(
'max_uses' => true,
'name' => false,
'code' => false,
'value' => false,
'setup_fee_value' => false,
'start_date' => false,
'active' => true,
'expiration_date' => false,
'date_created' => wu_get_current_time('mysql', true),
'date_modified' => wu_get_current_time('mysql', true),
'skip_validation' => false,
)
);
$discount_code = new Discount_Code($discount_code_data);
$saved = $discount_code->save();
return is_wp_error($saved) ? $saved : $discount_code;
} // end wu_create_discount_code;
}

View File

@ -21,5 +21,4 @@ defined('ABSPATH') || exit;
function wu_get_documentation_url($slug, $return_default = true) {
return \WP_Ultimo\Documentation::get_instance()->get_link($slug, $return_default);
} // end wu_get_documentation_url;
}

View File

@ -9,7 +9,7 @@
// Exit if accessed directly
defined('ABSPATH') || exit;
use \WP_Ultimo\Models\Domain;
use WP_Ultimo\Models\Domain;
/**
* Returns a domain.
@ -22,8 +22,7 @@ use \WP_Ultimo\Models\Domain;
function wu_get_domain($domain_id) {
return \WP_Ultimo\Models\Domain::get_by_id($domain_id);
} // end wu_get_domain;
}
/**
* Queries domains.
@ -36,8 +35,7 @@ function wu_get_domain($domain_id) {
function wu_get_domains($query = array()) {
return \WP_Ultimo\Models\Domain::query($query);
} // end wu_get_domains;
}
/**
* Returns a domain based on domain.
*
@ -49,8 +47,7 @@ function wu_get_domains($query = array()) {
function wu_get_domain_by_domain($domain) {
return \WP_Ultimo\Models\Domain::get_by('domain', $domain);
} // end wu_get_domain_by_domain;
}
/**
* Creates a new domain.
*
@ -63,26 +60,27 @@ function wu_get_domain_by_domain($domain) {
*/
function wu_create_domain($domain_data) {
$domain_data = wp_parse_args($domain_data, array(
'blog_id' => false,
'domain' => false,
'active' => true,
'primary_domain' => false,
'secure' => false,
'stage' => 'checking-dns',
'date_created' => wu_get_current_time('mysql', true),
'date_modified' => wu_get_current_time('mysql', true),
));
$domain_data = wp_parse_args(
$domain_data,
array(
'blog_id' => false,
'domain' => false,
'active' => true,
'primary_domain' => false,
'secure' => false,
'stage' => 'checking-dns',
'date_created' => wu_get_current_time('mysql', true),
'date_modified' => wu_get_current_time('mysql', true),
)
);
$domain = new Domain($domain_data);
$saved = $domain->save();
if (is_wp_error($saved)) {
return $saved;
} // end if;
}
/*
* Add the processing.
@ -90,8 +88,7 @@ function wu_create_domain($domain_data) {
wu_enqueue_async_action('wu_async_process_domain_stage', array('domain_id' => $domain->get_id()), 'domain');
return $domain;
} // end wu_create_domain;
}
/**
* Restores the original URL for a mapped URL.
@ -107,7 +104,6 @@ function wu_restore_original_url($url, $blog_id) {
$site = wu_get_site($blog_id);
if ($site) {
$original_site_url = $site->get_site_url();
$mapped_domain_url = $site->get_active_site_url();
@ -117,16 +113,12 @@ function wu_restore_original_url($url, $blog_id) {
$mapped_domain = wp_parse_url($mapped_domain_url, PHP_URL_HOST);
if ($original_domain !== $mapped_domain) {
$url = str_replace($mapped_domain, $original_domain, $url);
} // end if;
} // end if;
}
}
return $url;
} // end wu_restore_original_url;
}
/**
* Adds the sso tags to a given URL.
@ -139,8 +131,7 @@ function wu_restore_original_url($url, $blog_id) {
function wu_with_sso($url) {
return \WP_Ultimo\SSO\SSO::with_sso($url);
} // end wu_with_sso;
}
/**
* Compares the current domain to the main network domain.
@ -153,5 +144,4 @@ function wu_is_same_domain() {
global $current_blog, $current_site;
return wp_parse_url(wu_get_current_url(), PHP_URL_HOST) === $current_blog->domain && $current_blog->domain === $current_site->domain;
} // end wu_is_same_domain;
}

View File

@ -17,6 +17,5 @@ defined('ABSPATH') || exit;
*/
function wu_element_setup_preview() {
!did_action('wu_element_preview') && do_action('wu_element_preview');
} // end wu_element_setup_preview;
! did_action('wu_element_preview') && do_action('wu_element_preview');
}

View File

@ -9,9 +9,9 @@
// Exit if accessed directly
defined('ABSPATH') || exit;
use \WP_Ultimo\Managers\Email_Manager;
use \WP_Ultimo\Models\Email;
use \WP_Ultimo\Helpers\Sender;
use WP_Ultimo\Managers\Email_Manager;
use WP_Ultimo\Models\Email;
use WP_Ultimo\Helpers\Sender;
/**
* Returns a email.
@ -24,8 +24,7 @@ use \WP_Ultimo\Helpers\Sender;
function wu_get_email($email_id) {
return Email::get_by_id($email_id);
} // end wu_get_email;
}
/**
* Returns a single email defined by a particular column and value.
@ -39,8 +38,7 @@ function wu_get_email($email_id) {
function wu_get_email_by($column, $value) {
return Email::get_by($column, $value);
} // end wu_get_email_by;
}
/**
* Queries emails.
@ -55,19 +53,16 @@ function wu_get_emails($query = array()) {
$query['type__in'] = array('system_email');
if (wu_get_isset($query, 'event')) {
$query['meta_query'] = array(
'event_query' => array(
'key' => 'wu_system_email_event',
'value' => wu_get_isset($query, 'event'),
),
);
} // end if;
}
return Email::query($query);
} // end wu_get_emails;
}
/**
* Get all saved system email.
@ -78,12 +73,13 @@ function wu_get_emails($query = array()) {
*/
function wu_get_all_system_emails() {
return Email::query(array(
'status__in' => array('draft', 'publish'),
'type__in' => array('system_email'),
));
} // end wu_get_all_system_emails;
return Email::query(
array(
'status__in' => array('draft', 'publish'),
'type__in' => array('system_email'),
)
);
}
/**
* Get a single or all default registered system emails.
@ -96,8 +92,7 @@ function wu_get_all_system_emails() {
function wu_get_default_system_emails($slug = '') {
return Email_Manager::get_instance()->get_default_system_emails($slug);
} // end wu_get_default_system_emails;
}
/**
* Create a single default system email.
@ -112,8 +107,7 @@ function wu_create_default_system_email($slug) {
$args = wu_get_default_system_emails($slug);
return Email_Manager::get_instance()->create_system_email($args);
} // end wu_create_default_system_email;
}
/**
* Send an email to one or more users.
@ -128,8 +122,7 @@ function wu_create_default_system_email($slug) {
function wu_send_mail($from = array(), $to = array(), $args = array()) {
return Sender::send_mail($from, $to, $args);
} // end wu_send_mail;
}
/**
* Returns email-like strings.
@ -145,8 +138,7 @@ function wu_send_mail($from = array(), $to = array(), $args = array()) {
function wu_format_email_string($email, $name = false) {
return $name ? sprintf('%s <%s>', $name, $email) : $email;
} // end wu_format_email_string;
}
/**
* Creates a new email.
@ -160,20 +152,22 @@ function wu_format_email_string($email, $name = false) {
*/
function wu_create_email($email_data) {
$email_data = wp_parse_args($email_data, array(
'type' => 'system_email',
'event' => 'Laborum consectetur',
'title' => 'Lorem Ipsum',
'slug' => 'lorem-ipsum',
'target' => 'admin',
'date_created' => wu_get_current_time('mysql', true),
'date_modified' => wu_get_current_time('mysql', true),
));
$email_data = wp_parse_args(
$email_data,
array(
'type' => 'system_email',
'event' => 'Laborum consectetur',
'title' => 'Lorem Ipsum',
'slug' => 'lorem-ipsum',
'target' => 'admin',
'date_created' => wu_get_current_time('mysql', true),
'date_modified' => wu_get_current_time('mysql', true),
)
);
$email = new Email($email_data);
$saved = $email->save();
return is_wp_error($saved) ? $saved : $email;
} // end wu_create_email;
}

View File

@ -35,5 +35,4 @@ function wu_env_picker($frontend_content, $backend_content, $is_admin = null) {
$is_admin = is_null($is_admin) ? is_admin() : $is_admin;
return $is_admin ? $backend_content : $frontend_content;
} // end wu_env_picker;
}

View File

@ -9,8 +9,8 @@
// Exit if accessed directly
defined('ABSPATH') || exit;
use \WP_Ultimo\Managers\Event_Manager;
use \WP_Ultimo\Models\Event;
use WP_Ultimo\Managers\Event_Manager;
use WP_Ultimo\Models\Event;
/**
* Add a new event to the System.
@ -24,8 +24,7 @@ use \WP_Ultimo\Models\Event;
function wu_do_event($slug, $payload) {
return Event_Manager::get_instance()->do_event($slug, $payload);
} // end wu_do_event;
}
/**
* Register a new event globally in order to set the params.
@ -39,8 +38,7 @@ function wu_do_event($slug, $payload) {
function wu_register_event_type($slug, $args) {
return Event_Manager::get_instance()->register_event($slug, $args);
} // end wu_register_event_type;
}
/**
* Gets all th events registered in the system
@ -52,8 +50,7 @@ function wu_register_event_type($slug, $args) {
function wu_get_event_types() {
return Event_Manager::get_instance()->get_events();
} // end wu_get_event_types;
}
/**
* Get the available event types as a key => label array.
@ -67,14 +64,11 @@ function wu_get_event_types_as_options() {
$event_types = Event_Manager::get_instance()->get_events();
foreach ($event_types as $event_type_key => &$event_type) {
$event_type = $event_type['name'];
} // end foreach;
}
return $event_types;
} // end wu_get_event_types_as_options;
}
/**
* Gets all th events registered in the system.
@ -87,8 +81,7 @@ function wu_get_event_types_as_options() {
function wu_get_event_type($slug) {
return Event_Manager::get_instance()->get_event($slug);
} // end wu_get_event_type;
}
/**
* Queries events.
@ -101,8 +94,7 @@ function wu_get_event_type($slug) {
function wu_get_events($query = array()) {
return \WP_Ultimo\Models\Event::query($query);
} // end wu_get_events;
}
/**
* Gets a event on the ID.
*
@ -114,8 +106,7 @@ function wu_get_events($query = array()) {
function wu_get_event($event_id) {
return \WP_Ultimo\Models\Event::get_by_id($event_id);
} // end wu_get_event;
}
/**
* Returns a event based on slug.
*
@ -127,8 +118,7 @@ function wu_get_event($event_id) {
function wu_get_event_by_slug($event_slug) {
return \WP_Ultimo\Models\Event::get_by('slug', $event_slug);
} // end wu_get_event_by_slug;
}
/**
* Creates a new event.
*
@ -143,27 +133,29 @@ function wu_create_event($event_data) {
$author_id = function_exists('get_current_user_id') ? get_current_user_id() : 0;
$event_data = wp_parse_args($event_data, array(
'severity' => Event::SEVERITY_NEUTRAL,
'initiator' => 'system',
'author_id' => $author_id,
'object_type' => 'network',
'object_id' => 0,
'date_created' => wu_get_current_time('mysql', true),
'payload' => array(
'key' => 'None',
'old_value' => 'None',
'new_value' => 'None',
),
));
$event_data = wp_parse_args(
$event_data,
array(
'severity' => Event::SEVERITY_NEUTRAL,
'initiator' => 'system',
'author_id' => $author_id,
'object_type' => 'network',
'object_id' => 0,
'date_created' => wu_get_current_time('mysql', true),
'payload' => array(
'key' => 'None',
'old_value' => 'None',
'new_value' => 'None',
),
)
);
$event = new Event($event_data);
$saved = $event->save();
return is_wp_error($saved) ? $saved : $event;
} // end wu_create_event;
}
/**
* Generates payload arrays for events.
@ -180,10 +172,8 @@ function wu_generate_event_payload($model_name, $model = false): array {
$payload = array();
if (!$model) {
if ( ! $model) {
switch ($model_name) {
case 'product':
$model = wu_mock_product();
break;
@ -202,19 +192,14 @@ function wu_generate_event_payload($model_name, $model = false): array {
case 'domain':
$model = wu_mock_domain();
break;
}
} // end switch;
if (!$model) {
if ( ! $model) {
return array();
} // end if;
} // end if;
}
}
if ($model_name === 'customer') {
$payload = $model->to_search_results();
$payload = array(
@ -225,13 +210,14 @@ function wu_generate_event_payload($model_name, $model = false): array {
'customer_email_verification' => $payload['email_verification'],
'customer_avatar' => $payload['avatar'],
'customer_billing_address' => $payload['billing_address'],
'customer_manage_url' => wu_network_admin_url('wp-ultimo-edit-customer', array(
'id' => $model->get_id(),
)),
'customer_manage_url' => wu_network_admin_url(
'wp-ultimo-edit-customer',
array(
'id' => $model->get_id(),
)
),
);
} elseif ($model_name === 'membership') {
$payload = $model->to_search_results();
$p = $payload;
@ -248,13 +234,14 @@ function wu_generate_event_payload($model_name, $model = false): array {
'membership_description' => $p['formatted_price'],
'membership_gateway' => $p['gateway'],
'membership_date_expiration' => $p['date_expiration'],
'membership_manage_url' => wu_network_admin_url('wp-ultimo-edit-membership', array(
'id' => $model->get_id(),
)),
'membership_manage_url' => wu_network_admin_url(
'wp-ultimo-edit-membership',
array(
'id' => $model->get_id(),
)
),
);
} elseif ($model_name === 'product') {
$payload = $model->to_search_results();
$payload = array(
@ -266,13 +253,14 @@ function wu_generate_event_payload($model_name, $model = false): array {
'product_currency' => $payload['currency'],
'product_description' => $payload['formatted_price'],
'product_image' => $payload['image'],
'product_manage_url' => wu_network_admin_url('wp-ultimo-edit-payment', array(
'id' => $model->get_id(),
)),
'product_manage_url' => wu_network_admin_url(
'wp-ultimo-edit-payment',
array(
'id' => $model->get_id(),
)
),
);
} elseif ($model_name === 'payment') {
$payload = $model->to_search_results();
$payload = array(
@ -290,13 +278,14 @@ function wu_generate_event_payload($model_name, $model = false): array {
'payment_date_created' => $payload['date_created'],
'payment_gateway' => $payload['gateway'],
'payment_invoice_url' => $model->get_invoice_url(),
'payment_manage_url' => wu_network_admin_url('wp-ultimo-edit-payment', array(
'id' => $model->get_id(),
)),
'payment_manage_url' => wu_network_admin_url(
'wp-ultimo-edit-payment',
array(
'id' => $model->get_id(),
)
),
);
} elseif ($model_name === 'site') {
$payload = $model->to_search_results();
$payload = array(
@ -305,13 +294,14 @@ function wu_generate_event_payload($model_name, $model = false): array {
'site_description' => $payload['description'],
'site_url' => $payload['siteurl'],
'site_admin_url' => get_admin_url($model->get_id()),
'site_manage_url' => wu_network_admin_url('wp-ultimo-edit-site', array(
'id' => $model->get_id(),
)),
'site_manage_url' => wu_network_admin_url(
'wp-ultimo-edit-site',
array(
'id' => $model->get_id(),
)
),
);
} elseif ($model_name === 'domain') {
$payload = $model->to_search_results();
$payload = array(
@ -323,16 +313,17 @@ function wu_generate_event_payload($model_name, $model = false): array {
'domain_primary' => var_export(wu_string_to_bool($payload['primary_domain']), true),
'domain_secure' => var_export(wu_string_to_bool($payload['secure']), true),
'domain_date_created' => $payload['date_created'],
'domain_manage_url' => wu_network_admin_url('wp-ultimo-edit-domain', array(
'id' => $model->get_id(),
)),
'domain_manage_url' => wu_network_admin_url(
'wp-ultimo-edit-domain',
array(
'id' => $model->get_id(),
)
),
);
} // end if;
}
return $payload;
} // end wu_generate_event_payload;
}
/**
* Checks if the payload is a callable or if it's ready to use.
@ -345,10 +336,8 @@ function wu_generate_event_payload($model_name, $model = false): array {
function wu_maybe_lazy_load_payload($payload) {
if (is_callable($payload)) {
$payload = (array) call_user_func($payload);
} // end if;
}
/*
* Adds the version number for control purposes.
@ -356,5 +345,4 @@ function wu_maybe_lazy_load_payload($payload) {
$payload['wu_version'] = wu_get_version();
return $payload;
} // end wu_maybe_lazy_load_payload;
}

View File

@ -9,8 +9,8 @@
// Exit if accessed directly
defined('ABSPATH') || exit;
use \WP_Ultimo\Database\Payments\Payment_Status;
use \WP_Ultimo\Database\Memberships\Membership_Status;
use WP_Ultimo\Database\Payments\Payment_Status;
use WP_Ultimo\Database\Memberships\Membership_Status;
/**
* Calculates the Monthly Recurring Revenue of the network.
@ -22,22 +22,21 @@ function wu_calculate_mrr() {
$total_mrr = 0;
$memberships = wu_get_memberships(array(
'recurring' => true,
'status__in' => array(
Membership_Status::ACTIVE,
),
));
$memberships = wu_get_memberships(
array(
'recurring' => true,
'status__in' => array(
Membership_Status::ACTIVE,
),
)
);
foreach ($memberships as $membership) {
$recurring_amount = $membership->get_amount();
if (!$membership->is_recurring()) {
if ( ! $membership->is_recurring()) {
continue;
} // end if;
}
$duration = $membership->get_duration() ? $membership->get_duration() : 1;
@ -48,12 +47,10 @@ function wu_calculate_mrr() {
$mrr = $recurring_amount / ($duration * $normalized_duration_unit);
$total_mrr += $mrr;
} // end foreach;
}
return $total_mrr;
} // end wu_calculate_mrr;
}
/**
* Converts the duration unit strings such as 'day', 'year' and such into
@ -69,26 +66,25 @@ function wu_convert_duration_unit_to_month($duration_unit) {
$months = 1;
switch ($duration_unit) {
case 'day':
$months = 1 / 30;
break;
case 'week':
$months = 1 / 4;
break;
case 'month':
$months = 1;
break;
case 'year':
$months = 12;
break;
default:
$months = $months;
break;
} // end switch;
case 'day':
$months = 1 / 30;
break;
case 'week':
$months = 1 / 4;
break;
case 'month':
$months = 1;
break;
case 'year':
$months = 12;
break;
default:
$months = $months;
break;
}
return $months;
} // end wu_convert_duration_unit_to_month;
}
/**
* Calculates the Annual Recurring Revenue.
@ -101,8 +97,7 @@ function wu_convert_duration_unit_to_month($duration_unit) {
function wu_calculate_arr() {
return wu_calculate_mrr() * 12;
} // end wu_calculate_arr;
}
/**
* Calculates the total revenue.
@ -128,32 +123,25 @@ function wu_calculate_revenue($start_date = false, $end_date = false, $inclusive
);
if ($start_date) {
$query_args['date_query']['column'] = 'date_created';
$query_args['date_query']['after'] = $start_date;
$query_args['date_query']['inclusive'] = $inclusive;
} // end if;
}
if ($end_date) {
$query_args['date_query']['column'] = 'date_created';
$query_args['date_query']['before'] = $end_date;
$query_args['date_query']['inclusive'] = $inclusive;
} // end if;
}
$payments = wu_get_payments($query_args);
foreach ($payments as $payment) {
$total_revenue += (float) $payment->total;
} // end foreach;
}
return $total_revenue;
} // end wu_calculate_revenue;
}
/**
* Calculates the total refunds.
@ -179,32 +167,25 @@ function wu_calculate_refunds($start_date = false, $end_date = false, $inclusive
);
if ($start_date) {
$query_args['date_query']['column'] = 'date_created';
$query_args['date_query']['after'] = $start_date;
$query_args['date_query']['inclusive'] = $inclusive;
} // end if;
}
if ($end_date) {
$query_args['date_query']['column'] = 'date_created';
$query_args['date_query']['before'] = $end_date;
$query_args['date_query']['inclusive'] = $inclusive;
} // end if;
}
$payments = wu_get_payments($query_args);
foreach ($payments as $payment) {
$total_revenue += -(float) $payment->refund_total;
} // end foreach;
}
return $total_revenue;
} // end wu_calculate_refunds;
}
/**
* Calculates the taxes collected grouped by the rate.
@ -223,18 +204,14 @@ function wu_calculate_taxes_by_rate($start_date = false, $end_date = false, $inc
);
if ($start_date) {
$query_args['date_query']['after'] = $start_date;
$query_args['date_query']['inclusive'] = $inclusive;
} // end if;
}
if ($end_date) {
$query_args['date_query']['before'] = $end_date;
$query_args['date_query']['inclusive'] = $inclusive;
} // end if;
}
$order = 0;
@ -243,22 +220,17 @@ function wu_calculate_taxes_by_rate($start_date = false, $end_date = false, $inc
$line_items_groups = \WP_Ultimo\Checkout\Line_Item::get_line_items($query_args);
foreach ($line_items_groups as $line_items_group) {
$order++;
++$order;
foreach ($line_items_group as $line_item) {
$tax_name = $line_item->get_tax_label();
if ($line_item->get_tax_rate() <= 0) {
continue;
}
} // end if;
if (!wu_get_isset($taxes_paid_list, $tax_name)) {
$taxes_paid_list[$tax_name] = array(
if ( ! wu_get_isset($taxes_paid_list, $tax_name)) {
$taxes_paid_list[ $tax_name ] = array(
'title' => $tax_name,
'country' => '',
'state' => '',
@ -266,21 +238,15 @@ function wu_calculate_taxes_by_rate($start_date = false, $end_date = false, $inc
'tax_rate' => $line_item->get_tax_rate(),
'tax_total' => $line_item->get_tax_total(),
);
} else {
$taxes_paid_list[$tax_name]['tax_total'] += $line_item->get_tax_total();
$taxes_paid_list[$tax_name]['order_count'] += $order;
} // end if;
} // end foreach;
} // end foreach;
$taxes_paid_list[ $tax_name ]['tax_total'] += $line_item->get_tax_total();
$taxes_paid_list[ $tax_name ]['order_count'] += $order;
}
}
}
return $taxes_paid_list;
} // end wu_calculate_taxes_by_rate;
}
/**
* Aggregate financial data on a per product basis.
@ -300,18 +266,14 @@ function wu_calculate_financial_data_by_product($start_date = false, $end_date =
);
if ($start_date) {
$query_args['date_query']['after'] = $start_date;
$query_args['date_query']['inclusive'] = $inclusive;
} // end if;
}
if ($end_date) {
$query_args['date_query']['before'] = $end_date;
$query_args['date_query']['inclusive'] = $inclusive;
} // end if;
}
$line_items_groups = \WP_Ultimo\Checkout\Line_Item::get_line_items($query_args);
@ -320,43 +282,32 @@ function wu_calculate_financial_data_by_product($start_date = false, $end_date =
$products = wu_get_products();
foreach ($products as $product) {
$data[$product->get_id()] = array(
$data[ $product->get_id() ] = array(
'label' => $product->get_name(),
'revenue' => 0,
);
} // end foreach;
}
foreach ($line_items_groups as $line_items_group) {
foreach ($line_items_group as $line_item) {
$product_id = $line_item->get_product_id();
if (empty($product_id)) {
continue;
}
} // end if;
if (!wu_get_isset($data, $product_id)) {
if ( ! wu_get_isset($data, $product_id)) {
continue;
}
} // end if;
$data[$product_id]['revenue'] += $line_item->get_total();
} // end foreach;
} // end foreach;
$data[ $product_id ]['revenue'] += $line_item->get_total();
}
}
uasort($data, fn($a, $b) => wu_sort_by_column($b, $a, 'revenue'));
return $data;
} // end wu_calculate_financial_data_by_product;
}
/**
* Calculates the taxes collected grouped by date.
@ -375,18 +326,14 @@ function wu_calculate_taxes_by_day($start_date = false, $end_date = false, $incl
);
if ($start_date) {
$query_args['date_query']['after'] = $start_date;
$query_args['date_query']['inclusive'] = $inclusive;
} // end if;
}
if ($end_date) {
$query_args['date_query']['before'] = $end_date;
$query_args['date_query']['inclusive'] = $inclusive;
} // end if;
}
$line_items_groups = \WP_Ultimo\Checkout\Line_Item::get_line_items($query_args);
@ -401,47 +348,36 @@ function wu_calculate_taxes_by_day($start_date = false, $end_date = false, $incl
$days = array_reverse(iterator_to_array($period));
foreach ($days as $day_datetime) {
$data[$day_datetime->format('Y-m-d')] = array(
$data[ $day_datetime->format('Y-m-d') ] = array(
'order_count' => 0,
'total' => 0,
'tax_total' => 0,
'net_profit' => 0,
);
} // end foreach;
}
foreach ($line_items_groups as $line_items_group) {
foreach ($line_items_group as $line_item) {
$date = gmdate('Y-m-d', strtotime((string) $line_item->date_created));
if (!wu_get_isset($data, $date)) {
$data[$date] = array(
if ( ! wu_get_isset($data, $date)) {
$data[ $date ] = array(
'order_count' => 0,
'total' => $line_item->get_total(),
'tax_total' => $line_item->get_tax_total(),
'net_profit' => $line_item->get_total() - $line_item->get_tax_total(),
);
} else {
$data[$date]['order_count'] += 1;
$data[$date]['total'] += $line_item->get_total();
$data[$date]['tax_total'] += $line_item->get_tax_total();
$data[$date]['net_profit'] += $line_item->get_total() - $line_item->get_tax_total();
} // end if;
} // end foreach;
} // end foreach;
$data[ $date ]['order_count'] += 1;
$data[ $date ]['total'] += $line_item->get_total();
$data[ $date ]['tax_total'] += $line_item->get_tax_total();
$data[ $date ]['net_profit'] += $line_item->get_total() - $line_item->get_tax_total();
}
}
}
return $data;
} // end wu_calculate_taxes_by_day;
}
/**
* Calculates the taxes collected this year, segregated by month.
@ -454,10 +390,8 @@ function wu_calculate_taxes_by_month() {
$cache = get_site_transient('wu_tax_monthly_stats');
if (is_array($cache)) {
return $cache;
} // end if;
}
$query_args = array(
'date_query' => array(
@ -480,49 +414,38 @@ function wu_calculate_taxes_by_month() {
$months = iterator_to_array($period);
foreach ($months as $month_datetime) {
$data[$month_datetime->format('n')] = array(
$data[ $month_datetime->format('n') ] = array(
'order_count' => 0,
'total' => 0,
'tax_total' => 0,
'net_profit' => 0,
);
} // end foreach;
}
foreach ($line_items_groups as $line_items_group) {
foreach ($line_items_group as $line_item) {
$date = gmdate('n', strtotime((string) $line_item->date_created));
if (!wu_get_isset($data, $date)) {
$data[$date] = array(
if ( ! wu_get_isset($data, $date)) {
$data[ $date ] = array(
'order_count' => 0,
'total' => $line_item->get_total(),
'tax_total' => $line_item->get_tax_total(),
'net_profit' => $line_item->get_total() - $line_item->get_tax_total(),
);
} else {
$data[$date]['order_count'] += 1;
$data[$date]['total'] += $line_item->get_total();
$data[$date]['tax_total'] += $line_item->get_tax_total();
$data[$date]['net_profit'] += $line_item->get_total() - $line_item->get_tax_total();
} // end if;
} // end foreach;
} // end foreach;
$data[ $date ]['order_count'] += 1;
$data[ $date ]['total'] += $line_item->get_total();
$data[ $date ]['tax_total'] += $line_item->get_tax_total();
$data[ $date ]['net_profit'] += $line_item->get_total() - $line_item->get_tax_total();
}
}
}
set_site_transient('wu_tax_monthly_stats', $data);
return $data;
} // end wu_calculate_taxes_by_month;
}
/**
* Returns the number of sign-ups by form slug.
@ -543,18 +466,14 @@ function wu_calculate_signups_by_form($start_date = false, $end_date = false, $i
);
if ($start_date) {
$query['date_query']['after'] = $start_date;
$query['date_query']['inclusive'] = $inclusive;
} // end if;
}
if ($end_date) {
$query['date_query']['before'] = $end_date;
$query['date_query']['inclusive'] = $inclusive;
} // end if;
}
$date_query = new \WP_Date_Query($query['date_query']);
@ -577,4 +496,4 @@ function wu_calculate_signups_by_form($start_date = false, $end_date = false, $i
return $results;
} // end wu_calculate_signups_by_form;
}

View File

@ -9,7 +9,7 @@
// Exit if accessed directly
defined('ABSPATH') || exit;
use \WP_Ultimo\Managers\Form_Manager;
use WP_Ultimo\Managers\Form_Manager;
/**
* Registers a new Ajax Form.
@ -28,8 +28,7 @@ use \WP_Ultimo\Managers\Form_Manager;
function wu_register_form($form_id, $atts = array()) {
return Form_Manager::get_instance()->register_form($form_id, $atts);
} // end wu_register_form;
}
/**
* Returns the ajax URL for a given form.
@ -45,21 +44,21 @@ function wu_register_form($form_id, $atts = array()) {
function wu_get_form_url($form_id, $atts = array(), $inline = false) {
if ($inline) {
$atts = wp_parse_args($atts, array(
'inlineId' => $form_id,
'width' => '400',
'height' => '360',
));
$atts = wp_parse_args(
$atts,
array(
'inlineId' => $form_id,
'width' => '400',
'height' => '360',
)
);
// TB_inline?height=300&width=300&inlineId=wu-add-field
return add_query_arg($atts, '#TB_inline');
} // end if;
}
return Form_Manager::get_instance()->get_form_url($form_id, $atts, $inline);
} // end wu_get_form_url;
}
/**
* Adds our fork of the thickbox script.
@ -70,5 +69,4 @@ function wu_get_form_url($form_id, $atts = array(), $inline = false) {
function add_wubox() { // phpcs:ignore
wp_enqueue_script('wubox');
} // end add_wubox;
}

View File

@ -21,19 +21,16 @@ function wu_get_main_site_upload_dir() {
is_multisite() && switch_to_blog($current_site->blog_id);
if (!defined('WP_CONTENT_URL')) {
if ( ! defined('WP_CONTENT_URL')) {
define('WP_CONTENT_URL', get_option('siteurl') . '/wp-content');
} // end if;
}
$uploads = wp_upload_dir(null, false);
is_multisite() && restore_current_blog();
return $uploads;
} // end wu_get_main_site_upload_dir;
}
/**
* Creates a WP Multisite WaaS folder inside the uploads folder - if needed - and return its path.
@ -53,7 +50,7 @@ function wu_maybe_create_folder($folder, ...$path) {
/*
* Checks if the folder exists.
*/
if (!file_exists($folder_path)) {
if ( ! file_exists($folder_path)) {
// Creates the Folder
wp_mkdir_p($folder_path);
@ -61,34 +58,28 @@ function wu_maybe_create_folder($folder, ...$path) {
// Creates htaccess
$htaccess = $folder_path . '.htaccess';
if (!file_exists($htaccess)) {
if ( ! file_exists($htaccess)) {
$fp = @fopen($htaccess, 'w');
@fputs($fp, 'deny from all'); // phpcs:ignore
@fclose($fp); // phpcs:ignore
} // end if;
}
// Creates index
$index = $folder_path . 'index.html';
if (!file_exists($index)) {
if ( ! file_exists($index)) {
$fp = @fopen($index, 'w');
@fputs($fp, ''); // phpcs:ignore
@fclose($fp); // phpcs:ignore
} // end if;
} // end if;
}
}
return $folder_path . implode('/', $path);
} // end wu_maybe_create_folder;
}
/**
* Gets the URL for the folders created with maybe_create_folder().
@ -106,5 +97,4 @@ function wu_get_folder_url($folder) {
$folder_url = trailingslashit($uploads['baseurl'] . '/' . $folder);
return set_url_scheme($folder_url);
} // end wu_get_folder_url;
}

View File

@ -25,15 +25,12 @@ use WP_Ultimo\Managers\Gateway_Manager;
*/
function wu_register_gateway($id, $title, $desc, $class_name, $hidden = false) {
if (!did_action('wu_register_gateways')) {
if ( ! did_action('wu_register_gateways')) {
_doing_it_wrong(__FUNCTION__, __('You should not register new payment gateways before the wu_register_gateways hook.', 'wp-ultimo'), '2.0.0');
} // end if;
}
return Gateway_Manager::get_instance()->register_gateway($id, $title, $desc, $class_name, $hidden);
} // end wu_register_gateway;
}
/**
* Returns the currently registered gateways.
@ -45,8 +42,7 @@ function wu_register_gateway($id, $title, $desc, $class_name, $hidden = false) {
function wu_get_gateways() {
return Gateway_Manager::get_instance()->get_registered_gateways();
} // end wu_get_gateways;
}
/**
* Returns the currently registered and active gateways.
@ -61,18 +57,13 @@ function wu_get_active_gateways() {
$active_gateways = (array) wu_get_setting('active_gateways', array());
foreach ($active_gateways as $active_gateway) {
if (Gateway_Manager::get_instance()->is_gateway_registered($active_gateway)) {
$gateways[$active_gateway] = Gateway_Manager::get_instance()->get_gateway($active_gateway);
} // end if;
} // end foreach;
$gateways[ $active_gateway ] = Gateway_Manager::get_instance()->get_gateway($active_gateway);
}
}
return apply_filters('wu_get_active_gateways', $gateways);
} // end wu_get_active_gateways;
}
/**
* Returns a gateway class if it exists.
@ -87,17 +78,14 @@ function wu_get_gateway($id, $subscription = null) {
$gateway = Gateway_Manager::get_instance()->get_gateway($id);
if (!$gateway) {
if ( ! $gateway) {
return false;
} // end if;
}
$gateway_class = new $gateway['class_name']();
return $gateway_class;
} // end wu_get_gateway;
}
/**
* Returns the list of available gateways as key => name.
@ -110,22 +98,17 @@ function wu_get_gateway_as_options() {
$options = array();
foreach (wu_get_gateways() as $gateway_slug => $gateway) {
$instance = class_exists($gateway['class_name']) ? new $gateway['class_name']() : false;
if ($instance === false || $gateway['hidden']) {
continue;
}
} // end if;
$options[$gateway_slug] = $gateway['title'];
} // end foreach;
$options[ $gateway_slug ] = $gateway['title'];
}
return $options;
} // end wu_get_gateway_as_options;
}
/**
* Get the active gateways.
@ -138,21 +121,16 @@ function wu_get_active_gateway_as_options() {
$options = array();
foreach (wu_get_active_gateways() as $gateway_slug => $gateway) {
$instance = class_exists($gateway['class_name']) ? new $gateway['class_name']() : false;
if ($instance === false || $gateway['hidden']) {
continue;
} // end if;
}
$title = $instance->get_public_title();
$options[$gateway_slug] = apply_filters("wu_gateway_{$gateway_slug}_as_option_title", $title, $gateway);
} // end foreach;
$options[ $gateway_slug ] = apply_filters("wu_gateway_{$gateway_slug}_as_option_title", $title, $gateway);
}
return $options;
} // end wu_get_active_gateway_as_options;
}

View File

@ -21,7 +21,6 @@ function wu_generate_csv($file_name, $data = array()) {
$fp = fopen('php://output', 'w');
if ($fp && $data) {
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename="' . $file_name . '.csv"');
@ -31,19 +30,11 @@ function wu_generate_csv($file_name, $data = array()) {
header('Expires: 0');
foreach ($data as $data_line) {
if (is_array($data_line)) {
fputcsv($fp, array_values($data_line));
} elseif (is_object($data_line)) {
fputcsv($fp, array_values(get_object_vars($data_line)));
} // end if;
} // end foreach;
} // end if;
} // end wu_generate_csv;
}
}
}
}

View File

@ -20,5 +20,4 @@ function wu_get_ip() {
$geolocation = \WP_Ultimo\Geolocation::geolocate_ip('', true);
return apply_filters('wu_get_ip', $geolocation['ip']);
} // end wu_get_ip;
}

View File

@ -9,8 +9,8 @@
// Exit if accessed directly
defined('ABSPATH') || exit;
use \WP_Ultimo\Exception\Runtime_Exception;
use \Psr\Log\LogLevel;
use WP_Ultimo\Exception\Runtime_Exception;
use Psr\Log\LogLevel;
/**
* Returns the WP Multisite WaaS version.
@ -21,8 +21,7 @@ use \Psr\Log\LogLevel;
function wu_get_version() {
return class_exists(\WP_Ultimo::class) ? \WP_Ultimo::VERSION : '';
} // end wu_get_version;
}
/**
* Check the debug status.
@ -33,8 +32,7 @@ function wu_get_version() {
function wu_is_debug() {
return defined('WP_ULTIMO_DEBUG') && WP_ULTIMO_DEBUG;
} // end wu_is_debug;
}
/**
* Checks if WP Multisite WaaS is being loaded as a must-use plugin.
@ -45,8 +43,7 @@ function wu_is_debug() {
function wu_is_must_use() {
return defined('WP_ULTIMO_IS_MUST_USE') && WP_ULTIMO_IS_MUST_USE;
} // end wu_is_must_use;
}
/**
* Checks if an array key value is set and returns it.
@ -68,15 +65,12 @@ function wu_is_must_use() {
*/
function wu_get_isset($array, $key, $default = false) {
if (!is_array($array)) {
if ( ! is_array($array)) {
$array = (array) $array;
}
} // end if;
return isset($array[$key]) ? $array[$key] : $default;
} // end wu_get_isset;
return isset($array[ $key ]) ? $array[ $key ] : $default;
}
/**
* Returns the main site id for the network.
@ -91,8 +85,7 @@ function wu_get_main_site_id() {
global $current_site;
return $current_site->blog_id;
} // end wu_get_main_site_id;
}
/**
* This function return 'slugfied' options terms to be used as options ids.
@ -104,8 +97,7 @@ function wu_get_main_site_id() {
function wu_slugify($term) {
return "wp-ultimo_$term";
} // end wu_slugify;
}
/**
* Returns the full path to the plugin folder.
*
@ -115,8 +107,7 @@ function wu_slugify($term) {
function wu_path($dir): string {
return WP_ULTIMO_PLUGIN_DIR . $dir; // @phpstan-ignore-line
} // end wu_path;
}
/**
* Returns the URL to the plugin folder.
@ -128,8 +119,7 @@ function wu_path($dir): string {
function wu_url($dir) {
return apply_filters('wp_ultimo_url', WP_ULTIMO_PLUGIN_URL . $dir); // @phpstan-ignore-line
} // end wu_url;
}
/**
* Shorthand to retrieving variables from $_GET, $_POST and $_REQUEST;
@ -142,11 +132,10 @@ function wu_url($dir) {
*/
function wu_request($key, $default = false) {
$value = isset($_REQUEST[$key]) ? stripslashes_deep($_REQUEST[$key]) : $default;
$value = isset($_REQUEST[ $key ]) ? stripslashes_deep($_REQUEST[ $key ]) : $default;
return apply_filters('wu_request', $value, $key, $default);
} // end wu_request;
}
/**
* Throws an exception if a given hook was not yet run.
@ -159,15 +148,12 @@ function wu_request($key, $default = false) {
*/
function _wu_require_hook($hook = 'ms_loaded') { // phpcs:ignore
if (!did_action($hook)) {
if ( ! did_action($hook)) {
$message = "This function can not yet be run as it relies on processing that happens on hook {$hook}.";
throw new Runtime_Exception($message);
} // end if;
} // end _wu_require_hook;
}
}
/**
* Checks if reflection is available.
@ -183,14 +169,11 @@ function wu_are_code_comments_available() {
static $res;
if ($res === null) {
$res = (bool) (new \ReflectionFunction(__FUNCTION__))->getDocComment();
} // end if;
}
return $res;
} // end wu_are_code_comments_available;
}
/**
* Join string into a single path string.
@ -202,18 +185,15 @@ function wu_are_code_comments_available() {
function wu_path_join(...$parts): string {
if (sizeof($parts) === 0) {
return '';
} // end if;
}
$prefix = ($parts[0] === DIRECTORY_SEPARATOR) ? DIRECTORY_SEPARATOR : '';
$processed = array_filter(array_map(fn($part) => rtrim((string) $part, DIRECTORY_SEPARATOR), $parts), fn($part) => !empty($part));
$processed = array_filter(array_map(fn($part) => rtrim((string) $part, DIRECTORY_SEPARATOR), $parts), fn($part) => ! empty($part));
return $prefix . implode(DIRECTORY_SEPARATOR, $processed);
} // end wu_path_join;
}
/**
@ -229,8 +209,7 @@ function wu_path_join(...$parts): string {
function wu_log_add($handle, $message, $log_level = LogLevel::INFO) {
\WP_Ultimo\Logger::add($handle, $message, $log_level);
} // end wu_log_add;
}
/**
* Clear entries from chosen file.
@ -243,8 +222,7 @@ function wu_log_add($handle, $message, $log_level = LogLevel::INFO) {
function wu_log_clear($handle) {
\WP_Ultimo\Logger::clear($handle);
} // end wu_log_clear;
}
/**
* Maybe log errors to the file.
@ -257,12 +235,9 @@ function wu_log_clear($handle) {
function wu_maybe_log_error($e) {
if (defined('WP_DEBUG') && WP_DEBUG) {
error_log($e);
} // end if;
} // end wu_maybe_log_error;
}
}
/**
* Get the function caller.
@ -276,11 +251,10 @@ function wu_get_function_caller($depth = 1) {
$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, $depth + 1);
$caller = isset($backtrace[$depth]['function']) ? $backtrace[$depth]['function'] : null;
$caller = isset($backtrace[ $depth ]['function']) ? $backtrace[ $depth ]['function'] : null;
return $caller;
} // end wu_get_function_caller;
}
/**
* Checks if a particular plugin is skipped in a CLI context.
*
@ -290,25 +264,20 @@ function wu_get_function_caller($depth = 1) {
*/
function wu_cli_is_plugin_skipped($plugin = null): bool {
if (!class_exists(\WP_CLI::class)) {
if ( ! class_exists(\WP_CLI::class)) {
return false;
} // end if;
}
$skipped_plugins = \WP_CLI::get_config('skip-plugins');
if (is_bool($skipped_plugins)) {
return true;
} // end if;
}
$skipped_plugins = array_map(fn($plugin_slug) => trim((string) $plugin_slug), explode(',', (string) $skipped_plugins));
return in_array($plugin, $skipped_plugins, true);
} // end wu_cli_is_plugin_skipped;
}
/**
* Capture errors and exceptions thrown inside the callback to prevent breakage.
@ -324,13 +293,9 @@ function wu_cli_is_plugin_skipped($plugin = null): bool {
function wu_ignore_errors($fn, $log = false) {
try {
call_user_func($fn);
} catch (\Throwable $exception) {
// Ignore it or log it.
} // end try;
} // end wu_ignore_errors;
}
}

View File

@ -22,8 +22,7 @@ function wu_get_input($raw = false) {
$body = @file_get_contents('php://input'); // phpcs:ignore
return $raw ? $body : json_decode($body);
} // end wu_get_input;
}
/**
* Prevents the current page from being cached.
@ -33,8 +32,7 @@ function wu_get_input($raw = false) {
*/
function wu_no_cache() {
if (!headers_sent()) {
if ( ! headers_sent()) {
nocache_headers();
header('Pragma: no-cache');
@ -44,12 +42,10 @@ function wu_no_cache() {
* easily spot when no-caching is out fault!
*/
wu_x_header('X-Ultimo-Cache: prevent-caching');
} // end if;
}
do_action('wu_no_cache');
} // end wu_no_cache;
}
/**
* Maybe sends a WP Multisite WaaS X Header.
@ -66,9 +62,6 @@ function wu_no_cache() {
function wu_x_header($header) {
if (apply_filters('wu_should_send_x_headers', defined('WP_DEBUG') && WP_DEBUG)) {
!headers_sent() && header($header);
} // end if;
} // end wu_x_header;
! headers_sent() && header($header);
}
}

View File

@ -19,5 +19,4 @@ defined('ABSPATH') || exit;
function wu_get_invoice_template() {
return false;
} // end wu_get_invoice_template;
}

View File

@ -18,7 +18,7 @@ function WU_Signup() {
return \WP_Ultimo\Checkout\Legacy_Checkout::get_instance();
} // end WU_Signup;
}
/**
*
@ -31,22 +31,22 @@ if (!function_exists('validate_blog_form')) {
$user = '';
if ( is_user_logged_in() ) {
$user = wp_get_current_user();
} // end if;
}
return wpmu_validate_blog_signup($_POST['blogname'], $_POST['blog_title'], $user);
} // end validate_blog_form;
}
} // end if;
}
if (!function_exists('validate_user_form')) {
function validate_user_form() {
return wpmu_validate_user_signup($_POST['user_name'], $_POST['user_email']);
} // end validate_user_form;
}
} // end if;
}
/**
* Builds HTML attributes from a PHP array
@ -62,15 +62,15 @@ function wu_create_html_attributes_from_array($attributes = array()) {
if (is_bool($value)) {
if ($value) {
$output .= $name . ' ';
} // end if;
}
} else {
$output .= sprintf('%s="%s"', $name, $value);
} // end if;
} // end foreach;
}
}
return $output;
} // end wu_create_html_attributes_from_array;
}
/**
* Display one single option
@ -85,7 +85,7 @@ function wu_print_signup_field_option($option_value, $option_label, $field = arr
<option <?php selected(isset($field['default']) && $field['default'] == $option_value); ?> value="<?php echo $option_value; ?>"><?php echo $option_label; ?></option>
<?php
} // end wu_print_signup_field_option;
}
/**
* Displays the option tags of an select field
@ -106,7 +106,7 @@ function wu_print_signup_field_options($options, $field = array()) {
wu_print_signup_field_option($option_value, $option_label, $field);
} // end foreach;
}
echo '</optgroup>';
@ -114,11 +114,11 @@ function wu_print_signup_field_options($options, $field = array()) {
wu_print_signup_field_option($option_value, $option_label, $field);
} // end if;
}
} // end foreach;
}
} // end wu_print_signup_field_options;
}
/**
* Print sing-up fields
@ -172,7 +172,7 @@ function wu_print_signup_field($field_slug, $field, $results) {
return true;
} // end if;
}
value = Array.isArray(value) ? value : [value];
@ -180,7 +180,7 @@ function wu_print_signup_field($field_slug, $field, $results) {
conditions_met++;
} // end if;
}
});
@ -194,7 +194,7 @@ function wu_print_signup_field($field_slug, $field, $results) {
} // end
} // end display_field;
}
display_field(target_field, requires, 0);
@ -209,7 +209,7 @@ function wu_print_signup_field($field_slug, $field, $results) {
<?php
} // end if;
}
$wrapper_attributes = '';
$attributes = '';
@ -221,13 +221,13 @@ function wu_print_signup_field($field_slug, $field, $results) {
$wrapper_attributes = wu_create_html_attributes_from_array($field['wrapper_attributes']);
} // end if;
}
if (isset($field['attributes']) && $field['attributes']) {
$attributes = wu_create_html_attributes_from_array($field['attributes']);
} // end if;
}
/**
* Switch type for display
@ -252,7 +252,7 @@ function wu_print_signup_field($field_slug, $field, $results) {
<?php
if ($error_message = $results['errors']->get_error_message($field_slug)) {
echo '<p class="error">' . $error_message . '</p>';
} // end if;
}
?>
@ -303,7 +303,7 @@ function wu_print_signup_field($field_slug, $field, $results) {
<?php
if ($error_message = $results['errors']->get_error_message($field_slug)) {
echo '<p class="error">' . $error_message . '</p>';
} // end if;
}
?>
@ -367,7 +367,7 @@ function wu_print_signup_field($field_slug, $field, $results) {
<?php
if ($error_message = $results['errors']->get_error_message($field_slug)) {
echo '<p class="error">' . $error_message . '</p>';
} // end if;
}
?>
@ -398,7 +398,7 @@ function wu_print_signup_field($field_slug, $field, $results) {
<?php
if ($error_message = $results['errors']->get_error_message($field_slug)) {
echo '<p class="error">' . $error_message . '</p>';
} // end if;
}
?>
@ -409,9 +409,9 @@ function wu_print_signup_field($field_slug, $field, $results) {
<?php
break;
} // end switch;
}
} // end wu_print_signup_field;
}
/**
* Alias function to allow creation of users for WP Multisite WaaS.
*
@ -428,7 +428,7 @@ function wu_create_user(array $user_data, array $plan_data, array $user_meta = a
return WU_Signup()->create_user($user_data, $plan_data, $user_meta);
} // end wu_create_user;
}
/**
* Alias function to allow creation of sites for WP Multisite WaaS.
@ -446,7 +446,7 @@ function wu_create_site_legacy($user_id, array $site_data, $template_id = false,
return WU_Signup()->create_site($user_id, $site_data, $template_id, $site_meta);
} // end wu_create_site_legacy;
}
/**
* Alias function that adds a new Step to the sign-up flow
*
@ -459,7 +459,7 @@ function wu_add_signup_step($id, $order, array $step) {
return WU_Signup()->add_signup_step($id, $order, $step);
} // end wu_add_signup_step;
}
/**
* Alias function that adds a new field to a step the sign-up flow
@ -475,4 +475,4 @@ function wu_add_signup_field($step, $id, $order, $field) {
return WU_Signup()->add_signup_field($step, $id, $order, $field);
} // end wu_add_signup_field;
}

View File

@ -54,33 +54,25 @@ defined('ABSPATH') || exit;
*/
function wu_has_product($product_slug, $blocking = false, $site_id = '') {
if (!is_array($product_slug)) {
if ( ! is_array($product_slug)) {
$product_slug = array($product_slug);
} // end if;
}
if (empty($site_id)) {
$site_id = get_current_blog_id();
} // end if;
}
$site = wu_get_site($site_id);
if (empty($site)) {
return new \WP_Error('site-not-found', __('Invalid site ID', 'wp-ultimo'));
} // end if;
}
$membership = $site->get_membership();
if (empty($membership)) {
return true;
} // end if;
}
$applicable_products_slugs = $membership->get_applicable_product_slugs();
@ -89,14 +81,11 @@ function wu_has_product($product_slug, $blocking = false, $site_id = '') {
$active_status = true;
if ($blocking) {
$active_status = $membership->is_active();
} // end if;
}
return $contains_product && $active_status;
} // end wu_has_product;
}
/**
* Checks if the membership associated with a site is active.
@ -109,30 +98,23 @@ function wu_has_product($product_slug, $blocking = false, $site_id = '') {
function wu_is_membership_active($site_id = '') {
if (empty($site_id)) {
$site_id = get_current_blog_id();
} // end if;
}
$site = wu_get_site($site_id);
if (empty($site)) {
return new \WP_Error('site-not-found', __('Invalid site ID', 'wp-ultimo'));
} // end if;
}
$membership = $site->get_membership();
if (empty($membership)) {
return true;
} // end if;
}
return $membership->is_active();
} // end wu_is_membership_active;
}
/**
* Register a new Limitation module.
@ -145,17 +127,18 @@ function wu_is_membership_active($site_id = '') {
*/
function wu_register_limit_module($id, $class_name) {
add_filter('wu_limit_classes', function($classes) use ($id, $class_name) {
add_filter(
'wu_limit_classes',
function ($classes) use ($id, $class_name) {
$id = sanitize_title($id);
$id = sanitize_title($id);
$classes[$id] = $class_name;
$classes[ $id ] = $class_name;
return $classes;
});
} // end wu_register_limit_module;
return $classes;
}
);
}
/**
* Generate the modal link to search for an upgrade path.
@ -167,18 +150,19 @@ function wu_register_limit_module($id, $class_name) {
*/
function wu_generate_upgrade_to_unlock_url($args) {
$args = wp_parse_args($args, array(
'module' => false,
'type' => false,
));
$args = wp_parse_args(
$args,
array(
'module' => false,
'type' => false,
)
);
$membership = wu_get_current_site()->get_membership();
if (!$membership) {
if ( ! $membership) {
return '';
} // end if;
}
$upgrade_url = wu_get_membership_update_url($membership);
@ -191,8 +175,7 @@ function wu_generate_upgrade_to_unlock_url($args) {
* @param array $args The module and type of limit that needs upgrading.
*/
return apply_filters('wu_upgrade_to_unlock_url', $url, $args);
} // end wu_generate_upgrade_to_unlock_url;
}
/**
* Generates a Unlock to Upgrade button for the upgrade modal.
@ -205,16 +188,21 @@ function wu_generate_upgrade_to_unlock_url($args) {
*/
function wu_generate_upgrade_to_unlock_button($title, $args) {
$args = wp_parse_args($args, array(
'module' => false,
'type' => false,
'classes' => '',
));
$args = wp_parse_args(
$args,
array(
'module' => false,
'type' => false,
'classes' => '',
)
);
$url = wu_generate_upgrade_to_unlock_url(array(
'module' => $args['module'],
'type' => $args['type'],
));
$url = wu_generate_upgrade_to_unlock_url(
array(
'module' => $args['module'],
'type' => $args['type'],
)
);
$element = sprintf(
'<a href="%s" title="%s" class="%s">%s</a>',
@ -225,8 +213,7 @@ function wu_generate_upgrade_to_unlock_button($title, $args) {
);
return $element;
} // end wu_generate_upgrade_to_unlock_button;
}
/**
* Activate a plugin(s) via Job Queue.
@ -241,15 +228,17 @@ function wu_generate_upgrade_to_unlock_button($title, $args) {
*/
function wu_async_activate_plugins($site_id, $plugins, $network_wide = false, $silent = true) {
wu_enqueue_async_action('wu_async_handle_plugins', array(
'action' => 'activate',
'site_id' => $site_id,
'plugins' => $plugins,
'network_wide' => $network_wide,
'silent' => $silent,
));
} // end wu_async_activate_plugins;
wu_enqueue_async_action(
'wu_async_handle_plugins',
array(
'action' => 'activate',
'site_id' => $site_id,
'plugins' => $plugins,
'network_wide' => $network_wide,
'silent' => $silent,
)
);
}
/**
* Deactivates a plugin(s) via Job Queue.
@ -264,15 +253,17 @@ function wu_async_activate_plugins($site_id, $plugins, $network_wide = false, $s
*/
function wu_async_deactivate_plugins($site_id, $plugins, $network_wide = false, $silent = true) {
wu_enqueue_async_action('wu_async_handle_plugins', array(
'action' => 'deactivate',
'site_id' => $site_id,
'plugins' => $plugins,
'network_wide' => $network_wide,
'silent' => $silent,
));
} // end wu_async_deactivate_plugins;
wu_enqueue_async_action(
'wu_async_handle_plugins',
array(
'action' => 'deactivate',
'site_id' => $site_id,
'plugins' => $plugins,
'network_wide' => $network_wide,
'silent' => $silent,
)
);
}
/**
* Switch themes via Job Queue.
@ -285,9 +276,11 @@ function wu_async_deactivate_plugins($site_id, $plugins, $network_wide = false,
*/
function wu_async_switch_theme($site_id, $theme_stylesheet) {
wu_enqueue_async_action('wu_async_switch_theme', array(
'site_id' => $site_id,
'theme_stylesheet' => $theme_stylesheet,
));
} // end wu_async_switch_theme;
wu_enqueue_async_action(
'wu_async_switch_theme',
array(
'site_id' => $site_id,
'theme_stylesheet' => $theme_stylesheet,
)
);
}

View File

@ -22,8 +22,7 @@ function wu_convert_to_state($state_array = array()) {
$object = (object) $state_array; // Force object to prevent issues with Vue.
return json_encode($object);
} // end wu_convert_to_state;
}
/**
* Clean up p tags around block elements.
@ -35,23 +34,26 @@ function wu_convert_to_state($state_array = array()) {
*/
function wu_remove_empty_p($content): ?string {
$content = preg_replace(array(
'#<p>\s*<(div|aside|section|article|header|footer)#',
'#</(div|aside|section|article|header|footer)>\s*</p>#',
'#</(div|aside|section|article|header|footer)>\s*<br ?/?>#',
'#<(div|aside|section|article|header|footer)(.*?)>\s*</p>#',
'#<p>\s*</(div|aside|section|article|header|footer)#',
), array(
'<$1',
'</$1>',
'</$1>',
'<$1$2>',
'</$1',
), $content);
$content = preg_replace(
array(
'#<p>\s*<(div|aside|section|article|header|footer)#',
'#</(div|aside|section|article|header|footer)>\s*</p>#',
'#</(div|aside|section|article|header|footer)>\s*<br ?/?>#',
'#<(div|aside|section|article|header|footer)(.*?)>\s*</p>#',
'#<p>\s*</(div|aside|section|article|header|footer)#',
),
array(
'<$1',
'</$1>',
'</$1>',
'<$1$2>',
'</$1',
),
$content
);
return preg_replace('#<p>(\s|&nbsp;)*+(<br\s*/*>)*(\s|&nbsp;)*</p>#i', '', $content);
} // end wu_remove_empty_p;
}
/**
* Generates a string containing html attributes to be used inside html tags.
*
@ -76,8 +78,7 @@ function wu_array_to_html_attrs($attributes = array()): string {
$attributes = array_map(fn($key, $value) => $key . '="' . htmlspecialchars((string) $value) . '"', array_keys($attributes), $attributes);
return implode(' ', $attributes);
} // end wu_array_to_html_attrs;
}
/**
* Adds a tooltip icon.
@ -91,28 +92,21 @@ function wu_array_to_html_attrs($attributes = array()): string {
function wu_tooltip($tooltip, $icon = 'dashicons-editor-help') {
if (empty($tooltip)) {
return '';
} // end if;
}
$markup = sprintf('<span class="wu-styling" role="tooltip" aria-label="%s">', esc_attr($tooltip));
if (!is_admin()) {
if ( ! is_admin()) {
$markup .= '<svg style="width:11px" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" id="Layer_1" x="0px" y="0px" viewBox="0 0 122.88 122.88" xml:space="preserve"><g><path class="st0" d="M122.88,61.44C122.88,27.51,95.37,0,61.44,0C27.51,0,0,27.51,0,61.44c0,33.93,27.51,61.44,61.44,61.44 C95.37,122.88,122.88,95.37,122.88,61.44L122.88,61.44z M68.79,74.58H51.3v-1.75c0-2.97,0.32-5.39,1-7.25 c0.68-1.87,1.68-3.55,3.01-5.1c1.34-1.54,4.35-4.23,9.01-8.11c2.48-2.03,3.73-3.88,3.73-5.56c0-1.71-0.51-3.01-1.5-3.95 c-1-0.93-2.51-1.4-4.54-1.4c-2.19,0-3.98,0.73-5.4,2.16c-1.43,1.44-2.34,3.97-2.74,7.56l-17.88-2.22c0.61-6.57,3-11.86,7.15-15.85 c4.17-4.02,10.55-6.01,19.14-6.01c6.7,0,12.1,1.4,16.21,4.19c5.6,3.78,8.38,8.82,8.38,15.1c0,2.62-0.73,5.14-2.16,7.56 c-1.44,2.44-4.39,5.39-8.85,8.88c-3.09,2.48-5.05,4.44-5.86,5.93C69.19,70.24,68.79,72.19,68.79,74.58L68.79,74.58z M50.68,79.25 h18.76v16.53H50.68V79.25L50.68,79.25z"></path></g></svg>';
} else {
$markup .= sprintf('<span class="dashicons wu-text-xs wu-w-auto wu-h-auto wu-align-text-bottom %s"></span>', esc_attr($icon));
} // end if;
}
$markup .= '</span>';
return $markup;
} // end wu_tooltip;
}
/**
* Adds a tooltip to a HTML element. Needs to be echo'ed.
*
@ -123,8 +117,7 @@ function wu_tooltip($tooltip, $icon = 'dashicons-editor-help') {
function wu_tooltip_text($tooltip): string {
return sprintf('role="tooltip" aria-label="%s"', esc_attr($tooltip));
} // end wu_tooltip_text;
}
/**
* Adds a preview tag that displays the image passed on hover.
*
@ -136,14 +129,11 @@ function wu_tooltip_text($tooltip): string {
function wu_preview_image($image_url, $label = false): string {
if (empty($label)) {
$label = __('Preview', 'wp-ultimo');
} // end if;
}
return sprintf(' <span class="wu-image-preview wu-text-gray-600 wu-bg-gray-200 wu-p-1 wu-px-2 wu-ml-1 wu-inline-block wu-text-2xs wu-uppercase wu-font-bold wu-rounded wu-cursor-pointer wu-border-gray-300 wu-border wu-border-solid" data-image="%s">%s %s</span>', $image_url, "<span class='dashicons-wu-image wu-align-middle wu-mr-1'></span>", $label);
} // end wu_preview_image;
}
/**
* Returns the list of available icons. To add more icons you need use the filter
@ -496,7 +486,7 @@ function wu_get_icons_list() {
'dashicons-wu-voicemail',
'dashicons-wu-wallet',
'dashicons-wu-warning',
'dashicons-wu-wp-ultimo'
'dashicons-wu-wp-ultimo',
);
$all_icons['Dashicons'] = array(
@ -757,8 +747,7 @@ function wu_get_icons_list() {
);
return apply_filters('wu_icons_list', $all_icons);
} // end wu_get_icons_list;
}
/**
* Checks if the current theme is a block theme.
@ -769,11 +758,8 @@ function wu_get_icons_list() {
function wu_is_block_theme() {
if (function_exists('wp_is_block_theme')) {
return wp_is_block_theme();
} // end if;
}
return false;
} // end wu_is_block_theme;
}

View File

@ -9,10 +9,10 @@
// Exit if accessed directly
defined('ABSPATH') || exit;
use \WP_Ultimo\Models\Membership;
use \WP_Ultimo\Models\Payment;
use \WP_Ultimo\Database\Payments\Payment_Status;
use \WP_Ultimo\Checkout\Cart;
use WP_Ultimo\Models\Membership;
use WP_Ultimo\Models\Payment;
use WP_Ultimo\Database\Payments\Payment_Status;
use WP_Ultimo\Checkout\Cart;
/**
* Returns a membership.
@ -25,8 +25,7 @@ use \WP_Ultimo\Checkout\Cart;
function wu_get_membership($membership_id) {
return Membership::get_by_id($membership_id);
} // end wu_get_membership;
}
/**
* Returns a single membership defined by a particular column and value.
*
@ -39,8 +38,7 @@ function wu_get_membership($membership_id) {
function wu_get_membership_by($column, $value) {
return Membership::get_by($column, $value);
} // end wu_get_membership_by;
}
/**
* Gets a membership based on the hash.
*
@ -52,8 +50,7 @@ function wu_get_membership_by($column, $value) {
function wu_get_membership_by_hash($hash) {
return Membership::get_by_hash($hash);
} // end wu_get_membership_by_hash;
}
/**
* Queries memberships.
@ -65,26 +62,23 @@ function wu_get_membership_by_hash($hash) {
*/
function wu_get_memberships($query = array()) {
if (!empty($query['search'])) {
$customer_ids = wu_get_customers(array(
'search' => $query['search'],
'fields' => 'ids',
));
if (!empty($customer_ids)) {
if ( ! empty($query['search'])) {
$customer_ids = wu_get_customers(
array(
'search' => $query['search'],
'fields' => 'ids',
)
);
if ( ! empty($customer_ids)) {
$query['customer_id__in'] = $customer_ids;
unset($query['search']);
} // end if;
} // end if;
}
}
return Membership::query($query);
} // end wu_get_memberships;
}
/**
* Creates a new membership.
*
@ -98,36 +92,39 @@ function wu_create_membership($membership_data) {
* Why do we use shortcode atts here?
* Shortcode atts clean the array from not-allowed keys, so we don't need to worry much.
*/
$membership_data = shortcode_atts(array(
'customer_id' => false,
'user_id' => false,
'migrated_from_id' => 0,
'plan_id' => false,
'addon_products' => false,
'currency' => false,
'initial_amount' => false,
'recurring' => false,
'duration' => 1,
'duration_unit' => 'month',
'amount' => false,
'auto_renew' => false,
'times_billed' => 0,
'billing_cycles' => 0,
'gateway_customer_id' => false,
'gateway_subscription_id' => false,
'gateway' => '',
'signup_method' => '',
'upgraded_from' => false,
'disabled' => false,
'status' => 'pending',
'date_created' => wu_get_current_time('mysql', true),
'date_activate' => null,
'date_trial_end' => null,
'date_renewed' => null,
'date_modified' => wu_get_current_time('mysql', true),
'date_expiration' => wu_get_current_time('mysql', true),
'skip_validation' => false,
), $membership_data);
$membership_data = shortcode_atts(
array(
'customer_id' => false,
'user_id' => false,
'migrated_from_id' => 0,
'plan_id' => false,
'addon_products' => false,
'currency' => false,
'initial_amount' => false,
'recurring' => false,
'duration' => 1,
'duration_unit' => 'month',
'amount' => false,
'auto_renew' => false,
'times_billed' => 0,
'billing_cycles' => 0,
'gateway_customer_id' => false,
'gateway_subscription_id' => false,
'gateway' => '',
'signup_method' => '',
'upgraded_from' => false,
'disabled' => false,
'status' => 'pending',
'date_created' => wu_get_current_time('mysql', true),
'date_activate' => null,
'date_trial_end' => null,
'date_renewed' => null,
'date_modified' => wu_get_current_time('mysql', true),
'date_expiration' => wu_get_current_time('mysql', true),
'skip_validation' => false,
),
$membership_data
);
$membership_data['migrated_from_id'] = is_numeric($membership_data['migrated_from_id']) ? $membership_data['migrated_from_id'] : 0;
@ -136,8 +133,7 @@ function wu_create_membership($membership_data) {
$saved = $membership->save();
return is_wp_error($saved) ? $saved : $membership;
} // end wu_create_membership;
}
/**
* Get all customers with a specific membership using the product_id as reference.
@ -168,8 +164,7 @@ function wu_get_membership_customers($product_id) {
is_multisite() && restore_current_blog();
return $results;
} // end wu_get_membership_customers;
}
/**
* Returns a membership based on the customer gateway ID.
*
@ -200,17 +195,14 @@ function wu_get_membership_by_customer_gateway_id($customer_gateway_id, $allowed
'order' => 'DESC',
);
if (!empty($amount)) {
if ( ! empty($amount)) {
$search_data['initial_amount'] = $amount;
} // end if;
}
$memberships = wu_get_memberships($search_data);
return !empty($memberships) ? current($memberships) : false;
} // end wu_get_membership_by_customer_gateway_id;
return ! empty($memberships) ? current($memberships) : false;
}
/**
* Returns the price for a product in a specific membership.
@ -229,56 +221,52 @@ function wu_get_membership_product_price($membership, $product_id, $quantity, $o
$address = $membership->get_billing_address();
// Create a Cart with this product
$cart = new Cart(array(
'duration' => $membership->get_duration(),
'duration_unit' => $membership->get_duration_unit(),
'country' => $address->billing_country,
'state' => $address->billing_state,
'city' => $address->billing_city,
));
$cart = new Cart(
array(
'duration' => $membership->get_duration(),
'duration_unit' => $membership->get_duration_unit(),
'country' => $address->billing_country,
'state' => $address->billing_state,
'city' => $address->billing_city,
)
);
$discount_code = $membership->get_discount_code();
if ($discount_code) {
$cart->add_discount_code($discount_code);
} // end if;
}
$added = $cart->add_product($product_id, $quantity);
if (!$added) {
if ( ! $added) {
return $cart->errors;
}
} // end if;
$payment_data = array_merge($cart->to_payment_data(), array(
'customer_id' => $membership->get_customer_id(),
'membership_id' => $membership->get_id(),
'gateway' => $membership->get_gateway(),
));
$payment_data = array_merge(
$cart->to_payment_data(),
array(
'customer_id' => $membership->get_customer_id(),
'membership_id' => $membership->get_id(),
'gateway' => $membership->get_gateway(),
)
);
// create a temporary payment to see the price.
$temp_payment = wu_create_payment($payment_data, false);
if (is_wp_error($temp_payment)) {
return $temp_payment;
} // end if;
}
if ($only_recurring) {
$temp_payment->remove_non_recurring_items();
} // end if;
}
$temp_payment->recalculate_totals();
return $temp_payment->get_total();
} // end wu_get_membership_product_price;
}
/**
* Creates a new payment for a membership.
*
@ -298,63 +286,53 @@ function wu_membership_create_new_payment($membership, $should_cancel_pending_pa
* pending payment, do that.
*/
if ($should_cancel_pending_payments) {
$pending_payment = $membership->get_last_pending_payment();
/*
* Change pending payment to cancelled.
*/
if ($pending_payment) {
$pending_payment->set_status(Payment_Status::CANCELLED);
$pending_payment->save();
} // end if;
} // end if;
}
}
$cart = wu_get_membership_new_cart($membership);
$payment_data = array_merge($cart->to_payment_data(), array(
'customer_id' => $membership->get_customer_id(),
'membership_id' => $membership->get_id(),
'gateway' => $membership->get_gateway(),
));
$payment_data = array_merge(
$cart->to_payment_data(),
array(
'customer_id' => $membership->get_customer_id(),
'membership_id' => $membership->get_id(),
'gateway' => $membership->get_gateway(),
)
);
// We will save the payment after we recalculate the totals.
$new_payment = wu_create_payment($payment_data, false);
if (is_wp_error($new_payment)) {
return $new_payment;
} // end if;
}
if ($remove_non_recurring) {
$new_payment->remove_non_recurring_items();
} // end if;
}
$new_payment->recalculate_totals();
if (!$save) {
if ( ! $save) {
return $new_payment;
} // end if;
}
$status = $new_payment->save();
if (is_wp_error($status)) {
return $status;
} // end if;
}
return $new_payment;
} // end wu_membership_create_new_payment;
}
/**
* Creates a full cart based on a membership.
@ -368,32 +346,29 @@ function wu_get_membership_new_cart($membership) {
$address = $membership->get_billing_address();
$cart = new Cart(array(
'duration' => $membership->get_duration(),
'duration_unit' => $membership->get_duration_unit(),
'country' => $address->billing_country,
'state' => $address->billing_state,
'city' => $address->billing_city,
));
$cart = new Cart(
array(
'duration' => $membership->get_duration(),
'duration_unit' => $membership->get_duration_unit(),
'country' => $address->billing_country,
'state' => $address->billing_state,
'city' => $address->billing_city,
)
);
$discount_code = $membership->get_discount_code();
if ($discount_code) {
$cart->add_discount_code($discount_code);
} // end if;
}
foreach ($membership->get_all_products() as $key => $product) {
$cart->add_product($product['product']->get_id(), $product['quantity']);
} // end foreach;
}
$difference = $membership->get_amount() - $cart->get_recurring_total();
if (round(abs($difference), wu_currency_decimal_filter()) > 0) {
$type_translate = $difference < 0 ? __('credit', 'wp-ultimo') : __('debit', 'wp-ultimo');
$line_item_params = array(
@ -414,11 +389,9 @@ function wu_get_membership_new_cart($membership) {
$adjustment_line_item = new \WP_Ultimo\Checkout\Line_Item($line_item_params);
$cart->add_line_item($adjustment_line_item);
} // end if;
}
if ($membership->get_initial_amount() !== $cart->get_total()) {
$t = $membership->get_initial_amount();
$y = $cart->get_total();
@ -441,15 +414,13 @@ function wu_get_membership_new_cart($membership) {
$adjustment_line_item = new \WP_Ultimo\Checkout\Line_Item($line_item_params);
$cart->add_line_item($adjustment_line_item);
} // end if;
}
$y = $cart->get_total();
$t = $cart->get_recurring_total();
return $cart;
} // end wu_get_membership_new_cart;
}
/**
* Generate the modal link to search for an upgrade path.
@ -468,36 +439,38 @@ function wu_get_membership_update_url($membership) {
$membership_hash = $membership->get_hash();
if ($url) {
return add_query_arg(
array(
'membership' => $membership_hash,
),
$url
);
}
return add_query_arg(array(
'membership' => $membership_hash,
), $url);
} // end if;
if (!is_main_site()) {
if ( ! is_main_site()) {
return admin_url('admin.php?page=wu-checkout&membership=' . $membership_hash);
} // end if;
}
$sites = $membership->get_sites(false);
if (count($sites) > 0) {
return add_query_arg(array(
'page' => 'wu-checkout',
'membership' => $membership_hash,
), get_admin_url($sites[0]->get_id()));
} // end if;
return add_query_arg(
array(
'page' => 'wu-checkout',
'membership' => $membership_hash,
),
get_admin_url($sites[0]->get_id())
);
}
// In last case we use the default register form
$url = $checkout_pages->get_page_url('register');
return add_query_arg(array(
'membership' => $membership_hash,
'wu_form' => 'wu-checkout',
), $url);
} // end wu_get_membership_update_url;
return add_query_arg(
array(
'membership' => $membership_hash,
'wu_form' => 'wu-checkout',
),
$url
);
}

View File

@ -18,23 +18,23 @@ defined('ABSPATH') || exit;
*/
function wu_mock_site($seed = false) {
$atts = apply_filters('wu_mock_site', array(
'title' => __('Example Site', 'wp-ultimo'),
'description' => __('This is an example of a site description.', 'wp-ultimo'),
'domain' => __('examplesite.dev', 'wp-ultimo'),
'path' => '/',
));
$atts = apply_filters(
'wu_mock_site',
array(
'title' => __('Example Site', 'wp-ultimo'),
'description' => __('This is an example of a site description.', 'wp-ultimo'),
'domain' => __('examplesite.dev', 'wp-ultimo'),
'path' => '/',
)
);
if ($seed) {
$atts['title'] .= " {$seed}";
$atts['domain'] = str_replace('.dev', "{$seed}.dev", (string) $atts['domain']);
} // end if;
}
return new \WP_Ultimo\Models\Site($atts);
} // end wu_mock_site;
}
/**
* Returns a mock membership object.
@ -44,14 +44,17 @@ function wu_mock_site($seed = false) {
*/
function wu_mock_membership() {
return new \WP_Ultimo\Models\Membership(array(
'billing_address' => new \WP_Ultimo\Objects\Billing_Address(array(
'company_name' => 'Company Co.',
'billing_email' => 'company@co.dev',
)),
));
} // end wu_mock_membership;
return new \WP_Ultimo\Models\Membership(
array(
'billing_address' => new \WP_Ultimo\Objects\Billing_Address(
array(
'company_name' => 'Company Co.',
'billing_email' => 'company@co.dev',
)
),
)
);
}
/**
* Returns a mock product object.
@ -61,15 +64,16 @@ function wu_mock_membership() {
*/
function wu_mock_product() {
$product = new \WP_Ultimo\Models\Product(array(
'name' => __('Test Product', 'wp-ultimo'),
));
$product = new \WP_Ultimo\Models\Product(
array(
'name' => __('Test Product', 'wp-ultimo'),
)
);
$product->_mocked = true;
return $product;
} // end wu_mock_product;
}
/**
* Returns a mock customer object.
@ -79,12 +83,16 @@ function wu_mock_product() {
*/
function wu_mock_customer() {
$customer = new \WP_Ultimo\Models\Customer(array(
'billing_address' => new \WP_Ultimo\Objects\Billing_Address(array(
'company_name' => 'Company Co.',
'billing_email' => 'company@co.dev',
)),
));
$customer = new \WP_Ultimo\Models\Customer(
array(
'billing_address' => new \WP_Ultimo\Objects\Billing_Address(
array(
'company_name' => 'Company Co.',
'billing_email' => 'company@co.dev',
)
),
)
);
$customer->_user = (object) array(
'data' => (object) array(
@ -104,8 +112,7 @@ function wu_mock_customer() {
);
return $customer;
} // end wu_mock_customer;
}
/**
* Returns a mock payment object.
@ -117,17 +124,20 @@ function wu_mock_payment() {
$payment = new \WP_Ultimo\Models\Payment();
$line_item = new \WP_Ultimo\Checkout\Line_Item(array(
'product' => wu_mock_product(),
));
$line_item = new \WP_Ultimo\Checkout\Line_Item(
array(
'product' => wu_mock_product(),
)
);
$payment->set_line_items(array(
$line_item,
));
$payment->set_line_items(
array(
$line_item,
)
);
return $payment;
} // end wu_mock_payment;
}
/**
* Returns a mock domain object.
@ -137,15 +147,16 @@ function wu_mock_payment() {
*/
function wu_mock_domain() {
$domain = new \WP_Ultimo\Models\Domain(array(
'blog_id' => 1,
'domain' => 'example.com',
'active' => true,
'primary_domain' => true,
'secure' => true,
'stage' => 'checking-dns',
));
$domain = new \WP_Ultimo\Models\Domain(
array(
'blog_id' => 1,
'domain' => 'example.com',
'active' => true,
'primary_domain' => true,
'secure' => true,
'stage' => 'checking-dns',
)
);
return $domain;
} // end wu_mock_domain;
}

View File

@ -20,14 +20,11 @@ defined('ABSPATH') || exit;
function wu_cast_model_to_array($model) {
if (is_a($model, '\\WP_Ultimo\\Models\\Base_Model')) {
$model = $model->to_array();
} // end if;
}
return $model;
} // end wu_cast_model_to_array;
}
/**
* Converts a list of Model objects to a list of ID => $label_field
@ -43,14 +40,11 @@ function wu_models_to_options($models, $label_field = 'name') {
$options_list = array();
foreach ($models as $model) {
$options_list[$model->get_id()] = call_user_func(array($model, "get_{$label_field}"));
} // end foreach;
$options_list[ $model->get_id() ] = call_user_func(array($model, "get_{$label_field}"));
}
return $options_list;
} // end wu_models_to_options;
}
/**
* Get the schema of a particular model.
@ -65,14 +59,11 @@ function wu_model_get_schema($class_name) {
$schema = array();
if (method_exists($class_name, 'get_schema')) {
$schema = $class_name::get_schema();
} // end if;
}
return $schema;
} // end wu_model_get_schema;
}
/**
* Returns a list of required fields form a model schema.
@ -87,21 +78,14 @@ function wu_model_get_required_fields($class_name) {
$required_fields = array();
if (method_exists($class_name, 'validation_rules')) {
$validation_rules = (new $class_name)->validation_rules();
$validation_rules = (new $class_name())->validation_rules();
foreach ($validation_rules as $field => $validation_rule) {
if (strpos((string) $validation_rule, 'required|') !== false || $validation_rule === 'required') {
$required_fields[] = $field;
} // end if;
} // end foreach;
} // end if;
}
}
}
return $required_fields;
} // end wu_model_get_required_fields;
}

View File

@ -24,8 +24,7 @@ function wu_extract_number($str) {
preg_match_all('/\d+/', $str, $matches);
return isset($matches[0][0]) ? (int) $matches[0][0] : 0;
} // end wu_extract_number;
}
/**
* Converts formatted values back into floats.
@ -39,29 +38,20 @@ function wu_extract_number($str) {
function wu_to_float($num, $decimal_separator = false) {
if (is_float($num) || is_numeric($num)) {
return (float) $num;
} // end if;
}
if (empty($decimal_separator)) {
$decimal_separator = wu_get_setting('decimal_separator', '.');
} // end if;
}
if ($decimal_separator) {
$pattern = '/[^0-9\\' . $decimal_separator . '-]+/';
} else {
$pattern = '/[^0-9-]+/';
} // end if;
}
$val = preg_replace($pattern, '', (string) $num);
return floatval($val);
} // end wu_to_float;
}

View File

@ -22,8 +22,7 @@ function wu_get_option($option_name = 'settings', $default = array()) {
$option_value = get_network_option(null, wu_slugify($option_name), $default);
return apply_filters('wu_get_option', $option_value, $option_name, $default);
} // end wu_get_option;
}
/**
* Save slugfied network option
@ -36,8 +35,7 @@ function wu_get_option($option_name = 'settings', $default = array()) {
function wu_save_option($option_name = 'settings', $value = false) {
return update_network_option(null, wu_slugify($option_name), $value);
} // end wu_save_option;
}
/**
* Delete slugfied network option
@ -49,5 +47,4 @@ function wu_save_option($option_name = 'settings', $value = false) {
function wu_delete_option($option_name) {
return delete_network_option(null, wu_slugify($option_name));
} // end wu_delete_option;
}

View File

@ -17,35 +17,31 @@ defined('ABSPATH') || exit;
*/
function wu_guess_registration_page() {
return wu_switch_blog_and_run(function() {
return wu_switch_blog_and_run(
function () {
$saved_register_page_id = wu_get_setting('default_registration_page', 0);
$saved_register_page_id = wu_get_setting('default_registration_page', 0);
$page = get_post($saved_register_page_id);
$page = get_post($saved_register_page_id);
if ($page) {
if ($page) {
return $page->ID;
}
return $page->ID;
$maybe_register_page = get_page_by_path('register');
if ($maybe_register_page && has_shortcode($maybe_register_page->post_content, 'wu_checkout') && $maybe_register_page->post_status === 'publish') {
wu_save_setting('default_registration_page', $maybe_register_page->ID);
function_exists('flush_rewrite_rules') && flush_rewrite_rules(true);
return $maybe_register_page->ID;
}
return false;
}
$maybe_register_page = get_page_by_path('register');
if ($maybe_register_page && has_shortcode($maybe_register_page->post_content, 'wu_checkout') && $maybe_register_page->post_status === 'publish') {
wu_save_setting('default_registration_page', $maybe_register_page->ID);
function_exists('flush_rewrite_rules') && flush_rewrite_rules(true);
return $maybe_register_page->ID;
}
return false;
});
} // end wu_guess_registration_page;
);
}
/**
* Checks if the current post is a registration page.
@ -58,21 +54,16 @@ function wu_is_registration_page() {
/** @var \WP_Post|null $post */
global $post;
if (!is_main_site()) {
if ( ! is_main_site()) {
return false;
}
} // end if;
if (!is_a($post, '\WP_Post')) {
if ( ! is_a($post, '\WP_Post')) {
return false;
} // end if;
}
return absint(wu_guess_registration_page()) === $post->ID;
} // end wu_is_registration_page;
}
/**
* Checks if the current post is a update page.
@ -84,21 +75,16 @@ function wu_is_update_page() {
global $post;
if (!is_main_site()) {
if ( ! is_main_site()) {
return false;
}
} // end if;
if (!is_a($post, '\WP_Post')) {
if ( ! is_a($post, '\WP_Post')) {
return false;
} // end if;
}
return absint(wu_get_setting('default_update_page', 0)) === $post->ID;
} // end wu_is_update_page;
}
/**
* Checks if the current post is a new site page.
@ -110,21 +96,16 @@ function wu_is_new_site_page() {
global $post;
if (!is_main_site()) {
if ( ! is_main_site()) {
return false;
}
} // end if;
if (!is_a($post, '\WP_Post')) {
if ( ! is_a($post, '\WP_Post')) {
return false;
} // end if;
}
return absint(wu_get_setting('default_new_site_page', 0)) === $post->ID;
} // end wu_is_new_site_page;
}
/**
* Checks if the current page is a login page.
@ -141,5 +122,4 @@ function wu_is_login_page() {
$is_default_wp_login = $pagenow === 'wp-login.php';
return $is_login_element_present || $is_default_wp_login;
} // end wu_is_login_page;
}

View File

@ -9,8 +9,8 @@
// Exit if accessed directly
defined('ABSPATH') || exit;
use \WP_Ultimo\Models\Payment;
use \WP_Ultimo\Database\Payments\Payment_Status;
use WP_Ultimo\Models\Payment;
use WP_Ultimo\Database\Payments\Payment_Status;
/**
* Returns a payment.
@ -23,8 +23,7 @@ use \WP_Ultimo\Database\Payments\Payment_Status;
function wu_get_payment($payment_id) {
return \WP_Ultimo\Models\Payment::get_by_id($payment_id);
} // end wu_get_payment;
}
/**
* Queries payments.
@ -37,8 +36,7 @@ function wu_get_payment($payment_id) {
function wu_get_payments($query = array()) {
return \WP_Ultimo\Models\Payment::query($query);
} // end wu_get_payments;
}
/**
* Returns a line-item.
@ -53,17 +51,14 @@ function wu_get_line_item($line_item_id, $payment_id) {
$payment = wu_get_payment($payment_id);
if (!$payment) {
if ( ! $payment) {
return false;
} // end if;
}
$line_items = $payment->get_line_items();
return wu_get_isset($line_items, $line_item_id, false);
} // end wu_get_line_item;
}
/**
* Gets a payment based on the hash.
*
@ -75,8 +70,7 @@ function wu_get_line_item($line_item_id, $payment_id) {
function wu_get_payment_by_hash($hash) {
return \WP_Ultimo\Models\Payment::get_by_hash($hash);
} // end wu_get_payment_by_hash;
}
/**
* Returns a single payment defined by a particular column and value.
*
@ -89,8 +83,7 @@ function wu_get_payment_by_hash($hash) {
function wu_get_payment_by($column, $value) {
return \WP_Ultimo\Models\Payment::get_by($column, $value);
} // end wu_get_payment_by;
}
/**
* Creates a new payment.
*
@ -105,41 +98,41 @@ function wu_create_payment($payment_data, $save = true) {
* Why do we use shortcode atts here?
* Shortcode atts clean the array from not-allowed keys, so we don't need to worry much.
*/
$payment_data = shortcode_atts(array(
'line_items' => array(),
'meta' => array(),
'customer_id' => false,
'membership_id' => false,
'parent_id' => '',
'product_id' => false,
'currency' => wu_get_setting('currency_symbol', 'USD'),
'discount_code' => '',
'subtotal' => 0.00,
'discount_total' => 0.00,
'tax_total' => 0.00,
'total' => 0.00,
'status' => Payment_Status::COMPLETED,
'gateway' => '',
'gateway_payment_id' => '',
'date_created' => wu_get_current_time('mysql', true),
'date_modified' => wu_get_current_time('mysql', true),
'migrated_from_id' => 0,
'skip_validation' => false,
), $payment_data);
$payment_data = shortcode_atts(
array(
'line_items' => array(),
'meta' => array(),
'customer_id' => false,
'membership_id' => false,
'parent_id' => '',
'product_id' => false,
'currency' => wu_get_setting('currency_symbol', 'USD'),
'discount_code' => '',
'subtotal' => 0.00,
'discount_total' => 0.00,
'tax_total' => 0.00,
'total' => 0.00,
'status' => Payment_Status::COMPLETED,
'gateway' => '',
'gateway_payment_id' => '',
'date_created' => wu_get_current_time('mysql', true),
'date_modified' => wu_get_current_time('mysql', true),
'migrated_from_id' => 0,
'skip_validation' => false,
),
$payment_data
);
$payment = new Payment($payment_data);
if (!$save) {
if ( ! $save) {
return $payment;
} // end if;
}
$saved = $payment->save();
return is_wp_error($saved) ? $saved : $payment;
} // end wu_create_payment;
}
/**
* Returns a list of the refundable payment types.
@ -158,8 +151,7 @@ function wu_get_refundable_payment_types() {
);
return apply_filters('wu_get_refundable_payment_type', $refundable_payment_types);
} // end wu_get_refundable_payment_types;
}
/**
* Returns the icon classes for a payment status.
@ -174,5 +166,4 @@ function wu_get_payment_icon_classes($payment_status) {
$payment_status_instance = new Payment_Status($payment_status);
return $payment_status_instance->get_icon_classes();
} // end wu_get_payment_icon_classes;
}

View File

@ -9,7 +9,7 @@
// Exit if accessed directly
defined('ABSPATH') || exit;
use \WP_Ultimo\Models\Product;
use WP_Ultimo\Models\Product;
/**
* Returns a product.
@ -22,14 +22,11 @@ use \WP_Ultimo\Models\Product;
function wu_get_product($product_id_or_slug) {
if (is_numeric($product_id_or_slug) === false) {
return wu_get_product_by_slug($product_id_or_slug);
} // end if;
}
return Product::get_by_id($product_id_or_slug);
} // end wu_get_product;
}
/**
* Queries products.
@ -42,8 +39,7 @@ function wu_get_product($product_id_or_slug) {
function wu_get_products($query = array()) {
return Product::query($query);
} // end wu_get_products;
}
/**
* Queries plans.
@ -64,8 +60,7 @@ function wu_get_plans($query = array()) {
$query['orderby'] = 'list_order';
return Product::query($query);
} // end wu_get_plans;
}
/**
* Returns the list of plans as ID -> Name.
@ -78,14 +73,11 @@ function wu_get_plans_as_options() {
$options = array();
foreach (wu_get_plans() as $plan) {
$options[$plan->get_id()] = $plan->get_name();
} // end foreach;
$options[ $plan->get_id() ] = $plan->get_name();
}
return $options;
} // end wu_get_plans_as_options;
}
/**
* Returns a product based on slug.
@ -98,8 +90,7 @@ function wu_get_plans_as_options() {
function wu_get_product_by_slug($product_slug) {
return Product::get_by('slug', $product_slug);
} // end wu_get_product_by_slug;
}
/**
* Returns a single product defined by a particular column and value.
*
@ -112,8 +103,7 @@ function wu_get_product_by_slug($product_slug) {
function wu_get_product_by($column, $value) {
return Product::get_by($column, $value);
} // end wu_get_product_by;
}
/**
* Creates a new product.
@ -125,40 +115,42 @@ function wu_get_product_by($column, $value) {
*/
function wu_create_product($product_data) {
$product_data = wp_parse_args($product_data, array(
'name' => false,
'description' => false,
'currency' => false,
'pricing_type' => false,
'setup_fee' => false,
'parent_id' => 0,
'slug' => false,
'recurring' => false,
'trial_duration' => 0,
'trial_duration_unit' => 'day',
'duration' => 1,
'duration_unit' => 'day',
'amount' => false,
'billing_cycles' => false,
'active' => false,
'type' => false,
'featured_image_id' => 0,
'list_order' => 0,
'date_created' => wu_get_current_time('mysql', true),
'date_modified' => wu_get_current_time('mysql', true),
'migrated_from_id' => 0,
'meta' => array(),
'available_addons' => array(),
'group' => '',
));
$product_data = wp_parse_args(
$product_data,
array(
'name' => false,
'description' => false,
'currency' => false,
'pricing_type' => false,
'setup_fee' => false,
'parent_id' => 0,
'slug' => false,
'recurring' => false,
'trial_duration' => 0,
'trial_duration_unit' => 'day',
'duration' => 1,
'duration_unit' => 'day',
'amount' => false,
'billing_cycles' => false,
'active' => false,
'type' => false,
'featured_image_id' => 0,
'list_order' => 0,
'date_created' => wu_get_current_time('mysql', true),
'date_modified' => wu_get_current_time('mysql', true),
'migrated_from_id' => 0,
'meta' => array(),
'available_addons' => array(),
'group' => '',
)
);
$product = new Product($product_data);
$saved = $product->save();
return is_wp_error($saved) ? $saved : $product;
} // end wu_create_product;
}
/**
* Returns a list of available product groups.
*
@ -173,8 +165,7 @@ function wu_get_product_groups(): array {
$results = array_column($wpdb->get_results($query, ARRAY_A), 'product_group'); // phpcs:ignore
return array_combine($results, $results);
} // end wu_get_product_groups;
}
/**
* Takes a list of product objects and separates them into plan and addons.
@ -189,31 +180,20 @@ function wu_segregate_products($products) {
$results = array(false, array());
foreach ($products as $product) {
if (is_a($product, Product::class) === false) {
$product = wu_get_product($product);
if (!$product) {
if ( ! $product) {
continue;
} // end if;
} // end if;
}
}
if ($product->get_type() === 'plan' && $results[0] === false) {
$results[0] = $product;
} else {
$results[1][] = $product;
} // end if;
} // end foreach;
}
}
return $results;
} // end wu_segregate_products;
}

View File

@ -9,7 +9,7 @@
// Exit if accessed directly
defined('ABSPATH') || exit;
use \phpDocumentor\Reflection\DocBlockFactory;
use phpDocumentor\Reflection\DocBlockFactory;
/**
* Creates the REST API schema blueprint for an object based on setters.
@ -28,8 +28,7 @@ function wu_reflection_parse_object_arguments($class_name) {
* @todo add a logger.
*/
return $base_schema;
} // end if;
}
$reflector = new \ReflectionClass($class_name);
@ -43,75 +42,55 @@ function wu_reflection_parse_object_arguments($class_name) {
$db_schema = method_exists($class_name, 'get_schema') ? $class_name::get_schema() : false;
foreach ($base_schema as $column) {
try {
$doc_block = $doc_block_factory->create($reflector->getMethod("set_{$column['name']}")->getDocComment());
} catch (\Throwable $exception) {
/**
* Something went wrong trying to parse the doc-blocks.
*/
continue;
} // end try;
}
$param = $doc_block->getTagsByName('param');
if (isset($param[0]) && is_object($param[0])) {
$arguments[$column['name']] = array(
$arguments[ $column['name'] ] = array(
'description' => (string) $param[0]->getDescription(),
'type' => (string) $param[0]->getType(),
'required' => false, // Actual value set later
);
if ($db_schema) {
$db_column = wu_array_find_first_by($db_schema, 'name', $column['name']);
if ($db_column && wu_get_isset($db_column, 'type') && preg_match('/^ENUM/', (string) $db_column['type'])) {
preg_match_all("/'(.*?)'/", (string) $db_column['type'], $matches);
if (isset($matches[1])) {
$arguments[$column['name']]['enum'] = array_map('strtolower', $matches[1]);
} // end if;
} // end if;
} // end if;
$arguments[ $column['name'] ]['enum'] = array_map('strtolower', $matches[1]);
}
}
}
$option = $doc_block->getTagsByName('options');
if (isset($option[0])) {
$description = (string) $option[0]->getDescription();
if (strpos($description, '\\WP_Ultimo\\') !== false) {
$enum_options = new $description();
$arguments[$column['name']]['enum'] = array_map('strtolower', array_keys(array_flip($enum_options->get_options())));
$arguments[ $column['name'] ]['enum'] = array_map('strtolower', array_keys(array_flip($enum_options->get_options())));
} else {
$arguments[$column['name']]['enum'] = explode(',', strtolower($description));
} // end if;
} // end if;
} // end if;
} // end foreach;
$arguments[ $column['name'] ]['enum'] = explode(',', strtolower($description));
}
}
}
}
return $arguments;
} // end wu_reflection_parse_object_arguments;
}
/**
* Use php reflection to generate the documentation for the REST API.
@ -127,28 +106,19 @@ function wu_reflection_parse_arguments_from_setters($class_name, $return_schema
$arguments = array();
foreach (get_class_methods($class_name) as $setter_name) {
if (preg_match('/^set_/', $setter_name)) {
$argument = str_replace('set_', '', $setter_name);
if ($return_schema) {
$arguments[] = array(
'name' => $argument,
'type' => '',
);
} else {
$arguments[] = $argument;
} // end if;
} // end if;
} // end foreach;
}
}
}
return $arguments;
} // end wu_reflection_parse_arguments_from_setters;
}

View File

@ -24,16 +24,13 @@ function wu_rest_get_endpoint_from_class_name($class_name) {
$endpoint = $class_name;
if (class_exists($class_name)) {
$last_segment = explode('\\', $class_name);
$endpoint = strtolower(end($last_segment));
} // end if;
}
return $endpoint;
} // end wu_rest_get_endpoint_from_class_name;
}
/**
* Searches the hard-coded schemas for a arguments list.
@ -56,22 +53,17 @@ function wu_rest_get_endpoint_schema($class_name, $context = 'create', $force_ge
$schema_file = wu_path("inc/api/schemas/$endpoint-$context.php");
if (file_exists($schema_file) && apply_filters('wu_rest_get_endpoint_schema_use_cache', true)) {
$schema = include $schema_file;
$from_cache = true;
} // end if;
}
if (empty($schema) && $from_cache === false && $force_generate) {
$schema = wu_rest_generate_schema($class_name, $context);
} // end if;
}
return $schema;
} // end wu_rest_get_endpoint_schema;
}
/**
* Generates the rest schema for a class name.
@ -89,18 +81,15 @@ function wu_rest_generate_schema($class_name, $context = 'create') {
$schema = wu_reflection_parse_object_arguments($class_name);
foreach ($schema as $argument_name => &$argument) {
$argument['type'] = wu_rest_treat_argument_type($argument['type']);
$argument['required'] = $context === 'create' ? in_array($argument_name, $required_fields, true) : false;
$schema[$argument_name] = $argument;
} // end foreach;
$schema[ $argument_name ] = $argument;
}
return $schema;
} // end wu_rest_generate_schema;
}
/**
* Treat argument types to perform additional validations.
@ -115,19 +104,12 @@ function wu_rest_treat_argument_type($type) {
$type = (string) $type;
if ($type === 'bool') {
$type = 'boolean';
} elseif ($type === 'int') {
$type = 'integer';
} elseif ($type === 'float') {
$type = 'number';
} // end if;
}
return $type;
} // end wu_rest_treat_argument_type;
}

View File

@ -18,14 +18,11 @@ defined('ABSPATH') || exit;
function wu_get_next_queue_run() {
if (class_exists('ActionScheduler')) {
return wu_switch_blog_and_run(fn() => ActionScheduler::lock()->get_expiration('async-request-runner') - time());
} // end if;
}
return 0;
} // end wu_get_next_queue_run;
}
/**
* Enqueue an action to run one time, as soon as possible.
@ -40,8 +37,7 @@ function wu_get_next_queue_run() {
function wu_enqueue_async_action($hook, $args = array(), $group = '') {
return wu_switch_blog_and_run(fn() => as_enqueue_async_action($hook, $args, $group));
} // end wu_enqueue_async_action;
}
/**
* Schedule an action to run one time.
@ -58,8 +54,7 @@ function wu_enqueue_async_action($hook, $args = array(), $group = '') {
function wu_schedule_single_action($timestamp, $hook, $args = array(), $group = '') {
return wu_switch_blog_and_run(fn() => as_schedule_single_action($timestamp, $hook, $args, $group));
} // end wu_schedule_single_action;
}
/**
* Schedule a recurring action.
@ -77,8 +72,7 @@ function wu_schedule_single_action($timestamp, $hook, $args = array(), $group =
function wu_schedule_recurring_action($timestamp, $interval_in_seconds, $hook, $args = array(), $group = '') {
return wu_switch_blog_and_run(fn() => as_schedule_recurring_action($timestamp, $interval_in_seconds, $hook, $args, $group));
} // end wu_schedule_recurring_action;
}
/**
* Schedule an action that recurs on a cron-like schedule.
@ -108,8 +102,7 @@ function wu_schedule_recurring_action($timestamp, $interval_in_seconds, $hook, $
function wu_schedule_cron_action($timestamp, $schedule, $hook, $args = array(), $group = '') {
return wu_switch_blog_and_run(fn() => as_schedule_cron_action($timestamp, $schedule, $hook, $args, $group));
} // end wu_schedule_cron_action;
}
/**
* Cancel the next occurrence of a scheduled action.
@ -125,8 +118,7 @@ function wu_schedule_cron_action($timestamp, $schedule, $hook, $args = array(),
function wu_unschedule_action($hook, $args = array(), $group = '') {
return wu_switch_blog_and_run(fn() => as_unschedule_action($hook, $args, $group));
} // end wu_unschedule_action;
}
/**
* Cancel all occurrences of a scheduled action.
@ -137,11 +129,10 @@ function wu_unschedule_action($hook, $args = array(), $group = '') {
* @param array $args Args that would have been passed to the job.
* @param string $group The group the job is assigned to.
*/
function wu_unschedule_all_actions($hook, $args = array(), $group = '' ) {
function wu_unschedule_all_actions($hook, $args = array(), $group = '') {
return wu_switch_blog_and_run(fn() => as_unschedule_all_actions($hook, $args, $group));
} // end wu_unschedule_all_actions;
}
/**
* Check if there is an existing action in the queue with a given hook, args and group combination.
@ -163,8 +154,7 @@ function wu_unschedule_all_actions($hook, $args = array(), $group = '' ) {
function wu_next_scheduled_action($hook, $args = null, $group = '') {
return wu_switch_blog_and_run(fn() => as_next_scheduled_action($hook, $args, $group));
} // end wu_next_scheduled_action;
}
/**
* Find scheduled actions.
@ -179,5 +169,4 @@ function wu_next_scheduled_action($hook, $args = null, $group = '') {
function wu_get_scheduled_actions($args = array(), $return_format = OBJECT) {
return wu_switch_blog_and_run(fn() => as_get_scheduled_actions($args, $return_format));
} // end wu_get_scheduled_actions;
}

View File

@ -25,14 +25,11 @@ function wu_get_session($session_key) {
$session = wu_get_isset($wu_session, $session_key, false);
if ($session && is_a( $session, \WP_Ultimo\Session_Cookie::class)) {
if ($session && is_a($session, \WP_Ultimo\Session_Cookie::class)) {
return $session;
}
} // end if;
$wu_session[ $session_key ] = new \WP_Ultimo\Session_Cookie($session_key);
$wu_session[$session_key] = new \WP_Ultimo\Session_Cookie($session_key);
return $wu_session[$session_key];
} // end wu_get_session;
return $wu_session[ $session_key ];
}

View File

@ -23,8 +23,7 @@ require_once wu_path('inc/functions/options.php');
function wu_get_all_settings() {
return WP_Ultimo()->settings->get_all();
} // end wu_get_all_settings;
}
/**
* Get a specific settings from the plugin.
@ -38,8 +37,7 @@ function wu_get_all_settings() {
function wu_get_setting($setting, $default = false) {
return WP_Ultimo()->settings->get_setting($setting, $default);
} // end wu_get_setting;
}
/**
* Saves a specific setting into the database.
@ -53,8 +51,7 @@ function wu_get_setting($setting, $default = false) {
function wu_save_setting($setting, $value) {
return WP_Ultimo()->settings->save_setting($setting, $value);
} // end wu_save_setting;
}
/**
* Adds a new settings section.
@ -72,8 +69,7 @@ function wu_save_setting($setting, $value) {
function wu_register_settings_section($section_slug, $atts) {
WP_Ultimo()->settings->add_section($section_slug, $atts);
} // end wu_register_settings_section;
}
/**
* Adds a new field to a settings section.
@ -91,8 +87,7 @@ function wu_register_settings_section($section_slug, $atts) {
function wu_register_settings_field($section_slug, $field_slug, $atts, $priority = 10) {
WP_Ultimo()->settings->add_field($section_slug, $field_slug, $atts, $priority);
} // end wu_register_settings_field;
}
/**
* Adds a help side-panel to the settings page.
@ -106,36 +101,40 @@ function wu_register_settings_field($section_slug, $field_slug, $atts, $priority
function wu_register_settings_side_panel($section_slug, $atts) {
if (wu_request('tab', 'general') !== $section_slug && $section_slug !== 'all') {
return;
}
} // end if;
$atts = wp_parse_args($atts, array(
'title' => __('Side Panel', 'wp-ultimo'),
'render' => '__return_false',
'show' => '__return_true',
));
$atts = wp_parse_args(
$atts,
array(
'title' => __('Side Panel', 'wp-ultimo'),
'render' => '__return_false',
'show' => '__return_true',
)
);
$callback = wu_get_isset($atts, 'show', '__return_true');
$should_display = is_callable($callback) && call_user_func($callback);
if (!$should_display) {
if ( ! $should_display) {
return;
} // end if;
}
$id = sanitize_title($atts['title']);
add_meta_box("wp-ultimo-{$id}", $atts['title'], function() use ($atts) {
add_meta_box(
"wp-ultimo-{$id}",
$atts['title'],
function () use ($atts) {
call_user_func($atts['render']);
}, 'wu_settings_admin_page', 'side', 'low');
} // end wu_register_settings_side_panel;
call_user_func($atts['render']);
},
'wu_settings_admin_page',
'side',
'low'
);
}
/**
* Retrieve the network custom logo.
@ -152,24 +151,19 @@ function wu_get_network_logo($size = 'full') {
restore_current_blog();
if ($settings_logo) {
return $settings_logo[0];
} // end if;
}
$logo = wu_get_asset('logo.png', 'img');
$custom_logo = wp_get_attachment_image_src(get_theme_mod('custom_logo'), $size);
if (!empty($custom_logo)) {
if ( ! empty($custom_logo)) {
$logo = $custom_logo[0];
} // end if;
}
return apply_filters('wu_get_logo', $logo);
} // end wu_get_network_logo;
}
/**
* Retrieve the network custom icon.
@ -182,5 +176,4 @@ function wu_get_network_favicon($size = '48') {
$custom_icon = get_site_icon_url($size, wu_get_asset('badge.png', 'img'), wu_get_main_site_id());
return $custom_icon;
} // end wu_get_network_favicon;
}

View File

@ -20,11 +20,9 @@ defined('ABSPATH') || exit;
*/
function wu_switch_blog_and_run($callback, $site_id = false) {
if (!$site_id) {
if ( ! $site_id) {
$site_id = wu_get_main_site_id();
} // end if;
}
is_multisite() && switch_to_blog($site_id);
@ -33,5 +31,4 @@ function wu_switch_blog_and_run($callback, $site_id = false) {
is_multisite() && restore_current_blog();
return $result;
} // end wu_switch_blog_and_run;
}

View File

@ -18,8 +18,7 @@ defined('ABSPATH') || exit;
function wu_get_current_site() {
return new \WP_Ultimo\Models\Site(get_blog_details());
} // end wu_get_current_site;
}
/**
* Returns the site object
@ -32,8 +31,7 @@ function wu_get_current_site() {
function wu_get_site($id) {
return \WP_Ultimo\Models\Site::get_by_id($id);
} // end wu_get_site;
}
/**
* Gets a site based on the hash.
*
@ -45,8 +43,7 @@ function wu_get_site($id) {
function wu_get_site_by_hash($hash) {
return \WP_Ultimo\Models\Site::get_by_hash($hash);
} // end wu_get_site_by_hash;
}
/**
* Queries sites.
@ -58,29 +55,26 @@ function wu_get_site_by_hash($hash) {
*/
function wu_get_sites($query = array()) {
if (!empty($query['search'])) {
$domain_ids = wu_get_domains(array(
'number' => -1,
'search' => '*' . $query['search'] . '*',
'fields' => array('blog_id'),
));
if ( ! empty($query['search'])) {
$domain_ids = wu_get_domains(
array(
'number' => -1,
'search' => '*' . $query['search'] . '*',
'fields' => array('blog_id'),
)
);
$domain_ids = array_column($domain_ids, 'blog_id');
if (!empty($domain_ids)) {
if ( ! empty($domain_ids)) {
$query['blog_id__in'] = $domain_ids;
unset($query['search']);
} // end if;
} // end if;
}
}
return \WP_Ultimo\Models\Site::query($query);
} // end wu_get_sites;
}
/**
* Returns the list of Site Templates.
@ -92,13 +86,15 @@ function wu_get_sites($query = array()) {
*/
function wu_get_site_templates($query = array()) {
$query = wp_parse_args($query, array(
'number' => 9999, // By default, we try to get ALL available templates.
));
$query = wp_parse_args(
$query,
array(
'number' => 9999, // By default, we try to get ALL available templates.
)
);
return \WP_Ultimo\Models\Site::get_all_by_type('site_template', $query);
} // end wu_get_site_templates;
}
/**
* Parses a URL and breaks it into different parts
@ -113,16 +109,13 @@ function wu_handle_site_domain($domain) {
global $current_site;
if (strpos($domain, 'http') === false) {
$domain = "https://{$domain}";
} // end if;
}
$parsed = parse_url($domain);
return (object) $parsed;
} // end wu_handle_site_domain;
}
/**
* Creates a new site.
*
@ -135,16 +128,19 @@ function wu_create_site($site_data) {
$current_site = get_current_site();
$site_data = wp_parse_args($site_data, array(
'domain' => $current_site->domain,
'path' => '/',
'title' => false,
'type' => false,
'template_id' => false,
'featured_image_id' => 0,
'duplication_arguments' => false,
'public' => true,
));
$site_data = wp_parse_args(
$site_data,
array(
'domain' => $current_site->domain,
'path' => '/',
'title' => false,
'type' => false,
'template_id' => false,
'featured_image_id' => 0,
'duplication_arguments' => false,
'public' => true,
)
);
$site = new \WP_Ultimo\Models\Site($site_data);
@ -153,8 +149,7 @@ function wu_create_site($site_data) {
$saved = $site->save();
return is_wp_error($saved) ? $saved : $site;
} // end wu_create_site;
}
/**
* Returns the correct domain/path combination when creating a new site.
@ -173,7 +168,7 @@ function wu_get_site_domain_and_path($path_or_subdomain = '/', $base_domain = fa
$domain = $base_domain ? $base_domain : $current_site->domain;
$d = new \stdClass;
$d = new \stdClass();
if (is_multisite() && is_subdomain_install()) {
/*
@ -186,8 +181,7 @@ function wu_get_site_domain_and_path($path_or_subdomain = '/', $base_domain = fa
$d->path = '/';
return $d;
} // end if;
}
$d->domain = $domain;
@ -205,5 +199,4 @@ function wu_get_site_domain_and_path($path_or_subdomain = '/', $base_domain = fa
* @return object An object containing a domain and path keys.
*/
return apply_filters('wu_get_site_domain_and_path', $d, $path_or_subdomain);
} // end wu_get_site_domain_and_path;
}

View File

@ -21,13 +21,12 @@ defined('ABSPATH') || exit;
*/
function wu_sort_by_column($a, $b, $column = 'order') {
$a[$column] = isset($a[$column]) ? (int) $a[$column] : 50;
$a[ $column ] = isset($a[ $column ]) ? (int) $a[ $column ] : 50;
$b[$column] = isset($b[$column]) ? (int) $b[$column] : 50;
$b[ $column ] = isset($b[ $column ]) ? (int) $b[ $column ] : 50;
return $a[$column] - $b[$column];
} // end wu_sort_by_column;
return $a[ $column ] - $b[ $column ];
}
/**
* Sorts the fields.
@ -39,8 +38,7 @@ function wu_sort_by_column($a, $b, $column = 'order') {
function wu_sort_by_order($a, $b) {
return wu_sort_by_column($a, $b, 'order');
} // end wu_sort_by_order;
}
/**
* Loops through the list items and adds a order key if none is set, based on the index.
@ -56,19 +54,14 @@ function wu_set_order_from_index($list, $order_key = 'order') {
$index = 1;
foreach ($list as &$item) {
if (isset($item[$order_key]) === false) {
if (isset($item[ $order_key ]) === false) {
$index = $index ? $index : 1; // phpcs:ignore
$item[$order_key] = $index * 10;
$item[ $order_key ] = $index * 10;
$index++;
} // end if;
} // end foreach;
++$index;
}
}
return $list;
} // end wu_set_order_from_index;
}

View File

@ -20,8 +20,7 @@ defined('ABSPATH') || exit;
function wu_string_to_bool($string) {
return is_bool($string) ? $string : ('on' === strtolower($string) || 'yes' === strtolower($string) || 1 === $string || 'true' === strtolower($string) || '1' === $string);
} // end wu_string_to_bool;
}
/**
* Converts a slug to a name.
@ -38,8 +37,7 @@ function wu_slug_to_name($slug) {
$slug = str_replace(array('-', '_'), ' ', $slug);
return ucwords($slug);
} // end wu_slug_to_name;
}
/**
* Replaces dashes with underscores on strings.
@ -52,8 +50,7 @@ function wu_slug_to_name($slug) {
function wu_replace_dashes($str) {
return str_replace('-', '_', $str);
} // end wu_replace_dashes;
}
/**
* Get the initials for a string.
@ -73,17 +70,12 @@ function wu_get_initials($string, $max_size = 2) {
$initials = '';
for ($i = 0; $i < $max_size; $i++) {
if (!isset($words[$i])) {
if ( ! isset($words[ $i ])) {
break;
}
} // end if;
$initials .= substr($words[$i], 0, 1);
} // end for;
$initials .= substr($words[ $i ], 0, 1);
}
return strtoupper($initials);
} // end wu_get_initials;
}

View File

@ -20,8 +20,7 @@ defined('ABSPATH') || exit;
function wu_should_load_sunrise() {
return \WP_Ultimo\Sunrise::should_load_sunrise();
} // end wu_should_load_sunrise;
}
/**
* Get a setting value, when te normal APIs are not available.
@ -37,18 +36,15 @@ function wu_should_load_sunrise() {
function wu_get_setting_early($setting, $default = false) {
if (did_action('wp_ultimo_load')) {
_doing_it_wrong('wu_get_setting_early', __('Regular setting APIs are already available. You should use wu_get_setting() instead.', 'wp-ultimo'), '2.0.0');
} // end if;
}
$settings_key = \WP_Ultimo\Settings::KEY;
$settings = get_network_option(null, 'wp-ultimo_' . $settings_key);
return wu_get_isset($settings, $setting, $default);
} // end wu_get_setting_early;
}
/**
* Set a setting value, when te normal APIs are not available.
@ -63,20 +59,17 @@ function wu_get_setting_early($setting, $default = false) {
function wu_save_setting_early($key, $value) {
if (did_action('wp_ultimo_load')) {
_doing_it_wrong('wu_save_setting_early', __('Regular setting APIs are already available. You should use wu_save_setting() instead.', 'wp-ultimo'), '2.0.20');
} // end if;
}
$settings_key = \WP_Ultimo\Settings::KEY;
$settings = get_network_option(null, 'wp-ultimo_' . $settings_key);
$settings[$key] = $value;
$settings[ $key ] = $value;
return update_network_option(null, 'wp-ultimo_' . $settings_key, $settings);
} // end wu_save_setting_early;
}
/**
* Get the security mode key used to disable security mode
@ -88,8 +81,7 @@ function wu_get_security_mode_key(): string {
$hash = md5((string) get_network_option(null, 'admin_email'));
return substr($hash, 0, 6);
} // end wu_get_security_mode_key;
}
/**
* Early substitute for wp_kses_data before it exists.
@ -106,5 +98,4 @@ function wu_get_security_mode_key(): string {
function wu_kses_data($data) {
return function_exists('wp_kses_data') ? wp_kses_data($data) : $data;
} // end wu_kses_data;
}

View File

@ -9,7 +9,7 @@
// Exit if accessed directly
defined('ABSPATH') || exit;
use \WP_Ultimo\Tax\Tax;
use WP_Ultimo\Tax\Tax;
/**
* Checks if WP Multisite WaaS should collect taxes.
@ -20,8 +20,7 @@ use \WP_Ultimo\Tax\Tax;
function wu_should_collect_taxes() {
return (bool) wu_get_setting('enable_taxes', false);
} // end wu_should_collect_taxes;
}
/**
* Returns the tax categories.
@ -32,8 +31,7 @@ function wu_should_collect_taxes() {
function wu_get_tax_categories() {
return Tax::get_instance()->get_tax_rates();
} // end wu_get_tax_categories;
}
/**
* Returns a given tax category
@ -46,11 +44,14 @@ function wu_get_tax_category($tax_category = 'default') {
$tax_categories = wu_get_tax_categories();
return wu_get_isset($tax_categories, $tax_category, array(
'rates' => array(),
));
} // end wu_get_tax_category;
return wu_get_isset(
$tax_categories,
$tax_category,
array(
'rates' => array(),
)
);
}
/**
* Returns the tax categories as a slug => name array.
*
@ -59,8 +60,7 @@ function wu_get_tax_category($tax_category = 'default') {
function wu_get_tax_categories_as_options(): array {
return array_map(fn($item) => $item['name'], wu_get_tax_categories());
} // end wu_get_tax_categories_as_options;
}
/**
* Calculates the tax value.
*
@ -81,8 +81,7 @@ function wu_get_tax_amount($base_price, $amount, $type, $format = true, $inclusi
$tax_total = $amount;
if ($type === 'percentage') {
if (!$inclusive) {
if ( ! $inclusive) {
/**
* Exclusive tax
@ -90,7 +89,6 @@ function wu_get_tax_amount($base_price, $amount, $type, $format = true, $inclusi
* Calculates tax to be ADDED to the order.
*/
$tax_total = $base_price * ($amount / 100);
} else {
/**
@ -99,24 +97,19 @@ function wu_get_tax_amount($base_price, $amount, $type, $format = true, $inclusi
* Calculates the tax value inside the total price.
*/
$tax_total = $base_price - ($base_price / (1 + ($amount / 100)));
} // end if;
} // end if;
}
}
/*
* Return results
*/
if (!$format) {
if ( ! $format) {
return round($tax_total, 2);
} // end if;
}
return number_format((float) $tax_total, 2);
} // end wu_get_tax_amount;
}
/**
* Searches for applicable tax rates based on the country.
@ -134,11 +127,9 @@ function wu_get_tax_amount($base_price, $amount, $type, $format = true, $inclusi
*/
function wu_get_applicable_tax_rates($country, $tax_category = 'default', $state = '*', $city = '*') {
if (!$country) {
if ( ! $country) {
return array();
} // end if;
}
$tax_category = wu_get_tax_category($tax_category);
@ -146,84 +137,69 @@ function wu_get_applicable_tax_rates($country, $tax_category = 'default', $state
foreach ($tax_category['rates'] as &$rate) {
/*
* Step 0: Prepare.
* Step 0: Prepare.
*/
$rate['state'] = explode(',', (string) $rate['state']);
$rate['city'] = explode(',', (string) $rate['city']);
$keys_of_interest = array_intersect_key($rate, array(
'country' => 1,
'state' => 1,
'city' => 1,
));
$keys_of_interest = array_intersect_key(
$rate,
array(
'country' => 1,
'state' => 1,
'city' => 1,
)
);
$priority = 0;
foreach ($keys_of_interest as $key => $value) {
$value = is_array($value) ? array_filter($value) : trim((string) $value);
/*
* Step 1: The country.
*/
if ($key === 'country' && $rate['country'] === $country) {
$priority += 10;
} // end if;
}
/*
* Step 2: The state / province
*/
if ($key === 'state' && $state !== '*') {
if (in_array($state, $value, true)) {
$priority += 1;
} elseif (empty($value) || in_array('*', $value, true)) {
$priority += 0.5;
} // end if;
} // end if;
}
}
/*
* Step 3: The city
*/
if ($key === 'city' && $city !== '*') {
if (in_array($city, $value, true)) {
/*
* If it's a full match, gives 1 point.
*/
$priority += 1;
} elseif (empty($value) || in_array('*', $value, true)) {
/*
* If it is a wildcard, award half a point.
*/
$priority += 0.5;
} // end if;
} // end if;
} // end foreach;
}
}
}
if ($priority >= 10) {
$rate['order'] = $priority;
$results[$rate['id']] = $rate;
} // end if;
} // end foreach;
$results[ $rate['id'] ] = $rate;
}
}
uasort($results, 'wu_sort_by_order');
return array_values($results);
} // end wu_get_applicable_tax_rates;
}

View File

@ -34,10 +34,8 @@ function wu_get_template($view, $args = array(), $default_view = false) {
// Make passed variables available
if (is_array($args)) {
extract($args); // phpcs:ignore
} // end if;
}
/**
* Allows developers to add additional folders to the replaceable list.
@ -49,32 +47,30 @@ function wu_get_template($view, $args = array(), $default_view = false) {
* @param array $replaceable_views List of allowed folders.
* @return array
*/
$replaceable_views = apply_filters('wu_view_override_replaceable_views', array(
'signup',
'emails',
'forms',
'checkout'
));
$replaceable_views = apply_filters(
'wu_view_override_replaceable_views',
array(
'signup',
'emails',
'forms',
'checkout',
)
);
/*
* Only allow template for emails and signup for now
*/
if (preg_match('/(' . implode('\/?|', $replaceable_views) . '\/?' . ')\w+/', $view)) {
$template = apply_filters('wu_view_override', $template, $view, $default_view);
}
} // end if;
if (!file_exists($template) && $default_view) {
if ( ! file_exists($template) && $default_view) {
$template = wu_path("views/$default_view.php");
} // end if;
}
// Load our view
include $template;
} // end wu_get_template;
}
/**
* Alias function to be used on the templates;
@ -92,5 +88,4 @@ function wu_get_template_contents($view, $args = array(), $default_view = false)
wu_get_template($view, $args, $default_view); // phpcs:ignore
return ob_get_clean();
} // end wu_get_template_contents;
}

View File

@ -20,15 +20,12 @@ defined('ABSPATH') || exit;
function wu_get_translatable_string($string) {
if (is_string($string) === false) {
return $string;
} // end if;
}
$translatable_strings = include WP_ULTIMO_PLUGIN_DIR . '/data/translatable-strings.php';
$translatable_strings = apply_filters('wu_translatable_strings', $translatable_strings, $string);
return wu_get_isset($translatable_strings, $string, $string);
} // end wu_get_translatable_string;
}

View File

@ -21,14 +21,11 @@ function wu_get_current_url() {
* the initiator URL.
*/
if (wp_doing_ajax() && isset($_SERVER['HTTP_REFERER'])) {
return $_SERVER['HTTP_REFERER'];
} // end if;
}
return (is_ssl() ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
} // end wu_get_current_url;
}
/**
* Replaces or removes the scheme from a URL.
@ -42,8 +39,7 @@ function wu_get_current_url() {
function wu_replace_scheme($url, $new_scheme = '') {
return preg_replace('(^https?://)', $new_scheme, $url);
} // end wu_replace_scheme;
}
/**
* Wrapper to the network_admin_url function for WP Multisite WaaS admin urls.
@ -61,8 +57,7 @@ function wu_network_admin_url($path, $query = array()) {
$url = network_admin_url($path);
return add_query_arg($query, $url);
} // end wu_network_admin_url;
}
/**
* Get the light ajax implementation URL.
@ -78,30 +73,23 @@ function wu_network_admin_url($path, $query = array()) {
function wu_ajax_url($when = null, $query_args = array(), $site_id = false, $scheme = null) {
if (empty($site_id)) {
$site_id = get_current_blog_id();
} // end if;
}
$base_url = get_home_url($site_id, '', $scheme);
if (!is_array($query_args)) {
if ( ! is_array($query_args)) {
$query_args = array();
} // end if;
}
$query_args['wu-ajax'] = 1;
$query_args['r'] = wp_create_nonce('wu-ajax-nonce');
if ($when) {
$query_args['wu-when'] = base64_encode($when);
} // end if;
}
$url = add_query_arg($query_args, $base_url);
return apply_filters('wu_ajax_url', $url, $query_args, $when, $site_id);
} // end wu_ajax_url;
}

View File

@ -18,28 +18,21 @@ defined('ABSPATH') || exit;
*/
function wu_get_roles_as_options($add_default_option = false) {
if (!function_exists('get_editable_roles')) {
require_once(ABSPATH . 'wp-admin/includes/user.php');
} // end if;
if ( ! function_exists('get_editable_roles')) {
require_once ABSPATH . 'wp-admin/includes/user.php';
}
$roles = array();
if ($add_default_option) {
$roles['default'] = __('Use WP Multisite WaaS default', 'wp-ultimo');
} // end if;
}
$editable_roles = get_editable_roles();
foreach ($editable_roles as $role => $details) {
$roles[esc_attr($role)] = translate_user_role($details['name']);
} // end foreach;
$roles[ esc_attr($role) ] = translate_user_role($details['name']);
}
return $roles;
} // end wu_get_roles_as_options;
}

View File

@ -9,7 +9,7 @@
// Exit if accessed directly
defined('ABSPATH') || exit;
use \WP_Ultimo\Models\Webhook;
use WP_Ultimo\Models\Webhook;
/**
* Queries webhook.
@ -22,8 +22,7 @@ use \WP_Ultimo\Models\Webhook;
function wu_get_webhooks($query = array()) {
return \WP_Ultimo\Models\Webhook::query($query);
} // end wu_get_webhooks;
}
/**
* Gets a webhook on the ID.
@ -36,8 +35,7 @@ function wu_get_webhooks($query = array()) {
function wu_get_webhook($webhook_id) {
return \WP_Ultimo\Models\Webhook::get_by_id($webhook_id);
} // end wu_get_webhook;
}
/**
* Creates a new webhook.
@ -51,21 +49,23 @@ function wu_get_webhook($webhook_id) {
*/
function wu_create_webhook($webhook_data) {
$webhook_data = wp_parse_args($webhook_data, array(
'name' => false,
'webhook_url' => false,
'event' => false,
'active' => false,
'event_count' => 0,
'date_created' => wu_get_current_time('mysql', true),
'date_modified' => wu_get_current_time('mysql', true),
'migrated_from_id' => 0,
));
$webhook_data = wp_parse_args(
$webhook_data,
array(
'name' => false,
'webhook_url' => false,
'event' => false,
'active' => false,
'event_count' => 0,
'date_created' => wu_get_current_time('mysql', true),
'date_modified' => wu_get_current_time('mysql', true),
'migrated_from_id' => 0,
)
);
$webhook = new Webhook($webhook_data);
$saved = $webhook->save();
return is_wp_error($saved) ? $saved : $webhook;
} // end wu_create_webhook;
}