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

@ -9,7 +9,7 @@
namespace WP_Ultimo\UI;
use \WP_Ultimo\UI\Base_Element;
use WP_Ultimo\UI\Base_Element;
// Exit if accessed directly
defined('ABSPATH') || exit;
@ -89,14 +89,11 @@ class Account_Summary_Element extends Base_Element {
public function get_icon($context = 'block') {
if ($context === 'elementor') {
return 'eicon-call-to-action';
} // end if;
}
return 'fa fa-search';
} // end get_icon;
}
/**
* The title of the UI element.
@ -111,8 +108,7 @@ class Account_Summary_Element extends Base_Element {
public function get_title() {
return __('Account Summary', 'wp-ultimo');
} // end get_title;
}
/**
* The description of the UI element.
@ -128,8 +124,7 @@ class Account_Summary_Element extends Base_Element {
public function get_description() {
return __('Adds a account summary block to the page.', 'wp-ultimo');
} // end get_description;
}
/**
* The list of fields to be added to Gutenberg.
@ -167,8 +162,7 @@ class Account_Summary_Element extends Base_Element {
);
return $fields;
} // end fields;
}
/**
* The list of keywords for this element.
@ -195,8 +189,7 @@ class Account_Summary_Element extends Base_Element {
'Summary',
'WP Multisite WaaS',
);
} // end keywords;
}
/**
* List of default parameters for the element.
@ -217,8 +210,7 @@ class Account_Summary_Element extends Base_Element {
return array(
'title' => __('About this Site', 'wp-ultimo'),
);
} // end defaults;
}
/**
* Runs early on the request lifecycle as soon as we detect the shortcode is present.
@ -230,13 +222,11 @@ class Account_Summary_Element extends Base_Element {
$this->site = WP_Ultimo()->currents->get_site();
if (!$this->site || !$this->site->is_customer_allowed()) {
if ( ! $this->site || ! $this->site->is_customer_allowed()) {
$this->set_display(false);
return;
} // end if;
}
$this->membership = $this->site->get_membership();
@ -260,8 +250,7 @@ class Account_Summary_Element extends Base_Element {
'unlimited_space' => $unlimited_space,
'message' => $message,
);
} // end setup;
}
/**
* Allows the setup in the context of previews.
@ -288,8 +277,7 @@ class Account_Summary_Element extends Base_Element {
'unlimited_space' => $unlimited_space,
'message' => $message,
);
} // end setup_preview;
}
/**
* The content to be output on the screen.
@ -315,8 +303,7 @@ class Account_Summary_Element extends Base_Element {
$atts['product'] = $this->product;
return wu_get_template_contents('dashboard-widgets/account-summary', $atts);
} // end output;
}
/**
* Returns the manage URL for sites, depending on the environment.
@ -331,7 +318,5 @@ class Account_Summary_Element extends Base_Element {
$base_url = \WP_Ultimo\Current::get_manage_url($site_id, 'site');
return is_admin() ? add_query_arg('page', 'account', $base_url . '/admin.php') : $base_url;
} // end get_manage_url;
} // end class Account_Summary_Element;
}
}

File diff suppressed because it is too large Load Diff

View File

@ -63,23 +63,20 @@ class Billing_Info_Element extends Base_Element {
protected $site;
/**
* The icon of the UI element.
* e.g. return fa fa-search
*
* @since 2.0.0
* @param string $context One of the values: block, elementor or bb.
*/
* The icon of the UI element.
* e.g. return fa fa-search
*
* @since 2.0.0
* @param string $context One of the values: block, elementor or bb.
*/
public function get_icon($context = 'block'): string {
if ($context === 'elementor') {
return 'eicon-info-circle-o';
} // end if;
}
return 'fa fa-search';
} // end get_icon;
}
/**
* Overload the init to add site-related forms.
@ -91,13 +88,15 @@ class Billing_Info_Element extends Base_Element {
parent::init();
wu_register_form('update_billing_address', array(
'render' => array($this, 'render_update_billing_address'),
'handler' => array($this, 'handle_update_billing_address'),
'capability' => 'exist',
));
} // end init;
wu_register_form(
'update_billing_address',
array(
'render' => array($this, 'render_update_billing_address'),
'handler' => array($this, 'handle_update_billing_address'),
'capability' => 'exist',
)
);
}
/**
* Loads the required scripts.
@ -108,8 +107,7 @@ class Billing_Info_Element extends Base_Element {
public function register_scripts() {
add_wubox();
} // end register_scripts;
}
/**
* The title of the UI element.
@ -124,8 +122,7 @@ class Billing_Info_Element extends Base_Element {
public function get_title() {
return __('Billing Information', 'wp-ultimo');
} // end get_title;
}
/**
* The description of the UI element.
@ -141,8 +138,7 @@ class Billing_Info_Element extends Base_Element {
public function get_description() {
return __('Adds a checkout form block to the page.', 'wp-ultimo');
} // end get_description;
}
/**
* The list of fields to be added to Gutenberg.
@ -180,8 +176,7 @@ class Billing_Info_Element extends Base_Element {
);
return $fields;
} // end fields;
}
/**
* The list of keywords for this element.
@ -209,8 +204,7 @@ class Billing_Info_Element extends Base_Element {
'Form',
'Cart',
);
} // end keywords;
}
/**
* List of default parameters for the element.
@ -231,8 +225,7 @@ class Billing_Info_Element extends Base_Element {
return array(
'title' => __('Billing Address', 'wp-ultimo'),
);
} // end defaults;
}
/**
* Runs early on the request lifecycle as soon as we detect the shortcode is present.
@ -244,15 +237,12 @@ class Billing_Info_Element extends Base_Element {
$this->membership = WP_Ultimo()->currents->get_membership();
if (!$this->membership) {
if ( ! $this->membership) {
$this->set_display(false);
return;
} // end if;
} // end setup;
}
}
/**
* Allows the setup in the context of previews.
@ -265,8 +255,7 @@ class Billing_Info_Element extends Base_Element {
$this->site = wu_mock_site();
$this->membership = wu_mock_membership();
} // end setup_preview;
}
/**
* The content to be output on the screen.
@ -287,14 +276,16 @@ class Billing_Info_Element extends Base_Element {
$atts['billing_address'] = $this->membership->get_billing_address();
$atts['update_billing_address_link'] = wu_get_form_url('update_billing_address', array(
'membership' => $this->membership->get_hash(),
'width' => 500,
));
$atts['update_billing_address_link'] = wu_get_form_url(
'update_billing_address',
array(
'membership' => $this->membership->get_hash(),
'width' => 500,
)
);
return wu_get_template_contents('dashboard-widgets/billing-info', $atts);
} // end output;
}
/**
* Apply the placeholders to the fields.
@ -307,14 +298,11 @@ class Billing_Info_Element extends Base_Element {
protected function apply_placeholders($fields) {
foreach ($fields as &$field) {
$field['placeholder'] = $field['default_placeholder'];
} // end foreach;
}
return $fields;
} // end apply_placeholders;
}
/**
* Renders the update billing address form.
@ -326,11 +314,9 @@ class Billing_Info_Element extends Base_Element {
$membership = wu_get_membership_by_hash(wu_request('membership'));
if (!$membership) {
if ( ! $membership) {
return '';
} // end if;
}
$billing_address = $membership->get_billing_address();
@ -361,19 +347,22 @@ class Billing_Info_Element extends Base_Element {
'value' => wu_request('membership'),
);
$form = new \WP_Ultimo\UI\Form('edit_site', $fields, array(
'views' => 'admin-pages/fields',
'classes' => 'wu-modal-form wu-widget-list wu-striped wu-m-0 wu-mt-0 wu-grid-cols-2 wu-grid',
'field_wrapper_classes' => 'wu-w-full wu-box-border wu-items-center wu-flex wu-justify-between wu-p-4 wu-m-0 wu-border-t wu-border-l-0 wu-border-r-0 wu-border-b-0 wu-border-gray-300 wu-border-solid wu-grid-col-span-2',
'html_attr' => array(
'data-wu-app' => 'edit_site',
'data-state' => wu_convert_to_state(),
),
));
$form = new \WP_Ultimo\UI\Form(
'edit_site',
$fields,
array(
'views' => 'admin-pages/fields',
'classes' => 'wu-modal-form wu-widget-list wu-striped wu-m-0 wu-mt-0 wu-grid-cols-2 wu-grid',
'field_wrapper_classes' => 'wu-w-full wu-box-border wu-items-center wu-flex wu-justify-between wu-p-4 wu-m-0 wu-border-t wu-border-l-0 wu-border-r-0 wu-border-b-0 wu-border-gray-300 wu-border-solid wu-grid-col-span-2',
'html_attr' => array(
'data-wu-app' => 'edit_site',
'data-state' => wu_convert_to_state(),
),
)
);
$form->render();
} // end render_update_billing_address;
}
/**
* Handles the password reset form.
@ -385,13 +374,11 @@ class Billing_Info_Element extends Base_Element {
$membership = wu_get_membership_by_hash(wu_request('membership'));
if (!$membership) {
if ( ! $membership) {
$error = new \WP_Error('membership-dont-exist', __('Something went wrong.', 'wp-ultimo'));
wp_send_json_error($error);
} // end if;
}
$billing_address = $membership->get_billing_address();
@ -400,25 +387,21 @@ class Billing_Info_Element extends Base_Element {
$valid_address = $billing_address->validate();
if (is_wp_error($valid_address)) {
wp_send_json_error($valid_address);
} // end if;
}
$membership->set_billing_address($billing_address);
$saved = $membership->save();
if (is_wp_error($saved)) {
wp_send_json_error($saved);
}
} // end if;
wp_send_json_success(array(
'redirect_url' => add_query_arg('updated', (int) $saved, $_SERVER['HTTP_REFERER']),
));
} // end handle_update_billing_address;
} // end class Billing_Info_Element;
wp_send_json_success(
array(
'redirect_url' => add_query_arg('updated', (int) $saved, $_SERVER['HTTP_REFERER']),
)
);
}
}

View File

@ -9,9 +9,9 @@
namespace WP_Ultimo\UI;
use \WP_Ultimo\UI\Base_Element;
use \ScssPhp\ScssPhp\Compiler;
use \WP_Ultimo\Database\Memberships\Membership_Status;
use WP_Ultimo\UI\Base_Element;
use ScssPhp\ScssPhp\Compiler;
use WP_Ultimo\Database\Memberships\Membership_Status;
// Exit if accessed directly
defined('ABSPATH') || exit;
@ -29,8 +29,8 @@ class Checkout_Element extends Base_Element {
* The current signup.
*
* @since 2.2.0
* @var Mocked_Signup
*/
* @var Mocked_Signup
*/
protected $signup;
/**
@ -81,23 +81,20 @@ class Checkout_Element extends Base_Element {
protected $public = true;
/**
* The icon of the UI element.
* e.g. return fa fa-search
*
* @since 2.0.0
* @param string $context One of the values: block, elementor or bb.
*/
* The icon of the UI element.
* e.g. return fa fa-search
*
* @since 2.0.0
* @param string $context One of the values: block, elementor or bb.
*/
public function get_icon($context = 'block'): string {
if ($context === 'elementor') {
return 'eicon-cart-medium';
} // end if;
}
return 'fa fa-search';
} // end get_icon;
}
/**
* The title of the UI element.
@ -112,8 +109,7 @@ class Checkout_Element extends Base_Element {
public function get_title() {
return __('Checkout', 'wp-ultimo');
} // end get_title;
}
/**
* The description of the UI element.
@ -129,8 +125,7 @@ class Checkout_Element extends Base_Element {
public function get_description() {
return __('Adds a checkout form block to the page.', 'wp-ultimo');
} // end get_description;
}
/**
* The list of fields to be added to Gutenberg.
@ -166,8 +161,7 @@ class Checkout_Element extends Base_Element {
);
return $fields;
} // end fields;
}
/**
* The list of keywords for this element.
@ -195,8 +189,7 @@ class Checkout_Element extends Base_Element {
'Form',
'Cart',
);
} // end keywords;
}
/**
* List of default parameters for the element.
@ -220,8 +213,7 @@ class Checkout_Element extends Base_Element {
'display_title' => false,
'membership_limitations' => array(),
);
} // end defaults;
}
/**
* Checks if we are on a thank you page.
@ -232,8 +224,7 @@ class Checkout_Element extends Base_Element {
public function is_thank_you_page() {
return is_user_logged_in() && wu_request('payment') && wu_request('status') === 'done';
} // end is_thank_you_page;
}
/**
* Triggers the setup event to allow the checkout class to hook in.
@ -244,16 +235,13 @@ class Checkout_Element extends Base_Element {
public function setup() {
if ($this->is_thank_you_page()) {
\WP_Ultimo\UI\Thank_You_Element::get_instance()->setup();
return;
} // end if;
}
do_action('wu_setup_checkout', $this);
} // end setup;
}
/**
* Print the Custom CSS added on the checkout.
@ -272,16 +260,15 @@ class Checkout_Element extends Base_Element {
$custom_css = $checkout_form->get_custom_css();
if ($custom_css) {
$custom_css = $scss->compileString(".wu_checkout_form_{$slug} {
$custom_css = $scss->compileString(
".wu_checkout_form_{$slug} {
{$custom_css}
}")->getCss();
}"
)->getCss();
echo sprintf('<style>%s</style>', $custom_css);
} // end if;
} // end print_custom_css;
printf('<style>%s</style>', $custom_css);
}
}
/**
* Outputs thank you page.
@ -305,8 +292,7 @@ class Checkout_Element extends Base_Element {
\WP_Ultimo\UI\Thank_You_Element::get_instance()->register_scripts();
return \WP_Ultimo\UI\Thank_You_Element::get_instance()->output($atts, $content);
} // end output_thank_you;
}
/**
* Outputs the registration form.
@ -336,18 +322,15 @@ class Checkout_Element extends Base_Element {
$bypass = apply_filters('wu_bypass_checkout_form', false, $atts);
if ($bypass) {
return is_string($bypass) ? $bypass : '';
} // end if;
}
if ($customer && $membership && $slug !== 'wu-finish-checkout') {
$published_sites = $membership->get_published_sites();
$pending_payment = $membership ? $membership->get_last_pending_payment() : false;
if ($pending_payment && !$membership->is_active() && $membership->get_status() !== Membership_Status::TRIALING) {
if ($pending_payment && ! $membership->is_active() && $membership->get_status() !== Membership_Status::TRIALING) {
/**
* We are talking about membership with a pending payment
*/
@ -355,9 +338,12 @@ class Checkout_Element extends Base_Element {
// Translators: Placeholder receives the customer display name
$message = sprintf(__('Hi %s. You have a pending payment for your membership!', 'wp-ultimo'), $customer->get_display_name());
$payment_url = add_query_arg(array(
'payment' => $pending_payment->get_hash(),
), wu_get_registration_url());
$payment_url = add_query_arg(
array(
'payment' => $pending_payment->get_hash(),
),
wu_get_registration_url()
);
// Translators: The link to registration url with payment hash
$message .= '<br>' . sprintf(__('Click <a href="%s">here</a> to pay.', 'wp-ultimo'), $payment_url);
@ -372,14 +358,13 @@ class Checkout_Element extends Base_Element {
* @param WP_Ultimo\Models\Customer $customer The active customer in use.
*/
return apply_filters('wu_checkout_pending_payment_error_message', $message, $membership, $customer);
} // end if;
}
$membership_blocked_forms = array(
'wu-add-new-site'
'wu-add-new-site',
);
if (!$membership->is_active() && $membership->get_status() !== Membership_Status::TRIALING && in_array($atts['slug'], $membership_blocked_forms, true)) {
if ( ! $membership->is_active() && $membership->get_status() !== Membership_Status::TRIALING && in_array($atts['slug'], $membership_blocked_forms, true)) {
// Translators: Placeholder receives the customer display name
$message = sprintf(__('Hi %s. You cannot take action on your membership while it is not active!', 'wp-ultimo'), $customer->get_display_name());
@ -390,15 +375,19 @@ class Checkout_Element extends Base_Element {
*/
wp_register_script('wu-thank-you', wu_get_asset('thank-you.js', 'js'), array(), wu_get_version());
wp_localize_script('wu-thank-you', 'wu_thank_you', array(
'ajaxurl' => admin_url('admin-ajax.php'),
'resend_verification_email_nonce' => wp_create_nonce('wu_resend_verification_email_nonce'),
'membership_hash' => $membership->get_hash(),
'i18n' => array(
'resending_verification_email' => __('Resending verification email...', 'wp-ultimo'),
'email_sent' => __('Verification email sent!', 'wp-ultimo'),
),
));
wp_localize_script(
'wu-thank-you',
'wu_thank_you',
array(
'ajaxurl' => admin_url('admin-ajax.php'),
'resend_verification_email_nonce' => wp_create_nonce('wu_resend_verification_email_nonce'),
'membership_hash' => $membership->get_hash(),
'i18n' => array(
'resending_verification_email' => __('Resending verification email...', 'wp-ultimo'),
'email_sent' => __('Verification email sent!', 'wp-ultimo'),
),
)
);
wp_enqueue_script('wu-thank-you');
@ -406,8 +395,7 @@ class Checkout_Element extends Base_Element {
$message .= '<span class="wu-styling">';
$message .= sprintf('<a href="#" class="wu-mr-2 wu-resend-verification-email wu-no-underline button button-primary">%s</a>', __('Resend verification email', 'wp-ultimo'));
$message .= '</span>';
} // end if;
}
/**
* Allow developers to change the message if membership have a pending payment
@ -417,33 +405,32 @@ class Checkout_Element extends Base_Element {
* @param WP_Ultimo\Models\Customer $customer The active customer in use.
*/
return apply_filters('wu_checkout_membership_status_error_message', $message, $membership, $customer);
}
} // end if;
if (!wu_multiple_memberships_enabled() && $membership) {
if ( ! wu_multiple_memberships_enabled() && $membership) {
/**
* Allow developers to add new form slugs to bypass this behaviour.
*
* @param array $slugs a list of form slugs to bypass.
*/
$allowed_forms = apply_filters('wu_get_membership_allowed_forms', array(
'wu-checkout',
'wu-add-new-site',
));
if (!in_array($slug, $allowed_forms, true) && !wu_request('payment')) {
$allowed_forms = apply_filters(
'wu_get_membership_allowed_forms',
array(
'wu-checkout',
'wu-add-new-site',
)
);
if ( ! in_array($slug, $allowed_forms, true) && ! wu_request('payment')) {
$message = sprintf('<p>%s</p>', __('You already have a membership!', 'wp-ultimo'));
if (isset($published_sites[0])) {
$account_link = get_admin_url($published_sites[0]->get_id(), 'admin.php?page=account');
$button_text = __('Go to my account', 'wp-ultimo');
$message .= "<p><a class=\"wu-no-underline button button-primary\" href=\"$account_link\">$button_text</a><p>";
} // end if;
}
/**
* Allow developers to change the message about the limitation of a single membership for customer.
@ -452,13 +439,10 @@ class Checkout_Element extends Base_Element {
* @param WP_Ultimo\Models\Customer $customer The active customer in use.
*/
return apply_filters('wu_checkout_single_membership_message', $message, $customer);
} // end if;
} // end if;
}
}
if ($membership && $membership->get_customer_id() !== $customer->get_id()) {
$message = sprintf('<p>%s</p>', __('You are not allowed to change this membership!', 'wp-ultimo'));
/**
@ -469,8 +453,7 @@ class Checkout_Element extends Base_Element {
* @param WP_Ultimo\Models\Customer $customer The active customer in use.
*/
return apply_filters('wu_checkout_customer_error_message', $message, $membership, $customer);
} // end if;
}
/**
* Now we filter the current membership for each membership_limitations
@ -478,23 +461,19 @@ class Checkout_Element extends Base_Element {
* a error message informing the user about and with buttons to allow
* account upgrade and/or to buy a new membership.
*/
if ($membership && !empty($atts['membership_limitations'])) {
if ($membership && ! empty($atts['membership_limitations'])) {
$limits = $membership->get_limitations();
foreach ($atts['membership_limitations'] as $limitation) {
if (!method_exists($membership, "get_$limitation")) {
if ( ! method_exists($membership, "get_$limitation")) {
continue;
} // end if;
}
$current_limit = $limits->{$limitation};
$limit_max = $current_limit->is_enabled() ? $current_limit->get_limit() : PHP_INT_MAX;
$limit_max = !empty($limit_max) ? (int) $limit_max : 1;
$limit_max = ! empty($limit_max) ? (int) $limit_max : 1;
$used_limit = $membership->{"get_$limitation"}();
@ -508,16 +487,13 @@ class Checkout_Element extends Base_Element {
$message .= '<span class="wu-styling">';
if (wu_multiple_memberships_enabled()) {
$register_page = wu_get_registration_url();
$button_text = __('Buy a new membership', 'wp-ultimo');
$message .= "<a class=\"wu-no-underline button button-primary wu-mr-2\" href=\"$register_page\">$button_text</a>";
} // end if;
}
if ($limitation !== 'sites' || wu_get_setting('enable_multiple_sites')) {
$update_link = '';
$checkout_pages = \WP_Ultimo\Checkout\Checkout_Pages::get_instance();
@ -525,30 +501,24 @@ class Checkout_Element extends Base_Element {
$update_url = $checkout_pages->get_page_url('update');
if ($update_url) {
$update_link = add_query_arg(array(
'membership' => $membership->get_hash(),
), $update_url);
$update_link = add_query_arg(
array(
'membership' => $membership->get_hash(),
),
$update_url
);
} elseif (is_admin()) {
$update_link = admin_url('admin.php?page=wu-checkout&membership=' . $membership->get_hash());
} elseif (isset($published_sites[0])) {
$update_link = get_admin_url($published_sites[0]->get_id(), 'admin.php?page=wu-checkout&membership=' . $membership->get_hash());
}
} // end if;
if (!empty($update_link)) {
if ( ! empty($update_link)) {
$button_text = __('Upgrade your account', 'wp-ultimo');
$message .= "<a class=\"wu-no-underline button button-primary wu-mr-2\" href=\"$update_link\">$button_text</a>";
} // end if;
} // end if;
}
}
$message .= '</span>';
@ -563,27 +533,18 @@ class Checkout_Element extends Base_Element {
* @param WP_Ultimo\Models\Customer $customer The active customer in use.
*/
return apply_filters('wu_checkout_membership_limit_message', $message, $limitation, $limit_max, $used_limit, $membership, $customer);
} // end if;
} // end foreach;
} // end if;
} elseif (!$customer && $slug === 'wu-finish-checkout') {
}
}
}
} elseif ( ! $customer && $slug === 'wu-finish-checkout') {
if (is_user_logged_in()) {
$message = __('You need to be the account owner to complete this payment.', 'wp-ultimo');
} else {
$message = __('You need to be logged in to complete a payment', 'wp-ultimo');
// Translators: The link to login url with redirect_to url
$message .= '<br>' . sprintf(__('Click <a href="%s">here</a> sign in.', 'wp-ultimo'), wp_login_url(wu_get_current_url()));
} // end if;
}
$message = '<p>' . $message . '</p>';
@ -593,42 +554,33 @@ class Checkout_Element extends Base_Element {
* @param string $message The HTML message to print in screen.
*/
return apply_filters('wu_checkout_payment_login_error_message', $message);
} // end if;
}
$checkout_form = wu_get_checkout_form_by_slug($slug);
if (!$checkout_form) {
if ( ! $checkout_form) {
// translators: %s is the id of the form. e.g. main-form
return sprintf(__('Checkout form %s not found.', 'wp-ultimo'), $slug);
} // end if;
}
if ($checkout_form->get_field_count() === 0) {
// translators: %s is the id of the form. e.g. main-form
return sprintf(__('Checkout form %s contains no fields.', 'wp-ultimo'), $slug);
}
if (!$checkout_form->is_active() || !wu_get_setting('enable_registration')) {
if ( ! $checkout_form->is_active() || ! wu_get_setting('enable_registration')) {
return sprintf('<p>%s</p>', __('Registration is not available at this time.', 'wp-ultimo'));
} // end if;
}
if ($checkout_form->has_country_lock()) {
$geolocation = \WP_Ultimo\Geolocation::geolocate_ip('', true);
if (!in_array($geolocation['country'], $checkout_form->get_allowed_countries(), true)) {
if ( ! in_array($geolocation['country'], $checkout_form->get_allowed_countries(), true)) {
return sprintf('<p>%s</p>', __('Registration is closed for your location.', 'wp-ultimo'));
} // end if;
} // end if;
}
}
$checkout = \WP_Ultimo\Checkout\Checkout::get_instance();
@ -640,10 +592,13 @@ class Checkout_Element extends Base_Element {
$this->step = $step ? $step : current($this->steps);
$this->step = wp_parse_args($this->step, array(
'classes' => '',
'fields' => array(),
));
$this->step = wp_parse_args(
$this->step,
array(
'classes' => '',
'fields' => array(),
)
);
$this->step_name = $this->step['id'] ?? '';
@ -656,11 +611,13 @@ class Checkout_Element extends Base_Element {
$this->signup = $signup;
add_action('wp_print_footer_scripts', function() use ($checkout_form) {
add_action(
'wp_print_footer_scripts',
function () use ($checkout_form) {
$this->print_custom_css($checkout_form);
});
$this->print_custom_css($checkout_form);
}
);
/*
* Load the checkout class with the parameters
@ -690,16 +647,18 @@ class Checkout_Element extends Base_Element {
$final_fields = apply_filters('wu_checkout_form_final_fields', $final_fields, $this);
return wu_get_template_contents('checkout/form', array(
'step' => $this->step,
'step_name' => $this->step_name,
'checkout_form_name' => $atts['slug'],
'errors' => $checkout->errors,
'display_title' => $atts['display_title'],
'final_fields' => $final_fields,
));
} // end output_form;
return wu_get_template_contents(
'checkout/form',
array(
'step' => $this->step,
'step_name' => $this->step_name,
'checkout_form_name' => $atts['slug'],
'errors' => $checkout->errors,
'display_title' => $atts['display_title'],
'final_fields' => $final_fields,
)
);
}
/**
* Injects the auto-submittable field inline snippet.
@ -711,30 +670,31 @@ class Checkout_Element extends Base_Element {
*/
public function inject_inline_auto_submittable_field($auto_submittable_field) {
$callback = function() use ($auto_submittable_field) {
$callback = function () use ($auto_submittable_field) {
wp_add_inline_script('wu-checkout', sprintf('
wp_add_inline_script(
'wu-checkout',
sprintf(
'
/**
* Set the auto-submittable field, if one exists.
*/
window.wu_auto_submittable_field = %s;
', json_encode($auto_submittable_field)), 'after');
',
json_encode($auto_submittable_field)
),
'after'
);
};
if (wu_is_block_theme() && !is_admin()) {
if (wu_is_block_theme() && ! is_admin()) {
add_action('wu_checkout_scripts', $callback, 100);
} else {
call_user_func($callback);
} // end if;
} // end inject_inline_auto_submittable_field;
}
}
/**
* The content to be output on the screen.
@ -752,66 +712,57 @@ class Checkout_Element extends Base_Element {
public function output($atts, $content = null) {
if (wu_is_update_page()) {
$atts = array(
'slug' => apply_filters('wu_membership_update_form', 'wu-checkout'),
'step' => false,
'display_title' => false,
);
} // end if;
}
if (wu_is_new_site_page()) {
$atts = array(
'slug' => apply_filters('wu_membership_new_site_form', 'wu-add-new-site'),
'step' => false,
'display_title' => false,
'membership_limitations' => array('sites'),
);
} // end if;
}
if ($this->is_thank_you_page()) {
return $this->output_thank_you($atts, $content);
} // end if;
}
/**
* Allow developers to add new update form slugs.
*
* @param array $slugs a list of form slugs to bypass.
*/
$update_forms = apply_filters('wu_membership_update_forms', array(
'wu-checkout',
));
if (!in_array($atts['slug'], $update_forms, true) && (wu_request('payment') || wu_request('payment_id'))) {
$update_forms = apply_filters(
'wu_membership_update_forms',
array(
'wu-checkout',
)
);
if ( ! in_array($atts['slug'], $update_forms, true) && (wu_request('payment') || wu_request('payment_id'))) {
$atts = array(
'slug' => 'wu-finish-checkout',
'step' => false,
'display_title' => false,
);
} // end if;
}
if (wu_request('wu_form') && in_array(wu_request('wu_form'), $update_forms, true)) {
$atts = array(
'slug' => wu_request('wu_form'),
'step' => false,
'display_title' => false,
);
} // end if;
}
return $this->output_form($atts, $content);
} // end output;
} // end class Checkout_Element;
}
}
/**
* Replacement of the old WU_Signup class for templates.
@ -820,14 +771,14 @@ class Checkout_Element extends Base_Element {
*/
class Mocked_Signup {
/**
* @var string
*/
public $step;
/**
* @var array
*/
public $steps;
/**
* @var string
*/
public $step;
/**
* @var array
*/
public $steps;
/**
* Constructs the class.
*
* @since 2.0.0
@ -835,11 +786,10 @@ class Mocked_Signup {
* @param string $step Current step.
* @param array $steps List of all steps.
*/
public function __construct($step, $steps)
{
$this->step = $step;
$this->steps = $steps;
} // end __construct;
public function __construct($step, $steps) {
$this->step = $step;
$this->steps = $steps;
}
/**
* Get the value of steps.
@ -850,8 +800,7 @@ class Mocked_Signup {
public function get_steps() {
return $this->steps;
} // end get_steps;
}
/**
* Deprecated: returns the prev step link.
*
@ -860,7 +809,5 @@ class Mocked_Signup {
public function get_prev_step_link(): string {
return '';
} // end get_prev_step_link;
} // end class Mocked_Signup;
}
}

View File

@ -9,8 +9,8 @@
namespace WP_Ultimo\UI;
use \WP_Ultimo\UI\Base_Element;
use \WP_Ultimo\Checkout\Cart;
use WP_Ultimo\UI\Base_Element;
use WP_Ultimo\Checkout\Cart;
// Exit if accessed directly
defined('ABSPATH') || exit;
@ -73,18 +73,23 @@ class Current_Membership_Element extends Base_Element {
parent::init();
wu_register_form('see_product_details', array(
'render' => array($this, 'render_product_details'),
'capability' => 'exist',
));
wu_register_form(
'see_product_details',
array(
'render' => array($this, 'render_product_details'),
'capability' => 'exist',
)
);
wu_register_form('edit_membership_product_modal', array(
'render' => array($this, 'render_edit_membership_product_modal'),
'handler' => array($this, 'handle_edit_membership_product_modal'),
'capability' => 'exist',
));
} // end init;
wu_register_form(
'edit_membership_product_modal',
array(
'render' => array($this, 'render_edit_membership_product_modal'),
'handler' => array($this, 'handle_edit_membership_product_modal'),
'capability' => 'exist',
)
);
}
/**
* Loads the required scripts.
@ -95,8 +100,7 @@ class Current_Membership_Element extends Base_Element {
public function register_scripts() {
add_wubox();
} // end register_scripts;
}
/**
* The icon of the UI element.
* e.g. return fa fa-search
@ -107,14 +111,11 @@ class Current_Membership_Element extends Base_Element {
public function get_icon($context = 'block'): string {
if ($context === 'elementor') {
return 'eicon-info-circle-o';
} // end if;
}
return 'fa fa-search';
} // end get_icon;
}
/**
* The title of the UI element.
@ -129,8 +130,7 @@ class Current_Membership_Element extends Base_Element {
public function get_title() {
return __('Membership', 'wp-ultimo');
} // end get_title;
}
/**
* The description of the UI element.
@ -146,8 +146,7 @@ class Current_Membership_Element extends Base_Element {
public function get_description() {
return __('Adds a checkout form block to the page.', 'wp-ultimo');
} // end get_description;
}
/**
* The list of fields to be added to Gutenberg.
@ -203,8 +202,7 @@ class Current_Membership_Element extends Base_Element {
);
return $fields;
} // end fields;
}
/**
* The list of keywords for this element.
@ -232,8 +230,7 @@ class Current_Membership_Element extends Base_Element {
'Form',
'Cart',
);
} // end keywords;
}
/**
* List of default parameters for the element.
@ -256,8 +253,7 @@ class Current_Membership_Element extends Base_Element {
'display_images' => 1,
'columns' => 2,
);
} // end defaults;
}
/**
* Runs early on the request lifecycle as soon as we detect the shortcode is present.
@ -269,17 +265,14 @@ class Current_Membership_Element extends Base_Element {
$this->membership = WP_Ultimo()->currents->get_membership();
if (!$this->membership) {
if ( ! $this->membership) {
$this->set_display(false);
return;
} // end if;
}
$this->plan = $this->membership ? $this->membership->get_plan() : false;
} // end setup;
}
/**
* Allows the setup in the context of previews.
@ -292,8 +285,7 @@ class Current_Membership_Element extends Base_Element {
$this->membership = wu_mock_membership();
$this->plan = wu_mock_product();
} // end setup_preview;
}
/**
* The content to be output on the screen.
@ -317,35 +309,33 @@ class Current_Membership_Element extends Base_Element {
$atts['pending_change'] = false;
if ($this->membership) {
$pending_swap_order = $this->membership->get_scheduled_swap();
$atts['pending_products'] = false;
if ($pending_swap_order) {
$atts['pending_change'] = $pending_swap_order->order->get_cart_descriptor();
$atts['pending_change_date'] = wu_date($pending_swap_order->scheduled_date)->format(get_option('date_format'));
$swap_membership = (clone $this->membership)->swap($pending_swap_order->order);
$pending_products = array_map(fn($product) => array(
'id' => $product['product']->get_id(),
'quantity' => $product['quantity'],
), $swap_membership->get_all_products());
$pending_products = array_map(
fn($product) => array(
'id' => $product['product']->get_id(),
'quantity' => $product['quantity'],
),
$swap_membership->get_all_products()
);
// add the id as key
$atts['pending_products'] = array_combine(array_column($pending_products, 'id'), $pending_products);
} // end if;
}
return wu_get_template_contents('dashboard-widgets/current-membership', $atts);
} // end if;
}
return '';
} // end output;
}
/**
* Renders the product details modal window.
@ -357,17 +347,14 @@ class Current_Membership_Element extends Base_Element {
$product = wu_get_product_by_slug(wu_request('product'));
if (!$product) {
if ( ! $product) {
return;
} // end if;
}
$atts['product'] = $product;
wu_get_template('dashboard-widgets/current-membership-product-details', $atts);
} // end render_product_details;
}
/**
* Renders the add/edit line items form.
@ -381,30 +368,23 @@ class Current_Membership_Element extends Base_Element {
$error = '';
if (!$membership) {
if ( ! $membership) {
$error = __('Membership not selected.', 'wp-ultimo');
} // end if;
}
$product = wu_get_product_by_slug(wu_request('product'));
if (!$product) {
if ( ! $product) {
$error = __('Product not selected.', 'wp-ultimo');
} // end if;
}
$customer = wu_get_current_customer();
if (empty($error) && !is_super_admin() && (!$customer || $customer->get_id() !== $membership->get_customer_id())) {
if (empty($error) && ! is_super_admin() && (! $customer || $customer->get_id() !== $membership->get_customer_id())) {
$error = __('You are not allowed to do this.', 'wp-ultimo');
}
} // end if;
if (!empty($error)) {
if ( ! empty($error)) {
$error_field = array(
'error_message' => array(
'type' => 'note',
@ -412,17 +392,20 @@ class Current_Membership_Element extends Base_Element {
),
);
$form = new \WP_Ultimo\UI\Form('cancel_payment_method', $error_field, array(
'views' => 'admin-pages/fields',
'classes' => 'wu-modal-form wu-widget-list wu-striped wu-m-0 wu-mt-0',
'field_wrapper_classes' => 'wu-w-full wu-box-border wu-items-center wu-flex wu-justify-between wu-p-4 wu-m-0 wu-border-t wu-border-l-0 wu-border-r-0 wu-border-b-0 wu-border-gray-300 wu-border-solid',
));
$form = new \WP_Ultimo\UI\Form(
'cancel_payment_method',
$error_field,
array(
'views' => 'admin-pages/fields',
'classes' => 'wu-modal-form wu-widget-list wu-striped wu-m-0 wu-mt-0',
'field_wrapper_classes' => 'wu-w-full wu-box-border wu-items-center wu-flex wu-justify-between wu-p-4 wu-m-0 wu-border-t wu-border-l-0 wu-border-r-0 wu-border-b-0 wu-border-gray-300 wu-border-solid',
)
);
$form->render();
return;
} // end if;
}
/**
* If there is a scheduled swap, we need to swap the membership before
@ -431,20 +414,16 @@ class Current_Membership_Element extends Base_Element {
$existing_swap = $membership->get_scheduled_swap();
if ($existing_swap) {
$membership = $membership->swap($existing_swap->order);
} // end if;
}
$gateway_message = false;
if (!empty($membership->get_gateway())) {
if ( ! empty($membership->get_gateway())) {
$gateway = wu_get_gateway($membership->get_gateway());
$gateway_message = $gateway ? $gateway->get_amount_update_message(true) : '';
} // end if;
}
$existing_quantity = array_filter($membership->get_addon_products(), fn($item) => $item['product']->get_id() === $product->get_id())[0]['quantity'];
@ -499,27 +478,30 @@ class Current_Membership_Element extends Base_Element {
),
);
if (!$gateway_message) {
if ( ! $gateway_message) {
unset($fields['update_note']);
}
} // end if;
$form = new \WP_Ultimo\UI\Form('edit_membership_product', $fields, array(
'views' => 'admin-pages/fields',
'classes' => 'wu-modal-form wu-widget-list wu-striped wu-m-0 wu-mt-0',
'field_wrapper_classes' => 'wu-w-full wu-box-border wu-items-center wu-flex wu-justify-between wu-p-4 wu-m-0 wu-border-t wu-border-l-0 wu-border-r-0 wu-border-b-0 wu-border-gray-300 wu-border-solid',
'html_attr' => array(
'data-wu-app' => 'edit_membership_product',
'data-state' => wu_convert_to_state(array(
'confirmed' => false,
)),
),
));
$form = new \WP_Ultimo\UI\Form(
'edit_membership_product',
$fields,
array(
'views' => 'admin-pages/fields',
'classes' => 'wu-modal-form wu-widget-list wu-striped wu-m-0 wu-mt-0',
'field_wrapper_classes' => 'wu-w-full wu-box-border wu-items-center wu-flex wu-justify-between wu-p-4 wu-m-0 wu-border-t wu-border-l-0 wu-border-r-0 wu-border-b-0 wu-border-gray-300 wu-border-solid',
'html_attr' => array(
'data-wu-app' => 'edit_membership_product',
'data-state' => wu_convert_to_state(
array(
'confirmed' => false,
)
),
),
)
);
$form->render();
} // end render_edit_membership_product_modal;
}
/**
* Handles the membership product remove.
@ -529,43 +511,35 @@ class Current_Membership_Element extends Base_Element {
*/
public function handle_edit_membership_product_modal() {
if (!wu_request('confirm')) {
if ( ! wu_request('confirm')) {
$error = new \WP_Error('not-confirmed', __('Please confirm the cancellation.', 'wp-ultimo'));
wp_send_json_error($error);
} // end if;
}
$membership = wu_get_membership_by_hash(wu_request('membership'));
if (!$membership) {
if ( ! $membership) {
$error = new \WP_Error('membership-not-found', __('Membership not found.', 'wp-ultimo'));
wp_send_json_error($error);
} // end if;
}
$product = wu_get_product_by_slug(wu_request('product'));
if (!$product) {
if ( ! $product) {
$error = new \WP_Error('product-not-found', __('Product not found.', 'wp-ultimo'));
wp_send_json_error($error);
} // end if;
}
$customer = wu_get_current_customer();
if (!is_super_admin() && (!$customer || $customer->get_id() !== $membership->get_customer_id())) {
if ( ! is_super_admin() && (! $customer || $customer->get_id() !== $membership->get_customer_id())) {
$error = __('You are not allowed to do this.', 'wp-ultimo');
wp_send_json_error($error);
} // end if;
}
// Get the existing quantity by filtering the products array.
$existing_quantity = array_filter($membership->get_addon_products(), fn($item) => $item['product']->get_id() === $product->get_id())[0]['quantity'];
@ -579,12 +553,10 @@ class Current_Membership_Element extends Base_Element {
$existing_swap = $membership->get_scheduled_swap();
if ($existing_swap) {
$membership = $membership->swap($existing_swap->order);
$existing_quantity = array_filter($membership->get_addon_products(), fn($item) => $item['product']->get_id() === $product->get_id())[0]['quantity'];
} // end if;
}
$quantity = (int) wu_request('quantity', 1);
$quantity = $quantity > $existing_quantity ? $existing_quantity : $quantity;
@ -594,20 +566,16 @@ class Current_Membership_Element extends Base_Element {
$value_to_remove = wu_get_membership_product_price($membership, $product->get_id(), $quantity);
if (is_wp_error($value_to_remove)) {
wp_send_json_error($value_to_remove);
} // end if;
}
$plan_price = wu_get_membership_product_price($membership, $membership->get_plan()->get_id(), 1);
// do not allow remove more than the plan price
if ($plan_price < $value_to_remove) {
$value_to_remove = $membership->get_amount() - $plan_price;
$value_to_remove = $value_to_remove < 0 ? 0 : $value_to_remove;
} // end if;
}
$membership->set_amount($membership->get_amount() - $value_to_remove);
@ -626,24 +594,20 @@ class Current_Membership_Element extends Base_Element {
// Lets schedule this change as the customer already paid for this period.
if (is_wp_error($schedule_swap)) {
wp_send_json_error($schedule_swap);
} // end if;
}
// Now we trigger the gateway update so the customer is charged for the new amount.
$gateway = wu_get_gateway($membership->get_gateway());
if ($gateway) {
$gateway->process_membership_update($membership, $customer);
}
} // end if;
wp_send_json_success(array(
'redirect_url' => add_query_arg('updated', 1, $_SERVER['HTTP_REFERER']),
));
} // end handle_edit_membership_product_modal;
} // end class Current_Membership_Element;
wp_send_json_success(
array(
'redirect_url' => add_query_arg('updated', 1, $_SERVER['HTTP_REFERER']),
)
);
}
}

View File

@ -63,23 +63,20 @@ class Current_Site_Element extends Base_Element {
public $membership;
/**
* The icon of the UI element.
* e.g. return fa fa-search
*
* @since 2.0.0
* @param string $context One of the values: block, elementor or bb.
*/
* The icon of the UI element.
* e.g. return fa fa-search
*
* @since 2.0.0
* @param string $context One of the values: block, elementor or bb.
*/
public function get_icon($context = 'block'): string {
if ($context === 'elementor') {
return 'eicon-info-circle-o';
} // end if;
}
return 'fa fa-search';
} // end get_icon;
}
/**
* Overload the init to add site-related forms.
@ -91,13 +88,15 @@ class Current_Site_Element extends Base_Element {
parent::init();
wu_register_form('edit_site', array(
'render' => array($this, 'render_edit_site'),
'handler' => array($this, 'handle_edit_site'),
'capability' => 'exist',
));
} // end init;
wu_register_form(
'edit_site',
array(
'render' => array($this, 'render_edit_site'),
'handler' => array($this, 'handle_edit_site'),
'capability' => 'exist',
)
);
}
/**
* The title of the UI element.
@ -112,8 +111,7 @@ class Current_Site_Element extends Base_Element {
public function get_title() {
return __('Site', 'wp-ultimo');
} // end get_title;
}
/**
* The description of the UI element.
@ -129,8 +127,7 @@ class Current_Site_Element extends Base_Element {
public function get_description() {
return __('Adds a block to display the current site being managed.', 'wp-ultimo');
} // end get_description;
}
/**
* The list of fields to be added to Gutenberg.
@ -167,19 +164,19 @@ class Current_Site_Element extends Base_Element {
'value' => 1,
);
$pages = get_pages(array(
'exclude' => array(get_the_ID()),
));
$pages = get_pages(
array(
'exclude' => array(get_the_ID()),
)
);
$pages = $pages ? $pages : array();
$pages_list = array(0 => __('Current Page', 'wp-ultimo'));
foreach ($pages as $page) {
$pages_list[$page->ID] = $page->post_title;
} // end foreach;
$pages_list[ $page->ID ] = $page->post_title;
}
$fields['breadcrumbs_my_sites_page'] = array(
'type' => 'select',
@ -242,8 +239,7 @@ class Current_Site_Element extends Base_Element {
);
return $fields;
} // end fields;
}
/**
* The list of keywords for this element.
@ -271,8 +267,7 @@ class Current_Site_Element extends Base_Element {
'Form',
'Cart',
);
} // end keywords;
}
/**
* List of default parameters for the element.
@ -299,8 +294,7 @@ class Current_Site_Element extends Base_Element {
'breadcrumbs_my_sites_page' => 0,
'show_admin_link' => 1,
);
} // end defaults;
}
/**
* Runs early on the request lifecycle as soon as we detect the shortcode is present.
@ -312,17 +306,14 @@ class Current_Site_Element extends Base_Element {
$this->site = WP_Ultimo()->currents->get_site();
if (!$this->site || !$this->site->is_customer_allowed()) {
if ( ! $this->site || ! $this->site->is_customer_allowed()) {
$this->set_display(false);
return;
} // end if;
}
$this->membership = $this->site->get_membership();
} // end setup;
}
/**
* Allows the setup in the context of previews.
@ -335,8 +326,7 @@ class Current_Site_Element extends Base_Element {
$this->site = wu_mock_site();
$this->membership = wu_mock_membership();
} // end setup_preview;
}
/**
* Loads the required scripts.
@ -347,8 +337,7 @@ class Current_Site_Element extends Base_Element {
public function register_scripts() {
add_wubox();
} // end register_scripts;
}
/**
* The content to be output on the screen.
@ -376,22 +365,23 @@ class Current_Site_Element extends Base_Element {
'label' => __('Edit Site', 'wp-ultimo'),
'icon_classes' => 'dashicons-wu-edit wu-align-text-bottom',
'classes' => 'wubox',
'href' => wu_get_form_url('edit_site', array(
'site' => $this->site->get_hash(),
)),
'href' => wu_get_form_url(
'edit_site',
array(
'site' => $this->site->get_hash(),
)
),
),
);
if ($atts['show_admin_link']) {
$actions['site_admin'] = array(
'label' => __('Admin Panel', 'wp-ultimo'),
'icon_classes' => 'dashicons-wu-grid wu-align-text-bottom',
'classes' => '',
'href' => get_admin_url($this->site->get_id()),
);
} // end if;
}
$atts['actions'] = apply_filters('wu_current_site_actions', $actions, $this->site);
@ -404,8 +394,7 @@ class Current_Site_Element extends Base_Element {
$atts['my_sites_url'] = is_admin() ? admin_url('admin.php?page=sites') : $my_sites_url;
return wu_get_template_contents('dashboard-widgets/current-site', $atts);
} // end output;
}
/**
* Renders the edit site modal.
@ -417,11 +406,9 @@ class Current_Site_Element extends Base_Element {
$site = wu_get_site_by_hash(wu_request('site'));
if (!$site) {
if ( ! $site) {
return '';
} // end if;
}
$fields = array(
'site_title' => array(
@ -460,21 +447,26 @@ class Current_Site_Element extends Base_Element {
$fields = apply_filters('wu_form_edit_site', $fields, $this);
$form = new \WP_Ultimo\UI\Form('edit_site', $fields, array(
'views' => 'admin-pages/fields',
'classes' => 'wu-modal-form wu-widget-list wu-striped wu-m-0 wu-mt-0',
'field_wrapper_classes' => 'wu-w-full wu-box-border wu-items-center wu-flex wu-justify-between wu-p-4 wu-m-0 wu-border-t wu-border-l-0 wu-border-r-0 wu-border-b-0 wu-border-gray-300 wu-border-solid',
'html_attr' => array(
'data-wu-app' => 'edit_site',
'data-state' => wu_convert_to_state(array(
'site_title' => $site->get_title(),
)),
),
));
$form = new \WP_Ultimo\UI\Form(
'edit_site',
$fields,
array(
'views' => 'admin-pages/fields',
'classes' => 'wu-modal-form wu-widget-list wu-striped wu-m-0 wu-mt-0',
'field_wrapper_classes' => 'wu-w-full wu-box-border wu-items-center wu-flex wu-justify-between wu-p-4 wu-m-0 wu-border-t wu-border-l-0 wu-border-r-0 wu-border-b-0 wu-border-gray-300 wu-border-solid',
'html_attr' => array(
'data-wu-app' => 'edit_site',
'data-state' => wu_convert_to_state(
array(
'site_title' => $site->get_title(),
)
),
),
)
);
$form->render();
} // end render_edit_site;
}
/**
* Handles the password reset form.
@ -486,32 +478,28 @@ class Current_Site_Element extends Base_Element {
$site = wu_get_site_by_hash(wu_request('site'));
if (!$site) {
if ( ! $site) {
$error = new \WP_Error('site-dont-exist', __('Something went wrong.', 'wp-ultimo'));
wp_send_json_error($error);
} // end if;
}
$new_title = wu_request('site_title');
if (!$new_title) {
if ( ! $new_title) {
$error = new \WP_Error('title_empty', __('Site title can not be empty.', 'wp-ultimo'));
wp_send_json_error($error);
} // end if;
}
$status = update_blog_option($site->get_id(), 'blogname', $new_title);
$status_desc = update_blog_option($site->get_id(), 'blogdescription', wu_request('site_description'));
wp_send_json_success(array(
'redirect_url' => add_query_arg('updated', (int) $status, $_SERVER['HTTP_REFERER']),
));
} // end handle_edit_site;
} // end class Current_Site_Element;
wp_send_json_success(
array(
'redirect_url' => add_query_arg('updated', (int) $status, $_SERVER['HTTP_REFERER']),
)
);
}
}

View File

@ -9,11 +9,11 @@
namespace WP_Ultimo\UI;
use \WP_Ultimo\UI\Base_Element;
use \WP_Ultimo\Models\Domain;
use \WP_Ultimo\Database\Domains\Domain_Stage;
use \WP_Ultimo\Models\Site;
use \WP_Ultimo\Models\Membership;
use WP_Ultimo\UI\Base_Element;
use WP_Ultimo\Models\Domain;
use WP_Ultimo\Database\Domains\Domain_Stage;
use WP_Ultimo\Models\Site;
use WP_Ultimo\Models\Membership;
// Exit if accessed directly
defined('ABSPATH') || exit;
@ -67,23 +67,20 @@ class Domain_Mapping_Element extends Base_Element {
protected $membership;
/**
* The icon of the UI element.
* e.g. return fa fa-search
*
* @since 2.0.0
* @param string $context One of the values: block, elementor or bb.
*/
* The icon of the UI element.
* e.g. return fa fa-search
*
* @since 2.0.0
* @param string $context One of the values: block, elementor or bb.
*/
public function get_icon($context = 'block'): string {
if ($context === 'elementor') {
return 'eicon-url';
} // end if;
}
return 'fa fa-search';
} // end get_icon;
}
/**
* The title of the UI element.
@ -98,8 +95,7 @@ class Domain_Mapping_Element extends Base_Element {
public function get_title() {
return __('Domains', 'wp-ultimo');
} // end get_title;
}
/**
* The description of the UI element.
@ -115,8 +111,7 @@ class Domain_Mapping_Element extends Base_Element {
public function get_description() {
return __('Adds the site\'s domains block.', 'wp-ultimo');
} // end get_description;
}
/**
* The list of fields to be added to Gutenberg.
@ -154,8 +149,7 @@ class Domain_Mapping_Element extends Base_Element {
);
return $fields;
} // end fields;
}
/**
* The list of keywords for this element.
@ -181,8 +175,7 @@ class Domain_Mapping_Element extends Base_Element {
'WP Multisite WaaS',
'Domain',
);
} // end keywords;
}
/**
* List of default parameters for the element.
@ -203,8 +196,7 @@ class Domain_Mapping_Element extends Base_Element {
return array(
'title' => __('Domains', 'wp-ultimo'),
);
} // end defaults;
}
/**
* Initializes the singleton.
@ -217,32 +209,25 @@ class Domain_Mapping_Element extends Base_Element {
parent::init();
if ($this->is_preview()) {
$this->site = wu_mock_site();
return;
} // end if;
}
$this->site = wu_get_current_site();
$maybe_limit_domain_mapping = true;
if ($this->site->has_limitations()) {
$maybe_limit_domain_mapping = $this->site->get_limitations()->domain_mapping->is_enabled();
}
} // end if;
if (!$this->site || !wu_get_setting('enable_domain_mapping') || !wu_get_setting('custom_domains') || !$maybe_limit_domain_mapping) {
if ( ! $this->site || ! wu_get_setting('enable_domain_mapping') || ! wu_get_setting('custom_domains') || ! $maybe_limit_domain_mapping) {
$this->set_display(false);
} // end if;
}
add_action('plugins_loaded', array($this, 'register_forms'));
} // end init;
}
/**
* Loads the required scripts.
@ -253,8 +238,7 @@ class Domain_Mapping_Element extends Base_Element {
public function register_scripts() {
add_wubox();
} // end register_scripts;
}
/**
* Register ajax forms used to add a new domain.
@ -266,25 +250,33 @@ class Domain_Mapping_Element extends Base_Element {
/*
* Add new Domain
*/
wu_register_form('user_add_new_domain', array(
'render' => array($this, 'render_user_add_new_domain_modal'),
'handler' => array($this, 'handle_user_add_new_domain_modal'),
'capability' => 'exist',
));
wu_register_form(
'user_add_new_domain',
array(
'render' => array($this, 'render_user_add_new_domain_modal'),
'handler' => array($this, 'handle_user_add_new_domain_modal'),
'capability' => 'exist',
)
);
wu_register_form('user_make_domain_primary', array(
'render' => array($this, 'render_user_make_domain_primary_modal'),
'handler' => array($this, 'handle_user_make_domain_primary_modal'),
'capability' => 'exist',
));
wu_register_form(
'user_make_domain_primary',
array(
'render' => array($this, 'render_user_make_domain_primary_modal'),
'handler' => array($this, 'handle_user_make_domain_primary_modal'),
'capability' => 'exist',
)
);
wu_register_form('user_delete_domain_modal', array(
'render' => array($this, 'render_user_delete_domain_modal'),
'handler' => array($this, 'handle_user_delete_domain_modal'),
'capability' => 'exist',
));
} // end register_forms;
wu_register_form(
'user_delete_domain_modal',
array(
'render' => array($this, 'render_user_delete_domain_modal'),
'handler' => array($this, 'handle_user_delete_domain_modal'),
'capability' => 'exist',
)
);
}
/**
* Renders the add new customer modal.
@ -313,7 +305,7 @@ class Domain_Mapping_Element extends Base_Element {
'display_value' => sprintf('<div class="wu--mt-2 wu--mb-2">%s</div>', wpautop($instructions)),
'wrapper_html_attr' => array(
'v-show' => '!ready',
'v-cloak' => 1
'v-cloak' => 1,
),
),
'ready' => array(
@ -327,7 +319,7 @@ class Domain_Mapping_Element extends Base_Element {
),
'wrapper_html_attr' => array(
'v-show' => '!ready',
'v-cloak' => 1
'v-cloak' => 1,
),
),
'current_site' => array(
@ -340,7 +332,7 @@ class Domain_Mapping_Element extends Base_Element {
'placeholder' => __('mydomain.com', 'wp-ultimo'),
'wrapper_html_attr' => array(
'v-show' => 'ready',
'v-cloak' => 1
'v-cloak' => 1,
),
),
'primary_domain' => array(
@ -371,27 +363,32 @@ class Domain_Mapping_Element extends Base_Element {
'wrapper_classes' => 'wu-items-end',
'wrapper_html_attr' => array(
'v-show' => 'ready',
'v-cloak' => 1
'v-cloak' => 1,
),
),
);
$form = new \WP_Ultimo\UI\Form('add_new_domain', $fields, array(
'views' => 'admin-pages/fields',
'classes' => 'wu-modal-form wu-widget-list wu-striped wu-m-0 wu-mt-0',
'field_wrapper_classes' => 'wu-w-full wu-box-border wu-items-center wu-flex wu-justify-between wu-p-4 wu-m-0 wu-border-t wu-border-l-0 wu-border-r-0 wu-border-b-0 wu-border-gray-300 wu-border-solid',
'html_attr' => array(
'data-wu-app' => 'add_new_domain',
'data-state' => json_encode(array(
'ready' => 0,
'primary_domain' => false,
)),
),
));
$form = new \WP_Ultimo\UI\Form(
'add_new_domain',
$fields,
array(
'views' => 'admin-pages/fields',
'classes' => 'wu-modal-form wu-widget-list wu-striped wu-m-0 wu-mt-0',
'field_wrapper_classes' => 'wu-w-full wu-box-border wu-items-center wu-flex wu-justify-between wu-p-4 wu-m-0 wu-border-t wu-border-l-0 wu-border-r-0 wu-border-b-0 wu-border-gray-300 wu-border-solid',
'html_attr' => array(
'data-wu-app' => 'add_new_domain',
'data-state' => json_encode(
array(
'ready' => 0,
'primary_domain' => false,
)
),
),
)
);
$form->render();
} // end render_user_add_new_domain_modal;
}
/**
* Handles creation of a new customer.
@ -407,46 +404,44 @@ class Domain_Mapping_Element extends Base_Element {
$current_site = wu_get_site($current_site_id);
if (!is_super_admin() && (!$current_site || $current_user_id !== $current_site->get_customer()->get_user_id())) {
if ( ! is_super_admin() && (! $current_site || $current_user_id !== $current_site->get_customer()->get_user_id())) {
wp_send_json_error(
new \WP_Error('no-permissions', __('You do not have permissions to perform this action.', 'wp-ultimo'))
);
exit;
} // end if;
}
/*
* Tries to create the domain
*/
$domain = wu_create_domain(array(
'domain' => wu_request('domain'),
'blog_id' => absint($current_site_id),
'primary_domain' => (bool) wu_request('primary_domain'),
));
$domain = wu_create_domain(
array(
'domain' => wu_request('domain'),
'blog_id' => absint($current_site_id),
'primary_domain' => (bool) wu_request('primary_domain'),
)
);
if (is_wp_error($domain)) {
wp_send_json_error($domain);
} // end if;
}
if (wu_request('primary_domain')) {
$old_primary_domains = wu_get_domains(array(
'primary_domain' => true,
'blog_id' => $current_site_id,
'id__not_in' => array($domain->get_id()),
'fields' => 'ids',
));
$old_primary_domains = wu_get_domains(
array(
'primary_domain' => true,
'blog_id' => $current_site_id,
'id__not_in' => array($domain->get_id()),
'fields' => 'ids',
)
);
/*
* Trigger async action to update the old primary domains.
*/
do_action_ref_array('wu_async_remove_old_primary_domains', array($old_primary_domains));
} // end if;
}
wu_enqueue_async_action('wu_async_process_domain_stage', array('domain_id' => $domain->get_id()), 'domain');
@ -455,13 +450,14 @@ class Domain_Mapping_Element extends Base_Element {
*/
do_action('wu_domain_created', $domain, $domain->get_site(), $domain->get_site()->get_membership());
wp_send_json_success(array(
'redirect_url' => wu_get_current_url(),
));
wp_send_json_success(
array(
'redirect_url' => wu_get_current_url(),
)
);
exit;
} // end handle_user_add_new_domain_modal;
}
/**
* Renders the domain delete action.
@ -497,21 +493,26 @@ class Domain_Mapping_Element extends Base_Element {
),
);
$form = new \WP_Ultimo\UI\Form('user_delete_domain_modal', $fields, array(
'views' => 'admin-pages/fields',
'classes' => 'wu-modal-form wu-widget-list wu-striped wu-m-0 wu-mt-0',
'field_wrapper_classes' => 'wu-w-full wu-box-border wu-items-center wu-flex wu-justify-between wu-p-4 wu-m-0 wu-border-t wu-border-l-0 wu-border-r-0 wu-border-b-0 wu-border-gray-300 wu-border-solid',
'html_attr' => array(
'data-wu-app' => 'user_delete_domain_modal',
'data-state' => json_encode(array(
'confirmed' => false,
)),
),
));
$form = new \WP_Ultimo\UI\Form(
'user_delete_domain_modal',
$fields,
array(
'views' => 'admin-pages/fields',
'classes' => 'wu-modal-form wu-widget-list wu-striped wu-m-0 wu-mt-0',
'field_wrapper_classes' => 'wu-w-full wu-box-border wu-items-center wu-flex wu-justify-between wu-p-4 wu-m-0 wu-border-t wu-border-l-0 wu-border-r-0 wu-border-b-0 wu-border-gray-300 wu-border-solid',
'html_attr' => array(
'data-wu-app' => 'user_delete_domain_modal',
'data-state' => json_encode(
array(
'confirmed' => false,
)
),
),
)
);
$form->render();
} // end render_user_delete_domain_modal;
}
/**
* Handles deletion of the selected domain
@ -522,10 +523,8 @@ class Domain_Mapping_Element extends Base_Element {
public function handle_user_delete_domain_modal() {
if (wu_request('user_id')) {
$customer = wu_get_customer_by_user_id(wu_request('user_id'));
} // end if;
}
$current_site = wu_request('current_site');
@ -534,16 +533,15 @@ class Domain_Mapping_Element extends Base_Element {
$domain = new Domain($get_domain);
if ($domain) {
$domain->delete();
}
} // end if;
wp_send_json_success(array(
'redirect_url' => wu_get_current_url(),
));
} // end handle_user_delete_domain_modal;
wp_send_json_success(
array(
'redirect_url' => wu_get_current_url(),
)
);
}
/**
* Renders the domain delete action.
@ -579,21 +577,26 @@ class Domain_Mapping_Element extends Base_Element {
),
);
$form = new \WP_Ultimo\UI\Form('user_delete_domain_modal', $fields, array(
'views' => 'admin-pages/fields',
'classes' => 'wu-modal-form wu-widget-list wu-striped wu-m-0 wu-mt-0',
'field_wrapper_classes' => 'wu-w-full wu-box-border wu-items-center wu-flex wu-justify-between wu-p-4 wu-m-0 wu-border-t wu-border-l-0 wu-border-r-0 wu-border-b-0 wu-border-gray-300 wu-border-solid',
'html_attr' => array(
'data-wu-app' => 'user_delete_domain_modal',
'data-state' => json_encode(array(
'confirmed' => false,
)),
),
));
$form = new \WP_Ultimo\UI\Form(
'user_delete_domain_modal',
$fields,
array(
'views' => 'admin-pages/fields',
'classes' => 'wu-modal-form wu-widget-list wu-striped wu-m-0 wu-mt-0',
'field_wrapper_classes' => 'wu-w-full wu-box-border wu-items-center wu-flex wu-justify-between wu-p-4 wu-m-0 wu-border-t wu-border-l-0 wu-border-r-0 wu-border-b-0 wu-border-gray-300 wu-border-solid',
'html_attr' => array(
'data-wu-app' => 'user_delete_domain_modal',
'data-state' => json_encode(
array(
'confirmed' => false,
)
),
),
)
);
$form->render();
} // end render_user_make_domain_primary_modal;
}
/**
* Handles conversion to primary domain.
@ -610,38 +613,37 @@ class Domain_Mapping_Element extends Base_Element {
$domain = wu_get_domain($domain_id);
if ($domain) {
$domain->set_primary_domain(true);
$status = $domain->save();
if (is_wp_error($status)) {
wp_send_json_error($status);
}
} // end if;
$old_primary_domains = wu_get_domains(array(
'primary_domain' => true,
'blog_id' => $domain->get_blog_id(),
'id__not_in' => array($domain->get_id()),
'fields' => 'ids',
));
$old_primary_domains = wu_get_domains(
array(
'primary_domain' => true,
'blog_id' => $domain->get_blog_id(),
'id__not_in' => array($domain->get_id()),
'fields' => 'ids',
)
);
/*
* Trigger async action to update the old primary domains.
*/
do_action_ref_array('wu_async_remove_old_primary_domains', array($old_primary_domains));
wp_send_json_success(array(
'redirect_url' => is_main_site() ? wu_get_current_url() : get_admin_url($current_site),
));
} // end if;
wp_send_json_success(
array(
'redirect_url' => is_main_site() ? wu_get_current_url() : get_admin_url($current_site),
)
);
}
wp_send_json_error(new \WP_Error('error', __('Something wrong happenned.', 'wp-ultimo')));
} // end handle_user_make_domain_primary_modal;
}
/**
* Runs early on the request lifecycle as soon as we detect the shortcode is present.
@ -653,20 +655,17 @@ class Domain_Mapping_Element extends Base_Element {
$this->site = WP_Ultimo()->currents->get_site();
if (!$this->site || !$this->site->is_customer_allowed()) {
if ( ! $this->site || ! $this->site->is_customer_allowed()) {
$this->set_display(false);
return;
} // end if;
}
// Ensure admin.php is loaded as we need wu_responsive_table_row function
require_once wu_path('inc/functions/admin.php');
$this->membership = $this->site->get_membership();
} // end setup;
}
/**
* Allows the setup in the context of previews.
@ -679,8 +678,7 @@ class Domain_Mapping_Element extends Base_Element {
$this->site = wu_mock_site();
$this->membership = wu_mock_membership();
} // end setup_preview;
}
/**
* The content to be output on the screen.
@ -699,16 +697,17 @@ class Domain_Mapping_Element extends Base_Element {
$current_site = $this->site;
$all_domains = wu_get_domains(array(
'blog_id' => $current_site->get_id(),
'orderby' => 'primary_domain',
'order' => 'DESC',
));
$all_domains = wu_get_domains(
array(
'blog_id' => $current_site->get_id(),
'orderby' => 'primary_domain',
'order' => 'DESC',
)
);
$domains = array();
foreach ($all_domains as $key => $domain) {
$stage = new Domain_Stage($domain->get_stage());
$secure = 'dashicons-wu-lock-open';
@ -716,12 +715,10 @@ class Domain_Mapping_Element extends Base_Element {
$secure_message = __('Domain not secured with HTTPS', 'wp-ultimo');
if ($domain->is_secure()) {
$secure = 'dashicons-wu-lock wu-text-green-500';
$secure_message = __('Domain secured with HTTPS', 'wp-ultimo');
} // end if;
}
$url_atts = array(
'current_site' => $current_site->get_id(),
@ -731,7 +728,7 @@ class Domain_Mapping_Element extends Base_Element {
$delete_url = wu_get_form_url('user_delete_domain_modal', $url_atts);
$primary_url = wu_get_form_url('user_make_domain_primary', $url_atts);
$domains[$key] = array(
$domains[ $key ] = array(
'id' => $domain->get_id(),
'domain_object' => $domain,
'domain' => $domain->get_domain(),
@ -742,9 +739,8 @@ class Domain_Mapping_Element extends Base_Element {
'secure_message' => $secure_message,
'delete_link' => $delete_url,
'primary_link' => $primary_url,
);
} // end foreach;
);
}
$url_atts = array(
'current_site' => $current_site->get_ID(),
@ -763,7 +759,5 @@ class Domain_Mapping_Element extends Base_Element {
$atts = array_merge($other_atts, $atts);
return wu_get_template_contents('dashboard-widgets/domain-mapping', $atts);
} // end output;
} // end class Domain_Mapping_Element;
}
}

View File

@ -46,8 +46,7 @@ class Field implements \JsonSerializable {
public function __construct($id, $atts) {
$this->set_attributes($id, $atts);
} // end __construct;
}
/**
* Set and the attributes passed via the constructor.
@ -60,57 +59,59 @@ class Field implements \JsonSerializable {
*/
public function set_attributes($id, $atts) {
$this->atts = wp_parse_args($atts, array(
'id' => $id,
'type' => 'text',
'icon' => 'dashicons-wu-cog',
'action' => false,
'form' => false,
'title' => false,
'img' => false,
'desc' => false,
'content' => false,
'display_value' => false,
'default_value' => false,
'tooltip' => false,
'args' => false,
'sortable' => false,
'placeholder' => false,
'options' => false,
'options_template' => false,
'require' => false,
'button' => false,
'width' => false,
'rules' => false,
'min' => false,
'max' => false,
'allow_html' => false,
'append' => false,
'order' => false,
'dummy' => false,
'disabled' => false,
'capability' => false,
'edit' => false,
'copy' => false,
'validation' => false,
'meter' => false,
'href' => false,
'raw' => false,
'money' => false,
'stacked' => false, // If the field is inside a restricted container
'columns' => 1,
'classes' => '',
'wrapper_classes' => '',
'html_attr' => array(),
'wrapper_html_attr' => array(),
'sub_fields' => array(),
'prefix' => '',
'suffix' => '',
'prefix_html_attr' => array(),
'suffix_html_attr' => array(),
));
} // end set_attributes;
$this->atts = wp_parse_args(
$atts,
array(
'id' => $id,
'type' => 'text',
'icon' => 'dashicons-wu-cog',
'action' => false,
'form' => false,
'title' => false,
'img' => false,
'desc' => false,
'content' => false,
'display_value' => false,
'default_value' => false,
'tooltip' => false,
'args' => false,
'sortable' => false,
'placeholder' => false,
'options' => false,
'options_template' => false,
'require' => false,
'button' => false,
'width' => false,
'rules' => false,
'min' => false,
'max' => false,
'allow_html' => false,
'append' => false,
'order' => false,
'dummy' => false,
'disabled' => false,
'capability' => false,
'edit' => false,
'copy' => false,
'validation' => false,
'meter' => false,
'href' => false,
'raw' => false,
'money' => false,
'stacked' => false, // If the field is inside a restricted container
'columns' => 1,
'classes' => '',
'wrapper_classes' => '',
'html_attr' => array(),
'wrapper_html_attr' => array(),
'sub_fields' => array(),
'prefix' => '',
'suffix' => '',
'prefix_html_attr' => array(),
'suffix_html_attr' => array(),
)
);
}
/**
* Set a particular attribute.
@ -123,9 +124,8 @@ class Field implements \JsonSerializable {
*/
public function set_attribute($att, $value) {
$this->atts[$att] = $value;
} // end set_attribute;
$this->atts[ $att ] = $value;
}
/**
* Returns the list of field attributes.
@ -136,8 +136,7 @@ class Field implements \JsonSerializable {
public function get_attributes() {
return $this->atts;
} // end get_attributes;
}
/**
* Makes sure old fields remain compatible.
@ -168,33 +167,27 @@ class Field implements \JsonSerializable {
);
if (array_key_exists($this->type, $aliases)) {
$new_type_name = $aliases[$this->type];
$new_type_name = $aliases[ $this->type ];
if (array_key_exists($this->type, $deprecated)) {
// translators: The %1$s placeholder is the old type name, the second, the new type name.
_doing_it_wrong('wu_add_field', sprintf(__('The field type "%1$s" is no longer supported, use "%2$s" instead.'), $this->type, $new_type_name), '2.0.0');
} // end if;
}
/*
* Back Compat for Select2 Fields
*/
if ($this->type === 'select2') {
$this->atts['html_attr']['data-selectize'] = 1;
$this->atts['html_attr']['multiple'] = 1;
} // end if;
}
return $new_type_name;
} // end if;
}
return false;
} // end get_compat_template_name;
}
/**
* Returns the template name for a field.
@ -214,8 +207,7 @@ class Field implements \JsonSerializable {
$view_name = $compat_name ? $compat_name : $this->type;
return str_replace('_', '-', (string) $view_name);
} // end get_template_name;
}
/**
* Returns attributes as class properties.
@ -242,56 +234,41 @@ class Field implements \JsonSerializable {
'img',
);
$attr = isset($this->atts[$att]) ? $this->atts[$att] : false;
$attr = isset($this->atts[ $att ]) ? $this->atts[ $att ] : false;
$allow_callable_prefix = is_string($attr) && strncmp($attr, 'wu_get_', strlen('wu_get_')) === 0 && is_callable($attr);
$allow_callable_method = is_array($attr) && is_callable($attr);
if (in_array($att, $allowed_callable, true) && ($allow_callable_prefix || $allow_callable_method || is_a($attr, \Closure::class))) {
$attr = call_user_func($attr, $this);
} // end if;
}
if ($att === 'wrapper_classes' && isset($this->atts['wrapper_html_attr']['v-show'])) {
$this->atts['wrapper_classes'] = $this->atts['wrapper_classes'] . ' wu-requires-other';
}
} // end if;
if ($att === 'type' && $this->atts[$att] === 'submit') {
if ($att === 'type' && $this->atts[ $att ] === 'submit') {
$this->atts['wrapper_classes'] = $this->atts['wrapper_classes'] . ' wu-submit-field';
}
} // end if;
if ($att === 'type' && $this->atts[$att] === 'tab-select') {
if ($att === 'type' && $this->atts[ $att ] === 'tab-select') {
$this->atts['wrapper_classes'] = $this->atts['wrapper_classes'] . ' wu-tab-field';
} // end if;
}
if ($att === 'wrapper_classes' && is_a($this->form, '\\WP_Ultimo\\UI\\Form')) {
return $this->form->field_wrapper_classes . ' ' . $this->atts['wrapper_classes'];
} // end if;
}
if ($att === 'classes' && is_a($this->form, '\\WP_Ultimo\\UI\\Form')) {
return $this->form->field_classes . ' ' . $this->atts['classes'];
} // end if;
}
if ($att === 'title' && $attr === false && isset($this->atts['name'])) {
$attr = $this->atts['name'];
} // end if;
}
return $attr;
} // end __get;
}
/**
* Returns the list of sanitization callbacks for each field type
@ -314,8 +291,7 @@ class Field implements \JsonSerializable {
);
return apply_filters('wu_settings_fields_sanitization_rules', $rules);
} // end sanitization_rules;
}
/**
* Returns the value of the setting represented by this field.
@ -326,8 +302,7 @@ class Field implements \JsonSerializable {
public function get_value() {
return $this->value;
} // end get_value;
}
/**
* Sets the value of the settings represented by this field.
@ -344,15 +319,12 @@ class Field implements \JsonSerializable {
$this->value = $value;
if (!$this->raw) {
if ( ! $this->raw) {
$this->sanitize();
} // end if;
}
return $this;
} // end set_value;
}
/**
* Runs the value of the field through the sanitization callback.
@ -364,45 +336,37 @@ class Field implements \JsonSerializable {
$rules = $this->sanitization_rules();
$sanitize_method = isset($rules[$this->type]) ? $rules[$this->type] : $rules['text'];
$sanitize_method = isset($rules[ $this->type ]) ? $rules[ $this->type ] : $rules['text'];
if ($sanitize_method) {
$this->value = call_user_func($sanitize_method, $this->value);
} // end if;
} // end sanitize;
/**
* Sanitization callback for fields of type number.
*
* Checks if the new value set is between the min and max boundaries.
*
* @since 2.0.0
*
* @param int|float $value Value of the settings being represented by this field.
* @return int|float
*/
protected function validate_number_field($value) {
}
}
/**
* Sanitization callback for fields of type number.
*
* Checks if the new value set is between the min and max boundaries.
*
* @since 2.0.0
*
* @param int|float $value Value of the settings being represented by this field.
* @return int|float
*/
protected function validate_number_field($value) {
/**
* Check if the value respects the min/max values.
*/
if ($this->min && $value < $this->min) {
return $this->min;
} // end if;
}
if ($this->max && $value > $this->max) {
return $this->max;
} // end if;
}
return $value;
} // end validate_number_field;
}
/**
* Cleans the value submitted via a textarea or wp_editor field for database insertion.
@ -415,14 +379,11 @@ class Field implements \JsonSerializable {
protected function validate_textarea_field($value) {
if ($this->allow_html) {
return stripslashes(wp_filter_post_kses(addslashes($value)));
} // end if;
}
return wp_strip_all_tags(stripslashes($value));
} // end validate_textarea_field;
}
/**
* Return HTML attributes for the field.
@ -433,43 +394,32 @@ class Field implements \JsonSerializable {
public function get_html_attributes() {
if (is_callable($this->atts['html_attr'])) {
$this->atts['html_attr'] = call_user_func($this->atts['html_attr']);
} // end if;
}
$attributes = $this->atts['html_attr'];
unset($this->atts['html_attr']['class']);
if ($this->type === 'number') {
if ($this->min !== false) {
$attributes['min'] = $this->min;
} // end if;
}
if ($this->max !== false) {
$attributes['max'] = $this->max;
} // end if;
} // end if;
}
}
/*
* Adds money formatting and masking
*/
if ($this->money !== false) {
$attributes['v-bind'] = 'money_settings';
} // end if;
}
return wu_array_to_html_attrs($attributes);
} // end get_html_attributes;
}
/**
* Return HTML attributes for the field.
@ -484,8 +434,7 @@ class Field implements \JsonSerializable {
unset($this->atts['wrapper_html_attr']['class']);
return wu_array_to_html_attrs($attributes);
} // end get_wrapper_html_attributes;
}
/**
* Implements our on json_decode version of this object. Useful for use in vue.js
@ -497,7 +446,5 @@ class Field implements \JsonSerializable {
public function jsonSerialize() {
return $this->atts;
} // end jsonSerialize;
} // end class Field;
}
}

View File

@ -9,7 +9,7 @@
namespace WP_Ultimo\UI;
use \WP_Ultimo\UI\Field;
use WP_Ultimo\UI\Field;
// Exit if accessed directly
defined('ABSPATH') || exit;
@ -48,32 +48,37 @@ class Form implements \JsonSerializable {
*/
public function __construct($id, $fields, $atts = array()) {
$this->atts = apply_filters("wu_{$id}_form_atts", wp_parse_args($atts, array(
'id' => $id,
'method' => 'post',
'before' => '',
'after' => '',
'action' => false,
'title' => false,
'wrap_in_form_tag' => false,
'wrap_tag' => 'div',
'classes' => false,
'field_wrapper_classes' => false,
'field_classes' => false,
'views' => 'settings/fields',
'variables' => array(),
'step' => (object) array(
'classes' => '',
'element_id' => '',
),
'html_attr' => array(
'class' => '',
),
)));
$this->atts = apply_filters(
"wu_{$id}_form_atts",
wp_parse_args(
$atts,
array(
'id' => $id,
'method' => 'post',
'before' => '',
'after' => '',
'action' => false,
'title' => false,
'wrap_in_form_tag' => false,
'wrap_tag' => 'div',
'classes' => false,
'field_wrapper_classes' => false,
'field_classes' => false,
'views' => 'settings/fields',
'variables' => array(),
'step' => (object) array(
'classes' => '',
'element_id' => '',
),
'html_attr' => array(
'class' => '',
),
)
)
);
$this->set_fields($fields);
} // end __construct;
}
/**
* Returns attributes as class properties.
@ -90,17 +95,14 @@ class Form implements \JsonSerializable {
'after',
);
$attr = isset($this->atts[$att]) ? $this->atts[$att] : false;
$attr = isset($this->atts[ $att ]) ? $this->atts[ $att ] : false;
if (in_array($att, $allowed_callable, true) && is_callable($attr)) {
$attr = call_user_func($attr, $this);
} // end if;
}
return $attr;
} // end __get;
}
/**
* Returns the list of field attributes.
@ -111,8 +113,7 @@ class Form implements \JsonSerializable {
public function get_attributes() {
return $this->atts;
} // end get_attributes;
}
/**
* Returns the list of fields used by the form.
@ -123,8 +124,7 @@ class Form implements \JsonSerializable {
public function get_fields() {
return (array) $this->fields;
} // end get_fields;
}
/**
* Casts fields to \WP_Ultimo\UI\Fields and stores them on private list.
@ -148,14 +148,11 @@ class Form implements \JsonSerializable {
$fields = apply_filters("wu_{$id}_form_fields", $fields);
foreach ($fields as $field_slug => $field) {
$field['form'] = $this;
$this->fields[$field_slug] = new Field($field_slug, $field);
} // end foreach;
} // end set_fields;
$this->fields[ $field_slug ] = new Field($field_slug, $field);
}
}
/**
* Renders the form with its fields.
@ -165,42 +162,44 @@ class Form implements \JsonSerializable {
*/
public function render() {
$variables = array_merge($this->variables, array(
'form_slug' => $this->id,
'form' => $this,
'step' => $this->step,
));
$variables = array_merge(
$this->variables,
array(
'form_slug' => $this->id,
'form' => $this,
'step' => $this->step,
)
);
ob_start();
foreach ($this->get_fields() as $field_slug => $field) {
$template_name = $field->get_template_name();
if (wu_get_isset($field->wrapper_html_attr, 'id') === false) {
$new_wrapper_attributes = $field->wrapper_html_attr;
$new_wrapper_attributes['id'] = "wrapper-field-$field_slug";
$field->set_attribute('wrapper_html_attr', $new_wrapper_attributes);
}
} // end if;
wu_get_template("{$this->views}/field-{$template_name}", array(
'field_slug' => $field_slug,
'field' => $field,
), "{$this->views}/field-text");
} // end foreach;
wu_get_template(
"{$this->views}/field-{$template_name}",
array(
'field_slug' => $field_slug,
'field' => $field,
),
"{$this->views}/field-text"
);
}
$rendered_fields = ob_get_clean();
$variables['rendered_fields'] = $rendered_fields;
wu_get_template("{$this->views}/form", $variables);
} // end render;
}
/**
* Return HTML attributes for the field.
@ -215,24 +214,17 @@ class Form implements \JsonSerializable {
unset($this->atts['html_attr']['class']);
if ($this->type === 'number') {
if ($this->min !== false) {
$attributes['min'] = $this->min;
} // end if;
}
if ($this->max !== false) {
$attributes['max'] = $this->max;
} // end if;
} // end if;
}
}
return wu_array_to_html_attrs($attributes);
} // end get_html_attributes;
}
/**
* Implements our on json_decode version of this object. Useful for use in vue.js
@ -244,7 +236,5 @@ class Form implements \JsonSerializable {
public function jsonSerialize() {
return $this->atts;
} // end jsonSerialize;
} // end class Form;
}
}

View File

@ -65,14 +65,11 @@ class Invoices_Element extends Base_Element {
public function get_icon($context = 'block') {
if ($context === 'elementor') {
return 'eicon-price-list';
} // end if;
}
return 'fa fa-search';
} // end get_icon;
}
/**
* The title of the UI element.
@ -87,8 +84,7 @@ class Invoices_Element extends Base_Element {
public function get_title() {
return __('Invoices', 'wp-ultimo');
} // end get_title;
}
/**
* The description of the UI element.
@ -104,8 +100,7 @@ class Invoices_Element extends Base_Element {
public function get_description() {
return __('Adds a checkout form block to the page.', 'wp-ultimo');
} // end get_description;
}
/**
* The list of fields to be added to Gutenberg.
@ -151,8 +146,7 @@ class Invoices_Element extends Base_Element {
);
return $fields;
} // end fields;
}
/**
* The list of keywords for this element.
@ -180,8 +174,7 @@ class Invoices_Element extends Base_Element {
'Form',
'Cart',
);
} // end keywords;
}
/**
* List of default parameters for the element.
@ -203,8 +196,7 @@ class Invoices_Element extends Base_Element {
'title' => __('Invoices', 'wp-ultimo'),
'limit' => 0,
);
} // end defaults;
}
/**
* Loads the required scripts.
@ -215,8 +207,7 @@ class Invoices_Element extends Base_Element {
public function register_scripts() {
wp_enqueue_script('wu-ajax-list-table');
} // end register_scripts;
}
/**
* Loads dependencies for the render.
@ -226,26 +217,19 @@ class Invoices_Element extends Base_Element {
*/
public function dependencies() {
if (!function_exists('convert_to_screen')) {
if ( ! function_exists('convert_to_screen')) {
require_once ABSPATH . 'wp-admin/includes/template.php';
}
} // end if;
if (!function_exists('get_column_headers')) {
if ( ! function_exists('get_column_headers')) {
require_once ABSPATH . 'wp-admin/includes/class-wp-screen.php';
require_once ABSPATH . 'wp-admin/includes/screen.php';
}
} // end if;
if (!function_exists('wu_responsive_table_row')) {
if ( ! function_exists('wu_responsive_table_row')) {
require wu_path('/inc/functions/admin.php');
} // end if;
} // end dependencies;
}
}
/**
* Runs early on the request lifecycle as soon as we detect the shortcode is present.
@ -257,15 +241,12 @@ class Invoices_Element extends Base_Element {
$this->membership = WP_Ultimo()->currents->get_membership();
if (!$this->membership) {
if ( ! $this->membership) {
$this->set_display(false);
return;
} // end if;
} // end setup;
}
}
/**
* Allows the setup in the context of previews.
@ -276,8 +257,7 @@ class Invoices_Element extends Base_Element {
public function setup_preview() {
$this->membership = wu_mock_membership();
} // end setup_preview;
}
/**
* The content to be output on the screen.
@ -297,7 +277,5 @@ class Invoices_Element extends Base_Element {
$atts['membership'] = $this->membership;
return wu_get_template_contents('dashboard-widgets/invoices', $atts);
} // end output;
} // end class Invoices_Element;
}
}

View File

@ -49,8 +49,7 @@ class Jumper {
add_action('wp_ultimo_load', array($this, 'add_settings'), 20);
add_action('init', array($this, 'load_jumper'));
} // end __construct;
}
/**
* Checks if we should add the jumper or not.
@ -61,8 +60,7 @@ class Jumper {
protected function is_jumper_enabled() {
return apply_filters('wu_is_jumper_enabled', wu_get_setting('enable_jumper', true) && current_user_can('manage_network'));
} // end is_jumper_enabled;
}
/**
* Adds the Jumper trigger to the admin top pages.
@ -74,12 +72,14 @@ class Jumper {
*/
public function add_jumper_trigger($page) {
wu_get_template('ui/jumper-trigger', array(
'page' => $page,
'jumper' => $this,
));
} // end add_jumper_trigger;
wu_get_template(
'ui/jumper-trigger',
array(
'page' => $page,
'jumper' => $this,
)
);
}
/**
* Loads the necessary elements to display the Jumper.
@ -90,7 +90,6 @@ class Jumper {
public function load_jumper() {
if ($this->is_jumper_enabled() && is_admin()) {
add_action('wu_header_right', array($this, 'add_jumper_trigger'));
add_action('admin_init', array($this, 'rebuild_menu'));
@ -108,10 +107,8 @@ class Jumper {
add_filter('wu_link_list', array($this, 'add_wp_ultimo_extra_links'));
add_filter('wu_link_list', array($this, 'add_user_custom_links'));
} // end if;
} // end load_jumper;
}
}
/**
* Clear the jumper menu cache on settings save
@ -127,12 +124,9 @@ class Jumper {
public function clear_jump_cache_on_save($settings) {
if (isset($settings['jumper_custom_links'])) {
delete_site_transient($this->transient_key);
} // end if;
} // end clear_jump_cache_on_save;
}
}
/**
* Rebuilds the jumper menu via a trigger URL.
@ -142,17 +136,14 @@ class Jumper {
*/
public function rebuild_menu() {
if (isset($_GET[$this->reset_slug]) && current_user_can('manage_network')) {
if (isset($_GET[ $this->reset_slug ]) && current_user_can('manage_network')) {
delete_site_transient($this->transient_key);
wp_redirect(network_admin_url());
exit;
} // end if;
} // end rebuild_menu;
}
}
/**
* Retrieves the custom links added by the super admin
@ -169,22 +160,17 @@ class Jumper {
$lines = explode(PHP_EOL, (string) $saved_links);
foreach ($lines as $line) {
$link_elements = explode(':', $line, 2);
if (count($link_elements) === 2) {
$title = trim($link_elements[1]);
$treated_lines[$title] = trim($link_elements[0]);
} // end if;
} // end foreach;
$treated_lines[ $title ] = trim($link_elements[0]);
}
}
return $treated_lines;
} // end get_user_custom_links;
}
/**
* Add the custom links to the Jumper menu
@ -198,15 +184,12 @@ class Jumper {
$custom_links = $this->get_user_custom_links();
if (!empty($custom_links)) {
$links[__('Custom Links', 'wp-ultimo')] = $custom_links;
} // end if;
if ( ! empty($custom_links)) {
$links[ __('Custom Links', 'wp-ultimo') ] = $custom_links;
}
return $links;
} // end add_user_custom_links;
}
/**
* Add WP Multisite WaaS settings links to the Jumper menu.
@ -219,7 +202,6 @@ class Jumper {
public function add_wp_ultimo_extra_links($links) {
if (isset($links['WP Ultimo'])) {
$settings_tabs = array(
'general' => __('General', 'wp-ultimo'),
'network' => __('Network Settings', 'wp-ultimo'),
@ -233,13 +215,11 @@ class Jumper {
);
foreach ($settings_tabs as $tab => $tab_label) {
$url = network_admin_url('admin.php?page=wp-ultimo-settings&wu-tab=' . $tab);
// translators: The placeholder represents the title of the Settings tab.
$links['WP Ultimo'][$url] = sprintf(__('Settings: %s', 'wp-ultimo'), $tab_label);
} // end foreach;
$links['WP Ultimo'][ $url ] = sprintf(__('Settings: %s', 'wp-ultimo'), $tab_label);
}
$links['WP Ultimo'][ network_admin_url('admin.php?page=wp-ultimo-settings&wu-tab=tools') ] = __('Settings: Webhooks', 'wp-ultimo');
@ -248,19 +228,15 @@ class Jumper {
/**
* Adds Main Site Dashboard
*/
if (isset($links[__('Sites')])) {
if (isset($links[ __('Sites') ])) {
$main_site_url = get_admin_url(get_current_site()->blog_id);
$links[__('Sites')][$main_site_url] = __('Main Site Dashboard', 'wp-ultimo');
} // end if;
} // end if;
$links[ __('Sites') ][ $main_site_url ] = __('Main Site Dashboard', 'wp-ultimo');
}
}
return $links;
} // end add_wp_ultimo_extra_links;
}
/**
* Get the trigger key defined by the user.
*
@ -269,8 +245,7 @@ class Jumper {
function get_defined_trigger_key(): string {
return substr((string) wu_get_setting('jumper_key', 'g'), 0, 1);
} // end get_defined_trigger_key;
}
/**
* Get the trigger key combination depending on the OS
@ -292,9 +267,8 @@ class Jumper {
'osx' => array('command', 'option', $trigger_key),
);
return isset($keys[$os]) ? $keys[$os] : $keys['win'];
} // end get_keys;
return isset($keys[ $os ]) ? $keys[ $os ] : $keys['win'];
}
/**
* Changes the helper footer message about the Jumper and its trigger
@ -306,11 +280,9 @@ class Jumper {
*/
public function add_jumper_footer_message($text) {
if (!wu_get_setting('jumper_display_tip', true)) {
if ( ! wu_get_setting('jumper_display_tip', true)) {
return $text;
} // end if;
}
$os = stristr((string) $_SERVER['HTTP_USER_AGENT'], 'mac') ? 'osx' : 'win';
@ -319,17 +291,14 @@ class Jumper {
$html = '';
foreach ($keys as $key) {
$html .= '<span class="wu-keys-key">' . $key . '</span>+';
} // end foreach;
}
$html = trim($html, '+');
// translators: the %s placeholder is the key combination to trigger the Jumper.
return '<span class="wu-keys">' . sprintf(__('<strong>Quick Tip:</strong> Use %s to jump between pages.', 'wp-ultimo'), $html) . '</span>' . $text;
} // end add_jumper_footer_message;
}
/**
* Enqueues the JavaScript files necessary to make the jumper work.
@ -343,19 +312,22 @@ class Jumper {
wp_register_script('wu-jumper', wu_get_asset('jumper.js', 'js'), array('jquery', 'wu-selectize', 'wu-mousetrap', 'underscore'), wu_get_version(), true);
wp_localize_script('wu-jumper', 'wu_jumper_vars', array(
'not_found_message' => __('Nothing found for', 'wp-ultimo'),
'trigger_key' => $this->get_defined_trigger_key(),
'network_base_url' => network_admin_url(),
'ajaxurl' => wu_ajax_url(),
'base_url' => get_admin_url(get_current_site()->blog_id),
));
wp_localize_script(
'wu-jumper',
'wu_jumper_vars',
array(
'not_found_message' => __('Nothing found for', 'wp-ultimo'),
'trigger_key' => $this->get_defined_trigger_key(),
'network_base_url' => network_admin_url(),
'ajaxurl' => wu_ajax_url(),
'base_url' => get_admin_url(get_current_site()->blog_id),
)
);
wp_enqueue_script('wu-jumper');
wp_enqueue_style('wu-admin');
} // end enqueue_scripts;
}
/**
* Enqueues the CSS files necessary to make the jumper work.
@ -366,8 +338,7 @@ class Jumper {
public function enqueue_styles() {
wp_enqueue_style('wu-jumper', wu_get_asset('jumper.css', 'css'), array(), wu_get_version());
} // end enqueue_styles;
}
/**
* Outputs the actual HTML markup of the Jumper.
@ -377,11 +348,13 @@ class Jumper {
*/
public function output() {
wu_get_template('ui/jumper', array(
'menu_groups' => $this->get_link_list(),
));
} // end output;
wu_get_template(
'ui/jumper',
array(
'menu_groups' => $this->get_link_list(),
)
);
}
/**
* Get the full page URL for admin pages.
*
@ -394,8 +367,7 @@ class Jumper {
$final_url = menu_page_url($url, false);
return str_replace(admin_url(), network_admin_url(), $final_url);
} // end get_menu_page_url;
}
/**
* Returns the URL of a jumper menu item
@ -411,20 +383,15 @@ class Jumper {
public function get_target_url($url) {
if (strpos($url, 'http') !== false) {
return $url;
} // end if;
}
if (strpos($url, '.php') !== false) {
return network_admin_url($url);
} // end if;
}
return $this->get_menu_page_url($url);
} // end get_target_url;
}
/**
* Builds the list of links based on the $menu and $submenu globals.
@ -435,55 +402,50 @@ class Jumper {
*/
public function build_link_list() {
return Logger::track_time('jumper', __('Regenerating Jumper menu items', 'wp-ultimo'), function() {
return Logger::track_time(
'jumper',
__('Regenerating Jumper menu items', 'wp-ultimo'),
function () {
global $menu, $submenu;
global $menu, $submenu;
// This variable is going to carry our options
$choices = array();
// This variable is going to carry our options
$choices = array();
// Prevent first run bug
if (!is_array($menu) || !is_array($submenu)) {
// Prevent first run bug
if ( ! is_array($menu) || ! is_array($submenu)) {
return array();
}
return array();
// Loop all submenus so que can get our final
foreach ($submenu as $menu_name => $submenu_items) {
$title = $this->search_recursive($menu_name, $menu);
} // end if;
$string = wu_get_isset($title, 0, '');
// Loop all submenus so que can get our final
foreach ($submenu as $menu_name => $submenu_items) {
$title = preg_replace('/[0-9]+/', '', strip_tags($string));
$title = $this->search_recursive($menu_name, $menu);
// If parent does not exists, skip
if ( ! empty($title) && is_array($submenu_items)) {
$string = wu_get_isset($title, 0, '');
// We have to loop now each submenu
foreach ($submenu_items as $submenu_item) {
$url = $this->get_target_url($submenu_item[2]);
$title = preg_replace('/[0-9]+/', '', strip_tags($string));
// Add to our choices the admin urls
$choices[ $title ][ $url ] = preg_replace('/[0-9]+/', '', strip_tags((string) $submenu_item[0]));
}
}
}
// If parent does not exists, skip
if (!empty($title) && is_array($submenu_items)) {
$choices = apply_filters('wu_link_list', $choices);
// We have to loop now each submenu
foreach ($submenu_items as $submenu_item) {
set_site_transient($this->transient_key, $choices, 10 * MINUTE_IN_SECONDS);
$url = $this->get_target_url($submenu_item[2]);
// Add to our choices the admin urls
$choices[$title][$url] = preg_replace('/[0-9]+/', '', strip_tags((string) $submenu_item[0]));
} // end foreach;
} // end if;
} // end foreach;
$choices = apply_filters('wu_link_list', $choices);
set_site_transient($this->transient_key, $choices, 10 * MINUTE_IN_SECONDS);
return $choices;
});
} // end build_link_list;
return $choices;
}
);
}
/**
* Gets the cached menu list saved.
@ -496,8 +458,7 @@ class Jumper {
$saved_menu = get_site_transient($this->transient_key);
return $saved_menu ? $saved_menu : array();
} // end get_saved_menu;
}
/**
* Returns the link list.
@ -507,11 +468,10 @@ class Jumper {
*/
public function get_link_list() {
$should_rebuild_menu = !get_site_transient($this->transient_key);
$should_rebuild_menu = ! get_site_transient($this->transient_key);
return $should_rebuild_menu && is_network_admin() ? $this->build_link_list() : $this->get_saved_menu();
} // end get_link_list;
}
/**
* Filter the WP Multisite WaaS settings to add Jumper options
@ -522,49 +482,67 @@ class Jumper {
*/
public function add_settings() {
wu_register_settings_section('tools', array(
'title' => __('Tools', 'wp-ultimo'),
'desc' => __('Tools', 'wp-ultimo'),
'icon' => 'dashicons-wu-tools',
));
wu_register_settings_section(
'tools',
array(
'title' => __('Tools', 'wp-ultimo'),
'desc' => __('Tools', 'wp-ultimo'),
'icon' => 'dashicons-wu-tools',
)
);
wu_register_settings_field('tools', 'tools_header', array(
'title' => __('Jumper', 'wp-ultimo'),
'desc' => __('Spotlight-like search bar that allows you to easily access everything on your network.', 'wp-ultimo'),
'type' => 'header',
));
wu_register_settings_field(
'tools',
'tools_header',
array(
'title' => __('Jumper', 'wp-ultimo'),
'desc' => __('Spotlight-like search bar that allows you to easily access everything on your network.', 'wp-ultimo'),
'type' => 'header',
)
);
wu_register_settings_field('tools', 'enable_jumper', array(
'title' => __('Enable Jumper', 'wp-ultimo'),
'desc' => __('Turn this option on to make the Jumper available on your network.', 'wp-ultimo'),
'type' => 'toggle',
'default' => 1,
));
wu_register_settings_field(
'tools',
'enable_jumper',
array(
'title' => __('Enable Jumper', 'wp-ultimo'),
'desc' => __('Turn this option on to make the Jumper available on your network.', 'wp-ultimo'),
'type' => 'toggle',
'default' => 1,
)
);
wu_register_settings_field('tools', 'jumper_key', array(
'title' => __('Trigger Key', 'wp-ultimo'),
'desc' => __('Change the keyboard key used in conjunction with ctrl + alt (or cmd + option), to trigger the Jumper box.', 'wp-ultimo'),
'type' => 'text',
'default' => 'g',
'require' => array(
'enable_jumper' => 1,
),
));
wu_register_settings_field(
'tools',
'jumper_key',
array(
'title' => __('Trigger Key', 'wp-ultimo'),
'desc' => __('Change the keyboard key used in conjunction with ctrl + alt (or cmd + option), to trigger the Jumper box.', 'wp-ultimo'),
'type' => 'text',
'default' => 'g',
'require' => array(
'enable_jumper' => 1,
),
)
);
wu_register_settings_field('tools', 'jumper_custom_links', array(
'title' => __('Custom Links', 'wp-ultimo'),
'desc' => __('Use this textarea to add custom links to the Jumper. Add one per line, with the format "Title : url".', 'wp-ultimo'),
'placeholder' => __('Tile of Custom Link : http://link.com', 'wp-ultimo'),
'type' => 'textarea',
'html_attr' => array(
'rows' => 4,
),
'require' => array(
'enable_jumper' => 1,
),
));
} // end add_settings;
wu_register_settings_field(
'tools',
'jumper_custom_links',
array(
'title' => __('Custom Links', 'wp-ultimo'),
'desc' => __('Use this textarea to add custom links to the Jumper. Add one per line, with the format "Title : url".', 'wp-ultimo'),
'placeholder' => __('Tile of Custom Link : http://link.com', 'wp-ultimo'),
'type' => 'textarea',
'html_attr' => array(
'rows' => 4,
),
'require' => array(
'enable_jumper' => 1,
),
)
);
}
/**
* Helper function to recursively seach an array.
@ -578,19 +556,13 @@ class Jumper {
public function search_recursive($needle, $haystack) {
foreach ($haystack as $key => $value) {
$current_key = $key;
if ($needle === $value || (is_array($value) && $this->search_recursive($needle, $value) !== false)) {
return $value;
} // end if;
} // end foreach;
}
}
return false;
} // end search_recursive;
} // end class Jumper;
}
}

View File

@ -9,7 +9,7 @@
namespace WP_Ultimo\UI;
use \WP_Ultimo\UI\Base_Element;
use WP_Ultimo\UI\Base_Element;
// Exit if accessed directly
defined('ABSPATH') || exit;
@ -55,23 +55,20 @@ class Limits_Element extends Base_Element {
protected $site;
/**
* The icon of the UI element.
* e.g. return fa fa-search
*
* @since 2.0.0
* @param string $context One of the values: block, elementor or bb.
*/
* The icon of the UI element.
* e.g. return fa fa-search
*
* @since 2.0.0
* @param string $context One of the values: block, elementor or bb.
*/
public function get_icon($context = 'block'): string {
if ($context === 'elementor') {
return 'eicon-skill-bar';
} // end if;
}
return 'fa fa-search';
} // end get_icon;
}
/**
* The title of the UI element.
@ -86,8 +83,7 @@ class Limits_Element extends Base_Element {
public function get_title() {
return __('Limits & Quotas', 'wp-ultimo');
} // end get_title;
}
/**
* The description of the UI element.
@ -103,8 +99,7 @@ class Limits_Element extends Base_Element {
public function get_description() {
return __('Adds a checkout form block to the page.', 'wp-ultimo');
} // end get_description;
}
/**
* The list of fields to be added to Gutenberg.
@ -152,8 +147,7 @@ class Limits_Element extends Base_Element {
);
return $fields;
} // end fields;
}
/**
* The list of keywords for this element.
@ -181,8 +175,7 @@ class Limits_Element extends Base_Element {
'Limits',
'Quotas',
);
} // end keywords;
}
/**
* List of default parameters for the element.
@ -204,8 +197,7 @@ class Limits_Element extends Base_Element {
'columns' => 1,
'title' => __('Site Limits', 'wp-ultimo'),
);
} // end defaults;
}
/**
* Runs early on the request lifecycle as soon as we detect the shortcode is present.
@ -217,13 +209,10 @@ class Limits_Element extends Base_Element {
$this->site = WP_Ultimo()->currents->get_site();
if (!$this->site || !$this->site->is_customer_allowed()) {
if ( ! $this->site || ! $this->site->is_customer_allowed()) {
$this->set_display(false);
} // end if;
} // end setup;
}
}
/**
* Allows the setup in the context of previews.
@ -234,8 +223,7 @@ class Limits_Element extends Base_Element {
public function setup_preview() {
$this->site = wu_mock_site();
} // end setup_preview;
}
/**
* The content to be output on the screen.
@ -252,9 +240,12 @@ class Limits_Element extends Base_Element {
*/
public function output($atts, $content = null) {
$post_types = get_post_types(array(
'public' => true,
), 'objects');
$post_types = get_post_types(
array(
'public' => true,
),
'objects'
);
/*
* Remove post types that where disabled or that are not available for display.
@ -278,7 +269,5 @@ class Limits_Element extends Base_Element {
$atts['post_type_limits'] = $this->site->get_limitations()->post_types;
return wu_get_template_contents('dashboard-widgets/limits-and-quotas', $atts);
} // end output;
} // end class Limits_Element;
}
}

View File

@ -9,8 +9,8 @@
namespace WP_Ultimo\UI;
use \WP_Ultimo\UI\Base_Element;
use \WP_Ultimo\Checkout\Checkout_Pages;
use WP_Ultimo\UI\Base_Element;
use WP_Ultimo\Checkout\Checkout_Pages;
// Exit if accessed directly
defined('ABSPATH') || exit;
@ -67,27 +67,23 @@ class Login_Form_Element extends Base_Element {
add_filter('login_redirect', array($this, 'handle_redirect'), -1, 3);
parent::init();
} // end init;
}
/**
* The icon of the UI element.
* e.g. return fa fa-search
*
* @since 2.0.0
* @param string $context One of the values: block, elementor or bb.
*/
* The icon of the UI element.
* e.g. return fa fa-search
*
* @since 2.0.0
* @param string $context One of the values: block, elementor or bb.
*/
public function get_icon($context = 'block'): string {
if ($context === 'elementor') {
return 'eicon-lock-user';
} // end if;
}
return 'fa fa-search';
} // end get_icon;
}
/**
* The title of the UI element.
@ -102,8 +98,7 @@ class Login_Form_Element extends Base_Element {
public function get_title() {
return __('Login Form', 'wp-ultimo');
} // end get_title;
}
/**
* The description of the UI element.
@ -119,8 +114,7 @@ class Login_Form_Element extends Base_Element {
public function get_description() {
return __('Adds a login form to the page.', 'wp-ultimo');
} // end get_description;
}
/**
* The list of fields to be added to Gutenberg.
@ -297,8 +291,7 @@ class Login_Form_Element extends Base_Element {
);
return $fields;
} // end fields;
}
/**
* Registers scripts and styles necessary to render this.
@ -309,8 +302,7 @@ class Login_Form_Element extends Base_Element {
public function register_scripts() {
wp_enqueue_style('wu-admin');
} // end register_scripts;
}
/**
* The list of keywords for this element.
@ -337,8 +329,7 @@ class Login_Form_Element extends Base_Element {
'Login',
'Reset Password',
);
} // end keywords;
}
/**
* List of default parameters for the element.
@ -389,8 +380,7 @@ class Login_Form_Element extends Base_Element {
'value_username' => '',
'value_remember' => false, // Set 'value_remember' to true to default the "Remember me" checkbox to checked.
);
} // end defaults;
}
/**
* Runs early on the request lifecycle as soon as we detect the shortcode is present.
@ -403,13 +393,11 @@ class Login_Form_Element extends Base_Element {
$this->logged = is_user_logged_in();
if ($this->is_reset_password_page()) {
$rp_path = '/';
$rp_cookie = 'wp-resetpass-' . COOKIEHASH;
if (isset($_GET['key']) && isset($_GET['login'])) {
$value = sprintf('%s:%s', wp_unslash($_GET['login']), wp_unslash($_GET['key']));
setcookie($rp_cookie, $value, 0, $rp_path, (string) COOKIE_DOMAIN, is_ssl(), true);
@ -417,10 +405,8 @@ class Login_Form_Element extends Base_Element {
wp_safe_redirect(remove_query_arg(array('key', 'login')));
exit;
} // end if;
} // end if;
}
}
global $post;
@ -428,12 +414,9 @@ class Login_Form_Element extends Base_Element {
* Handles maintenance mode on Elementor.
*/
if ($post && $post->ID === absint(wu_get_setting('default_login_page', 0))) {
add_filter('elementor/maintenance_mode/is_login_page', '__return_true');
} // end if;
} // end setup;
}
}
/**
* Checks if we are in a lost password form page.
@ -444,8 +427,7 @@ class Login_Form_Element extends Base_Element {
public function is_lost_password_page() {
return wu_request('action') === 'lostpassword';
} // end is_lost_password_page;
}
/**
* Checks if we are in the email confirm instruction page of a reset password.
@ -456,8 +438,7 @@ class Login_Form_Element extends Base_Element {
public function is_check_email_confirm() {
return wu_request('checkemail') === 'confirm';
} // end is_check_email_confirm;
}
/**
* Checks if we are in a reset password page.
@ -468,8 +449,7 @@ class Login_Form_Element extends Base_Element {
public function is_reset_password_page() {
return wu_request('action') === 'rp' || wu_request('action') === 'resetpass';
} // end is_reset_password_page;
}
/**
* Checks if we are in the the password rest confirmation page.
@ -480,8 +460,7 @@ class Login_Form_Element extends Base_Element {
public function is_reset_confirmation_page() {
return wu_request('password-reset') === 'success';
} // end is_reset_confirmation_page;
}
/**
* Handle custom login redirection
@ -496,28 +475,22 @@ class Login_Form_Element extends Base_Element {
public function handle_redirect($redirect_to, $requested_redirect_to, $user) {
if (is_wp_error($user)) {
if (wu_request('wu_login_page_url')) {
$redirect_to = wu_request('wu_login_page_url');
$redirect_to = add_query_arg('error', $user->get_error_code(), $redirect_to);
if ($user->get_error_code() === 'invalid_username') {
$redirect_to = add_query_arg('username', wu_request('log'), $redirect_to);
} // end if;
}
// In this case, WP will not redirect, so we need to do it here
wp_redirect($redirect_to);
exit;
} // end if;
}
return $redirect_to;
} // end if;
}
$redirect_type = wu_request('wu_login_form_redirect_type', 'default');
@ -526,24 +499,18 @@ class Login_Form_Element extends Base_Element {
// query_redirect is the default wp behaviour
return $redirect_to;
} elseif ($redirect_type === 'customer_site') {
$user_site = get_active_blog_for_user( $user->ID );
$user_site = get_active_blog_for_user($user->ID);
wp_redirect($user_site->siteurl . $requested_redirect_to);
exit;
} elseif ($redirect_type === 'main_site') {
wp_redirect(network_site_url($requested_redirect_to));
exit;
} // end if;
}
return $redirect_to;
} // end handle_redirect;
}
/**
* Allows the setup in the context of previews.
@ -554,8 +521,7 @@ class Login_Form_Element extends Base_Element {
public function setup_preview() {
$this->logged = false;
} // end setup_preview;
}
/**
* Returns the logout URL for the "not you bar".
@ -568,8 +534,7 @@ class Login_Form_Element extends Base_Element {
$redirect_to = wu_get_current_url();
return wp_logout_url($redirect_to);
} // end get_logout_url;
}
/**
* The content to be output on the screen.
@ -595,7 +560,6 @@ class Login_Form_Element extends Base_Element {
* login URL so the user can re-login with the new password.
*/
if ($this->is_reset_confirmation_page()) {
$fields = array(
'email-activation-instructions' => array(
'type' => 'note',
@ -603,13 +567,12 @@ class Login_Form_Element extends Base_Element {
),
);
/*
* Check if are in the email confirmation instructions page.
*
* If that's the case, we show the instructions.
*/
/*
* Check if are in the email confirmation instructions page.
*
* If that's the case, we show the instructions.
*/
} elseif ($this->is_check_email_confirm()) {
$fields = array(
'email-activation-instructions' => array(
'type' => 'note',
@ -621,33 +584,26 @@ class Login_Form_Element extends Base_Element {
),
);
/*
* Check if we are in the set new password page.
*
* If that's the case, we show the new password fields
* so the user can set a new password.
*/
/*
* Check if we are in the set new password page.
*
* If that's the case, we show the new password fields
* so the user can set a new password.
*/
} elseif ($this->is_reset_password_page()) {
$rp_cookie = 'wp-resetpass-' . COOKIEHASH;
if (isset($_COOKIE[$rp_cookie]) && 0 < strpos((string) $_COOKIE[$rp_cookie], ':')) {
list($rp_login, $rp_key) = explode(':', wp_unslash($_COOKIE[$rp_cookie]), 2);
if (isset($_COOKIE[ $rp_cookie ]) && 0 < strpos((string) $_COOKIE[ $rp_cookie ], ':')) {
list($rp_login, $rp_key) = explode(':', wp_unslash($_COOKIE[ $rp_cookie ]), 2);
$user = check_password_reset_key($rp_key, $rp_login);
if (isset($_POST['pass1']) && !hash_equals($rp_key, $_POST['rp_key'])) {
if (isset($_POST['pass1']) && ! hash_equals($rp_key, $_POST['rp_key'])) {
$user = false;
} // end if;
}
} else {
$user = false;
} // end if;
}
$redirect_to = add_query_arg('password-reset', 'success', remove_query_arg(array('action', 'error')));
@ -702,21 +658,18 @@ class Login_Form_Element extends Base_Element {
),
);
/*
* Checks if we are in the first reset password page, where the customer requests a reset.
*
* If that's the case, we show the username/email field, so the user can
* get an email with the reset link.
*/
/*
* Checks if we are in the first reset password page, where the customer requests a reset.
*
* If that's the case, we show the username/email field, so the user can
* get an email with the reset link.
*/
} elseif ($this->is_lost_password_page()) {
$user_login = wu_request('user_login', '');
if ($user_login) {
$user_login = wp_unslash($user_login);
} // end if;
}
$redirect_to = add_query_arg('checkemail', 'confirm', remove_query_arg(array('action', 'error')));
@ -752,9 +705,7 @@ class Login_Form_Element extends Base_Element {
'wrapper_classes' => 'wu-items-end wu-bg-none',
),
);
} else {
$view = 'dashboard-widgets/login-form';
$fields = array(
@ -773,14 +724,12 @@ class Login_Form_Element extends Base_Element {
);
if ($atts['remember']) {
$fields['rememberme'] = array(
'type' => 'toggle',
'title' => $atts['label_remember'],
'desc' => $atts['desc_remember'],
);
} // end if;
}
$fields['redirect_to'] = array(
'type' => 'hidden',
@ -788,19 +737,13 @@ class Login_Form_Element extends Base_Element {
);
if (isset($_GET['redirect_to'])) {
$atts['redirect_type'] = 'query_redirect';
$fields['redirect_to']['value'] = $_GET['redirect_to'];
} elseif ($atts['redirect_type'] === 'customer_site') {
$fields['redirect_to']['value'] = $atts['customer_redirect_path'];
} elseif ($atts['redirect_type'] === 'main_site') {
$fields['redirect_to']['value'] = $atts['main_redirect_path'];
} // end if;
}
$fields['wu_login_form_redirect_type'] = array(
'type' => 'hidden',
@ -821,8 +764,7 @@ class Login_Form_Element extends Base_Element {
'classes' => '',
'wrapper_classes' => 'wu-items-end wu-bg-none',
);
} // end if;
}
/*
* Check for error messages
@ -831,7 +773,6 @@ class Login_Form_Element extends Base_Element {
* at the top of the fields array, to display the errors.
*/
if (wu_request('error')) {
$username = wu_request('username', '');
$error_message_field = array(
@ -842,8 +783,7 @@ class Login_Form_Element extends Base_Element {
);
$fields = array_merge($error_message_field, $fields);
} // end if;
}
$fields['wu_login_page_url'] = array(
'type' => 'hidden',
@ -855,23 +795,25 @@ class Login_Form_Element extends Base_Element {
*
* @since 2.0.0
*/
$form = new \WP_Ultimo\UI\Form($this->get_id(), $fields, array(
'action' => esc_url(site_url('wp-login.php', 'login_post')),
'wrap_in_form_tag' => true,
'views' => 'admin-pages/fields',
'classes' => 'wu-p-0 wu-m-0',
'field_wrapper_classes' => 'wu-box-border wu-items-center wu-flex wu-justify-between wu-py-4 wu-m-0',
'html_attr' => array(
'class' => 'wu-w-full',
),
));
$form = new \WP_Ultimo\UI\Form(
$this->get_id(),
$fields,
array(
'action' => esc_url(site_url('wp-login.php', 'login_post')),
'wrap_in_form_tag' => true,
'views' => 'admin-pages/fields',
'classes' => 'wu-p-0 wu-m-0',
'field_wrapper_classes' => 'wu-box-border wu-items-center wu-flex wu-justify-between wu-py-4 wu-m-0',
'html_attr' => array(
'class' => 'wu-w-full',
),
)
);
$atts['logged'] = $this->logged;
$atts['login_url'] = $this->get_logout_url();
$atts['form'] = $form;
return wu_get_template_contents($view, $atts);
} // end output;
} // end class Login_Form_Element;
}
}

View File

@ -74,14 +74,11 @@ class My_Sites_Element extends Base_Element {
public function get_icon($context = 'block') {
if ($context === 'elementor') {
return 'eicon-info-circle-o';
} // end if;
}
return 'fa fa-search';
} // end get_icon;
}
/**
* The title of the UI element.
@ -96,8 +93,7 @@ class My_Sites_Element extends Base_Element {
public function get_title() {
return __('My Sites', 'wp-ultimo');
} // end get_title;
}
/**
* The description of the UI element.
@ -113,8 +109,7 @@ class My_Sites_Element extends Base_Element {
public function get_description() {
return __('Adds a block to display the sites owned by the current customer.', 'wp-ultimo');
} // end get_description;
}
/**
* The list of fields to be added to Gutenberg.
@ -168,19 +163,19 @@ class My_Sites_Element extends Base_Element {
),
);
$pages = get_pages(array(
'exclude' => array(get_the_ID()),
));
$pages = get_pages(
array(
'exclude' => array(get_the_ID()),
)
);
$pages = $pages ? $pages : array();
$pages_list = array(0 => __('Current Page', 'wp-ultimo'));
foreach ($pages as $page) {
$pages_list[$page->ID] = $page->post_title;
} // end foreach;
$pages_list[ $page->ID ] = $page->post_title;
}
$fields['custom_manage_page'] = array(
'type' => 'select',
@ -213,8 +208,7 @@ class My_Sites_Element extends Base_Element {
);
return $fields;
} // end fields;
}
/**
* The list of keywords for this element.
@ -242,8 +236,7 @@ class My_Sites_Element extends Base_Element {
'Form',
'Cart',
);
} // end keywords;
}
/**
* List of default parameters for the element.
@ -268,8 +261,7 @@ class My_Sites_Element extends Base_Element {
'custom_manage_page' => 0,
'site_show' => 'owned',
);
} // end defaults;
}
/**
* Loads the necessary scripts and styles for this element.
@ -280,8 +272,7 @@ class My_Sites_Element extends Base_Element {
public function register_scripts() {
wp_enqueue_style('wu-admin');
} // end register_scripts;
}
/**
* Runs early on the request lifecycle as soon as we detect the shortcode is present.
@ -293,17 +284,14 @@ class My_Sites_Element extends Base_Element {
global $wpdb;
if (!is_user_logged_in() || WP_Ultimo()->currents->is_site_set_via_request()) {
if ( ! is_user_logged_in() || WP_Ultimo()->currents->is_site_set_via_request()) {
$this->set_display(false);
return;
} // end if;
}
$this->customer = WP_Ultimo()->currents->get_customer();
} // end setup;
}
/**
* Allows the setup in the context of previews.
@ -319,8 +307,7 @@ class My_Sites_Element extends Base_Element {
wu_mock_site(1),
wu_mock_site(2),
);
} // end setup_preview;
}
/**
* The content to be output on the screen.
@ -342,8 +329,7 @@ class My_Sites_Element extends Base_Element {
$atts['sites'] = $this->get_sites(wu_get_isset($atts, 'site_show'));
return wu_get_template_contents('dashboard-widgets/my-sites', $atts);
} // end output;
}
/**
* Get sites to display on widget
@ -353,46 +339,42 @@ class My_Sites_Element extends Base_Element {
*/
protected function get_sites(?string $show = null): array {
if (!empty($this->sites)) {
if ( ! empty($this->sites)) {
return $this->sites;
}
$this->sites = apply_filters('wp_ultimo_pre_my_sites_sites', array(), $show);
if (!empty($this->sites)) {
if ( ! empty($this->sites)) {
return $this->sites;
}
if (!empty($this->customer)) {
if ( ! empty($this->customer)) {
$pending_sites = \WP_Ultimo\Models\Site::get_all_by_type('pending', array('customer_id' => $this->customer->get_id()));
$customer_sites = array_reduce(
$this->customer->get_sites(),
function ($customer_sites, $site) {
$customer_sites[$site->get_id()] = $site;
$customer_sites[ $site->get_id() ] = $site;
return $customer_sites;
}
);
}
if ($show === 'all') {
$wp_user_sites = get_blogs_of_user(get_current_user_id());
$user_sites = array_reduce($wp_user_sites, function($user_sites, $wp_site) use ($customer_sites) {
if (!array_key_exists($wp_site->userblog_id, $customer_sites ?? array()) && $wp_site->userblog_id !== get_main_site_id()) {
$wu_site = wu_get_site($wp_site->userblog_id);
$wu_site->set_membership_id(0);
$user_sites[$wp_site->userblog_id] = $wu_site;
$user_sites = array_reduce(
$wp_user_sites,
function ($user_sites, $wp_site) use ($customer_sites) {
if ( ! array_key_exists($wp_site->userblog_id, $customer_sites ?? array()) && $wp_site->userblog_id !== get_main_site_id()) {
$wu_site = wu_get_site($wp_site->userblog_id);
$wu_site->set_membership_id(0);
$user_sites[ $wp_site->userblog_id ] = $wu_site;
}
return $user_sites;
}
return $user_sites;
});
);
}
$sites = array_merge(
@ -404,8 +386,7 @@ class My_Sites_Element extends Base_Element {
$this->sites = apply_filters('wp_ultimo_after_my_sites_sites', $sites, $show);
return $this->sites;
} // end get_sites;
}
/**
@ -421,28 +402,26 @@ class My_Sites_Element extends Base_Element {
public function get_manage_url($site_id, $type = 'default', $custom_page_id = 0) {
if ($type === 'wp_admin') {
return get_admin_url($site_id);
} // end if;
}
if ($type === 'custom_page') {
$custom_page = get_page_link($custom_page_id);
$url_param = \WP_Ultimo\Current::param_key('site');
$site_hash = \WP_Ultimo\Helpers\Hash::encode($site_id, 'site');
return add_query_arg(array(
$url_param => $site_hash,
), $custom_page);
} // end if;
return add_query_arg(
array(
$url_param => $site_hash,
),
$custom_page
);
}
return \WP_Ultimo\Current::get_manage_url($site_id, 'site');
} // end get_manage_url;
}
/**
* Returns the new site URL for site creation.
@ -460,35 +439,31 @@ class My_Sites_Element extends Base_Element {
$url = $checkout_pages->get_page_url('new_site');
if ($membership) {
if ($url) {
return add_query_arg(array(
'membership' => $membership->get_hash(),
), $url);
} // end if;
return add_query_arg(
array(
'membership' => $membership->get_hash(),
),
$url
);
}
if (is_main_site()) {
$sites = $membership->get_sites(false);
if (!empty($sites)) {
return add_query_arg(array(
'page' => 'add-new-site',
), get_admin_url($sites[0]->get_id()));
} // end if;
if ( ! empty($sites)) {
return add_query_arg(
array(
'page' => 'add-new-site',
),
get_admin_url($sites[0]->get_id())
);
}
return '';
} // end if;
} // end if;
}
}
return admin_url('admin.php?page=add-new-site');
} // end get_new_site_url;
} // end class My_Sites_Element;
}
}

View File

@ -49,14 +49,11 @@ class Payment_Methods_Element extends Base_Element {
public function get_icon($context = 'block') {
if ($context === 'elementor') {
return 'eicon-info-circle-o';
} // end if;
}
return 'fa fa-search';
} // end get_icon;
}
/**
* The title of the UI element.
@ -71,8 +68,7 @@ class Payment_Methods_Element extends Base_Element {
public function get_title() {
return __('Payment Methods', 'wp-ultimo');
} // end get_title;
}
/**
* The description of the UI element.
@ -88,8 +84,7 @@ class Payment_Methods_Element extends Base_Element {
public function get_description() {
return __('Adds a checkout form block to the page.', 'wp-ultimo');
} // end get_description;
}
/**
* The list of fields to be added to Gutenberg.
@ -135,8 +130,7 @@ class Payment_Methods_Element extends Base_Element {
);
return $fields;
} // end fields;
}
/**
* The list of keywords for this element.
@ -164,8 +158,7 @@ class Payment_Methods_Element extends Base_Element {
'Form',
'Cart',
);
} // end keywords;
}
/**
* List of default parameters for the element.
@ -184,8 +177,7 @@ class Payment_Methods_Element extends Base_Element {
public function defaults() {
return array();
} // end defaults;
}
/**
* The content to be output on the screen.
@ -203,7 +195,5 @@ class Payment_Methods_Element extends Base_Element {
public function output($atts, $content = null) {
return 'lol';
} // end output;
} // end class Payment_Methods_Element;
}
}

View File

@ -65,14 +65,11 @@ class Simple_Text_Element extends Base_Element {
public function get_icon($context = 'block') {
if ($context === 'elementor') {
return 'eicon-lock-user';
} // end if;
}
return 'fa fa-search';
} // end get_icon;
}
/**
* The title of the UI element.
@ -87,8 +84,7 @@ class Simple_Text_Element extends Base_Element {
public function get_title() {
return __('Simple Text', 'wp-ultimo');
} // end get_title;
}
/**
* The description of the UI element.
@ -104,8 +100,7 @@ class Simple_Text_Element extends Base_Element {
public function get_description() {
return __('Adds a simple text block to the page.', 'wp-ultimo');
} // end get_description;
}
/**
* The list of fields to be added to Gutenberg.
@ -142,12 +137,11 @@ class Simple_Text_Element extends Base_Element {
'tooltip' => '',
'html_attr' => array(
'rows' => 6,
)
),
);
return $fields;
} // end fields;
}
/**
* Registers scripts and styles necessary to render this.
@ -158,8 +152,7 @@ class Simple_Text_Element extends Base_Element {
public function register_scripts() {
wp_enqueue_style('wu-admin');
} // end register_scripts;
}
/**
* The list of keywords for this element.
@ -186,10 +179,9 @@ class Simple_Text_Element extends Base_Element {
'text',
'simple text',
'shortcode',
'textarea'
'textarea',
);
} // end keywords;
}
/**
* List of default parameters for the element.
@ -210,8 +202,7 @@ class Simple_Text_Element extends Base_Element {
return array(
'simple_text' => __('Text, HTML or shortcode.', 'wp-ultimo'),
);
} // end defaults;
}
/**
* The content to be output on the screen.
@ -229,7 +220,5 @@ class Simple_Text_Element extends Base_Element {
public function output($atts, $content = null) {
return wu_get_template_contents('dashboard-widgets/simple-text', $atts);
} // end output;
} // end class Simple_Text_Element;
}
}

File diff suppressed because it is too large Load Diff

View File

@ -55,12 +55,9 @@ class Site_Maintenance_Element extends Base_Element {
public function init() {
if (wu_get_setting('maintenance_mode')) {
parent::init();
} // end if;
} // end init;
}
}
/**
* The icon of the UI element.
@ -73,14 +70,11 @@ class Site_Maintenance_Element extends Base_Element {
public function get_icon($context = 'block') {
if ($context === 'elementor') {
return 'eicon-lock-user';
} // end if;
}
return 'fa fa-search';
} // end get_icon;
}
/**
* The title of the UI element.
@ -95,8 +89,7 @@ class Site_Maintenance_Element extends Base_Element {
public function get_title() {
return __('Site Maintenance', 'wp-ultimo');
} // end get_title;
}
/**
* The description of the UI element.
@ -112,8 +105,7 @@ class Site_Maintenance_Element extends Base_Element {
public function get_description() {
return __('Adds the toggle control to turn maintenance mode on.', 'wp-ultimo');
} // end get_description;
}
/**
* The list of fields to be added to Gutenberg.
@ -158,8 +150,7 @@ class Site_Maintenance_Element extends Base_Element {
);
return $fields;
} // end fields;
}
/**
* The list of keywords for this element.
@ -186,8 +177,7 @@ class Site_Maintenance_Element extends Base_Element {
'Login',
'Reset Password',
);
} // end keywords;
}
/**
* List of default parameters for the element.
@ -209,8 +199,7 @@ class Site_Maintenance_Element extends Base_Element {
'title' => __('Toggle Maintenance Mode', 'wp-ultimo'),
'desc' => __('Put your site on maintenance mode. When activated, the front-end will only be accessible to logged users.', 'wp-ultimo'),
);
} // end defaults;
}
/**
* Runs early on the request lifecycle as soon as we detect the shortcode is present.
@ -222,15 +211,12 @@ class Site_Maintenance_Element extends Base_Element {
$this->site = WP_Ultimo()->currents->get_site();
if (!$this->site || !$this->site->is_customer_allowed()) {
if ( ! $this->site || ! $this->site->is_customer_allowed()) {
$this->set_display(false);
return;
} // end if;
} // end setup;
}
}
/**
* Allows the setup in the context of previews.
@ -241,8 +227,7 @@ class Site_Maintenance_Element extends Base_Element {
public function setup_preview() {
$this->site = wu_mock_site();
} // end setup_preview;
}
/**
* Registers scripts and styles necessary to render this.
@ -254,14 +239,17 @@ class Site_Maintenance_Element extends Base_Element {
wp_register_script('wu-site-maintenance', wu_get_asset('site-maintenance.js', 'js'), array('jquery', 'wu-functions'), wu_get_version());
wp_localize_script('wu-site-maintenance', 'wu_site_maintenance', array(
'nonce' => wp_create_nonce('wu_toggle_maintenance_mode'),
'ajaxurl' => wu_ajax_url(),
));
wp_localize_script(
'wu-site-maintenance',
'wu_site_maintenance',
array(
'nonce' => wp_create_nonce('wu_toggle_maintenance_mode'),
'ajaxurl' => wu_ajax_url(),
)
);
wp_enqueue_script('wu-site-maintenance');
} // end register_scripts;
}
/**
* The content to be output on the screen.
@ -296,17 +284,19 @@ class Site_Maintenance_Element extends Base_Element {
*
* @since 2.0.0
*/
$form = new \WP_Ultimo\UI\Form('maintenance-mode', $fields, array(
'views' => 'admin-pages/fields',
'classes' => 'wu-widget-list wu-striped wu-modal-form wu-widget-list wu-striped wu-m-0 wu-mt-0 wu-list-none wu-p-0',
'field_wrapper_classes' => 'wu-w-full wu-box-border wu-items-center wu-flex wu-justify-between wu-p-4 wu-m-0 wu-border-t wu-border-l-0 wu-border-r-0 wu-border-b-0 wu-border-gray-300 wu-border-solid',
'html_attr' => array(),
));
$form = new \WP_Ultimo\UI\Form(
'maintenance-mode',
$fields,
array(
'views' => 'admin-pages/fields',
'classes' => 'wu-widget-list wu-striped wu-modal-form wu-widget-list wu-striped wu-m-0 wu-mt-0 wu-list-none wu-p-0',
'field_wrapper_classes' => 'wu-w-full wu-box-border wu-items-center wu-flex wu-justify-between wu-p-4 wu-m-0 wu-border-t wu-border-l-0 wu-border-r-0 wu-border-b-0 wu-border-gray-300 wu-border-solid',
'html_attr' => array(),
)
);
$atts['form'] = $form;
return wu_get_template_contents('dashboard-widgets/site-maintenance', $atts);
} // end output;
} // end class Site_Maintenance_Element;
}
}

View File

@ -45,8 +45,7 @@ class Template_Previewer {
public function init() {
add_action('wp_ultimo_load', array($this, 'hooks'));
} // end init;
}
/**
* Hooks into WordPress to add the template preview.
@ -71,11 +70,9 @@ class Template_Previewer {
add_action('send_headers', array($this, 'send_cross_origin_headers'), 1000);
return;
} // end if;
}
if ($this->is_template_previewer()) {
add_action('init', array($this, 'template_previewer'));
add_action('wp_enqueue_scripts', array($this, 'register_scripts'));
@ -89,10 +86,8 @@ class Template_Previewer {
* @param self $template_previewer Instance of the current class.
*/
do_action('wu_template_previewer', $this);
} // end if;
} // end hooks;
}
}
/**
* Send the cross origin headers to allow iframes to be loaded.
@ -109,8 +104,7 @@ class Template_Previewer {
send_origin_headers();
header_remove('X-Frame-Options');
} // end send_cross_origin_headers;
}
/**
* Register the necessary scripts.
@ -130,25 +124,34 @@ class Template_Previewer {
wp_register_script('wu-template-previewer', wu_get_asset('template-previewer.js', 'js'), array(), wu_get_version());
wp_localize_script('wu-template-previewer', 'wu_template_previewer', array(
'domain' => str_replace('www.', '', (string) $current_site->domain),
'current_template' => wu_request($this->get_preview_parameter(), false),
'current_url' => wu_get_current_url(),
'query_parameter' => $this->get_preview_parameter(),
));
wp_localize_script(
'wu-template-previewer',
'wu_template_previewer',
array(
'domain' => str_replace('www.', '', (string) $current_site->domain),
'current_template' => wu_request($this->get_preview_parameter(), false),
'current_url' => wu_get_current_url(),
'query_parameter' => $this->get_preview_parameter(),
)
);
wp_enqueue_script('wu-template-previewer');
wp_enqueue_style('wu-template-previewer', wu_get_asset('template-previewer.css', 'css'), array(), wu_get_version());
wp_add_inline_style('wu-template-previewer', wu_get_template_contents('dynamic-styles/template-previewer', array(
'bg_color' => $bg_color,
'button_bg_color' => $button_bg_color,
)));
wp_add_inline_style(
'wu-template-previewer',
wu_get_template_contents(
'dynamic-styles/template-previewer',
array(
'bg_color' => $bg_color,
'button_bg_color' => $button_bg_color,
)
)
);
wp_enqueue_style('dashicons');
} // end register_scripts;
}
/**
* Remove the unnecessary styles added by themes and other plugins.
@ -165,8 +168,7 @@ class Template_Previewer {
'wu-template-previewer',
'dashicons',
);
} // end remove_unnecessary_styles;
}
/**
* Append preview parameter.
@ -189,20 +191,15 @@ class Template_Previewer {
);
if (in_array($orig_scheme, $allowed_schemes, true) === false) {
return $url;
} // end if;
}
if (apply_filters('wu_append_preview_parameter', true, $this) === false) {
return $url;
} // end if;
}
return add_query_arg('wu-preview', 1, $url);
} // end append_preview_parameter;
}
/**
* Returns the preview URL for the template previewer.
@ -219,14 +216,11 @@ class Template_Previewer {
);
if (wu_request('open')) {
$args['open'] = 1;
} // end if;
}
return add_query_arg($args, home_url());
} // end get_preview_url;
}
/**
* Template Previewer code
@ -245,11 +239,9 @@ class Template_Previewer {
/**
* Check if this is a site template
*/
if (!$selected_template || ($selected_template->get_type() !== Site_Type::SITE_TEMPLATE && !wu_request('customizer'))) {
if ( ! $selected_template || ($selected_template->get_type() !== Site_Type::SITE_TEMPLATE && ! wu_request('customizer'))) {
wp_die(__('This template is not available', 'wp-ultimo'));
} // end if;
}
$categories = array();
@ -262,15 +254,14 @@ class Template_Previewer {
'tp' => $this,
);
$products_ids = isset($_COOKIE['wu_selected_products']) ? explode( ',', (string) $_COOKIE['wu_selected_products']) : array();
$products_ids = isset($_COOKIE['wu_selected_products']) ? explode(',', (string) $_COOKIE['wu_selected_products']) : array();
$products = array_map('wu_get_product', $products_ids);
// clear array
$products = array_filter($products);
if (!empty($products)) {
if ( ! empty($products)) {
$limits = new \WP_Ultimo\Objects\Limitations();
list($plan, $additional_products) = wu_segregate_products($products);
@ -278,13 +269,10 @@ class Template_Previewer {
$products = array_merge(array($plan), $additional_products);
foreach ($products as $product) {
$limits = $limits->merge($product->get_limitations());
} // end foreach;
}
if ($limits->site_templates->get_mode() !== 'default') {
$site_ids = $limits->site_templates->get_available_site_templates();
$render_parameters['templates'] = array_map('wu_get_site', $site_ids);
@ -293,8 +281,7 @@ class Template_Previewer {
* Check if the current site is a member of
* the list of available templates
*/
if (!in_array($selected_template->get_id(), $site_ids, true)) {
if ( ! in_array($selected_template->get_id(), $site_ids, true)) {
$redirect_to = wu_get_current_url();
$redirect_to = add_query_arg($this->get_preview_parameter(), current($site_ids), $redirect_to);
@ -302,18 +289,13 @@ class Template_Previewer {
wp_redirect($redirect_to);
exit;
}
}
}
} // end if;
} // end if;
} // end if;
if (!isset($render_parameters['templates'])) {
if ( ! isset($render_parameters['templates'])) {
$render_parameters['templates'] = wu_get_site_templates();
} // end if;
}
$render_parameters['templates'] = array_filter((array) $render_parameters['templates'], fn($site) => $site->is_active());
@ -322,8 +304,7 @@ class Template_Previewer {
wu_get_template('ui/template-previewer', $render_parameters);
exit;
} // end template_previewer;
}
/**
* Returns the preview parameter, so admins can change it.
@ -336,8 +317,7 @@ class Template_Previewer {
$slug = $this->get_setting('preview_url_parameter', 'template-preview');
return apply_filters('wu_get_template_preview_slug', $slug);
} // end get_preview_parameter;
}
/**
* Checks if this is a template previewer window.
@ -350,8 +330,7 @@ class Template_Previewer {
$slug = $this->get_preview_parameter();
return wu_request($slug);
} // end is_template_previewer;
}
/**
* Check if the frame is a preview.
@ -361,9 +340,8 @@ class Template_Previewer {
*/
public function is_preview() {
return !empty(wu_request('wu-preview'));
} // end is_preview;
return ! empty(wu_request('wu-preview'));
}
/**
* Returns the settings.
@ -375,7 +353,7 @@ class Template_Previewer {
// Fix to issue on wp_get_attachment_url() inside core.
// @todo report it.
$initial_pagenow = $GLOBALS['pagenow'] ?? '';
$initial_pagenow = $GLOBALS['pagenow'] ?? '';
$GLOBALS['pagenow'] = '';
$default_settings = array(
@ -390,7 +368,7 @@ class Template_Previewer {
'enabled' => true,
);
$saved_settings = wu_get_option(Template_Previewer::KEY, array());
$saved_settings = wu_get_option(self::KEY, array());
$default_settings = array_merge($default_settings, $saved_settings);
@ -398,10 +376,8 @@ class Template_Previewer {
// Ensure that templates key does not change with request
if (isset($server_request['templates'])) {
unset($server_request['templates']);
} // end if;
}
$parsed_args = wp_parse_args($server_request, $default_settings);
@ -410,8 +386,7 @@ class Template_Previewer {
$GLOBALS['pagenow'] = $initial_pagenow;
return $parsed_args;
} // end get_settings;
}
/**
* Gets a particular setting.
@ -425,8 +400,7 @@ class Template_Previewer {
public function get_setting($setting, $default = false) {
return wu_get_isset($this->get_settings(), $setting, $default);
} // end get_setting;
}
/**
* Save settings.
@ -441,21 +415,15 @@ class Template_Previewer {
$settings = $this->get_settings();
foreach ($settings as $setting => $value) {
if ($setting === 'logo_url') {
$settings['logo_url'] = wu_get_network_logo();
continue;
}
} // end if;
$settings[ $setting ] = wu_get_isset($settings_to_save, $setting, false);
}
$settings[$setting] = wu_get_isset($settings_to_save, $setting, false);
} // end foreach;
return wu_save_option(Template_Previewer::KEY, $settings);
} // end save_settings;
} // end class Template_Previewer;
return wu_save_option(self::KEY, $settings);
}
}

View File

@ -9,8 +9,8 @@
namespace WP_Ultimo\UI;
use \WP_Ultimo\UI\Base_Element;
use \WP_Ultimo\Managers\Field_Templates_Manager;
use WP_Ultimo\UI\Base_Element;
use WP_Ultimo\Managers\Field_Templates_Manager;
// Exit if accessed directly
defined('ABSPATH') || exit;
@ -59,23 +59,20 @@ class Template_Switching_Element extends Base_Element {
protected $products;
/**
* The icon of the UI element.
* e.g. return fa fa-search
*
* @since 2.0.0
* @param string $context One of the values: block, elementor or bb.
*/
* The icon of the UI element.
* e.g. return fa fa-search
*
* @since 2.0.0
* @param string $context One of the values: block, elementor or bb.
*/
public function get_icon($context = 'block'): string {
if ($context === 'elementor') {
return 'eicon-cart-medium';
} // end if;
}
return 'fa fa-search';
} // end get_icon;
}
/**
* The title of the UI element.
@ -86,8 +83,7 @@ class Template_Switching_Element extends Base_Element {
public function get_title() {
return __('Template Switching', 'wp-ultimo');
} // end get_title;
}
/**
* The description of the UI element.
@ -98,8 +94,7 @@ class Template_Switching_Element extends Base_Element {
public function get_description() {
return __('Adds the template switching form to this page.', 'wp-ultimo');
} // end get_description;
}
/**
* Initializes the singleton.
@ -112,8 +107,7 @@ class Template_Switching_Element extends Base_Element {
add_action('wu_ajax_wu_switch_template', array($this, 'switch_template'));
parent::init();
} // end init;
}
/**
* Register element scripts.
@ -126,13 +120,16 @@ class Template_Switching_Element extends Base_Element {
wp_register_script('wu-template-switching', wu_get_asset('template-switching.js', 'js'), array('jquery', 'wu-vue-apps', 'wu-selectizer', 'wp-hooks', 'wu-cookie-helpers'));
wp_localize_script('wu-template-switching', 'wu_template_switching_params', array(
'ajaxurl' => wu_ajax_url(),
));
wp_localize_script(
'wu-template-switching',
'wu_template_switching_params',
array(
'ajaxurl' => wu_ajax_url(),
)
);
wp_enqueue_script('wu-template-switching');
} // end register_scripts;
}
/**
* The list of fields to be added to Gutenberg.
@ -177,8 +174,7 @@ class Template_Switching_Element extends Base_Element {
);
return $fields;
} // end fields;
}
/**
* The list of keywords for this element.
@ -195,8 +191,7 @@ class Template_Switching_Element extends Base_Element {
'Template',
'Template Switching',
);
} // end keywords;
}
/**
* List of default parameters for the element.
@ -206,17 +201,18 @@ class Template_Switching_Element extends Base_Element {
*/
public function defaults() {
$site_template_ids = wu_get_site_templates(array(
'fields' => 'ids',
));
$site_template_ids = wu_get_site_templates(
array(
'fields' => 'ids',
)
);
return array(
'slug' => 'template-switching',
'template_selection_template' => 'clean',
'template_selection_sites' => implode(',', $site_template_ids),
);
} // end defaults;
}
/**
* Runs early on the request lifecycle as soon as we detect the shortcode is present.
@ -228,13 +224,11 @@ class Template_Switching_Element extends Base_Element {
$this->site = wu_get_current_site();
if (!$this->site || !$this->site->is_customer_allowed()) {
if ( ! $this->site || ! $this->site->is_customer_allowed()) {
$this->set_display(false);
return;
} // end if;
}
$this->membership = $this->site->get_membership();
@ -243,22 +237,15 @@ class Template_Switching_Element extends Base_Element {
$all_membership_products = array();
if ($this->membership) {
$all_membership_products = $this->membership->get_all_products();
if (is_array($all_membership_products) && $all_membership_products) {
foreach ($all_membership_products as $product) {
$this->products[] = $product['product']->get_id();
} // end foreach;
} // end if;
} // end if;
} // end setup;
}
}
}
}
/**
* Runs early on the request lifecycle as soon as we detect the shortcode is present.
@ -270,8 +257,7 @@ class Template_Switching_Element extends Base_Element {
public function setup_preview() {
$this->site = wu_mock_site();
} // end setup_preview;
}
/**
* Ajax action to change the template for a given site.
@ -282,19 +268,15 @@ class Template_Switching_Element extends Base_Element {
*/
public function switch_template() {
if (!$this->site) {
if ( ! $this->site) {
$this->site = wu_get_current_site();
} // end if;
}
$template_id = wu_request('template_id', '');
if (!$template_id) {
if ( ! $template_id) {
return new \WP_Error('template_id_required', __('You need to provide a valid template to duplicate.', 'wp-ultimo'));
} // end if;
}
$switch = \WP_Ultimo\Helpers\Site_Duplicator::override_site($template_id, $this->site->get_id());
@ -308,16 +290,18 @@ class Template_Switching_Element extends Base_Element {
do_action('wu_after_switch_template', $this->site->get_id());
if ($switch) {
wp_send_json_success(array(
'redirect_url' => add_query_arg(array(
'updated' => 1,
), $_SERVER['HTTP_REFERER']),
));
} // end if;
} // end switch_template;
wp_send_json_success(
array(
'redirect_url' => add_query_arg(
array(
'updated' => 1,
),
$_SERVER['HTTP_REFERER']
),
)
);
}
}
/**
* The content to be output on the screen.
@ -335,18 +319,15 @@ class Template_Switching_Element extends Base_Element {
public function output($atts, $content = null) {
if ($this->site) {
$filter_template_limits = new \WP_Ultimo\Limits\Site_Template_Limits();
$atts['products'] = $this->products;
$template_selection_field = $filter_template_limits->maybe_filter_template_selection_options($atts);
if (!isset($template_selection_field['sites'])) {
if ( ! isset($template_selection_field['sites'])) {
$template_selection_field['sites'] = array();
} // end if;
}
$atts['template_selection_sites'] = implode(',', $template_selection_field['sites']);
@ -400,7 +381,7 @@ class Template_Switching_Element extends Base_Element {
'wrapper_classes' => '',
'value' => 0,
'html_attr' => array(
'v-model' => 'confirm_switch'
'v-model' => 'confirm_switch',
),
'wrapper_html_attr' => array(
'v-show' => 'template_id != 0 && template_id != original_template_id',
@ -416,7 +397,7 @@ class Template_Switching_Element extends Base_Element {
'wrapper_html_attr' => array(
'v-cloak' => 1,
'v-show' => 'confirm_switch',
'v-on:click.prevent' => 'ready = true'
'v-on:click.prevent' => 'ready = true',
),
);
@ -430,23 +411,25 @@ class Template_Switching_Element extends Base_Element {
$section_slug = 'wu-template-switching-form';
$form = new Form($section_slug, $checkout_fields, array(
'views' => 'admin-pages/fields',
'classes' => 'wu-striped wu-widget-inset',
'field_wrapper_classes' => 'wu-w-full wu-box-border wu-items-center wu-flex wu-justify-between wu-p-4 wu-py-5 wu-m-0 wu-border-t wu-border-l-0 wu-border-r-0 wu-border-b-0 wu-border-gray-300 wu-border-solid'
));
$form = new Form(
$section_slug,
$checkout_fields,
array(
'views' => 'admin-pages/fields',
'classes' => 'wu-striped wu-widget-inset',
'field_wrapper_classes' => 'wu-w-full wu-box-border wu-items-center wu-flex wu-justify-between wu-p-4 wu-py-5 wu-m-0 wu-border-t wu-border-l-0 wu-border-r-0 wu-border-b-0 wu-border-gray-300 wu-border-solid',
)
);
ob_start();
$form->render();
return ob_get_clean();
} // end if;
}
return '';
} // end output;
}
/**
* Returns the list of available pricing table templates.
@ -459,7 +442,5 @@ class Template_Switching_Element extends Base_Element {
$available_templates = Field_Templates_Manager::get_instance()->get_templates_as_options('template_selection');
return $available_templates;
} // end get_template_selection_templates;
} // end class Template_Switching_Element;
}
}

View File

@ -63,23 +63,20 @@ class Thank_You_Element extends Base_Element {
protected $customer;
/**
* The icon of the UI element.
* e.g. return fa fa-search
*
* @since 2.0.0
* @param string $context One of the values: block, elementor or bb.
*/
* The icon of the UI element.
* e.g. return fa fa-search
*
* @since 2.0.0
* @param string $context One of the values: block, elementor or bb.
*/
public function get_icon($context = 'block'): string {
if ($context === 'elementor') {
return 'eicon-info-circle-o';
} // end if;
}
return 'fa fa-search';
} // end get_icon;
}
/**
* Overload the init to add site-related forms.
@ -90,8 +87,7 @@ class Thank_You_Element extends Base_Element {
public function init() {
parent::init();
} // end init;
}
/**
* Replace the register page title with the Thank you title.
@ -106,8 +102,7 @@ class Thank_You_Element extends Base_Element {
$title_parts['title'] = $this->get_title();
return $title_parts;
} // end replace_page_title;
}
/**
* Maybe clear the title at the content level.
@ -123,14 +118,11 @@ class Thank_You_Element extends Base_Element {
global $post;
if ($post && $post->ID === $id) {
return '';
} // end if;
}
return $title;
} // end maybe_replace_page_title;
}
/**
* Register additional scripts for the thank you page.
@ -145,22 +137,25 @@ class Thank_You_Element extends Base_Element {
wp_register_script('wu-thank-you', wu_get_asset('thank-you.js', 'js'), array(), wu_get_version());
wp_localize_script('wu-thank-you', 'wu_thank_you', array(
'creating' => $is_publishing,
'has_pending_site' => $has_pending_site,
'next_queue' => wu_get_next_queue_run(),
'ajaxurl' => admin_url('admin-ajax.php'),
'resend_verification_email_nonce' => wp_create_nonce('wu_resend_verification_email_nonce'),
'membership_hash' => $this->membership ? $this->membership->get_hash() : false,
'i18n' => array(
'resending_verification_email' => __('Resending verification email...', 'wp-ultimo'),
'email_sent' => __('Verification email sent!', 'wp-ultimo'),
),
));
wp_localize_script(
'wu-thank-you',
'wu_thank_you',
array(
'creating' => $is_publishing,
'has_pending_site' => $has_pending_site,
'next_queue' => wu_get_next_queue_run(),
'ajaxurl' => admin_url('admin-ajax.php'),
'resend_verification_email_nonce' => wp_create_nonce('wu_resend_verification_email_nonce'),
'membership_hash' => $this->membership ? $this->membership->get_hash() : false,
'i18n' => array(
'resending_verification_email' => __('Resending verification email...', 'wp-ultimo'),
'email_sent' => __('Verification email sent!', 'wp-ultimo'),
),
)
);
wp_enqueue_script('wu-thank-you');
} // end register_scripts;
}
/**
* The title of the UI element.
@ -175,8 +170,7 @@ class Thank_You_Element extends Base_Element {
public function get_title() {
return __('Thank You', 'wp-ultimo');
} // end get_title;
}
/**
* The description of the UI element.
@ -192,8 +186,7 @@ class Thank_You_Element extends Base_Element {
public function get_description() {
return __('Adds a checkout form block to the page.', 'wp-ultimo');
} // end get_description;
}
/**
* The list of fields to be added to Gutenberg.
@ -272,8 +265,7 @@ class Thank_You_Element extends Base_Element {
);
return $fields;
} // end fields;
}
/**
* The list of keywords for this element.
@ -301,8 +293,7 @@ class Thank_You_Element extends Base_Element {
'Form',
'Cart',
);
} // end keywords;
}
/**
* List of default parameters for the element.
@ -327,8 +318,7 @@ class Thank_You_Element extends Base_Element {
'thank_you_message_pending' => __('Thank you for your order! We are waiting on the payment processor to confirm your payment, which can take up to 5 minutes. We will notify you via email when your site is ready.', 'wp-ultimo'),
'no_sites_message' => __('No sites found', 'wp-ultimo'),
);
} // end defaults;
}
/**
* Runs early on the request lifecycle as soon as we detect the shortcode is present.
@ -340,31 +330,26 @@ class Thank_You_Element extends Base_Element {
$this->payment = wu_get_payment_by_hash(wu_request('payment'));
if (!$this->payment) {
if ( ! $this->payment) {
$this->set_display(false);
return;
} // end if;
}
$this->membership = $this->payment->get_membership();
if (!$this->membership || !$this->membership->is_customer_allowed()) {
if ( ! $this->membership || ! $this->membership->is_customer_allowed()) {
$this->set_display(false);
return;
} // end if;
}
$this->customer = $this->membership->get_customer();
add_filter('document_title_parts', array($this, 'replace_page_title'));
add_filter('the_title', array($this, 'maybe_replace_page_title'), 10, 2);
} // end setup;
}
/**
* Allows the setup in the context of previews.
@ -379,8 +364,7 @@ class Thank_You_Element extends Base_Element {
$this->membership = wu_mock_membership();
$this->customer = wu_mock_customer();
} // end setup_preview;
}
/**
* The content to be output on the screen.
@ -410,45 +394,42 @@ class Thank_You_Element extends Base_Element {
*/
$conversion_snippets = $atts['checkout_form']->get_conversion_snippets();
if (!empty($conversion_snippets)) {
if ( ! empty($conversion_snippets)) {
$product_ids = array();
foreach ($this->payment->get_line_items() as $line_item) {
if ($line_item->get_product_id()) {
$product_ids[] = (string) $line_item->get_product_id();
}
}
} // end if;
} // end foreach;
$conversion_placeholders = apply_filters( 'wu_conversion_placeholders', array(
'CUSTOMER_ID' => $this->customer->get_id(),
'CUSTOMER_EMAIL' => $this->customer->get_email_address(),
'MEMBERSHIP_DURATION' => $this->membership->get_recurring_description(),
'MEMBERSHIP_PLAN' => $this->membership->get_plan_id(),
'MEMBERSHIP_AMOUNT' => $this->membership->get_amount(),
'ORDER_ID' => $this->payment->get_hash(),
'ORDER_CURRENCY' => $this->payment->get_currency(),
'ORDER_PRODUCTS' => array_values($product_ids),
'ORDER_AMOUNT' => $this->payment->get_total(),
));
$conversion_placeholders = apply_filters(
'wu_conversion_placeholders',
array(
'CUSTOMER_ID' => $this->customer->get_id(),
'CUSTOMER_EMAIL' => $this->customer->get_email_address(),
'MEMBERSHIP_DURATION' => $this->membership->get_recurring_description(),
'MEMBERSHIP_PLAN' => $this->membership->get_plan_id(),
'MEMBERSHIP_AMOUNT' => $this->membership->get_amount(),
'ORDER_ID' => $this->payment->get_hash(),
'ORDER_CURRENCY' => $this->payment->get_currency(),
'ORDER_PRODUCTS' => array_values($product_ids),
'ORDER_AMOUNT' => $this->payment->get_total(),
)
);
foreach ($conversion_placeholders as $placeholder => $value) {
$conversion_snippets = preg_replace('/\%\%\s?' . $placeholder . '\s?\%\%/', json_encode($value), (string) $conversion_snippets);
}
} // end foreach;
add_action(
'wp_print_footer_scripts',
function () use ($conversion_snippets) {
add_action('wp_print_footer_scripts', function() use ($conversion_snippets) {
echo $conversion_snippets;
});
} // end if;
echo $conversion_snippets;
}
);
}
/*
* Account for the 'className' Gutenberg attribute.
@ -456,7 +437,5 @@ class Thank_You_Element extends Base_Element {
$atts['className'] = trim('wu-' . $this->id . ' ' . wu_get_isset($atts, 'className', ''));
return wu_get_template_contents('dashboard-widgets/thank-you', $atts);
} // end output;
} // end class Thank_You_Element;
}
}

View File

@ -29,8 +29,7 @@ class Toolbox {
public function __construct() {
add_action('init', array($this, 'load_toolbox'));
} // end __construct;
}
/**
* Checks if we should add the toolbox or not.
@ -42,17 +41,14 @@ class Toolbox {
$can_see_toolbox = current_user_can('manage_network');
if (class_exists('\user_switching') && !$can_see_toolbox) {
if (class_exists('\user_switching') && ! $can_see_toolbox) {
$old_user = \user_switching::get_old_user();
$can_see_toolbox = user_can($old_user, 'manage_network');
}
} // end if;
return apply_filters('wu_is_toolbox_enabled', wu_get_setting('enable_jumper', true) && $can_see_toolbox && !is_network_admin());
} // end is_toolbox_enabled;
return apply_filters('wu_is_toolbox_enabled', wu_get_setting('enable_jumper', true) && $can_see_toolbox && ! is_network_admin());
}
/**
* Loads the necessary elements to display the Toolbox.
@ -63,16 +59,13 @@ class Toolbox {
public function load_toolbox() {
if ($this->is_toolbox_enabled()) {
add_action('wp_footer', array($this, 'output'));
add_action('admin_footer', array($this, 'output'));
add_action('wp_enqueue_scripts', array($this, 'enqueue_styles'));
} // end if;
} // end load_toolbox;
}
}
/**
* Adds the admin styles to make sure the tooltip renders.
@ -83,8 +76,7 @@ class Toolbox {
public function enqueue_styles() {
wp_enqueue_style('wu-admin');
} // end enqueue_styles;
}
/**
* Outputs the actual HTML markup of the Toolbox.
@ -96,13 +88,14 @@ class Toolbox {
$current_site = wu_get_current_site();
wu_get_template('ui/toolbox', array(
'toolbox' => $this,
'current_site' => $current_site,
'customer' => $current_site ? $current_site->get_customer() : false,
'membership' => $current_site ? $current_site->get_membership() : false,
));
} // end output;
} // end class Toolbox;
wu_get_template(
'ui/toolbox',
array(
'toolbox' => $this,
'current_site' => $current_site,
'customer' => $current_site ? $current_site->get_customer() : false,
'membership' => $current_site ? $current_site->get_membership() : false,
)
);
}
}

View File

@ -41,8 +41,7 @@ class Tours {
add_action('admin_enqueue_scripts', array($this, 'register_scripts'));
add_action('in_admin_footer', array($this, 'enqueue_scripts'));
} // end __construct;
}
/**
* Mark the tour as finished for a particular user.
@ -57,16 +56,13 @@ class Tours {
$id = wu_request('tour_id');
if ($id) {
set_user_setting("wu_tour_$id", true);
wp_send_json_success();
} // end if;
}
wp_send_json_error();
} // end mark_as_finished;
}
/**
* Register the necessary scripts.
@ -79,8 +75,7 @@ class Tours {
WP_Ultimo()->scripts->register_script('wu-shepherd', wu_get_asset('lib/shepherd.js', 'js'), array());
WP_Ultimo()->scripts->register_script('wu-tours', wu_get_asset('tours.js', 'js'), array('wu-shepherd', 'underscore'));
} // end register_scripts;
}
/**
* Enqueues the scripts, if we need to.
@ -91,23 +86,24 @@ class Tours {
public function enqueue_scripts() {
if ($this->has_tours()) {
wp_localize_script('wu-tours', 'wu_tours', $this->tours);
wp_localize_script('wu-tours', 'wu_tours_vars', array(
'ajaxurl' => wu_ajax_url(),
'nonce' => wp_create_nonce('wu_tour_finished'),
'i18n' => array(
'next' => __('Next', 'wp-ultimo'),
'finish' => __('Close', 'wp-ultimo')
),
));
wp_localize_script(
'wu-tours',
'wu_tours_vars',
array(
'ajaxurl' => wu_ajax_url(),
'nonce' => wp_create_nonce('wu_tour_finished'),
'i18n' => array(
'next' => __('Next', 'wp-ultimo'),
'finish' => __('Close', 'wp-ultimo'),
),
)
);
wp_enqueue_script('wu-tours');
} // end if;
} // end enqueue_scripts;
}
}
/**
* Checks if we have registered tours.
@ -117,9 +113,8 @@ class Tours {
*/
public function has_tours() {
return !empty($this->tours);
} // end has_tours;
return ! empty($this->tours);
}
/**
* Register a new tour.
@ -136,41 +131,33 @@ class Tours {
public function create_tour($id, $steps = array(), $once = true) {
if (did_action('in_admin_header')) {
return;
}
} // end if;
add_action(
'in_admin_header',
function () use ($id, $steps, $once) {
add_action('in_admin_header', function() use ($id, $steps, $once) {
$force_hide = wu_get_setting('hide_tours', false);
$force_hide = wu_get_setting('hide_tours', false);
if ($force_hide) {
return;
}
if ($force_hide) {
$finished = (bool) get_user_setting("wu_tour_$id", false);
return;
$finished = apply_filters('wu_tour_finished', $finished, $id, get_current_user_id());
} // end if;
if ( ! $finished || ! $once) {
foreach ($steps as &$step) {
$step['text'] = is_array($step['text']) ? implode('</p><p>', $step['text']) : $step['text'];
$finished = (bool) get_user_setting("wu_tour_$id", false);
$step['text'] = sprintf('<p>%s</p>', $step['text']);
}
$finished = apply_filters('wu_tour_finished', $finished, $id, get_current_user_id());
if (!$finished || !$once) {
foreach ($steps as &$step) {
$step['text'] = is_array($step['text']) ? implode('</p><p>', $step['text']) : $step['text'];
$step['text'] = sprintf('<p>%s</p>', $step['text']);
} // end foreach;
$this->tours[$id] = $steps;
} // end if;
});
} // end create_tour;
} // end class Tours;
$this->tours[ $id ] = $steps;
}
}
);
}
}