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

@ -27,11 +27,18 @@
<!-- https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards -->
<!-- https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Customizable-sniff-properties -->
<config name="minimum_supported_wp_version" value="5.3"/>
<rule ref="WordPress"/>
<rule ref="WordPress">
<exclude name="Squiz.Commenting.InlineComment.InvalidEndChar" />
<exclude name="WordPress.WhiteSpace.ControlStructureSpacing.NoSpaceAfterOpenParenthesis" />
<exclude name="WordPress.WhiteSpace.ControlStructureSpacing.NoSpaceBeforeCloseParenthesis" />
<exclude name="Squiz.Commenting.VariableComment.Missing" />
<exclude name="WordPress.WhiteSpace.CastStructureSpacing.NoSpaceBeforeOpenParenthesis" />
<exclude name="WordPress.WhiteSpace.OperatorSpacing.NoSpaceBefore" />
</rule>
<rule ref="WordPress.NamingConventions.PrefixAllGlobals">
<properties>
<!-- Value: replace the function, class, and variable prefixes used. Separate multiple prefixes with a comma. -->
<property name="prefixes" type="array" value="my-plugin"/>
<property name="prefixes" type="array" value="wu_,wp_ultimo"/>
</properties>
</rule>
<rule ref="WordPress.WP.I18n">
@ -45,4 +52,28 @@
<property name="blank_line_check" value="true"/>
</properties>
</rule>
<rule ref="PEAR.Functions.FunctionCallSignature">
<properties>
<property name="requiredSpacesAfterOpen" value="0"/>
<property name="requiredSpacesBeforeClose" value="0"/>
</properties>
</rule>
<rule ref="NormalizedArrays.Arrays.ArrayBraceSpacing">
<properties>
<property name="spacesSingleLine" value="0"/>
</properties>
</rule>
<rule ref="Squiz.Functions.FunctionDeclarationArgumentSpacing">
<properties>
<property name="equalsSpacing" value="1"/>
<property name="requiredSpacesAfterOpen" value="0"/>
<property name="requiredSpacesBeforeClose" value="0"/>
</properties>
</rule>
<rule ref="Generic.WhiteSpace.ArbitraryParenthesesSpacing">
<properties>
<property name="spacing" value="0"/>
<property name="ignoreNewlines" value="true"/>
</properties>
</rule>
</ruleset>

View File

@ -42,7 +42,8 @@
"symfony/cache": "v5.4.29",
"scssphp/scssphp": "v1.11.1",
"cweagans/composer-patches": "^1.7",
"woocommerce/action-scheduler": "^3.9.1"
"woocommerce/action-scheduler": "^3.9.1",
"ext-json": "*"
},
"require-dev": {
"composer/installers": "1.9.0",

View File

@ -11,21 +11,15 @@ defined('ABSPATH') || exit;
// Plugin Folder Path
if ( ! defined('WP_ULTIMO_PLUGIN_DIR')) {
define('WP_ULTIMO_PLUGIN_DIR', plugin_dir_path(WP_ULTIMO_PLUGIN_FILE));
} // end if;
// Plugin Folder URL
if ( ! defined('WP_ULTIMO_PLUGIN_URL')) {
define('WP_ULTIMO_PLUGIN_URL', plugin_dir_url(WP_ULTIMO_PLUGIN_FILE));
} // end if;
// Plugin Root File
if ( ! defined('WP_ULTIMO_PLUGIN_BASENAME')) {
define('WP_ULTIMO_PLUGIN_BASENAME', plugin_basename(WP_ULTIMO_PLUGIN_FILE));
} // end if;

View File

@ -87,8 +87,7 @@ class About_Admin_Page extends Base_Admin_Page {
public function get_title() {
return __('About', 'wp-ultimo');
} // end get_title;
}
/**
* Returns the title of menu for this page.
@ -99,8 +98,7 @@ class About_Admin_Page extends Base_Admin_Page {
public function get_menu_title() {
return __('Multisite WaaS', 'wp-ultimo');
} // end get_menu_title;
}
/**
* Allows admins to rename the sub-menu (first item) for a top-level page.
@ -111,8 +109,7 @@ class About_Admin_Page extends Base_Admin_Page {
public function get_submenu_title() {
return __('About', 'wp-ultimo');
} // end get_submenu_title;
}
/**
* Every child class should implement the output method to display the contents of the page.
@ -123,8 +120,7 @@ class About_Admin_Page extends Base_Admin_Page {
public function output() {
wu_get_template('about');
} // end output;
}
/**
* Adds the cure bg image here as well.
@ -136,12 +132,16 @@ class About_Admin_Page extends Base_Admin_Page {
parent::register_scripts();
wp_add_inline_style('wu-admin', sprintf('
wp_add_inline_style(
'wu-admin',
sprintf(
'
#wpwrap {
background: url("%s") right bottom no-repeat;
background-size: 60%%;
}', wu_get_asset('bg-setup.png', 'img')));
} // end register_scripts;
} // end class About_Admin_Page;
}',
wu_get_asset('bg-setup.png', 'img')
)
);
}
}

View File

@ -173,12 +173,10 @@ abstract class Base_Admin_Page {
* Adds the page to all the necessary admin panels.
*/
foreach ($this->supported_panels as $panel => $capability) {
add_action($panel, array($this, 'add_menu_page'));
add_action($panel, array($this, 'fix_subdomain_name'), 100);
} // end foreach;
}
/*
* Delegates further initializations to the child class.
@ -202,8 +200,7 @@ abstract class Base_Admin_Page {
* @return void
*/
do_action('wu_page_added', $this->id, $this->page_hook);
} // end __construct;
}
/**
* Returns the ID of the admin page.
@ -214,8 +211,7 @@ abstract class Base_Admin_Page {
public function get_id() {
return $this->id;
} // end get_id;
}
/**
* Returns the appropriate capability for a this page, depending on the context.
@ -226,18 +222,13 @@ abstract class Base_Admin_Page {
public function get_capability() {
if (is_user_admin()) {
return $this->supported_panels['user_admin_menu'];
} elseif (is_network_admin()) {
return $this->supported_panels['network_admin_menu'];
} // end if;
}
return $this->supported_panels['admin_menu'];
} // end get_capability;
}
/**
* Fix the subdomain name if an option (submenu title) is passed.
@ -250,12 +241,9 @@ abstract class Base_Admin_Page {
global $submenu;
if ($this->get_submenu_title() && $this->type === 'menu' && isset($submenu[ $this->id ]) && $submenu[ $this->id ][0][3] === $this->get_title()) {
$submenu[ $this->id ][0][0] = $this->get_submenu_title();
} // end if;
} // end fix_subdomain_name;
}
}
/**
* Fix the highlight Menu.
@ -269,16 +257,13 @@ abstract class Base_Admin_Page {
global $plugin_page;
if ($this->highlight_menu_slug && isset($_GET['page']) && $_GET['page'] === $this->get_id()) {
$plugin_page = $this->highlight_menu_slug;
$file = $this->highlight_menu_slug;
} // end if;
}
return $file;
} // end fix_menu_highlight;
}
/**
* Install the base hooks for developers
@ -327,8 +312,7 @@ abstract class Base_Admin_Page {
add_filter('parent_file', array($this, 'fix_menu_highlight'), 99);
add_filter('submenu_file', array($this, 'fix_menu_highlight'), 99);
} // end install_hooks;
}
/**
* Get the badge value, to append to the menu item title.
@ -343,8 +327,7 @@ abstract class Base_Admin_Page {
</span>';
return $this->badge_count >= 1 ? sprintf($markup, $this->badge_count, $this->badge_count) : '';
} // end get_badge;
}
/**
* Displays the page content.
@ -359,13 +342,15 @@ abstract class Base_Admin_Page {
*
* @todo review when possible.
*/
add_filter('wp_ultimo_render_vars', function($vars) {
add_filter(
'wp_ultimo_render_vars',
function ($vars) {
$vars['page_title'] = $this->get_title();
return $vars;
});
}
);
/**
* Allow plugin developers to add additional content before we print the page.
@ -407,8 +392,7 @@ abstract class Base_Admin_Page {
* @return void
*/
do_action("wu_page_{$this->id}_after_render", $this->id, $this);
} // end display;
}
/**
* Get the menu item, with the badge if necessary.
@ -419,8 +403,7 @@ abstract class Base_Admin_Page {
public function get_menu_label() {
return $this->get_menu_title() . $this->get_badge();
} // end get_menu_label;
}
/**
* Adds the menu items using default WordPress functions and handles the side-effects
@ -439,8 +422,7 @@ abstract class Base_Admin_Page {
* Add the default hooks
*/
$this->enqueue_default_hooks();
} // end add_menu_page;
}
/**
* Adds top-level admin page.
@ -451,10 +433,8 @@ abstract class Base_Admin_Page {
public function add_toplevel_menu_page() {
if (wu_request('id')) {
$this->edit = true;
} // end if;
}
return add_menu_page(
$this->get_title(),
@ -465,8 +445,7 @@ abstract class Base_Admin_Page {
$this->menu_icon,
$this->position
);
} // end add_toplevel_menu_page;
}
/**
* Adds sub-pages.
@ -477,10 +456,8 @@ abstract class Base_Admin_Page {
public function add_submenu_page() {
if (wu_request('id')) {
$this->edit = true;
} // end if;
}
return add_submenu_page(
$this->parent,
@ -490,8 +467,7 @@ abstract class Base_Admin_Page {
$this->id,
array($this, 'display')
);
} // end add_submenu_page;
}
/**
* Adds WP Multisite WaaS branding to this page, if that's the case.
@ -502,7 +478,6 @@ abstract class Base_Admin_Page {
public function add_branding() {
if (apply_filters('wp_ultimo_remove_branding', false) === false) {
add_action('in_admin_header', array($this, 'brand_header'));
add_action('wu_header_right', array($this, 'add_container_toggle'));
@ -512,10 +487,8 @@ abstract class Base_Admin_Page {
add_filter('admin_footer_text', '__return_empty_string', 1000);
add_filter('update_footer', '__return_empty_string', 1000);
} // end if;
} // end add_branding;
}
}
/**
* Adds the Jumper trigger to the admin top pages.
@ -525,11 +498,13 @@ abstract class Base_Admin_Page {
*/
public function add_container_toggle() {
wu_get_template('ui/container-toggle', array(
wu_get_template(
'ui/container-toggle',
array(
'page' => $this,
));
} // end add_container_toggle;
)
);
}
/**
* Adds the WP Multisite WaaS branding header.
@ -539,11 +514,13 @@ abstract class Base_Admin_Page {
*/
public function brand_header() {
wu_get_template('ui/branding/header', array(
wu_get_template(
'ui/branding/header',
array(
'page' => $this,
));
} // end brand_header;
)
);
}
/**
* Adds the WP Multisite WaaS branding footer.
@ -553,11 +530,13 @@ abstract class Base_Admin_Page {
*/
public function brand_footer() {
wu_get_template('ui/branding/footer', array(
wu_get_template(
'ui/branding/footer',
array(
'page' => $this,
));
} // end brand_footer;
)
);
}
/**
* Injects our admin classes to the admin body classes.
@ -567,37 +546,30 @@ abstract class Base_Admin_Page {
*/
public function add_admin_body_classes() {
add_action('admin_body_class', function($classes) {
add_action(
'admin_body_class',
function ($classes) {
if ($this->hide_admin_notices) {
$classes .= ' wu-hide-admin-notices';
} // end if;
}
if ($this->fold_menu) {
$classes .= ' folded';
} // end if;
}
if ($this->remove_frame) {
$classes .= ' wu-remove-frame folded';
} // end if;
}
if (is_network_admin()) {
$classes .= ' wu-network-admin';
} // end if;
}
return "$classes wu-page-{$this->id} wu-styling hover:wu-styling first:wu-styling odd:wu-styling";
});
} // end add_admin_body_classes;
}
);
}
/**
* Register the default hooks.
@ -610,7 +582,6 @@ abstract class Base_Admin_Page {
final public function enqueue_default_hooks() {
if ($this->page_hook) {
add_action("load-$this->page_hook", array($this, 'install_hooks'));
add_action("load-$this->page_hook", array($this, 'page_loaded'));
@ -629,10 +600,8 @@ abstract class Base_Admin_Page {
* Add the page to WP Multisite WaaS branding (aka top-bar and footer)
*/
if (is_network_admin()) {
add_action("load-$this->page_hook", array($this, 'add_branding'));
} // end if;
}
/**
* Allow plugin developers to add additional hooks
@ -641,10 +610,8 @@ abstract class Base_Admin_Page {
* @param string
*/
do_action('wu_enqueue_extra_hooks', $this->page_hook);
} // end if;
} // end enqueue_default_hooks;
}
}
/**
* Returns an array with the title links.
@ -655,14 +622,12 @@ abstract class Base_Admin_Page {
public function get_title_links() {
if (wu_get_documentation_url($this->get_id(), false)) {
$this->action_links[] = array(
'url' => wu_get_documentation_url($this->get_id()),
'label' => __('Documentation'),
'icon' => 'wu-open-book',
);
} // end if;
}
/**
* Allow plugin developers, and ourselves, to add action links to our edit pages
@ -672,8 +637,7 @@ abstract class Base_Admin_Page {
* @return array
*/
return apply_filters('wu_page_get_title_links', $this->action_links, $this);
} // end get_title_links;
}
/**
* Allows child classes to register their own title links.
@ -684,8 +648,7 @@ abstract class Base_Admin_Page {
public function action_links() {
return array();
} // end action_links;
}
/**
* Allow child classes to add further initializations.
@ -693,7 +656,7 @@ abstract class Base_Admin_Page {
* @since 1.8.2
* @return void
*/
public function init() {} // end init;
public function init() {}
/**
* Allow child classes to add further initializations, but only after the page is loaded.
@ -701,7 +664,7 @@ abstract class Base_Admin_Page {
* @since 1.8.2
* @return void
*/
public function page_loaded() {} // end page_loaded;
public function page_loaded() {}
/**
* Allow child classes to add hooks to be run once the page is loaded.
@ -710,7 +673,7 @@ abstract class Base_Admin_Page {
* @since 1.8.2
* @return void
*/
public function hooks() {} // end hooks;
public function hooks() {}
/**
* Allow child classes to add screen options; Useful for pages that have list tables.
@ -718,7 +681,7 @@ abstract class Base_Admin_Page {
* @since 1.8.2
* @return void
*/
public function screen_options() {} // end screen_options;
public function screen_options() {}
/**
* Allow child classes to register scripts and styles that can be loaded on the output function, for example.
@ -726,7 +689,7 @@ abstract class Base_Admin_Page {
* @since 1.8.2
* @return void
*/
public function register_scripts() {} // end register_scripts;
public function register_scripts() {}
/**
* Allow child classes to register widgets, if they need them.
@ -734,7 +697,7 @@ abstract class Base_Admin_Page {
* @since 1.8.2
* @return void
*/
public function register_widgets() {} // end register_widgets;
public function register_widgets() {}
/**
* Allow child classes to register forms, if they need them.
@ -742,7 +705,7 @@ abstract class Base_Admin_Page {
* @since 2.0.0
* @return void
*/
public function register_forms() {} // end register_forms;
public function register_forms() {}
/**
* Returns the title of the page. Must be declared on the child classes.
@ -769,8 +732,7 @@ abstract class Base_Admin_Page {
public function get_submenu_title() {
return false;
} // end get_submenu_title;
}
/**
* Every child class should implement the output method to display the contents of the page.
@ -778,6 +740,5 @@ abstract class Base_Admin_Page {
* @since 1.8.2
* @return void
*/
abstract public function output(); // end output;
} // end class Base_Admin_Page;
abstract public function output();
}

View File

@ -12,7 +12,7 @@ namespace WP_Ultimo\Admin_Pages;
// Exit if accessed directly
defined('ABSPATH') || exit;
use \WP_Ultimo\Admin_Pages\Base_Admin_Page;
use WP_Ultimo\Admin_Pages\Base_Admin_Page;
/**
* Abstract class that adds customizability to customer facing pages.
@ -74,15 +74,17 @@ abstract class Base_Customer_Facing_Admin_Page extends Base_Admin_Page {
add_action('updated_user_meta', array($this, 'save_settings'), 10, 4);
wu_register_form("edit_admin_page_$this->id", array(
wu_register_form(
"edit_admin_page_$this->id",
array(
'render' => array($this, 'render_edit_page'),
'handler' => array($this, 'handle_edit_page'),
'capability' => 'exist',
));
)
);
$this->register_page_settings();
} // end init;
}
/**
* Saves the original parameters and change them with the settings saved.
@ -104,8 +106,7 @@ abstract class Base_Customer_Facing_Admin_Page extends Base_Admin_Page {
$this->menu_title = wu_get_isset($new_parameters, 'title', $this->original_parameters['title']);
$this->position = wu_get_isset($new_parameters, 'position', $this->original_parameters['position']);
$this->menu_icon = str_replace('dashicons-before', '', (string) wu_get_isset($new_parameters, 'menu_icon', $this->original_parameters['menu_icon'] ?? ''));
} // end change_parameters;
}
/**
* Renders the edit page form.
@ -127,7 +128,6 @@ abstract class Base_Customer_Facing_Admin_Page extends Base_Admin_Page {
);
if ($this->menu_settings) {
$fields['position'] = array(
'type' => 'number',
'title' => __('Menu', 'wp-ultimo'),
@ -141,8 +141,7 @@ abstract class Base_Customer_Facing_Admin_Page extends Base_Admin_Page {
'value' => wu_get_isset($settings, 'menu_icon', ''),
'tooltip' => '',
);
} // end if;
}
$fields['save_line'] = array(
'type' => 'group',
@ -168,7 +167,10 @@ abstract class Base_Customer_Facing_Admin_Page extends Base_Admin_Page {
$fields = apply_filters("wu_customer_facing_page_{$this->id}_fields", $fields);
$form = new \WP_Ultimo\UI\Form('edit_page', $fields, array(
$form = new \WP_Ultimo\UI\Form(
'edit_page',
$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',
@ -176,15 +178,15 @@ abstract class Base_Customer_Facing_Admin_Page extends Base_Admin_Page {
'data-wu-app' => "{$this->id}_page_customize",
'data-state' => wu_convert_to_state(),
),
));
)
);
echo '<div class="wu-styling">';
$form->render();
echo '</div>';
} // end render_edit_page;
}
/**
* Handles the edit page form and saved changes.
@ -198,11 +200,12 @@ abstract class Base_Customer_Facing_Admin_Page extends Base_Admin_Page {
$this->save_page_settings($settings_to_save);
wp_send_json_success(array(
wp_send_json_success(
array(
'redirect_url' => add_query_arg('updated', 1, $_SERVER['HTTP_REFERER']),
));
} // end handle_edit_page;
)
);
}
/**
* Generates a unique id for each page based on the class name.
@ -217,8 +220,7 @@ abstract class Base_Customer_Facing_Admin_Page extends Base_Admin_Page {
$class_name = array_pop($class_name_array);
return wu_replace_dashes(strtolower($class_name));
} // end get_page_unique_id;
}
/**
* Grabs the original page parameters.
@ -229,8 +231,7 @@ abstract class Base_Customer_Facing_Admin_Page extends Base_Admin_Page {
public function get_defaults() {
return $this->original_parameters;
} // end get_defaults;
}
/**
* Register the default setting on the core section.
@ -240,11 +241,14 @@ abstract class Base_Customer_Facing_Admin_Page extends Base_Admin_Page {
*/
public function register_page_settings() {
wu_register_settings_field('core', $this->get_page_unique_id() . '_settings', array(
wu_register_settings_field(
'core',
$this->get_page_unique_id() . '_settings',
array(
'raw' => true,
));
} // end register_page_settings;
)
);
}
/**
* Get the page settings saved.
@ -257,8 +261,7 @@ abstract class Base_Customer_Facing_Admin_Page extends Base_Admin_Page {
$atts = wu_get_setting($this->get_page_unique_id() . '_settings', array());
return wp_parse_args($atts, $this->get_defaults());
} // end get_page_settings;
}
/**
* Saves the page settings.
@ -273,8 +276,7 @@ abstract class Base_Customer_Facing_Admin_Page extends Base_Admin_Page {
$atts = shortcode_atts($this->get_defaults(), $settings); // Use shortcode atts to remove unauthorized params.
return wu_save_setting($this->get_page_unique_id() . '_settings', $atts);
} // end save_page_settings;
}
/**
* Adds additional hooks using the right hook on the page lifecycle.
@ -289,8 +291,7 @@ abstract class Base_Customer_Facing_Admin_Page extends Base_Admin_Page {
add_action("load-$this->page_hook", array($this, 'add_additional_body_classes'));
add_action("load-$this->page_hook", array($this, 'additional_on_page_load'));
} // end additional_hooks;
}
/**
* Registers additional hooks for the page load.
@ -311,15 +312,17 @@ abstract class Base_Customer_Facing_Admin_Page extends Base_Admin_Page {
*
* @todo review when possible.
*/
add_filter('wp_ultimo_render_vars', function($vars) {
add_filter(
'wp_ultimo_render_vars',
function ($vars) {
$vars['page_title'] = $this->title;
return $vars;
}, 15);
} // end additional_on_page_load;
},
15
);
}
/**
* Adds additional body classes for styling control purposes.
@ -329,15 +332,16 @@ abstract class Base_Customer_Facing_Admin_Page extends Base_Admin_Page {
*/
public function add_additional_body_classes() {
add_action('admin_body_class', function($classes) {
add_action(
'admin_body_class',
function ($classes) {
$classes .= $this->is_edit_mode() ? ' wu-customize-admin-screen' : '';
return $classes;
});
} // end add_additional_body_classes;
}
);
}
/**
* Registers and enqueues additional scripts and styles required.
@ -352,16 +356,16 @@ abstract class Base_Customer_Facing_Admin_Page extends Base_Admin_Page {
wp_enqueue_style('wu-admin-screen');
if ($this->is_edit_mode()) {
wp_enqueue_script('dashboard');
} // end if;
}
if (current_user_can($this->edit_capability)) {
\WP_Ultimo\Scripts::get_instance()->register_script('wu-admin-screen', wu_get_asset('admin-screen.js', 'js'), array('jquery', 'wu-fonticonpicker'));
wp_localize_script('wu-admin-screen', 'wu_admin_screen', array(
wp_localize_script(
'wu-admin-screen',
'wu_admin_screen',
array(
'page_customize_link' => wu_get_form_url("edit_admin_page_$this->id"),
'customize_link' => add_query_arg('customize', 1),
'close_link' => remove_query_arg('customize'),
@ -370,13 +374,12 @@ abstract class Base_Customer_Facing_Admin_Page extends Base_Admin_Page {
'customize_label' => __('Customize Elements', 'wp-ultimo'),
'close_label' => __('Exit Customize Mode', 'wp-ultimo'),
),
));
)
);
wp_enqueue_script('wu-admin-screen');
} // end if;
} // end register_additional_scripts;
}
}
/**
* Filters the order and columns of the widgets to return a globally saved value.
@ -395,8 +398,7 @@ abstract class Base_Customer_Facing_Admin_Page extends Base_Admin_Page {
$saved = wu_get_setting($option);
return empty($saved) ? $result : $saved;
} // end get_settings;
}
/**
* Save the settings globally for columns and order of the widgets.
@ -412,30 +414,23 @@ abstract class Base_Customer_Facing_Admin_Page extends Base_Admin_Page {
public function save_settings($meta_id, $user_id, $meta_key, $_meta_value) {
if (wu_request('action') !== 'meta-box-order') {
return;
} // end if;
}
$is_this_page = strpos((string) wu_request('page'), $this->id) !== false;
if ( ! $is_this_page) {
return;
} // end if;
}
if ( ! user_can($user_id, $this->edit_capability)) {
return;
} // end if;
}
$meta_key = wu_replace_dashes($meta_key);
wu_save_setting($meta_key, $_meta_value);
} // end save_settings;
}
/**
* Get the value of editing.
@ -446,8 +441,7 @@ abstract class Base_Customer_Facing_Admin_Page extends Base_Admin_Page {
public function is_edit_mode() {
return $this->editing && current_user_can($this->edit_capability);
} // end is_edit_mode;
}
/**
* Adds top-level admin page.
@ -458,10 +452,8 @@ abstract class Base_Customer_Facing_Admin_Page extends Base_Admin_Page {
public function add_toplevel_menu_page() {
if (wu_request('id')) {
$this->edit = true;
} // end if;
}
return add_menu_page(
$this->title,
@ -472,7 +464,5 @@ abstract class Base_Customer_Facing_Admin_Page extends Base_Admin_Page {
$this->menu_icon,
$this->position
);
} // end add_toplevel_menu_page;
} // end class Base_Customer_Facing_Admin_Page;
}
}

View File

@ -12,7 +12,7 @@ namespace WP_Ultimo\Admin_Pages;
// Exit if accessed directly
defined('ABSPATH') || exit;
use \WP_Ultimo\Models\Broadcast;
use WP_Ultimo\Models\Broadcast;
/**
* WP Multisite WaaS Broadcast Edit/Add New Admin Page.
@ -90,18 +90,25 @@ class Broadcast_Edit_Admin_Page extends Edit_Admin_Page {
parent::register_widgets();
$this->add_list_table_widget('events', array(
$this->add_list_table_widget(
'events',
array(
'title' => __('Events', 'wp-ultimo'),
'table' => new \WP_Ultimo\List_Tables\Inside_Events_List_Table(),
'query_filter' => array($this, 'events_query_filter'),
));
)
);
$this->add_save_widget('save', array(
$this->add_save_widget(
'save',
array(
'html_attr' => array(
'data-wu-app' => 'save_broadcast',
'data-state' => wu_convert_to_state(array(
'data-state' => wu_convert_to_state(
array(
'type' => $this->get_object()->get_type(),
)),
)
),
),
'fields' => array(
'type' => array(
@ -117,8 +124,8 @@ class Broadcast_Edit_Admin_Page extends Edit_Admin_Page {
'tooltip' => '',
'html_attr' => array(
'disabled' => 'disabled',
'name' => ''
)
'name' => '',
),
),
'notice_type' => array(
'type' => 'select',
@ -136,16 +143,16 @@ class Broadcast_Edit_Admin_Page extends Edit_Admin_Page {
'wrapper_html_attr' => array(
'v-if' => 'type === "broadcast_notice"',
'v-cloak' => 1,
),
),
),
)
),
),
));
);
add_meta_box('wp-ultimo-broadcast-customer-targets', __('Customer Targets', 'wp-ultimo'), array($this, 'output_default_widget_customer_targets'), get_current_screen()->id, 'side');
add_meta_box('wp-ultimo-broadcast-product-targets', __('Product Targets', 'wp-ultimo'), array($this, 'output_default_widget_product_targets'), get_current_screen()->id, 'side');
} // end register_widgets;
}
/**
* Outputs the markup for the customer targets widget.
@ -164,16 +171,12 @@ class Broadcast_Edit_Admin_Page extends Edit_Admin_Page {
$customer_targets = wu_get_isset($all_targets, 'customers', '');
if ($customer_targets) {
if (is_array($all_targets['customers'])) {
$all_targets['customers'] = $all_targets['customers'][0];
} // end if;
}
$targets = explode(',', (string) $all_targets['customers']);
} // end if;
}
$targets_count = count($targets);
@ -201,10 +204,16 @@ class Broadcast_Edit_Admin_Page extends Edit_Admin_Page {
$customer_link = wu_network_admin_url('wp-ultimo-edit-customer', $url_atts);
$avatar = get_avatar($customer->get_user_id(), 32, 'identicon', '', array(
$avatar = get_avatar(
$customer->get_user_id(),
32,
'identicon',
'',
array(
'force_display' => true,
'class' => 'wu-rounded-full wu-border-solid wu-border-1 wu-border-white hover:wu-border-gray-400',
));
)
);
$display_name = $customer->get_display_name();
@ -222,16 +231,21 @@ class Broadcast_Edit_Admin_Page extends Edit_Admin_Page {
break;
case $targets_count > 1:
foreach ($targets as $key => $target) {
$customer = wu_get_customer($target);
$tooltip_name = $customer->get_display_name();
$email = $customer->get_email_address();
$avatar = get_avatar($email, 32, 'identicon', '', array(
$avatar = get_avatar(
$email,
32,
'identicon',
'',
array(
'class' => 'wu-rounded-full wu-border-solid wu-border-1 wu-border-white hover:wu-border-gray-400',
));
)
);
$url_atts = array(
'id' => $customer->get_id(),
@ -240,11 +254,9 @@ class Broadcast_Edit_Admin_Page extends Edit_Admin_Page {
$customer_link = wu_network_admin_url('wp-ultimo-edit-customer', $url_atts);
$html .= "<div class='wu-flex wu--mr-4'><a role='tooltip' aria-label='{$tooltip_name}' href='{$customer_link}'>{$avatar}</a></div>";
} // end foreach;
}
if ($targets_count < 7) {
$modal_atts = array(
'action' => 'wu_modal_targets_display',
'object_id' => $object->get_id(),
@ -253,12 +265,16 @@ class Broadcast_Edit_Admin_Page extends Edit_Admin_Page {
'target_type' => 'customers',
);
$html .= sprintf('<div class="wu-inline-block wu--mr-4">
$html .= sprintf(
'<div class="wu-inline-block wu--mr-4">
<a href="%s" title="%s" class="wubox wu-no-underline"><span class="wu-ml-6 wu-uppercase wu-text-xs wu-text-gray-600 wu-font-bold"> %s %s</span></a>
</div>', wu_get_form_url('view_broadcast_targets', $modal_atts), __('Targets', 'wp-ultimo'), $targets_count, __('Targets', 'wp-ultimo'));
</div>',
wu_get_form_url('view_broadcast_targets', $modal_atts),
__('Targets', 'wp-ultimo'),
$targets_count,
__('Targets', 'wp-ultimo')
);
} else {
$count = $targets_count - 6;
$modal_atts = array(
@ -269,21 +285,24 @@ class Broadcast_Edit_Admin_Page extends Edit_Admin_Page {
'target_type' => 'customers',
);
$html .= sprintf('<div class="wu-inline-block wu-ml-4">
$html .= sprintf(
'<div class="wu-inline-block wu-ml-4">
<a href="%s" title="%s" class="wubox wu-no-underline"><span class="wu-pl-2 wu-uppercase wu-text-xs wu-font-bold"> %s %s</span></a>
</div>', wu_get_form_url('view_broadcast_targets', $modal_atts), __('Targets', 'wp-ultimo'), $targets_count, __('Targets', 'wp-ultimo'));
} // end if;
</div>',
wu_get_form_url('view_broadcast_targets', $modal_atts),
__('Targets', 'wp-ultimo'),
$targets_count,
__('Targets', 'wp-ultimo')
);
}
break;
} // end switch;
}
$html .= '</div></li></ul></div>';
echo $html;
} // end output_default_widget_customer_targets;
}
/**
* Outputs the markup for the products targets widget.
@ -300,13 +319,10 @@ class Broadcast_Edit_Admin_Page extends Edit_Admin_Page {
$product_targets = array();
if ($targets) {
foreach ($targets as $key => $value) {
$product = wu_get_product($value);
if ($product) {
$modal_atts = array(
'action' => 'wu_modal_product_targets_display',
'product_id' => $product->get_id(),
@ -325,10 +341,8 @@ class Broadcast_Edit_Admin_Page extends Edit_Admin_Page {
$customer_count = (int) 0;
if ($plan_customers) {
$customer_count = count($plan_customers);
} // end if;
}
// translators: %s is the number of customers.
$description = sprintf(__('%s customer(s) targeted.', 'wp-ultimo'), $customer_count);
@ -338,14 +352,11 @@ class Broadcast_Edit_Admin_Page extends Edit_Admin_Page {
'avatar' => $image,
'display_name' => $product->get_name(),
'id' => $product->get_id(),
'description' => $description
'description' => $description,
);
} // end if;
} // end foreach;
} // end if;
}
}
}
$args = array(
'targets' => $product_targets,
@ -355,8 +366,7 @@ class Broadcast_Edit_Admin_Page extends Edit_Admin_Page {
);
wu_get_template('broadcast/widget-targets', $args);
} // end output_default_widget_product_targets;
}
/**
* Returns the title of the page.
@ -367,8 +377,7 @@ class Broadcast_Edit_Admin_Page extends Edit_Admin_Page {
public function get_title() {
return $this->edit ? __('Edit Broadcast', 'wp-ultimo') : __('Add new Broadcast', 'wp-ultimo');
} // end get_title;
}
/**
* Returns the title of menu for this page.
@ -379,8 +388,7 @@ class Broadcast_Edit_Admin_Page extends Edit_Admin_Page {
public function get_menu_title() {
return __('Edit Broadcast', 'wp-ultimo');
} // end get_menu_title;
}
/**
* Returns the action links for that page.
@ -391,8 +399,7 @@ class Broadcast_Edit_Admin_Page extends Edit_Admin_Page {
public function action_links() {
return array();
} // end action_links;
}
/**
* Returns the labels to be used on the admin page.
@ -413,8 +420,7 @@ class Broadcast_Edit_Admin_Page extends Edit_Admin_Page {
'delete_button_label' => __('Delete Broadcast', 'wp-ultimo'),
'delete_description' => __('Be careful. This action is irreversible.', 'wp-ultimo'),
);
} // end get_labels;
}
/**
* Filters the list table to return only relevant events.
@ -432,8 +438,7 @@ class Broadcast_Edit_Admin_Page extends Edit_Admin_Page {
);
return array_merge($args, $extra_args);
} // end query_filter;
}
/**
* Returns the object being edit at the moment.
@ -444,26 +449,21 @@ class Broadcast_Edit_Admin_Page extends Edit_Admin_Page {
public function get_object() {
if (isset($_GET['id'])) {
$query = new \WP_Ultimo\Database\Broadcasts\Broadcast_Query;
$query = new \WP_Ultimo\Database\Broadcasts\Broadcast_Query();
$item = $query->get_item_by('id', $_GET['id']);
if ( ! $item) {
wp_redirect(wu_network_admin_url('wp-ultimo-broadcasts'));
exit;
} // end if;
}
return $item;
}
} // end if;
return new Broadcast;
} // end get_object;
return new Broadcast();
}
/**
* Broadcasts have titles.
@ -473,8 +473,7 @@ class Broadcast_Edit_Admin_Page extends Edit_Admin_Page {
public function has_title(): bool {
return true;
} // end has_title;
}
/**
* Wether or not this pages should have an editor field.
@ -484,8 +483,7 @@ class Broadcast_Edit_Admin_Page extends Edit_Admin_Page {
public function has_editor(): bool {
return true;
} // end has_editor;
}
/**
* Filters the list table to return only relevant events.
@ -503,7 +501,5 @@ class Broadcast_Edit_Admin_Page extends Edit_Admin_Page {
);
return array_merge($args, $extra_args);
} // end events_query_filter;
} // end class Broadcast_Edit_Admin_Page;
}
}

View File

@ -12,7 +12,7 @@ namespace WP_Ultimo\Admin_Pages;
// Exit if accessed directly
defined('ABSPATH') || exit;
use \WP_Ultimo\Managers\Broadcast_Manager;
use WP_Ultimo\Managers\Broadcast_Manager;
/**
* WP Multisite WaaS Broadcast Admin Page.
@ -66,11 +66,14 @@ class Broadcast_List_Admin_Page extends List_Admin_Page {
/*
* Add new broadcast notice.
*/
wu_register_form('add_new_broadcast_message', array(
wu_register_form(
'add_new_broadcast_message',
array(
'render' => array($this, 'render_add_new_broadcast_modal'),
'handler' => array($this, 'handle_add_new_broadcast_modal'),
'capability' => 'wu_add_broadcasts',
));
)
);
/**
* Ajax to render the broadcast targets modal.
@ -81,8 +84,7 @@ class Broadcast_List_Admin_Page extends List_Admin_Page {
* Ajax to render the targets modal with customers from a specific membership.
*/
add_action('wu_ajax_wu_modal_product_targets_display', array($this, 'display_product_targets_modal'));
} // end register_forms;
}
/**
* Enqueue the necessary scripts.
@ -95,8 +97,7 @@ class Broadcast_List_Admin_Page extends List_Admin_Page {
parent::register_scripts();
wp_enqueue_editor();
} // end register_scripts;
}
/**
* Renders the broadcast targets modal, when requested.
@ -117,11 +118,8 @@ class Broadcast_List_Admin_Page extends List_Admin_Page {
$display_targets = array();
if ($targets) {
if ($target_type === 'customers') {
foreach ($targets as $key => $value) {
$customer = wu_get_customer($value);
$url_atts = array(
@ -130,10 +128,16 @@ class Broadcast_List_Admin_Page extends List_Admin_Page {
$link = wu_network_admin_url('wp-ultimo-edit-customer', $url_atts);
$avatar = get_avatar($customer->get_user_id(), 48, 'identicon', '', array(
$avatar = get_avatar(
$customer->get_user_id(),
48,
'identicon',
'',
array(
'force_display' => true,
'class' => 'wu-rounded-full',
));
)
);
$display_targets[ $key ] = array(
'link' => $link,
@ -142,15 +146,11 @@ class Broadcast_List_Admin_Page extends List_Admin_Page {
'id' => $customer->get_id(),
'description' => $customer->get_email_address(),
);
} // end foreach;
} // end if;
}
}
if ($target_type === 'products') {
foreach ($targets as $key => $value) {
$product = wu_get_product($value);
$url_atts = array(
@ -162,24 +162,18 @@ class Broadcast_List_Admin_Page extends List_Admin_Page {
$avatar = $product->get_featured_image('thumbnail');
if ($avatar) {
$avatar = sprintf('<img class="wu-w-8 wu-h-8 wu-bg-gray-200 wu-rounded-full wu-text-gray-600 wu-flex wu-items-center wu-justify-center" src="%s">', esc_attr($avatar));
} else {
$avatar = '<span class="dashicons-wu-image wu-p-1 wu-rounded-full"></span>';
} // end if;
}
$plan_customers = wu_get_membership_customers($product->get_id());
$customer_count = (int) 0;
if ($plan_customers) {
$customer_count = count($plan_customers);
} // end if;
}
// translators: %s is the number of customers.
$description = sprintf(__('%s customer(s) targeted.', 'wp-ultimo'), $customer_count);
@ -191,12 +185,9 @@ class Broadcast_List_Admin_Page extends List_Admin_Page {
'id' => $product->get_id(),
'description' => $description,
);
} // end foreach;
} // end if;
} // end if;
}
}
}
$args = array(
'targets' => $display_targets,
@ -207,8 +198,7 @@ class Broadcast_List_Admin_Page extends List_Admin_Page {
wu_get_template('broadcast/widget-targets', $args);
exit;
} // end display_targets_modal;
}
/**
* Renders the broadcast targets modal, when requested.
@ -225,9 +215,7 @@ class Broadcast_List_Admin_Page extends List_Admin_Page {
$display_targets = array();
if ($customers) {
foreach ($customers as $key => $value) {
$customer = wu_get_customer($value);
$url_atts = array(
@ -236,10 +224,16 @@ class Broadcast_List_Admin_Page extends List_Admin_Page {
$link = wu_network_admin_url('wp-ultimo-edit-customer', $url_atts);
$avatar = get_avatar($customer->get_user_id(), 48, 'identicon', '', array(
$avatar = get_avatar(
$customer->get_user_id(),
48,
'identicon',
'',
array(
'force_display' => true,
'class' => 'wu-rounded-full',
));
)
);
$display_targets[ $key ] = array(
'link' => $link,
@ -248,10 +242,8 @@ class Broadcast_List_Admin_Page extends List_Admin_Page {
'id' => $customer->get_id(),
'description' => $customer->get_email_address(),
);
} // end foreach;
} // end if;
}
}
$args = array(
'targets' => $display_targets,
@ -262,8 +254,7 @@ class Broadcast_List_Admin_Page extends List_Admin_Page {
wu_get_template('broadcast/widget-targets', $args);
exit;
} // end display_product_targets_modal;
}
/**
* Renders the add new broadcast message modal.
@ -356,7 +347,7 @@ class Broadcast_List_Admin_Page extends List_Admin_Page {
),
'wrapper_html_attr' => array(
'v-show' => "step === 2 && require('type', 'broadcast_notice')",
'v-cloak' => 1
'v-cloak' => 1,
),
),
'step_note_2' => array(
@ -404,7 +395,7 @@ class Broadcast_List_Admin_Page extends List_Admin_Page {
),
'html_attr' => array(
'v-bind:disabled' => 'type === ""',
'v-on:click.prevent' => 'step = 2'
'v-on:click.prevent' => 'step = 2',
),
),
'submit_button_2' => array(
@ -418,7 +409,7 @@ class Broadcast_List_Admin_Page extends List_Admin_Page {
),
'html_attr' => array(
'v-bind:disabled' => 'target_customers === "" && target_products === ""', // phpcs:ignore
'v-on:click.prevent' => 'step = 3'
'v-on:click.prevent' => 'step = 3',
),
),
'submit_button_3' => array(
@ -436,13 +427,17 @@ class Broadcast_List_Admin_Page extends List_Admin_Page {
),
);
$form = new \WP_Ultimo\UI\Form('add_new_broadcast', $fields, array(
$form = new \WP_Ultimo\UI\Form(
'add_new_broadcast',
$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_broadcast',
'data-state' => wu_convert_to_state(array(
'data-state' => wu_convert_to_state(
array(
'type' => 'broadcast_notice',
'content' => '',
'step' => 1,
@ -450,13 +445,14 @@ class Broadcast_List_Admin_Page extends List_Admin_Page {
'target_customers' => '',
'target_products' => '',
'subject' => '',
)),
)
),
));
),
)
);
$form->render();
} // end render_add_new_broadcast_modal;
}
/**
* Handles the add new broadcast modal.
@ -469,8 +465,7 @@ class Broadcast_List_Admin_Page extends List_Admin_Page {
$broadcast = Broadcast_Manager::get_instance();
$broadcast->handle_broadcast();
} // end handle_add_new_broadcast_modal;
}
/**
* Allow child classes to register widgets, if they need them.
@ -478,7 +473,7 @@ class Broadcast_List_Admin_Page extends List_Admin_Page {
* @since 1.8.2
* @return void
*/
public function register_widgets() {} // end register_widgets;
public function register_widgets() {}
/**
* Returns an array with the labels for the edit page.
@ -492,8 +487,7 @@ class Broadcast_List_Admin_Page extends List_Admin_Page {
'deleted_message' => __('Broadcast removed successfully.', 'wp-ultimo'),
'search_label' => __('Search Broadcast', 'wp-ultimo'),
);
} // end get_labels;
}
/**
* Returns the title of the page.
@ -504,8 +498,7 @@ class Broadcast_List_Admin_Page extends List_Admin_Page {
public function get_title() {
return __('Broadcast', 'wp-ultimo');
} // end get_title;
}
/**
* Returns the title of menu for this page.
@ -516,8 +509,7 @@ class Broadcast_List_Admin_Page extends List_Admin_Page {
public function get_menu_title() {
return __('Broadcasts', 'wp-ultimo');
} // end get_menu_title;
}
/**
* Allows admins to rename the sub-menu (first item) for a top-level page.
@ -528,8 +520,7 @@ class Broadcast_List_Admin_Page extends List_Admin_Page {
public function get_submenu_title() {
return __('Broadcasts', 'wp-ultimo');
} // end get_submenu_title;
}
/**
* Returns the action links for that page.
@ -552,8 +543,7 @@ class Broadcast_List_Admin_Page extends List_Admin_Page {
'icon' => 'wu-mail',
),
);
} // end action_links;
}
/**
* Loads the list table for this particular page.
@ -564,7 +554,5 @@ class Broadcast_List_Admin_Page extends List_Admin_Page {
public function table() {
return new \WP_Ultimo\List_Tables\Broadcast_List_Table();
} // end table;
} // end class Broadcast_List_Admin_Page;
}
}

File diff suppressed because it is too large Load Diff

View File

@ -12,7 +12,7 @@ namespace WP_Ultimo\Admin_Pages;
// Exit if accessed directly
defined('ABSPATH') || exit;
use \WP_Ultimo\Models\Checkout_Form;
use WP_Ultimo\Models\Checkout_Form;
/**
* WP Multisite WaaS Checkout Form Admin Page.
@ -64,7 +64,9 @@ class Checkout_Form_List_Admin_Page extends List_Admin_Page {
*/
public function register_widgets() {
\WP_Ultimo\UI\Tours::get_instance()->create_tour('checkout-form-list', array(
\WP_Ultimo\UI\Tours::get_instance()->create_tour(
'checkout-form-list',
array(
array(
'id' => 'checkout-form-list',
'title' => __('Checkout Forms', 'wp-ultimo'),
@ -84,9 +86,9 @@ class Checkout_Form_List_Admin_Page extends List_Admin_Page {
'on' => 'right',
),
),
));
} // end register_widgets;
)
);
}
/**
* Register ajax forms to handle adding new checkout forms.
@ -98,13 +100,15 @@ class Checkout_Form_List_Admin_Page extends List_Admin_Page {
/*
* Add new Checkout Form
*/
wu_register_form('add_new_checkout_form', array(
wu_register_form(
'add_new_checkout_form',
array(
'render' => array($this, 'render_add_new_checkout_form_modal'),
'handler' => array($this, 'handle_add_new_checkout_form_modal'),
'capability' => 'wu_edit_checkout_forms',
));
} // end register_forms;
)
);
}
/**
* Renders the add new customer modal.
@ -150,21 +154,26 @@ class Checkout_Form_List_Admin_Page extends List_Admin_Page {
),
);
$form = new \WP_Ultimo\UI\Form('add_new_checkout_form', $fields, array(
$form = new \WP_Ultimo\UI\Form(
'add_new_checkout_form',
$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_checkout_form_field',
'data-state' => json_encode(array(
'data-state' => json_encode(
array(
'template' => 'single-step',
)),
)
),
));
),
)
);
$form->render();
} // end render_add_new_checkout_form_modal;
}
/**
* Handles creation of a new memberships.
@ -176,7 +185,7 @@ class Checkout_Form_List_Admin_Page extends List_Admin_Page {
$template = wu_request('template');
$checkout_form = new \WP_Ultimo\Models\Checkout_Form;
$checkout_form = new \WP_Ultimo\Models\Checkout_Form();
$checkout_form->use_template($template);
@ -189,20 +198,20 @@ class Checkout_Form_List_Admin_Page extends List_Admin_Page {
$status = $checkout_form->save();
if (is_wp_error($status)) {
wp_send_json_error($status);
} else {
wp_send_json_success(array(
'redirect_url' => wu_network_admin_url('wp-ultimo-edit-checkout-form', array(
wp_send_json_success(
array(
'redirect_url' => wu_network_admin_url(
'wp-ultimo-edit-checkout-form',
array(
'id' => $checkout_form->get_id(),
))
));
} // end if;
} // end handle_add_new_checkout_form_modal;
)
),
)
);
}
}
/**
* Returns an array with the labels for the edit page.
@ -216,8 +225,7 @@ class Checkout_Form_List_Admin_Page extends List_Admin_Page {
'deleted_message' => __('Checkout Form removed successfully.', 'wp-ultimo'),
'search_label' => __('Search Checkout Form', 'wp-ultimo'),
);
} // end get_labels;
}
/**
* Returns the title of the page.
@ -228,8 +236,7 @@ class Checkout_Form_List_Admin_Page extends List_Admin_Page {
public function get_title() {
return __('Checkout Forms', 'wp-ultimo');
} // end get_title;
}
/**
* Returns the title of menu for this page.
@ -240,8 +247,7 @@ class Checkout_Form_List_Admin_Page extends List_Admin_Page {
public function get_menu_title() {
return __('Checkout Forms', 'wp-ultimo');
} // end get_menu_title;
}
/**
* Allows admins to rename the sub-menu (first item) for a top-level page.
@ -252,8 +258,7 @@ class Checkout_Form_List_Admin_Page extends List_Admin_Page {
public function get_submenu_title() {
return __('Checkout Forms', 'wp-ultimo');
} // end get_submenu_title;
}
/**
* Returns the action links for that page.
@ -271,8 +276,7 @@ class Checkout_Form_List_Admin_Page extends List_Admin_Page {
'url' => wu_get_form_url('add_new_checkout_form'),
),
);
} // end action_links;
}
/**
* Loads the list table for this particular page.
@ -283,7 +287,5 @@ class Checkout_Form_List_Admin_Page extends List_Admin_Page {
public function table() {
return new \WP_Ultimo\List_Tables\Checkout_Form_List_Table();
} // end table;
} // end class Checkout_Form_List_Admin_Page;
}
}

File diff suppressed because it is too large Load Diff

View File

@ -51,8 +51,7 @@ class Customer_List_Admin_Page extends List_Admin_Page {
parent::init();
add_action('plugins_loaded', array($this, 'export_customers'));
} // end init;
}
/**
* Export customers in .csv file
@ -63,18 +62,15 @@ class Customer_List_Admin_Page extends List_Admin_Page {
public function export_customers() {
if (wu_request('wu_action') !== 'wu_export_customers') {
return;
} // end if;
}
if ( ! wp_verify_nonce(wu_request('nonce'), 'wu_export_customers')) {
wp_die(__('You do not have permissions to access this file.', 'wp-ultimo'));
}
} // end if;
$customer_data = array_map(function($customer) {
$customer_data = array_map(
function ($customer) {
$memberships = $customer->get_memberships();
@ -104,8 +100,9 @@ class Customer_List_Admin_Page extends List_Admin_Page {
$customer->get_date_registered(),
)
);
}, wu_get_customers());
},
wu_get_customers()
);
$billing_fields = array_keys(\WP_Ultimo\Objects\Billing_Address::fields());
@ -135,8 +132,7 @@ class Customer_List_Admin_Page extends List_Admin_Page {
wu_generate_csv($file_name, array_merge(array($headers), $customer_data));
die;
} // end export_customers;
}
/**
* Holds the admin panels where this page should be displayed, as well as which capability to require.
@ -162,13 +158,15 @@ class Customer_List_Admin_Page extends List_Admin_Page {
/*
* Add new Customer
*/
wu_register_form('add_new_customer', array(
wu_register_form(
'add_new_customer',
array(
'render' => array($this, 'render_add_new_customer_modal'),
'handler' => array($this, 'handle_add_new_customer_modal'),
'capability' => 'wu_invite_customers',
));
} // end register_forms;
)
);
}
/**
* Renders the add new customer modal.
@ -253,22 +251,27 @@ class Customer_List_Admin_Page extends List_Admin_Page {
),
);
$form = new \WP_Ultimo\UI\Form('add_new_customer', $fields, array(
$form = new \WP_Ultimo\UI\Form(
'add_new_customer',
$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_customer',
'data-state' => json_encode(array(
'data-state' => json_encode(
array(
'set_password' => false,
'type' => 'existing',
)),
)
),
));
),
)
);
$form->render();
} // end render_add_new_customer_modal;
}
/**
* Handles creation of a new customer.
@ -279,21 +282,17 @@ class Customer_List_Admin_Page extends List_Admin_Page {
public function handle_add_new_customer_modal() {
if (wu_request('type', 'existing') === 'new') {
$customer_data = array(
'email' => wu_request('email_address'),
'username' => wu_request('username'),
'password' => wu_request('password', false),
'meta' => array(),
);
} else {
$customer_data = array(
'user_id' => wu_request('user_id', 0),
);
} // end if;
}
/*
* Tries to create the customer
@ -301,18 +300,20 @@ class Customer_List_Admin_Page extends List_Admin_Page {
$customer = wu_create_customer($customer_data);
if (is_wp_error($customer)) {
wp_send_json_error($customer);
}
} // end if;
wp_send_json_success(array(
'redirect_url' => wu_network_admin_url('wp-ultimo-edit-customer', array(
wp_send_json_success(
array(
'redirect_url' => wu_network_admin_url(
'wp-ultimo-edit-customer',
array(
'id' => $customer->get_id(),
))
));
} // end handle_add_new_customer_modal;
)
),
)
);
}
/**
* Allow child classes to register widgets, if they need them.
@ -320,7 +321,7 @@ class Customer_List_Admin_Page extends List_Admin_Page {
* @since 1.8.2
* @return void
*/
public function register_widgets() {} // end register_widgets;
public function register_widgets() {}
/**
* Returns an array with the labels for the edit page.
@ -334,8 +335,7 @@ class Customer_List_Admin_Page extends List_Admin_Page {
'deleted_message' => __('Customer removed successfully.', 'wp-ultimo'),
'search_label' => __('Search Customer', 'wp-ultimo'),
);
} // end get_labels;
}
/**
* Returns the title of the page.
@ -346,8 +346,7 @@ class Customer_List_Admin_Page extends List_Admin_Page {
public function get_title() {
return __('Customers', 'wp-ultimo');
} // end get_title;
}
/**
* Returns the title of menu for this page.
@ -358,8 +357,7 @@ class Customer_List_Admin_Page extends List_Admin_Page {
public function get_menu_title() {
return __('Customers', 'wp-ultimo');
} // end get_menu_title;
}
/**
* Allows admins to rename the sub-menu (first item) for a top-level page.
@ -370,8 +368,7 @@ class Customer_List_Admin_Page extends List_Admin_Page {
public function get_submenu_title() {
return __('Customers', 'wp-ultimo');
} // end get_submenu_title;
}
/**
* Returns the action links for that page.
@ -391,14 +388,15 @@ class Customer_List_Admin_Page extends List_Admin_Page {
array(
'label' => __('Export as CSV', 'wp-ultimo'),
'icon' => 'wu-export',
'url' => add_query_arg(array(
'url' => add_query_arg(
array(
'wu_action' => 'wu_export_customers',
'nonce' => wp_create_nonce('wu_export_customers'),
)),
)
),
),
);
} // end action_links;
}
/**
* Loads the list table for this particular page.
@ -409,7 +407,5 @@ class Customer_List_Admin_Page extends List_Admin_Page {
public function table() {
return new \WP_Ultimo\List_Tables\Customer_List_Table();
} // end table;
} // end class Customer_List_Admin_Page;
}
}

View File

@ -42,8 +42,7 @@ abstract class Customizer_Admin_Page extends Edit_Admin_Page {
public function get_preview_url() {
return get_site_url(null);
} // end get_preview_url;
}
/**
* Adds hooks when the page loads.
@ -61,8 +60,7 @@ abstract class Customizer_Admin_Page extends Edit_Admin_Page {
$screen = get_current_screen();
add_action("wu_edit_{$screen->id}_after_normal", array($this, 'display_preview_window'));
} // end page_loaded;
}
/**
* Adds the preview window.
@ -72,12 +70,14 @@ abstract class Customizer_Admin_Page extends Edit_Admin_Page {
*/
public function display_preview_window() {
wu_get_template('base/edit/editor-customizer', array(
wu_get_template(
'base/edit/editor-customizer',
array(
'preview_iframe_url' => $this->get_preview_url(),
'preview_height' => $this->preview_height,
));
} // end display_preview_window;
)
);
}
/**
* Registers the necessary scripts and styles for this admin page.
@ -96,8 +96,7 @@ abstract class Customizer_Admin_Page extends Edit_Admin_Page {
wp_enqueue_script('wp-color-picker');
wp_enqueue_media();
} // end register_scripts;
}
/**
* Checkout_Forms have titles.
@ -108,8 +107,7 @@ abstract class Customizer_Admin_Page extends Edit_Admin_Page {
public function has_title() {
return false;
} // end has_title;
}
/**
* Not needed.
@ -117,6 +115,5 @@ abstract class Customizer_Admin_Page extends Edit_Admin_Page {
* @since 2.0.0
* @return void
*/
public function get_object() {} // end get_object;
} // end class Customizer_Admin_Page;
public function get_object() {}
}

View File

@ -12,7 +12,7 @@ namespace WP_Ultimo\Admin_Pages;
// Exit if accessed directly
defined('ABSPATH') || exit;
use \WP_Ultimo\Dashboard_Statistics;
use WP_Ultimo\Dashboard_Statistics;
/**
* WP Multisite WaaS Dashboard Admin Page.
@ -104,8 +104,7 @@ class Dashboard_Admin_Page extends Base_Admin_Page {
$this->tab = wu_request('tab', 'general');
$this->start_date = date_i18n('Y-m-d', strtotime((string) wu_request('start_date', '-1 month')));
$this->end_date = date_i18n('Y-m-d', strtotime((string) wu_request('end_date', 'tomorrow')));
} // end init;
}
/**
* Allow child classes to add hooks to be run once the page is loaded.
@ -119,8 +118,7 @@ class Dashboard_Admin_Page extends Base_Admin_Page {
add_action('wu_dash_after_full_metaboxes', array($this, 'render_filter'));
add_action('wu_dashboard_general_widgets', array($this, 'register_general_tab_widgets'), 10, 2);
} // end hooks;
}
/**
* Renders the filter.
@ -133,13 +131,10 @@ class Dashboard_Admin_Page extends Base_Admin_Page {
public function render_filter($page) {
if (apply_filters('wu_dashboard_display_filter', true) === false) {
return;
} // end if;
}
if ($page->id === 'wp-ultimo') {
$preset_options = array(
'last_7_days' => array(
'label' => __('Last 7 days', 'wp-ultimo'),
@ -170,10 +165,8 @@ class Dashboard_Admin_Page extends Base_Admin_Page {
);
wu_get_template('dashboard-statistics/filter', $args);
} // end if;
} // end render_filter;
}
}
/**
* Returns the views for the filter menu bar.
@ -193,8 +186,7 @@ class Dashboard_Admin_Page extends Base_Admin_Page {
);
return apply_filters('wu_dashboard_filter_bar', $dashboard_filters);
} // end get_views;
}
/**
* Allow child classes to register widgets, if they need them.
@ -207,10 +199,8 @@ class Dashboard_Admin_Page extends Base_Admin_Page {
$screen = get_current_screen();
if ( ! $screen) {
return;
} // end if;
}
/**
* Allow plugin developers to add widgets to Network Dashboard Panel.
@ -235,8 +225,9 @@ class Dashboard_Admin_Page extends Base_Admin_Page {
do_action('wu_dashboard_widgets', $this->tab, $screen, $this);
if (wu_request('tab', 'general') === 'general') {
\WP_Ultimo\UI\Tours::get_instance()->create_tour('wp-ultimo-dashboard', array(
\WP_Ultimo\UI\Tours::get_instance()->create_tour(
'wp-ultimo-dashboard',
array(
array(
'id' => 'your-dashboard',
'title' => __('Our dashboard', 'wp-ultimo'),
@ -278,11 +269,10 @@ class Dashboard_Admin_Page extends Base_Admin_Page {
'on' => 'bottom',
),
),
));
} // end if;
} // end register_widgets;
)
);
}
}
/**
* Register the widgets of the default general tab.
@ -296,12 +286,10 @@ class Dashboard_Admin_Page extends Base_Admin_Page {
public function register_general_tab_widgets($tab, $screen) {
if (current_user_can('wu_read_financial')) {
add_meta_box('wp-ultimo-mrr-growth', __('Monthly Recurring Revenue Growth', 'wp-ultimo'), array($this, 'output_widget_mrr_growth'), $screen->id, 'full', 'high');
add_meta_box('wp-ultimo-revenue', __('Revenue', 'wp-ultimo'), array($this, 'output_widget_revenues'), $screen->id, 'normal', 'high');
} // end if;
}
add_meta_box('wp-ultimo-countries', __('Signups by Countries', 'wp-ultimo'), array($this, 'output_widget_countries'), $screen->id, 'side', 'high');
@ -310,8 +298,7 @@ class Dashboard_Admin_Page extends Base_Admin_Page {
add_meta_box('wp-ultimo-most-visited-sites', __('Most Visited Sites', 'wp-ultimo'), array($this, 'output_widget_most_visited_sites'), $screen->id, 'side', 'low');
add_meta_box('wp-ultimo-new-accounts', __('New Memberships', 'wp-ultimo'), array($this, 'output_widget_new_accounts'), $screen->id, 'normal', 'low');
} // end register_general_tab_widgets;
}
/**
* Output the statistics filter widget
@ -322,8 +309,7 @@ class Dashboard_Admin_Page extends Base_Admin_Page {
public function output_widget_mrr_growth() {
wu_get_template('dashboard-statistics/widget-mrr-growth');
} // end output_widget_mrr_growth;
}
/**
* Output the statistics filter widget
@ -333,12 +319,14 @@ class Dashboard_Admin_Page extends Base_Admin_Page {
*/
public function output_widget_countries() {
wu_get_template('dashboard-statistics/widget-countries', array(
wu_get_template(
'dashboard-statistics/widget-countries',
array(
'countries' => wu_get_countries_of_customers(10, $this->start_date, $this->end_date),
'page' => $this,
));
} // end output_widget_countries;
)
);
}
/**
* Output the statistics filter widget
@ -348,12 +336,14 @@ class Dashboard_Admin_Page extends Base_Admin_Page {
*/
public function output_widget_forms() {
wu_get_template('dashboard-statistics/widget-forms', array(
wu_get_template(
'dashboard-statistics/widget-forms',
array(
'forms' => wu_calculate_signups_by_form($this->start_date, $this->end_date),
'page' => $this,
));
} // end output_widget_forms;
)
);
}
/**
* Output the statistics filter widget
@ -368,28 +358,26 @@ class Dashboard_Admin_Page extends Base_Admin_Page {
$site_results = \WP_Ultimo\Objects\Visits::get_sites_by_visit_count($this->start_date, $this->end_date, 10);
foreach ($site_results as $site_result) {
$site = wu_get_site($site_result->site_id);
if ( ! $site) {
continue;
} // end if;
}
$sites[] = (object) array(
'site' => $site,
'count' => $site_result->count,
);
}
} // end foreach;
wu_get_template('dashboard-statistics/widget-most-visited-sites', array(
wu_get_template(
'dashboard-statistics/widget-most-visited-sites',
array(
'sites' => $sites,
'page' => $this,
));
} // end output_widget_most_visited_sites;
)
);
}
/**
* Outputs the total refunds widget content.
@ -402,14 +390,16 @@ class Dashboard_Admin_Page extends Base_Admin_Page {
*/
public function output_widget_revenues($unknown = null, $metabox = null) {
wu_get_template('dashboard-statistics/widget-revenue', array(
wu_get_template(
'dashboard-statistics/widget-revenue',
array(
'mrr' => wu_calculate_mrr(),
'gross_revenue' => wu_calculate_revenue($this->start_date, $this->end_date),
'refunds' => wu_calculate_refunds($this->start_date, $this->end_date),
'product_stats' => wu_calculate_financial_data_by_product($this->start_date, $this->end_date),
));
} // end output_widget_revenues;
)
);
}
/**
* Outputs the total refunds widget content.
@ -422,7 +412,8 @@ class Dashboard_Admin_Page extends Base_Admin_Page {
*/
public function output_widget_new_accounts($unknown = null, $metabox = array()) {
$new_accounts = wu_get_memberships(array(
$new_accounts = wu_get_memberships(
array(
'fields' => array('plan_id'),
'date_query' => array(
'column' => 'date_created',
@ -430,24 +421,29 @@ class Dashboard_Admin_Page extends Base_Admin_Page {
'before' => $this->end_date . ' 23:59:59',
'inclusive' => true,
),
));
)
);
$products = wu_get_products(array(
$products = wu_get_products(
array(
'type' => 'plan',
'fields' => array('id', 'name', 'count'),
));
)
);
$products_ids = array_column($products, 'id');
$products = array_combine($products_ids, $products);
$products = array_map(function($item) {
$products = array_map(
function ($item) {
$item->count = 0;
return $item;
}, $products);
},
$products
);
/**
* Add edge case for no plan.
@ -458,25 +454,21 @@ class Dashboard_Admin_Page extends Base_Admin_Page {
);
foreach ($new_accounts as $new_account) {
if (isset($products[ $new_account->plan_id ])) {
$products[ $new_account->plan_id ]->count += 1;
} else {
$products['none']->count += 1;
}
}
} // end if;
} // end foreach;
wu_get_template('dashboard-statistics/widget-new-accounts', array(
wu_get_template(
'dashboard-statistics/widget-new-accounts',
array(
'new_accounts' => count($new_accounts),
'products' => $products,
));
} // end output_widget_new_accounts;
)
);
}
/**
* Enqueue the necessary scripts.
@ -494,13 +486,15 @@ class Dashboard_Admin_Page extends Base_Admin_Page {
$month_list[] = date_i18n('M y', mktime(0, 0, 0, $i, 1, $current_year));
}
$statistics = new Dashboard_Statistics(array(
$statistics = new Dashboard_Statistics(
array(
'start_date' => $this->start_date,
'end_date' => $this->end_date,
'types' => array(
'mrr_growth' => 'mrr_growth',
),
));
)
);
$data = $statistics->statistics_data();
@ -510,7 +504,10 @@ class Dashboard_Admin_Page extends Base_Admin_Page {
wp_register_script('wu-dashboard-stats', wu_get_asset('dashboard-statistics.js', 'js'), array('jquery', 'wu-functions', 'wu-ajax-list-table', 'moment', 'wu-block-ui', 'dashboard', 'wu-apex-charts', 'wu-vue-apex-charts'), wu_get_version(), true);
wp_localize_script('wu-dashboard-stats', 'wu_dashboard_statistics_vars', array(
wp_localize_script(
'wu-dashboard-stats',
'wu_dashboard_statistics_vars',
array(
'mrr_array' => $data['mrr_growth'],
'start_date' => date_i18n('Y-m-d', strtotime((string) wu_request('start_date', '-1 month'))),
'end_date' => date_i18n('Y-m-d', strtotime((string) wu_request('end_date', 'tomorrow'))),
@ -520,15 +517,15 @@ class Dashboard_Admin_Page extends Base_Admin_Page {
'new_mrr' => __('New MRR', 'wp-ultimo'),
'cancellations' => __('Cancellations', 'wp-ultimo'),
),
));
)
);
wp_enqueue_script('wu-dashboard-stats');
wp_enqueue_style('wu-apex-charts', wu_get_asset('apexcharts.css', 'css'), array(), wu_get_version());
wp_enqueue_style('wu-flags');
} // end register_scripts;
}
/**
* Returns the title of the page.
@ -539,8 +536,7 @@ class Dashboard_Admin_Page extends Base_Admin_Page {
public function get_title() {
return __('Dashboard', 'wp-ultimo');
} // end get_title;
}
/**
* Returns the title of menu for this page.
@ -551,8 +547,7 @@ class Dashboard_Admin_Page extends Base_Admin_Page {
public function get_menu_title() {
return __('Multisite WaaS', 'wp-ultimo');
} // end get_menu_title;
}
/**
* Allows admins to rename the sub-menu (first item) for a top-level page.
@ -563,8 +558,7 @@ class Dashboard_Admin_Page extends Base_Admin_Page {
public function get_submenu_title() {
return __('Dashboard', 'wp-ultimo');
} // end get_submenu_title;
}
/**
* Every child class should implement the output method to display the contents of the page.
@ -576,13 +570,15 @@ class Dashboard_Admin_Page extends Base_Admin_Page {
/*
* Renders the base edit page layout, with the columns and everything else =)
*/
wu_get_template('base/dash', array(
wu_get_template(
'base/dash',
array(
'screen' => get_current_screen(),
'page' => $this,
'has_full_position' => true,
));
} // end output;
)
);
}
/**
* Render an export CSV button.
@ -594,12 +590,15 @@ class Dashboard_Admin_Page extends Base_Admin_Page {
*/
public function render_csv_button($args) {
$args = wp_parse_args($args, array(
$args = wp_parse_args(
$args,
array(
'slug' => 'csv',
'headers' => array(),
'data' => array(),
'action' => apply_filters('wu_export_data_table_action', 'wu_generate_csv'),
));
)
);
$slug = $args['slug'];
@ -621,8 +620,6 @@ class Dashboard_Admin_Page extends Base_Admin_Page {
$html = apply_filters('wu_export_html_render', $html, $html);
echo sprintf($html, apply_filters('wu_export_data_table_label', __('CSV', 'wp-ultimo')));
} // end render_csv_button;
} // end class Dashboard_Admin_Page;
printf($html, apply_filters('wu_export_data_table_label', __('CSV', 'wp-ultimo')));
}
}

View File

@ -12,8 +12,8 @@ namespace WP_Ultimo\Admin_Pages;
// Exit if accessed directly
defined('ABSPATH') || exit;
use \WP_Ultimo\Models\Discount_Code;
use \WP_Ultimo\Managers\Discount_Code_Manager;
use WP_Ultimo\Models\Discount_Code;
use WP_Ultimo\Managers\Discount_Code_Manager;
/**
* WP Multisite WaaS Discount_Code Edit/Add New Admin Page.
@ -91,7 +91,9 @@ class Discount_Code_Edit_Admin_Page extends Edit_Admin_Page {
parent::register_widgets();
$this->add_fields_widget('description', array(
$this->add_fields_widget(
'description',
array(
'title' => __('Description', 'wp-ultimo'),
'position' => 'normal',
'fields' => array(
@ -105,7 +107,8 @@ class Discount_Code_Edit_Admin_Page extends Edit_Admin_Page {
),
),
),
));
)
);
$tz_note = sprintf('The site timezone is <code>%s</code>. The current time is <code>%s</code>', date_i18n('e'), date_i18n('r'));
@ -215,39 +218,50 @@ class Discount_Code_Edit_Admin_Page extends Edit_Admin_Page {
'v-model' => 'limit_products',
),
),
), $this->get_product_field_list()
),
$this->get_product_field_list()
),
),
);
$this->add_tabs_widget('options', array(
$this->add_tabs_widget(
'options',
array(
'title' => __('Advanced Options', 'wp-ultimo'),
'position' => 'normal',
'sections' => apply_filters('wu_discount_code_options_sections', $options, $this->get_object()),
));
)
);
/*
* Handle legacy options for back-compat.
*/
$this->handle_legacy_options();
$this->add_list_table_widget('events', array(
$this->add_list_table_widget(
'events',
array(
'title' => __('Events', 'wp-ultimo'),
'table' => new \WP_Ultimo\List_Tables\Inside_Events_List_Table(),
'query_filter' => array($this, 'query_filter'),
));
)
);
$this->add_save_widget('save', array(
$this->add_save_widget(
'save',
array(
'html_attr' => array(
'data-wu-app' => 'save_discount_code',
'data-state' => wu_convert_to_state(array(
'data-state' => wu_convert_to_state(
array(
'apply_to_setup_fee' => $this->get_object()->get_setup_fee_value() > 0,
'code' => $this->get_object()->get_code(),
'type' => $this->get_object()->get_type(),
'value' => $this->get_object()->get_value(),
'setup_fee_type' => $this->get_object()->get_setup_fee_type(),
'setup_fee_value' => $this->get_object()->get_setup_fee_value(),
)),
)
),
),
'fields' => array(
'code' => array(
@ -294,7 +308,7 @@ class Discount_Code_Edit_Admin_Page extends Edit_Admin_Page {
'html_attr' => array(
'min' => 0,
'v-bind:max' => "type === 'percentage' ? 100 : 999999999",
'step' => 'any'
'step' => 'any',
),
),
),
@ -355,9 +369,12 @@ class Discount_Code_Edit_Admin_Page extends Edit_Admin_Page {
),
),
),
));
)
);
$this->add_fields_widget('active', array(
$this->add_fields_widget(
'active',
array(
'title' => __('Active', 'wp-ultimo'),
'fields' => array(
'active' => array(
@ -367,9 +384,9 @@ class Discount_Code_Edit_Admin_Page extends Edit_Admin_Page {
'value' => $this->get_object()->is_active(),
),
),
));
} // end register_widgets;
)
);
}
/**
* List of products to apply this coupon to.
@ -382,7 +399,6 @@ class Discount_Code_Edit_Admin_Page extends Edit_Admin_Page {
$fields = array();
foreach (wu_get_products() as $product) {
$product_id = $product->get_id();
$fields[ "allowed_products_{$product_id}" ] = array(
@ -410,11 +426,9 @@ class Discount_Code_Edit_Admin_Page extends Edit_Admin_Page {
':name' => "'allowed_products[]'",
),
);
} // end foreach;
}
if (empty($fields)) {
$fields['allowed_products_no_products'] = array(
'type' => 'note',
'title' => '',
@ -424,12 +438,10 @@ class Discount_Code_Edit_Admin_Page extends Edit_Admin_Page {
'v-show' => 'limit_products',
),
);
} // end if;
}
return $fields;
} // end get_product_field_list;
}
/**
* Handles legacy advanced options for coupons.
@ -444,10 +456,8 @@ class Discount_Code_Edit_Admin_Page extends Edit_Admin_Page {
$tabs = array(__('Legacy Add-ons', 'wp-ultimo'));
if ( ! isset($wp_filter['wp_ultimo_coupon_advanced_options'])) {
return;
} // end if;
}
wp_enqueue_style('wu-legacy-admin-tabs', wu_get_asset('legacy-admin-tabs.css', 'css'), false, wu_get_version());
@ -463,24 +473,21 @@ class Discount_Code_Edit_Admin_Page extends Edit_Admin_Page {
);
foreach ($priorities as $priority => $callbacks) {
foreach ($callbacks as $id => $callable) {
$fields[ $id ] = array(
'type' => 'html',
'classes' => 'wu--mt-2',
'content' => function () use ($callable) {
call_user_func($callable['function'], $this->get_object());
},
);
}
}
} // end foreach;
} // end foreach;
$this->add_fields_widget('legacy-options', array(
$this->add_fields_widget(
'legacy-options',
array(
'title' => __('Legacy Options', 'wp-ultimo'),
'position' => 'normal',
'fields' => $fields,
@ -489,9 +496,9 @@ class Discount_Code_Edit_Admin_Page extends Edit_Admin_Page {
'html_attr' => array(
'style' => 'margin-top: -5px;',
),
));
} // end handle_legacy_options;
)
);
}
/**
* Register ajax forms that we use for discount code.
@ -504,11 +511,13 @@ class Discount_Code_Edit_Admin_Page extends Edit_Admin_Page {
* Delete Discount code - Confirmation modal
*/
add_filter('wu_data_json_success_delete_discount_code_modal', fn($data_json) => array(
'redirect_url' => wu_network_admin_url('wp-ultimo-discount-codes', array('deleted' => 1))
));
} // end register_forms;
add_filter(
'wu_data_json_success_delete_discount_code_modal',
fn($data_json) => array(
'redirect_url' => wu_network_admin_url('wp-ultimo-discount-codes', array('deleted' => 1)),
)
);
}
/**
* Filters the list table to return only relevant events.
@ -526,8 +535,7 @@ class Discount_Code_Edit_Admin_Page extends Edit_Admin_Page {
);
return array_merge($args, $extra_args);
} // end query_filter;
}
/**
* Returns the title of the page.
@ -538,8 +546,7 @@ class Discount_Code_Edit_Admin_Page extends Edit_Admin_Page {
public function get_title() {
return $this->edit ? __('Edit Discount Code', 'wp-ultimo') : __('Add new Discount Code', 'wp-ultimo');
} // end get_title;
}
/**
* Returns the title of menu for this page.
@ -550,8 +557,7 @@ class Discount_Code_Edit_Admin_Page extends Edit_Admin_Page {
public function get_menu_title() {
return __('Edit Discount Code', 'wp-ultimo');
} // end get_menu_title;
}
/**
* Returns the action links for that page.
@ -562,8 +568,7 @@ class Discount_Code_Edit_Admin_Page extends Edit_Admin_Page {
public function action_links() {
return array();
} // end action_links;
}
/**
* Returns the labels to be used on the admin page.
@ -584,8 +589,7 @@ class Discount_Code_Edit_Admin_Page extends Edit_Admin_Page {
'delete_button_label' => __('Delete Discount Code', 'wp-ultimo'),
'delete_description' => __('Be careful. This action is irreversible.', 'wp-ultimo'),
);
} // end get_labels;
}
/**
* Returns the object being edit at the moment.
@ -596,36 +600,29 @@ class Discount_Code_Edit_Admin_Page extends Edit_Admin_Page {
public function get_object() {
if ($this->object !== null) {
return $this->object;
} // end if;
}
if (isset($_GET['id'])) {
$item_id = wu_request('id', 0);
$item = wu_get_discount_code($item_id);
if ( ! $item) {
wp_redirect(wu_network_admin_url('wp-ultimo-discount_codes'));
exit;
} // end if;
}
$this->object = $item;
return $this->object;
}
} // end if;
$this->object = new Discount_Code;
$this->object = new Discount_Code();
return $this->object;
} // end get_object;
}
/**
* Discount_Codes have titles.
*
@ -634,8 +631,7 @@ class Discount_Code_Edit_Admin_Page extends Edit_Admin_Page {
public function has_title(): bool {
return true;
} // end has_title;
}
/**
* Should implement the processes necessary to save the changes made to the object.
@ -648,48 +644,36 @@ class Discount_Code_Edit_Admin_Page extends Edit_Admin_Page {
* Set the recurring value to zero if the toggle is disabled.
*/
if ( ! wu_request('apply_to_renewals')) {
$_POST['apply_to_renewals'] = false;
} // end if;
}
/*
* Set the limit products value.
*/
if ( ! wu_request('limit_products')) {
$_POST['limit_products'] = false;
} // end if;
}
/*
* Set the setup fee value to zero if the toggle is disabled.
*/
if ( ! wu_request('apply_to_setup_fee')) {
$_POST['setup_fee_value'] = 0;
} // end if;
}
/**
* Unset dates to prevent invalid dates
*/
if ( ! wu_request('enable_date_start') || ! wu_validate_date(wu_request('date_start'))) {
$_POST['date_start'] = null;
} // end if;
}
if ( ! wu_request('enable_date_expiration') || ! wu_validate_date(wu_request('date_expiration'))) {
$_POST['date_expiration'] = null;
} // end if;
}
$_POST['code'] = trim((string) wu_request('code'));
parent::handle_save();
} // end handle_save;
} // end class Discount_Code_Edit_Admin_Page;
}
}

View File

@ -60,7 +60,7 @@ class Discount_Code_List_Admin_Page extends List_Admin_Page {
* @since 1.8.2
* @return void
*/
public function register_widgets() {} // end register_widgets;
public function register_widgets() {}
/**
* Returns an array with the labels for the edit page.
@ -74,8 +74,7 @@ class Discount_Code_List_Admin_Page extends List_Admin_Page {
'deleted_message' => __('Discount Code removed successfully.', 'wp-ultimo'),
'search_label' => __('Search Discount Code', 'wp-ultimo'),
);
} // end get_labels;
}
/**
* Returns the title of the page.
@ -86,8 +85,7 @@ class Discount_Code_List_Admin_Page extends List_Admin_Page {
public function get_title() {
return __('Discount Codes', 'wp-ultimo');
} // end get_title;
}
/**
* Returns the title of menu for this page.
@ -98,8 +96,7 @@ class Discount_Code_List_Admin_Page extends List_Admin_Page {
public function get_menu_title() {
return __('Discount Codes', 'wp-ultimo');
} // end get_menu_title;
}
/**
* Allows admins to rename the sub-menu (first item) for a top-level page.
@ -110,8 +107,7 @@ class Discount_Code_List_Admin_Page extends List_Admin_Page {
public function get_submenu_title() {
return __('Discount Codes', 'wp-ultimo');
} // end get_submenu_title;
}
/**
* Returns the action links for that page.
@ -128,8 +124,7 @@ class Discount_Code_List_Admin_Page extends List_Admin_Page {
'icon' => 'wu-circle-with-plus',
),
);
} // end action_links;
}
/**
* Loads the list table for this particular page.
@ -140,7 +135,5 @@ class Discount_Code_List_Admin_Page extends List_Admin_Page {
public function table() {
return new \WP_Ultimo\List_Tables\Discount_Code_List_Table();
} // end table;
} // end class Discount_Code_List_Admin_Page;
}
}

View File

@ -12,7 +12,7 @@ namespace WP_Ultimo\Admin_Pages;
// Exit if accessed directly
defined('ABSPATH') || exit;
use \WP_Ultimo\Database\Domains\Domain_Stage;
use WP_Ultimo\Database\Domains\Domain_Stage;
/**
* WP Multisite WaaS Domain Edit/Add New Admin Page.
@ -93,8 +93,7 @@ class Domain_Edit_Admin_Page extends Edit_Admin_Page {
add_filter('wu_form_fields_delete_domain_modal', array($this, 'domain_extra_delete_fields'), 10, 2);
add_action('wu_after_delete_domain_modal', array($this, 'domain_after_delete_actions'));
} // end register_forms;
}
/**
* Adds the extra delete fields to the delete form.
@ -112,12 +111,10 @@ class Domain_Edit_Admin_Page extends Edit_Admin_Page {
$has_other_domains = false;
if ($is_primary_domain) {
$other_domains = \WP_Ultimo\Models\Domain::get_by_site($domain->get_blog_id());
$has_other_domains = is_countable($other_domains) ? count($other_domains) - 1 : false;
} // end if;
}
$custom_fields = array(
'set_domain_as_primary' => array(
@ -162,8 +159,7 @@ class Domain_Edit_Admin_Page extends Edit_Admin_Page {
);
return array_merge($custom_fields, $fields);
} // end domain_extra_delete_fields;
}
/**
* Adds the primary domain handling to the domain deletion.
@ -180,14 +176,11 @@ class Domain_Edit_Admin_Page extends Edit_Admin_Page {
$new_primary_domain = wu_get_domain($new_primary_domain_name);
if ($new_primary_domain) {
$new_primary_domain->set_primary_domain(true);
$new_primary_domain->save();
} // end if;
} // end domain_after_delete_actions;
}
}
/**
* Allow child classes to register widgets, if they need them.
@ -199,7 +192,9 @@ class Domain_Edit_Admin_Page extends Edit_Admin_Page {
parent::register_widgets();
$this->add_fields_widget('domain-url', array(
$this->add_fields_widget(
'domain-url',
array(
'title' => __('Domain URL', 'wp-ultimo'),
'position' => 'normal',
'after' => array($this, 'render_dns_widget'),
@ -211,9 +206,12 @@ class Domain_Edit_Admin_Page extends Edit_Admin_Page {
'display_value' => '<span class="wu-text-sm wu-uppercase wu-font-mono">' . $this->get_object()->get_domain() . '</span> <a target="_blank" class="wu-no-underline" href="' . esc_url($this->get_object()->get_url()) . '"><span class="dashicons-wu-link1 "></span></a>',
),
),
));
)
);
$this->add_tabs_widget('options', array(
$this->add_tabs_widget(
'options',
array(
'title' => __('Domain Options', 'wp-ultimo'),
'position' => 'normal',
'sections' => array(
@ -251,28 +249,39 @@ class Domain_Edit_Admin_Page extends Edit_Admin_Page {
),
),
),
));
)
);
$this->add_list_table_widget('sites', array(
$this->add_list_table_widget(
'sites',
array(
'title' => __('Linked Site', 'wp-ultimo'),
'table' => new \WP_Ultimo\List_Tables\Memberships_Site_List_Table(),
'query_filter' => array($this, 'sites_query_filter'),
));
)
);
add_meta_box('wp-ultimo-domain-log', __('Domain Test Log', 'wp-ultimo'), array($this, 'render_log_widget'), get_current_screen()->id, 'normal', null);
$this->add_list_table_widget('events', array(
$this->add_list_table_widget(
'events',
array(
'title' => __('Events', 'wp-ultimo'),
'table' => new \WP_Ultimo\List_Tables\Inside_Events_List_Table(),
'query_filter' => array($this, 'query_filter'),
));
)
);
$this->add_save_widget('save', array(
$this->add_save_widget(
'save',
array(
'html_attr' => array(
'data-wu-app' => 'save',
'data-state' => wu_convert_to_state( array(
'data-state' => wu_convert_to_state(
array(
'stage' => $this->get_object()->get_stage(),
)),
)
),
),
'fields' => array(
'stage' => array(
@ -310,17 +319,22 @@ class Domain_Edit_Admin_Page extends Edit_Admin_Page {
),
),
),
));
)
);
$check_for_active_string = sprintf('%s.includes(stage)', json_encode(\WP_Ultimo\Models\Domain::INACTIVE_STAGES));
$this->add_fields_widget('basic', array(
$this->add_fields_widget(
'basic',
array(
'title' => __('Active', 'wp-ultimo'),
'html_attr' => array(
'data-wu-app' => 'basic',
'data-state' => wu_convert_to_state( array(
'data-state' => wu_convert_to_state(
array(
'stage' => $this->get_object()->get_stage(),
)),
)
),
),
'fields' => array(
'active' => array(
@ -347,8 +361,9 @@ class Domain_Edit_Admin_Page extends Edit_Admin_Page {
),
),
),
));
} // end register_widgets;
)
);
}
/**
* Renders the DNS widget
@ -358,11 +373,13 @@ class Domain_Edit_Admin_Page extends Edit_Admin_Page {
*/
public function render_dns_widget() {
wu_get_template('domain/dns-table', array(
wu_get_template(
'domain/dns-table',
array(
'domain' => $this->get_object(),
));
} // end render_dns_widget;
)
);
}
/**
* Renders the DNS widget
@ -372,12 +389,14 @@ class Domain_Edit_Admin_Page extends Edit_Admin_Page {
*/
public function render_log_widget() {
wu_get_template('domain/log', array(
wu_get_template(
'domain/log',
array(
'domain' => $this->get_object(),
'log_path' => \WP_Ultimo\Logger::get_logs_folder(),
));
} // end render_log_widget;
)
);
}
/**
* Returns the title of the page.
@ -388,8 +407,7 @@ class Domain_Edit_Admin_Page extends Edit_Admin_Page {
public function get_title() {
return $this->edit ? __('Edit Domain', 'wp-ultimo') : __('Add new Domain', 'wp-ultimo');
} // end get_title;
}
/**
* Returns the title of menu for this page.
@ -400,8 +418,7 @@ class Domain_Edit_Admin_Page extends Edit_Admin_Page {
public function get_menu_title() {
return __('Edit Domain', 'wp-ultimo');
} // end get_menu_title;
}
/**
* Returns the action links for that page.
@ -412,8 +429,7 @@ class Domain_Edit_Admin_Page extends Edit_Admin_Page {
public function action_links() {
return array();
} // end action_links;
}
/**
* Returns the labels to be used on the admin page.
@ -434,8 +450,7 @@ class Domain_Edit_Admin_Page extends Edit_Admin_Page {
'delete_button_label' => __('Delete Domain', 'wp-ultimo'),
'delete_description' => __('Be careful. This action is irreversible.', 'wp-ultimo'),
);
} // end get_labels;
}
/**
* Filters the list table to return only relevant events.
@ -453,8 +468,7 @@ class Domain_Edit_Admin_Page extends Edit_Admin_Page {
);
return array_merge($args, $extra_args);
} // end query_filter;
}
/**
* Filters the list table to return only relevant sites.
@ -469,8 +483,7 @@ class Domain_Edit_Admin_Page extends Edit_Admin_Page {
$args['blog_id'] = $this->get_object()->get_site_id();
return $args;
} // end sites_query_filter;
}
/**
* Returns the object being edit at the moment.
@ -481,28 +494,23 @@ class Domain_Edit_Admin_Page extends Edit_Admin_Page {
public function get_object() {
if ($this->object !== null) {
return $this->object;
} // end if;
}
$item_id = wu_request('id', 0);
$item = wu_get_domain($item_id);
if ( ! $item) {
wp_redirect(wu_network_admin_url('wp-ultimo-domains'));
exit;
} // end if;
}
$this->object = $item;
return $this->object;
} // end get_object;
}
/**
* Domains have titles.
*
@ -511,8 +519,7 @@ class Domain_Edit_Admin_Page extends Edit_Admin_Page {
public function has_title(): bool {
return false;
} // end has_title;
}
/**
* Should implement the processes necessary to save the changes made to the object.
@ -523,27 +530,19 @@ class Domain_Edit_Admin_Page extends Edit_Admin_Page {
public function handle_save() {
if ( ! wu_request('primary_domain')) {
$_POST['primary_domain'] = false;
} // end if;
}
if ( ! wu_request('active')) {
$_POST['active'] = false;
} // end if;
}
if ( ! wu_request('secure')) {
$_POST['secure'] = false;
} // end if;
}
wu_enqueue_async_action('wu_async_process_domain_stage', array('domain_id' => $this->get_object()->get_id()), 'domain');
parent::handle_save();
} // end handle_save;
} // end class Domain_Edit_Admin_Page;
}
}

View File

@ -12,8 +12,8 @@ namespace WP_Ultimo\Admin_Pages;
// Exit if accessed directly
defined('ABSPATH') || exit;
use \WP_Ultimo\Models\Domain;
use \WP_Ultimo\Database\Domains\Domain_Stage;
use WP_Ultimo\Models\Domain;
use WP_Ultimo\Database\Domains\Domain_Stage;
/**
* WP Multisite WaaS Dashboard Admin Page.
@ -67,13 +67,15 @@ class Domain_List_Admin_Page extends List_Admin_Page {
/*
* Add new Domain
*/
wu_register_form('add_new_domain', array(
wu_register_form(
'add_new_domain',
array(
'render' => array($this, 'render_add_new_domain_modal'),
'handler' => array($this, 'handle_add_new_domain_modal'),
'capability' => 'wu_edit_domains',
));
} // end register_forms;
)
);
}
/**
* Renders the add new customer modal.
@ -83,9 +85,12 @@ class Domain_List_Admin_Page extends List_Admin_Page {
*/
public function render_add_new_domain_modal() {
$addon_url = wu_network_admin_url('wp-ultimo-addons', array(
's' => 'Domain Seller'
));
$addon_url = wu_network_admin_url(
'wp-ultimo-addons',
array(
's' => 'Domain Seller',
)
);
// translators: %s is the URL to the add-on.
$note_desc = sprintf(__('To activate this feature you need to install the <a href="%s" target="_blank" class="wu-no-underline">WP Multisite WaaS: Domain Seller</a> add-on.', 'wp-ultimo'), $addon_url);
@ -182,22 +187,27 @@ class Domain_List_Admin_Page extends List_Admin_Page {
),
);
$form = new \WP_Ultimo\UI\Form('add_new_domain', $fields, array(
$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(
'data-state' => json_encode(
array(
'type' => 'add',
'primary_domain' => false,
)),
)
),
));
),
)
);
$form->render();
} // end render_add_new_domain_modal;
}
/**
* Handles creation of a new customer.
@ -218,46 +228,49 @@ class Domain_List_Admin_Page extends List_Admin_Page {
/*
* Tries to create the domain
*/
$domain = wu_create_domain(array(
$domain = wu_create_domain(
array(
'domain' => wu_request('domain'),
'stage' => wu_request('stage'),
'blog_id' => (int) wu_request('blog_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(
$old_primary_domains = wu_get_domains(
array(
'primary_domain' => true,
'blog_id' => wu_request('blog_id'),
'id__not_in' => array($domain->get_id()),
'fields' => 'ids',
));
)
);
/*
* Trigger async action to update the old primary domains.
*/
do_action('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');
wp_send_json_success(array(
'redirect_url' => wu_network_admin_url('wp-ultimo-edit-domain', array(
wp_send_json_success(
array(
'redirect_url' => wu_network_admin_url(
'wp-ultimo-edit-domain',
array(
'id' => $domain->get_id(),
))
));
} // end if;
} // end handle_add_new_domain_modal;
)
),
)
);
}
}
/**
* Returns an array with the labels for the edit page.
@ -271,8 +284,7 @@ class Domain_List_Admin_Page extends List_Admin_Page {
'deleted_message' => __('Domains removed successfully.', 'wp-ultimo'),
'search_label' => __('Search Domains', 'wp-ultimo'),
);
} // end get_labels;
}
/**
* Returns the title of the page.
@ -283,8 +295,7 @@ class Domain_List_Admin_Page extends List_Admin_Page {
public function get_title() {
return __('Domains', 'wp-ultimo');
} // end get_title;
}
/**
* Returns the title of menu for this page.
@ -295,8 +306,7 @@ class Domain_List_Admin_Page extends List_Admin_Page {
public function get_menu_title() {
return __('Domains', 'wp-ultimo');
} // end get_menu_title;
}
/**
* Allows admins to rename the sub-menu (first item) for a top-level page.
@ -307,8 +317,7 @@ class Domain_List_Admin_Page extends List_Admin_Page {
public function get_submenu_title() {
return __('Domains', 'wp-ultimo');
} // end get_submenu_title;
}
/**
* Returns the action links for that page.
@ -326,8 +335,7 @@ class Domain_List_Admin_Page extends List_Admin_Page {
'url' => wu_get_form_url('add_new_domain'),
),
);
} // end action_links;
}
/**
* Loads the list table for this particular page.
@ -338,7 +346,5 @@ class Domain_List_Admin_Page extends List_Admin_Page {
public function table() {
return new \WP_Ultimo\List_Tables\Domain_List_Table();
} // end table;
} // end class Domain_List_Admin_Page;
}
}

View File

@ -63,14 +63,11 @@ abstract class Edit_Admin_Page extends Base_Admin_Page {
public function get_errors() {
if ($this->errors === null) {
$this->errors = new \WP_Error;
} // end if;
$this->errors = new \WP_Error();
}
return $this->errors;
} // end get_errors;
}
/**
* Register additional hooks to page load such as the action links and the save processing.
@ -93,22 +90,16 @@ abstract class Edit_Admin_Page extends Base_Admin_Page {
$this->add_lock_notices();
if (wu_request('submit_button') === 'delete') {
$this->process_delete();
} elseif (wu_request('remove-lock')) {
$this->remove_lock();
} else {
/*
* Process save, if necessary
*/
$this->process_save();
} // end if;
} // end page_loaded;
}
}
/**
* Add some other necessary hooks.
@ -120,8 +111,7 @@ abstract class Edit_Admin_Page extends Base_Admin_Page {
parent::hooks();
add_filter('removable_query_args', array($this, 'removable_query_args'));
} // end hooks;
}
/**
* Adds the wu-new-model to the list of removable query args of WordPress.
@ -136,8 +126,7 @@ abstract class Edit_Admin_Page extends Base_Admin_Page {
$removable_query_args[] = 'wu-new-model';
return $removable_query_args;
} // end removable_query_args;
}
/**
* Displays lock notices, if necessary.
@ -157,18 +146,18 @@ abstract class Edit_Admin_Page extends Base_Admin_Page {
$actions = array(
'preview' => array(
'title' => __('Unlock', 'wp-ultimo'),
'url' => add_query_arg(array(
'url' => add_query_arg(
array(
'remove-lock' => 1,
'unlock_wpultimo_nonce' => wp_create_nonce(sprintf('unlocking_%s', $this->object_id)),
)),
)
),
),
);
WP_Ultimo()->notices->add($message, 'warning', 'network-admin', false, $actions);
} // end if;
} // end add_lock_notices;
}
}
/**
* Remove the lock from the object.
@ -181,7 +170,6 @@ abstract class Edit_Admin_Page extends Base_Admin_Page {
$unlock_tag = "unlocking_{$this->object_id}";
if (isset($_REQUEST['remove-lock'])) {
check_admin_referer($unlock_tag, 'unlock_wpultimo_nonce');
/**
@ -196,16 +184,18 @@ abstract class Edit_Admin_Page extends Base_Admin_Page {
*/
$this->get_object()->unlock();
wp_redirect(remove_query_arg(array(
wp_redirect(
remove_query_arg(
array(
'remove-lock',
'unlock_wpultimo_nonce',
)));
)
)
);
exit;
} // end if;
} // end remove_lock;
}
}
/**
* Handles saves, after verifying nonces and such. Should not be rewritten by child classes.
@ -218,7 +208,6 @@ abstract class Edit_Admin_Page extends Base_Admin_Page {
$saving_tag = "saving_{$this->object_id}";
if (isset($_REQUEST[ $saving_tag ])) {
check_admin_referer($saving_tag, '_wpultimo_nonce');
/**
@ -234,14 +223,10 @@ abstract class Edit_Admin_Page extends Base_Admin_Page {
$status = $this->handle_save();
if ($status) {
exit;
} // end if;
} // end if;
} // end process_save;
}
}
}
/**
* Handles delete, after verifying nonces and such. Should not be rewritten by child classes.
@ -254,7 +239,6 @@ abstract class Edit_Admin_Page extends Base_Admin_Page {
$deleting_tag = "deleting_{$this->object_id}";
if (isset($_REQUEST[ $deleting_tag ])) {
check_admin_referer($deleting_tag, 'delete_wpultimo_nonce');
/**
@ -268,10 +252,8 @@ abstract class Edit_Admin_Page extends Base_Admin_Page {
* Calls the deleting function
*/
$this->handle_delete();
} // end if;
} // end process_delete;
}
}
/**
* Returns the labels to be used on the admin page.
@ -294,8 +276,7 @@ abstract class Edit_Admin_Page extends Base_Admin_Page {
);
return apply_filters('wu_edit_admin_page_labels', $default_labels);
} // end get_labels;
}
/**
* Allow child classes to register scripts and styles that can be loaded on the output function, for example.
@ -322,8 +303,7 @@ abstract class Edit_Admin_Page extends Base_Admin_Page {
wp_enqueue_style('wp-color-picker');
wp_enqueue_script('wu-selectizer');
} // end register_scripts;
}
/**
* Registers widgets to the edit page.
@ -339,18 +319,18 @@ abstract class Edit_Admin_Page extends Base_Admin_Page {
$screen = get_current_screen();
$this->add_info_widget('info', array(
$this->add_info_widget(
'info',
array(
'title' => __('Timestamps', 'wp-ultimo'),
'position' => 'side-bottom',
));
)
);
if ($this->edit) {
$this->add_delete_widget('delete', array());
} // end if;
} // end register_widgets;
}
}
/**
* Adds a basic widget with info (and fields) to be shown.
@ -366,10 +346,8 @@ abstract class Edit_Admin_Page extends Base_Admin_Page {
$created_key = 'date_created';
if (method_exists($this->get_object(), 'get_date_registered')) {
$created_key = 'date_registered';
} // end if;
}
$created_value = call_user_func(array($this->get_object(), "get_$created_key"));
@ -390,7 +368,6 @@ abstract class Edit_Admin_Page extends Base_Admin_Page {
$show_modified = wu_get_isset($atts, 'modified', true);
if ($this->edit && $show_modified === true) {
$atts['fields']['date_modified'] = array(
'title' => __('Last Modified at', 'wp-ultimo'),
'type' => 'text-display',
@ -404,12 +381,10 @@ abstract class Edit_Admin_Page extends Base_Admin_Page {
'data-allow-time' => 'true',
),
);
} // end if;
}
$this->add_fields_widget($id, $atts);
} // end add_info_widget;
}
/**
* Adds a basic widget to display list tables.
@ -422,7 +397,9 @@ abstract class Edit_Admin_Page extends Base_Admin_Page {
*/
protected function add_list_table_widget($id, $atts = array()) {
$atts = wp_parse_args($atts, array(
$atts = wp_parse_args(
$atts,
array(
'widget_id' => $id,
'before' => '',
'after' => '',
@ -435,37 +412,43 @@ abstract class Edit_Admin_Page extends Base_Admin_Page {
'edit' => true,
'table' => false,
'query_filter' => false,
));
)
);
$atts['table']->set_context('widget');
$table_name = $atts['table']->get_table_id();
if (is_callable($atts['query_filter'])) {
add_filter("wu_{$table_name}_get_items", $atts['query_filter']);
}
} // end if;
add_filter('wu_events_list_table_get_columns', function($columns) {
add_filter(
'wu_events_list_table_get_columns',
function ($columns) {
unset($columns['object_type']);
unset($columns['code']);
return $columns;
}
);
});
add_meta_box("wp-ultimo-list-table-{$id}", $atts['title'], function() use ($atts) {
add_meta_box(
"wp-ultimo-list-table-{$id}",
$atts['title'],
function () use ($atts) {
wp_enqueue_script('wu-ajax-list-table');
wu_get_template('base/edit/widget-list-table', $atts);
}, $atts['screen']->id, $atts['position'], 'default');
} // end add_list_table_widget;
},
$atts['screen']->id,
$atts['position'],
'default'
);
}
/**
* Adds field widgets to edit pages with the same Form/Field APIs used elsewhere.
@ -479,7 +462,9 @@ abstract class Edit_Admin_Page extends Base_Admin_Page {
*/
protected function add_fields_widget($id, $atts = array()) {
$atts = wp_parse_args($atts, array(
$atts = wp_parse_args(
$atts,
array(
'widget_id' => $id,
'before' => '',
'after' => '',
@ -490,12 +475,15 @@ abstract class Edit_Admin_Page extends Base_Admin_Page {
'html_attr' => array(),
'classes' => '',
'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',
));
)
);
add_meta_box("wp-ultimo-{$id}-widget", $atts['title'], function() use ($atts) {
add_meta_box(
"wp-ultimo-{$id}-widget",
$atts['title'],
function () use ($atts) {
if (wu_get_isset($atts['html_attr'], 'data-wu-app')) {
$atts['fields']['loading'] = array(
'type' => 'note',
'desc' => sprintf('<div class="wu-block wu-text-center wu-blinking-animation wu-text-gray-600 wu-my-1 wu-text-2xs wu-uppercase wu-font-semibold">%s</div>', __('Loading...', 'wp-ultimo')),
@ -503,28 +491,33 @@ abstract class Edit_Admin_Page extends Base_Admin_Page {
'v-if' => 0,
),
);
} // end if;
}
/**
* Instantiate the form for the order details.
*
* @since 2.0.0
*/
$form = new \WP_Ultimo\UI\Form($atts['widget_id'], $atts['fields'], array(
$form = new \WP_Ultimo\UI\Form(
$atts['widget_id'],
$atts['fields'],
array(
'views' => 'admin-pages/fields',
'classes' => 'wu-widget-list wu-striped wu-m-0 wu--mt-2 wu--mb-3 wu--mx-3 ' . $atts['classes'],
'field_wrapper_classes' => $atts['field_wrapper_classes'],
'html_attr' => $atts['html_attr'],
'before' => $atts['before'],
'after' => $atts['after'],
));
)
);
$form->render();
}, $atts['screen']->id, $atts['position'], 'default');
} // end add_fields_widget;
},
$atts['screen']->id,
$atts['position'],
'default'
);
}
/**
* Adds field widgets to edit pages with the same Form/Field APIs used elsewhere.
@ -538,7 +531,9 @@ abstract class Edit_Admin_Page extends Base_Admin_Page {
*/
protected function add_tabs_widget($id, $atts = array()) {
$atts = wp_parse_args($atts, array(
$atts = wp_parse_args(
$atts,
array(
'widget_id' => $id,
'before' => '',
'after' => '',
@ -547,7 +542,8 @@ abstract class Edit_Admin_Page extends Base_Admin_Page {
'screen' => get_current_screen(),
'sections' => array(),
'html_attr' => array(),
));
)
);
$current_section = wu_request($id, current(array_keys($atts['sections'])));
@ -558,11 +554,15 @@ abstract class Edit_Admin_Page extends Base_Admin_Page {
'display_all' => false,
);
add_meta_box("wp-ultimo-{$id}-widget", $atts['title'], function() use ($atts) {
add_meta_box(
"wp-ultimo-{$id}-widget",
$atts['title'],
function () use ($atts) {
foreach ($atts['sections'] as $section_id => &$section) {
$section = wp_parse_args($section, array(
$section = wp_parse_args(
$section,
array(
'form' => '',
'before' => '',
'after' => '',
@ -571,7 +571,8 @@ abstract class Edit_Admin_Page extends Base_Admin_Page {
'html_attr' => array(),
'state' => array(),
'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',
));
)
);
/**
* Move state ont step up
@ -586,7 +587,8 @@ abstract class Edit_Admin_Page extends Base_Admin_Page {
/**
* Adds a header field
*/
$section['fields'] = array_merge(array(
$section['fields'] = array_merge(
array(
$section_id => array(
'title' => $section['title'],
'desc' => $section['desc'],
@ -594,35 +596,45 @@ abstract class Edit_Admin_Page extends Base_Admin_Page {
'wrapper_html_attr' => array(
'v-show' => 'display_all',
),
)
), $section['fields']);
),
),
$section['fields']
);
/**
* Instantiate the form for the order details.
*
* @since 2.0.0
*/
$section['form'] = new \WP_Ultimo\UI\Form($section_id, $section['fields'], array(
$section['form'] = new \WP_Ultimo\UI\Form(
$section_id,
$section['fields'],
array(
'views' => 'admin-pages/fields',
'classes' => 'wu-widget-list wu-striped wu-m-0 wu-border-solid wu-border-gray-300 wu-border-0 wu-border-b',
'field_wrapper_classes' => $section['field_wrapper_classes'],
'html_attr' => $section['html_attr'],
'before' => $section['before'],
'after' => $section['after'],
));
)
);
}
} // end foreach;
wu_get_template('base/edit/widget-tabs', array(
wu_get_template(
'base/edit/widget-tabs',
array(
'sections' => $atts['sections'],
'html_attr' => $atts['html_attr'],
'before' => $atts['before'],
'after' => $atts['after'],
));
}, $atts['screen']->id, $atts['position'], 'default');
} // end add_tabs_widget;
)
);
},
$atts['screen']->id,
$atts['position'],
'default'
);
}
/**
* Adds a generic widget to the admin page.
@ -635,7 +647,9 @@ abstract class Edit_Admin_Page extends Base_Admin_Page {
*/
protected function add_widget($id, $atts = array()) {
$atts = wp_parse_args($atts, array(
$atts = wp_parse_args(
$atts,
array(
'widget_id' => $id,
'before' => '',
'after' => '',
@ -643,11 +657,11 @@ abstract class Edit_Admin_Page extends Base_Admin_Page {
'screen' => get_current_screen(),
'position' => 'side',
'display' => '__return_empty_string',
));
)
);
add_meta_box("wp-ultimo-{$id}-widget", $atts['title'], $atts['display'], $atts['screen']->id, $atts['position'], 'default');
} // end add_widget;
}
/**
* Adds a basic save widget.
@ -678,22 +692,17 @@ abstract class Edit_Admin_Page extends Base_Admin_Page {
);
if (isset($atts['html_attr']['data-wu-app'])) {
$atts['fields']['submit_save']['wrapper_html_attr']['v-cloak'] = 1;
} // end if;
}
if ($this->get_object() && $this->edit && $this->get_object()->is_locked()) {
$atts['fields']['submit_save']['title'] = __('Locked', 'wp-ultimo');
$atts['fields']['submit_save']['value'] = 'none';
$atts['fields']['submit_save']['html_attr']['disabled'] = 'disabled';
} // end if;
}
$this->add_fields_widget('save', $atts);
} // end add_save_widget;
}
/**
* Adds a basic delete widget.
@ -739,7 +748,7 @@ abstract class Edit_Admin_Page extends Base_Admin_Page {
'delete_modal',
array(
'id' => $this->get_object()->get_id(),
'model' => $this->get_object()->model
'model' => $this->get_object()->model,
)
),
),
@ -750,8 +759,7 @@ abstract class Edit_Admin_Page extends Base_Admin_Page {
$atts['fields']['delete'] = array_merge($default_delete_field_settings, $custom_delete_field_settings);
$this->add_fields_widget('delete', $atts);
} // end add_delete_widget;
}
/**
* Displays the contents of the edit page.
@ -763,14 +771,16 @@ abstract class Edit_Admin_Page extends Base_Admin_Page {
/*
* Renders the base edit page layout, with the columns and everything else =)
*/
wu_get_template('base/edit', array(
wu_get_template(
'base/edit',
array(
'screen' => get_current_screen(),
'page' => $this,
'labels' => $this->get_labels(),
'object' => $this->get_object(),
));
} // end output;
)
);
}
/**
* Wether or not this pages should have a title field.
@ -781,8 +791,7 @@ abstract class Edit_Admin_Page extends Base_Admin_Page {
public function has_title() {
return false;
} // end has_title;
}
/**
* Wether or not this pages should have an editor field.
@ -793,8 +802,7 @@ abstract class Edit_Admin_Page extends Base_Admin_Page {
public function has_editor() {
return false;
} // end has_editor;
}
/**
* Should return the object being edited, or false.
@ -805,7 +813,7 @@ abstract class Edit_Admin_Page extends Base_Admin_Page {
* @since 2.0.0
* @return \WP_Ultimo\Models\Base_Model
*/
abstract public function get_object(); // end get_object;
abstract public function get_object();
/**
* Should implement the processes necessary to save the changes made to the object.
@ -825,44 +833,36 @@ abstract class Edit_Admin_Page extends Base_Admin_Page {
$object->attributes($_POST);
if (method_exists($object, 'handle_limitations')) {
$object->handle_limitations($_POST); // @phpstan-ignore-line
} // end if;
}
$save = $object->save();
if (is_wp_error($save)) {
$errors = implode('<br>', $save->get_error_messages());
WP_Ultimo()->notices->add($errors, 'error', 'network-admin');
return false;
} else {
$array_params = array(
'updated' => 1,
);
if ($this->edit === false) {
$array_params['id'] = $object->get_id();
$array_params['wu-new-model'] = true;
} // end if;
}
$url = add_query_arg($array_params);
wp_redirect($url);
return true;
} // end if;
} // end handle_save;
}
}
/**
* Should implement the processes necessary to delete the object.
@ -877,13 +877,12 @@ abstract class Edit_Admin_Page extends Base_Admin_Page {
$saved = $object->delete();
if (is_wp_error($saved)) {
$errors = implode('<br>', $saved->get_error_messages());
WP_Ultimo()->notices->add($errors, 'error', 'network-admin');
return;
} // end if;
}
$url = str_replace('_', '-', (string) $object->model);
$url = wu_network_admin_url("wp-ultimo-{$url}s");
@ -891,7 +890,5 @@ abstract class Edit_Admin_Page extends Base_Admin_Page {
wp_redirect($url);
exit;
} // end handle_delete;
} // end class Edit_Admin_Page;
}
}

View File

@ -12,8 +12,8 @@ namespace WP_Ultimo\Admin_Pages;
// Exit if accessed directly
defined('ABSPATH') || exit;
use \WP_Ultimo\Models\Email;
use \WP_Ultimo\Managers\Email_Manager;
use WP_Ultimo\Models\Email;
use WP_Ultimo\Managers\Email_Manager;
/**
* WP Multisite WaaS Email Edit/Add New Admin Page.
@ -96,8 +96,7 @@ class Email_Edit_Admin_Page extends Edit_Admin_Page {
parent::init();
add_action('wu_page_edit_redirect_handlers', array($this, 'handle_page_redirect'), 10);
} // end init;
}
/**
* Registers the necessary scripts.
@ -110,8 +109,7 @@ class Email_Edit_Admin_Page extends Edit_Admin_Page {
parent::register_scripts();
wp_enqueue_script('wu-email-edit-page', wu_get_asset('email-edit-page.js', 'js'), array('jquery', 'clipboard'));
} // end register_scripts;
}
/**
* Allow child classes to register widgets, if they need them.
@ -131,22 +129,28 @@ class Email_Edit_Admin_Page extends Edit_Admin_Page {
// translators: %1$s is replaced with the number of hours, %2$s is replaced with the number of minutes.
$hour_text = sprintf(__('Send %1$s hour(s) and %2$s minute(s) after the event.', 'wp-ultimo'), '{{ hours.split(":").shift() }}', '{{ hours.split(":").pop() }}');
$desc = sprintf('
<span v-show="schedule && schedule_type == \'days\'">%s</span>
<span v-show="schedule && schedule_type == \'hours\'">%s</span>
', $days_text, $hour_text);
$desc = sprintf(
'<span v-show="schedule && schedule_type == \'days\'">%s</span>
<span v-show="schedule && schedule_type == \'hours\'">%s</span>',
$days_text,
$hour_text
);
$this->add_save_widget('save', array(
$this->add_save_widget(
'save',
array(
'html_attr' => array(
'data-wu-app' => 'email_edit_save',
'data-state' => wu_convert_to_state(array(
'data-state' => wu_convert_to_state(
array(
'slug' => $this->edit ? $object->get_slug() : '',
'target' => $this->edit ? $object->get_target() : 'admin',
'schedule' => $this->edit ? $object->has_schedule() : false,
'schedule_type' => $this->edit ? $object->get_schedule_type() : 'days',
'days' => $this->edit ? $object->get_send_days() : 1,
'hours' => $this->edit ? $object->get_send_hours() : '12:00',
)),
)
),
),
'fields' => array(
'slug' => array(
@ -168,7 +172,7 @@ class Email_Edit_Admin_Page extends Edit_Admin_Page {
'options' => 'wu_get_event_types_as_options',
'value' => $this->edit ? $object->get_event() : 0,
'html_attr' => array(
'name' => ''
'name' => '',
),
),
'target' => array(
@ -264,11 +268,14 @@ class Email_Edit_Admin_Page extends Edit_Admin_Page {
),
),
));
)
);
add_meta_box('wp-ultimo-placeholders', __('Placeholders', 'wp-ultimo'), array($this, 'output_default_widget_placeholders'), get_current_screen()->id, 'normal', null, array());
$this->add_fields_widget('active', array(
$this->add_fields_widget(
'active',
array(
'title' => __('Active', 'wp-ultimo'),
'fields' => array(
'active' => array(
@ -278,9 +285,12 @@ class Email_Edit_Admin_Page extends Edit_Admin_Page {
'value' => $this->get_object()->is_active(),
),
),
));
)
);
$this->add_tabs_widget('email_edit_options', array(
$this->add_tabs_widget(
'email_edit_options',
array(
'title' => __('Advanced Options', 'wp-ultimo'),
'position' => 'normal',
'sections' => array(
@ -343,11 +353,11 @@ class Email_Edit_Admin_Page extends Edit_Admin_Page {
),
),
),
),
),
)
)
));
} // end register_widgets;
);
}
/**
* Outputs the block that shows the event payload placeholders.
@ -360,12 +370,14 @@ class Email_Edit_Admin_Page extends Edit_Admin_Page {
*/
public function output_default_widget_placeholders($unused, $data) {
wu_get_template('email/widget-placeholders', array(
wu_get_template(
'email/widget-placeholders',
array(
'title' => __('Event Payload', 'wp-ultimo'),
'loading_text' => __('Loading Payload', 'wp-ultimo'),
));
} // end output_default_widget_placeholders;
)
);
}
/**
* Returns the title of the page.
@ -376,8 +388,7 @@ class Email_Edit_Admin_Page extends Edit_Admin_Page {
public function get_title() {
return $this->edit ? __('Edit Email', 'wp-ultimo') : __('Add new Email', 'wp-ultimo');
} // end get_title;
}
/**
* Returns the title of menu for this page.
@ -388,8 +399,7 @@ class Email_Edit_Admin_Page extends Edit_Admin_Page {
public function get_menu_title() {
return __('Edit Email', 'wp-ultimo');
} // end get_menu_title;
}
/**
* Returns the action links for that page.
@ -402,7 +412,7 @@ class Email_Edit_Admin_Page extends Edit_Admin_Page {
$url_atts = array(
'id' => $this->get_object()->get_id(),
'model' => 'email',
'page' => 'edit'
'page' => 'edit',
);
$send_test_link = wu_get_form_url('send_new_test', $url_atts);
@ -417,11 +427,10 @@ class Email_Edit_Admin_Page extends Edit_Admin_Page {
'url' => $send_test_link,
'label' => __('Send Test Email', 'wp-ultimo'),
'icon' => 'wu-mail',
'classes' => 'wubox'
'classes' => 'wubox',
),
);
} // end action_links;
}
/**
* Returns the labels to be used on the admin page.
@ -442,8 +451,7 @@ class Email_Edit_Admin_Page extends Edit_Admin_Page {
'delete_button_label' => __('Delete Email', 'wp-ultimo'),
'delete_description' => __('Be careful. This action is irreversible.', 'wp-ultimo'),
);
} // end get_labels;
}
/**
* Filters the list table to return only relevant events.
@ -461,8 +469,7 @@ class Email_Edit_Admin_Page extends Edit_Admin_Page {
);
return array_merge($args, $extra_args);
} // end query_filter;
}
/**
* Handles the toggles.
@ -479,8 +486,7 @@ class Email_Edit_Admin_Page extends Edit_Admin_Page {
$_POST['custom_sender'] = wu_request('custom_sender');
parent::handle_save();
} // end handle_save;
}
/**
* Handles the redirect notice from sent new test modal.
@ -491,9 +497,7 @@ class Email_Edit_Admin_Page extends Edit_Admin_Page {
public function handle_page_redirect($page) {
if ($page->get_id() === 'wp-ultimo-edit-email') {
if (wu_request('test_notice')) {
$test_notice = wu_request('test_notice');
?>
@ -506,11 +510,9 @@ class Email_Edit_Admin_Page extends Edit_Admin_Page {
<?php
} // end if;
} // end if;
} // end handle_page_redirect;
}
}
}
/**
* Returns the object being edit at the moment.
@ -521,26 +523,21 @@ class Email_Edit_Admin_Page extends Edit_Admin_Page {
public function get_object() {
if (isset($_GET['id'])) {
$query = new \WP_Ultimo\Database\Emails\Email_Query;
$query = new \WP_Ultimo\Database\Emails\Email_Query();
$item = $query->get_item_by('id', $_GET['id']);
if (! $item) {
wp_redirect(wu_network_admin_url('wp-ultimo-emails'));
exit;
} // end if;
}
return $item;
}
} // end if;
return new Email;
} // end get_object;
return new Email();
}
/**
* Emails have titles.
*
@ -549,8 +546,7 @@ class Email_Edit_Admin_Page extends Edit_Admin_Page {
public function has_title(): bool {
return true;
} // end has_title;
}
/**
* Wether or not this pages should have an editor field.
*
@ -559,8 +555,7 @@ class Email_Edit_Admin_Page extends Edit_Admin_Page {
public function has_editor(): bool {
return true;
} // end has_editor;
}
/**
* Filters the list table to return only relevant events.
@ -578,7 +573,5 @@ class Email_Edit_Admin_Page extends Edit_Admin_Page {
);
return array_merge($args, $extra_args);
} // end events_query_filter;
} // end class Email_Edit_Admin_Page;
}
}

View File

@ -84,8 +84,7 @@ class Email_List_Admin_Page extends List_Admin_Page {
parent::init();
add_action('wu_page_list_redirect_handlers', array($this, 'handle_page_redirect'), 10);
} // end init;
}
/**
* Allow child classes to register widgets, if they need them.
@ -93,7 +92,7 @@ class Email_List_Admin_Page extends List_Admin_Page {
* @since 1.8.2
* @return void
*/
public function register_widgets() {} // end register_widgets;
public function register_widgets() {}
/**
* Returns the title of the page.
@ -104,8 +103,7 @@ class Email_List_Admin_Page extends List_Admin_Page {
public function get_title() {
return __('System Emails', 'wp-ultimo');
} // end get_title;
}
/**
* Returns the title of menu for this page.
@ -116,8 +114,7 @@ class Email_List_Admin_Page extends List_Admin_Page {
public function get_menu_title() {
return __('System Emails', 'wp-ultimo');
} // end get_menu_title;
}
/**
* Allows admins to rename the sub-menu (first item) for a top-level page.
@ -128,8 +125,7 @@ class Email_List_Admin_Page extends List_Admin_Page {
public function get_submenu_title() {
return __('System Emails', 'wp-ultimo');
} // end get_submenu_title;
}
/**
* Register ajax form that we use for system emails.
@ -141,31 +137,39 @@ class Email_List_Admin_Page extends List_Admin_Page {
/*
* Send a email test
*/
wu_register_form('send_new_test', array(
wu_register_form(
'send_new_test',
array(
'render' => array($this, 'render_send_new_test_modal'),
'handler' => array($this, 'handle_send_new_test_modal'),
'capability' => 'wu_add_broadcast',
));
)
);
/*
* Reset or Import modal.
*/
wu_register_form('reset_import', array(
wu_register_form(
'reset_import',
array(
'render' => array($this, 'render_reset_import_modal'),
'handler' => array($this, 'handle_reset_import_modal'),
'capability' => 'wu_add_broadcasts',
));
)
);
/*
* Reset Confirmation modal.
*/
wu_register_form('reset_confirmation', array(
wu_register_form(
'reset_confirmation',
array(
'render' => array($this, 'render_reset_confirmation_modal'),
'handler' => array($this, 'handle_reset_confirmation_modal'),
'capability' => 'wu_add_broadcasts',
));
} // end register_forms;
)
);
}
/**
* Renders the modal to send tests with system emails.
@ -184,7 +188,7 @@ class Email_List_Admin_Page extends List_Admin_Page {
'value' => get_network_option(null, 'admin_email'),
'html_attr' => array(
'required' => 'required',
)
),
),
'email_id' => array(
'type' => 'hidden',
@ -203,18 +207,21 @@ class Email_List_Admin_Page extends List_Admin_Page {
),
);
$form = new \WP_Ultimo\UI\Form('send_new_test', $fields, array(
$form = new \WP_Ultimo\UI\Form(
'send_new_test',
$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' => 'send_new_test',
),
));
)
);
$form->render();
} // end render_send_new_test_modal;
}
/**
* Handles the modal to send tests with system emails.
@ -229,12 +236,10 @@ class Email_List_Admin_Page extends List_Admin_Page {
$send_to = wu_request('send_to');
if ( ! $email_id || ! $send_to) {
$error = new \WP_Error('error', __('Something wrong happened.', 'wp-ultimo'));
return wp_send_json_error($error);
} // end if;
}
$from = array(
'name' => wu_get_setting('from_name'),
@ -245,7 +250,7 @@ class Email_List_Admin_Page extends List_Admin_Page {
array(
'name' => wu_get_setting('from_name'),
'email' => $send_to,
)
),
);
$email = wu_get_email($email_id);
@ -257,10 +262,8 @@ class Email_List_Admin_Page extends List_Admin_Page {
$payload = array();
if ($event_type) {
$payload = wu_maybe_lazy_load_payload($event_type['payload']);
} // end if;
}
$args = array(
'style' => $email->get_style(),
@ -272,35 +275,40 @@ class Email_List_Admin_Page extends List_Admin_Page {
$send_mail = wu_send_mail($from, $to, $args);
if ( ! $send_mail) {
$error = new \WP_Error('error', __('Something wrong happened with your test.', 'wp-ultimo'));
return wp_send_json_error($error);
} // end if;
}
$page = wu_request('page', 'list');
if ($page === 'edit') {
wp_send_json_success(array(
'redirect_url' => wu_network_admin_url('wp-ultimo-edit-email', array(
wp_send_json_success(
array(
'redirect_url' => wu_network_admin_url(
'wp-ultimo-edit-email',
array(
'id' => $email_id,
'test_notice' => __('Test sent successfully', 'wp-ultimo')
))
));
'test_notice' => __('Test sent successfully', 'wp-ultimo'),
)
),
)
);
die();
}
} // end if;
wp_send_json_success(array(
'redirect_url' => wu_network_admin_url('wp-ultimo-emails', array(
wp_send_json_success(
array(
'redirect_url' => wu_network_admin_url(
'wp-ultimo-emails',
array(
'notice' => __('Test sent successfully', 'wp-ultimo'),
))
));
} // end handle_send_new_test_modal;
)
),
)
);
}
/**
* Renders the modal to reset or import system emails.
@ -325,7 +333,7 @@ class Email_List_Admin_Page extends List_Admin_Page {
'html_attr' => array(
'v-model' => 'reset_emails',
),
)
),
);
$fields['reset_note'] = array(
@ -341,11 +349,9 @@ class Email_List_Admin_Page extends List_Admin_Page {
);
foreach ($created_emails as $system_email_key => $system_email_value) {
$system_email_slug = $system_email_value->get_slug();
if (isset($default_system_emails[ $system_email_slug ])) {
$field_name = 'reset_' . $system_email_value->get_slug();
$system_email_target = $system_email_value->get_target();
@ -366,14 +372,10 @@ class Email_List_Admin_Page extends List_Admin_Page {
);
if (isset($fields['reset_note'])) {
unset($fields['reset_note']);
} // end if;
} // end if;
} // end foreach;
}
}
}
$fields['import_emails'] = array(
'type' => 'toggle',
@ -399,11 +401,9 @@ class Email_List_Admin_Page extends List_Admin_Page {
);
foreach ($default_system_emails as $default_email_key => $default_email_value) {
$maybe_is_created = wu_get_email_by('slug', $default_email_key);
if ( ! $maybe_is_created) {
$field_name = 'import_' . $default_email_key;
$field_title = '<div><strong class="wu-inline-block wu-pr-1">' . $default_email_value['title'] . '</strong> </div>';
@ -422,14 +422,10 @@ class Email_List_Admin_Page extends List_Admin_Page {
);
if (isset($fields['import_note'])) {
unset($fields['import_note']);
} // end if;
} // end if;
} // end foreach;
}
}
}
$fields['submit_button'] = array(
'type' => 'submit',
@ -439,22 +435,27 @@ class Email_List_Admin_Page extends List_Admin_Page {
'wrapper_classes' => 'wu-items-end wu-text-right',
);
$form = new \WP_Ultimo\UI\Form('reset_import', $fields, array(
$form = new \WP_Ultimo\UI\Form(
'reset_import',
$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' => 'reset_import',
'data-state' => json_encode(array(
'data-state' => json_encode(
array(
'reset_emails' => false,
'import_emails' => false
)),
'import_emails' => false,
)
),
));
),
)
);
$form->render();
} // end render_reset_import_modal;
}
/**
* Handles the modal to reset or import system emails.
@ -474,48 +475,37 @@ class Email_List_Admin_Page extends List_Admin_Page {
$created_emails = wu_get_all_system_emails();
if ($reset) {
foreach ($created_emails as $created_email) {
$slug = $created_email->get_slug();
$maybe_reset = wu_request('reset_' . $slug, '');
if ($maybe_reset) {
$created_email->delete();
wu_create_default_system_email($slug);
} // end if;
} // end foreach;
} // end if;
}
}
}
if ($import) {
foreach ($default_system_emails as $default_system_emails_key => $default_system_emails_value) {
$slug = $default_system_emails_value['slug'];
$maybe_import = wu_request('import_' . $slug, '');
if ($maybe_import) {
wu_create_default_system_email($slug);
}
}
}
} // end if;
} // end foreach;
} // end if;
wp_send_json_success(array(
'redirect_url' => wu_network_admin_url('wp-ultimo-emails')
));
} // end handle_reset_import_modal;
wp_send_json_success(
array(
'redirect_url' => wu_network_admin_url('wp-ultimo-emails'),
)
);
}
/**
* Handles the redirect notice from sent new test modal.
@ -526,9 +516,7 @@ class Email_List_Admin_Page extends List_Admin_Page {
public function handle_page_redirect($page) {
if ($page->get_id() === 'wp-ultimo-emails') {
if (wu_request('notice')) {
$notice = wu_request('notice');
?>
@ -541,11 +529,9 @@ class Email_List_Admin_Page extends List_Admin_Page {
<?php
} // end if;
} // end if;
} // end handle_page_redirect;
}
}
}
/**
* Renders the reset confirmation modal.
@ -563,7 +549,7 @@ class Email_List_Admin_Page extends List_Admin_Page {
'default' => 0,
'html_attr' => array(
'required' => 'required',
)
),
),
'email_id' => array(
'type' => 'hidden',
@ -578,18 +564,21 @@ class Email_List_Admin_Page extends List_Admin_Page {
),
);
$form = new \WP_Ultimo\UI\Form('reset_confirmation', $fields, array(
$form = new \WP_Ultimo\UI\Form(
'reset_confirmation',
$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' => 'reset_confirmation',
),
));
)
);
$form->render();
} // end render_reset_confirmation_modal;
}
/**
* Handles the reset confirmation modal.
@ -605,12 +594,10 @@ class Email_List_Admin_Page extends List_Admin_Page {
$email_id = wu_request('email_id');
if ( ! $single_reset || ! $email_id) {
$error = new \WP_Error('error', __('Something wrong happened.', 'wp-ultimo'));
return wp_send_json_error($error);
} // end if;
}
$email = wu_get_email($email_id);
@ -619,7 +606,6 @@ class Email_List_Admin_Page extends List_Admin_Page {
$default_system_emails = wu_get_default_system_emails();
if (isset($default_system_emails[ $slug ])) {
$email->delete();
wu_create_default_system_email($slug);
@ -627,22 +613,23 @@ class Email_List_Admin_Page extends List_Admin_Page {
$new_email = wu_get_email_by('slug', $slug);
if ( ! $new_email) {
$error = new \WP_Error('error', __('Something wrong happened.', 'wp-ultimo'));
return wp_send_json_error($error);
}
} // end if;
wp_send_json_success(array(
'redirect_url' => wu_network_admin_url('wp-ultimo-edit-email', array(
wp_send_json_success(
array(
'redirect_url' => wu_network_admin_url(
'wp-ultimo-edit-email',
array(
'id' => $new_email->get_id(),
))
));
} // end if;
} // end handle_reset_confirmation_modal;
)
),
)
);
}
}
/**
* Returns the action links for that page.
@ -672,8 +659,7 @@ class Email_List_Admin_Page extends List_Admin_Page {
'icon' => 'wu-cycle',
),
);
} // end action_links;
}
/**
* Loads the list table for this particular page.
@ -684,7 +670,5 @@ class Email_List_Admin_Page extends List_Admin_Page {
public function table() {
return new \WP_Ultimo\List_Tables\Email_List_Table();
} // end table;
} // end class Email_List_Admin_Page;
}
}

View File

@ -81,8 +81,7 @@ class Email_Template_Customize_Admin_Page extends Customizer_Admin_Page {
parent::init();
add_action('wp_ajax_wu-email-template-preview', array($this, 'email_template_preview'));
} // end init;
}
/**
* Return the page object
@ -94,8 +93,7 @@ class Email_Template_Customize_Admin_Page extends Customizer_Admin_Page {
public function get_object() {
return $this;
} // end get_object;
}
/**
* Renders the preview of a given form being customized.
@ -107,12 +105,12 @@ class Email_Template_Customize_Admin_Page extends Customizer_Admin_Page {
$object = $this;
$content = wpautop('
$content = wpautop(
'
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam nulla diam, iaculis sit amet tellus sit amet, tempus hendrerit risus. Proin elementum aliquet lorem ut cursus. Ut varius pharetra magna, eu malesuada metus feugiat id. Aenean cursus purus et massa commodo pretium id ut erat. Suspendisse erat odio, auctor ac elit eget, rhoncus iaculis nulla. Aliquam turpis leo, egestas eget dui a, imperdiet ullamcorper felis. Suspendisse ut lacinia mauris.
Phasellus vitae diam euismod diam tristique faucibus. Proin gravida, augue in molestie porttitor, orci justo aliquam mauris, et commodo mauris nisi vitae tortor. Mauris vulputate fringilla purus et finibus. Duis lacus turpis, tincidunt vel dui ac, fermentum aliquet dolor. Donec auctor tristique consequat. In pharetra lacus quis mi dictum, ut dapibus eros bibendum. Donec tristique nibh ac sem bibendum, at feugiat turpis molestie. Suspendisse eget eleifend nunc. Sed tempor varius nisi non tincidunt. Sed leo arcu, feugiat dapibus sollicitudin a, tincidunt eu ligula. Nam ut arcu id arcu auctor vulputate non molestie quam. Nunc non diam mauris. Praesent erat est, posuere sit amet hendrerit non, molestie eget sem. Cras ac tempor est.'
);
$content .= '<table cellpadding="0" cellspacing="0" style="width:100%; font-family:Roboto,HelveticaNeue,sans-serif; font-size: 15px">
@ -151,7 +149,9 @@ class Email_Template_Customize_Admin_Page extends Customizer_Admin_Page {
*/
$first_request = ! wu_request('background_color');
wu_get_template('broadcast/emails/base', array(
wu_get_template(
'broadcast/emails/base',
array(
'site_name' => get_network_option(null, 'site_name'),
'site_url' => get_site_url(),
'logo_url' => wu_get_network_logo(),
@ -174,12 +174,12 @@ class Email_Template_Customize_Admin_Page extends Customizer_Admin_Page {
'footer_color' => wu_request('footer_color', $object->get_setting('footer_color', '#000000')),
'footer_align' => wu_request('footer_align', $object->get_setting('footer_align', 'center')),
'display_company_address' => wu_string_to_bool(wu_request('display_company_address', $first_request ? $object->get_setting('display_company_address', true) : false)),
),
)
));
);
die;
} // end email_template_preview;
}
/**
* Returns the preview URL. This is then added to the iframe.
@ -191,12 +191,14 @@ class Email_Template_Customize_Admin_Page extends Customizer_Admin_Page {
$url = get_admin_url(wu_get_main_site_id(), 'admin-ajax.php');
return add_query_arg(array(
return add_query_arg(
array(
'action' => 'wu-email-template-preview',
'customizer' => 1,
), $url);
} // end get_preview_url;
),
$url
);
}
/**
* Allow child classes to register widgets, if they need them.
@ -206,7 +208,9 @@ class Email_Template_Customize_Admin_Page extends Customizer_Admin_Page {
*/
public function register_widgets() {
$this->add_save_widget('save', array(
$this->add_save_widget(
'save',
array(
'html_attr' => array(
'data-wu-app' => 'save',
'data-state' => wu_convert_to_state(),
@ -216,8 +220,9 @@ class Email_Template_Customize_Admin_Page extends Customizer_Admin_Page {
'type' => 'note',
'desc' => __('System emails and broadcasts will be sent using this template.', 'wp-ultimo'),
),
),
)
));
);
$settings = $this->get_attributes();
@ -473,12 +478,17 @@ class Email_Template_Customize_Admin_Page extends Customizer_Admin_Page {
),
);
$state = array_merge($settings, array(
$state = array_merge(
$settings,
array(
'tab' => 'header',
'refresh' => true,
));
)
);
$this->add_fields_widget('customizer', array(
$this->add_fields_widget(
'customizer',
array(
'title' => __('Customizer', 'wp-ultimo'),
'position' => 'side',
'fields' => $fields,
@ -488,9 +498,9 @@ class Email_Template_Customize_Admin_Page extends Customizer_Admin_Page {
'data-wu-customizer-panel' => true,
'data-state' => json_encode($state),
),
));
} // end register_widgets;
)
);
}
/**
* Returns the title of the page.
@ -501,8 +511,7 @@ class Email_Template_Customize_Admin_Page extends Customizer_Admin_Page {
public function get_title() {
return __('Customize Email Template:', 'wp-ultimo');
} // end get_title;
}
/**
* Returns the title of menu for this page.
@ -513,8 +522,7 @@ class Email_Template_Customize_Admin_Page extends Customizer_Admin_Page {
public function get_menu_title() {
return __('Customize Email Template', 'wp-ultimo');
} // end get_menu_title;
}
/**
* Returns the action links for that page.
@ -525,8 +533,7 @@ class Email_Template_Customize_Admin_Page extends Customizer_Admin_Page {
public function action_links() {
return array();
} // end action_links;
}
/**
* Returns the labels to be used on the admin page.
@ -548,8 +555,7 @@ class Email_Template_Customize_Admin_Page extends Customizer_Admin_Page {
'delete_button_label' => __('Delete Email Template', 'wp-ultimo'),
'delete_description' => __('Be careful. This action is irreversible.', 'wp-ultimo'),
);
} // end get_labels;
}
/**
* Should implement the processes necessary to save the changes made to the object.
@ -574,8 +580,7 @@ class Email_Template_Customize_Admin_Page extends Customizer_Admin_Page {
wp_redirect($url);
exit;
} // end handle_save;
}
/**
* Get the value of attributes.
@ -590,8 +595,7 @@ class Email_Template_Customize_Admin_Page extends Customizer_Admin_Page {
$attributes = wp_parse_args($saved_atts, $this->get_default_settings());
return $attributes;
} // end get_attributes;
}
/**
* Gets the default email template settings.
@ -618,8 +622,7 @@ class Email_Template_Customize_Admin_Page extends Customizer_Admin_Page {
'footer_color' => '#000000',
'footer_align' => 'center',
);
} // end get_default_settings;
}
/**
* Returns the list of saved settings to customize the email template.
@ -631,8 +634,7 @@ class Email_Template_Customize_Admin_Page extends Customizer_Admin_Page {
public static function get_settings() {
return wu_get_option('email_template', array());
} // end get_settings;
}
/**
* Returns a specitic email template setting.
@ -646,24 +648,17 @@ class Email_Template_Customize_Admin_Page extends Customizer_Admin_Page {
public function get_setting($setting, $default = false) {
if ($setting) {
$return = wu_get_option('email_template', array());
if ($return && isset($return[ $setting ])) {
$return = $return[ $setting ];
} else {
$return = $default;
} // end if;
}
return $return;
} // end if;
} // end get_setting;
}
}
/**
* Save settings.
@ -678,17 +673,11 @@ class Email_Template_Customize_Admin_Page extends Customizer_Admin_Page {
$allowed_keys = $this->get_attributes();
foreach ($settings_to_save as $setting_to_save => $value) {
if ( ! array_key_exists($setting_to_save, $allowed_keys)) {
unset($settings_to_save[ $setting_to_save ]);
} // end if;
} // end foreach;
}
}
return wu_save_option('email_template', $settings_to_save);
} // end save_settings;
} // end class Email_Template_Customize_Admin_Page;
}
}

View File

@ -9,7 +9,7 @@
namespace WP_Ultimo\Admin_Pages;
use \WP_Ultimo\Models\Event;
use WP_Ultimo\Models\Event;
// Exit if accessed directly
defined('ABSPATH') || exit;
@ -65,8 +65,7 @@ class Event_List_Admin_Page extends List_Admin_Page {
public function init() {
add_action('init', array($this, 'set_badge_count'));
} // end init;
}
/**
* Adds hooks when the page loads.
@ -79,8 +78,7 @@ class Event_List_Admin_Page extends List_Admin_Page {
parent::page_loaded();
add_action('in_admin_header', array($this, 'count_seen_events'));
} // end page_loaded;
}
/**
* Sets events badge notification subtracting the total number of events from the seen events in the user meta.
@ -97,12 +95,10 @@ class Event_List_Admin_Page extends List_Admin_Page {
$cache = get_site_transient("wu_{$user_id}_unseen_events_count");
if ($cache) {
$this->badge_count = $cache;
return;
} // end if;
}
$table_name = "{$wpdb->base_prefix}wu_events";
@ -115,8 +111,7 @@ class Event_List_Admin_Page extends List_Admin_Page {
$this->badge_count = $unseen;
set_site_transient("wu_{$user_id}_unseen_events_count", $unseen, 5 * MINUTE_IN_SECONDS);
} // end set_badge_count;
}
/**
* Sets the seen events in the current user meta.
@ -130,24 +125,23 @@ class Event_List_Admin_Page extends List_Admin_Page {
delete_site_transient("wu_{$user_id}_unseen_events_count");
$last_event = wu_get_events(array(
$last_event = wu_get_events(
array(
'orderby' => 'id',
'fields' => 'ids',
'order' => 'DESC',
'number' => 1,
));
)
);
if ( ! empty($last_event)) {
$last_event_id = current($last_event);
update_user_meta($user_id, 'wu_seen_events', $last_event_id);
} // end if;
}
$this->badge_count = '';
} // end count_seen_events;
}
/**
* Allow child classes to register widgets, if they need them.
@ -155,7 +149,7 @@ class Event_List_Admin_Page extends List_Admin_Page {
* @since 1.8.2
* @return void
*/
public function register_widgets() {} // end register_widgets;
public function register_widgets() {}
/**
* Returns an array with the labels for the edit page.
@ -169,8 +163,7 @@ class Event_List_Admin_Page extends List_Admin_Page {
'deleted_message' => __('Event removed successfully.', 'wp-ultimo'),
'search_label' => __('Search Event', 'wp-ultimo'),
);
} // end get_labels;
}
/**
* Returns the title of the page.
@ -181,8 +174,7 @@ class Event_List_Admin_Page extends List_Admin_Page {
public function get_title() {
return __('Events', 'wp-ultimo');
} // end get_title;
}
/**
* Returns the title of menu for this page.
@ -193,8 +185,7 @@ class Event_List_Admin_Page extends List_Admin_Page {
public function get_menu_title() {
return __('Events', 'wp-ultimo');
} // end get_menu_title;
}
/**
* Allows admins to rename the sub-menu (first item) for a top-level page.
@ -205,8 +196,7 @@ class Event_List_Admin_Page extends List_Admin_Page {
public function get_submenu_title() {
return __('Events', 'wp-ultimo');
} // end get_submenu_title;
}
/**
* Returns the action links for that page.
@ -223,8 +213,7 @@ class Event_List_Admin_Page extends List_Admin_Page {
'icon' => 'dashicons dashicons-editor-ol',
),
);
} // end action_links;
}
/**
* Loads the list table for this particular page.
@ -235,7 +224,5 @@ class Event_List_Admin_Page extends List_Admin_Page {
public function table() {
return new \WP_Ultimo\List_Tables\Event_List_Table();
} // end table;
} // end class Event_List_Admin_Page;
}
}

View File

@ -12,7 +12,7 @@ namespace WP_Ultimo\Admin_Pages;
// Exit if accessed directly
defined('ABSPATH') || exit;
use \WP_Ultimo\Models\Event;
use WP_Ultimo\Models\Event;
/**
* WP Multisite WaaS Event View Admin Page.
@ -97,8 +97,7 @@ class Event_View_Admin_Page extends Edit_Admin_Page {
wp_enqueue_script('clipboard');
wp_enqueue_script('wu-vue');
} // end register_scripts;
}
/**
* Register ajax forms that we use for membership.
@ -111,11 +110,13 @@ class Event_View_Admin_Page extends Edit_Admin_Page {
* Delete Event - Confirmation modal
*/
add_filter('wu_data_json_success_delete_event_modal', fn($data_json) => array(
'redirect_url' => wu_network_admin_url('wp-ultimo-events', array('deleted' => 1))
));
} // end register_forms;
add_filter(
'wu_data_json_success_delete_event_modal',
fn($data_json) => array(
'redirect_url' => wu_network_admin_url('wp-ultimo-events', array('deleted' => 1)),
)
);
}
/**
* Allow child classes to register widgets, if they need them.
@ -133,13 +134,15 @@ class Event_View_Admin_Page extends Edit_Admin_Page {
add_meta_box('wp-ultimo-payload', __('Event Payload', 'wp-ultimo'), array($this, 'output_default_widget_payload'), get_current_screen()->id, 'normal', 'default');
$this->add_info_widget('info', array(
$this->add_info_widget(
'info',
array(
'title' => __('Timestamps', 'wp-ultimo'),
'position' => 'side',
'modified' => false,
));
} // end register_widgets;
)
);
}
/**
* Outputs the markup for the default Save widget.
@ -149,14 +152,16 @@ class Event_View_Admin_Page extends Edit_Admin_Page {
*/
public function output_default_widget_message() {
wu_get_template('events/widget-message', array(
wu_get_template(
'events/widget-message',
array(
'screen' => get_current_screen(),
'page' => $this,
'labels' => $this->get_labels(),
'object' => $this->get_object(),
));
} // end output_default_widget_message;
)
);
}
/**
* Outputs the markup for the payload widget.
@ -168,13 +173,15 @@ class Event_View_Admin_Page extends Edit_Admin_Page {
$object = $this->get_object();
wu_get_template('events/widget-payload', array(
wu_get_template(
'events/widget-payload',
array(
'title' => __('Event Payload', 'wp-ultimo'),
'loading_text' => __('Loading Payload', 'wp-ultimo'),
'payload' => json_encode($object->get_payload(), JSON_PRETTY_PRINT),
));
} // end output_default_widget_payload;
)
);
}
/**
* Outputs the markup for the initiator widget.
@ -191,8 +198,7 @@ class Event_View_Admin_Page extends Edit_Admin_Page {
);
wu_get_template('events/widget-initiator', $args);
} // end output_default_widget_initiator;
}
/**
* Returns the title of the page.
@ -203,8 +209,7 @@ class Event_View_Admin_Page extends Edit_Admin_Page {
public function get_title() {
return $this->edit ? __('Edit Event', 'wp-ultimo') : __('Add new Event', 'wp-ultimo');
} // end get_title;
}
/**
* Returns the title of menu for this page.
@ -215,8 +220,7 @@ class Event_View_Admin_Page extends Edit_Admin_Page {
public function get_menu_title() {
return __('Edit Event', 'wp-ultimo');
} // end get_menu_title;
}
/**
* Returns the action links for that page.
@ -227,8 +231,7 @@ class Event_View_Admin_Page extends Edit_Admin_Page {
public function action_links() {
return array();
} // end action_links;
}
/**
* Returns the labels to be used on the admin page.
@ -249,8 +252,7 @@ class Event_View_Admin_Page extends Edit_Admin_Page {
'delete_button_label' => __('Delete Event', 'wp-ultimo'),
'delete_description' => __('Be careful. This action is irreversible.', 'wp-ultimo'),
);
} // end get_labels;
}
/**
* Returns the object being edit at the moment.
@ -261,24 +263,19 @@ class Event_View_Admin_Page extends Edit_Admin_Page {
public function get_object() {
if (isset($_GET['id'])) {
$query = new \WP_Ultimo\Database\Events\Event_Query;
$query = new \WP_Ultimo\Database\Events\Event_Query();
$item = $query->get_item_by('id', $_GET['id']);
if ($item) {
return $item;
} // end if;
} // end if;
}
}
wp_redirect(wu_network_admin_url('wp-ultimo-events'));
exit;
} // end get_object;
}
/**
* Events have titles.
*
@ -287,8 +284,7 @@ class Event_View_Admin_Page extends Edit_Admin_Page {
public function has_title(): bool {
return false;
} // end has_title;
}
/**
* Handles the save of this form.
*
@ -297,7 +293,5 @@ class Event_View_Admin_Page extends Edit_Admin_Page {
public function handle_save(): bool {
return true;
} // end handle_save;
} // end class Event_View_Admin_Page;
}
}

View File

@ -87,24 +87,19 @@ class Hosting_Integration_Wizard_Admin_Page extends Wizard_Admin_Page {
public function page_loaded() {
if (isset($_GET['integration'])) {
$domain_manager = \WP_Ultimo\Managers\Domain_Manager::get_instance();
$this->integration = $domain_manager->get_integration_instance($_GET['integration']);
} // end if;
}
if ( ! $this->integration) {
wp_redirect(network_admin_url('admin.php?page=wp-ultimo-settings'));
exit;
} // end if;
}
parent::page_loaded();
} // end page_loaded;
}
/**
* Returns the title of the page.
@ -115,8 +110,7 @@ class Hosting_Integration_Wizard_Admin_Page extends Wizard_Admin_Page {
public function get_title(): string {
return sprintf(__('Integration Setup', 'wp-ultimo'));
} // end get_title;
}
/**
* Returns the title of menu for this page.
@ -127,8 +121,7 @@ class Hosting_Integration_Wizard_Admin_Page extends Wizard_Admin_Page {
public function get_menu_title() {
return __('Host Provider Integration', 'wp-ultimo');
} // end get_menu_title;
}
/**
* Returns the sections for this Wizard.
@ -167,23 +160,18 @@ class Hosting_Integration_Wizard_Admin_Page extends Wizard_Admin_Page {
* Some host providers require no instructions.
*/
if ($this->integration->supports('no-instructions')) {
unset($sections['instructions']);
} // end if;
}
/*
* Some host providers require no additional setup.
*/
if ($this->integration->supports('no-config')) {
unset($sections['config']);
} // end if;
}
return $sections;
} // end get_sections;
}
/**
* Displays the content of the activation section.
@ -195,15 +183,17 @@ class Hosting_Integration_Wizard_Admin_Page extends Wizard_Admin_Page {
$explainer_lines = $this->integration->get_explainer_lines();
wu_get_template('wizards/host-integrations/activation', array(
wu_get_template(
'wizards/host-integrations/activation',
array(
'screen' => get_current_screen(),
'page' => $this,
'integration' => $this->integration,
'will' => $explainer_lines['will'],
'will_not' => $explainer_lines['will_not'],
));
} // end section_activation;
)
);
}
/**
* Displays the contents of the instructions section.
@ -216,8 +206,7 @@ class Hosting_Integration_Wizard_Admin_Page extends Wizard_Admin_Page {
call_user_func(array($this->integration, 'get_instructions'));
$this->render_submit_box();
} // end section_instructions;
}
/**
* Displays the content of the configuration section.
@ -230,39 +219,44 @@ class Hosting_Integration_Wizard_Admin_Page extends Wizard_Admin_Page {
$fields = $this->integration->get_fields();
foreach ($fields as $field_constant => &$field) {
$field['value'] = defined($field_constant) && constant($field_constant) ? constant($field_constant) : '';
}
} // end foreach;
$form = new \WP_Ultimo\UI\Form($this->get_current_section(), $fields, array(
$form = new \WP_Ultimo\UI\Form(
$this->get_current_section(),
$fields,
array(
'views' => 'admin-pages/fields',
'classes' => 'wu-widget-list wu-striped wu-m-0 wu--mt-2 wu--mb-3 wu--mx-3',
'field_wrapper_classes' => 'wu-w-full wu-box-border wu-items-center wu-flex wu-justify-between wu-px-6 wu-py-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',
));
)
);
if (wu_request('manual')) {
wu_get_template('wizards/host-integrations/configuration-results', array(
wu_get_template(
'wizards/host-integrations/configuration-results',
array(
'screen' => get_current_screen(),
'page' => $this,
'integration' => $this->integration,
'form' => $form,
'post' => $_GET['post'],
));
)
);
return;
}
} // end if;
wu_get_template('wizards/host-integrations/configuration', array(
wu_get_template(
'wizards/host-integrations/configuration',
array(
'screen' => get_current_screen(),
'page' => $this,
'integration' => $this->integration,
'form' => $form,
));
} // end section_configuration;
)
);
}
/**
* Displays the content of the final section.
@ -272,13 +266,15 @@ class Hosting_Integration_Wizard_Admin_Page extends Wizard_Admin_Page {
*/
public function section_ready() {
wu_get_template('wizards/host-integrations/ready', array(
wu_get_template(
'wizards/host-integrations/ready',
array(
'screen' => get_current_screen(),
'page' => $this,
'integration' => $this->integration,
));
} // end section_ready;
)
);
}
/**
* Handles the activation of a given integration.
@ -291,20 +287,17 @@ class Hosting_Integration_Wizard_Admin_Page extends Wizard_Admin_Page {
$is_enabled = $this->integration->is_enabled();
if ($is_enabled) {
$this->integration->disable();
return;
} // end if;
}
$this->integration->enable();
wp_redirect($this->get_next_section_link());
exit;
} // end handle_activation;
}
/**
* Handles the configuration of a given integration.
@ -316,22 +309,22 @@ class Hosting_Integration_Wizard_Admin_Page extends Wizard_Admin_Page {
if (wu_request('submit') == '0') { // phpcs:ignore
$redirect_url = add_query_arg(array(
$redirect_url = add_query_arg(
array(
'manual' => '1',
'post' => $_POST,
));
)
);
wp_redirect($redirect_url);
exit;
} // end if;
}
if (wu_request('submit') == '1') { // phpcs:ignore
$this->integration->setup_constants($_POST);
} // end if;
}
$redirect_url = $this->get_next_section_link();
@ -342,8 +335,7 @@ class Hosting_Integration_Wizard_Admin_Page extends Wizard_Admin_Page {
wp_redirect($redirect_url);
exit;
} // end handle_configuration;
}
/**
* Handles the testing of a given configuration.
@ -356,12 +348,13 @@ class Hosting_Integration_Wizard_Admin_Page extends Wizard_Admin_Page {
wp_enqueue_script('wu-vue');
wu_get_template('wizards/host-integrations/test', array(
wu_get_template(
'wizards/host-integrations/test',
array(
'screen' => get_current_screen(),
'page' => $this,
'integration' => $this->integration,
));
} // end section_test;
} // end class Hosting_Integration_Wizard_Admin_Page;
)
);
}
}

View File

@ -9,7 +9,7 @@
namespace WP_Ultimo\Admin_Pages;
use \WP_Ultimo\Invoices\Invoice;
use WP_Ultimo\Invoices\Invoice;
// Exit if accessed directly
defined('ABSPATH') || exit;
@ -83,8 +83,7 @@ class Invoice_Template_Customize_Admin_Page extends Customizer_Admin_Page {
parent::init();
add_action('wp_ajax_wu-preview-invoice', array($this, 'generate_invoice_preview'));
} // end init;
}
/**
* Ajax endpoint to generate the Ajax Preview.
@ -95,10 +94,8 @@ class Invoice_Template_Customize_Admin_Page extends Customizer_Admin_Page {
public function generate_invoice_preview() {
if ( ! current_user_can('wu_manage_invoice')) {
return;
} // end if;
}
$order = false;
@ -109,8 +106,7 @@ class Invoice_Template_Customize_Admin_Page extends Customizer_Admin_Page {
$invoice->print_file();
die;
} // end generate_invoice_preview;
}
/**
* Returns the preview URL. This is then added to the iframe.
@ -122,13 +118,15 @@ class Invoice_Template_Customize_Admin_Page extends Customizer_Admin_Page {
$url = get_admin_url(wu_get_main_site_id(), 'admin-ajax.php');
return add_query_arg(array(
return add_query_arg(
array(
'action' => 'wu-preview-invoice',
'customizer' => 1,
'invoice-customize' => 1
), $url);
} // end get_preview_url;
'invoice-customize' => 1,
),
$url
);
}
/**
* Allow child classes to register widgets, if they need them.
@ -140,14 +138,17 @@ class Invoice_Template_Customize_Admin_Page extends Customizer_Admin_Page {
$settings = Invoice::get_settings();
$this->add_save_widget('save', array(
$this->add_save_widget(
'save',
array(
'fields' => array(
'note' => array(
'type' => 'note',
'desc' => __('Changes to this template will be applied to all PDF invoices generated after the change. <br><br>Existing PDF Invoices will not be affected unless explicitly re-generated', 'wp-ultimo'),
),
),
)
));
);
$custom_logo = wu_get_isset($settings, 'custom_logo');
@ -267,12 +268,17 @@ class Invoice_Template_Customize_Admin_Page extends Customizer_Admin_Page {
'font' => wu_get_isset($settings, 'font', 'DejaVuSansCondensed'),
);
$state = array_merge($settings, array(
$state = array_merge(
$settings,
array(
'tab' => 'general',
'refresh' => true,
));
)
);
$this->add_fields_widget('customizer', array(
$this->add_fields_widget(
'customizer',
array(
'title' => __('Customizer', 'wp-ultimo'),
'position' => 'side',
'fields' => $fields,
@ -282,9 +288,9 @@ class Invoice_Template_Customize_Admin_Page extends Customizer_Admin_Page {
'data-wu-customizer-panel' => true,
'data-state' => json_encode($state),
),
));
} // end register_widgets;
)
);
}
/**
* Returns the title of the page.
@ -295,8 +301,7 @@ class Invoice_Template_Customize_Admin_Page extends Customizer_Admin_Page {
public function get_title() {
return __('Customize Invoice Template', 'wp-ultimo');
} // end get_title;
}
/**
* Returns the title of menu for this page.
@ -307,8 +312,7 @@ class Invoice_Template_Customize_Admin_Page extends Customizer_Admin_Page {
public function get_menu_title() {
return __('Customize Invoice Template', 'wp-ultimo');
} // end get_menu_title;
}
/**
* Returns the action links for that page.
@ -319,8 +323,7 @@ class Invoice_Template_Customize_Admin_Page extends Customizer_Admin_Page {
public function action_links() {
return array();
} // end action_links;
}
/**
* Returns the labels to be used on the admin page.
@ -340,8 +343,7 @@ class Invoice_Template_Customize_Admin_Page extends Customizer_Admin_Page {
'save_button_label' => __('Save Invoice Template', 'wp-ultimo'),
'save_description' => __('Save Invoice Template', 'wp-ultimo'),
);
} // end get_labels;
}
/**
* Should implement the processes necessary to save the changes made to the object.
@ -358,7 +360,5 @@ class Invoice_Template_Customize_Admin_Page extends Customizer_Admin_Page {
wp_redirect($url);
exit;
} // end handle_save;
} // end class Invoice_Template_Customize_Admin_Page;
}
}

View File

@ -81,8 +81,7 @@ class Jobs_List_Admin_Page extends Base_Admin_Page {
parent::init();
add_filter('action_scheduler_admin_view_class', array($this, 'hide_as_admin_page'), 9999, 1);
} // end init;
}
/**
* Hide the Action Scheduler admin page on sub-sites.
@ -95,14 +94,11 @@ class Jobs_List_Admin_Page extends Base_Admin_Page {
public function hide_as_admin_page($admin_view_class) {
if (is_network_admin() || class_exists('WooCommerce')) {
return $admin_view_class;
} // end if;
}
return '\WP_Ultimo\Compat\AS_Admin_View';
} // end hide_as_admin_page;
}
/**
* Returns the title of the page.
@ -113,8 +109,7 @@ class Jobs_List_Admin_Page extends Base_Admin_Page {
public function get_title() {
return __('Jobs', 'wp-ultimo');
} // end get_title;
}
/**
* Returns the title of menu for this page.
@ -125,8 +120,7 @@ class Jobs_List_Admin_Page extends Base_Admin_Page {
public function get_menu_title() {
return __('Jobs', 'wp-ultimo');
} // end get_menu_title;
}
/**
* Allows admins to rename the sub-menu (first item) for a top-level page.
@ -137,8 +131,7 @@ class Jobs_List_Admin_Page extends Base_Admin_Page {
public function get_submenu_title() {
return __('Jobs', 'wp-ultimo');
} // end get_submenu_title;
}
/**
* Runs the hooks for the admin list table.
@ -151,8 +144,7 @@ class Jobs_List_Admin_Page extends Base_Admin_Page {
public function page_loaded() {
\ActionScheduler_AdminView::instance()->process_admin_ui();
} // end page_loaded;
}
/**
* Calls the Action Scheduler renderer.
@ -163,7 +155,5 @@ class Jobs_List_Admin_Page extends Base_Admin_Page {
public function output() {
\ActionScheduler_AdminView::instance()->render_admin_ui();
} // end output;
} // end class Jobs_List_Admin_Page;
}
}

View File

@ -82,8 +82,7 @@ abstract class List_Admin_Page extends Base_Admin_Page {
* Adds the process for process actions
*/
$this->process_single_action();
} // end page_loaded;
}
/**
* Initializes the class
@ -99,8 +98,7 @@ abstract class List_Admin_Page extends Base_Admin_Page {
parent::init();
add_filter('set-screen-option', array($this, 'save_screen_option'), 8, 3);
} // end init;
}
/**
* Process lins actions of the tables
@ -111,12 +109,9 @@ abstract class List_Admin_Page extends Base_Admin_Page {
public function process_single_action() {
if ($this->table) {
$this->table->process_single_action();
} // end if;
} // end process_single_action;
}
}
/**
* Returns an array with the labels for the edit page.
@ -130,8 +125,7 @@ abstract class List_Admin_Page extends Base_Admin_Page {
'deleted_message' => __('Object removed successfully.', 'wp-ultimo'),
'search_label' => __('Search Object', 'wp-ultimo'),
);
} // end get_labels;
}
/**
* Allow child classes to register scripts and styles that can be loaded on the output function, for example.
@ -150,8 +144,7 @@ abstract class List_Admin_Page extends Base_Admin_Page {
wp_enqueue_style('wp-color-picker');
wp_enqueue_script('wu-selectizer');
} // end register_scripts;
}
/**
* Sets the default list template
@ -164,13 +157,15 @@ abstract class List_Admin_Page extends Base_Admin_Page {
/**
* Renders the base list page layout, with the columns and everything else =)
*/
wu_get_template('base/list', array(
wu_get_template(
'base/list',
array(
'page' => $this,
'table' => $this->get_table(),
'classes' => $this->table->get_filters() ? 'wu-advanced-filters' : 'wu-no-advanced-filters',
));
} // end output;
)
);
}
/**
* Child classes can to implement to hide the search field
@ -181,8 +176,7 @@ abstract class List_Admin_Page extends Base_Admin_Page {
public function has_search() {
return true;
} // end has_search;
}
/**
* Set the screen options to allow users to set the pagination options of the subscriptions list
@ -193,7 +187,6 @@ abstract class List_Admin_Page extends Base_Admin_Page {
public function screen_options() {
if ($this->table) {
$args = array(
'default' => 20,
'label' => $this->table->get_per_page_option_label(),
@ -201,10 +194,8 @@ abstract class List_Admin_Page extends Base_Admin_Page {
);
add_screen_option('per_page', $args);
} // end if;
} // end screen_options;
}
}
/**
* Tells WordPress we want to save screen options on our pages.
@ -219,8 +210,7 @@ abstract class List_Admin_Page extends Base_Admin_Page {
public function save_screen_option($value, $option, $other_value) {
return $value === false && is_numeric($other_value) ? (int) $other_value : $value;
} // end save_screen_option;
}
/**
* Dumb function. Child classes need to implement this to set the table that WP Multisite WaaS will use
@ -231,8 +221,7 @@ abstract class List_Admin_Page extends Base_Admin_Page {
public function get_table() {
return $this->table;
} // end get_table;
}
/**
* Loads the list table for this particular page.
@ -241,5 +230,4 @@ abstract class List_Admin_Page extends Base_Admin_Page {
* @return \WP_Ultimo\List_Tables\Base_List_Table
*/
abstract function table();
} // end class List_Admin_Page;
}

File diff suppressed because it is too large Load Diff

View File

@ -12,8 +12,8 @@ namespace WP_Ultimo\Admin_Pages;
// Exit if accessed directly
defined('ABSPATH') || exit;
use \WP_Ultimo\Models\Membership;
use \WP_Ultimo\Database\Memberships\Membership_Status;
use WP_Ultimo\Models\Membership;
use WP_Ultimo\Database\Memberships\Membership_Status;
/**
* WP Multisite WaaS Membership Admin Page.
@ -67,13 +67,15 @@ class Membership_List_Admin_Page extends List_Admin_Page {
/*
* Add new Membership
*/
wu_register_form('add_new_membership', array(
wu_register_form(
'add_new_membership',
array(
'render' => array($this, 'render_add_new_membership_modal'),
'handler' => array($this, 'handle_add_new_membership_modal'),
'capability' => 'wu_edit_memberships',
));
} // end register_forms;
)
);
}
/**
* Renders the add new customer modal.
@ -155,22 +157,27 @@ class Membership_List_Admin_Page extends List_Admin_Page {
),
);
$form = new \WP_Ultimo\UI\Form('add_new_membership', $fields, array(
$form = new \WP_Ultimo\UI\Form(
'add_new_membership',
$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_membership',
'data-on-load' => 'wu_initialize_datepickers',
'data-state' => wu_convert_to_state(array(
'lifetime' => 1
)),
'data-state' => wu_convert_to_state(
array(
'lifetime' => 1,
)
),
));
),
)
);
$form->render();
} // end render_add_new_membership_modal;
}
/**
* Handles creation of a new memberships.
@ -187,29 +194,31 @@ class Membership_List_Admin_Page extends List_Admin_Page {
$products = explode(',', (string) $products);
if (empty($products)) {
wp_send_json_error(new \WP_Error(
wp_send_json_error(
new \WP_Error(
'empty-products',
__('Products can not be empty.', 'wp-ultimo')
));
} // end if;
)
);
}
$customer = wu_get_customer(wu_request('customer_id', 0));
if (empty($customer)) {
wp_send_json_error(new \WP_Error(
wp_send_json_error(
new \WP_Error(
'customer-not-found',
__('The selected customer does not exist.', 'wp-ultimo')
));
)
);
}
} // end if;
$cart = new \WP_Ultimo\Checkout\Cart(array(
$cart = new \WP_Ultimo\Checkout\Cart(
array(
'products' => $products,
'country' => $customer->get_country(),
));
)
);
$data = $cart->to_membership_data();
@ -222,28 +231,28 @@ class Membership_List_Admin_Page extends List_Admin_Page {
$maybe_lifetime = wu_request('lifetime');
if ($maybe_lifetime) {
$date_expiration = null;
} // end if;
}
$data['date_expiration'] = $date_expiration;
$membership = wu_create_membership($data);
if (is_wp_error($membership)) {
wp_send_json_error($membership);
}
} // end if;
wp_send_json_success(array(
'redirect_url' => wu_network_admin_url('wp-ultimo-edit-membership', array(
wp_send_json_success(
array(
'redirect_url' => wu_network_admin_url(
'wp-ultimo-edit-membership',
array(
'id' => $membership->get_id(),
))
));
} // end handle_add_new_membership_modal;
)
),
)
);
}
/**
* Returns an array with the labels for the edit page.
@ -257,8 +266,7 @@ class Membership_List_Admin_Page extends List_Admin_Page {
'deleted_message' => __('Membership removed successfully.', 'wp-ultimo'),
'search_label' => __('Search Membership', 'wp-ultimo'),
);
} // end get_labels;
}
/**
* Returns the title of the page.
@ -269,8 +277,7 @@ class Membership_List_Admin_Page extends List_Admin_Page {
public function get_title() {
return __('Memberships', 'wp-ultimo');
} // end get_title;
}
/**
* Returns the title of menu for this page.
@ -281,8 +288,7 @@ class Membership_List_Admin_Page extends List_Admin_Page {
public function get_menu_title() {
return __('Memberships', 'wp-ultimo');
} // end get_menu_title;
}
/**
* Allows admins to rename the sub-menu (first item) for a top-level page.
@ -293,8 +299,7 @@ class Membership_List_Admin_Page extends List_Admin_Page {
public function get_submenu_title() {
return __('Memberships', 'wp-ultimo');
} // end get_submenu_title;
}
/**
* Returns the action links for that page.
@ -312,8 +317,7 @@ class Membership_List_Admin_Page extends List_Admin_Page {
'url' => wu_get_form_url('add_new_membership'),
),
);
} // end action_links;
}
/**
* Loads the list table for this particular page.
@ -324,7 +328,5 @@ class Membership_List_Admin_Page extends List_Admin_Page {
public function table() {
return new \WP_Ultimo\List_Tables\Membership_List_Table();
} // end table;
} // end class Membership_List_Admin_Page;
}
}

View File

@ -83,8 +83,7 @@ class Migration_Alert_Admin_Page extends Wizard_Admin_Page {
public function __construct() {
parent::__construct();
} // end __construct;
}
/**
* Returns the logo for the wizard.
@ -95,8 +94,7 @@ class Migration_Alert_Admin_Page extends Wizard_Admin_Page {
public function get_logo() {
return wu_get_asset('logo.png', 'img');
} // end get_logo;
}
/**
* Returns the title of the page.
@ -107,8 +105,7 @@ class Migration_Alert_Admin_Page extends Wizard_Admin_Page {
public function get_title(): string {
return sprintf(__('Migration', 'wp-ultimo'));
} // end get_title;
}
/**
* Returns the title of menu for this page.
@ -119,8 +116,7 @@ class Migration_Alert_Admin_Page extends Wizard_Admin_Page {
public function get_menu_title() {
return WP_Ultimo()->is_loaded() ? __('WP Multisite WaaS Migration Alert', 'wp-ultimo') : __('WP Multisite WaaS', 'wp-ultimo');
} // end get_menu_title;
}
/**
* Returns the sections for this Wizard.
@ -137,8 +133,7 @@ class Migration_Alert_Admin_Page extends Wizard_Admin_Page {
'handler' => array($this, 'handle_proceed'),
),
);
} // end get_sections;
}
/**
* Displays the content of the final section.
@ -148,12 +143,14 @@ class Migration_Alert_Admin_Page extends Wizard_Admin_Page {
*/
public function section_alert() {
wu_get_template('wizards/setup/alert', array(
wu_get_template(
'wizards/setup/alert',
array(
'screen' => get_current_screen(),
'page' => $this,
));
} // end section_alert;
)
);
}
/**
* Handles the proceed action.
@ -169,7 +166,5 @@ class Migration_Alert_Admin_Page extends Wizard_Admin_Page {
wp_redirect(wu_network_admin_url('wp-ultimo-setup'));
exit;
} // end handle_proceed;
} // end class Migration_Alert_Admin_Page;
}
}

View File

@ -12,8 +12,8 @@ namespace WP_Ultimo\Admin_Pages;
// Exit if accessed directly
defined('ABSPATH') || exit;
use \WP_Ultimo\Models\Payment;
use \WP_Ultimo\Database\Payments\Payment_Status;
use WP_Ultimo\Models\Payment;
use WP_Ultimo\Database\Payments\Payment_Status;
/**
* WP Multisite WaaS Payment Edit/Add New Admin Page.
@ -92,8 +92,7 @@ class Payment_Edit_Admin_Page extends Edit_Admin_Page {
parent::register_scripts();
wp_enqueue_editor();
} // end register_scripts;
}
/**
* Register ajax forms that we use for payments.
@ -105,38 +104,49 @@ class Payment_Edit_Admin_Page extends Edit_Admin_Page {
/*
* Edit/Add Line Item
*/
wu_register_form('edit_line_item', array(
wu_register_form(
'edit_line_item',
array(
'render' => array($this, 'render_edit_line_item_modal'),
'handler' => array($this, 'handle_edit_line_item_modal'),
'capability' => 'wu_edit_payments',
));
)
);
/*
* Delete Line Item - Confirmation modal
*/
wu_register_form('delete_line_item', array(
wu_register_form(
'delete_line_item',
array(
'render' => array($this, 'render_delete_line_item_modal'),
'handler' => array($this, 'handle_delete_line_item_modal'),
'capability' => 'wu_delete_payments',
));
)
);
/*
* Refund Line Item
*/
wu_register_form('refund_payment', array(
wu_register_form(
'refund_payment',
array(
'render' => array($this, 'render_refund_payment_modal'),
'handler' => array($this, 'handle_refund_payment_modal'),
'capability' => 'wu_refund_payments',
));
)
);
/*
* Delete - Confirmation modal
*/
add_filter('wu_data_json_success_delete_payment_modal', fn($data_json) => array(
'redirect_url' => wu_network_admin_url('wp-ultimo-payments', array('deleted' => 1))
));
} // end register_forms;
add_filter(
'wu_data_json_success_delete_payment_modal',
fn($data_json) => array(
'redirect_url' => wu_network_admin_url('wp-ultimo-payments', array('deleted' => 1)),
)
);
}
/**
* Renders the deletion confirmation form.
@ -151,10 +161,8 @@ class Payment_Edit_Admin_Page extends Edit_Admin_Page {
$line_item = wu_get_line_item(wu_request('line_item_id'), $payment->get_id());
if ( ! $line_item || ! $payment) {
return;
} // end if;
}
$fields = array(
'confirm' => array(
@ -185,21 +193,26 @@ class Payment_Edit_Admin_Page extends Edit_Admin_Page {
),
);
$form = new \WP_Ultimo\UI\Form('total-actions', $fields, array(
$form = new \WP_Ultimo\UI\Form(
'total-actions',
$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' => 'true',
'data-state' => wu_convert_to_state(array(
'data-state' => wu_convert_to_state(
array(
'confirmed' => false,
)),
)
),
));
),
)
);
$form->render();
} // end render_delete_line_item_modal;
}
/**
* Handles the deletion of line items.
@ -214,10 +227,8 @@ class Payment_Edit_Admin_Page extends Edit_Admin_Page {
$line_item = wu_get_line_item(wu_request('line_item_id'), $payment->get_id());
if ( ! $payment || ! $line_item) {
wp_send_json_error(new \WP_Error('not-found', __('Payment not found.', 'wp-ultimo')));
} // end if;
}
$line_items = $payment->get_line_items();
@ -228,16 +239,15 @@ class Payment_Edit_Admin_Page extends Edit_Admin_Page {
$saved = $payment->recalculate_totals()->save();
if (is_wp_error($saved)) {
wp_send_json_error($saved);
}
} // end if;
wp_send_json_success(array(
wp_send_json_success(
array(
'redirect_url' => add_query_arg('updated', 1, $_SERVER['HTTP_REFERER']),
));
} // end handle_delete_line_item_modal;
)
);
}
/**
* Renders the refund line item modal.
@ -250,10 +260,8 @@ class Payment_Edit_Admin_Page extends Edit_Admin_Page {
$payment = wu_get_payment(wu_request('id'));
if ( ! $payment) {
return;
} // end if;
}
$fields = array(
'_amount' => array(
@ -265,7 +273,7 @@ class Payment_Edit_Admin_Page extends Edit_Admin_Page {
'html_attr' => array(
'v-model' => 'amount',
'step' => '0.01',
'v-bind:max' => 'total'
'v-bind:max' => 'total',
),
'wrapper_html_attr' => array(
'v-show' => 'step === 1',
@ -317,7 +325,7 @@ class Payment_Edit_Admin_Page extends Edit_Admin_Page {
),
'html_attr' => array(
'v-bind:disabled' => 'amount <= 0 || amount > total',
'v-on:click.prevent' => 'step = 2'
'v-on:click.prevent' => 'step = 2',
),
),
'submit_button_2' => array(
@ -340,24 +348,29 @@ class Payment_Edit_Admin_Page extends Edit_Admin_Page {
),
);
$form = new \WP_Ultimo\UI\Form('total-actions', $fields, array(
$form = new \WP_Ultimo\UI\Form(
'total-actions',
$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' => 'refund',
'data-state' => wu_convert_to_state(array(
'data-state' => wu_convert_to_state(
array(
'step' => 1,
'confirmed' => false,
'total' => round($payment->get_total(), 2),
'amount' => round($payment->get_total(), 2),
)),
)
),
));
),
)
);
$form->render();
} // end render_refund_payment_modal;
}
/**
* Handles the deletion of line items.
@ -372,19 +385,15 @@ class Payment_Edit_Admin_Page extends Edit_Admin_Page {
$payment = wu_get_payment(wu_request('id'));
if ( ! $payment) {
wp_send_json_error(new \WP_Error('not-found', __('Payment not found.', 'wp-ultimo')));
} // end if;
}
/*
* Checks for a valid amount.
*/
if (empty($amount) || $amount > $payment->get_total()) {
wp_send_json_error(new \WP_Error('invalid-amount', __('The refund amount is out of bounds.', 'wp-ultimo')));
} // end if;
}
/*
* Check if the payment is in a
@ -393,10 +402,8 @@ class Payment_Edit_Admin_Page extends Edit_Admin_Page {
$is_refundable = in_array($payment->get_status(), wu_get_refundable_payment_types(), true);
if ( ! $is_refundable) {
wp_send_json_error(new \WP_Error('payment-not-refunded', __('This payment is not in a refundable state.', 'wp-ultimo')));
} // end if;
}
/*
* First we set the flag to cancel membership
@ -424,30 +431,30 @@ class Payment_Edit_Admin_Page extends Edit_Admin_Page {
$status = $payment->refund($amount, $should_cancel_membership_on_refund);
if (is_wp_error($status)) {
wp_send_json_error($status);
} // end if;
}
/*
* Done! Redirect back.
*/
wp_send_json_success(array(
'redirect_url' => wu_network_admin_url('wp-ultimo-edit-payment', array(
wp_send_json_success(
array(
'redirect_url' => wu_network_admin_url(
'wp-ultimo-edit-payment',
array(
'id' => $payment->get_id(),
'updated' => 1,
)),
));
} // end if;
)
),
)
);
}
$gateway = wu_get_gateway($gateway_id);
if ( ! $gateway) {
wp_send_json_error(new \WP_Error('gateway-not-found', __('Payment gateway not found.', 'wp-ultimo')));
} // end if;
}
/*
* Process the refund on the gateway.
@ -478,29 +485,30 @@ class Payment_Edit_Admin_Page extends Edit_Admin_Page {
$error = new \WP_Error('refund-error', sprintf(__('An error occurred: %s', 'wp-ultimo'), $status->get_error_message()));
wp_send_json_error($error);
} // end if;
}
} catch (\Throwable $e) {
// translators: %s is the exception error message.
$error = new \WP_Error('refund-error', sprintf(__('An error occurred: %s', 'wp-ultimo'), $e->getMessage()));
wp_send_json_error($error);
} // end try;
}
/*
* Done! Redirect back.
*/
wp_send_json_success(array(
'redirect_url' => wu_network_admin_url('wp-ultimo-edit-payment', array(
wp_send_json_success(
array(
'redirect_url' => wu_network_admin_url(
'wp-ultimo-edit-payment',
array(
'id' => $payment->get_id(),
'updated' => 1,
)),
));
} // end handle_refund_payment_modal;
)
),
)
);
}
/**
* Handles the add/edit of line items.
@ -515,10 +523,8 @@ class Payment_Edit_Admin_Page extends Edit_Admin_Page {
$line_item = wu_get_line_item(wu_request('line_item_id'), $payment->get_id());
if ( ! $line_item) {
$line_item = new \WP_Ultimo\Checkout\Line_Item(array());
} // end if;
}
/*
* First, we get the type.
@ -532,16 +538,13 @@ class Payment_Edit_Admin_Page extends Edit_Admin_Page {
$type = wu_request('type', 'product');
if ($type === 'product') {
$product = wu_get_product(wu_request('product_id'));
if (empty($product)) {
$error = new \WP_Error('missing-product', __('The product was not found.', 'wp-ultimo'));
wp_send_json_error($error);
} // end if;
}
/*
* Constructs the arguments
@ -557,7 +560,6 @@ class Payment_Edit_Admin_Page extends Edit_Admin_Page {
'tax_type' => wu_request('tax_type', 'percentage'),
'tax_label' => wu_request('tax_label', ''),
);
} else {
/**
@ -566,19 +568,20 @@ class Payment_Edit_Admin_Page extends Edit_Admin_Page {
*
* First, check the valid types.
*/
$allowed_types = apply_filters('wu_allowed_line_item_types', array(
$allowed_types = apply_filters(
'wu_allowed_line_item_types',
array(
'fee',
'refund',
'credit',
));
)
);
if ( ! in_array($type, $allowed_types, true)) {
$error = new \WP_Error('invalid-type', __('The line item type is invalid.', 'wp-ultimo'));
wp_send_json_error($error);
} // end if;
}
/*
* Set the new attributes
@ -592,8 +595,7 @@ class Payment_Edit_Admin_Page extends Edit_Admin_Page {
'tax_type' => 'percentage',
'tax_label' => '',
);
} // end if;
}
$line_item->attributes($atts);
@ -608,22 +610,19 @@ class Payment_Edit_Admin_Page extends Edit_Admin_Page {
$saved = $payment->recalculate_totals()->save();
if ( ! $saved) {
wp_send_json_error(new \WP_Error('error', __('Something wrong happened.', 'wp-ultimo')));
} // end if;
}
if (is_wp_error($saved)) {
wp_send_json_error($saved);
}
} // end if;
wp_send_json_success(array(
wp_send_json_success(
array(
'redirect_url' => add_query_arg('updated', 1, $_SERVER['HTTP_REFERER']),
));
} // end handle_edit_line_item_modal;
)
);
}
/**
* Renders the add/edit line items form.
@ -643,8 +642,7 @@ class Payment_Edit_Admin_Page extends Edit_Admin_Page {
* we start a new line.
*/
$line_item = new \WP_Ultimo\Checkout\Line_Item(array());
} // end if;
}
$fields = array(
'tab' => array(
@ -845,24 +843,29 @@ class Payment_Edit_Admin_Page extends Edit_Admin_Page {
),
);
$form = new \WP_Ultimo\UI\Form('edit_line_item', $fields, array(
$form = new \WP_Ultimo\UI\Form(
'edit_line_item',
$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_line_item',
'data-state' => wu_convert_to_state(array(
'data-state' => wu_convert_to_state(
array(
'tab' => 'type',
'type' => $line_item->get_type(),
'taxable' => $line_item->get_tax_rate() > 0,
'unit_price' => $line_item->get_unit_price(),
)),
)
),
));
),
)
);
$form->render();
} // end render_edit_line_item_modal;
}
/**
* Display the payment actions.
@ -877,33 +880,39 @@ class Payment_Edit_Admin_Page extends Edit_Admin_Page {
$is_refundable = in_array($this->get_object()->get_status(), wu_get_refundable_payment_types(), true);
if ($is_refundable) {
$actions['refund_payment'] = array(
'label' => __('Refund Payment', 'wp-ultimo'),
'icon_classes' => 'dashicons-wu-ccw wu-align-text-bottom',
'classes' => 'button wubox',
'href' => wu_get_form_url('refund_payment', array(
'href' => wu_get_form_url(
'refund_payment',
array(
'id' => $this->get_object()->get_id(),
)),
)
),
);
} // end if;
}
$actions['add_line_item'] = array(
'label' => __('Add Line Item', 'wp-ultimo'),
'icon_classes' => 'dashicons-wu-circle-with-plus wu-align-text-bottom',
'classes' => 'button wubox',
'href' => wu_get_form_url('edit_line_item', array(
'href' => wu_get_form_url(
'edit_line_item',
array(
'id' => $this->get_object()->get_id(),
)),
)
),
);
return wu_get_template_contents('payments/line-item-actions', array(
return wu_get_template_contents(
'payments/line-item-actions',
array(
'payment' => $this->get_object(),
'actions' => $actions,
));
} // end display_payment_actions;
)
);
}
/**
* Displays the tax tax breakthrough.
@ -915,12 +924,14 @@ class Payment_Edit_Admin_Page extends Edit_Admin_Page {
$tax_breakthrough = $this->get_object()->get_tax_breakthrough();
wu_get_template('payments/tax-details', array(
wu_get_template(
'payments/tax-details',
array(
'tax_breakthrough' => $tax_breakthrough,
'payment' => $this->get_object(),
));
} // end display_tax_breakthrough;
)
);
}
/**
* Allow child classes to register widgets, if they need them.
@ -938,7 +949,9 @@ class Payment_Edit_Admin_Page extends Edit_Admin_Page {
$tag = "<span class='wu-bg-gray-200 wu-text-gray-700 wu-py-1 wu-px-2 wu-rounded-sm wu-text-xs wu-font-mono $class'>{$label}</span>";
$this->add_fields_widget('at_a_glance', array(
$this->add_fields_widget(
'at_a_glance',
array(
'title' => __('At a Glance', 'wp-ultimo'),
'position' => 'normal',
'classes' => 'wu-overflow-hidden wu-widget-inset',
@ -963,46 +976,63 @@ class Payment_Edit_Admin_Page extends Edit_Admin_Page {
'wrapper_classes' => 'sm:wu-border-r-0',
),
),
));
)
);
$this->add_list_table_widget('line-items', array(
$this->add_list_table_widget(
'line-items',
array(
'title' => __('Line Items', 'wp-ultimo'),
'table' => new \WP_Ultimo\List_Tables\Payment_Line_Item_List_Table(),
'position' => 'normal',
'query_filter' => array($this, 'payments_query_filter'),
'after' => $this->display_payment_actions(),
));
)
);
$this->add_widget('tax-rates', array(
$this->add_widget(
'tax-rates',
array(
'title' => __('Tax Rate Breakthrough', 'wp-ultimo'),
'position' => 'normal',
'display' => array($this, 'display_tax_breakthrough'),
));
)
);
$this->add_tabs_widget('options', array(
$this->add_tabs_widget(
'options',
array(
'title' => __('Payment Options', 'wp-ultimo'),
'position' => 'normal',
'sections' => apply_filters('wu_payments_options_sections', array(), $this->get_object()),
));
)
);
$this->add_list_table_widget('events', array(
$this->add_list_table_widget(
'events',
array(
'title' => __('Events', 'wp-ultimo'),
'table' => new \WP_Ultimo\List_Tables\Inside_Events_List_Table(),
'query_filter' => array($this, 'events_query_filter'),
));
)
);
$membership = $this->get_object()->get_membership();
$this->add_save_widget('save', array(
$this->add_save_widget(
'save',
array(
'html_attr' => array(
'data-wu-app' => 'payment_save',
'data-state' => wu_convert_to_state(array(
'data-state' => wu_convert_to_state(
array(
'status' => $this->get_object()->get_status(),
'original_status' => $this->get_object()->get_status(),
'membership_id' => $membership ? $this->get_object()->get_membership_id() : '',
'membership_status' => $membership ? $membership->get_status() : 'active',
'gateway' => $this->get_object()->get_gateway(),
)),
)
),
),
'fields' => array(
'status' => array(
@ -1072,21 +1102,16 @@ class Payment_Edit_Admin_Page extends Edit_Admin_Page {
$gateway_id = $this->get_object()->get_gateway();
if (empty($this->get_object()->get_gateway_payment_id())) {
return '';
} // end if;
}
$url = apply_filters("wu_{$gateway_id}_remote_payment_url", $this->get_object()->get_gateway_payment_id());
if ($url) {
return sprintf('<a class="wu-text-gray-800 wu-text-center wu-w-full wu-no-underline" href="%s" target="_blank">%s</a>', esc_attr($url), __('View on Gateway &rarr;', 'wp-ultimo'));
} // end if;
}
return '';
},
'wrapper_html_attr' => array(
'v-cloak' => '1',
@ -1121,9 +1146,9 @@ class Payment_Edit_Admin_Page extends Edit_Admin_Page {
),
),
),
));
} // end register_widgets;
)
);
}
/**
* Returns the title of the page.
@ -1134,8 +1159,7 @@ class Payment_Edit_Admin_Page extends Edit_Admin_Page {
public function get_title() {
return $this->edit ? __('Edit Payment', 'wp-ultimo') : __('Add new Payment', 'wp-ultimo');
} // end get_title;
}
/**
* Returns the title of menu for this page.
@ -1146,8 +1170,7 @@ class Payment_Edit_Admin_Page extends Edit_Admin_Page {
public function get_menu_title() {
return __('Edit Payment', 'wp-ultimo');
} // end get_menu_title;
}
/**
* Returns the action links for that page.
@ -1162,7 +1185,6 @@ class Payment_Edit_Admin_Page extends Edit_Admin_Page {
$payment = $this->get_object();
if ($payment) {
$actions[] = array(
'url' => $payment->get_invoice_url(),
'label' => __('Generate Invoice', 'wp-ultimo'),
@ -1170,20 +1192,16 @@ class Payment_Edit_Admin_Page extends Edit_Admin_Page {
);
if ($payment->is_payable()) {
$actions[] = array(
'url' => $payment->get_payment_url(),
'label' => __('Payment URL', 'wp-ultimo'),
'icon' => 'wu-credit-card',
);
} // end if;
} // end if;
}
}
return $actions;
} // end action_links;
}
/**
* Returns the labels to be used on the admin page.
@ -1204,8 +1222,7 @@ class Payment_Edit_Admin_Page extends Edit_Admin_Page {
'delete_button_label' => __('Delete Payment', 'wp-ultimo'),
'delete_description' => __('Be careful. This action is irreversible.', 'wp-ultimo'),
);
} // end get_labels;
}
/**
* Filters the list table to return only relevant events.
@ -1223,8 +1240,7 @@ class Payment_Edit_Admin_Page extends Edit_Admin_Page {
);
return array_merge($args, $extra_args);
} // end events_query_filter;
}
/**
* Filters the list table to return only relevant events.
@ -1242,8 +1258,7 @@ class Payment_Edit_Admin_Page extends Edit_Admin_Page {
);
return array_merge($args, $extra_args);
} // end payments_query_filter;
}
/**
* Returns the object being edit at the moment.
@ -1256,34 +1271,27 @@ class Payment_Edit_Admin_Page extends Edit_Admin_Page {
static $payment;
if ($payment !== null) {
return $payment;
} // end if;
}
if (isset($_GET['id'])) {
$query = new \WP_Ultimo\Database\Payments\Payment_Query;
$query = new \WP_Ultimo\Database\Payments\Payment_Query();
$item = $query->get_item_by('id', $_GET['id']);
if ( ! $item || $item->get_parent_id()) {
wp_redirect(wu_network_admin_url('wp-ultimo-payments'));
exit;
} // end if;
}
$payment = $item;
return $item;
}
} // end if;
return new Payment;
} // end get_object;
return new Payment();
}
/**
* Payments have titles.
*
@ -1292,8 +1300,7 @@ class Payment_Edit_Admin_Page extends Edit_Admin_Page {
public function has_title(): bool {
return false;
} // end has_title;
}
/**
* WIP: Handles saving by recalculating totals for a payment.
@ -1309,21 +1316,15 @@ class Payment_Edit_Admin_Page extends Edit_Admin_Page {
$should_confirm_membership = wu_request('confirm_membership');
if ($should_confirm_membership) {
$membership = $this->get_object()->get_membership();
if ($membership) {
$membership->add_to_times_billed(1);
$membership->renew(false, 'active');
} // end if;
} // end if;
}
}
parent::handle_save();
} // end handle_save;
} // end class Payment_Edit_Admin_Page;
}
}

View File

@ -12,7 +12,7 @@ namespace WP_Ultimo\Admin_Pages;
// Exit if accessed directly
defined('ABSPATH') || exit;
use \WP_Ultimo\Database\Payments\Payment_Status;
use WP_Ultimo\Database\Payments\Payment_Status;
/**
* WP Multisite WaaS Payment Admin Page.
@ -66,13 +66,15 @@ class Payment_List_Admin_Page extends List_Admin_Page {
/*
* Edit/Add Line Item
*/
wu_register_form('add_new_payment', array(
wu_register_form(
'add_new_payment',
array(
'render' => array($this, 'render_add_new_payment_modal'),
'handler' => array($this, 'handle_add_new_payment_modal'),
'capability' => 'wu_edit_payments',
));
} // end register_forms;
)
);
}
/**
* Renders the add/edit line items form.
@ -137,22 +139,27 @@ class Payment_List_Admin_Page extends List_Admin_Page {
),
);
$form = new \WP_Ultimo\UI\Form('add_payment', $fields, array(
$form = new \WP_Ultimo\UI\Form(
'add_payment',
$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_payment',
'data-state' => wu_convert_to_state(array(
'data-state' => wu_convert_to_state(
array(
'taxable' => 0,
'type' => 'product',
)),
)
),
));
),
)
);
$form->render();
} // end render_add_new_payment_modal;
}
/**
* Handles the add/edit of line items.
@ -165,39 +172,44 @@ class Payment_List_Admin_Page extends List_Admin_Page {
$membership = wu_get_membership(wu_request('membership_id'));
if ( ! $membership) {
$error = new \WP_Error('invalid-membership', __('Invalid membership.', 'wp-ultimo'));
return wp_send_json_error($error);
}
} // end if;
$cart = new \WP_Ultimo\Checkout\Cart(array(
$cart = new \WP_Ultimo\Checkout\Cart(
array(
'products' => explode(',', (string) wu_request('products')),
'cart_type' => wu_request('add_setup_fees') ? 'new' : 'renewal',
));
)
);
$payment_data = array_merge($cart->to_payment_data(), array(
$payment_data = array_merge(
$cart->to_payment_data(),
array(
'status' => wu_request('status'),
'membership_id' => $membership->get_id(),
'customer_id' => $membership->get_customer_id(),
));
)
);
$payment = wu_create_payment($payment_data);
if (is_wp_error($payment)) {
return wp_send_json_error($payment);
}
} // end if;
wp_send_json_success(array(
'redirect_url' => wu_network_admin_url('wp-ultimo-edit-payment', array(
wp_send_json_success(
array(
'redirect_url' => wu_network_admin_url(
'wp-ultimo-edit-payment',
array(
'id' => $payment->get_id(),
))
));
} // end handle_add_new_payment_modal;
)
),
)
);
}
/**
* Allow child classes to register widgets, if they need them.
@ -205,7 +217,7 @@ class Payment_List_Admin_Page extends List_Admin_Page {
* @since 1.8.2
* @return void
*/
public function register_widgets() {} // end register_widgets;
public function register_widgets() {}
/**
* Returns an array with the labels for the edit page.
@ -219,8 +231,7 @@ class Payment_List_Admin_Page extends List_Admin_Page {
'deleted_message' => __('Payment removed successfully.', 'wp-ultimo'),
'search_label' => __('Search Payment', 'wp-ultimo'),
);
} // end get_labels;
}
/**
* Returns the title of the page.
@ -231,8 +242,7 @@ class Payment_List_Admin_Page extends List_Admin_Page {
public function get_title() {
return __('Payments', 'wp-ultimo');
} // end get_title;
}
/**
* Returns the title of menu for this page.
@ -243,8 +253,7 @@ class Payment_List_Admin_Page extends List_Admin_Page {
public function get_menu_title() {
return __('Payments', 'wp-ultimo');
} // end get_menu_title;
}
/**
* Allows admins to rename the sub-menu (first item) for a top-level page.
@ -255,8 +264,7 @@ class Payment_List_Admin_Page extends List_Admin_Page {
public function get_submenu_title() {
return __('Payments', 'wp-ultimo');
} // end get_submenu_title;
}
/**
* Returns the action links for that page.
@ -274,8 +282,7 @@ class Payment_List_Admin_Page extends List_Admin_Page {
'url' => wu_get_form_url('add_new_payment'),
),
);
} // end action_links;
}
/**
* Loads the list table for this particular page.
@ -286,7 +293,5 @@ class Payment_List_Admin_Page extends List_Admin_Page {
public function table() {
return new \WP_Ultimo\List_Tables\Payment_List_Table();
} // end table;
} // end class Payment_List_Admin_Page;
}
}

View File

@ -71,8 +71,7 @@ class Placeholders_Admin_Page extends Base_Admin_Page {
public function get_title() {
return __('Edit Template Placeholders', 'wp-ultimo');
} // end get_title;
}
/**
* Returns the title of menu for this page.
@ -83,8 +82,7 @@ class Placeholders_Admin_Page extends Base_Admin_Page {
public function get_menu_title() {
return __('Edit Template Placeholders', 'wp-ultimo');
} // end get_menu_title;
}
/**
* Allows admins to rename the sub-menu (first item) for a top-level page.
@ -95,8 +93,7 @@ class Placeholders_Admin_Page extends Base_Admin_Page {
public function get_submenu_title() {
return __('Edit Template Placeholders', 'wp-ultimo');
} // end get_submenu_title;
}
/**
* Every child class should implement the output method to display the contents of the page.
@ -108,17 +105,22 @@ class Placeholders_Admin_Page extends Base_Admin_Page {
do_action('wu_load_edit_placeholders_list_page');
$columns = apply_filters('wu_edit_placeholders_columns', array(
$columns = apply_filters(
'wu_edit_placeholders_columns',
array(
'placeholder' => __('Placeholder', 'wp-ultimo'),
'content' => __('Content', 'wp-ultimo'),
));
)
);
wu_get_template('sites/edit-placeholders', array(
wu_get_template(
'sites/edit-placeholders',
array(
'columns' => $columns,
'types' => array(),
));
} // end output;
)
);
}
/**
* Adds the cure bg image here as well.
@ -132,14 +134,16 @@ class Placeholders_Admin_Page extends Base_Admin_Page {
wp_register_script('wu-edit-placeholders', wu_get_asset('edit-placeholders.js', 'js'), array('wu-admin', 'wu-vue', 'underscore'), wu_get_version(), false);
wp_localize_script('wu-edit-placeholders', 'wu_placeholdersl10n', array(
wp_localize_script(
'wu-edit-placeholders',
'wu_placeholdersl10n',
array(
'name' => __('Tax', 'wp-ultimo'),
'confirm_message' => __('Are you sure you want to delete this rows?', 'wp-ultimo'),
'confirm_delete_tax_category_message' => __('Are you sure you want to delete this tax category?', 'wp-ultimo'),
));
)
);
wp_enqueue_script('wu-edit-placeholders');
} // end register_scripts;
} // end class Placeholders_Admin_Page;
}
}

View File

@ -12,8 +12,8 @@ namespace WP_Ultimo\Admin_Pages;
// Exit if accessed directly
defined('ABSPATH') || exit;
use \WP_Ultimo\Models\Product;
use \WP_Ultimo\Database\Products\Product_Type;
use WP_Ultimo\Models\Product;
use WP_Ultimo\Database\Products\Product_Type;
/**
* WP Multisite WaaS Product Edit/Add New Admin Page.
@ -96,8 +96,7 @@ class Product_Edit_Admin_Page extends Edit_Admin_Page {
add_action('wu_after_delete_product_modal', array($this, 'product_after_delete_actions'));
add_filter("wu_page_{$this->id}_load", array($this, 'add_new_product_warning_message'));
} // end register_forms;
}
/**
* Adds the new product warning.
@ -108,14 +107,13 @@ class Product_Edit_Admin_Page extends Edit_Admin_Page {
public function add_new_product_warning_message() {
if (wu_request('wu-new-model')) {
if ( ! $this->get_object() || $this->get_object()->get_type() !== Product_Type::PLAN) {
return;
}
} // end if;
\WP_Ultimo\UI\Tours::get_instance()->create_tour('new_product_warning', array(
\WP_Ultimo\UI\Tours::get_instance()->create_tour(
'new_product_warning',
array(
array(
'id' => 'new-product-warning',
'title' => __('On adding a new product...', 'wp-ultimo'),
@ -129,18 +127,17 @@ class Product_Edit_Admin_Page extends Edit_Admin_Page {
'classes' => 'button wu-text-xs sm:wu-normal-case wu-float-left',
'text' => __('Go to Checkout Forms', 'wp-ultimo'),
'url' => wu_network_admin_url('wp-ultimo-checkout-forms'),
)
),
),
'attachTo' => array(
'element' => '#message.updated',
'on' => 'top',
),
),
));
} // end if;
} // end add_new_product_warning_message;
)
);
}
}
/**
* Adds the extra delete fields to the delete form.
@ -165,14 +162,13 @@ class Product_Edit_Admin_Page extends Edit_Admin_Page {
'data-label-field' => 'name',
'data-search-field' => 'name',
'data-max-items' => 1,
'data-exclude' => json_encode(array($product->get_id()))
'data-exclude' => json_encode(array($product->get_id())),
),
),
);
return array_merge($custom_fields, $fields);
} // end product_extra_delete_fields;
}
/**
* Adds the primary domain handling to the product deletion.
@ -191,7 +187,6 @@ class Product_Edit_Admin_Page extends Edit_Admin_Page {
$re_assignment_product = wu_get_product($new_product_id);
if ($re_assignment_product) {
$query = $wpdb->prepare(
"UPDATE {$wpdb->base_prefix}wu_memberships
SET product_id = %d
@ -201,10 +196,8 @@ class Product_Edit_Admin_Page extends Edit_Admin_Page {
);
$wpdb->query($query); // phpcs:ignore
} // end if;
} // end product_after_delete_actions;
}
}
/**
* Registers the necessary scripts and styles for this admin page.
@ -217,8 +210,7 @@ class Product_Edit_Admin_Page extends Edit_Admin_Page {
parent::register_scripts();
wp_enqueue_media();
} // end register_scripts;
}
/**
* Allow child classes to register widgets, if they need them.
@ -230,7 +222,9 @@ class Product_Edit_Admin_Page extends Edit_Admin_Page {
parent::register_widgets();
$this->add_fields_widget('description', array(
$this->add_fields_widget(
'description',
array(
'title' => __('Description', 'wp-ultimo'),
'position' => 'normal',
'fields' => array(
@ -245,29 +239,39 @@ class Product_Edit_Admin_Page extends Edit_Admin_Page {
),
),
),
));
)
);
$this->add_tabs_widget('product_options', array(
$this->add_tabs_widget(
'product_options',
array(
'title' => __('Product Options', 'wp-ultimo'),
'position' => 'normal',
'sections' => $this->get_product_option_sections(),
));
)
);
/*
* Handle legacy options for back-compat.
*/
$this->handle_legacy_options();
$this->add_list_table_widget('events', array(
$this->add_list_table_widget(
'events',
array(
'title' => __('Events', 'wp-ultimo'),
'table' => new \WP_Ultimo\List_Tables\Inside_Events_List_Table(),
'query_filter' => array($this, 'query_filter'),
));
)
);
$save_widget_args = apply_filters('wu_product_edit_save_widget', array(
$save_widget_args = apply_filters(
'wu_product_edit_save_widget',
array(
'html_attr' => array(
'data-wu-app' => 'product_pricing',
'data-state' => json_encode(array(
'data-state' => json_encode(
array(
'is_recurring' => $this->get_object()->is_recurring(),
'pricing_type' => $this->get_object()->get_pricing_type(),
'has_trial' => $this->get_object()->get_trial_duration() > 0,
@ -276,7 +280,8 @@ class Product_Edit_Admin_Page extends Edit_Admin_Page {
'amount' => $this->get_object()->get_formatted_amount(),
'duration' => $this->get_object()->get_duration(),
'duration_unit' => $this->get_object()->get_duration_unit(),
)),
)
),
),
'fields' => array(
// Fields for price
@ -496,11 +501,15 @@ class Product_Edit_Admin_Page extends Edit_Admin_Page {
),
),
),
), $this->get_object());
),
$this->get_object()
);
$this->add_save_widget('save', $save_widget_args);
$this->add_fields_widget('active', array(
$this->add_fields_widget(
'active',
array(
'title' => __('Active', 'wp-ultimo'),
'fields' => array(
'active' => array(
@ -510,9 +519,12 @@ class Product_Edit_Admin_Page extends Edit_Admin_Page {
'value' => $this->get_object()->is_active(),
),
),
));
)
);
$this->add_fields_widget('image', array(
$this->add_fields_widget(
'image',
array(
'title' => __('Product Image', 'wp-ultimo'),
'fields' => array(
'featured_image_id' => array(
@ -524,9 +536,9 @@ class Product_Edit_Admin_Page extends Edit_Admin_Page {
'img' => $this->get_object()->get_featured_image(),
),
),
));
} // end register_widgets;
)
);
}
/**
* Handles legacy advanced options for plans.
@ -538,15 +550,18 @@ class Product_Edit_Admin_Page extends Edit_Admin_Page {
global $wp_filter;
$tabs = apply_filters_deprecated('wu_plans_advanced_options_tabs', array(
$tabs = apply_filters_deprecated(
'wu_plans_advanced_options_tabs',
array(
array(),
), '2.0.0', 'wu_product_options_sections');
),
'2.0.0',
'wu_product_options_sections'
);
if ( ! isset($wp_filter['wu_plans_advanced_options_after_panels'])) {
return;
} // end if;
}
wp_enqueue_style('wu-legacy-admin-tabs', wu_get_asset('legacy-admin-tabs.css', 'css'), false, wu_get_version());
@ -562,24 +577,21 @@ class Product_Edit_Admin_Page extends Edit_Admin_Page {
);
foreach ($priorities as $priority => $callbacks) {
foreach ($callbacks as $id => $callable) {
$fields[ $id ] = array(
'type' => 'html',
'classes' => 'wu--mt-2',
'content' => function () use ($callable) {
call_user_func($callable['function'], new \WU_Plan($this->get_object()));
},
);
}
}
} // end foreach;
} // end foreach;
$this->add_fields_widget('legacy-options', array(
$this->add_fields_widget(
'legacy-options',
array(
'title' => __('Legacy Options', 'wp-ultimo'),
'position' => 'normal',
'fields' => $fields,
@ -588,9 +600,9 @@ class Product_Edit_Admin_Page extends Edit_Admin_Page {
'html_attr' => array(
'style' => 'margin-top: -5px;',
),
));
} // end handle_legacy_options;
)
);
}
/**
* Returns the list of sections and its fields for the product page.
@ -693,10 +705,14 @@ class Product_Edit_Admin_Page extends Edit_Admin_Page {
'data-label-field' => 'name',
'data-search-field' => 'name',
'data-max-items' => 99,
'data-selected' => json_encode(wu_get_products(array(
'data-selected' => json_encode(
wu_get_products(
array(
'id__in' => $this->get_object()->get_available_addons(),
'id__not_in' => array_keys(wu_get_plans_as_options()),
))),
)
)
),
),
),
),
@ -770,7 +786,7 @@ class Product_Edit_Admin_Page extends Edit_Admin_Page {
'type' => 'hidden',
'html_attr' => array(
'v-bind:value' => 'price_variation.amount',
'v-bind:name' => '"price_variations[" + index + "][amount]"'
'v-bind:name' => '"price_variations[" + index + "][amount]"',
),
),
'_price_variations_amount' => array(
@ -869,7 +885,7 @@ class Product_Edit_Admin_Page extends Edit_Admin_Page {
'options' => array(
'default' => __('Default', 'wp-ultimo'),
'assign_template' => __('Assign Site Template', 'wp-ultimo'),
'choose_available_templates' => __('Choose Available Site Templates', 'wp-ultimo')
'choose_available_templates' => __('Choose Available Site Templates', 'wp-ultimo'),
),
'html_attr' => array(
'v-model' => 'site_template_selection_mode',
@ -893,8 +909,7 @@ class Product_Edit_Admin_Page extends Edit_Admin_Page {
);
return apply_filters('wu_product_options_sections', $sections, $this->get_object());
} // end get_product_option_sections;
}
/**
* Returns the HTML markup for the plugin selector list.
@ -908,12 +923,14 @@ class Product_Edit_Admin_Page extends Edit_Admin_Page {
$all_templates = wu_get_site_templates();
return wu_get_template_contents('limitations/site-template-selector', array(
return wu_get_template_contents(
'limitations/site-template-selector',
array(
'templates' => $all_templates,
'product' => $product,
));
} // end get_site_template_selection_list;
)
);
}
/**
* Returns the title of the page.
@ -924,8 +941,7 @@ class Product_Edit_Admin_Page extends Edit_Admin_Page {
public function get_title() {
return $this->edit ? __('Edit Product', 'wp-ultimo') : __('Add new Product', 'wp-ultimo');
} // end get_title;
}
/**
* Returns the title of menu for this page.
@ -936,8 +952,7 @@ class Product_Edit_Admin_Page extends Edit_Admin_Page {
public function get_menu_title() {
return __('Edit Product', 'wp-ultimo');
} // end get_menu_title;
}
/**
* Returns the action links for that page.
@ -950,7 +965,6 @@ class Product_Edit_Admin_Page extends Edit_Admin_Page {
$actions = array();
if ($this->get_object()->get_type() === 'plan' && $this->edit) {
$shareable_link = $this->get_object()->get_shareable_link();
$actions[] = array(
@ -960,12 +974,10 @@ class Product_Edit_Admin_Page extends Edit_Admin_Page {
'classes' => 'wu-copy',
'attrs' => 'data-clipboard-text="' . esc_attr($shareable_link) . '"',
);
} // end if;
}
return $actions;
} // end action_links;
}
/**
* Returns the labels to be used on the admin page.
@ -986,8 +998,7 @@ class Product_Edit_Admin_Page extends Edit_Admin_Page {
'delete_button_label' => __('Delete Product', 'wp-ultimo'),
'delete_description' => __('Be careful. This action is irreversible.', 'wp-ultimo'),
);
} // end get_labels;
}
/**
* Filters the list table to return only relevant events.
@ -1005,8 +1016,7 @@ class Product_Edit_Admin_Page extends Edit_Admin_Page {
);
return array_merge($args, $extra_args);
} // end query_filter;
}
/**
* Returns the object being edit at the moment.
@ -1017,36 +1027,29 @@ class Product_Edit_Admin_Page extends Edit_Admin_Page {
public function get_object() {
if ($this->object !== null) {
return $this->object;
} // end if;
}
if (isset($_GET['id'])) {
$query = new \WP_Ultimo\Database\Products\Product_Query;
$query = new \WP_Ultimo\Database\Products\Product_Query();
$item = $query->get_item_by('id', $_GET['id']);
if ( ! $item) {
wp_redirect(wu_network_admin_url('wp-ultimo-products'));
exit;
} // end if;
}
$this->object = $item;
return $this->object;
}
} // end if;
$this->object = new Product;
$this->object = new Product();
return $this->object;
} // end get_object;
}
/**
* Products have titles.
*
@ -1055,8 +1058,7 @@ class Product_Edit_Admin_Page extends Edit_Admin_Page {
public function has_title(): bool {
return true;
} // end has_title;
}
/**
* Should implement the processes necessary to save the changes made to the object.
@ -1069,61 +1071,45 @@ class Product_Edit_Admin_Page extends Edit_Admin_Page {
* Set the recurring value to zero if the toggle is disabled.
*/
if ( ! wu_request('recurring')) {
$_POST['recurring'] = false;
} // end if;
}
if ( ! wu_request('legacy_options')) {
$_POST['legacy_options'] = false;
} // end if;
}
if ( ! wu_request('featured_plan')) {
$_POST['featured_plan'] = false;
} // end if;
}
/*
* Set the setup fee value to zero if the toggle is disabled.
*/
if ( ! wu_request('has_setup_fee')) {
$_POST['setup_fee'] = 0;
} // end if;
}
/*
* Disabled Trial
*/
if ( ! wu_request('has_trial')) {
$_POST['trial_duration'] = 0;
} // end if;
}
/*
* Set the setup fee value to zero if the toggle is disabled.
*/
if ( ! wu_request('price_variations')) {
$_POST['price_variations'] = array();
} // end if;
}
/*
* Set the taxable value to zero if the toggle is disabled.
*/
if ( ! wu_request('taxable')) {
$_POST['taxable'] = 0;
} // end if;
}
parent::handle_save();
} // end handle_save;
} // end class Product_Edit_Admin_Page;
}
}

View File

@ -60,7 +60,7 @@ class Product_List_Admin_Page extends List_Admin_Page {
* @since 1.8.2
* @return void
*/
public function hooks() {} // end hooks;
public function hooks() {}
/**
* Returns an array with the labels for the edit page.
@ -74,8 +74,7 @@ class Product_List_Admin_Page extends List_Admin_Page {
'deleted_message' => __('Product removed successfully.', 'wp-ultimo'),
'search_label' => __('Search Product', 'wp-ultimo'),
);
} // end get_labels;
}
/**
* Returns the title of the page.
@ -86,8 +85,7 @@ class Product_List_Admin_Page extends List_Admin_Page {
public function get_title() {
return __('Products', 'wp-ultimo');
} // end get_title;
}
/**
* Returns the title of menu for this page.
@ -98,8 +96,7 @@ class Product_List_Admin_Page extends List_Admin_Page {
public function get_menu_title() {
return __('Products', 'wp-ultimo');
} // end get_menu_title;
}
/**
* Allows admins to rename the sub-menu (first item) for a top-level page.
@ -110,8 +107,7 @@ class Product_List_Admin_Page extends List_Admin_Page {
public function get_submenu_title() {
return __('Products', 'wp-ultimo');
} // end get_submenu_title;
}
/**
* Returns the action links for that page.
@ -128,8 +124,7 @@ class Product_List_Admin_Page extends List_Admin_Page {
'icon' => 'wu-circle-with-plus',
),
);
} // end action_links;
}
/**
* Loads the list table for this particular page.
@ -140,7 +135,5 @@ class Product_List_Admin_Page extends List_Admin_Page {
public function table() {
return new \WP_Ultimo\List_Tables\Product_List_Table();
} // end table;
} // end class Product_List_Admin_Page;
}
}

View File

@ -9,9 +9,9 @@
namespace WP_Ultimo\Admin_Pages;
use \WP_Ultimo\Settings;
use \WP_Ultimo\UI\Form;
use \WP_Ultimo\UI\Field;
use WP_Ultimo\Settings;
use WP_Ultimo\UI\Form;
use WP_Ultimo\UI\Field;
// Exit if accessed directly
defined('ABSPATH') || exit;
@ -118,8 +118,7 @@ class Settings_Admin_Page extends Wizard_Admin_Page {
wp_enqueue_script('wu-fields');
wp_enqueue_style('wp-color-picker');
} // end register_scripts;
}
/**
* Registers widgets to the edit page.
@ -135,37 +134,54 @@ class Settings_Admin_Page extends Wizard_Admin_Page {
parent::register_widgets();
wu_register_settings_side_panel('login-and-registration', array(
wu_register_settings_side_panel(
'login-and-registration',
array(
'title' => __('Checkout Forms', 'wp-ultimo'),
'render' => array($this, 'render_checkout_forms_side_panel'),
));
)
);
wu_register_settings_side_panel('sites', array(
wu_register_settings_side_panel(
'sites',
array(
'title' => __('Template Previewer', 'wp-ultimo'),
'render' => array($this, 'render_site_template_side_panel'),
));
)
);
wu_register_settings_side_panel('sites', array(
wu_register_settings_side_panel(
'sites',
array(
'title' => __('Placeholder Editor', 'wp-ultimo'),
'render' => array($this, 'render_site_placeholders_side_panel'),
));
)
);
wu_register_settings_side_panel('payment-gateways', array(
wu_register_settings_side_panel(
'payment-gateways',
array(
'title' => __('Invoices', 'wp-ultimo'),
'render' => array($this, 'render_invoice_side_panel'),
));
)
);
wu_register_settings_side_panel('emails', array(
wu_register_settings_side_panel(
'emails',
array(
'title' => __('System Emails', 'wp-ultimo'),
'render' => array($this, 'render_system_emails_side_panel'),
));
)
);
wu_register_settings_side_panel('emails', array(
wu_register_settings_side_panel(
'emails',
array(
'title' => __('Email Template', 'wp-ultimo'),
'render' => array($this, 'render_email_template_side_panel'),
));
} // end register_widgets;
)
);
}
/**
* Renders the addons side panel
@ -173,7 +189,8 @@ class Settings_Admin_Page extends Wizard_Admin_Page {
* @since 2.0.0
* @return void
*/
public function render_checkout_forms_side_panel() { ?>
public function render_checkout_forms_side_panel() {
?>
<div class="wu-widget-inset">
@ -206,8 +223,7 @@ class Settings_Admin_Page extends Wizard_Admin_Page {
</div>
<?php
} // end render_checkout_forms_side_panel;
}
/**
* Renders the site template side panel
@ -215,7 +231,9 @@ class Settings_Admin_Page extends Wizard_Admin_Page {
* @since 2.0.0
* @return void
*/
public function render_site_template_side_panel() { ?>
public function render_site_template_side_panel() {
?>
<div class="wu-widget-inset">
@ -248,8 +266,7 @@ class Settings_Admin_Page extends Wizard_Admin_Page {
</div>
<?php
} // end render_site_template_side_panel;
}
/**
* Renders the site placeholder side panel
@ -257,7 +274,9 @@ class Settings_Admin_Page extends Wizard_Admin_Page {
* @since 2.0.0
* @return void
*/
public function render_site_placeholders_side_panel() { ?>
public function render_site_placeholders_side_panel() {
?>
<div class="wu-widget-inset">
@ -290,8 +309,7 @@ class Settings_Admin_Page extends Wizard_Admin_Page {
</div>
<?php
} // end render_site_placeholders_side_panel;
}
/**
* Renders the invoice side panel
@ -299,7 +317,9 @@ class Settings_Admin_Page extends Wizard_Admin_Page {
* @since 2.0.0
* @return void
*/
public function render_invoice_side_panel() { ?>
public function render_invoice_side_panel() {
?>
<div class="wu-widget-inset">
@ -332,8 +352,7 @@ class Settings_Admin_Page extends Wizard_Admin_Page {
</div>
<?php
} // end render_invoice_side_panel;
}
/**
* Renders system emails side panel.
@ -341,7 +360,9 @@ class Settings_Admin_Page extends Wizard_Admin_Page {
* @since 2.0.0
* @return void
*/
public function render_system_emails_side_panel() { ?>
public function render_system_emails_side_panel() {
?>
<div class="wu-widget-inset">
@ -374,8 +395,7 @@ class Settings_Admin_Page extends Wizard_Admin_Page {
</div>
<?php
} // end render_system_emails_side_panel;
}
/**
* Renders the email template side panel.
@ -383,7 +403,9 @@ class Settings_Admin_Page extends Wizard_Admin_Page {
* @since 2.0.0
* @return void
*/
public function render_email_template_side_panel() { ?>
public function render_email_template_side_panel() {
?>
<div class="wu-widget-inset">
@ -416,8 +438,7 @@ class Settings_Admin_Page extends Wizard_Admin_Page {
</div>
<?php
} // end render_email_template_side_panel;
}
// phpcs:enable
@ -430,8 +451,7 @@ class Settings_Admin_Page extends Wizard_Admin_Page {
public function get_title() {
return __('Settings', 'wp-ultimo');
} // end get_title;
}
/**
* Returns the title of menu for this page.
@ -442,8 +462,7 @@ class Settings_Admin_Page extends Wizard_Admin_Page {
public function get_menu_title() {
return __('Settings', 'wp-ultimo');
} // end get_menu_title;
}
/**
* Every child class should implement the output method to display the contents of the page.
@ -465,16 +484,18 @@ class Settings_Admin_Page extends Wizard_Admin_Page {
do_action('wu_render_settings');
wu_get_template('base/settings', array(
wu_get_template(
'base/settings',
array(
'screen' => get_current_screen(),
'page' => $this,
'classes' => '',
'sections' => $this->get_sections(),
'current_section' => $this->get_current_section(),
'clickable_navigation' => $this->clickable_navigation,
));
} // end output;
)
);
}
/**
* Returns the list of settings sections.
@ -485,8 +506,7 @@ class Settings_Admin_Page extends Wizard_Admin_Page {
public function get_sections() {
return WP_Ultimo()->settings->get_sections();
} // end get_sections;
}
/**
* Default handler for step submission. Simply redirects to the next step.
@ -497,24 +517,19 @@ class Settings_Admin_Page extends Wizard_Admin_Page {
public function default_handler() {
if ( ! current_user_can('wu_edit_settings')) {
wp_die(__('You do not have the permissions required to change settings.', 'wp-ultimo'));
} // end if;
}
if ( ! isset($_POST['active_gateways']) && wu_request('tab') === 'payment-gateways') {
$_POST['active_gateways'] = array();
} // end if;
}
WP_Ultimo()->settings->save_settings($_POST);
wp_redirect(add_query_arg('updated', 1, wu_get_current_url()));
exit;
} // end default_handler;
}
/**
* Default method for views.
@ -543,17 +558,18 @@ class Settings_Admin_Page extends Wizard_Admin_Page {
'classes' => 'button button-primary button-large wu-ml-auto wu-w-full md:wu-w-auto',
'wrapper_classes' => 'wu-sticky wu-bottom-0 wu-save-button wu-mr-px wu-w-full md:wu-w-auto',
'html_attr' => array(
'v-on:click' => 'send("window", "wu_block_ui", "#wpcontent")'
'v-on:click' => 'send("window", "wu_block_ui", "#wpcontent")',
),
);
if ( ! current_user_can('wu_edit_settings')) {
$fields['save']['html_attr']['disabled'] = 'disabled';
}
} // end if;
$form = new Form($section_slug, $fields, array(
$form = new Form(
$section_slug,
$fields,
array(
'views' => 'admin-pages/fields',
'classes' => 'wu-modal-form wu-widget-list wu-striped wu--mt-5 wu--mx-in wu--mb-in',
'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',
@ -563,10 +579,9 @@ class Settings_Admin_Page extends Wizard_Admin_Page {
'data-wu-app' => str_replace('-', '_', $section_slug),
'data-state' => json_encode(wu_array_map_keys('wu_replace_dashes', Settings::get_instance()->get_all(true))),
),
));
)
);
$form->render();
} // end default_view;
} // end class Settings_Admin_Page;
}
}

View File

@ -12,10 +12,10 @@ namespace WP_Ultimo\Admin_Pages;
// Exit if accessed directly
defined('ABSPATH') || exit;
use \WP_Ultimo\Installers\Migrator;
use \WP_Ultimo\Installers\Core_Installer;
use \WP_Ultimo\Installers\Default_Content_Installer;
use \WP_Ultimo\Logger;
use WP_Ultimo\Installers\Migrator;
use WP_Ultimo\Installers\Core_Installer;
use WP_Ultimo\Installers\Default_Content_Installer;
use WP_Ultimo\Logger;
/**
* WP Multisite WaaS Dashboard Admin Page.
@ -104,7 +104,6 @@ class Setup_Wizard_Admin_Page extends Wizard_Admin_Page {
public function __construct() {
if ( ! $this->is_core_loaded()) {
require_once wu_path('inc/functions/documentation.php');
/**
@ -121,8 +120,7 @@ class Setup_Wizard_Admin_Page extends Wizard_Admin_Page {
$this->menu_icon = 'dashicons-wu-wp-ultimo';
add_action('admin_enqueue_scripts', array($this, 'register_scripts'));
} // end if;
}
parent::__construct();
@ -144,8 +142,7 @@ class Setup_Wizard_Admin_Page extends Wizard_Admin_Page {
* Redirect on activation
*/
add_action('wu_activation', array($this, 'redirect_to_wizard'));
} // end __construct;
}
/**
* Download the migration logs.
@ -172,8 +169,7 @@ class Setup_Wizard_Admin_Page extends Wizard_Admin_Page {
readfile($file);
exit;
} // end download_migration_logs;
}
/**
* Loads the extra elements we need on the wizard itself.
@ -186,8 +182,7 @@ class Setup_Wizard_Admin_Page extends Wizard_Admin_Page {
parent::page_loaded();
$this->set_settings();
} // end page_loaded;
}
/**
* Checks if this is a migration or not.
@ -198,14 +193,11 @@ class Setup_Wizard_Admin_Page extends Wizard_Admin_Page {
public function is_migration() {
if ($this->is_migration === null) {
$this->is_migration = Migrator::is_legacy_network();
} // end if;
}
return $this->is_migration;
} // end is_migration;
}
/**
* Adds missing setup from settings when WP Multisite WaaS is not fully loaded.
@ -216,8 +208,7 @@ class Setup_Wizard_Admin_Page extends Wizard_Admin_Page {
public function set_settings() {
WP_Ultimo()->settings->default_sections();
} // end set_settings;
}
/**
* Redirects to the wizard, if we need to.
@ -228,14 +219,11 @@ class Setup_Wizard_Admin_Page extends Wizard_Admin_Page {
public function redirect_to_wizard() {
if ( ! \WP_Ultimo\Requirements::run_setup() && wu_request('page') !== 'wp-ultimo-setup') {
wp_redirect(wu_network_admin_url('wp-ultimo-setup'));
exit;
} // end if;
} // end redirect_to_wizard;
}
}
/**
* Handles the ajax actions for installers and migrators.
@ -248,12 +236,10 @@ class Setup_Wizard_Admin_Page extends Wizard_Admin_Page {
global $wpdb;
if ( ! current_user_can('manage_network')) {
wp_send_json_error(new \WP_Error('not-allowed', __('Permission denied.', 'wp-ultimo')));
exit;
} // end if;
}
/*
* Load tables.
@ -268,14 +254,11 @@ class Setup_Wizard_Admin_Page extends Wizard_Admin_Page {
$status = apply_filters('wu_handle_ajax_installers', true, $installer, $this);
if (is_wp_error($status)) {
wp_send_json_error($status);
} // end if;
}
wp_send_json_success();
} // end setup_install;
}
/**
* Check if the core was loaded.
@ -286,8 +269,7 @@ class Setup_Wizard_Admin_Page extends Wizard_Admin_Page {
public function is_core_loaded() {
return \WP_Ultimo\Requirements::met() && \WP_Ultimo\Requirements::run_setup();
} // end is_core_loaded;
}
/**
* Returns the logo for the wizard.
@ -298,8 +280,7 @@ class Setup_Wizard_Admin_Page extends Wizard_Admin_Page {
public function get_logo() {
return wu_get_asset('logo.png', 'img');
} // end get_logo;
}
/**
* Returns the title of the page.
@ -310,8 +291,7 @@ class Setup_Wizard_Admin_Page extends Wizard_Admin_Page {
public function get_title(): string {
return sprintf(__('Installation', 'wp-ultimo'));
} // end get_title;
}
/**
* Returns the title of menu for this page.
@ -322,8 +302,7 @@ class Setup_Wizard_Admin_Page extends Wizard_Admin_Page {
public function get_menu_title() {
return WP_Ultimo()->is_loaded() ? __('WP Multisite WaaS Install', 'wp-ultimo') : __('WP Multisite WaaS', 'wp-ultimo');
} // end get_menu_title;
}
/**
* Returns the sections for this Wizard.
@ -336,11 +315,14 @@ class Setup_Wizard_Admin_Page extends Wizard_Admin_Page {
$sections = array(
'welcome' => array(
'title' => __('Welcome', 'wp-ultimo'),
'description' => implode('<br><br>', array(
'description' => implode(
'<br><br>',
array(
__('...and thanks for choosing WP Multisite WaaS!', 'wp-ultimo'),
__('This quick setup wizard will make sure your server is correctly setup, help you configure your new network, and migrate data from previous WP Multisite WaaS versions if necessary.', 'wp-ultimo'),
__('You will also have the option of importing default content. It should take 10 minutes or less!', 'wp-ultimo')
)),
__('You will also have the option of importing default content. It should take 10 minutes or less!', 'wp-ultimo'),
)
),
'next_label' => __('Get Started &rarr;', 'wp-ultimo'),
'back' => false,
),
@ -354,7 +336,7 @@ class Setup_Wizard_Admin_Page extends Wizard_Admin_Page {
'requirements' => array(
'type' => 'note',
'desc' => array($this, 'renders_requirements_table'),
)
),
),
),
'installation' => array(
@ -374,7 +356,6 @@ class Setup_Wizard_Admin_Page extends Wizard_Admin_Page {
* In case of migrations, add different sections.
*/
if ($this->is_migration()) {
$dry_run = wu_request('dry-run', true);
$next = true;
@ -388,12 +369,10 @@ class Setup_Wizard_Admin_Page extends Wizard_Admin_Page {
$description = __('No errors found during dry run! Now it is time to actually migrate! <br><br><strong>We strongly recommend creating a backup of your database before moving forward with the migration.</strong>', 'wp-ultimo');
if ($dry_run) {
$next_label = __('Run Check', 'wp-ultimo');
$description = __('It seems that you were running WP Multisite WaaS 1.X on this network. This migrator will convert the data from the old version to the new one.', 'wp-ultimo') . '<br><br>' . __('First, let\'s run a test migration to see if we can spot any potential errors.', 'wp-ultimo');
} // end if;
}
$fields = array(
'migration' => array(
@ -403,7 +382,6 @@ class Setup_Wizard_Admin_Page extends Wizard_Admin_Page {
);
if ($errors) {
$subject = 'Errors on migrating my network';
$user = wp_get_current_user();
@ -415,7 +393,7 @@ class Setup_Wizard_Admin_Page extends Wizard_Admin_Page {
'Here are the error messages I got:',
sprintf('```%s%s%s```', PHP_EOL, implode(PHP_EOL, $errors), PHP_EOL),
sprintf('```%s%s%s```', PHP_EOL, $back_traces ? implode(PHP_EOL, $back_traces) : 'No backtraces found.', PHP_EOL),
'Kind regards.'
'Kind regards.',
);
$message = implode(PHP_EOL . PHP_EOL, $message_lines);
@ -428,20 +406,35 @@ class Setup_Wizard_Admin_Page extends Wizard_Admin_Page {
$error_list = '<strong>' . __('List of errors detected:', 'wp-ultimo') . '</strong><br><br>';
$errors[] = sprintf('<br><a href="%2$s" class="wu-no-underline wu-text-red-500 wu-font-bold"><span class="dashicons-wu-download wu-mr-2"></span>%1$s</a>', __('Download migration error log', 'wp-ultimo'), add_query_arg(array(
$errors[] = sprintf(
'<br><a href="%2$s" class="wu-no-underline wu-text-red-500 wu-font-bold"><span class="dashicons-wu-download wu-mr-2"></span>%1$s</a>',
__('Download migration error log', 'wp-ultimo'),
add_query_arg(
array(
'action' => 'download_migration_logs',
'nonce' => wp_create_nonce('download_migration_logs'),
), network_admin_url('admin.php')));
),
network_admin_url('admin.php')
)
);
$errors[] = sprintf('<br><a href="%2$s" class="wu-no-underline wu-text-red-500 wu-font-bold"><span class="dashicons-wu-back-in-time wu-mr-2"></span>%1$s</a>', __('Rollback to version 1.10.13', 'wp-ultimo'), add_query_arg(array(
$errors[] = sprintf(
'<br><a href="%2$s" class="wu-no-underline wu-text-red-500 wu-font-bold"><span class="dashicons-wu-back-in-time wu-mr-2"></span>%1$s</a>',
__('Rollback to version 1.10.13', 'wp-ultimo'),
add_query_arg(
array(
'page' => 'wp-ultimo-rollback',
'version' => '1.10.13',
'type' => 'select-version',
), network_admin_url('admin.php')));
),
network_admin_url('admin.php')
)
);
$error_list .= implode('<br>', $errors);
$fields = array_merge(array(
$fields = array_merge(
array(
'errors' => array(
'type' => 'note',
'classes' => 'wu-flex-grow',
@ -451,12 +444,12 @@ class Setup_Wizard_Admin_Page extends Wizard_Admin_Page {
Migrator::get_instance()->session->set('errors', array());
return sprintf('<div class="wu-mt-0 wu-p-4 wu-bg-red-100 wu-border wu-border-solid wu-border-red-200 wu-rounded-sm wu-text-red-500">%s</div>', $error_list);
},
),
), $fields);
} // end if;
),
$fields
);
}
$sections['migration'] = array(
'title' => __('Migration', 'wp-ultimo'),
@ -467,9 +460,7 @@ class Setup_Wizard_Admin_Page extends Wizard_Admin_Page {
'handler' => array($this, 'handle_migration'),
'fields' => $fields,
);
} else {
$sections['your-company'] = array(
'title' => __('Your Company', 'wp-ultimo'),
'description' => __('Before we move on, let\'s configure the basic settings of your network, shall we?', 'wp-ultimo'),
@ -488,8 +479,7 @@ class Setup_Wizard_Admin_Page extends Wizard_Admin_Page {
),
),
);
} // end if;
}
$sections['done'] = array(
'title' => __('Ready!', 'wp-ultimo'),
@ -507,8 +497,7 @@ class Setup_Wizard_Admin_Page extends Wizard_Admin_Page {
* @return array
*/
return apply_filters('wu_setup_wizard', $sections, $this->is_migration(), $this);
} // end get_sections;
}
/**
* Returns the general settings to add to the wizard.
@ -533,10 +522,8 @@ class Setup_Wizard_Admin_Page extends Wizard_Admin_Page {
);
foreach ($fields_to_unset as $field_to_unset) {
unset($general_fields[ $field_to_unset ]);
} // end foreach;
}
// Adds a fake first field to bypass some styling issues with the top-border
$fake_field = array(
@ -548,8 +535,7 @@ class Setup_Wizard_Admin_Page extends Wizard_Admin_Page {
$fields = array_merge($fake_field, $general_fields);
return apply_filters('wu_setup_get_general_settings', $fields);
} // end get_general_settings;
}
/**
* Returns the payment settings to add to the setup wizard.
@ -568,16 +554,13 @@ class Setup_Wizard_Admin_Page extends Wizard_Admin_Page {
);
foreach ($fields_to_unset as $field_to_unset) {
unset($payment_fields[ $field_to_unset ]);
} // end foreach;
}
$fields = array_merge($payment_fields);
return apply_filters('wu_setup_get_payment_settings', $fields);
} // end get_payment_settings;
}
/**
* Render the installation steps table.
@ -592,20 +575,26 @@ class Setup_Wizard_Admin_Page extends Wizard_Admin_Page {
wp_localize_script('wu-setup-wizard', 'wu_setup', $steps);
wp_localize_script('wu-setup-wizard', 'wu_setup_settings', array(
wp_localize_script(
'wu-setup-wizard',
'wu_setup_settings',
array(
'dry_run' => wu_request('dry-run', true),
'generic_error_message' => __('A server error happened while processing this item.', 'wp-ultimo'),
));
)
);
wp_enqueue_script('wu-setup-wizard');
return wu_get_template_contents('wizards/setup/installation_steps', array(
return wu_get_template_contents(
'wizards/setup/installation_steps',
array(
'page' => $this,
'steps' => $steps,
'checks' => $checks,
));
} // end render_installation_steps;
)
);
}
/**
* Renders the terms of support.
@ -616,8 +605,7 @@ class Setup_Wizard_Admin_Page extends Wizard_Admin_Page {
public function _terms_of_support() {
return wu_get_template_contents('wizards/setup/support_terms');
} // end _terms_of_support;
}
/**
* Renders the requirements tables.
@ -637,7 +625,7 @@ class Setup_Wizard_Admin_Page extends Wizard_Admin_Page {
'recommended_version' => \WP_Ultimo\Requirements::$php_recommended_version,
'installed_version' => phpversion(),
'pass_requirements' => version_compare(phpversion(), \WP_Ultimo\Requirements::$php_version, '>='),
'pass_recommendation' => version_compare(phpversion(), \WP_Ultimo\Requirements::$php_recommended_version, '>=')
'pass_recommendation' => version_compare(phpversion(), \WP_Ultimo\Requirements::$php_recommended_version, '>='),
),
'wordpress' => array(
'name' => __('WordPress', 'wp-ultimo'),
@ -646,7 +634,7 @@ class Setup_Wizard_Admin_Page extends Wizard_Admin_Page {
'recommended_version' => \WP_Ultimo\Requirements::$wp_recommended_version,
'installed_version' => $wp_version,
'pass_requirements' => version_compare(phpversion(), \WP_Ultimo\Requirements::$wp_version, '>='),
'pass_recommendation' => version_compare(phpversion(), \WP_Ultimo\Requirements::$wp_recommended_version, '>=')
'pass_recommendation' => version_compare(phpversion(), \WP_Ultimo\Requirements::$wp_recommended_version, '>='),
),
);
@ -671,12 +659,14 @@ class Setup_Wizard_Admin_Page extends Wizard_Admin_Page {
),
);
return wu_get_template_contents('wizards/setup/requirements_table', array(
return wu_get_template_contents(
'wizards/setup/requirements_table',
array(
'requirements' => $requirements,
'plugin_requirements' => $plugin_requirements,
));
} // end renders_requirements_table;
)
);
}
/**
* Displays the content of the final section.
@ -694,21 +684,25 @@ class Setup_Wizard_Admin_Page extends Wizard_Admin_Page {
* @since 2.0.7
*/
if (Migrator::is_legacy_network()) {
update_network_option(null, 'wu_is_migration_done', true);
}
} // end if;
wu_enqueue_async_action('wu_async_take_screenshot', array(
wu_enqueue_async_action(
'wu_async_take_screenshot',
array(
'site_id' => wu_get_main_site_id(),
), 'site');
),
'site'
);
wu_get_template('wizards/setup/ready', array(
wu_get_template(
'wizards/setup/ready',
array(
'screen' => get_current_screen(),
'page' => $this,
));
} // end section_ready;
)
);
}
/**
* Handles the requirements check.
@ -719,18 +713,15 @@ class Setup_Wizard_Admin_Page extends Wizard_Admin_Page {
public function handle_checks() {
if (\WP_Ultimo\Requirements::met() === false) {
wp_redirect(add_query_arg());
exit;
} // end if;
}
wp_redirect($this->get_next_section_link());
exit;
} // end handle_checks;
}
/**
* Handles the saving of setting steps.
@ -745,18 +736,12 @@ class Setup_Wizard_Admin_Page extends Wizard_Admin_Page {
$step = wu_request('step');
if ($step === 'your-company') {
$fields_to_save = $this->get_general_settings();
} elseif ($step === 'payment-gateways') {
$fields_to_save = $this->get_payment_settings();
} else {
return;
} // end if;
}
$settings_to_save = array_intersect_key($_POST, $fields_to_save);
@ -765,8 +750,7 @@ class Setup_Wizard_Admin_Page extends Wizard_Admin_Page {
wp_redirect($this->get_next_section_link());
exit;
} // end handle_save_settings;
}
/**
* Handles the migration step and checks for a test run.
@ -781,28 +765,17 @@ class Setup_Wizard_Admin_Page extends Wizard_Admin_Page {
$errors = Migrator::get_instance()->get_errors();
if ($dry_run) {
$url = add_query_arg('dry-run', empty($errors) ? 0 : 1);
} else {
if (empty($errors)) {
} elseif (empty($errors)) {
$url = remove_query_arg('dry-run', $this->get_next_section_link());
} else {
$url = add_query_arg('dry-run', 0);
} // end if;
} // end if;
}
wp_redirect($url);
exit;
} // end handle_migration;
}
/**
* Handles the configuration of a given integration.
@ -813,7 +786,6 @@ class Setup_Wizard_Admin_Page extends Wizard_Admin_Page {
public function handle_configuration() {
if ($_POST['submit'] === '1') {
$this->integration->setup_constants($_POST);
$redirect_url = $this->get_next_section_link();
@ -821,10 +793,8 @@ class Setup_Wizard_Admin_Page extends Wizard_Admin_Page {
wp_redirect($redirect_url);
exit;
} // end if;
} // end handle_configuration;
}
}
/**
* Handles the testing of a given configuration.
@ -837,13 +807,15 @@ class Setup_Wizard_Admin_Page extends Wizard_Admin_Page {
wp_enqueue_script('wu-vue');
wu_get_template('wizards/host-integrations/test', array(
wu_get_template(
'wizards/host-integrations/test',
array(
'screen' => get_current_screen(),
'page' => $this,
'integration' => $this->integration,
));
} // end section_test;
)
);
}
/**
* Adds the necessary missing scripts if WP Multisite WaaS was not loaded.
@ -854,7 +826,6 @@ class Setup_Wizard_Admin_Page extends Wizard_Admin_Page {
public function register_scripts() {
if (WP_Ultimo()->is_loaded() === false) {
wp_enqueue_style('wu-styling', wu_get_asset('framework.css', 'css'), false, wu_get_version());
wp_enqueue_style('wu-admin', wu_get_asset('admin.css', 'css'), array('wu-styling'), wu_get_version());
@ -874,18 +845,25 @@ class Setup_Wizard_Admin_Page extends Wizard_Admin_Page {
/*
* Localize components
*/
wp_localize_script('wu-fields', 'wu_fields', array(
wp_localize_script(
'wu-fields',
'wu_fields',
array(
'l10n' => array(
'image_picker_title' => __('Select an Image.', 'wp-ultimo'),
'image_picker_button_text' => __('Use this image', 'wp-ultimo'),
),
));
)
);
wp_register_script('wu-functions', wu_get_asset('functions.js', 'js'), array('jquery'));
wp_register_script('wubox', wu_get_asset('wubox.js', 'js'), array('wu-functions'));
wp_localize_script('wubox', 'wuboxL10n', array(
wp_localize_script(
'wubox',
'wuboxL10n',
array(
'next' => __('Next &gt;'),
'prev' => __('&lt; Prev'),
'image' => __('Image'),
@ -893,11 +871,11 @@ class Setup_Wizard_Admin_Page extends Wizard_Admin_Page {
'close' => __('Close'),
'noiframes' => __('This feature requires inline frames. You have iframes disabled or your browser does not support them.'),
'loadingAnimation' => includes_url('js/thickbox/loadingAnimation.gif'),
));
)
);
wp_add_inline_script('wu-setup-wizard-polyfill', 'document.addEventListener("DOMContentLoaded", () => wu_initialize_imagepicker());', 'after');
} // end if;
}
wp_enqueue_script('wu-setup-wizard-polyfill', wu_get_asset('setup-wizard-polyfill.js', 'js'), array('jquery', 'wu-fields', 'wu-functions', 'wubox'), wu_get_version());
@ -905,12 +883,16 @@ class Setup_Wizard_Admin_Page extends Wizard_Admin_Page {
wp_register_script('wu-setup-wizard', wu_get_asset('setup-wizard.js', 'js'), array('jquery'), wu_get_version());
wp_add_inline_style('wu-admin', sprintf('
wp_add_inline_style(
'wu-admin',
sprintf(
'
body.wu-page-wp-ultimo-setup #wpwrap {
background: url("%s") right bottom no-repeat;
background-size: 90%%;
}', wu_get_asset('bg-setup.png', 'img')));
} // end register_scripts;
} // end class Setup_Wizard_Admin_Page;
}',
wu_get_asset('bg-setup.png', 'img')
)
);
}
}

View File

@ -81,8 +81,7 @@ class Shortcodes_Admin_Page extends Base_Admin_Page {
public function init() {
parent::init();
} // end init;
}
/**
* Returns the title of the page.
@ -93,8 +92,7 @@ class Shortcodes_Admin_Page extends Base_Admin_Page {
public function get_title() {
return __('Available Shortcodes', 'wp-ultimo');
} // end get_title;
}
/**
* Returns the title of menu for this page.
@ -105,8 +103,7 @@ class Shortcodes_Admin_Page extends Base_Admin_Page {
public function get_menu_title() {
return __('Available Shortcodes', 'wp-ultimo');
} // end get_menu_title;
}
/**
* Allows admins to rename the sub-menu (first item) for a top-level page.
@ -117,8 +114,7 @@ class Shortcodes_Admin_Page extends Base_Admin_Page {
public function get_submenu_title() {
return __('Dashboard', 'wp-ultimo');
} // end get_submenu_title;
}
/**
* Every child class should implement the output method to display the contents of the page.
@ -130,12 +126,14 @@ class Shortcodes_Admin_Page extends Base_Admin_Page {
$screen = get_current_screen();
wu_get_template('shortcodes/shortcodes', array(
wu_get_template(
'shortcodes/shortcodes',
array(
'screen' => $screen,
'data' => $this->get_data(),
));
} // end output;
)
);
}
/**
* Get data for shortcodes
@ -150,13 +148,11 @@ class Shortcodes_Admin_Page extends Base_Admin_Page {
$data = array();
foreach ($elements as $element) {
$defaults = $element->defaults();
$params = array_filter($element->fields(), fn($el) => $el['type'] !== 'note' && $el['type'] !== 'header');
foreach ($params as $key => $value) {
$params[ $key ]['default'] = wu_get_isset($defaults, $key, '');
$params[ $key ]['desc'] = ! isset($value['desc']) ? '' : $params[ $key ]['desc'];
@ -183,17 +179,14 @@ class Shortcodes_Admin_Page extends Base_Admin_Page {
default:
$params[ $key ]['options'] = $value['type'];
break;
} // end switch;
} // end foreach;
}
}
$id = $element->get_id();
if (strncmp((string) $id, 'wp-ultimo/', strlen('wp-ultimo/')) === 0) {
$id = substr((string) $element->get_id(), strlen('wp-ultimo/'));
} // end if;
}
$data[] = array(
'generator_form_url' => wu_get_form_url("shortcode_{$id}"),
@ -202,11 +195,8 @@ class Shortcodes_Admin_Page extends Base_Admin_Page {
'description' => $element->get_description(),
'params' => $params,
);
} // end foreach;
}
return $data;
} // end get_data;
} // end class Shortcodes_Admin_Page;
}
}

View File

@ -12,8 +12,8 @@ namespace WP_Ultimo\Admin_Pages;
// Exit if accessed directly
defined('ABSPATH') || exit;
use \WP_Ultimo\Database\Sites\Site_Type;
use \WP_Ultimo\Models\Site;
use WP_Ultimo\Database\Sites\Site_Type;
use WP_Ultimo\Models\Site;
/**
* WP Multisite WaaS Site Edit New Admin Page.
@ -98,8 +98,7 @@ class Site_Edit_Admin_Page extends Edit_Admin_Page {
wp_enqueue_media();
wp_enqueue_editor();
} // end register_scripts;
}
/**
* Register ajax forms that we use for site.
@ -111,23 +110,28 @@ class Site_Edit_Admin_Page extends Edit_Admin_Page {
/*
* Transfer site - Confirmation modal
*/
wu_register_form('transfer_site', array(
wu_register_form(
'transfer_site',
array(
'render' => array($this, 'render_transfer_site_modal'),
'handler' => array($this, 'handle_transfer_site_modal'),
'capability' => 'wu_transfer_sites',
));
)
);
/*
* Delete Site - Confirmation modal
*/
add_filter('wu_data_json_success_delete_site_modal', fn($data_json) => array(
'redirect_url' => wu_network_admin_url('wp-ultimo-sites', array('deleted' => 1))
));
add_filter(
'wu_data_json_success_delete_site_modal',
fn($data_json) => array(
'redirect_url' => wu_network_admin_url('wp-ultimo-sites', array('deleted' => 1)),
)
);
add_filter("wu_page_{$this->id}_load", array($this, 'add_new_site_template_warning_message'));
} // end register_forms;
}
/**
* Adds the new site_template warning.
@ -138,14 +142,13 @@ class Site_Edit_Admin_Page extends Edit_Admin_Page {
public function add_new_site_template_warning_message() {
if (wu_request('wu-new-model')) {
if ( ! $this->get_object() || $this->get_object()->get_type() !== Site_Type::SITE_TEMPLATE) {
return;
}
} // end if;
\WP_Ultimo\UI\Tours::get_instance()->create_tour('new_site_template_warning', array(
\WP_Ultimo\UI\Tours::get_instance()->create_tour(
'new_site_template_warning',
array(
array(
'id' => 'new-site-template-warning',
'title' => __('On adding a new Site Template...', 'wp-ultimo'),
@ -159,18 +162,17 @@ class Site_Edit_Admin_Page extends Edit_Admin_Page {
'classes' => 'button wu-text-xs sm:wu-normal-case wu-float-left',
'text' => __('Go to Checkout Forms', 'wp-ultimo'),
'url' => wu_network_admin_url('wp-ultimo-checkout-forms'),
)
),
),
'attachTo' => array(
'element' => '#message.updated',
'on' => 'top',
),
),
));
} // end if;
} // end add_new_site_template_warning_message;
)
);
}
}
/**
* Renders the transfer confirmation form.
@ -183,10 +185,8 @@ class Site_Edit_Admin_Page extends Edit_Admin_Page {
$site = wu_get_site(wu_request('id'));
if ( ! $site) {
return;
} // end if;
}
$fields = array(
'confirm' => array(
@ -218,21 +218,26 @@ class Site_Edit_Admin_Page extends Edit_Admin_Page {
),
);
$form = new \WP_Ultimo\UI\Form('total-actions', $fields, array(
$form = new \WP_Ultimo\UI\Form(
'total-actions',
$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' => 'transfer_site',
'data-state' => json_encode(array(
'data-state' => json_encode(
array(
'confirmed' => false,
)),
)
),
));
),
)
);
$form->render();
} // end render_transfer_site_modal;
}
/**
* Handles the transfer of site.
@ -249,16 +254,12 @@ class Site_Edit_Admin_Page extends Edit_Admin_Page {
$target_membership = wu_get_membership(wu_request('target_membership_id'));
if ( ! $site) {
wp_send_json_error(new \WP_Error('not-found', __('Site not found.', 'wp-ultimo')));
} // end if;
}
if ( ! $target_membership) {
wp_send_json_error(new \WP_Error('not-found', __('Membership not found.', 'wp-ultimo')));
} // end if;
}
$site->set_membership_id($target_membership->get_id());
@ -269,19 +270,21 @@ class Site_Edit_Admin_Page extends Edit_Admin_Page {
$saved = $site->save();
if (is_wp_error($saved)) {
wp_send_json_error($saved);
}
} // end if;
wp_send_json_success(array(
'redirect_url' => wu_network_admin_url('wp-ultimo-edit-site', array(
wp_send_json_success(
array(
'redirect_url' => wu_network_admin_url(
'wp-ultimo-edit-site',
array(
'id' => $site->get_id(),
'updated' => 1,
))
));
} // end handle_transfer_site_modal;
)
),
)
);
}
/**
* Allow child classes to register widgets, if they need them.
@ -299,7 +302,9 @@ class Site_Edit_Admin_Page extends Edit_Admin_Page {
$tag = "<span class='wu-bg-gray-200 wu-py-1 wu-px-2 wu-rounded-sm wu-text-xs wu-font-mono $class'>{$label}</span>";
$this->add_fields_widget('at_a_glance', array(
$this->add_fields_widget(
'at_a_glance',
array(
'title' => __('At a Glance', 'wp-ultimo'),
'position' => 'normal',
'classes' => 'wu-overflow-hidden wu-m-0 wu--mt-1 wu--mx-3 wu--mb-3',
@ -322,9 +327,12 @@ class Site_Edit_Admin_Page extends Edit_Admin_Page {
'tooltip' => '',
),
),
));
)
);
$this->add_fields_widget('description', array(
$this->add_fields_widget(
'description',
array(
'title' => __('Description', 'wp-ultimo'),
'position' => 'normal',
'fields' => array(
@ -338,23 +346,31 @@ class Site_Edit_Admin_Page extends Edit_Admin_Page {
),
),
),
));
)
);
$this->add_tabs_widget('options', array(
$this->add_tabs_widget(
'options',
array(
'title' => __('Site Options', 'wp-ultimo'),
'position' => 'normal',
'sections' => $this->get_site_option_sections(),
));
)
);
$this->add_list_table_widget('domains', array(
$this->add_list_table_widget(
'domains',
array(
'title' => __('Mapped Domains', 'wp-ultimo'),
'table' => new \WP_Ultimo\List_Tables\Sites_Domain_List_Table(),
'query_filter' => array($this, 'domain_query_filter'),
));
)
);
if ($this->get_object()->get_type() === 'customer_owned') {
$this->add_list_table_widget('membership', array(
$this->add_list_table_widget(
'membership',
array(
'title' => __('Linked Membership', 'wp-ultimo'),
'table' => new \WP_Ultimo\List_Tables\Customers_Membership_List_Table(),
'query_filter' => function ($query) {
@ -362,11 +378,13 @@ class Site_Edit_Admin_Page extends Edit_Admin_Page {
$query['id'] = $this->get_object()->get_membership_id();
return $query;
},
));
)
);
$this->add_list_table_widget('customer', array(
$this->add_list_table_widget(
'customer',
array(
'title' => __('Linked Customer', 'wp-ultimo'),
'table' => new \WP_Ultimo\List_Tables\Site_Customer_List_Table(),
'query_filter' => function ($query) {
@ -374,29 +392,35 @@ class Site_Edit_Admin_Page extends Edit_Admin_Page {
$query['id'] = $this->get_object()->get_customer_id();
return $query;
},
));
)
);
}
} // end if;
$this->add_list_table_widget('events', array(
$this->add_list_table_widget(
'events',
array(
'title' => __('Events', 'wp-ultimo'),
'table' => new \WP_Ultimo\List_Tables\Inside_Events_List_Table(),
'query_filter' => array($this, 'query_filter'),
));
)
);
$membership_selected = $this->get_object()->get_membership() ? $this->get_object()->get_membership()->to_search_results() : '';
$template_selected = $this->get_object()->get_template() ? $this->get_object()->get_template()->to_search_results() : '';
$this->add_fields_widget('save', array(
$this->add_fields_widget(
'save',
array(
'html_attr' => array(
'data-wu-app' => 'site_type',
'data-state' => json_encode(array(
'data-state' => json_encode(
array(
'type' => $this->get_object()->get_type(),
'original_membership_id' => $this->get_object()->get_membership_id(),
'membership_id' => $this->get_object()->get_membership_id(),
)),
)
),
),
'fields' => array(
// Fields for price
@ -496,17 +520,23 @@ class Site_Edit_Admin_Page extends Edit_Admin_Page {
'v-cloak' => '1',
),
'html_attr' => array(
'v-bind:href' => "'" . wu_get_form_url('transfer_site', array(
'v-bind:href' => "'" . wu_get_form_url(
'transfer_site',
array(
'id' => $this->get_object()->get_id(),
'target_membership_id' => '',
)) . "=' + membership_id",
)
) . "=' + membership_id",
'title' => __('Transfer Site', 'wp-ultimo'),
),
),
),
));
)
);
$this->add_fields_widget('active', array(
$this->add_fields_widget(
'active',
array(
'title' => __('Active', 'wp-ultimo'),
'fields' => array(
'active' => array(
@ -516,9 +546,12 @@ class Site_Edit_Admin_Page extends Edit_Admin_Page {
'value' => $this->get_object()->is_active(),
),
),
));
)
);
$this->add_fields_widget('image', array(
$this->add_fields_widget(
'image',
array(
'title' => __('Site Image', 'wp-ultimo'),
'fields' => array(
'featured_image_id' => array(
@ -551,9 +584,9 @@ class Site_Edit_Admin_Page extends Edit_Admin_Page {
'classes' => 'button wu-w-full',
),
),
));
} // end register_widgets;
)
);
}
/**
* Returns the list of sections and its fields for the site page.
@ -572,8 +605,7 @@ class Site_Edit_Admin_Page extends Edit_Admin_Page {
$sections = apply_filters('wu_site_options_sections', $sections, $this->get_object());
return $sections;
} // end get_site_option_sections;
}
/**
* Returns the title of the page.
@ -584,8 +616,7 @@ class Site_Edit_Admin_Page extends Edit_Admin_Page {
public function get_title() {
return $this->edit ? __('Edit Site', 'wp-ultimo') : __('Add new Site', 'wp-ultimo');
} // end get_title;
}
/**
* Returns the title of menu for this page.
@ -596,8 +627,7 @@ class Site_Edit_Admin_Page extends Edit_Admin_Page {
public function get_menu_title() {
return __('Edit Site', 'wp-ultimo');
} // end get_menu_title;
}
/**
* Returns the action links for that page.
@ -624,8 +654,7 @@ class Site_Edit_Admin_Page extends Edit_Admin_Page {
'icon' => 'dashboard',
),
);
} // end action_links;
}
/**
* Returns the labels to be used on the admin page.
@ -646,8 +675,7 @@ class Site_Edit_Admin_Page extends Edit_Admin_Page {
'delete_button_label' => __('Delete Site', 'wp-ultimo'),
'delete_description' => __('Be careful. This action is irreversible.', 'wp-ultimo'),
);
} // end get_labels;
}
/**
* Filters the list table to return only relevant events.
@ -664,8 +692,7 @@ class Site_Edit_Admin_Page extends Edit_Admin_Page {
);
return array_merge($args, $extra_args);
} // end domain_query_filter;
}
/**
* Filters the list table to return only relevant events.
@ -683,8 +710,7 @@ class Site_Edit_Admin_Page extends Edit_Admin_Page {
);
return array_merge($args, $extra_args);
} // end query_filter;
}
/**
* Returns the object being edit at the moment.
@ -695,28 +721,23 @@ class Site_Edit_Admin_Page extends Edit_Admin_Page {
public function get_object() {
if ($this->object !== null) {
return $this->object;
} // end if;
}
$item_id = wu_request('id', 0);
$item = wu_get_site($item_id);
if ( ! $item) {
wp_redirect(wu_network_admin_url('wp-ultimo-sites'));
exit;
} // end if;
}
$this->object = $item;
return $this->object;
} // end get_object;
}
/**
* Sites have titles.
*
@ -725,8 +746,7 @@ class Site_Edit_Admin_Page extends Edit_Admin_Page {
public function has_title(): bool {
return true;
} // end has_title;
}
/**
* Should implement the processes necessary to save the changes made to the object.
@ -739,14 +759,10 @@ class Site_Edit_Admin_Page extends Edit_Admin_Page {
$_POST['categories'] = wu_get_isset($_POST, 'categories', array());
if ($_POST['type'] !== Site_Type::CUSTOMER_OWNED) {
$_POST['membership_id'] = false;
$_POST['customer_id'] = false;
} // end if;
}
return parent::handle_save();
} // end handle_save;
} // end class Site_Edit_Admin_Page;
}
}

View File

@ -64,24 +64,29 @@ class Site_List_Admin_Page extends List_Admin_Page {
/*
* Edit/Add New Site
*/
wu_register_form('add_new_site', array(
wu_register_form(
'add_new_site',
array(
'render' => array($this, 'render_add_new_site_modal'),
'handler' => array($this, 'handle_add_new_site_modal'),
'capability' => 'wu_add_sites',
));
)
);
/*
* Publish pending site.
*/
wu_register_form('publish_pending_site', array(
wu_register_form(
'publish_pending_site',
array(
'render' => array($this, 'render_publish_pending_site_modal'),
'handler' => array($this, 'handle_publish_pending_site_modal'),
'capability' => 'wu_publish_sites',
));
)
);
add_action('wu_handle_bulk_action_form_site_screenshot', array($this, 'handle_bulk_screenshots'), 10, 3);
} // end register_forms;
}
/**
* Handles the screenshot bulk action.
@ -98,14 +103,15 @@ class Site_List_Admin_Page extends List_Admin_Page {
$item_ids = array_filter($ids);
foreach ($item_ids as $item_id) {
wu_enqueue_async_action('wu_async_take_screenshot', array(
wu_enqueue_async_action(
'wu_async_take_screenshot',
array(
'site_id' => $item_id,
), 'site');
} // end foreach;
} // end handle_bulk_screenshots;
),
'site'
);
}
}
/**
* Renders the deletion confirmation form.
@ -118,10 +124,8 @@ class Site_List_Admin_Page extends List_Admin_Page {
$membership = wu_get_membership(wu_request('membership_id'));
if ( ! $membership) {
return;
} // end if;
}
$fields = array(
'confirm' => array(
@ -153,21 +157,26 @@ class Site_List_Admin_Page extends List_Admin_Page {
),
);
$form = new \WP_Ultimo\UI\Form('total-actions', $fields, array(
$form = new \WP_Ultimo\UI\Form(
'total-actions',
$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' => 'true',
'data-state' => json_encode(array(
'data-state' => json_encode(
array(
'confirmed' => false,
)),
)
),
));
),
)
);
$form->render();
} // end render_publish_pending_site_modal;
}
/**
* Handles the deletion of line items.
@ -180,28 +189,22 @@ class Site_List_Admin_Page extends List_Admin_Page {
$membership = wu_get_membership(wu_request('membership_id'));
if ( ! $membership) {
wp_send_json_error(new \WP_Error('not-found', __('Pending site not found.', 'wp-ultimo')));
} // end if;
}
$pending_site = $membership->get_pending_site();
if ( ! is_a($pending_site, '\\WP_Ultimo\\Models\\Site')) {
wp_send_json_error(new \WP_Error('not-found', __('Pending site not found.', 'wp-ultimo')));
} // end if;
}
$pending_site->set_type('customer_owned');
$saved = $pending_site->save();
if (is_wp_error($saved)) {
wp_send_json_error($saved);
} // end if;
}
$membership->delete_pending_site();
@ -212,13 +215,17 @@ class Site_List_Admin_Page extends List_Admin_Page {
$redirect = current_user_can('wu_edit_sites') ? 'wp-ultimo-edit-site' : 'wp-ultimo-sites';
wp_send_json_success(array(
'redirect_url' => wu_network_admin_url($redirect, array(
wp_send_json_success(
array(
'redirect_url' => wu_network_admin_url(
$redirect,
array(
'id' => $pending_site->get_id(),
))
));
} // end handle_publish_pending_site_modal;
)
),
)
);
}
/**
* Handles the add/edit of line items.
@ -233,17 +240,13 @@ class Site_List_Admin_Page extends List_Admin_Page {
$domain_type = wu_request('tab', is_subdomain_install() ? 'sub-domain' : 'sub-directory');
if ($domain_type === 'domain') {
$domain = wu_request('domain', '');
$path = '/';
} else {
$d = wu_get_site_domain_and_path(wu_request('domain', ''));
$domain = $d->domain;
$path = $d->path;
} // end if;
}
$atts = array(
'domain' => $domain,
@ -254,36 +257,36 @@ class Site_List_Admin_Page extends List_Admin_Page {
'membership_id' => wu_request('membership_id', false),
'duplication_arguments' => array(
'copy_media' => wu_request('copy_media'),
)
),
);
$site = wu_create_site($atts);
if (is_wp_error($site)) {
return wp_send_json_error($site);
} // end if;
}
if ($site->get_blog_id() === false) {
$error = new \WP_Error('error', __('Something wrong happened.', 'wp-ultimo'));
return wp_send_json_error($error);
} // end if;
}
$redirect = current_user_can('wu_edit_sites') ? 'wp-ultimo-edit-site' : 'wp-ultimo-sites';
wp_send_json_success(array(
'redirect_url' => wu_network_admin_url($redirect, array(
wp_send_json_success(
array(
'redirect_url' => wu_network_admin_url(
$redirect,
array(
'id' => $site->get_id(),
'wu-new-model' => 1,
'updated' => 1,
))
));
} // end handle_add_new_site_modal;
)
),
)
);
}
/**
* Renders the add/edit line items form.
@ -316,8 +319,7 @@ class Site_List_Admin_Page extends List_Admin_Page {
$type = $site->get_type();
$template_id = $duplicate_id;
$membership_id = $site->get_membership_id();
} // end if;
}
$save_label = $duplicate_id ? __('Duplicate Site', 'wp-ultimo') : __('Add new Site', 'wp-ultimo');
@ -331,14 +333,10 @@ class Site_List_Admin_Page extends List_Admin_Page {
* Only keep the tab that correspond to the install type.
*/
if (is_subdomain_install()) {
unset($options['sub-directory']);
} else {
unset($options['sub-domain']);
} // end if;
}
$fields = array(
'tab' => array(
@ -460,13 +458,17 @@ class Site_List_Admin_Page extends List_Admin_Page {
$d = wu_get_site_domain_and_path('replace');
$form = new \WP_Ultimo\UI\Form('add_new_site', $fields, array(
$form = new \WP_Ultimo\UI\Form(
'add_new_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' => 'add_new_site',
'data-state' => wu_convert_to_state(array(
'data-state' => wu_convert_to_state(
array(
'tab' => is_subdomain_install() ? 'sub-domain' : 'sub-directory',
'install_type' => is_subdomain_install() ? 'sub-domain' : 'sub-directory',
'membership' => $membership_id,
@ -475,13 +477,14 @@ class Site_List_Admin_Page extends List_Admin_Page {
'base_url' => str_replace('replace.', '', (string) $d->domain) . '/',
'scheme' => is_ssl() ? 'https://' : 'http://',
'domain' => $path,
)),
)
),
));
),
)
);
$form->render();
} // end render_add_new_site_modal;
}
/**
* Allow child classes to register widgets, if they need them.
@ -489,7 +492,7 @@ class Site_List_Admin_Page extends List_Admin_Page {
* @since 1.8.2
* @return void
*/
public function register_widgets() {} // end register_widgets;
public function register_widgets() {}
/**
* Returns an array with the labels for the edit page.
@ -503,8 +506,7 @@ class Site_List_Admin_Page extends List_Admin_Page {
'deleted_message' => __('Site removed successfully.', 'wp-ultimo'),
'search_label' => __('Search Site', 'wp-ultimo'),
);
} // end get_labels;
}
/**
* Returns the title of the page.
@ -515,8 +517,7 @@ class Site_List_Admin_Page extends List_Admin_Page {
public function get_title() {
return __('Sites', 'wp-ultimo');
} // end get_title;
}
/**
* Returns the title of menu for this page.
@ -527,8 +528,7 @@ class Site_List_Admin_Page extends List_Admin_Page {
public function get_menu_title() {
return __('Sites', 'wp-ultimo');
} // end get_menu_title;
}
/**
* Allows admins to rename the sub-menu (first item) for a top-level page.
@ -539,8 +539,7 @@ class Site_List_Admin_Page extends List_Admin_Page {
public function get_submenu_title() {
return __('Sites', 'wp-ultimo');
} // end get_submenu_title;
}
/**
* Returns the action links for that page.
@ -558,8 +557,7 @@ class Site_List_Admin_Page extends List_Admin_Page {
'url' => wu_get_form_url('add_new_site'),
),
);
} // end action_links;
}
/**
* Loads the list table for this particular page.
@ -570,7 +568,5 @@ class Site_List_Admin_Page extends List_Admin_Page {
public function table() {
return new \WP_Ultimo\List_Tables\Site_List_Table();
} // end table;
} // end class Site_List_Admin_Page;
}
}

View File

@ -81,8 +81,7 @@ class System_Info_Admin_Page extends Base_Admin_Page {
public function init() {
add_action('wp_ajax_wu_generate_text_file_system_info', array($this, 'generate_text_file_system_info'));
} // end init;
}
/**
* Allow child classes to register scripts and styles that can be loaded on the output function, for example.
@ -95,8 +94,7 @@ class System_Info_Admin_Page extends Base_Admin_Page {
wp_enqueue_script('dashboard');
wp_enqueue_script('clipboard');
} // end register_scripts;
}
/**
* Allow child classes to register widgets, if they need them.
@ -109,16 +107,19 @@ class System_Info_Admin_Page extends Base_Admin_Page {
$screen = get_current_screen();
foreach ($this->get_data() as $name_type => $data) {
add_meta_box('wp-table-system-info-' . sanitize_title($name_type), $name_type, function() use ($data) {
add_meta_box(
'wp-table-system-info-' . sanitize_title($name_type),
$name_type,
function () use ($data) {
$this->output_table_system_info($data);
}, $screen->id, 'normal', null);
} // end foreach;
} // end register_widgets;
},
$screen->id,
'normal',
null
);
}
}
/**
* Display system info Table
@ -132,12 +133,14 @@ class System_Info_Admin_Page extends Base_Admin_Page {
$screen = get_current_screen();
wu_get_template('system-info/system-info-table', array(
wu_get_template(
'system-info/system-info-table',
array(
'data' => $data,
'screen' => $screen,
));
} // end output_table_system_info;
)
);
}
/**
* Returns the title of the page.
@ -148,8 +151,7 @@ class System_Info_Admin_Page extends Base_Admin_Page {
public function get_title() {
return __('System Info', 'wp-ultimo');
} // end get_title;
}
/**
* Returns the title of menu for this page.
@ -160,8 +162,7 @@ class System_Info_Admin_Page extends Base_Admin_Page {
public function get_menu_title() {
return __('System Info', 'wp-ultimo');
} // end get_menu_title;
}
/**
* Allows admins to rename the sub-menu (first item) for a top-level page.
@ -172,8 +173,7 @@ class System_Info_Admin_Page extends Base_Admin_Page {
public function get_submenu_title() {
return __('Dashboard', 'wp-ultimo');
} // end get_submenu_title;
}
/**
* Every child class should implement the output method to display the contents of the page.
@ -185,12 +185,14 @@ class System_Info_Admin_Page extends Base_Admin_Page {
$screen = get_current_screen();
wu_get_template('system-info/system-info', array(
wu_get_template(
'system-info/system-info',
array(
'data' => $this->get_data(),
'screen' => $screen,
));
} // end output;
)
);
}
/**
* Get data for system info
@ -238,96 +240,76 @@ class System_Info_Admin_Page extends Base_Admin_Page {
$array_constants = array();
foreach ($array_constants_options as $constant) {
$array_constants[] = array(
'tooltip' => '',
'title' => $constant,
'value' => defined($constant) ? (is_bool(constant($constant)) ? __('Enabled', 'wp-ultimo') : constant($constant)) : __('Disabled', 'wp-ultimo'),
);
} // end foreach;
}
foreach ($plugins as $plugin_path => $plugin) {
if (in_array($plugin_path, array_keys($active_plugins), true)) {
$plugin_uri = '';
if (isset($plugin['PluginURI'])) {
$plugin_uri = ' (' . $plugin['PluginURI'] . ')';
} // end if;
}
$array_active_plugins[] = array(
'tooltip' => '',
'title' => $plugin['Name'],
'value' => $plugin['Version'] . $plugin_uri
'value' => $plugin['Version'] . $plugin_uri,
);
} // end if;
} // end foreach;
}
}
$array_active_plugins_main_site = array();
foreach ($plugins as $plugin_path => $plugin) {
if (in_array($plugin_path, $active_plugins_main_site, true)) {
$plugin_uri = '';
if (isset($plugin['PluginURI'])) {
$plugin_uri = ' (' . $plugin['PluginURI'] . ')';
} // end if;
}
$array_active_plugins_main_site[] = array(
'tooltip' => '',
'title' => $plugin['Name'],
'value' => $plugin['Version'] . $plugin_uri
'value' => $plugin['Version'] . $plugin_uri,
);
} // end if;
} // end foreach;
}
}
$wpultimo_settings = array();
foreach ($this->get_all_wp_ultimo_settings() as $setting => $value) {
if (is_array($value)) {
continue;
} // end if;
}
$wpultimo_settings[ $setting ] = array(
'tooltip' => '',
'title' => $setting,
'value' => $value
'value' => $value,
);
} // end foreach;
}
$array_wu_tables = array();
foreach ($wpdb->ms_global_tables as $key => $value) {
if (strncmp((string) $value, 'wu_', strlen('wu_')) === 0 && ! array_key_exists($value, $array_wu_tables)) {
$array_wu_tables[ $value ] = array(
'tooltip' => '',
'title' => $value,
'value' => get_network_option(null, "wpdb_{$value}_version")
'value' => get_network_option(null, "wpdb_{$value}_version"),
);
}
}
} // end if;
} // end foreach;
return apply_filters('wu_system_info_data', array(
return apply_filters(
'wu_system_info_data',
array(
'WordPress and System Settings' => array(
'wp-ultimo-version' => array(
'tooltip' => 'WP Multisite WaaS current version installed locally',
@ -337,67 +319,67 @@ class System_Info_Admin_Page extends Base_Admin_Page {
'wordpress-version' => array(
'tooltip' => '',
'title' => 'WordPress Version',
'value' => get_bloginfo('version')
'value' => get_bloginfo('version'),
),
'php-version' => array(
'tooltip' => '',
'title' => 'PHP Version',
'value' => PHP_VERSION
'value' => PHP_VERSION,
),
'mysql-version' => array(
'tooltip' => '',
'title' => 'MySQL Version ',
'value' => $wpdb->db_version()
'value' => $wpdb->db_version(),
),
'web-server' => array(
'tooltip' => '',
'title' => 'Web Server',
'value' => $_SERVER['SERVER_SOFTWARE']
'value' => $_SERVER['SERVER_SOFTWARE'],
),
'wordpress-url' => array(
'tooltip' => '',
'title' => 'WordPress URL',
'value' => get_bloginfo('wpurl')
'value' => get_bloginfo('wpurl'),
),
'home-url' => array(
'tooltip' => '',
'title' => 'Home URL',
'value' => get_bloginfo('url')
'value' => get_bloginfo('url'),
),
'content-directory' => array(
'tooltip' => '',
'title' => 'Content Directory',
'value' => WP_CONTENT_DIR
'value' => WP_CONTENT_DIR,
),
'content-url' => array(
'tooltip' => '',
'title' => 'Content URL',
'value' => WP_CONTENT_URL
'value' => WP_CONTENT_URL,
),
'plugins-directory' => array(
'tooltip' => '',
'title' => 'Plugins Directory',
'value' => WP_PLUGIN_DIR
'value' => WP_PLUGIN_DIR,
),
'pluguins-url' => array(
'tooltip' => '',
'title' => 'Plugins URL',
'value' => WP_PLUGIN_URL
'value' => WP_PLUGIN_URL,
),
'uploads-directory' => array(
'tooltip' => '',
'title' => 'Uploads Directory',
'value' => (defined('UPLOADS') ? UPLOADS : WP_CONTENT_DIR . '/uploads')
'value' => (defined('UPLOADS') ? UPLOADS : WP_CONTENT_DIR . '/uploads'),
),
'pluguins-url' => array(
'tooltip' => '',
'title' => 'Cookie Domain',
'value' => defined('COOKIE_DOMAIN') ? COOKIE_DOMAIN ? COOKIE_DOMAIN : __('Disabled', 'wp-ultimo') : __('Not set', 'wp-ultimo')
'value' => defined('COOKIE_DOMAIN') ? COOKIE_DOMAIN ? COOKIE_DOMAIN : __('Disabled', 'wp-ultimo') : __('Not set', 'wp-ultimo'),
),
'multisite-active' => array(
'tooltip' => '',
'title' => 'Multi-Site Active',
'value' => is_multisite() ? __('Yes', 'wp-ultimo') : __('No', 'wp-ultimo')
'value' => is_multisite() ? __('Yes', 'wp-ultimo') : __('No', 'wp-ultimo'),
),
'php-current-time-gmt' => array(
'tooltip' => '',
@ -412,132 +394,132 @@ class System_Info_Admin_Page extends Base_Admin_Page {
'php-current-time' => array(
'tooltip' => '',
'title' => 'PHP Current Time - with Timezone',
'value' => wu_get_current_time()
'value' => wu_get_current_time(),
),
'database-current-time' => array(
'tooltip' => '',
'title' => 'Database Current Time',
'value' => gmdate('Y-m-d H:i:s', strtotime((string) $wpdb->get_row('SELECT NOW() as time;')->time))
'value' => gmdate('Y-m-d H:i:s', strtotime((string) $wpdb->get_row('SELECT NOW() as time;')->time)),
),
'php-curl-support' => array(
'tooltip' => '',
'title' => 'PHP cURL Support',
'value' => function_exists('curl_init') ? __('Yes', 'wp-ultimo') : __('No', 'wp-ultimo')
'value' => function_exists('curl_init') ? __('Yes', 'wp-ultimo') : __('No', 'wp-ultimo'),
),
'php-gd-time' => array(
'tooltip' => '',
'title' => 'PHP GD Support',
'value' => function_exists('gd_info') ? __('Yes', 'wp-ultimo') : __('No', 'wp-ultimo')
'value' => function_exists('gd_info') ? __('Yes', 'wp-ultimo') : __('No', 'wp-ultimo'),
),
'php-memory-limit' => array(
'tooltip' => '',
'title' => 'PHP Memory Limit',
'value' => $memory_limit . 'M'
'value' => $memory_limit . 'M',
),
'php-memory-usage' => array(
'tooltip' => '',
'title' => 'PHP Memory Usage',
'value' => $memory_usage . 'M (' . round($memory_usage / $memory_limit * $pad_spaces, 0) . '%)'
'value' => $memory_usage . 'M (' . round($memory_usage / $memory_limit * $pad_spaces, 0) . '%)',
),
'php-post-max-size' => array(
'tooltip' => '',
'title' => 'PHP Post Max Size',
'value' => ini_get('post_max_size')
'value' => ini_get('post_max_size'),
),
'php-upload-max-size' => array(
'tooltip' => '',
'title' => 'PHP Upload Max Size',
'value' => ini_get('upload_max_filesize')
'value' => ini_get('upload_max_filesize'),
),
'php-max-execution-time' => array(
'tooltip' => '',
'title' => 'PHP Max Execution Time',
'value' => $max_execution_time
'value' => $max_execution_time,
),
'php-allow-url-fopen' => array(
'tooltip' => '',
'title' => 'PHP Allow URL Fopen',
'value' => ini_get('allow_url_fopen')
'value' => ini_get('allow_url_fopen'),
),
'php-max-file-uploads' => array(
'tooltip' => '',
'title' => 'PHP Max File Uploads',
'value' => ini_get('max_file_uploads')
'value' => ini_get('max_file_uploads'),
),
'wp-options-count' => array(
'tooltip' => '',
'title' => 'WP Options Count',
'value' => count($all_options)
'value' => count($all_options),
),
'wp-options-size' => array(
'tooltip' => '',
'title' => 'WP Options Size',
'value' => $all_options_bytes . 'kb'
'value' => $all_options_bytes . 'kb',
),
'wp-options-transients' => array(
'tooltip' => '',
'title' => 'WP Options Transients',
'value' => count($all_options_transients)
'value' => count($all_options_transients),
),
'wp-debug' => array(
'tooltip' => '',
'title' => 'WP Options Transients',
'value' => defined('WP_DEBUG') ? WP_DEBUG ? __('Enabled', 'wp-ultimo') : __('Disabled', 'wp-ultimo') : __('Not set', 'wp-ultimo')
'value' => defined('WP_DEBUG') ? WP_DEBUG ? __('Enabled', 'wp-ultimo') : __('Disabled', 'wp-ultimo') : __('Not set', 'wp-ultimo'),
),
'script-debug' => array(
'tooltip' => '',
'title' => 'WP Options Transients',
'value' => defined('SCRIPT_DEBUG') ? SCRIPT_DEBUG ? __('Enabled', 'wp-ultimo') : __('Disabled', 'wp-ultimo') : __('Not set', 'wp-ultimo')
'value' => defined('SCRIPT_DEBUG') ? SCRIPT_DEBUG ? __('Enabled', 'wp-ultimo') : __('Disabled', 'wp-ultimo') : __('Not set', 'wp-ultimo'),
),
'save-queries' => array(
'tooltip' => '',
'title' => 'WP Options Transients',
'value' => defined('SAVEQUERIES') ? SAVEQUERIES ? __('Enabled', 'wp-ultimo') : __('Disabled', 'wp-ultimo') : __('Not set', 'wp-ultimo')
'value' => defined('SAVEQUERIES') ? SAVEQUERIES ? __('Enabled', 'wp-ultimo') : __('Disabled', 'wp-ultimo') : __('Not set', 'wp-ultimo'),
),
'autosave-interval' => array(
'tooltip' => '',
'title' => 'WP Options Transients',
'value' => defined('AUTOSAVE_INTERVAL') ? AUTOSAVE_INTERVAL ? AUTOSAVE_INTERVAL : __('Disabled', 'wp-ultimo') : __('Not set', 'wp-ultimo')
'value' => defined('AUTOSAVE_INTERVAL') ? AUTOSAVE_INTERVAL ? AUTOSAVE_INTERVAL : __('Disabled', 'wp-ultimo') : __('Not set', 'wp-ultimo'),
),
'wp_post_revisions' => array(
'tooltip' => '',
'title' => 'WP Options Transients',
'value' => defined('WP_POST_REVISIONS') ? WP_POST_REVISIONS ? WP_POST_REVISIONS : __('Disabled', 'wp-ultimo') : __('Not set', 'wp-ultimo')
'value' => defined('WP_POST_REVISIONS') ? WP_POST_REVISIONS ? WP_POST_REVISIONS : __('Disabled', 'wp-ultimo') : __('Not set', 'wp-ultimo'),
),
'disable_wp_cron' => array(
'tooltip' => '',
'title' => 'DISABLE_WP_CRON',
'value' => defined('DISABLE_WP_CRON') ? DISABLE_WP_CRON ? DISABLE_WP_CRON : __('Yes', 'wp-ultimo') : __('No', 'wp-ultimo')
'value' => defined('DISABLE_WP_CRON') ? DISABLE_WP_CRON ? DISABLE_WP_CRON : __('Yes', 'wp-ultimo') : __('No', 'wp-ultimo'),
),
'wp_lang' => array(
'tooltip' => '',
'title' => 'WPLANG',
'value' => defined('WPLANG') ? WPLANG ? WPLANG : __('Yes', 'wp-ultimo') : __('No', 'wp-ultimo')
'value' => defined('WPLANG') ? WPLANG ? WPLANG : __('Yes', 'wp-ultimo') : __('No', 'wp-ultimo'),
),
'wp_memory_limit' => array(
'tooltip' => '',
'title' => 'WP_MEMORY_LIMIT',
'value' => (defined('WP_MEMORY_LIMIT') && WP_MEMORY_LIMIT) ? WP_MEMORY_LIMIT : __('Not set', 'wp-ultimo')
'value' => (defined('WP_MEMORY_LIMIT') && WP_MEMORY_LIMIT) ? WP_MEMORY_LIMIT : __('Not set', 'wp-ultimo'),
),
'wp_max_memory_limit' => array(
'tooltip' => '',
'title' => 'WP_MAX_MEMORY_LIMIT',
'value' => (defined('WP_MAX_MEMORY_LIMIT') && WP_MAX_MEMORY_LIMIT) ? WP_MAX_MEMORY_LIMIT : __('Not set', 'wp-ultimo')
'value' => (defined('WP_MAX_MEMORY_LIMIT') && WP_MAX_MEMORY_LIMIT) ? WP_MAX_MEMORY_LIMIT : __('Not set', 'wp-ultimo'),
),
'operating-system' => array(
'tooltip' => '',
'title' => 'Operating System',
'value' => $browser['platform']
'value' => $browser['platform'],
),
'browser' => array(
'tooltip' => '',
'title' => 'Browser',
'value' => $browser['name'] . ' ' . $browser['version']
'value' => $browser['name'] . ' ' . $browser['version'],
),
'user-agent' => array(
'tooltip' => '',
'title' => 'User Agent',
'value' => $browser['user_agent']
'value' => $browser['user_agent'],
),
),
@ -545,7 +527,7 @@ class System_Info_Admin_Page extends Base_Admin_Page {
'active-theme' => array(
'tooltip' => '',
'title' => 'Active Theme',
'value' => $theme->get('Name') . ' - ' . $theme->get('Version') . '(' . $theme->get('ThemeURI') . ')'
'value' => $theme->get('Name') . ' - ' . $theme->get('Version') . '(' . $theme->get('ThemeURI') . ')',
),
),
@ -559,15 +541,15 @@ class System_Info_Admin_Page extends Base_Admin_Page {
'logs-directory' => array(
'tooltip' => '',
'title' => 'Logs Directory',
'value' => is_writable(Logger::get_logs_folder()) ? __('Writable', 'wp-ultimo') : __('Not Writable', 'wp-ultimo')
'value' => is_writable(Logger::get_logs_folder()) ? __('Writable', 'wp-ultimo') : __('Not Writable', 'wp-ultimo'),
),
),
$wpultimo_settings
),
'Defined Constants' => $array_constants,
));
} // end get_data;
)
);
}
/**
* Generate text file of system info data
@ -581,14 +563,10 @@ class System_Info_Admin_Page extends Base_Admin_Page {
$txt = fopen($file_name, 'w') or die('Unable to open file!');
foreach ($this->get_data() as $type) {
foreach ($type as $item) {
fwrite($txt, $item['title'] . ': ' . $item['value'] . PHP_EOL);
} // end foreach;
} // end foreach;
}
}
fclose($txt);
@ -602,8 +580,7 @@ class System_Info_Admin_Page extends Base_Admin_Page {
readfile($file_name);
die;
} // end generate_text_file_system_info;
}
/**
* Get browser data
@ -623,51 +600,33 @@ class System_Info_Admin_Page extends Base_Admin_Page {
// First get the platform
if (preg_match('/linux/i', (string) $user_agent)) {
$platform = 'Linux';
} elseif (preg_match('/macintosh|mac os x/i', (string) $user_agent)) {
$platform = 'Mac';
} elseif (preg_match('/windows|win32/i', (string) $user_agent)) {
$platform = 'Windows';
} // end if;
}
// Next get the name of the user agent yes seperately and for good reason
if (preg_match('/MSIE/i', (string) $user_agent) && ! preg_match('/Opera/i', (string) $user_agent)) {
$browser_name = 'Internet Explorer';
$browser_name_short = 'MSIE';
} elseif (preg_match('/Firefox/i', (string) $user_agent)) {
$browser_name = 'Mozilla Firefox';
$browser_name_short = 'Firefox';
} elseif (preg_match('/Chrome/i', (string) $user_agent)) {
$browser_name = 'Google Chrome';
$browser_name_short = 'Chrome';
} elseif (preg_match('/Safari/i', (string) $user_agent)) {
$browser_name = 'Apple Safari';
$browser_name_short = 'Safari';
} elseif (preg_match('/Opera/i', (string) $user_agent)) {
$browser_name = 'Opera';
$browser_name_short = 'Opera';
} elseif (preg_match('/Netscape/i', (string) $user_agent)) {
$browser_name = 'Netscape';
$browser_name_short = 'Netscape';
} // end if;
}
// Finally get the correct version number
$known = array('Version', $browser_name_short, 'other');
@ -675,7 +634,7 @@ class System_Info_Admin_Page extends Base_Admin_Page {
if ( ! preg_match_all($pattern, (string) $user_agent, $matches)) {
// We have no matching number just continue
} // end if;
}
// See how many we have
$i = count($matches['browser']);
@ -685,37 +644,27 @@ class System_Info_Admin_Page extends Base_Admin_Page {
// We will have two since we are not using 'other' argument yet
// See if version is before or after the name
if (strripos((string) $user_agent, 'Version') < strripos((string) $user_agent, (string) $browser_name_short)) {
$version = $matches['version'][0];
} else {
$version = $matches['version'][1];
} // end if;
}
} else {
$version = $matches['version'][0];
} // end if;
}
// Check if we have a version number
if (empty($version)) {
$version = '?';
} // end if;
}
return array(
'user_agent' => $user_agent,
'name' => $browser_name,
'version' => $version,
'platform' => $platform,
'pattern' => $pattern
'pattern' => $pattern,
);
} // end get_browser;
}
/**
* Get list of all the plugins
@ -725,8 +674,7 @@ class System_Info_Admin_Page extends Base_Admin_Page {
public function get_all_plugins() {
return get_plugins();
} // end get_all_plugins;
}
/**
* Get only the active plugins
@ -736,8 +684,7 @@ class System_Info_Admin_Page extends Base_Admin_Page {
public function get_active_plugins() {
return (array) get_site_option('active_sitewide_plugins', array());
} // end get_active_plugins;
}
/**
* Get only the active plugins on main site
@ -747,16 +694,14 @@ class System_Info_Admin_Page extends Base_Admin_Page {
public function get_active_plugins_on_main_site() {
return (array) get_option('active_plugins', array());
} // end get_active_plugins_on_main_site;
}
/**
* Get memory usage
*/
public function get_memory_usage(): float {
return round(memory_get_usage() / 1024 / 1024, 2);
} // end get_memory_usage;
}
/**
* Get all the ioptions
@ -767,8 +712,7 @@ class System_Info_Admin_Page extends Base_Admin_Page {
// Not to be confused with the core deprecated get_alloptions
return wp_load_alloptions();
} // end get_all_options;
}
/**
* Return all the desired WP Multisite WaaS Settings
@ -796,35 +740,26 @@ class System_Info_Admin_Page extends Base_Admin_Page {
$return_settings = array();
$settings = new \WP_Ultimo\Settings;
$settings = new \WP_Ultimo\Settings();
foreach ($settings->get_all() as $setting => $value) {
$add = true;
foreach ($exclude as $ex) {
if (stristr($setting, $ex) !== false) {
$add = false;
break;
} // end if;
} // end foreach;
}
}
if ($add) {
$return_settings[ $setting ] = $value;
} // end if;
} // end foreach;
}
}
return $return_settings;
} // end get_all_wp_ultimo_settings;
}
/**
* Get the transients om the options
@ -837,17 +772,11 @@ class System_Info_Admin_Page extends Base_Admin_Page {
$transients = array();
foreach ($options as $name => $value) {
if (stristr($name, 'transient')) {
$transients[ $name ] = $value;
} // end if;
} // end foreach;
}
}
return $transients;
} // end get_transients_in_options;
} // end class System_Info_Admin_Page;
}
}

View File

@ -9,7 +9,7 @@
namespace WP_Ultimo\Admin_Pages;
use \WP_Ultimo\Tax\Tax;
use WP_Ultimo\Tax\Tax;
// Exit if accessed directly
defined('ABSPATH') || exit;
@ -73,8 +73,7 @@ class Tax_Rates_Admin_Page extends Base_Admin_Page {
public function get_title() {
return __('Tax Rates', 'wp-ultimo');
} // end get_title;
}
/**
* Returns the title of menu for this page.
@ -85,8 +84,7 @@ class Tax_Rates_Admin_Page extends Base_Admin_Page {
public function get_menu_title() {
return __('Tax Rates', 'wp-ultimo');
} // end get_menu_title;
}
/**
* Allows admins to rename the sub-menu (first item) for a top-level page.
@ -97,8 +95,7 @@ class Tax_Rates_Admin_Page extends Base_Admin_Page {
public function get_submenu_title() {
return __('Tax Rates', 'wp-ultimo');
} // end get_submenu_title;
}
/**
* Every child class should implement the output method to display the contents of the page.
@ -110,22 +107,27 @@ class Tax_Rates_Admin_Page extends Base_Admin_Page {
do_action('wu_load_tax_rates_list_page');
$columns = apply_filters('wu_tax_rates_columns', array(
$columns = apply_filters(
'wu_tax_rates_columns',
array(
'title' => __('Label', 'wp-ultimo'),
'country' => __('Country', 'wp-ultimo'),
'state' => __('State / Province', 'wp-ultimo'),
'city' => __('City', 'wp-ultimo'),
'tax_rate' => __('Tax Rate (%)', 'wp-ultimo'),
'move' => '',
));
)
);
wu_get_template('taxes/list', array(
wu_get_template(
'taxes/list',
array(
'columns' => $columns,
'screen' => get_current_screen(),
'types' => Tax::get_instance()->get_tax_rate_types(),
));
} // end output;
)
);
}
/**
* Adds the cure bg image here as well.
@ -139,19 +141,22 @@ class Tax_Rates_Admin_Page extends Base_Admin_Page {
wp_register_script('wu-tax-rates', wu_get_asset('tax-rates.js', 'js'), array('wu-admin', 'wu-vue', 'underscore', 'wu-selectizer'), wu_get_version(), false);
wp_localize_script('wu-tax-rates', 'wu_tax_ratesl10n', array(
wp_localize_script(
'wu-tax-rates',
'wu_tax_ratesl10n',
array(
'name' => __('Tax', 'wp-ultimo'),
'confirm_message' => __('Are you sure you want to delete this rows?', 'wp-ultimo'),
'confirm_delete_tax_category_message' => __('Are you sure you want to delete this tax category?', 'wp-ultimo'),
));
)
);
wp_enqueue_script('wu-vue-sortable', '//cdn.jsdelivr.net/npm/sortablejs@1.8.4/Sortable.min.js', array(), wu_get_version());
wp_enqueue_script('wu-vue-draggable', '//cdnjs.cloudflare.com/ajax/libs/Vue.Draggable/2.20.0/vuedraggable.umd.min.js', array(), wu_get_version());
wp_enqueue_script('wu-tax-rates');
} // end register_scripts;
}
/**
* Adds field widgets to edit pages with the same Form/Field APIs used elsewhere.
@ -165,7 +170,9 @@ class Tax_Rates_Admin_Page extends Base_Admin_Page {
*/
protected function add_fields_widget($id, $atts = array()) {
$atts = wp_parse_args($atts, array(
$atts = wp_parse_args(
$atts,
array(
'widget_id' => $id,
'before' => '',
'after' => '',
@ -176,12 +183,15 @@ class Tax_Rates_Admin_Page extends Base_Admin_Page {
'html_attr' => array(),
'classes' => '',
'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',
));
)
);
add_meta_box("wp-ultimo-{$id}-widget", $atts['title'], function() use ($atts) {
add_meta_box(
"wp-ultimo-{$id}-widget",
$atts['title'],
function () use ($atts) {
if (wu_get_isset($atts['html_attr'], 'data-wu-app')) {
$atts['fields']['loading'] = array(
'type' => 'note',
'desc' => sprintf('<div class="wu-block wu-text-center wu-blinking-animation wu-text-gray-600 wu-my-1 wu-text-2xs wu-uppercase wu-font-semibold">%s</div>', __('Loading...', 'wp-ultimo')),
@ -189,27 +199,31 @@ class Tax_Rates_Admin_Page extends Base_Admin_Page {
'v-if' => 0,
),
);
} // end if;
}
/**
* Instantiate the form for the order details.
*
* @since 2.0.0
*/
$form = new \WP_Ultimo\UI\Form($atts['widget_id'], $atts['fields'], array(
$form = new \WP_Ultimo\UI\Form(
$atts['widget_id'],
$atts['fields'],
array(
'views' => 'admin-pages/fields',
'classes' => 'wu-widget-list wu-striped wu-m-0 wu--mt-2 wu--mb-3 wu--mx-3 ' . $atts['classes'],
'field_wrapper_classes' => $atts['field_wrapper_classes'],
'html_attr' => $atts['html_attr'],
'before' => $atts['before'],
'after' => $atts['after'],
));
)
);
$form->render();
}, $atts['screen']->id, $atts['position'], null);
} // end add_fields_widget;
} // end class Tax_Rates_Admin_Page;
},
$atts['screen']->id,
$atts['position'],
null
);
}
}

View File

@ -9,7 +9,7 @@
namespace WP_Ultimo\Admin_Pages;
use \WP_Ultimo\UI\Template_Previewer;
use WP_Ultimo\UI\Template_Previewer;
// Exit if accessed directly
defined('ABSPATH') || exit;
@ -74,12 +74,14 @@ class Template_Previewer_Customize_Admin_Page extends Customizer_Admin_Page {
$url = get_site_url(null);
return add_query_arg(array(
return add_query_arg(
array(
'customizer' => 1,
Template_Previewer::get_instance()->get_preview_parameter() => 1,
), $url);
} // end get_preview_url;
),
$url
);
}
/**
* Allow child classes to register widgets, if they need them.
@ -89,7 +91,9 @@ class Template_Previewer_Customize_Admin_Page extends Customizer_Admin_Page {
*/
public function register_widgets() {
$this->add_save_widget('save', array(
$this->add_save_widget(
'save',
array(
'fields' => array(
'preview_url_parameter' => array(
'type' => 'text',
@ -102,11 +106,11 @@ class Template_Previewer_Customize_Admin_Page extends Customizer_Admin_Page {
'title' => __('Active', 'wp-ultimo'),
'desc' => __('If your site templates are not loading, you can disable the top-bar using this setting.', 'wp-ultimo'),
'value' => Template_Previewer::get_instance()->get_setting('enabled', true),
'html_attr' => array(
'html_attr' => array(),
),
),
),
));
)
);
$custom_logo_id = Template_Previewer::get_instance()->get_setting('custom_logo');
@ -211,12 +215,17 @@ class Template_Previewer_Customize_Admin_Page extends Customizer_Admin_Page {
$settings = Template_Previewer::get_instance()->get_settings();
$state = array_merge($settings, array(
$state = array_merge(
$settings,
array(
'tab' => 'general',
'refresh' => true,
));
)
);
$this->add_fields_widget('customizer', array(
$this->add_fields_widget(
'customizer',
array(
'title' => __('Customizer', 'wp-ultimo'),
'position' => 'side',
'fields' => $fields,
@ -226,9 +235,9 @@ class Template_Previewer_Customize_Admin_Page extends Customizer_Admin_Page {
'data-wu-customizer-panel' => true,
'data-state' => json_encode($state),
),
));
} // end register_widgets;
)
);
}
/**
* Returns the title of the page.
@ -239,8 +248,7 @@ class Template_Previewer_Customize_Admin_Page extends Customizer_Admin_Page {
public function get_title() {
return __('Customize Template Previewer', 'wp-ultimo');
} // end get_title;
}
/**
* Returns the title of menu for this page.
@ -251,8 +259,7 @@ class Template_Previewer_Customize_Admin_Page extends Customizer_Admin_Page {
public function get_menu_title() {
return __('Customize Template Previewer', 'wp-ultimo');
} // end get_menu_title;
}
/**
* Returns the action links for that page.
@ -263,8 +270,7 @@ class Template_Previewer_Customize_Admin_Page extends Customizer_Admin_Page {
public function action_links() {
return array();
} // end action_links;
}
/**
* Returns the labels to be used on the admin page.
@ -284,8 +290,7 @@ class Template_Previewer_Customize_Admin_Page extends Customizer_Admin_Page {
'save_button_label' => __('Save Changes', 'wp-ultimo'),
'save_description' => '',
);
} // end get_labels;
}
/**
* Should implement the processes necessary to save the changes made to the object.
@ -306,7 +311,5 @@ class Template_Previewer_Customize_Admin_Page extends Customizer_Admin_Page {
wp_redirect($url);
exit;
} // end handle_save;
} // end class Template_Previewer_Customize_Admin_Page;
}
}

View File

@ -33,8 +33,7 @@ class Top_Admin_Nav_Menu {
public function __construct() {
add_action('admin_bar_menu', array($this, 'add_top_bar_menus'), 50);
} // end __construct;
}
/**
* Adds the WP Multisite WaaS top-bar shortcut menu
@ -47,10 +46,8 @@ class Top_Admin_Nav_Menu {
// Only for super admins
if ( ! current_user_can('manage_network')) {
return;
} // end if;
}
// Add Parent element
$parent = array(
@ -60,7 +57,7 @@ class Top_Admin_Nav_Menu {
'meta' => array(
'class' => 'wp-ultimo-top-menu',
'title' => __('Go to the dashboard', 'wp-ultimo'),
)
),
);
// Site
@ -72,7 +69,7 @@ class Top_Admin_Nav_Menu {
'meta' => array(
'class' => 'wp-ultimo-top-menu',
'title' => __('Go to the sites page', 'wp-ultimo'),
)
),
);
// Memberships
@ -84,7 +81,7 @@ class Top_Admin_Nav_Menu {
'meta' => array(
'class' => 'wp-ultimo-top-menu',
'title' => __('Go to the memberships page', 'wp-ultimo'),
)
),
);
// Customers
@ -96,7 +93,7 @@ class Top_Admin_Nav_Menu {
'meta' => array(
'class' => 'wp-ultimo-top-menu',
'title' => __('Go to the customers page', 'wp-ultimo'),
)
),
);
// Products
@ -108,7 +105,7 @@ class Top_Admin_Nav_Menu {
'meta' => array(
'class' => 'wp-ultimo-top-menu',
'title' => __('Go to the products page', 'wp-ultimo'),
)
),
);
// Payments
@ -120,7 +117,7 @@ class Top_Admin_Nav_Menu {
'meta' => array(
'class' => 'wp-ultimo-top-menu',
'title' => __('Go to the payments page', 'wp-ultimo'),
)
),
);
// Discount Codes
@ -132,7 +129,7 @@ class Top_Admin_Nav_Menu {
'meta' => array(
'class' => 'wp-ultimo-top-menu',
'title' => __('Go to the discount codes page', 'wp-ultimo'),
)
),
);
$container = array(
@ -144,7 +141,7 @@ class Top_Admin_Nav_Menu {
'meta' => array(
'class' => 'wp-ultimo-top-menu ab-sub-secondary',
'title' => __('Go to the settings page', 'wp-ultimo'),
)
),
);
// Settings
@ -156,7 +153,7 @@ class Top_Admin_Nav_Menu {
'meta' => array(
'class' => 'wp-ultimo-top-menu ab-sub-secondary',
'title' => __('Go to the settings page', 'wp-ultimo'),
)
),
);
/**
@ -165,44 +162,32 @@ class Top_Admin_Nav_Menu {
$wp_admin_bar->add_node($parent);
if (current_user_can('wu_read_sites')) {
$wp_admin_bar->add_node($sites);
} //end if;
if (current_user_can('wu_read_memberships')) {
$wp_admin_bar->add_node($memberships);
} //end if;
if (current_user_can('wu_read_customers')) {
$wp_admin_bar->add_node($customers);
} //end if;
if (current_user_can('wu_read_products')) {
$wp_admin_bar->add_node($products);
} //end if;
if (current_user_can('wu_read_payments')) {
$wp_admin_bar->add_node($payments);
} //end if;
if (current_user_can('wu_read_discount_codes')) {
$wp_admin_bar->add_node($discount_codes);
} //end if;
if (current_user_can('wu_read_settings')) {
$wp_admin_bar->add_node($container);
$wp_admin_bar->add_node($settings);
} //end if;
/*
@ -213,20 +198,15 @@ class Top_Admin_Nav_Menu {
$has_addons = false;
foreach ($settings_tabs as $tab => $tab_info) {
if (wu_get_isset($tab_info, 'invisible')) {
continue;
} // end if;
}
$parent = 'wp-ultimo-settings';
if (wu_get_isset($tab_info, 'addon', false)) {
$parent = 'wp-ultimo-settings-addons';
} // end if;
}
$settings_tab = array(
'id' => 'wp-ultimo-settings-' . $tab,
@ -236,13 +216,10 @@ class Top_Admin_Nav_Menu {
'meta' => array(
'class' => 'wp-ultimo-top-menu',
'title' => __('Go to the settings page', 'wp-ultimo'),
)
),
);
$wp_admin_bar->add_node($settings_tab);
} // end foreach;
} // end add_top_bar_menus;
} // end class Top_Admin_Nav_Menu;
}
}
}

View File

@ -81,8 +81,7 @@ class View_Logs_Admin_Page extends Edit_Admin_Page {
public function init() {
add_action('wp_ajax_wu_handle_view_logs', array($this, 'handle_view_logs'));
} // end init;
}
/**
* Registers extra scripts needed for this page.
@ -96,17 +95,20 @@ class View_Logs_Admin_Page extends Edit_Admin_Page {
\WP_Ultimo\Scripts::get_instance()->register_script('wu-view-log', wu_get_asset('view-logs.js', 'js'), array('jquery'));
wp_localize_script('wu-view-log', 'wu_view_logs', array(
wp_localize_script(
'wu-view-log',
'wu_view_logs',
array(
'i18n' => array(
'copied' => __('Copied!', 'wp-ultimo'),
),
));
)
);
wp_enqueue_script('wu-view-log');
wp_enqueue_script('clipboard');
} // end register_scripts;
}
/**
* Returns the title of the page.
@ -117,8 +119,7 @@ class View_Logs_Admin_Page extends Edit_Admin_Page {
public function get_title() {
return __('View Log', 'wp-ultimo');
} // end get_title;
}
/**
* Returns the title of menu for this page.
@ -129,8 +130,7 @@ class View_Logs_Admin_Page extends Edit_Admin_Page {
public function get_menu_title() {
return __('View Log', 'wp-ultimo');
} // end get_menu_title;
}
/**
* Handles the actions for the logs and system info.
@ -141,17 +141,19 @@ class View_Logs_Admin_Page extends Edit_Admin_Page {
*/
public function handle_view_logs() {
$logs_list = list_files(Logger::get_logs_folder(), 2, array(
$logs_list = list_files(
Logger::get_logs_folder(),
2,
array(
'index.html',
));
)
);
$logs_list = array_combine(array_values($logs_list), array_map(fn($file) => str_replace(Logger::get_logs_folder(), '', (string) $file), $logs_list));
if (empty($logs_list)) {
$logs_list[''] = __('No log files found', 'wp-ultimo');
} // end if;
}
$file = wu_request('file');
@ -161,16 +163,12 @@ class View_Logs_Admin_Page extends Edit_Admin_Page {
// Security check
if ($file && ! stristr((string) $file, Logger::get_logs_folder())) {
wp_die(__('You can see files that are not WP Multisite WaaS\'s logs', 'wp-ultimo'));
} // end if;
}
if ( ! $file && ! empty($logs_list)) {
$file = ! $file && ! empty($logs_list) ? current(array_keys($logs_list)) : false;
} // end if;
}
$file_name = str_replace(Logger::get_logs_folder(), '', (string) $file);
@ -186,16 +184,11 @@ class View_Logs_Admin_Page extends Edit_Admin_Page {
);
if (wp_doing_ajax()) {
wp_send_json_success($response);
} else {
return $response;
} // end if;
} // end handle_view_logs;
}
}
/**
* Allow child classes to register widgets, if they need them.
@ -209,7 +202,9 @@ class View_Logs_Admin_Page extends Edit_Admin_Page {
add_meta_box('wp-ultimo-log-contents', __('Log Contents', 'wp-ultimo'), array($this, 'output_default_widget_payload'), get_current_screen()->id, 'normal', null, $info);
$this->add_fields_widget('file-selector', array(
$this->add_fields_widget(
'file-selector',
array(
'title' => __('Log Files', 'wp-ultimo'),
'fields' => array(
'log_file' => array(
@ -227,9 +222,12 @@ class View_Logs_Admin_Page extends Edit_Admin_Page {
'classes' => 'button button-primary wu-w-full',
),
),
));
)
);
$this->add_fields_widget('info', array(
$this->add_fields_widget(
'info',
array(
'title' => __('Timestamps', 'wp-ultimo'),
'position' => 'side',
'fields' => array(
@ -239,11 +237,11 @@ class View_Logs_Admin_Page extends Edit_Admin_Page {
'date' => true,
'value' => date_i18n('Y-m-d H:i:s', filemtime($info['file'])),
'display_value' => date_i18n('Y-m-d H:i:s', filemtime($info['file'])),
)
),
));
} // end register_widgets;
),
)
);
}
/**
* Outputs the pre block that shows the content.
@ -256,13 +254,15 @@ class View_Logs_Admin_Page extends Edit_Admin_Page {
*/
public function output_default_widget_payload($unused, $data) {
wu_get_template('events/widget-payload', array(
wu_get_template(
'events/widget-payload',
array(
'title' => __('Event Payload', 'wp-ultimo'),
'loading_text' => __('Loading Payload', 'wp-ultimo'),
'payload' => $data['args']['contents'],
));
} // end output_default_widget_payload;
)
);
}
/**
* Returns the labels to be used on the admin page.
@ -280,8 +280,7 @@ class View_Logs_Admin_Page extends Edit_Admin_Page {
'delete_button_label' => __('Delete Log File', 'wp-ultimo'),
'delete_description' => __('Be careful. This action is irreversible.', 'wp-ultimo'),
);
} // end get_labels;
}
/**
* Returns the object being edit at the moment.
@ -292,8 +291,7 @@ class View_Logs_Admin_Page extends Edit_Admin_Page {
public function get_object() {
return array();
} // end get_object;
}
/**
* Register additional hooks to page load such as the action links and the save processing.
@ -312,8 +310,7 @@ class View_Logs_Admin_Page extends Edit_Admin_Page {
* Process save, if necessary
*/
$this->process_save();
} // end page_loaded;
}
/**
* Should implement the processes necessary to save the changes made to the object.
@ -326,25 +323,20 @@ class View_Logs_Admin_Page extends Edit_Admin_Page {
$action = wu_request('submit_button', 'none');
if ($action === 'none') {
WP_Ultimo()->notices->add(__('Something wrong happened', 'wp-ultimo'), 'error', 'network-admin');
return;
} // end if;
}
$file = wu_request('log_file', false);
if ( ! file_exists($file)) {
WP_Ultimo()->notices->add(__('File not found', 'wp-ultimo'), 'error', 'network-admin');
return;
} // end if;
}
if ($action === 'download') {
$file_name = str_replace(Logger::get_logs_folder(), '', (string) $file);
header('Content-Type: application/octet-stream');
@ -354,27 +346,20 @@ class View_Logs_Admin_Page extends Edit_Admin_Page {
readfile($file);
exit;
} elseif ($action === 'delete') {
$status = unlink($file);
if ( ! $status) {
WP_Ultimo()->notices->add(__('We were unable to delete file', 'wp-ultimo'), 'error', 'network-admin');
return;
} // end if;
} // end if;
}
}
$url = remove_query_arg('log_file');
wp_redirect(add_query_arg('deleted', 1, $url));
exit;
} // end handle_save;
} // end class View_Logs_Admin_Page;
}
}

View File

@ -12,7 +12,7 @@ namespace WP_Ultimo\Admin_Pages;
// Exit if accessed directly
defined('ABSPATH') || exit;
use \WP_Ultimo\Models\Webhook;
use WP_Ultimo\Models\Webhook;
/**
* WP Multisite WaaS Webhook Edit/Add New Admin Page.
@ -92,17 +92,20 @@ class Webhook_Edit_Admin_Page extends Edit_Admin_Page {
wp_register_script('wu-webhook-page', wu_get_asset('webhook-page.js', 'js'), array('jquery', 'wu-sweet-alert'));
wp_localize_script('wu-webhook-page', 'wu_webhook_page', array(
wp_localize_script(
'wu-webhook-page',
'wu_webhook_page',
array(
'i18n' => array(
'error_title' => __('Webhook Test', 'wp-ultimo'),
'error_message' => __('An error occurred when sending the test webhook, please try again.', 'wp-ultimo'),
'copied' => __('Copied!', 'wp-ultimo'),
),
));
)
);
wp_enqueue_script('wu-webhook-page');
} // end register_scripts;
}
/**
* Register ajax forms that we use for webhook.
@ -114,11 +117,13 @@ class Webhook_Edit_Admin_Page extends Edit_Admin_Page {
/*
* Delete Webhook - Confirmation modal
*/
add_filter('wu_data_json_success_delete_webhook_modal', fn($data_json) => array(
'redirect_url' => wu_network_admin_url('wp-ultimo-webhooks', array('deleted' => 1))
));
} // end register_forms;
add_filter(
'wu_data_json_success_delete_webhook_modal',
fn($data_json) => array(
'redirect_url' => wu_network_admin_url('wp-ultimo-webhooks', array('deleted' => 1)),
)
);
}
/**
* Allow child classes to register widgets, if they need them.
@ -130,7 +135,9 @@ class Webhook_Edit_Admin_Page extends Edit_Admin_Page {
parent::register_widgets();
$this->add_fields_widget('domain-url', array(
$this->add_fields_widget(
'domain-url',
array(
'title' => __('Webhook URL', 'wp-ultimo'),
'position' => 'normal',
'fields' => array(
@ -158,25 +165,29 @@ class Webhook_Edit_Admin_Page extends Edit_Admin_Page {
'wrapper_classes' => 'wu-items-left wu-justify-start',
),
),
));
)
);
add_meta_box('wp-ultimo-payload', __('Event Payload', 'wp-ultimo'), array($this, 'output_default_widget_payload'), get_current_screen()->id, 'normal');
$this->add_list_table_widget('events', array(
$this->add_list_table_widget(
'events',
array(
'title' => __('Events', 'wp-ultimo'),
'table' => new \WP_Ultimo\List_Tables\Inside_Events_List_Table(),
'query_filter' => array($this, 'query_filter'),
));
)
);
$event_list = array();
foreach (wu_get_event_types() as $key => $value) {
$event_list[ $key ] = $value['name'];
}
} // end foreach;
$this->add_save_widget('save', array(
$this->add_save_widget(
'save',
array(
'fields' => array(
'event' => array(
'type' => 'select',
@ -187,9 +198,12 @@ class Webhook_Edit_Admin_Page extends Edit_Admin_Page {
'value' => $this->get_object()->get_event(),
),
),
));
)
);
$this->add_fields_widget('active', array(
$this->add_fields_widget(
'active',
array(
'title' => __('Active', 'wp-ultimo'),
'fields' => array(
'active' => array(
@ -200,9 +214,12 @@ class Webhook_Edit_Admin_Page extends Edit_Admin_Page {
'value' => $this->get_object()->is_active(),
),
),
));
)
);
$this->add_fields_widget('options', array(
$this->add_fields_widget(
'options',
array(
'title' => __('Options', 'wp-ultimo'),
'fields' => array(
'integration' => array(
@ -226,9 +243,9 @@ class Webhook_Edit_Admin_Page extends Edit_Admin_Page {
'tooltip' => __('The number of times that this webhook was triggered so far. It includes test runs.', 'wp-ultimo'),
),
),
));
} // end register_widgets;
)
);
}
/**
* Outputs the markup for the payload widget.
@ -244,13 +261,15 @@ class Webhook_Edit_Admin_Page extends Edit_Admin_Page {
$payload = isset($event['payload']) ? json_encode(wu_maybe_lazy_load_payload($event['payload']), JSON_PRETTY_PRINT) : '{}';
wu_get_template('events/widget-payload', array(
wu_get_template(
'events/widget-payload',
array(
'title' => __('Event Payload', 'wp-ultimo'),
'loading_text' => __('Loading Payload', 'wp-ultimo'),
'payload' => $payload,
));
} // end output_default_widget_payload;
)
);
}
/**
* Filters the list table to return only relevant events.
@ -268,8 +287,7 @@ class Webhook_Edit_Admin_Page extends Edit_Admin_Page {
);
return array_merge($args, $extra_args);
} // end query_filter;
}
/**
* Returns the title of the page.
@ -280,8 +298,7 @@ class Webhook_Edit_Admin_Page extends Edit_Admin_Page {
public function get_title() {
return $this->edit ? __('Edit Webhook', 'wp-ultimo') : __('Add new Webhook', 'wp-ultimo');
} // end get_title;
}
/**
* Returns the title of menu for this page.
@ -292,8 +309,7 @@ class Webhook_Edit_Admin_Page extends Edit_Admin_Page {
public function get_menu_title() {
return __('Edit Webhook', 'wp-ultimo');
} // end get_menu_title;
}
/**
* Returns the action links for that page.
@ -304,8 +320,7 @@ class Webhook_Edit_Admin_Page extends Edit_Admin_Page {
public function action_links() {
return array();
} // end action_links;
}
/**
* Returns the labels to be used on the admin page.
@ -326,8 +341,7 @@ class Webhook_Edit_Admin_Page extends Edit_Admin_Page {
'delete_button_label' => __('Delete Webhook', 'wp-ultimo'),
'delete_description' => __('Be careful. This action is irreversible.', 'wp-ultimo'),
);
} // end get_labels;
}
/**
* Returns the object being edit at the moment.
@ -338,26 +352,21 @@ class Webhook_Edit_Admin_Page extends Edit_Admin_Page {
public function get_object() {
if (wu_request('id')) {
$query = new \WP_Ultimo\Database\Webhooks\Webhook_Query;
$query = new \WP_Ultimo\Database\Webhooks\Webhook_Query();
$item = $query->get_item_by('id', wu_request('id'));
if ( ! $item) {
wp_redirect(wu_network_admin_url('wp-ultimo-webhooks'));
exit;
} // end if;
}
return $item;
}
} // end if;
return new Webhook;
} // end get_object;
return new Webhook();
}
/**
* Webhooks have titles.
*
@ -366,8 +375,7 @@ class Webhook_Edit_Admin_Page extends Edit_Admin_Page {
public function has_title(): bool {
return true;
} // end has_title;
}
/**
* Handles the save of this form.
@ -382,33 +390,25 @@ class Webhook_Edit_Admin_Page extends Edit_Admin_Page {
$object->attributes($_POST);
if (is_wp_error($object->save())) {
$errors = implode('<br>', $object->save()->get_error_messages());
WP_Ultimo()->notices->add($errors, 'error', 'network-admin');
return;
} else {
$array_params = array(
'updated' => 1,
);
if ($this->edit === false) {
$array_params['id'] = $object->get_id();
} // end if;
}
$url = add_query_arg($array_params);
wp_redirect($url);
exit;
} // end if;
} // end handle_save;
} // end class Webhook_Edit_Admin_Page;
}
}
}

View File

@ -66,17 +66,20 @@ class Webhook_List_Admin_Page extends List_Admin_Page {
wp_register_script('wu-webhook-page', wu_get_asset('webhook-page.js', 'js'), array('jquery', 'wu-sweet-alert'));
wp_localize_script('wu-webhook-page', 'wu_webhook_page', array(
wp_localize_script(
'wu-webhook-page',
'wu_webhook_page',
array(
'i18n' => array(
'error_title' => __('Webhook Test', 'wp-ultimo'),
'error_message' => __('An error occurred when sending the test webhook, please try again.', 'wp-ultimo'),
'copied' => __('Copied!', 'wp-ultimo'),
),
));
)
);
wp_enqueue_script('wu-webhook-page');
} // end register_scripts;
}
/**
* Register ajax forms that we use for add new webhooks.
@ -88,13 +91,15 @@ class Webhook_List_Admin_Page extends List_Admin_Page {
/*
* Add new webhook.
*/
wu_register_form('add_new_webhook_modal', array(
wu_register_form(
'add_new_webhook_modal',
array(
'render' => array($this, 'render_add_new_webhook_modal'),
'handler' => array($this, 'handle_add_new_webhook_modal'),
'capability' => 'wu_edit_webhooks',
));
} // end register_forms;
)
);
}
/**
* Renders the add new webhook modal.
@ -109,10 +114,8 @@ class Webhook_List_Admin_Page extends List_Admin_Page {
$event_options = array();
foreach ($events as $slug => $event) {
$event_options[ $slug ] = $event['name'];
} // end foreach;
}
$fields = array(
'name' => array(
@ -125,7 +128,7 @@ class Webhook_List_Admin_Page extends List_Admin_Page {
'title' => __('Event', 'wp-ultimo'),
'type' => 'select',
'desc' => __('The event that will trigger the webhook.', 'wp-ultimo'),
'options' => $event_options
'options' => $event_options,
),
'webhook_url' => array(
'type' => 'url',
@ -145,21 +148,26 @@ class Webhook_List_Admin_Page extends List_Admin_Page {
),
);
$form = new \WP_Ultimo\UI\Form('edit_line_item', $fields, array(
$form = new \WP_Ultimo\UI\Form(
'edit_line_item',
$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_line_item',
'data-state' => json_encode(array(
'event' => ''
)),
'data-state' => json_encode(
array(
'event' => '',
)
),
));
),
)
);
$form->render();
} // end render_add_new_webhook_modal;
}
/**
* Handles the add new webhook modal.
@ -172,20 +180,20 @@ class Webhook_List_Admin_Page extends List_Admin_Page {
$status = wu_create_webhook($_POST);
if (is_wp_error($status)) {
wp_send_json_error($status);
} else {
wp_send_json_success(array(
'redirect_url' => wu_network_admin_url('wp-ultimo-edit-webhook', array(
'id' => $status->get_id()
))
));
} // end if;
} // end handle_add_new_webhook_modal;
wp_send_json_success(
array(
'redirect_url' => wu_network_admin_url(
'wp-ultimo-edit-webhook',
array(
'id' => $status->get_id(),
)
),
)
);
}
}
/**
* Allow child classes to register widgets, if they need them.
@ -193,7 +201,7 @@ class Webhook_List_Admin_Page extends List_Admin_Page {
* @since 1.8.2
* @return void
*/
public function register_widgets() {} // end register_widgets;
public function register_widgets() {}
/**
* Returns an array with the labels for the edit page.
@ -207,8 +215,7 @@ class Webhook_List_Admin_Page extends List_Admin_Page {
'deleted_message' => __('Webhook removed successfully.', 'wp-ultimo'),
'search_label' => __('Search Webhook', 'wp-ultimo'),
);
} // end get_labels;
}
/**
* Returns the title of the page.
@ -219,8 +226,7 @@ class Webhook_List_Admin_Page extends List_Admin_Page {
public function get_title() {
return __('Webhooks', 'wp-ultimo');
} // end get_title;
}
/**
* Returns the title of menu for this page.
@ -231,8 +237,7 @@ class Webhook_List_Admin_Page extends List_Admin_Page {
public function get_menu_title() {
return __('Webhooks', 'wp-ultimo');
} // end get_menu_title;
}
/**
* Allows admins to rename the sub-menu (first item) for a top-level page.
@ -243,8 +248,7 @@ class Webhook_List_Admin_Page extends List_Admin_Page {
public function get_submenu_title() {
return __('Webhooks', 'wp-ultimo');
} // end get_submenu_title;
}
/**
* Returns the action links for that page.
@ -262,8 +266,7 @@ class Webhook_List_Admin_Page extends List_Admin_Page {
'url' => wu_get_form_url('add_new_webhook_modal'),
),
);
} // end action_links;
}
/**
@ -275,7 +278,5 @@ class Webhook_List_Admin_Page extends List_Admin_Page {
public function table() {
return new \WP_Ultimo\List_Tables\Webhook_List_Table();
} // end table;
} // end class Webhook_List_Admin_Page;
}
}

View File

@ -91,8 +91,7 @@ abstract class Wizard_Admin_Page extends Base_Admin_Page {
* Process save, if necessary
*/
$this->process_save();
} // end page_loaded;
}
/**
* Handles saves, after verifying nonces and such. Should not be rewritten by child classes.
@ -105,7 +104,6 @@ abstract class Wizard_Admin_Page extends Base_Admin_Page {
$saving_tag = sprintf('saving_%s', $this->get_current_section());
if (isset($_REQUEST[ $saving_tag ])) {
check_admin_referer($saving_tag, '_wpultimo_nonce');
$handler = isset($this->current_section['handler']) ? $this->current_section['handler'] : array($this, 'default_handler');
@ -114,10 +112,8 @@ abstract class Wizard_Admin_Page extends Base_Admin_Page {
* Calls the saving function
*/
call_user_func($handler);
} // end if;
} // end process_save;
}
}
/**
* Returns the labels to be used on the admin page.
@ -136,8 +132,7 @@ abstract class Wizard_Admin_Page extends Base_Admin_Page {
'save_button_label' => __('Save', 'wp-ultimo'),
'save_description' => '',
);
} // end get_labels;
}
/**
* Registers widgets to the edit page.
@ -154,14 +149,11 @@ abstract class Wizard_Admin_Page extends Base_Admin_Page {
$screen = get_current_screen();
if (wu_get_isset($this->current_section, 'separator')) {
return;
} // end if;
}
add_meta_box('wp-ultimo-wizard-body', wu_get_isset($this->current_section, 'title', __('Section', 'wp-ultimo')), array($this, 'output_default_widget_body'), $screen->id, 'normal', null);
} // end register_widgets;
}
/**
* Outputs the markup for the default Save widget.
@ -181,8 +173,7 @@ abstract class Wizard_Admin_Page extends Base_Admin_Page {
call_user_func($view);
echo '</div>';
} // end output_default_widget_body;
}
/**
* Returns the logo to be used on the wizard.
@ -193,8 +184,7 @@ abstract class Wizard_Admin_Page extends Base_Admin_Page {
public function get_logo() {
return '';
} // end get_logo;
}
/**
* Displays the contents of the edit page.
@ -206,7 +196,9 @@ abstract class Wizard_Admin_Page extends Base_Admin_Page {
/*
* Renders the base edit page layout, with the columns and everything else =)
*/
wu_get_template('base/wizard', array(
wu_get_template(
'base/wizard',
array(
'screen' => get_current_screen(),
'page' => $this,
'logo' => $this->get_logo(),
@ -216,9 +208,9 @@ abstract class Wizard_Admin_Page extends Base_Admin_Page {
'classes' => 'wu-w-full wu-mx-auto sm:wu-w-11/12 xl:wu-w-8/12 wu-mt-8 sm:wu-max-w-screen-lg',
'clickable_navigation' => $this->clickable_navigation,
'form_id' => $this->form_id,
));
} // end output;
)
);
}
/**
* Returns the first section of the signup process
@ -230,16 +222,11 @@ abstract class Wizard_Admin_Page extends Base_Admin_Page {
$keys = array_keys($this->get_sections());
if (isset($keys[1])) {
return $keys[1];
} else {
return false;
} // end if;
} // end get_first_section;
}
}
/**
* Get the current section
@ -255,8 +242,7 @@ abstract class Wizard_Admin_Page extends Base_Admin_Page {
$current_section = isset($_GET[ $this->section_slug ]) ? sanitize_key($_GET[ $this->section_slug ]) : current(array_keys($sections));
return $current_section;
} // end get_current_section;
}
/**
* Returns the page link for the current section.
@ -269,8 +255,7 @@ abstract class Wizard_Admin_Page extends Base_Admin_Page {
public function get_section_link($section) {
return add_query_arg($this->section_slug, $section);
} // end get_section_link;
}
/**
* Returns the link to the next section on the wizard.
@ -287,8 +272,7 @@ abstract class Wizard_Admin_Page extends Base_Admin_Page {
$keys = array_keys($sections);
return add_query_arg($this->section_slug, $keys[ array_search($current_section, array_keys($sections), true) + 1 ]);
} // end get_next_section_link;
}
/**
* Returns the link to the previous section on the wizard.
@ -305,8 +289,7 @@ abstract class Wizard_Admin_Page extends Base_Admin_Page {
$keys = array_keys($sections);
return add_query_arg($this->section_slug, $keys[ array_search($current_section, array_keys($sections), true) - 1 ]);
} // end get_prev_section_link;
}
/**
* Default handler for step submission. Simply redirects to the next step.
@ -319,8 +302,7 @@ abstract class Wizard_Admin_Page extends Base_Admin_Page {
wp_redirect($this->get_next_section_link());
exit;
} // end default_handler;
}
/**
* Default method for views.
@ -330,7 +312,9 @@ abstract class Wizard_Admin_Page extends Base_Admin_Page {
*/
public function default_view() {
$section = wp_parse_args($this->current_section, array(
$section = wp_parse_args(
$this->current_section,
array(
'title' => '',
'description' => '',
'content' => '',
@ -341,38 +325,44 @@ abstract class Wizard_Admin_Page extends Base_Admin_Page {
'back' => false,
'skip' => false,
'next' => true,
));
)
);
/*
* Check if the section has fields
*/
if ( ! empty($section['fields'])) {
if (is_callable($section['fields'])) {
$section['fields'] = call_user_func($section['fields']);
}
} // end if;
$form = new \WP_Ultimo\UI\Form($this->get_current_section(), $section['fields'], array(
$form = new \WP_Ultimo\UI\Form(
$this->get_current_section(),
$section['fields'],
array(
'views' => 'admin-pages/fields',
'classes' => 'wu-widget-list wu-striped wu-m-0 wu-mt-2 wu--mb-6 wu--mx-6',
'field_wrapper_classes' => 'wu-w-full wu-box-border wu-items-center wu-flex wu-justify-between wu-px-6 wu-py-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',
));
)
);
ob_start();
$form->render();
$section['content'] = ob_get_clean();
}
} // end if;
wu_get_template('wizards/setup/default', array_merge($section, array(
wu_get_template(
'wizards/setup/default',
array_merge(
$section,
array(
'page' => $this,
)));
} // end default_view;
)
)
);
}
/**
* Renders the default submit box with action buttons at the bottom of the wizard.
@ -382,13 +372,15 @@ abstract class Wizard_Admin_Page extends Base_Admin_Page {
*/
public function render_submit_box() {
wu_get_template('base/wizard/submit-box', array(
wu_get_template(
'base/wizard/submit-box',
array(
'screen' => get_current_screen(),
'page' => $this,
'labels' => $this->get_labels(),
));
} // end render_submit_box;
)
);
}
/**
* Wizard classes should implement a method that returns an array of sections and subsections.
@ -396,6 +388,5 @@ abstract class Wizard_Admin_Page extends Base_Admin_Page {
* @since 2.0.0
* @return array
*/
abstract public function get_sections(); // end get_sections;
} // end class Wizard_Admin_Page;
abstract public function get_sections();
}

View File

@ -12,7 +12,7 @@ namespace WP_Ultimo\Admin_Pages\Customer_Panel;
// Exit if accessed directly
defined('ABSPATH') || exit;
use \WP_Ultimo\Admin_Pages\Base_Customer_Facing_Admin_Page;
use WP_Ultimo\Admin_Pages\Base_Customer_Facing_Admin_Page;
/**
* WP Multisite WaaS My_Account Admin Page.
@ -103,12 +103,9 @@ class Account_Admin_Page extends Base_Customer_Facing_Admin_Page {
$this->register_page_settings();
if ($this->current_site->get_type() === 'customer_owned') {
parent::__construct();
} // end if;
} // end __construct;
}
}
/**
* Loads the current site and membership.
@ -123,8 +120,7 @@ class Account_Admin_Page extends Base_Customer_Facing_Admin_Page {
$this->current_membership = $this->current_site->get_membership();
$this->add_notices();
} // end page_loaded;
}
/**
* Adds notices after a membership is changed.
@ -139,16 +135,13 @@ class Account_Admin_Page extends Base_Customer_Facing_Admin_Page {
$update_type = wu_request('updated');
if (empty($update_type)) {
return;
} // end if;
}
$update_message = apply_filters('wu_account_update_message', __('Your account was successfully updated.', 'wp-ultimo'), $update_type);
WP_Ultimo()->notices->add($update_message);
} // end add_notices;
}
/**
* Allow child classes to add hooks to be run once the page is loaded.
@ -157,7 +150,7 @@ class Account_Admin_Page extends Base_Customer_Facing_Admin_Page {
* @since 1.8.2
* @return void
*/
public function hooks() {} // end hooks;
public function hooks() {}
/**
* Allow child classes to add screen options; Useful for pages that have list tables.
@ -165,7 +158,7 @@ class Account_Admin_Page extends Base_Customer_Facing_Admin_Page {
* @since 1.8.2
* @return void
*/
public function screen_options() {} // end screen_options;
public function screen_options() {}
/**
* Allow child classes to register widgets, if they need them.
@ -194,8 +187,7 @@ class Account_Admin_Page extends Base_Customer_Facing_Admin_Page {
\WP_Ultimo\UI\Simple_Text_Element::get_instance()->as_inline_content(get_current_screen()->id, 'wu_dash_before_metaboxes');
\WP_Ultimo\UI\Current_Site_Element::get_instance()->as_inline_content(get_current_screen()->id, 'wu_dash_before_metaboxes', array('show_admin_link' => false));
} // end register_widgets;
}
/**
* Returns the title of the page.
@ -206,8 +198,7 @@ class Account_Admin_Page extends Base_Customer_Facing_Admin_Page {
public function get_title() {
return __('Account', 'wp-ultimo');
} // end get_title;
}
/**
* Returns the title of menu for this page.
@ -218,8 +209,7 @@ class Account_Admin_Page extends Base_Customer_Facing_Admin_Page {
public function get_menu_title() {
return __('Account', 'wp-ultimo');
} // end get_menu_title;
}
/**
* Allows admins to rename the sub-menu (first item) for a top-level page.
@ -230,8 +220,7 @@ class Account_Admin_Page extends Base_Customer_Facing_Admin_Page {
public function get_submenu_title() {
return __('Account', 'wp-ultimo');
} // end get_submenu_title;
}
/**
* Every child class should implement the output method to display the contents of the page.
@ -243,12 +232,13 @@ class Account_Admin_Page extends Base_Customer_Facing_Admin_Page {
/*
* Renders the base edit page layout, with the columns and everything else =)
*/
wu_get_template('base/dash', array(
wu_get_template(
'base/dash',
array(
'screen' => get_current_screen(),
'page' => $this,
'has_full_position' => false,
));
} // end output;
} // end class Account_Admin_Page;
)
);
}
}

View File

@ -12,7 +12,7 @@ namespace WP_Ultimo\Admin_Pages\Customer_Panel;
// Exit if accessed directly
defined('ABSPATH') || exit;
use \WP_Ultimo\Admin_Pages\Base_Customer_Facing_Admin_Page;
use WP_Ultimo\Admin_Pages\Base_Customer_Facing_Admin_Page;
/**
* WP Multisite WaaS Add New Site Admin Page.
@ -127,12 +127,9 @@ class Add_New_Site_Admin_Page extends Base_Customer_Facing_Admin_Page {
$this->register_page_settings();
if ($this->current_site->get_type() === 'customer_owned') {
parent::__construct();
} // end if;
} // end __construct;
}
}
/**
* Loads the current site and membership.
@ -143,8 +140,7 @@ class Add_New_Site_Admin_Page extends Base_Customer_Facing_Admin_Page {
public function page_loaded() {
$this->customer = wu_get_current_customer();
} // end page_loaded;
}
/**
* Allow child classes to add hooks to be run once the page is loaded.
@ -153,7 +149,7 @@ class Add_New_Site_Admin_Page extends Base_Customer_Facing_Admin_Page {
* @since 1.8.2
* @return void
*/
public function hooks() {} // end hooks;
public function hooks() {}
/**
* Force the screen options so our customize options show up.
@ -164,18 +160,18 @@ class Add_New_Site_Admin_Page extends Base_Customer_Facing_Admin_Page {
public function force_screen_options() {
if (get_current_screen()->id !== 'toplevel_page_sites') {
return;
} // end if;
}
// Forces Screen options so we can add our links.
add_screen_option('wu_fix', array(
add_screen_option(
'wu_fix',
array(
'option' => 'test',
'value' => true,
));
} // end force_screen_options;
)
);
}
/**
* Allow child classes to add screen options; Useful for pages that have list tables.
@ -183,7 +179,7 @@ class Add_New_Site_Admin_Page extends Base_Customer_Facing_Admin_Page {
* @since 1.8.2
* @return void
*/
public function screen_options() {} // end screen_options;
public function screen_options() {}
/**
* Allow child classes to register widgets, if they need them.
@ -195,12 +191,15 @@ class Add_New_Site_Admin_Page extends Base_Customer_Facing_Admin_Page {
\WP_Ultimo\UI\Simple_Text_Element::get_instance()->as_inline_content(get_current_screen()->id, 'wu_dash_before_metaboxes');
\WP_Ultimo\UI\Checkout_Element::get_instance()->as_inline_content(get_current_screen()->id, 'wu_dash_before_metaboxes', array(
\WP_Ultimo\UI\Checkout_Element::get_instance()->as_inline_content(
get_current_screen()->id,
'wu_dash_before_metaboxes',
array(
'slug' => 'wu-add-new-site',
'membership_limitations' => array('sites'),
));
} // end register_widgets;
)
);
}
/**
* Returns the title of the page.
@ -211,8 +210,7 @@ class Add_New_Site_Admin_Page extends Base_Customer_Facing_Admin_Page {
public function get_title() {
return __('Add New Site', 'wp-ultimo');
} // end get_title;
}
/**
* Returns the title of menu for this page.
@ -223,8 +221,7 @@ class Add_New_Site_Admin_Page extends Base_Customer_Facing_Admin_Page {
public function get_menu_title() {
return __('Add New Site', 'wp-ultimo');
} // end get_menu_title;
}
/**
* Allows admins to rename the sub-menu (first item) for a top-level page.
@ -235,8 +232,7 @@ class Add_New_Site_Admin_Page extends Base_Customer_Facing_Admin_Page {
public function get_submenu_title() {
return __('Add New Site', 'wp-ultimo');
} // end get_submenu_title;
}
/**
* Every child class should implement the output method to display the contents of the page.
@ -248,12 +244,13 @@ class Add_New_Site_Admin_Page extends Base_Customer_Facing_Admin_Page {
/*
* Renders the base edit page layout, with the columns and everything else =)
*/
wu_get_template('base/dash', array(
wu_get_template(
'base/dash',
array(
'screen' => get_current_screen(),
'page' => $this,
'has_full_position' => false,
));
} // end output;
} // end class Add_New_Site_Admin_Page;
)
);
}
}

View File

@ -96,8 +96,7 @@ class Checkout_Admin_Page extends \WP_Ultimo\Admin_Pages\Base_Customer_Facing_Ad
public function get_title() {
return sprintf(__('Checkout', 'wp-ultimo'));
} // end get_title;
}
/**
* Returns the title of menu for this page.
@ -108,8 +107,7 @@ class Checkout_Admin_Page extends \WP_Ultimo\Admin_Pages\Base_Customer_Facing_Ad
public function get_menu_title() {
return __('Checkout', 'wp-ultimo');
} // end get_menu_title;
}
/**
* Registers the necessary scripts.
@ -120,8 +118,7 @@ class Checkout_Admin_Page extends \WP_Ultimo\Admin_Pages\Base_Customer_Facing_Ad
public function register_scripts() {
do_action('wu_checkout_scripts', null, null);
} // end register_scripts;
}
/**
* Overrides the page loaded method.
@ -134,8 +131,7 @@ class Checkout_Admin_Page extends \WP_Ultimo\Admin_Pages\Base_Customer_Facing_Ad
do_action('wu_setup_checkout', null);
parent::page_loaded();
} // end page_loaded;
}
/**
* Returns the sections for this Wizard.
@ -153,8 +149,7 @@ class Checkout_Admin_Page extends \WP_Ultimo\Admin_Pages\Base_Customer_Facing_Ad
);
return $sections;
} // end get_sections;
}
/**
* Displays the content of the activation section.
@ -166,13 +161,15 @@ class Checkout_Admin_Page extends \WP_Ultimo\Admin_Pages\Base_Customer_Facing_Ad
/*
* Renders the base edit page layout, with the columns and everything else =)
*/
wu_get_template('base/centered', array(
wu_get_template(
'base/centered',
array(
'screen' => get_current_screen(),
'page' => $this,
'content' => do_shortcode('[wu_checkout slug="wu-checkout"]'),
));
} // end output;
)
);
}
/**
* Allow child classes to register widgets, if they need them.
@ -185,7 +182,5 @@ class Checkout_Admin_Page extends \WP_Ultimo\Admin_Pages\Base_Customer_Facing_Ad
\WP_Ultimo\UI\Current_Membership_Element::get_instance()->as_metabox(get_current_screen()->id);
\WP_Ultimo\UI\Simple_Text_Element::get_instance()->as_inline_content(get_current_screen()->id, 'wu_centered_right');
} // end register_widgets;
} // end class Checkout_Admin_Page;
}
}

View File

@ -12,7 +12,7 @@ namespace WP_Ultimo\Admin_Pages\Customer_Panel;
// Exit if accessed directly
defined('ABSPATH') || exit;
use \WP_Ultimo\Admin_Pages\Base_Customer_Facing_Admin_Page;
use WP_Ultimo\Admin_Pages\Base_Customer_Facing_Admin_Page;
/**
* WP Multisite WaaS My Sites Admin Page.
@ -111,7 +111,6 @@ class My_Sites_Admin_Page extends Base_Customer_Facing_Admin_Page {
$this->register_page_settings();
if ($this->current_site->get_type() === 'customer_owned') {
parent::__construct();
add_action('admin_menu', array($this, 'unset_default_my_sites_menu'));
@ -119,10 +118,8 @@ class My_Sites_Admin_Page extends Base_Customer_Facing_Admin_Page {
add_action('admin_bar_menu', array($this, 'change_my_sites_link'), 90);
add_action('current_screen', array($this, 'force_screen_options'));
} // end if;
} // end __construct;
}
}
/**
* Loads the current site and membership.
@ -133,8 +130,7 @@ class My_Sites_Admin_Page extends Base_Customer_Facing_Admin_Page {
public function page_loaded() {
$this->customer = wu_get_current_customer();
} // end page_loaded;
}
/**
* Allow child classes to add hooks to be run once the page is loaded.
@ -143,7 +139,7 @@ class My_Sites_Admin_Page extends Base_Customer_Facing_Admin_Page {
* @since 1.8.2
* @return void
*/
public function hooks() {} // end hooks;
public function hooks() {}
/**
* Remove the default my sites link.
@ -156,8 +152,7 @@ class My_Sites_Admin_Page extends Base_Customer_Facing_Admin_Page {
global $submenu;
unset($submenu['index.php'][5]);
} // end unset_default_my_sites_menu;
}
/**
* Update the my sites link on the top-bar.
@ -172,10 +167,8 @@ class My_Sites_Admin_Page extends Base_Customer_Facing_Admin_Page {
$my_sites = $wp_admin_bar->get_node('my-sites');
if (empty($my_sites)) {
return;
} // end if;
}
$args = array(
'page' => 'sites',
@ -184,8 +177,7 @@ class My_Sites_Admin_Page extends Base_Customer_Facing_Admin_Page {
$my_sites->href = add_query_arg($args, admin_url('admin.php'));
$wp_admin_bar->add_node($my_sites);
} // end change_my_sites_link;
}
/**
* Force the screen options so our customize options show up.
@ -196,18 +188,18 @@ class My_Sites_Admin_Page extends Base_Customer_Facing_Admin_Page {
public function force_screen_options() {
if (get_current_screen()->id !== 'toplevel_page_sites') {
return;
} // end if;
}
// Forces Screen options so we can add our links.
add_screen_option('wu_fix', array(
add_screen_option(
'wu_fix',
array(
'option' => 'test',
'value' => true,
));
} // end force_screen_options;
)
);
}
/**
* Allow child classes to add screen options; Useful for pages that have list tables.
@ -215,7 +207,7 @@ class My_Sites_Admin_Page extends Base_Customer_Facing_Admin_Page {
* @since 1.8.2
* @return void
*/
public function screen_options() {} // end screen_options;
public function screen_options() {}
/**
* Allow child classes to register widgets, if they need them.
@ -230,8 +222,7 @@ class My_Sites_Admin_Page extends Base_Customer_Facing_Admin_Page {
\WP_Ultimo\UI\Simple_Text_Element::get_instance()->as_inline_content(get_current_screen()->id, 'wu_dash_before_metaboxes');
\WP_Ultimo\UI\My_Sites_Element::get_instance()->as_inline_content(get_current_screen()->id, 'wu_dash_before_metaboxes');
} // end register_widgets;
}
/**
* Returns the title of the page.
@ -242,8 +233,7 @@ class My_Sites_Admin_Page extends Base_Customer_Facing_Admin_Page {
public function get_title() {
return __('My Sites', 'wp-ultimo');
} // end get_title;
}
/**
* Returns the title of menu for this page.
@ -254,8 +244,7 @@ class My_Sites_Admin_Page extends Base_Customer_Facing_Admin_Page {
public function get_menu_title() {
return __('My Sites', 'wp-ultimo');
} // end get_menu_title;
}
/**
* Allows admins to rename the sub-menu (first item) for a top-level page.
@ -266,8 +255,7 @@ class My_Sites_Admin_Page extends Base_Customer_Facing_Admin_Page {
public function get_submenu_title() {
return __('My Sites', 'wp-ultimo');
} // end get_submenu_title;
}
/**
* Every child class should implement the output method to display the contents of the page.
@ -279,12 +267,13 @@ class My_Sites_Admin_Page extends Base_Customer_Facing_Admin_Page {
/*
* Renders the base edit page layout, with the columns and everything else =)
*/
wu_get_template('base/dash', array(
wu_get_template(
'base/dash',
array(
'screen' => get_current_screen(),
'page' => $this,
'has_full_position' => false,
));
} // end output;
} // end class My_Sites_Admin_Page;
)
);
}
}

View File

@ -104,8 +104,7 @@ class Template_Switching_Admin_Page extends \WP_Ultimo\Admin_Pages\Base_Customer
public function get_title() {
return __('Switch Template', 'wp-ultimo');
} // end get_title;
}
/**
* Returns the title of menu for this page.
@ -116,8 +115,7 @@ class Template_Switching_Admin_Page extends \WP_Ultimo\Admin_Pages\Base_Customer
public function get_menu_title() {
return __('Switch Template', 'wp-ultimo');
} // end get_menu_title;
}
/**
* Registers the necessary scripts.
@ -128,8 +126,7 @@ class Template_Switching_Admin_Page extends \WP_Ultimo\Admin_Pages\Base_Customer
public function register_scripts() {
do_action('wu_template_switching_admin_page_scripts', null, null);
} // end register_scripts;
}
/**
* Overrides the page loaded method.
@ -142,8 +139,7 @@ class Template_Switching_Admin_Page extends \WP_Ultimo\Admin_Pages\Base_Customer
do_action('wu_template_switching_admin_page', null);
parent::page_loaded();
} // end page_loaded;
}
/**
* Displays the content of the activation section.
@ -155,16 +151,18 @@ class Template_Switching_Admin_Page extends \WP_Ultimo\Admin_Pages\Base_Customer
/*
* Renders the base edit page layout, with the columns and everything else =)
*/
wu_get_template('base/centered', array(
wu_get_template(
'base/centered',
array(
'screen' => get_current_screen(),
'page' => $this,
'content' => '',
'labels' => array(
'updated_message' => __('Template switched successfully!', 'wp-ultimo')
'updated_message' => __('Template switched successfully!', 'wp-ultimo'),
),
)
));
} // end output;
);
}
/**
* Allow child classes to register widgets, if they need them.
@ -175,7 +173,5 @@ class Template_Switching_Admin_Page extends \WP_Ultimo\Admin_Pages\Base_Customer
public function register_widgets() {
\WP_Ultimo\UI\Template_Switching_Element::get_instance()->as_metabox(get_current_screen()->id);
} // end register_widgets;
} // end class Template_Switching_Admin_Page;
}
}

View File

@ -89,8 +89,7 @@ class Debug_Admin_Page extends Base_Admin_Page {
'normal',
null
);
} // end register_widgets;
}
/**
* Renders the list of WP Multisite WaaS registered pages.
@ -105,18 +104,19 @@ class Debug_Admin_Page extends Base_Admin_Page {
echo '<ul class="wu-flex wu-flex-wrap wu--mx-1">';
foreach ($pages as $page_id => $url) {
echo sprintf('
printf(
'
<li class="wu-w-1/2 wu-box-border">
<a class="wu-mx-1 wu-block wu-p-2 wu-box-border wu-border wu-border-gray-400 wu-border-solid wu-rounded" href="%s">%s</a>
</li>
', $url, $page_id);
} // end foreach;
',
$url,
$page_id
);
}
echo '</ul>';
} // end render_debug_pages;
}
/**
* Returns the title of the page.
@ -127,8 +127,7 @@ class Debug_Admin_Page extends Base_Admin_Page {
public function get_title() {
return __('Registered Pages', 'wp-ultimo');
} // end get_title;
}
/**
* Returns the title of menu for this page.
@ -139,8 +138,7 @@ class Debug_Admin_Page extends Base_Admin_Page {
public function get_menu_title() {
return __('Registered Pages', 'wp-ultimo');
} // end get_menu_title;
}
/**
* Allows admins to rename the sub-menu (first item) for a top-level page.
@ -151,8 +149,7 @@ class Debug_Admin_Page extends Base_Admin_Page {
public function get_submenu_title() {
return __('Registered Pages', 'wp-ultimo');
} // end get_submenu_title;
}
/**
* Every child class should implement the output method to display the contents of the page.
@ -162,12 +159,13 @@ class Debug_Admin_Page extends Base_Admin_Page {
*/
public function output() {
wu_get_template('base/dash', array(
wu_get_template(
'base/dash',
array(
'page' => $this,
'screen' => get_current_screen(),
'has_full_position' => false,
));
} // end output;
} // end class Debug_Admin_Page;
)
);
}
}

View File

@ -9,11 +9,11 @@
namespace WP_Ultimo\API;
use \WP_Ultimo\Checkout\Cart;
use \WP_Ultimo\Database\Sites\Site_Type;
use \WP_Ultimo\Database\Payments\Payment_Status;
use \WP_Ultimo\Database\Memberships\Membership_Status;
use \WP_Ultimo\Objects\Billing_Address;
use WP_Ultimo\Checkout\Cart;
use WP_Ultimo\Database\Sites\Site_Type;
use WP_Ultimo\Database\Payments\Payment_Status;
use WP_Ultimo\Database\Memberships\Membership_Status;
use WP_Ultimo\Objects\Billing_Address;
// Exit if accessed directly
defined('ABSPATH') || exit;
@ -36,8 +36,7 @@ class Register_Endpoint {
public function init() {
add_action('wu_register_rest_routes', array($this, 'register_route'));
} // end init;
}
/**
* Adds a new route to the wu namespace, for the register endpoint.
@ -51,20 +50,27 @@ class Register_Endpoint {
$namespace = $api->get_namespace();
register_rest_route($namespace, '/register', array(
register_rest_route(
$namespace,
'/register',
array(
'methods' => \WP_REST_Server::READABLE,
'callback' => array($this, 'handle_get'),
'permission_callback' => \Closure::fromCallable([$api, 'check_authorization']),
));
'permission_callback' => \Closure::fromCallable(array($api, 'check_authorization')),
)
);
register_rest_route($namespace, '/register', array(
register_rest_route(
$namespace,
'/register',
array(
'methods' => \WP_REST_Server::CREATABLE,
'callback' => array($this, 'handle_endpoint'),
'permission_callback' => \Closure::fromCallable([$api, 'check_authorization']),
'permission_callback' => \Closure::fromCallable(array($api, 'check_authorization')),
'args' => $this->get_rest_args(),
));
} // end register_route;
)
);
}
/**
* Handle the register endpoint get for zapier integration reasons.
@ -79,8 +85,7 @@ class Register_Endpoint {
return array(
'registration_status' => wu_get_setting('enable_registration', true) ? 'open' : 'closed',
);
} // end handle_get;
}
/**
* Handle the register endpoint logic.
@ -97,60 +102,63 @@ class Register_Endpoint {
$params = json_decode($request->get_body(), true);
if (\WP_Ultimo\API::get_instance()->should_log_api_calls()) {
wu_log_add('api-calls', json_encode($params, JSON_PRETTY_PRINT));
} // end if;
}
$validation_errors = $this->validate($params);
if (is_wp_error($validation_errors)) {
$validation_errors->add_data(array(
$validation_errors->add_data(
array(
'status' => 400,
));
)
);
return $validation_errors;
} // end if;
}
$wpdb->query('START TRANSACTION');
try {
$customer = $this->maybe_create_customer($params);
if (is_wp_error($customer)) {
return $this->rollback_and_return($customer);
} // end if;
}
$customer->update_last_login(true, true);
$customer->add_note(array(
$customer->add_note(
array(
'text' => __('Created via REST API', 'wp-ultimo'),
'author_id' => $customer->get_user_id(),
));
)
);
/*
* Payment Method defaults
*/
$payment_method = wp_parse_args(wu_get_isset($params, 'payment_method'), array(
$payment_method = wp_parse_args(
wu_get_isset($params, 'payment_method'),
array(
'gateway' => '',
'gateway_customer_id' => '',
'gateway_subscription_id' => '',
'gateway_payment_id' => '',
));
)
);
/*
* Cart params and creation
*/
$cart_params = $params;
$cart_params = wp_parse_args($cart_params, array(
$cart_params = wp_parse_args(
$cart_params,
array(
'type' => 'new',
));
)
);
$cart = new Cart($cart_params);
@ -158,21 +166,33 @@ class Register_Endpoint {
* Validates if the cart is valid.
*/
if ($cart->is_valid() && count($cart->get_line_items()) === 0) {
return new \WP_Error('invalid_cart', __('Products are required.', 'wp-ultimo'), array_merge((array) $cart->done(), array(
return new \WP_Error(
'invalid_cart',
__('Products are required.', 'wp-ultimo'),
array_merge(
(array) $cart->done(),
array(
'status' => 400,
)));
} // end if;
)
)
);
}
/*
* Get Membership data
*/
$membership_data = $cart->to_membership_data();
$membership_data = array_merge($membership_data, wu_get_isset($params, 'membership', array(
$membership_data = array_merge(
$membership_data,
wu_get_isset(
$params,
'membership',
array(
'status' => Membership_Status::PENDING,
)));
)
)
);
$membership_data['customer_id'] = $customer->get_id();
$membership_data['gateway'] = wu_get_isset($payment_method, 'gateway');
@ -190,21 +210,28 @@ class Register_Endpoint {
$membership = wu_create_membership($membership_data);
if (is_wp_error($membership)) {
return $this->rollback_and_return($membership);
}
} // end if;
$membership->add_note(array(
$membership->add_note(
array(
'text' => __('Created via REST API', 'wp-ultimo'),
'author_id' => $customer->get_user_id(),
));
)
);
$payment_data = $cart->to_payment_data();
$payment_data = array_merge($payment_data, wu_get_isset($params, 'payment', array(
$payment_data = array_merge(
$payment_data,
wu_get_isset(
$params,
'payment',
array(
'status' => Payment_Status::PENDING,
)));
)
)
);
/*
* Unset the status because we are going to transition it later.
@ -221,15 +248,15 @@ class Register_Endpoint {
$payment = wu_create_payment($payment_data);
if (is_wp_error($payment)) {
return $this->rollback_and_return($payment);
}
} // end if;
$payment->add_note(array(
$payment->add_note(
array(
'text' => __('Created via REST API', 'wp-ultimo'),
'author_id' => $customer->get_user_id(),
));
)
);
$site = false;
@ -237,22 +264,17 @@ class Register_Endpoint {
* Site creation.
*/
if (wu_get_isset($params, 'site')) {
$site = $this->maybe_create_site($params, $membership);
if (is_wp_error($site)) {
return $this->rollback_and_return($site);
} // end if;
} // end if;
}
}
/*
* Deal with status changes.
*/
if ($membership_status !== $membership->get_status()) {
$membership->set_status($membership_status);
$membership->save();
@ -263,34 +285,24 @@ class Register_Endpoint {
* again, this time as a WU Site object.
*/
if ($site) {
$wp_site = get_site_by_path($site['domain'], $site['path']);
if ($wp_site) {
$site['id'] = $wp_site->blog_id;
} // end if;
} // end if;
} // end if;
}
}
}
if ($payment_status !== $payment->get_status()) {
$payment->set_status($payment_status);
$payment->save();
} // end if;
}
} catch (\Throwable $e) {
$wpdb->query('ROLLBACK');
return new \WP_Error('registration_error', $e->getMessage(), array('status' => 500));
} // end try;
}
$wpdb->query('COMMIT');
@ -303,8 +315,7 @@ class Register_Endpoint {
'payment' => $payment->to_array(),
'site' => $site ? $site : array('id' => 0),
);
} // end handle_endpoint;
}
/**
* Returns the list of arguments allowed on to the endpoint.
@ -351,7 +362,7 @@ class Register_Endpoint {
'billing_address' => array(
'type' => 'object',
'properties' => $billing_address_fields,
)
),
),
),
);
@ -521,8 +532,7 @@ class Register_Endpoint {
$args = array_merge($customer_args, $membership_args, $cart_args, $payment_args, $site_args);
return apply_filters('wu_rest_register_endpoint_args', $args, $this);
} // end get_rest_args;
}
/**
* Maybe create a customer, if needed.
*
@ -536,24 +546,17 @@ class Register_Endpoint {
$customer_id = wu_get_isset($p, 'customer_id');
if ($customer_id) {
$customer = wu_get_customer($customer_id);
if ( ! $customer) {
return new \WP_Error('customer_not_found', __('The customer id sent does not correspond to a valid customer.', 'wp-ultimo'));
} // end if;
}
} else {
$customer = wu_create_customer($p['customer']);
} // end if;
}
return $customer;
} // end maybe_create_customer;
}
/**
* Undocumented function
@ -592,8 +595,7 @@ class Register_Endpoint {
* one site here, it's ok. for now.
*/
return current($sites);
} // end if;
}
$site_url = wu_get_isset($site_data, 'site_url');
@ -605,10 +607,8 @@ class Register_Endpoint {
$results = wpmu_validate_blog_signup($site_url, wu_get_isset($site_data, 'site_title'), $membership->get_customer()->get_user());
if ($results['errors']->has_errors()) {
return $results['errors'];
} // end if;
}
/*
* Get the transient data to save with the site
@ -640,22 +640,17 @@ class Register_Endpoint {
$site_data['id'] = 0;
if (wu_get_isset($site_data, 'publish')) {
$membership->publish_pending_site();
$wp_site = get_site_by_path($site_data['domain'], $site_data['path']);
if ($wp_site) {
$site_data['id'] = $wp_site->blog_id;
} // end if;
} // end if;
}
}
return $site_data;
} // end maybe_create_site;
}
/**
* Set the validation rules for this particular model.
@ -679,8 +674,7 @@ class Register_Endpoint {
'site.site_url' => 'required_with:site|alpha_num|min:4|lowercase|unique_site',
'site.site_title' => 'required_with:site|min:4',
);
} // end validation_rules;
}
/**
* Validates the rules and make sure we only save models when necessary.
*
@ -690,19 +684,16 @@ class Register_Endpoint {
*/
public function validate($args) {
$validator = new \WP_Ultimo\Helpers\Validator;
$validator = new \WP_Ultimo\Helpers\Validator();
$validator->validate($args, $this->validation_rules());
if ($validator->fails()) {
return $validator->get_errors();
} // end if;
}
return true;
} // end validate;
}
/**
* Rolls back database changes and returns the error passed.
@ -719,7 +710,5 @@ class Register_Endpoint {
$wpdb->query('ROLLBACK');
return $error;
} // end rollback_and_return;
} // end class Register_Endpoint;
}
}

View File

@ -46,8 +46,7 @@ trait Rest_Api {
public function get_rest_base() {
return (! empty($this->rest_base)) ? $this->rest_base : $this->slug;
} // end get_rest_base;
}
/**
* Registers the routes. Should be called by the entity
@ -60,14 +59,11 @@ trait Rest_Api {
$is_enabled = \WP_Ultimo\API::get_instance()->is_api_enabled();
if ($is_enabled) {
add_action('rest_api_init', array($this, 'register_routes_general'));
add_action('rest_api_init', array($this, 'register_routes_with_id'));
} // end if;
} // end enable_rest_api;
}
}
/**
* Register the endpoints that don't need an ID,
@ -80,7 +76,6 @@ trait Rest_Api {
$routes = array();
if (in_array('get_items', $this->enabled_rest_endpoints, true)) {
$routes = array(
array(
'methods' => \WP_REST_Server::READABLE,
@ -88,34 +83,28 @@ trait Rest_Api {
'permission_callback' => array($this, 'get_items_permissions_check'),
),
);
} // end if;
}
if (in_array('create_item', $this->enabled_rest_endpoints, true)) {
$routes[] = array(
'methods' => \WP_REST_Server::CREATABLE,
'callback' => array($this, 'create_item_rest'),
'permission_callback' => array($this, 'create_item_permissions_check'),
'args' => $this->get_arguments_schema()
'args' => $this->get_arguments_schema(),
);
} // end if;
}
if ( ! empty($routes)) {
register_rest_route(
\WP_Ultimo\API::get_instance()->get_namespace(),
'/' . $this->get_rest_base(),
$routes,
true
);
} // end if;
}
do_action('wu_rest_register_routes_general', $routes, $this->get_rest_base(), 'create', $this);
} // end register_routes_general;
}
/**
* Register the endpoints that need an ID,
@ -128,50 +117,41 @@ trait Rest_Api {
$routes = array();
if (in_array('get_item', $this->enabled_rest_endpoints, true)) {
$routes[] = array(
'methods' => \WP_REST_Server::READABLE,
'callback' => array($this, 'get_item_rest'),
'permission_callback' => array($this, 'get_item_permissions_check'),
);
} // end if;
}
if (in_array('update_item', $this->enabled_rest_endpoints, true)) {
$routes[] = array(
'methods' => \WP_REST_Server::EDITABLE,
'callback' => array($this, 'update_item_rest'),
'permission_callback' => array($this, 'update_item_permissions_check'),
'args' => $this->get_arguments_schema(true)
'args' => $this->get_arguments_schema(true),
);
} // end if;
}
if (in_array('delete_item', $this->enabled_rest_endpoints, true)) {
$routes[] = array(
'methods' => \WP_REST_Server::DELETABLE,
'callback' => array($this, 'delete_item_rest'),
'permission_callback' => array($this, 'delete_item_permissions_check'),
);
} // end if;
}
if ( ! empty($routes)) {
register_rest_route(
\WP_Ultimo\API::get_instance()->get_namespace(),
'/' . $this->get_rest_base() . '/(?P<id>[\d]+)',
$routes,
true
);
} // end if;
}
do_action('wu_rest_register_routes_with_id', $routes, $this->get_rest_base(), 'update', $this);
} // end register_routes_with_id;
}
/**
* Returns a specific item.
*
@ -185,14 +165,11 @@ trait Rest_Api {
$item = $this->model_class::get_by_id($request['id']);
if (empty($item)) {
return new \WP_Error("wu_rest_{$this->slug}_invalid_id", __('Item not found.', 'wp-ultimo'), array('status' => 404));
} // end if;
}
return rest_ensure_response($item);
} // end get_item_rest;
}
/**
* Returns a list of items.
*
@ -206,8 +183,7 @@ trait Rest_Api {
$items = $this->model_class::query($request->get_params());
return rest_ensure_response($items);
} // end get_items_rest;
}
/**
* Creates an item.
*
@ -225,34 +201,25 @@ trait Rest_Api {
$saver_function = "wu_create_{$model_name}";
if (function_exists($saver_function)) {
$item = call_user_func($saver_function, $body);
$saved = is_wp_error($item) ? $item : true;
} else {
$item = new $this->model_class($body);
$saved = $item->save();
} // end if;
}
if (is_wp_error($saved)) {
return rest_ensure_response($saved);
} // end if;
}
if ( ! $saved) {
return new \WP_Error("wu_rest_{$this->slug}", __('Something went wrong (Code 1).', 'wp-ultimo'), array('status' => 400));
} // end if;
}
return rest_ensure_response($item);
} // end create_item_rest;
}
/**
* Updates an item.
*
@ -268,10 +235,8 @@ trait Rest_Api {
$item = $this->model_class::get_by_id($id);
if (empty($item)) {
return new \WP_Error("wu_rest_{$this->slug}_invalid_id", __('Item not found.', 'wp-ultimo'), array('status' => 404));
} // end if;
}
$params = array_filter(
json_decode($request->get_body(), true),
@ -280,19 +245,13 @@ trait Rest_Api {
);
foreach ($params as $param => $value) {
$set_method = "set_{$param}";
if ($param === 'meta') {
$item->update_meta_batch($value);
} elseif (method_exists($item, $set_method)) {
call_user_func(array($item, $set_method), $value);
} else {
$error_message = sprintf(
/* translators: 1. Object class name; 2. Set method name */
__('The %1$s object does not have a %2$s method', 'wp-ultimo'),
@ -305,28 +264,21 @@ trait Rest_Api {
$error_message,
array('status' => 400)
);
} // end if;
} // end foreach;
}
}
$saved = $item->save();
if (is_wp_error($saved)) {
return rest_ensure_response($saved);
} // end if;
}
if ( ! $saved) {
return new \WP_Error("wu_rest_{$this->slug}", __('Something went wrong (Code 2).', 'wp-ultimo'));
} // end if;
}
return rest_ensure_response($item);
} // end update_item_rest;
}
/**
* Deletes an item.
*
@ -340,16 +292,13 @@ trait Rest_Api {
$item = $this->model_class::get_by_id($request['id']);
if (empty($item)) {
return new \WP_Error("wu_rest_{$this->slug}_invalid_id", __('Item not found.', 'wp-ultimo'), array('status' => 404));
} // end if;
}
$result = $item->delete();
return rest_ensure_response($result);
} // end delete_item_rest;
}
/**
* Check permissions to list items.
@ -362,10 +311,8 @@ trait Rest_Api {
public function get_items_permissions_check($request) {
if ( ! \WP_Ultimo\API::get_instance()->check_authorization($request)) {
return false;
} // end if;
}
/**
* Filters if it is allowed to proceed with the request or not.
@ -377,8 +324,7 @@ trait Rest_Api {
* @param Base_Manager $this The object instance.
*/
return apply_filters('wu_rest_get_items', true, $this->get_rest_base(), $this);
} // end get_items_permissions_check;
}
/**
* Check permissions to create an item.
@ -391,10 +337,8 @@ trait Rest_Api {
public function create_item_permissions_check($request) {
if ( ! \WP_Ultimo\API::get_instance()->check_authorization($request)) {
return false;
} // end if;
}
/**
* Filters if it is allowed to proceed with the request or not.
@ -406,8 +350,7 @@ trait Rest_Api {
* @param Base_Manager $this The object instance.
*/
return apply_filters('wu_rest_create_item', true, $this->get_rest_base(), $this);
} // end create_item_permissions_check;
}
/**
* Check permissions to get an item.
@ -420,10 +363,8 @@ trait Rest_Api {
public function get_item_permissions_check($request) {
if ( ! \WP_Ultimo\API::get_instance()->check_authorization($request)) {
return false;
} // end if;
}
/**
* Filters if it is allowed to proceed with the request or not.
@ -435,8 +376,7 @@ trait Rest_Api {
* @param Base_Manager $this The object instance.
*/
return apply_filters('wu_rest_get_item', true, $this->get_rest_base(), $this);
} // end get_item_permissions_check;
}
/**
* Check permissions to update an item.
@ -449,10 +389,8 @@ trait Rest_Api {
public function update_item_permissions_check($request) {
if ( ! \WP_Ultimo\API::get_instance()->check_authorization($request)) {
return false;
} // end if;
}
/**
* Filters if it is allowed to proceed with the request or not.
@ -464,8 +402,7 @@ trait Rest_Api {
* @param Base_Manager $this The object instance.
*/
return apply_filters('wu_rest_update_item', true, $this->get_rest_base(), $this);
} // end update_item_permissions_check;
}
/**
* Check permissions to delete an item.
@ -478,10 +415,8 @@ trait Rest_Api {
public function delete_item_permissions_check($request) {
if ( ! \WP_Ultimo\API::get_instance()->check_authorization($request)) {
return false;
} // end if;
}
/**
* Filters if it is allowed to proceed with the request or not.
@ -493,8 +428,7 @@ trait Rest_Api {
* @param Base_Manager $this The object instance.
*/
return apply_filters('wu_rest_delete_item', true, $this->get_rest_base(), $this);
} // end delete_item_permissions_check;
}
/**
* Checks if a value is not a credential key.
@ -514,8 +448,7 @@ trait Rest_Api {
);
return ! in_array($value, $credentials_keys, true);
} // end is_not_credential_key;
}
/**
* Checks if a value is not equal to "id".
@ -532,17 +465,14 @@ trait Rest_Api {
);
if ($this->slug === 'site') {
$arr = array(
'id',
'blog_id',
);
} // end if;
}
return ! in_array($value, $arr, true);
} // end is_not_id_key;
}
/**
* Get the arguments for an endpoint
@ -559,8 +489,7 @@ trait Rest_Api {
$args = array_filter($schema, array($this, 'is_not_id_key'), ARRAY_FILTER_USE_KEY);
return $this->filter_schema_arguments($args);
} // end get_arguments_schema;
}
/**
* Remove some properties from the API schema.
@ -583,102 +512,78 @@ trait Rest_Api {
apply_filters('wu_before_' . $this->slug . '_api_arguments', $args, $this);
if ($this->slug !== 'broadcast' && isset($args['author_id'])) {
unset($args['author_id']);
} // end if;
}
if (isset($args['list_order'])) {
unset($args['list_order']);
}
} // end if;
$remove_status = apply_filters("wu_api_{$this->slug}_remove_status", array(
$remove_status = apply_filters(
"wu_api_{$this->slug}_remove_status",
array(
'broadcast',
'membership',
'product',
'payment',
));
)
);
if ( ! in_array($this->slug, $remove_status, true) && isset($args['status'])) {
unset($args['status']);
}
} // end if;
$remove_slug = apply_filters("wu_api_{$this->slug}_remove_slug", array(
$remove_slug = apply_filters(
"wu_api_{$this->slug}_remove_slug",
array(
'broadcast',
'product',
'checkout_form',
'event',
));
)
);
if ( ! in_array($this->slug, $remove_slug, true) && isset($args['slug'])) {
unset($args['slug']);
} // end if;
}
if ($this->slug === 'product' && isset($args['price_variations'])) {
unset($args['price_variations']);
} // end if;
}
if ($this->slug === 'payment' && isset($args['line_items'])) {
unset($args['line_items']);
} // end if;
}
if ($this->slug === 'site') {
if (isset($args['duplication_arguments'])) {
unset($args['duplication_arguments']);
} // end if;
}
if (isset($args['transient'])) {
unset($args['transient']);
} // end if;
} // end if;
}
}
if ($this->slug === 'email') {
if (isset($args['status'])) {
unset($args['status']);
} // end if;
}
if (isset($args['email_schedule'])) {
unset($args['email_schedule']);
} // end if;
} // end if;
}
}
if ($this->slug === 'broadcast') {
if (isset($args['message_targets'])) {
unset($args['message_targets']);
} // end if;
} // end if;
}
}
if (isset($args['billing_address'])) {
unset($args['billing_address']);
} // end if;
}
/**
* Filter after being changed.
@ -691,7 +596,5 @@ trait Rest_Api {
apply_filters('wu_after_' . $this->slug . '_api_arguments', $args, $this);
return $args;
} // end filter_schema_arguments;
} // end trait Rest_Api;
}
}

View File

@ -40,8 +40,7 @@ trait WP_CLI {
public function get_wp_cli_command_base() {
return (! empty($this->wp_cli_command_base)) ? $this->wp_cli_command_base : $this->slug;
} // end get_wp_cli_command_base;
}
/**
* Registers the routes. Should be called by the entity
@ -52,17 +51,14 @@ trait WP_CLI {
public function enable_wp_cli() {
if ( ! defined('WP_CLI')) {
return;
} // end if;
}
$wp_cli_root = 'wu';
$this->set_wp_cli_enabled_sub_commands();
foreach ($this->wp_cli_enabled_sub_commands as $sub_command => $sub_command_data) {
\WP_CLI::add_command(
"{$wp_cli_root} {$this->get_wp_cli_command_base()} {$sub_command}",
$sub_command_data['callback'],
@ -70,10 +66,8 @@ trait WP_CLI {
'synopsis' => $sub_command_data['synopsis'],
)
);
} // end foreach;
} // end enable_wp_cli;
}
}
/**
* Set wP-CLI Sub-command enabled for this entity.
@ -105,34 +99,32 @@ trait WP_CLI {
/**
* Unset undesired Params.
*/
$params_to_remove = apply_filters('wu_cli_params_to_remove', array(
$params_to_remove = apply_filters(
'wu_cli_params_to_remove',
array(
'id',
'model',
));
)
);
$params = array_filter($params, fn($param) => ! in_array($param, $params_to_remove, true));
foreach ($sub_commands as $sub_command => &$sub_command_data) {
$sub_command_data['synopsis'] = array();
if (in_array($sub_command, array('get', 'update', 'delete'), true)) {
$sub_command_data['synopsis'][] = array(
'name' => 'id',
'type' => 'positional',
'description' => __('The id for the resource.', 'wp-ultimo'),
'optional' => false,
);
} // end if;
}
if (in_array($sub_command, array('list', 'update', 'create'), true)) {
$explanation_list = wu_rest_get_endpoint_schema($this->model_class, 'update');
foreach ($params as $name) {
$explanation = wu_get_isset($explanation_list, $name, array());
$type = wu_get_isset($explanation, 'type', 'assoc');
@ -147,30 +139,23 @@ trait WP_CLI {
$options = wu_get_isset($explanation, 'options', array());
if ($options) {
$field['options'] = $options;
} // end if;
}
$sub_command_data['synopsis'][] = $field;
} // end foreach;
} // end if;
}
}
if (in_array($sub_command, array('create', 'update'), true)) {
$sub_command_data['synopsis'][] = array(
'name' => 'porcelain',
'type' => 'flag',
'description' => __('Output just the id when the operation is successful.', 'wp-ultimo'),
'optional' => true,
);
} // end if;
}
if (in_array($sub_command, array('list', 'get'), true)) {
$sub_command_data['synopsis'][] = array(
'name' => 'format',
'type' => 'assoc',
@ -194,10 +179,8 @@ trait WP_CLI {
'optional' => true,
'options' => array_merge(array('id'), $params),
);
} // end if;
} // end foreach;
}
}
$this->wp_cli_enabled_sub_commands = $sub_commands;
@ -216,8 +199,7 @@ trait WP_CLI {
$this->get_wp_cli_command_base(),
$this
);
} // end set_wp_cli_enabled_sub_commands;
}
/**
* Allows the additional of additional parameters.
*
@ -228,8 +210,7 @@ trait WP_CLI {
$model = new $this->model_class();
return array_keys($model->to_array());
} // end wp_cli_extra_parameters;
}
/**
* Returns the list of default fields, based on the table schema.
@ -242,8 +223,7 @@ trait WP_CLI {
$schema = $this->model_class::get_schema();
return array_column($schema, 'name');
} // end wp_cli_get_fields;
}
/**
* Returns a specific item.
@ -258,18 +238,15 @@ trait WP_CLI {
$item = $this->model_class::get_by_id($args[0]);
if (empty($item)) {
\WP_CLI::error('Invalid ID.');
} // end if;
}
$fields = (! empty($array_assoc['fields'])) ? $array_assoc['fields'] : $this->wp_cli_get_fields();
$formatter = new \WP_CLI\Formatter($array_assoc, $fields);
$formatter->display_item($item->to_array());
} // end wp_cli_get_item;
}
/**
* Returns a list of items.
@ -290,8 +267,7 @@ trait WP_CLI {
$items = array_map(fn($item) => $item->to_array(), $items);
\WP_CLI\Utils\format_items($array_assoc['format'], $items, $fields);
} // end wp_cli_get_items;
}
/**
* Creates an item.
@ -308,28 +284,19 @@ trait WP_CLI {
$success = $item->save();
if ($success === true) {
$item_id = $item->get_id();
if ( ! empty($array_assoc['porcelain'])) {
\WP_CLI::line($item_id);
} else {
$message = sprintf('Item created with ID %d', $item_id);
\WP_CLI::success($message);
} // end if;
}
} else {
\WP_CLI::error($success);
} // end if;
} // end wp_cli_create_item;
}
}
/**
* Updates an item.
@ -344,37 +311,27 @@ trait WP_CLI {
$item = $this->model_class::get_by_id($args[0]);
if (empty($item)) {
\WP_CLI::error('Invalid ID.');
} // end if;
}
$porcelain = false;
if ( ! empty($array_assoc['porcelain'])) {
$porcelain = true;
unset($array_assoc['porcelain']);
} // end if;
}
$params = $array_assoc;
foreach ($params as $param => $value) {
$set_method = "set_{$param}";
if ($param === 'meta') {
$item->update_meta_batch($value);
} elseif (method_exists($item, $set_method)) {
call_user_func(array($item, $set_method), $value);
} else {
$error_message = sprintf(
/* translators: 1. Object class name; 2. Set method name */
__('The %1$s object does not have a %2$s method', 'wp-ultimo'),
@ -383,36 +340,25 @@ trait WP_CLI {
);
\WP_CLI::error($error_message);
} // end if;
} // end foreach;
}
}
$success = $item->save();
if ($success) {
$item_id = $item->get_id();
if ($porcelain) {
\WP_CLI::line($item_id);
} else {
$message = sprintf('Item updated with ID %d', $item_id);
\WP_CLI::success($message);
} // end if;
}
} else {
\WP_CLI::error('Unexpected error. The item was not updated.');
} // end if;
} // end wp_cli_update_item;
}
}
/**
* Deletes an item.
@ -426,23 +372,15 @@ trait WP_CLI {
$item = $this->model_class::get_by_id($args[0]);
if (empty($item)) {
\WP_CLI::error('Invalid ID.');
} // end if;
}
$success = $item->delete();
if (is_wp_error($success) || ! $success) {
\WP_CLI::error('Unexpected error. The item was not deleted.');
} else {
\WP_CLI::success('Item deleted.');
} // end if;
} // end wp_cli_delete_item;
} // end trait WP_CLI;
}
}
}

View File

@ -44,7 +44,7 @@
},
});
}); // end each;
});
function wu_fields_to_block_options(fields, props) {
@ -72,7 +72,7 @@
field_slug = _.first(_.keys(sub_fields));
} // end if;
}
const component = wu_get_field_component(field.type, field);
@ -80,7 +80,7 @@
field.required = {};
} // end if;
}
let should_display = true;
@ -113,7 +113,7 @@
},
}));
} // end if;
}
/*
* Handle header types differently
@ -126,7 +126,7 @@
new_panel = true;
} // end if;
}
if (new_panel) {
@ -141,7 +141,7 @@
first_panel = false;
} // end if;
}
current_panel = field;
@ -149,7 +149,7 @@
gt_fields = [];
} // end if;
}
});
@ -164,7 +164,7 @@
return el(InspectorControls, { key: 'wp-ultimo' }, gt_panels);
} // end wu_fields_to_block_options;
}
function wu_format_options(options) {
@ -205,7 +205,7 @@
component = NumberControl;
} // end if;
}
break;
@ -233,7 +233,7 @@
break;
} // end switch;
}
return component;

View File

@ -12,7 +12,7 @@ namespace WP_Ultimo\Builders\Block_Editor;
// Exit if accessed directly
defined('ABSPATH') || exit;
use \WP_Ultimo\Database\Sites\Site_Type;
use WP_Ultimo\Database\Sites\Site_Type;
/**
* Handles Block Editor Widget Support.
@ -32,16 +32,13 @@ class Block_Editor_Widget_Manager {
public function init() {
if (\WP_Ultimo\Compat\Gutenberg_Support::get_instance()->should_load()) {
add_action('wu_element_loaded', array($this, 'handle_element'));
add_action('init', array($this, 'register_scripts'));
add_action('wu_element_is_preview', array($this, 'is_block_preview'));
} // end if;
} // end init;
}
}
/**
* Adds the required scripts.
@ -56,8 +53,7 @@ class Block_Editor_Widget_Manager {
$blocks = apply_filters('wu_blocks', array());
wp_localize_script('wu-blocks', 'wu_blocks', $blocks);
} // end register_scripts;
}
/**
* Checks if we are inside a block preview render.
@ -69,14 +65,11 @@ class Block_Editor_Widget_Manager {
public function is_block_preview($is_preview) {
if (defined('REST_REQUEST') && true === REST_REQUEST && 'edit' === filter_input(INPUT_GET, 'context', FILTER_SANITIZE_STRING)) {
$is_preview = true;
} // end if;
}
return $is_preview;
} // end is_block_preview;
}
/**
* Gets called when a new element is registered
@ -89,16 +82,13 @@ class Block_Editor_Widget_Manager {
public function handle_element($element) {
if (wu_get_current_site()->get_type() === Site_Type::CUSTOMER_OWNED) {
return;
} // end if;
}
$this->register_block($element);
add_filter('wu_blocks', fn($blocks) => $this->load_block_settings($blocks, $element));
} // end handle_element;
}
/**
* Registers block with WordPress.
@ -111,20 +101,20 @@ class Block_Editor_Widget_Manager {
public function register_block($element) {
if (\WP_Block_Type_Registry::get_instance()->is_registered($element->get_id())) {
return;
} // end if;
}
$attributes = $this->get_attributes_from_fields($element);
register_block_type($element->get_id(), array(
register_block_type(
$element->get_id(),
array(
'attributes' => $attributes,
'editor_script' => 'wu-blocks',
'render_callback' => \Closure::fromCallable([$element, 'display']),
));
} // end register_block;
'render_callback' => \Closure::fromCallable(array($element, 'display')),
)
);
}
/**
* Consolidate field attributes that are callables for blocks.
@ -150,52 +140,36 @@ class Block_Editor_Widget_Manager {
* Discard fields that are notes and start with _
*/
if (in_array($field['type'], $fields_to_ignore, true) && strncmp($field_slug, '_', strlen('_')) === 0) {
unset($fields[ $field_slug ]);
} // end if;
}
/*
* Deal with the group type.
* On those, we need to loop the sub-fields.
*/
if ($field['type'] === 'group') {
foreach ($field['fields'] as &$sub_field) {
foreach ($sub_field as $sub_item => &$sub_value) {
if (in_array($sub_item, $callable_keys, true) && is_callable($sub_value)) {
$sub_value = call_user_func($sub_value);
} // end if;
} // end foreach;
} // end foreach;
} // end if;
}
}
}
}
/*
* Deal with the regular field types and its
* callables.
*/
foreach ($field as $item => &$value) {
if (in_array($item, $callable_keys, true) && is_callable($value)) {
$value = call_user_func($value);
} // end if;
} // end foreach;
} // end foreach;
}
}
}
return $fields;
} // end consolidate_callables;
}
/**
* Registers the block so WP Multisite WaaS can add it on the JS side.
@ -219,8 +193,7 @@ class Block_Editor_Widget_Manager {
);
return $blocks;
} // end load_block_settings;
}
/**
* Generates the list of attributes supported based on the fields.
@ -238,20 +211,15 @@ class Block_Editor_Widget_Manager {
$_fields = array();
foreach ($fields as $field_id => $field) {
$type = 'string';
if ($field['type'] === 'toggle') {
$type = 'boolean';
} // end if;
}
if ($field['type'] === 'number') {
$type = 'integer';
} // end if;
}
$default_value = wu_get_isset($defaults, $field_id, '');
@ -259,11 +227,8 @@ class Block_Editor_Widget_Manager {
'default' => wu_get_isset($field, 'value', $default_value),
'type' => $type,
);
} // end foreach;
}
return $_fields;
} // end get_attributes_from_fields;
} // end class Block_Editor_Widget_Manager;
}
}

File diff suppressed because it is too large Load Diff

View File

@ -38,16 +38,13 @@ class Checkout_Pages {
add_filter('lostpassword_redirect', array($this, 'filter_lost_password_redirect'));
if (is_main_site()) {
add_action('before_signup_header', array($this, 'redirect_to_registration_page'));
$use_custom_login = wu_get_setting('enable_custom_login_page', false);
if ( ! $use_custom_login) {
return;
} // end if;
}
add_filter('login_url', array($this, 'filter_login_url'), 10, 3);
@ -73,10 +70,8 @@ class Checkout_Pages {
add_action('post_submitbox_misc_actions', array($this, 'render_compat_mode_setting'));
add_action('save_post', array($this, 'handle_compat_mode_setting'));
} // end if;
} // end init;
}
}
/**
* Filters the lost password redirect URL.
@ -86,16 +81,13 @@ class Checkout_Pages {
public function filter_lost_password_redirect(string $redirect_to): string {
if ( ! empty($redirect_to)) {
return $redirect_to;
} // end if;
}
$redirect_to = add_query_arg('checkemail', 'confirm', wp_login_url());
return $redirect_to;
} // end filter_lost_password_redirect;
}
/**
* Renders the compat mode option for pages and posts.
@ -127,8 +119,7 @@ class Checkout_Pages {
<?php
// phpcs:enable
} // end render_compat_mode_setting;
}
/**
* Handles saving the compat mode switch on posts.
@ -141,34 +132,23 @@ class Checkout_Pages {
public function handle_compat_mode_setting($post_id) {
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
return;
} // end if;
}
if ( ! isset($_POST['_wu_force_compat']) || ! wp_verify_nonce($_POST['_wu_force_compat'], '_wu_force_compat_' . $post_id)) {
return;
} // end if;
}
if ( ! current_user_can('edit_post', $post_id)) {
return;
} // end if;
}
if (isset($_POST['_wu_force_elements_loading'])) {
update_post_meta($post_id, '_wu_force_elements_loading', $_POST['_wu_force_elements_loading']);
} else {
delete_post_meta($post_id, '_wu_force_elements_loading');
} // end if;
} // end handle_compat_mode_setting;
}
}
/**
* Replace wp-login.php in email URLs.
@ -184,24 +164,19 @@ class Checkout_Pages {
* wp-login.php in it to begin with.
*/
if (strpos($url, 'wp-login.php') === false) {
return $url;
} // end if;
}
$post_id = wu_get_setting('default_login_page', 0);
$post = get_post($post_id);
if ($post) {
$url = str_replace('wp-login.php', $post->post_name, $url);
} // end if;
}
return $url;
} // end maybe_change_wp_login_on_urls;
}
/**
* Get an error message.
@ -243,8 +218,7 @@ class Checkout_Pages {
$messages = apply_filters('wu_checkout_pages_error_messages', $messages);
return wu_get_isset($messages, $error_code, __('Something went wrong', 'wp-ultimo'));
} // end get_error_message;
}
/**
* Handle password reset errors.
@ -260,20 +234,20 @@ class Checkout_Pages {
public function maybe_handle_password_reset_errors($errors) {
if ($errors->has_errors()) {
$url = add_query_arg(array(
$url = add_query_arg(
array(
'action' => wu_request('action', ''),
'user_login' => wu_request('user_login', ''),
'error' => $errors->get_error_code(),
), wp_login_url());
),
wp_login_url()
);
wp_redirect($url);
exit;
} // end if;
} // end maybe_handle_password_reset_errors;
}
}
/**
* Maybe redirects users to the confirm screen.
@ -289,14 +263,11 @@ class Checkout_Pages {
public function maybe_redirect_to_confirm_screen() {
if (wu_request('redirect_to')) {
wp_redirect(wu_request('redirect_to'));
exit;
} // end if;
} // end maybe_redirect_to_confirm_screen;
}
}
/**
* Replace the reset password link, if necessary.
@ -312,10 +283,8 @@ class Checkout_Pages {
public function replace_reset_password_link($message, $key, $user_login, $user_data) {
if ( ! is_main_site()) {
return $message;
} // end if;
}
$results = array();
@ -330,28 +299,27 @@ class Checkout_Pages {
$switched_locale = switch_to_locale($locale);
$new_url = add_query_arg(array(
$new_url = add_query_arg(
array(
'action' => 'rp',
'key' => $key,
'login' => rawurlencode($user_login),
'wp_lang' => $locale
), wp_login_url());
'wp_lang' => $locale,
),
wp_login_url()
);
$new_url = set_url_scheme($new_url, null);
$message = str_replace($results[0], $new_url, $message);
} // end if;
}
if ($switched_locale) {
restore_previous_locale();
} // end if;
}
return $message;
} // end replace_reset_password_link;
}
/**
* Redirect logged users when they reach the login page.
@ -364,24 +332,18 @@ class Checkout_Pages {
global $post;
if ( ! is_user_logged_in()) {
return;
} // end if;
}
$custom_login_page = $this->get_signup_page('login');
if (empty($custom_login_page) || empty($post)) {
return;
} // end if;
}
if ($custom_login_page->ID !== $post->ID) {
return;
} // end if;
}
/**
* Create an exclusion list of parameters that prevent the auto-redirect.
@ -392,24 +354,26 @@ class Checkout_Pages {
* @since 2.0.4
* @return array
*/
$exclusion_list = apply_filters('wu_maybe_redirect_to_admin_panel_exclusion_list', array(
$exclusion_list = apply_filters(
'wu_maybe_redirect_to_admin_panel_exclusion_list',
array(
'preview', // WordPress Preview
'ct_builder', // Oxygen Builder
'fl_builder', // Beaver Builder
'elementor-preview', // Elementor
'brizy-edit', // Brizy
'brizy-edit-iframe', // Brizy
), $custom_login_page, $post, $this);
),
$custom_login_page,
$post,
$this
);
foreach ($exclusion_list as $exclusion_param) {
if (wu_request($exclusion_param, null) !== null) {
return;
} // end if;
} // end foreach;
}
}
$user = wp_get_current_user();
@ -418,34 +382,23 @@ class Checkout_Pages {
$redirect_to = $active_blog ? get_admin_url($active_blog->blog_id) : false;
if (isset($_GET['redirect_to'])) {
$redirect_to = $_GET['redirect_to'];
} elseif (is_multisite() && ! get_active_blog_for_user($user->ID) && ! is_super_admin($user->ID)) {
$redirect_to = user_admin_url();
} elseif (is_multisite() && ! $user->has_cap('read')) {
$redirect_to = get_dashboard_url($user->ID);
} elseif ( ! $user->has_cap('edit_posts')) {
$redirect_to = $user->has_cap('read') ? admin_url('profile.php') : home_url();
} // end if;
}
if ( ! $redirect_to) {
return;
} // end if;
}
wp_redirect($redirect_to);
exit;
} // end maybe_redirect_to_admin_panel;
}
/**
* Adds the unverified email account error message.
@ -460,7 +413,6 @@ class Checkout_Pages {
public function add_verify_email_notice($payment, $membership, $customer) {
if ($payment->get_total() == 0 && $customer->get_email_verification() === 'pending') {
$html = '<div class="wu-p-4 wu-bg-yellow-200 wu-mb-2 wu-text-yellow-700 wu-rounded">%s</div>';
$message = __('Your email address is not yet verified. Your site <strong>will only be activated</strong> after your email address is verified. Check your inbox and verify your email address.', 'wp-ultimo');
@ -468,10 +420,8 @@ class Checkout_Pages {
$message .= sprintf('<br><a href="#" class="wu-resend-verification-email wu-text-gray-700">%s</a>', __('Resend verification email &rarr;', 'wp-ultimo'));
printf($html, $message);
} // end if;
} // end add_verify_email_notice;
}
}
/**
* Check if we should obfuscate the login URL.
@ -484,43 +434,32 @@ class Checkout_Pages {
$use_custom_login = wu_get_setting('enable_custom_login_page', false);
if ( ! $use_custom_login) {
return;
} // end if;
}
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
return;
} // end if;
}
if (wu_request('interim-login')) {
return;
} // end if;
}
if (wu_request('action') === 'logout') {
return;
} // end if;
}
$new_login_url = $this->get_page_url('login');
if ( ! $new_login_url) {
return;
} // end if;
}
$should_obfuscate = wu_get_setting('obfuscate_original_login_url', 1);
$bypass_obfuscation = wu_request('wu_bypass_obfuscation');
if ($should_obfuscate && ! $bypass_obfuscation) {
status_header(404);
nocache_headers();
@ -529,19 +468,15 @@ class Checkout_Pages {
$wp_query->set_404();
include(get_404_template());
include get_404_template();
die;
} else {
wp_redirect($new_login_url);
exit;
} // end if;
} // end maybe_obfuscate_login_url;
}
}
/**
* Redirects the customers to the registration page, when one is used.
@ -554,14 +489,11 @@ class Checkout_Pages {
$registration_url = $this->get_page_url('register');
if ($registration_url) {
wp_redirect($registration_url);
exit;
} // end if;
} // end redirect_to_registration_page;
}
}
/**
* Filters the login URL if necessary.
@ -579,18 +511,14 @@ class Checkout_Pages {
* Fix incompatibility with UIPress, making sure we only filter after wp_loaded ran.
*/
if ( ! did_action('wp_loaded')) {
return $login_url;
} // end if;
}
$function_caller = wu_get_function_caller(5);
if ($function_caller === 'wp_auth_check_html') {
return $login_url;
} // end if;
}
$params = array();
@ -601,32 +529,23 @@ class Checkout_Pages {
$new_login_url = $this->get_page_url('login');
if ( ! $new_login_url) {
return $login_url;
} // end if;
}
if ($params) {
$new_login_url = add_query_arg($params, $new_login_url);
} // end if;
}
if ($redirect) {
$new_login_url = add_query_arg('redirect_to', urlencode($redirect), $new_login_url);
} // end if;
}
if ($force_reauth) {
$new_login_url = add_query_arg('reauth', 1, $new_login_url);
} // end if;
}
return $new_login_url;
} // end filter_login_url;
}
/**
* Returns the ID of the pages being used for each WP Multisite WaaS purpose.
@ -643,8 +562,7 @@ class Checkout_Pages {
'block_frontend' => wu_get_setting('default_block_frontend_page', false),
'new_site' => wu_get_setting('default_new_site_page', false),
);
} // end get_signup_pages;
}
/**
* Returns the WP_Post object for one of the pages.
*
@ -660,14 +578,11 @@ class Checkout_Pages {
$page_id = wu_get_isset($pages, $page);
if ( ! $page_id) {
return false;
} // end if;
}
return get_blog_post(wu_get_main_site_id(), $page_id);
} // end get_signup_page;
}
/**
* Returns the URL for a particular page type.
*
@ -681,14 +596,11 @@ class Checkout_Pages {
$page = $this->get_signup_page($page_slug);
if ( ! $page) {
return false;
} // end if;
}
return wu_switch_blog_and_run(fn() => get_the_permalink($page));
} // end get_page_url;
}
/**
* Tags the WP Multisite WaaS pages on the main site.
@ -702,10 +614,8 @@ class Checkout_Pages {
public function add_wp_ultimo_status_annotation($states, $post) {
if ( ! is_main_site()) {
return $states;
} // end if;
}
$labels = array(
'register' => __('WP Multisite WaaS - Register Page', 'wp-ultimo'),
@ -718,16 +628,13 @@ class Checkout_Pages {
$pages = array_map('absint', $this->get_signup_pages());
if (in_array($post->ID, $pages, true)) {
$key = array_search($post->ID, $pages, true);
$states['wp_ultimo_page'] = wu_get_isset($labels, $key);
} // end if;
}
return $states;
} // end add_wp_ultimo_status_annotation;
}
/**
* Renders the confirmation page.
@ -740,11 +647,12 @@ class Checkout_Pages {
*/
public function render_confirmation_page($atts, $content = null) {
return wu_get_template_contents('checkout/confirmation', array(
return wu_get_template_contents(
'checkout/confirmation',
array(
'errors' => Checkout::get_instance()->errors,
'membership' => wu_get_membership_by_hash(wu_request('membership')),
));
} // end render_confirmation_page;
} // end class Checkout_Pages;
)
);
}
}

File diff suppressed because it is too large Load Diff

View File

@ -111,7 +111,7 @@ class Legacy_Checkout {
// template assigned and return it's path
add_filter('template_include', array($this, 'view_legacy_template'));
} // end init;
}
/**
* Adds our page templates to the page template dropdown.
@ -127,11 +127,11 @@ class Legacy_Checkout {
$posts_templates = array_merge($posts_templates, $this->templates);
} // end if;
}
return $posts_templates;
} // end add_new_template;
}
/**
* Adds our template to the pages cache in order to trick WordPress
@ -155,7 +155,7 @@ class Legacy_Checkout {
$templates = array();
} // end if;
}
// New cache, therefore remove the old one
wp_cache_delete($cache_key, 'themes');
@ -170,7 +170,7 @@ class Legacy_Checkout {
return $atts;
} // end register_legacy_templates;
}
/**
* Checks if our custom template is assigned to the page and display it.
@ -187,7 +187,7 @@ class Legacy_Checkout {
return $template;
} // end if;
}
// Get global post
global $post, $signup;
@ -197,7 +197,7 @@ class Legacy_Checkout {
return $template;
} // end if;
}
$template_slug = get_post_meta($post->ID, '_wp_page_template', true);
@ -206,7 +206,7 @@ class Legacy_Checkout {
return $template;
} // end if;
}
$file = wu_path("views/legacy/signup/$template_slug");
@ -215,12 +215,12 @@ class Legacy_Checkout {
return $file;
} // end if;
}
// Return template
return $template;
} // end view_legacy_template;
}
/**
* Loads the necessary scripts.
@ -251,11 +251,11 @@ class Legacy_Checkout {
wp_enqueue_style('login');
} // end if;
}
wp_enqueue_style('common');
} // end register_scripts;
}
/**
* Adds the additional dynamic styles.
@ -298,8 +298,7 @@ class Legacy_Checkout {
// phpcs:enable
return ob_get_clean();
} // end get_legacy_dynamic_styles;
}
/**
* Checks if we should pre-fill checkout fields based on the request.
@ -319,7 +318,6 @@ class Legacy_Checkout {
$page_name = isset($request['pagename']) ? $request['pagename'] : '';
if (strncmp((string) $page_name, $checkout_page_slug, strlen($checkout_page_slug)) === 0) {
$page = explode('/', (string) $page_name);
/**
@ -328,24 +326,20 @@ class Legacy_Checkout {
* @todo needs to check for frequency and unit.
*/
if (isset($page[1])) {
$product_slug = $page[1];
$product = wu_get_product_by_slug($product_slug);
$this->product = $product;
} // end if;
}
$request['pagename'] = $checkout_page_slug;
return $this->legacy_signup();
} // end if;
}
return $request;
} // end maybe_render_legacy_signup;
}
/**
* Renders the legacy checkout.
@ -369,13 +363,15 @@ class Legacy_Checkout {
$this->handle_post();
wu_get_template('legacy/signup/signup-main', array(
wu_get_template(
'legacy/signup/signup-main',
array(
'signup' => $this,
));
)
);
exit;
} // end legacy_signup;
}
/**
* Check Geolocation
@ -391,16 +387,11 @@ class Legacy_Checkout {
$allowed_countries = wu_get_setting('allowed_countries');
if (isset($location['country']) && $location['country'] && $allowed_countries) {
if ( ! in_array($location['country'], $allowed_countries, true)) {
wp_die(apply_filters('wu_geolocation_error_message', __('Sorry. Our service is not allowed in your country.', 'wp-ultimo')));
} // end if;
} // end if;
} // end check_geolocation;
}
}
}
/**
* Gets the info for the current step.
@ -411,8 +402,7 @@ class Legacy_Checkout {
protected function get_current_step_info() {
return $this->steps[ $this->step ];
} // end get_current_step_info;
}
/**
* Handles a post submission.
@ -433,23 +423,17 @@ class Legacy_Checkout {
/** Checks if the view has a handler of its own */
if (isset($current_step['handler']) && $current_step['handler']) {
$handler_function = $current_step['handler'];
} else {
$handler_function = array($this, 'default_save');
} // end if;
}
/** Allows for handler rewrite */
$handler_function = apply_filters("wu_signup_step_handler_$this->step", $handler_function);
call_user_func($handler_function);
} // end if;
} // end handle_post;
}
}
/**
* The first invisible step, handles the creation of the transient saver
@ -479,19 +463,16 @@ class Legacy_Checkout {
// Adds to the payload
$content['coupon'] = $_REQUEST['coupon'];
} // end if;
}
/**
* Check if user came from a pricing select table
*/
if (isset($_REQUEST['plan_id']) && isset($_REQUEST['plan_freq']) && WU_Gateway::check_frequency($_REQUEST['plan_freq'])) {
$content['plan_id'] = $_REQUEST['plan_id'];
$content['plan_freq'] = $_REQUEST['plan_freq'];
$content['skip_plan'] = true;
} // end if;
}
/**
* Check if we only have one plan and the skip_plan enabled
@ -500,7 +481,6 @@ class Legacy_Checkout {
$plans = wu_get_plans();
if (wu_get_setting('skip_plan', false) && count($plans) === 1) {
$billing_frequency = wu_get_setting('default_pricing_option', 1);
$plan = reset($plans);
@ -511,8 +491,7 @@ class Legacy_Checkout {
$content['skip_plan'] = true;
$_REQUEST['skip_plan'] = 1;
} // end if;
}
/**
* Check if we are settings the template via the URL
@ -525,20 +504,16 @@ class Legacy_Checkout {
$site = new WU_Site_Template($_REQUEST['template_id']);
if ($site->is_template) {
$content['template'] = $_REQUEST['template_id'];
$content['skip_template_selection'] = true;
} // end if;
} // end if;
}
}
$this->session->set('form', $content);
/** Go to the next step */
$this->next_step();
} // end begin_signup;
}
/**
* Check if the current page is a customizer page.
*/
@ -547,18 +522,13 @@ class Legacy_Checkout {
$exclude_list = apply_filters('wu_replace_signup_urls_exclude', array('wu-signup-customizer-preview'));
foreach ($exclude_list as $replace_word) {
if (isset($_GET[ $replace_word ])) {
return true;
} // end if;
} // end foreach;
}
}
return false;
} // end is_customizer;
}
/**
* Returns the first step of the signup process
@ -570,16 +540,11 @@ class Legacy_Checkout {
$keys = array_keys($this->get_steps());
if (isset($keys[1])) {
return $keys[1];
} else {
return false;
} // end if;
} // end get_first_step;
}
}
/**
* Get the current step
@ -592,14 +557,11 @@ class Legacy_Checkout {
// Always get the first step for the customizer //
if ($this->is_customizer()) {
$current_step = $this->get_first_step();
} // end if;
}
return apply_filters('wu_current_step', $current_step);
} // end get_current_step;
}
/**
* Includes the template for that particular step; If none is set (false), includes the default template
@ -616,16 +578,12 @@ class Legacy_Checkout {
* Set the errors
*/
if ($this->results === null) {
$this->results = array('errors' => new \WP_Error);
} // end if;
$this->results = array('errors' => new \WP_Error());
}
if (empty($_POST)) {
$this->results = array_merge($this->results, $transient);
} // end if;
}
/**
* Builds the array containing the available elements inside the template
@ -641,29 +599,20 @@ class Legacy_Checkout {
* Checks if anything is passed to the view element
*/
if (isset($this->steps[ $step ]['view']) && $this->steps[ $step ]['view']) {
wu_get_template('legacy/signup/steps/' . $this->steps[ $step ]['view'], $args);
} else {
$found = locate_template("wp-ultimo/signup/steps/step-$step.php");
/**
* Let's try to locate a custom template on the user's theme. If it's there, we use it instead
*/
if ($found) {
wu_get_template("legacy/signup/steps/step-$step", $args);
} else {
wu_get_template('legacy/signup/steps/step-default', $args);
} // end if;
} // end if;
} // end get_step_view;
}
}
}
/**
* Set and return the steps and fields of each step.
@ -696,7 +645,6 @@ class Legacy_Checkout {
// We add template selection if this has template
if ($site_templates) {
$steps['template'] = array(
'name' => __('Template Selection', 'wp-ultimo'),
'desc' => __('Select the base template of your new site.', 'wp-ultimo'),
@ -705,8 +653,7 @@ class Legacy_Checkout {
'handler' => false,
'core' => true,
);
} // end if;
}
// Domain registering
$steps['domain'] = array(
@ -716,7 +663,9 @@ class Legacy_Checkout {
'view' => false,
'order' => 30,
'core' => true,
'fields' => apply_filters('wu_signup_fields_domain', array(
'fields' => apply_filters(
'wu_signup_fields_domain',
array(
'blog_title' => array(
'order' => 10,
'name' => apply_filters('wu_signup_site_title_label', __('Site Title', 'wp-ultimo')),
@ -749,7 +698,8 @@ class Legacy_Checkout {
'name' => __('Continue to the next step', 'wp-ultimo'),
'core' => true,
),
)),
)
),
);
/**
@ -818,10 +768,10 @@ class Legacy_Checkout {
),
'attributes' => array(
'autocomplete' => 'nope',
)
),
),
); // end first account fields;
);
/**
* Check and Add Coupon Code Fields
@ -851,7 +801,7 @@ class Legacy_Checkout {
// 'requires' => array('has_coupon' => true),
// 'core' => true,
// );
// } // end if;
// }
// /**
// * Check and Add the Terms field
// * @since 1.0.4
@ -864,7 +814,7 @@ class Legacy_Checkout {
// 'name' => sprintf(__('I agree with the <a href="%s" target="_blank">Terms of Service</a>', 'wp-ultimo'), $this->get_terms_url()),
// 'core' => true,
// );
// } // end if;
// }
/**
* Submit Field
@ -896,19 +846,19 @@ class Legacy_Checkout {
// Sorts each of the fields block
foreach ($steps as &$step) {
$step = wp_parse_args($step, array(
$step = wp_parse_args(
$step,
array(
'hidden' => false,
));
)
);
if (isset($step['fields']) && is_array($step['fields'])) {
// Sort elements based on their order
uasort($step['fields'], array($this, 'sort_steps_and_fields'));
} // end if;
} // end foreach;
}
}
/**
* Adds the hidden step now responsible for validating data entry and the actual account creation
@ -953,21 +903,16 @@ class Legacy_Checkout {
* @var array
*/
if ( ! $include_hidden) {
$steps = array_filter($steps, fn($step) => ! (isset($step['hidden']) && $step['hidden']));
} // end if;
}
// If we need to add that
if ( ! $this->has_plan_step()) {
unset($steps['plan']);
} // end if;
}
return $steps;
} // end get_steps;
}
/**
* Check the transient, and if it does not exists, throw fatal
@ -978,32 +923,24 @@ class Legacy_Checkout {
public static function get_transient($die = true) {
if (self::is_customizer()) {
$transient = array(
'not-empty' => '',
);
} else {
$transient = wu_get_session('signup')->get('form');
} // end if;
}
if ($die && empty($transient)) {
// wp_die(__('Try again', 'wp-ultimo'));
} // end if;
}
if (is_null($transient)) {
return array();
} // end if;
}
return $transient;
} // end get_transient;
}
/**
* Update the transient data in out database
@ -1015,8 +952,7 @@ class Legacy_Checkout {
$this->session->set('form', $transient);
$this->session->commit();
} // end update_transient;
}
/**
* Checks transient data to see if the plan step is necessary
*/
@ -1025,14 +961,11 @@ class Legacy_Checkout {
$transient = $this->get_transient();
if (isset($transient['skip_plan']) && isset($transient['plan_id']) && isset($transient['plan_freq'])) {
return false;
} // end if;
}
return true;
} // end has_plan_step;
}
/**
* Get the link for the next step
@ -1044,57 +977,42 @@ class Legacy_Checkout {
// Add CS
if (isset($_GET['cs'])) {
$params['cs'] = $_GET['cs'];
} // end if;
}
if (isset($_REQUEST['customized'])) {
$params['customized'] = $_REQUEST['customized'];
} // end if;
}
if (isset($_REQUEST['skip_plan']) && $_REQUEST['skip_plan'] == 1) {
unset($this->steps['plan']);
unset($params['skip_plan']);
} // end if;
}
if (isset($_REQUEST['template_id'])) {
$plan = false;
if (isset($_REQUEST['plan_id'])) {
$plan = wu_get_plan($_REQUEST['plan_id']);
} // end if;
}
$templates = array_keys((array) wu_get_setting('templates'));
if ( ($plan && $plan->is_template_available($_REQUEST['template_id'])) || in_array($_REQUEST['template_id'], $templates)) {
unset($this->steps['template']);
unset($params['skip_template_selection']);
} // end if;
} // end if;
}
}
$keys = array_keys($this->steps);
$url = add_query_arg('step', $keys[ array_search($this->step, array_keys($this->steps)) + 1 ]);
foreach ($params as $param => $value) {
$url = add_query_arg($param, $value, $url);
} // end foreach;
}
return $url;
} // end get_next_step_link;
}
/**
* Redirects the user to the next step on the signup flow
@ -1109,8 +1027,7 @@ class Legacy_Checkout {
/** Kill the execution after the redirect */
exit;
} // end next_step;
}
/**
* Get the link for the previous step
@ -1122,38 +1039,29 @@ class Legacy_Checkout {
// Add CS
if (isset($_GET['cs'])) {
$params['cs'] = $_GET['cs'];
} // end if;
}
if (isset($_REQUEST['customized'])) {
$params['customized'] = $_REQUEST['customized'];
} // end if;
}
$keys = array_keys($this->steps);
$search_key = array_search($this->step, array_keys($this->steps)) - 1 >= 0 ? array_search($this->step, array_keys($this->steps)) - 1 : false;
$key = $search_key === false ? '' : $keys[ $search_key ];
if ( ! $key || $key == 'begin-signup') {
return false;
} // end if;
}
$url = add_query_arg('step', $key);
foreach ($params as $param => $value) {
$url = add_query_arg($param, $value, $url);
} // end foreach;
}
return $url;
} // end get_prev_step_link;
}
/**
* Sorts the steps.
@ -1169,8 +1077,7 @@ class Legacy_Checkout {
$b['order'] = isset($b['order']) ? (int) $b['order'] : 50;
return $a['order'] - $b['order'];
} // end sort_steps_and_fields;
}
/**
* Display the necessary fields for the plan template
@ -1195,7 +1102,7 @@ class Legacy_Checkout {
<input type="hidden" id="wu_plan_freq" name="plan_freq" value="<?php echo $freq; ?>">
<?php
} // end if;
}
?>
<input type="hidden" name="save_step" value="1">
@ -1210,8 +1117,7 @@ class Legacy_Checkout {
<?php endif; ?>
<?php
} // end form_fields;
}
/**
* Get the primary site URL we will use on the URL previewer, during sign-up
@ -1228,10 +1134,8 @@ class Legacy_Checkout {
$domain = $site->domain;
if (wu_get_setting('enable_multiple_domains', false) && $domain_options) {
$domain = array_shift($domain_options);
} // end if;
}
$domain = rtrim($domain . $site->path, '/');
@ -1244,8 +1148,7 @@ class Legacy_Checkout {
* @return string New domain to be used
*/
return apply_filters('get_site_url_for_previewer', $domain, $domain_options); // phpcs:ignore
} // end get_site_url_for_previewer;
}
/**
* We pass the following info
@ -1259,7 +1162,7 @@ class Legacy_Checkout {
check_admin_referer('signup_form_1', '_signup_form');
// Errors
$this->results['errors'] = new \WP_Error;
$this->results['errors'] = new \WP_Error();
// We need now to check for plan
if ( ! isset($_POST['plan_id'])) {
@ -1270,8 +1173,8 @@ class Legacy_Checkout {
if ( ! $plan->exists()) {
$this->results['errors']->add('plan_id', __('The plan you\'ve selected doesn\'t exist.', 'wp-ultimo'));
} // end if;
} // end if;
}
}
$transient = apply_filters('wp_ultimo_registration_step_plans_save_transient', $transient);
@ -1281,7 +1184,7 @@ class Legacy_Checkout {
// Stay on the form if we get any errors
if ($this->results['errors']->get_error_code()) {
return;
} // end if;
}
/** Update Transient Content */
$transient['plan_freq'] = $_POST['plan_freq'];
@ -1292,8 +1195,7 @@ class Legacy_Checkout {
/** Go to the next step */
$this->next_step();
} // end plans_save;
}
/**
* Personal Info Settings.
@ -1324,20 +1226,17 @@ class Legacy_Checkout {
// Stay on the form if we get any errors
if ($this->results['errors']->get_error_code()) {
$this->results = array_merge($this->results, $_POST);
return;
} // end if;
}
// Re-saves the transient
$this->update_transient($transient);
/** Go to the next step */
$this->next_step();
} // end domain_save;
}
/**
* Filters the input variables and sanitizes its contents
@ -1357,8 +1256,7 @@ class Legacy_Checkout {
$post = array_map(fn($element) => sanitize_text_field($element), $post);
return $post;
} // end filter_post_array;
}
/**
* Helper function to filter based on key.
*
@ -1372,8 +1270,7 @@ class Legacy_Checkout {
$matched_keys = array_filter(array_keys($array), $callback === null ? fn($v, $k): bool => ! empty($v) : $callback, $callback === null ? ARRAY_FILTER_USE_BOTH : 0);
return array_intersect_key($array, array_flip($matched_keys));
} // end array_filter_key;
}
/**
* Get the active until + trial days, to allow for putting subscription on hold
*
@ -1388,8 +1285,7 @@ class Legacy_Checkout {
$active_until->add(new \DateInterval('P' . $trial_days . 'D'));
return $active_until->format('Y-m-d H:i:s');
} // end get_active_until_with_trial;
}
/**
* Adds a new Step to the sign-up flow
@ -1402,7 +1298,9 @@ class Legacy_Checkout {
*/
public function add_signup_step($id, $order, $step) {
add_filter('wp_ultimo_registration_steps', function($steps) use ($id, $order, $step) {
add_filter(
'wp_ultimo_registration_steps',
function ($steps) use ($id, $order, $step) {
// Save new order
$step['order'] = $order;
@ -1413,10 +1311,9 @@ class Legacy_Checkout {
$steps[ $id ] = $step;
return $steps;
});
} // end add_signup_step;
}
);
}
/**
* Adds a new field to a step the sign-up flow
@ -1430,14 +1327,14 @@ class Legacy_Checkout {
*/
public function add_signup_field($step, $id, $order, $field) {
add_filter('wp_ultimo_registration_steps', function($steps) use ($step, $id, $order, $field) {
add_filter(
'wp_ultimo_registration_steps',
function ($steps) use ($step, $id, $order, $field) {
// Checks for honey-trap id
if ($id === 'site_url') {
wp_die(__('Please, do not use the "site_url" as one of your custom fields\' ids. We use it as a honeytrap field to prevent spam registration. Consider alternatives such as "url" or "website".', 'wp-ultimo'));
} // end if;
}
// Saves the order
$field['order'] = $order;
@ -1448,9 +1345,7 @@ class Legacy_Checkout {
$steps[ $step ]['fields'][ $id ] = $field;
return $steps;
});
} // end add_signup_field;
} // end class Legacy_Checkout;
}
);
}
}

View File

@ -12,8 +12,8 @@ namespace WP_Ultimo\Checkout;
// Exit if accessed directly
defined('ABSPATH') || exit;
use \WP_Ultimo\Database\Payments\Payment_Status;
use \WP_Ultimo\Models\Product;
use WP_Ultimo\Database\Payments\Payment_Status;
use WP_Ultimo\Models\Product;
/**
* Creates an cart with the parameters of the purchase being placed.
@ -295,8 +295,7 @@ class Line_Item implements \JsonSerializable {
* Refresh totals.
*/
$this->recalculate_totals();
} // end __construct;
}
/**
* Loops through allowed fields and loads them.
@ -313,10 +312,8 @@ class Line_Item implements \JsonSerializable {
$type = wu_get_isset($data, 'type');
if ($type) {
$this->set_type($data['type']);
} // end if;
}
/*
* Set product first to allow for overriding the other parameters.
@ -324,28 +321,21 @@ class Line_Item implements \JsonSerializable {
$product = wu_get_isset($data, 'product');
if ($product) {
$this->set_product($data['product']);
unset($data['product']);
} // end if;
}
$allowed_attributes = array_keys(get_object_vars($this));
foreach ($data as $key => $value) {
if (in_array($key, $allowed_attributes, true)) {
$this->{$key} = $value;
} // end if;
} // end foreach;
}
}
$this->id = 'LN_' . strtoupper($this->type) . '_' . $this->hash;
} // end attributes;
}
/**
* Get the value of id
@ -356,8 +346,7 @@ class Line_Item implements \JsonSerializable {
public function get_id() {
return $this->id;
} // end get_id;
}
/**
* Get the value of type
@ -368,8 +357,7 @@ class Line_Item implements \JsonSerializable {
public function get_type() {
return $this->type;
} // end get_type;
}
/**
* Set the value of type.
@ -383,8 +371,7 @@ class Line_Item implements \JsonSerializable {
public function set_type($type) {
$this->type = $type;
} // end set_type;
}
/**
* Get product associated with this line item.
*
@ -396,29 +383,22 @@ class Line_Item implements \JsonSerializable {
$product = wu_get_product($this->product_id);
if ( ! $product) {
return false;
} // end if;
}
if ($product->is_recurring() && ($this->duration_unit !== $product->get_duration_unit() || $this->duration !== $product->get_duration())) {
$product_variation = $product->get_as_variation($this->duration, $this->duration_unit);
/*
* Checks if the variation exists before re-setting the product.
*/
if ($product_variation) {
$product = $product_variation;
} // end if;
} // end if;
}
}
return $product;
} // end get_product;
}
/**
* Set product associated with this line item.
@ -452,8 +432,7 @@ class Line_Item implements \JsonSerializable {
$this->tax_category = $product->get_tax_category();
$this->discountable = true;
} // end set_product;
}
/**
* Calculate the taxes value based on the tax_amount and tax_type.
@ -465,8 +444,7 @@ class Line_Item implements \JsonSerializable {
public function calculate_taxes($sub_total) {
return wu_get_tax_amount($sub_total, $this->get_tax_rate(), $this->get_tax_type(), false, $this->get_tax_inclusive());
} // end calculate_taxes;
}
/**
* Calculate the discounts value based on the discount_amount and discount_type.
@ -478,8 +456,7 @@ class Line_Item implements \JsonSerializable {
public function calculate_discounts($sub_total) {
return wu_get_tax_amount($sub_total, $this->get_discount_rate(), $this->get_discount_type(), false);
} // end calculate_discounts;
}
/**
* Recalculate payment totals.
@ -496,30 +473,23 @@ class Line_Item implements \JsonSerializable {
$discounted_subtotal = $sub_total - $discounts;
if ($sub_total > 0 && $discounted_subtotal < 0) {
$discounted_subtotal = 0;
$discounts = $sub_total;
} // end if;
}
$taxes = $this->calculate_taxes($discounted_subtotal);
if ($this->get_tax_inclusive()) {
$total = $this->is_tax_exempt() ? $discounted_subtotal - $taxes : $discounted_subtotal;
} else {
$total = $this->is_tax_exempt() ? $discounted_subtotal : $discounted_subtotal + $taxes; // tax exclusive
} // end if;
}
if ($this->is_tax_exempt()) {
$taxes = 0;
} // end if;
}
$totals = array(
'subtotal' => $sub_total,
@ -531,8 +501,7 @@ class Line_Item implements \JsonSerializable {
$this->attributes($totals);
return $this;
} // end recalculate_totals;
}
/**
* Get quantity of the given product.
@ -543,8 +512,7 @@ class Line_Item implements \JsonSerializable {
public function get_quantity() {
return $this->quantity;
} // end get_quantity;
}
/**
* Set quantity of the given product.
@ -556,8 +524,7 @@ class Line_Item implements \JsonSerializable {
public function set_quantity($quantity) {
$this->quantity = $quantity;
} // end set_quantity;
}
/**
* Get unit price of the product.
@ -568,8 +535,7 @@ class Line_Item implements \JsonSerializable {
public function get_unit_price() {
return $this->unit_price;
} // end get_unit_price;
}
/**
* Set unit price of the product.
@ -581,8 +547,7 @@ class Line_Item implements \JsonSerializable {
public function set_unit_price($unit_price) {
$this->unit_price = $unit_price;
} // end set_unit_price;
}
/**
* Get tax amount, absolute or percentage.
@ -593,8 +558,7 @@ class Line_Item implements \JsonSerializable {
public function get_tax_rate() {
return $this->tax_rate;
} // end get_tax_rate;
}
/**
* Set tax amount, absolute or percentage.
@ -606,8 +570,7 @@ class Line_Item implements \JsonSerializable {
public function set_tax_rate($tax_rate) {
$this->tax_rate = $tax_rate;
} // end set_tax_rate;
}
/**
* Get type of the tax, percentage or absolute.
@ -618,8 +581,7 @@ class Line_Item implements \JsonSerializable {
public function get_tax_type() {
return $this->tax_type;
} // end get_tax_type;
}
/**
* Set type of the tax, percentage or absolute.
@ -631,8 +593,7 @@ class Line_Item implements \JsonSerializable {
public function set_tax_type($tax_type) {
$this->tax_type = $tax_type;
} // end set_tax_type;
}
/**
* Get if tax are included in the price or not.
@ -643,8 +604,7 @@ class Line_Item implements \JsonSerializable {
public function get_tax_inclusive() {
return (bool) $this->tax_inclusive;
} // end get_tax_inclusive;
}
/**
* Set if tax are included in the price or not.
@ -656,8 +616,7 @@ class Line_Item implements \JsonSerializable {
public function set_tax_inclusive($tax_inclusive) {
$this->tax_inclusive = $tax_inclusive;
} // end set_tax_inclusive;
}
/**
* Get if the line item is tax exempt ot not.
@ -668,8 +627,7 @@ class Line_Item implements \JsonSerializable {
public function is_tax_exempt() {
return $this->tax_exempt;
} // end is_tax_exempt;
}
/**
* Set if the line item is tax exempt ot not.
@ -681,8 +639,7 @@ class Line_Item implements \JsonSerializable {
public function set_tax_exempt($tax_exempt) {
$this->tax_exempt = $tax_exempt;
} // end set_tax_exempt;
}
/**
* Get the amount, in currency, of the tax.
@ -693,8 +650,7 @@ class Line_Item implements \JsonSerializable {
public function get_tax_total() {
return $this->tax_total;
} // end get_tax_total;
}
/**
* Set the amount, in currency, of the tax.
@ -706,8 +662,7 @@ class Line_Item implements \JsonSerializable {
public function set_tax_total($tax_total) {
$this->tax_total = $tax_total;
} // end set_tax_total;
}
/**
* Get the value of total
@ -718,8 +673,7 @@ class Line_Item implements \JsonSerializable {
public function get_total() {
return $this->total;
} // end get_total;
}
/**
* Set the value of total.
@ -731,8 +685,7 @@ class Line_Item implements \JsonSerializable {
public function set_total($total) {
$this->total = $total;
} // end set_total;
}
/**
* Get the value of recurring.
@ -743,8 +696,7 @@ class Line_Item implements \JsonSerializable {
public function is_recurring() {
return $this->recurring;
} // end is_recurring;
}
/**
* Set the value of recurring.
@ -756,8 +708,7 @@ class Line_Item implements \JsonSerializable {
public function set_recurring($recurring) {
$this->recurring = $recurring;
} // end set_recurring;
}
/**
* Get value before taxes, discounts, fees and etc.
@ -768,8 +719,7 @@ class Line_Item implements \JsonSerializable {
public function get_subtotal() {
return $this->subtotal;
} // end get_subtotal;
}
/**
* Set value before taxes, discounts, fees and etc.
@ -781,8 +731,7 @@ class Line_Item implements \JsonSerializable {
public function set_subtotal($subtotal) {
$this->subtotal = $subtotal;
} // end set_subtotal;
}
/**
* Get the value of duration
@ -793,8 +742,7 @@ class Line_Item implements \JsonSerializable {
public function get_duration() {
return $this->duration;
} // end get_duration;
}
/**
* Set the value of duration.
@ -806,8 +754,7 @@ class Line_Item implements \JsonSerializable {
public function set_duration($duration) {
$this->duration = $duration;
} // end set_duration;
}
/**
* Get the value of duration_unit.
@ -818,8 +765,7 @@ class Line_Item implements \JsonSerializable {
public function get_duration_unit() {
return $this->duration_unit;
} // end get_duration_unit;
}
/**
* Set the value of duration_unit.
@ -831,8 +777,7 @@ class Line_Item implements \JsonSerializable {
public function set_duration_unit($duration_unit) {
$this->duration_unit = $duration_unit;
} // end set_duration_unit;
}
/**
* Get the value of billing_cycles.
@ -843,8 +788,7 @@ class Line_Item implements \JsonSerializable {
public function get_billing_cycles() {
return $this->billing_cycles;
} // end get_billing_cycles;
}
/**
* Set the value of billing_cycles.
@ -856,8 +800,7 @@ class Line_Item implements \JsonSerializable {
public function set_billing_cycles($billing_cycles) {
$this->billing_cycles = $billing_cycles;
} // end set_billing_cycles;
}
/**
* Get the value of discount_total.
@ -868,8 +811,7 @@ class Line_Item implements \JsonSerializable {
public function get_discount_total() {
return $this->discount_total;
} // end get_discount_total;
}
/**
* Set the value of discount_total.
@ -881,8 +823,7 @@ class Line_Item implements \JsonSerializable {
public function set_discount_total($discount_total) {
$this->discount_total = $discount_total;
} // end set_discount_total;
}
/**
* Get the value of tax_category.
@ -893,8 +834,7 @@ class Line_Item implements \JsonSerializable {
public function get_tax_category() {
return $this->tax_category;
} // end get_tax_category;
}
/**
* Set the value of tax_category.
@ -906,8 +846,7 @@ class Line_Item implements \JsonSerializable {
public function set_tax_category($tax_category) {
$this->tax_category = $tax_category;
} // end set_tax_category;
}
/**
* Get the value of discountable.
@ -918,8 +857,7 @@ class Line_Item implements \JsonSerializable {
public function is_discountable() {
return $this->discountable;
} // end is_discountable;
}
/**
* Set the value of discountable.
@ -931,8 +869,7 @@ class Line_Item implements \JsonSerializable {
public function set_discountable($discountable) {
$this->discountable = $discountable;
} // end set_discountable;
}
/**
* Get the value of taxable.
@ -943,8 +880,7 @@ class Line_Item implements \JsonSerializable {
public function is_taxable() {
return $this->taxable;
} // end is_taxable;
}
/**
* Set the value of taxable.
@ -956,8 +892,7 @@ class Line_Item implements \JsonSerializable {
public function set_taxable($taxable) {
$this->taxable = $taxable;
} // end set_taxable;
}
/**
* Get the value of discount_rate.
@ -968,8 +903,7 @@ class Line_Item implements \JsonSerializable {
public function get_discount_rate() {
return $this->discount_rate;
} // end get_discount_rate;
}
/**
* Set the value of discount_rate.
@ -981,8 +915,7 @@ class Line_Item implements \JsonSerializable {
public function set_discount_rate($discount_rate) {
$this->discount_rate = $discount_rate;
} // end set_discount_rate;
}
/**
* Get the value of discount_type.
@ -993,8 +926,7 @@ class Line_Item implements \JsonSerializable {
public function get_discount_type() {
return $this->discount_type;
} // end get_discount_type;
}
/**
* Set the value of discount_type.
@ -1006,8 +938,7 @@ class Line_Item implements \JsonSerializable {
public function set_discount_type($discount_type) {
$this->discount_type = $discount_type;
} // end set_discount_type;
}
/**
* Get discount Label.
@ -1018,8 +949,7 @@ class Line_Item implements \JsonSerializable {
public function get_discount_label() {
return $this->discount_label;
} // end get_discount_label;
}
/**
* Set discount Label.
@ -1031,8 +961,7 @@ class Line_Item implements \JsonSerializable {
public function set_discount_label($discount_label) {
$this->discount_label = $discount_label;
} // end set_discount_label;
}
/**
* Get if we should apply discount to renewals.
@ -1043,8 +972,7 @@ class Line_Item implements \JsonSerializable {
public function should_apply_discount_to_renewals() {
return $this->apply_discount_to_renewals;
} // end should_apply_discount_to_renewals;
}
/**
* Set if we should apply discount to renewals.
@ -1056,8 +984,7 @@ class Line_Item implements \JsonSerializable {
public function set_apply_discount_to_renewals($apply_discount_to_renewals) {
$this->apply_discount_to_renewals = $apply_discount_to_renewals;
} // end set_apply_discount_to_renewals;
}
/**
* Get the value of product_id.
@ -1068,8 +995,7 @@ class Line_Item implements \JsonSerializable {
public function get_product_id() {
return $this->product_id;
} // end get_product_id;
}
/**
* Set the value of product_id.
@ -1081,8 +1007,7 @@ class Line_Item implements \JsonSerializable {
public function set_product_id($product_id) {
$this->product_id = $product_id;
} // end set_product_id;
}
/**
* Get the value of title
@ -1093,8 +1018,7 @@ class Line_Item implements \JsonSerializable {
public function get_title() {
return $this->title;
} // end get_title;
}
/**
* Set the value of title.
@ -1106,8 +1030,7 @@ class Line_Item implements \JsonSerializable {
public function set_title($title) {
$this->title = $title;
} // end set_title;
}
/**
* Get the value of description.
@ -1118,8 +1041,7 @@ class Line_Item implements \JsonSerializable {
public function get_description() {
return $this->description;
} // end get_description;
}
/**
* Set the value of description.
@ -1131,8 +1053,7 @@ class Line_Item implements \JsonSerializable {
public function set_description($description) {
$this->description = $description;
} // end set_description;
}
/**
* Get label of the tax applied.
@ -1143,8 +1064,7 @@ class Line_Item implements \JsonSerializable {
public function get_tax_label() {
return $this->tax_label;
} // end get_tax_label;
}
/**
* Set label of the tax applied.
@ -1156,8 +1076,7 @@ class Line_Item implements \JsonSerializable {
public function set_tax_label($tax_label) {
$this->tax_label = $tax_label;
} // end set_tax_label;
}
/**
* Returns the amount recurring in a human-friendly way.
@ -1168,10 +1087,8 @@ class Line_Item implements \JsonSerializable {
public function get_recurring_description() {
if ( ! $this->is_recurring()) {
return '';
} // end if;
}
$description = sprintf(
// translators: %1$s the duration, and %2$s the duration unit (day, week, month, etc)
@ -1181,8 +1098,7 @@ class Line_Item implements \JsonSerializable {
);
return $description;
} // end get_recurring_description;
}
/**
* Converts the line item to an array.
@ -1197,8 +1113,7 @@ class Line_Item implements \JsonSerializable {
$array['recurring_description'] = $this->get_recurring_description();
return $array;
} // end to_array;
}
/**
* Implements our on json_decode version of this object. Useful for use in vue.js.
@ -1210,8 +1125,7 @@ class Line_Item implements \JsonSerializable {
public function jsonSerialize() {
return $this->to_array();
} // end jsonSerialize;
}
/**
* Queries the database for Line Items across payments.
@ -1225,11 +1139,14 @@ class Line_Item implements \JsonSerializable {
global $wpdb;
$query = wp_parse_args($query, array(
$query = wp_parse_args(
$query,
array(
'number' => 100,
'date_query' => array(),
'payment_status' => false,
));
)
);
$query['date_query']['column'] = 'p.date_created';
@ -1241,11 +1158,9 @@ class Line_Item implements \JsonSerializable {
$status_query_sql = '';
if ($query['payment_status'] && (new Payment_Status)->is_valid($query['payment_status'])) {
if ($query['payment_status'] && (new Payment_Status())->is_valid($query['payment_status'])) {
$status_query_sql = "AND p.status = '{$query['payment_status']}'";
} // end if;
}
// phpcs:disable;
$query = $wpdb->prepare("
@ -1266,26 +1181,25 @@ class Line_Item implements \JsonSerializable {
$results = $wpdb->get_results($query); // phpcs:ignore
foreach ($results as &$ln) {
$copy = $ln;
$line_items = $ln->line_items;
$ln = maybe_unserialize($line_items);
$ln = array_map(function($_ln) use ($copy) {
$ln = array_map(
function ($_ln) use ($copy) {
$_ln->date_created = $copy->date_created;
return $_ln;
}, $ln);
} // end foreach;
},
$ln
);
}
return $results;
} // end get_line_items;
}
/**
* Get the product slug, if any.
@ -1296,8 +1210,7 @@ class Line_Item implements \JsonSerializable {
public function get_product_slug() {
return $this->product_slug;
} // end get_product_slug;
}
/**
* Set the product slug.
@ -1309,7 +1222,5 @@ class Line_Item implements \JsonSerializable {
public function set_product_slug($product_slug) {
$this->product_slug = $product_slug;
} // end set_product_slug;
} // end class Line_Item;
}
}

View File

@ -112,8 +112,7 @@ abstract class Base_Signup_Field {
public function is_hidden() {
return false;
} // end is_hidden;
}
/**
* Defines if this field/element is related to site creation or not.
@ -124,8 +123,7 @@ abstract class Base_Signup_Field {
public function is_site_field() {
return false;
} // end is_site_field;
}
/**
* Defines if this field/element is related to user/customer creation or not.
@ -136,8 +134,7 @@ abstract class Base_Signup_Field {
public function is_user_field() {
return false;
} // end is_user_field;
}
/**
* Returns the field as an array that the form builder can understand.
@ -159,8 +156,7 @@ abstract class Base_Signup_Field {
'all_attributes' => $this->get_all_attributes(),
'fields' => array($this, 'get_editor_fields'),
);
} // end get_field_as_type_option;
}
/**
* Modifies the HTML attr array before sending it over to the form.
@ -174,8 +170,7 @@ abstract class Base_Signup_Field {
public function get_editor_fields_html_attr($html_attr, $field_name) {
return $html_attr;
} // end get_editor_fields_html_attr;
}
/**
* Get the tabs available for this field.
@ -189,8 +184,7 @@ abstract class Base_Signup_Field {
'content',
'style',
);
} // end get_tabs;
}
/**
* Gets the pre-filled value for the field.
@ -207,20 +201,15 @@ abstract class Base_Signup_Field {
$value_session = wu_get_isset($session->get('signup'), $this->attributes['id']);
if ($value_session) {
$value = $value_session;
} // end if;
}
if (wu_get_isset($this->attributes, 'from_request') && wu_get_isset($this->attributes, 'id')) {
$value = wu_request($this->attributes['id'], '');
} // end if;
}
return $value;
} // end get_value;
}
/**
* Calculate the style attributes for the field.
@ -235,24 +224,17 @@ abstract class Base_Signup_Field {
$width = (int) wu_get_isset($this->attributes, 'width');
if ($width) {
if ($width !== 100) {
$styles[] = 'float: left';
$styles[] = sprintf('width: %s%%', $width);
} // end if;
}
} else {
$styles[] = 'clear: both';
} // end if;
}
return implode('; ', $styles);
} // end calculate_style_attr;
}
/**
* Sets the config values for the current field.
@ -265,8 +247,7 @@ abstract class Base_Signup_Field {
public function set_attributes($attributes) {
$this->attributes = $attributes;
} // end set_attributes;
}
/**
* If you want to force a particular attribute to a value, declare it here.
@ -277,8 +258,7 @@ abstract class Base_Signup_Field {
public function force_attributes() {
return array();
} // end force_attributes;
}
/**
* Default values for the editor fields.
@ -289,8 +269,7 @@ abstract class Base_Signup_Field {
public function defaults() {
return array();
} // end defaults;
}
/**
* List of keys of the default fields we want to display on the builder.
@ -308,8 +287,7 @@ abstract class Base_Signup_Field {
'default',
'required',
);
} // end default_fields;
}
/**
* Returns the editor fields.
@ -327,32 +305,27 @@ abstract class Base_Signup_Field {
* Checks if this is a site field
*/
if ($this->is_site_field()) {
$final_field_list[ '_site_notice_field_' . uniqid() ] = array(
'type' => 'note',
'classes' => 'wu--mt-px',
'desc' => sprintf('<div class="wu-p-4 wu--m-4 wu-bg-blue-100 wu-text-blue-600 wu-border-t wu-border-l-0 wu-border-r-0 wu-border-b-0 wu-border-gray-300 wu-border-solid">%s</div>', __('This is a site-related field. For that reason, this field will not show up when no plans are present on the shopping cart.', 'wp-ultimo')),
'order' => 98.5,
);
} // end if;
}
/*
* Checks if this is a user field
*/
if ($this->is_user_field()) {
$final_field_list[ '_user_notice_field_' . uniqid() ] = array(
'type' => 'note',
'classes' => 'wu--mt-px',
'desc' => sprintf('<div class="wu-p-4 wu--m-4 wu-bg-blue-100 wu-text-blue-600 wu-border-t wu-border-l-0 wu-border-r-0 wu-border-b-0 wu-border-gray-300 wu-border-solid">%s</div>', __('This is a customer-related field. For that reason, this field will not show up when the user is logged and already has a customer on file.', 'wp-ultimo')),
'order' => 98.5,
);
} // end if;
}
foreach ($final_field_list as $key => &$field) {
$field['html_attr'] = wu_get_isset($field, 'html_attr', array());
$value = wu_get_isset($attributes, $key, null);
@ -360,13 +333,10 @@ abstract class Base_Signup_Field {
$field['default'] = wu_get_isset($this->defaults(), $key, '');
if ($value === null) {
$value = $field['default'];
} // end if;
}
if (wu_get_isset($field['html_attr'], 'data-model')) {
$model_name = wu_get_isset($field['html_attr'], 'data-model', 'product');
$models = explode(',', (string) $value);
@ -374,34 +344,29 @@ abstract class Base_Signup_Field {
$func_name = "wu_get_{$model_name}";
if (function_exists($func_name)) {
$selected = array_map(function($id) use ($func_name) {
$selected = array_map(
function ($id) use ($func_name) {
$model = call_user_func($func_name, absint($id));
if ( ! $model) {
return false;
} // end if;
}
return $model->to_search_results();
}, $models);
},
$models
);
$selected = array_filter($selected);
$field['html_attr']['data-selected'] = json_encode($selected);
} // end if;
} // end if;
}
}
if ( ! is_null($value)) {
$field['value'] = $value;
} // end if;
}
$field['html_attr'] = $this->get_editor_fields_html_attr($field['html_attr'], $field['type']);
@ -411,23 +376,22 @@ abstract class Base_Signup_Field {
$show_reqs = false;
if (isset($field['wrapper_html_attr'])) {
$show_reqs = wu_get_isset($field['wrapper_html_attr'], 'v-show');
} // end if;
}
$tab = wu_get_isset($field, 'tab', 'content');
$field['wrapper_html_attr'] = array_merge(wu_get_isset($field, 'wrapper_html_attr', array()), array(
$field['wrapper_html_attr'] = array_merge(
wu_get_isset($field, 'wrapper_html_attr', array()),
array(
'v-cloak' => 1,
'v-show' => sprintf('require("type", "%s") && require("tab", "%s")', $this->get_type(), $tab) . ($show_reqs ? " && $show_reqs" : ''),
));
} // end foreach;
)
);
}
return $final_field_list;
} // end get_editor_fields;
}
/**
* Returns a list of all the attributes.
@ -449,8 +413,7 @@ abstract class Base_Signup_Field {
$field_keys = array_keys($this->get_fields());
return array_merge($this->default_fields(), $field_keys, $styles);
} // end get_all_attributes;
}
/**
* Treat the attributes array to avoid reaching the input var limits.
@ -463,8 +426,7 @@ abstract class Base_Signup_Field {
public function reduce_attributes($attributes) {
return $attributes;
} // end reduce_attributes;
}
/**
* List of all the default fields available.
@ -608,7 +570,5 @@ abstract class Base_Signup_Field {
);
return $fields;
} // end fields_list;
} // end class Base_Signup_Field;
}
}

View File

@ -9,7 +9,7 @@
namespace WP_Ultimo\Checkout\Signup_Fields;
use \WP_Ultimo\Checkout\Signup_Fields\Base_Signup_Field;
use WP_Ultimo\Checkout\Signup_Fields\Base_Signup_Field;
// Exit if accessed directly
defined('ABSPATH') || exit;
@ -32,8 +32,7 @@ class Signup_Field_Billing_Address extends Base_Signup_Field {
public function get_type() {
return 'billing_address';
} // end get_type;
}
/**
* Returns if this field should be present on the checkout flow or not.
@ -44,8 +43,7 @@ class Signup_Field_Billing_Address extends Base_Signup_Field {
public function is_required() {
return false;
} // end is_required;
}
/**
* Is this a user-related field?
@ -59,8 +57,7 @@ class Signup_Field_Billing_Address extends Base_Signup_Field {
public function is_user_field() {
return true;
} // end is_user_field;
}
/**
* Requires the title of the field/element type.
@ -73,8 +70,7 @@ class Signup_Field_Billing_Address extends Base_Signup_Field {
public function get_title() {
return __('Address', 'wp-ultimo');
} // end get_title;
}
/**
* Returns the description of the field/element.
@ -87,8 +83,7 @@ class Signup_Field_Billing_Address extends Base_Signup_Field {
public function get_description() {
return __('Adds billing address fields such as country, zip code.', 'wp-ultimo');
} // end get_description;
}
/**
* Returns the tooltip of the field/element.
@ -101,8 +96,7 @@ class Signup_Field_Billing_Address extends Base_Signup_Field {
public function get_tooltip() {
return __('Adds billing address fields such as country, zip code.', 'wp-ultimo');
} // end get_tooltip;
}
/**
* Returns the icon to be used on the selector.
@ -115,8 +109,7 @@ class Signup_Field_Billing_Address extends Base_Signup_Field {
public function get_icon() {
return 'dashicons-wu-map1';
} // end get_icon;
}
/**
* Returns the default values for the field-elements.
@ -132,8 +125,7 @@ class Signup_Field_Billing_Address extends Base_Signup_Field {
return array(
'zip_and_country' => true,
);
} // end defaults;
}
/**
* List of keys of the default fields we want to display on the builder.
@ -146,8 +138,7 @@ class Signup_Field_Billing_Address extends Base_Signup_Field {
return array(
'name',
);
} // end default_fields;
}
/**
* If you want to force a particular attribute to a value, declare it here.
@ -161,8 +152,7 @@ class Signup_Field_Billing_Address extends Base_Signup_Field {
'id' => 'billing_address',
'required' => true,
);
} // end force_attributes;
}
/**
* Returns the list of additional fields specific to this type.
@ -180,8 +170,7 @@ class Signup_Field_Billing_Address extends Base_Signup_Field {
'value' => true,
),
);
} // end get_fields;
}
/**
* Build a filed alternative.
@ -199,9 +188,12 @@ class Signup_Field_Billing_Address extends Base_Signup_Field {
$field = $base_field;
$option_template = sprintf('<option v-for="item in %s" :value="item.code">
$option_template = sprintf(
'<option v-for="item in %s" :value="item.code">
{{ item.name }}
</option>', $data_key_name);
</option>',
$data_key_name
);
$field['type'] = 'select';
$field['options_template'] = $option_template;
@ -214,8 +206,7 @@ class Signup_Field_Billing_Address extends Base_Signup_Field {
$field['title'] = sprintf('<span v-html="%s">%s</span>', "labels.$label_key_field", $field['title']);
return $field;
} // end build_select_alternative;
}
/**
* Returns the field/element actual field array to be used on the checkout form.
@ -235,29 +226,21 @@ class Signup_Field_Billing_Address extends Base_Signup_Field {
* Checks for an existing customer
*/
if ($customer) {
$fields = $customer->get_billing_address()->get_fields($zip_only);
} else {
$checkout_form = \WP_Ultimo\Checkout\Checkout::get_instance()->checkout_form;
$fields = \WP_Ultimo\Objects\Billing_Address::fields($zip_only, $checkout_form);
} // end if;
}
if (isset($fields['billing_country'])) {
$fields['billing_country']['html_attr'] = array(
'v-model' => 'country',
);
} // end if;
}
if ( ! $zip_only) {
if (isset($fields['billing_state'])) {
$fields['billing_state']['html_attr'] = array(
'v-model.lazy' => 'state',
);
@ -268,11 +251,9 @@ class Signup_Field_Billing_Address extends Base_Signup_Field {
* @since 2.0.11
*/
$fields['billing_state_select'] = $this->build_select_alternative($fields['billing_state'], 'state_list', 'state_field');
} // end if;
}
if (isset($fields['billing_city'])) {
$fields['billing_city']['html_attr'] = array(
'v-model.lazy' => 'city',
);
@ -283,21 +264,15 @@ class Signup_Field_Billing_Address extends Base_Signup_Field {
* @since 2.0.11
*/
$fields['billing_city_select'] = $this->build_select_alternative($fields['billing_city'], 'city_list', 'city_field');
} // end if;
} // end if;
}
}
foreach ($fields as &$field) {
$field['wrapper_classes'] = trim(wu_get_isset($field, 'wrapper_classes', '') . ' ' . $attributes['element_classes']);
} // end foreach;
}
uasort($fields, 'wu_sort_by_order');
return $fields;
} // end to_fields_array;
} // end class Signup_Field_Billing_Address;
}
}

View File

@ -9,7 +9,7 @@
namespace WP_Ultimo\Checkout\Signup_Fields;
use \WP_Ultimo\Checkout\Signup_Fields\Base_Signup_Field;
use WP_Ultimo\Checkout\Signup_Fields\Base_Signup_Field;
// Exit if accessed directly
defined('ABSPATH') || exit;
@ -32,8 +32,7 @@ class Signup_Field_Checkbox extends Base_Signup_Field {
public function get_type() {
return 'checkbox';
} // end get_type;
}
/**
* Returns if this field should be present on the checkout flow or not.
@ -44,8 +43,7 @@ class Signup_Field_Checkbox extends Base_Signup_Field {
public function is_required() {
return false;
} // end is_required;
}
/**
* Is this a user-related field?
@ -59,8 +57,7 @@ class Signup_Field_Checkbox extends Base_Signup_Field {
public function is_user_field() {
return false;
} // end is_user_field;
}
/**
* Requires the title of the field/element type.
@ -73,8 +70,7 @@ class Signup_Field_Checkbox extends Base_Signup_Field {
public function get_title() {
return __('Checkbox', 'wp-ultimo');
} // end get_title;
}
/**
* Returns the description of the field/element.
@ -87,8 +83,7 @@ class Signup_Field_Checkbox extends Base_Signup_Field {
public function get_description() {
return __('Adds a checkout box that can be checked by the customer.', 'wp-ultimo');
} // end get_description;
}
/**
* Returns the tooltip of the field/element.
@ -101,8 +96,7 @@ class Signup_Field_Checkbox extends Base_Signup_Field {
public function get_tooltip() {
return __('Adds a checkout box that can be checked by the customer.', 'wp-ultimo');
} // end get_tooltip;
}
/**
* Returns the icon to be used on the selector.
@ -115,8 +109,7 @@ class Signup_Field_Checkbox extends Base_Signup_Field {
public function get_icon() {
return 'dashicons-wu-check-square';
} // end get_icon;
}
/**
* Returns the default values for the field-elements.
@ -130,10 +123,9 @@ class Signup_Field_Checkbox extends Base_Signup_Field {
public function defaults() {
return array(
''
'',
);
} // end defaults;
}
/**
* List of keys of the default fields we want to display on the builder.
@ -150,8 +142,7 @@ class Signup_Field_Checkbox extends Base_Signup_Field {
'save_as',
'required',
);
} // end default_fields;
}
/**
* If you want to force a particular attribute to a value, declare it here.
@ -162,8 +153,7 @@ class Signup_Field_Checkbox extends Base_Signup_Field {
public function force_attributes() {
return array();
} // end force_attributes;
}
/**
* Returns the list of additional fields specific to this type.
@ -182,8 +172,7 @@ class Signup_Field_Checkbox extends Base_Signup_Field {
'order' => 12,
),
);
} // end get_fields;
}
/**
* Returns the field/element actual field array to be used on the checkout form.
@ -207,21 +196,15 @@ class Signup_Field_Checkbox extends Base_Signup_Field {
);
if ($attributes['default_state']) {
$checkout_fields[ $attributes['id'] ]['html_attr']['checked'] = 'checked';
} // end if;
}
$value = $this->get_value();
if ($value !== '' && (bool) $value === true) {
$checkout_fields[ $attributes['id'] ]['html_attr']['checked'] = 'checked';
} // end if;
}
return $checkout_fields;
} // end to_fields_array;
} // end class Signup_Field_Checkbox;
}
}

View File

@ -9,7 +9,7 @@
namespace WP_Ultimo\Checkout\Signup_Fields;
use \WP_Ultimo\Checkout\Signup_Fields\Base_Signup_Field;
use WP_Ultimo\Checkout\Signup_Fields\Base_Signup_Field;
// Exit if accessed directly
defined('ABSPATH') || exit;
@ -32,8 +32,7 @@ class Signup_Field_Color extends Base_Signup_Field {
public function get_type() {
return 'color_picker';
} // end get_type;
}
/**
* Returns if this field should be present on the checkout flow or not.
@ -44,8 +43,7 @@ class Signup_Field_Color extends Base_Signup_Field {
public function is_required() {
return false;
} // end is_required;
}
/**
* Requires the title of the field/element type.
@ -58,8 +56,7 @@ class Signup_Field_Color extends Base_Signup_Field {
public function get_title() {
return __('Color', 'wp-ultimo');
} // end get_title;
}
/**
* Returns the description of the field/element.
@ -72,8 +69,7 @@ class Signup_Field_Color extends Base_Signup_Field {
public function get_description() {
return __('Adds a color picker field.', 'wp-ultimo');
} // end get_description;
}
/**
* Returns the tooltip of the field/element.
@ -86,8 +82,7 @@ class Signup_Field_Color extends Base_Signup_Field {
public function get_tooltip() {
return __('Adds a color picker field.', 'wp-ultimo');
} // end get_tooltip;
}
/**
* Returns the icon to be used on the selector.
@ -100,8 +95,7 @@ class Signup_Field_Color extends Base_Signup_Field {
public function get_icon() {
return 'dashicons-wu-droplet';
} // end get_icon;
}
/**
* Returns the default values for the field-elements.
@ -115,10 +109,9 @@ class Signup_Field_Color extends Base_Signup_Field {
public function defaults() {
return array(
''
'',
);
} // end defaults;
}
/**
* List of keys of the default fields we want to display on the builder.
@ -136,8 +129,7 @@ class Signup_Field_Color extends Base_Signup_Field {
'required',
'save_as',
);
} // end default_fields;
}
/**
* If you want to force a particular attribute to a value, declare it here.
@ -148,8 +140,7 @@ class Signup_Field_Color extends Base_Signup_Field {
public function force_attributes() {
return array();
} // end force_attributes;
}
/**
* Returns the list of additional fields specific to this type.
@ -167,8 +158,7 @@ class Signup_Field_Color extends Base_Signup_Field {
'desc' => __('Set the default value for this color field.', 'wp-ultimo'),
),
);
} // end get_fields;
}
/**
* Returns the field/element actual field array to be used on the checkout form.
@ -197,7 +187,5 @@ class Signup_Field_Color extends Base_Signup_Field {
),
),
);
} // end to_fields_array;
} // end class Signup_Field_Color;
}
}

View File

@ -9,7 +9,7 @@
namespace WP_Ultimo\Checkout\Signup_Fields;
use \WP_Ultimo\Checkout\Signup_Fields\Base_Signup_Field;
use WP_Ultimo\Checkout\Signup_Fields\Base_Signup_Field;
// Exit if accessed directly
defined('ABSPATH') || exit;
@ -32,8 +32,7 @@ class Signup_Field_Discount_Code extends Base_Signup_Field {
public function get_type() {
return 'discount_code';
} // end get_type;
}
/**
* Returns if this field should be present on the checkout flow or not.
@ -44,8 +43,7 @@ class Signup_Field_Discount_Code extends Base_Signup_Field {
public function is_required() {
return false;
} // end is_required;
}
/**
* Requires the title of the field/element type.
@ -58,8 +56,7 @@ class Signup_Field_Discount_Code extends Base_Signup_Field {
public function get_title() {
return __('Coupon Code', 'wp-ultimo');
} // end get_title;
}
/**
* Returns the description of the field/element.
@ -72,8 +69,7 @@ class Signup_Field_Discount_Code extends Base_Signup_Field {
public function get_description() {
return __('Adds an additional field to apply a discount code.', 'wp-ultimo');
} // end get_description;
}
/**
* Returns the tooltip of the field/element.
@ -86,8 +82,7 @@ class Signup_Field_Discount_Code extends Base_Signup_Field {
public function get_tooltip() {
return __('Adds an additional field to apply a discount code.', 'wp-ultimo');
} // end get_tooltip;
}
/**
* Returns the icon to be used on the selector.
@ -100,8 +95,7 @@ class Signup_Field_Discount_Code extends Base_Signup_Field {
public function get_icon() {
return 'dashicons-wu-tag1';
} // end get_icon;
}
/**
* Returns the default values for the field-elements.
@ -118,8 +112,7 @@ class Signup_Field_Discount_Code extends Base_Signup_Field {
'placeholder' => '',
'default' => '',
);
} // end defaults;
}
/**
* List of keys of the default fields we want to display on the builder.
@ -134,8 +127,7 @@ class Signup_Field_Discount_Code extends Base_Signup_Field {
'placeholder',
'tooltip',
);
} // end default_fields;
}
/**
* If you want to force a particular attribute to a value, declare it here.
@ -148,8 +140,7 @@ class Signup_Field_Discount_Code extends Base_Signup_Field {
return array(
'id' => 'discount_code',
);
} // end force_attributes;
}
/**
* Returns the list of additional fields specific to this type.
@ -160,8 +151,7 @@ class Signup_Field_Discount_Code extends Base_Signup_Field {
public function get_fields() {
return array();
} // end get_fields;
}
/**
* Returns the field/element actual field array to be used on the checkout form.
@ -206,7 +196,5 @@ class Signup_Field_Discount_Code extends Base_Signup_Field {
);
return $checkout_fields;
} // end to_fields_array;
} // end class Signup_Field_Discount_Code;
}
}

View File

@ -9,7 +9,7 @@
namespace WP_Ultimo\Checkout\Signup_Fields;
use \WP_Ultimo\Checkout\Signup_Fields\Base_Signup_Field;
use WP_Ultimo\Checkout\Signup_Fields\Base_Signup_Field;
// Exit if accessed directly
defined('ABSPATH') || exit;
@ -31,8 +31,7 @@ class Signup_Field_Email extends Base_Signup_Field {
public function get_type(): string {
return 'email';
} // end get_type;
}
/**
* Returns if this field should be present on the checkout flow or not.
*
@ -41,8 +40,7 @@ class Signup_Field_Email extends Base_Signup_Field {
public function is_required(): bool {
return true;
} // end is_required;
}
/**
* Is this a user-related field?
*
@ -54,8 +52,7 @@ class Signup_Field_Email extends Base_Signup_Field {
public function is_user_field(): bool {
return false;
} // end is_user_field;
}
/**
* Requires the title of the field/element type.
@ -68,8 +65,7 @@ class Signup_Field_Email extends Base_Signup_Field {
public function get_title() {
return __('Email', 'wp-ultimo');
} // end get_title;
}
/**
* Returns the description of the field/element.
@ -82,8 +78,7 @@ class Signup_Field_Email extends Base_Signup_Field {
public function get_description() {
return __('Adds a email address field. This email address will be used to create the WordPress user.', 'wp-ultimo');
} // end get_description;
}
/**
* Returns the tooltip of the field/element.
@ -96,8 +91,7 @@ class Signup_Field_Email extends Base_Signup_Field {
public function get_tooltip() {
return __('Adds a email address field. This email address will be used to create the WordPress user.', 'wp-ultimo');
} // end get_tooltip;
}
/**
* Returns the icon to be used on the selector.
*
@ -108,8 +102,7 @@ class Signup_Field_Email extends Base_Signup_Field {
public function get_icon(): string {
return 'dashicons-wu-at-sign';
} // end get_icon;
}
/**
* Returns the default values for the field-elements.
@ -125,8 +118,7 @@ class Signup_Field_Email extends Base_Signup_Field {
return array(
'display_notices' => true,
);
} // end defaults;
}
/**
* List of keys of the default fields we want to display on the builder.
@ -141,8 +133,7 @@ class Signup_Field_Email extends Base_Signup_Field {
'placeholder',
'tooltip',
);
} // end default_fields;
}
/**
* If you want to force a particular attribute to a value, declare it here.
@ -156,8 +147,7 @@ class Signup_Field_Email extends Base_Signup_Field {
'id' => 'email_address',
'required' => true,
);
} // end force_attributes;
}
/**
* Returns the list of additional fields specific to this type.
@ -179,8 +169,7 @@ class Signup_Field_Email extends Base_Signup_Field {
),
),
);
} // end get_fields;
}
/**
* Returns the field/element actual field array to be used on the checkout form.
@ -195,9 +184,7 @@ class Signup_Field_Email extends Base_Signup_Field {
$checkout_fields = array();
if (is_user_logged_in()) {
if ($attributes['display_notices']) {
$checkout_fields['login_note'] = array(
'type' => 'note',
'title' => __('Not you?', 'wp-ultimo'),
@ -207,13 +194,9 @@ class Signup_Field_Email extends Base_Signup_Field {
'style' => $this->calculate_style_attr(),
),
);
} // end if;
}
} else {
if ($attributes['display_notices']) {
$checkout_fields['login_note'] = array(
'type' => 'note',
'title' => __('Existing customer?', 'wp-ultimo'),
@ -223,8 +206,7 @@ class Signup_Field_Email extends Base_Signup_Field {
'style' => $this->calculate_style_attr(),
),
);
} // end if;
}
$checkout_fields['email_address'] = array(
'type' => 'text',
@ -240,12 +222,10 @@ class Signup_Field_Email extends Base_Signup_Field {
'style' => $this->calculate_style_attr(),
),
);
} // end if;
}
return $checkout_fields;
} // end to_fields_array;
}
/**
* Renders the login message for users that are not logged in.
@ -273,8 +253,7 @@ class Signup_Field_Email extends Base_Signup_Field {
<?php // phpcs:enable
return ob_get_clean();
} // end render_existing_customer_message;
}
/**
* Renders the login message for users that are not logged in.
@ -302,7 +281,5 @@ class Signup_Field_Email extends Base_Signup_Field {
<?php
return ob_get_clean();
} // end render_not_you_customer_message;
} // end class Signup_Field_Email;
}
}

View File

@ -9,7 +9,7 @@
namespace WP_Ultimo\Checkout\Signup_Fields;
use \WP_Ultimo\Checkout\Signup_Fields\Base_Signup_Field;
use WP_Ultimo\Checkout\Signup_Fields\Base_Signup_Field;
// Exit if accessed directly
defined('ABSPATH') || exit;
@ -32,8 +32,7 @@ class Signup_Field_Hidden extends Base_Signup_Field {
public function get_type() {
return 'hidden';
} // end get_type;
}
/**
* Returns if this field should be present on the checkout flow or not.
@ -44,8 +43,7 @@ class Signup_Field_Hidden extends Base_Signup_Field {
public function is_required() {
return false;
} // end is_required;
}
/**
* Requires the title of the field/element type.
@ -58,8 +56,7 @@ class Signup_Field_Hidden extends Base_Signup_Field {
public function get_title() {
return __('Hidden Field', 'wp-ultimo');
} // end get_title;
}
/**
* Returns the description of the field/element.
@ -72,8 +69,7 @@ class Signup_Field_Hidden extends Base_Signup_Field {
public function get_description() {
return __('Adds a hidden field. This is useful when coupled with the "Fill from the Request" option, to load values from the URL, for example.', 'wp-ultimo');
} // end get_description;
}
/**
* Returns the tooltip of the field/element.
@ -86,8 +82,7 @@ class Signup_Field_Hidden extends Base_Signup_Field {
public function get_tooltip() {
return __('Adds a hidden field. This is useful when coupled with the "Fill from the Request" option, to load values from the URL, for example.', 'wp-ultimo');
} // end get_tooltip;
}
/**
* Returns the icon to be used on the selector.
@ -100,8 +95,7 @@ class Signup_Field_Hidden extends Base_Signup_Field {
public function get_icon() {
return 'dashicons-wu-eye-off';
} // end get_icon;
}
/**
* Returns the default values for the field-elements.
@ -117,8 +111,7 @@ class Signup_Field_Hidden extends Base_Signup_Field {
return array(
'from_request' => true,
);
} // end defaults;
}
/**
* List of keys of the default fields we want to display on the builder.
@ -132,8 +125,7 @@ class Signup_Field_Hidden extends Base_Signup_Field {
'id',
'save_as',
);
} // end default_fields;
}
/**
* If you want to force a particular attribute to a value, declare it here.
@ -144,8 +136,7 @@ class Signup_Field_Hidden extends Base_Signup_Field {
public function force_attributes() {
return array();
} // end force_attributes;
}
/**
* Returns the list of additional fields specific to this type.
@ -166,8 +157,7 @@ class Signup_Field_Hidden extends Base_Signup_Field {
'value' => '',
),
);
} // end get_fields;
}
/**
* Gets the pre-filled value for the field.
@ -180,14 +170,11 @@ class Signup_Field_Hidden extends Base_Signup_Field {
$value = parent::get_value();
if (empty($value)) {
$value = $this->attributes['fixed_value'];
} // end if;
}
return $value;
} // end get_value;
}
/**
* Returns the field/element actual field array to be used on the checkout form.
@ -207,7 +194,5 @@ class Signup_Field_Hidden extends Base_Signup_Field {
'value' => $this->get_value(),
),
);
} // end to_fields_array;
} // end class Signup_Field_Hidden;
}
}

View File

@ -9,8 +9,8 @@
namespace WP_Ultimo\Checkout\Signup_Fields;
use \WP_Ultimo\Checkout\Signup_Fields\Base_Signup_Field;
use \WP_Ultimo\Managers\Field_Templates_Manager;
use WP_Ultimo\Checkout\Signup_Fields\Base_Signup_Field;
use WP_Ultimo\Managers\Field_Templates_Manager;
// Exit if accessed directly
defined('ABSPATH') || exit;
@ -33,8 +33,7 @@ class Signup_Field_Order_Bump extends Base_Signup_Field {
public function get_type() {
return 'order_bump';
} // end get_type;
}
/**
* Returns if this field should be present on the checkout flow or not.
@ -45,8 +44,7 @@ class Signup_Field_Order_Bump extends Base_Signup_Field {
public function is_required() {
return false;
} // end is_required;
}
/**
* Requires the title of the field/element type.
@ -59,8 +57,7 @@ class Signup_Field_Order_Bump extends Base_Signup_Field {
public function get_title() {
return __('Order Bump', 'wp-ultimo');
} // end get_title;
}
/**
* Returns the description of the field/element.
@ -73,8 +70,7 @@ class Signup_Field_Order_Bump extends Base_Signup_Field {
public function get_description() {
return __('Adds a product offer that the customer can click to add to the current cart.', 'wp-ultimo');
} // end get_description;
}
/**
* Returns the tooltip of the field/element.
@ -87,8 +83,7 @@ class Signup_Field_Order_Bump extends Base_Signup_Field {
public function get_tooltip() {
return __('Adds a product offer that the customer can click to add to the current cart.', 'wp-ultimo');
} // end get_tooltip;
}
/**
* Returns the icon to be used on the selector.
@ -101,8 +96,7 @@ class Signup_Field_Order_Bump extends Base_Signup_Field {
public function get_icon() {
return 'dashicons-wu-gift';
} // end get_icon;
}
/**
* Returns the default values for the field-elements.
@ -119,8 +113,7 @@ class Signup_Field_Order_Bump extends Base_Signup_Field {
'order_bump_template' => 'simple',
'display_product_description' => 0,
);
} // end defaults;
}
/**
* List of keys of the default fields we want to display on the builder.
@ -134,8 +127,7 @@ class Signup_Field_Order_Bump extends Base_Signup_Field {
// 'id',
'name',
);
} // end default_fields;
}
/**
* If you want to force a particular attribute to a value, declare it here.
@ -148,8 +140,7 @@ class Signup_Field_Order_Bump extends Base_Signup_Field {
return array(
'order_bump_template' => 'simple',
);
} // end force_attributes;
}
/**
* Returns the list of available pricing table templates.
@ -162,8 +153,7 @@ class Signup_Field_Order_Bump extends Base_Signup_Field {
$available_templates = Field_Templates_Manager::get_instance()->get_templates_as_options('order_bump');
return $available_templates;
} // end get_templates;
}
/**
* Returns the list of additional fields specific to this type.
@ -233,8 +223,7 @@ class Signup_Field_Order_Bump extends Base_Signup_Field {
// );
return $editor_fields;
} // end get_fields;
}
/**
* Returns the field/element actual field array to be used on the checkout form.
@ -251,10 +240,8 @@ class Signup_Field_Order_Bump extends Base_Signup_Field {
$product = is_numeric($product_id) ? wu_get_product($product_id) : wu_get_product_by_slug($product_id);
if ( ! $product) {
return array();
} // end if;
}
$attributes['product'] = $product;
@ -269,7 +256,5 @@ class Signup_Field_Order_Bump extends Base_Signup_Field {
'wrapper_classes' => $attributes['element_classes'],
),
);
} // end to_fields_array;
} // end class Signup_Field_Order_Bump;
}
}

View File

@ -9,8 +9,8 @@
namespace WP_Ultimo\Checkout\Signup_Fields;
use \WP_Ultimo\Checkout\Signup_Fields\Base_Signup_Field;
use \WP_Ultimo\Managers\Field_Templates_Manager;
use WP_Ultimo\Checkout\Signup_Fields\Base_Signup_Field;
use WP_Ultimo\Managers\Field_Templates_Manager;
// Exit if accessed directly
defined('ABSPATH') || exit;
@ -32,8 +32,7 @@ class Signup_Field_Order_Summary extends Base_Signup_Field {
public function get_type(): string {
return 'order_summary';
} // end get_type;
}
/**
* Returns if this field should be present on the checkout flow or not.
*
@ -42,8 +41,7 @@ class Signup_Field_Order_Summary extends Base_Signup_Field {
public function is_required(): bool {
return true;
} // end is_required;
}
/**
* Requires the title of the field/element type.
@ -56,8 +54,7 @@ class Signup_Field_Order_Summary extends Base_Signup_Field {
public function get_title() {
return __('Order Summary', 'wp-ultimo');
} // end get_title;
}
/**
* Returns the description of the field/element.
@ -70,8 +67,7 @@ class Signup_Field_Order_Summary extends Base_Signup_Field {
public function get_description() {
return __('Adds a summary table with prices, key subscription dates, discounts, and taxes.', 'wp-ultimo');
} // end get_description;
}
/**
* Returns the tooltip of the field/element.
@ -84,8 +80,7 @@ class Signup_Field_Order_Summary extends Base_Signup_Field {
public function get_tooltip() {
return __('Adds a summary table with prices, key subscription dates, discounts, and taxes.', 'wp-ultimo');
} // end get_tooltip;
}
/**
* Returns the icon to be used on the selector.
*
@ -96,8 +91,7 @@ class Signup_Field_Order_Summary extends Base_Signup_Field {
public function get_icon(): string {
return 'dashicons-wu-dollar-sign';
} // end get_icon;
}
/**
* Returns the default values for the field-elements.
@ -114,8 +108,7 @@ class Signup_Field_Order_Summary extends Base_Signup_Field {
'order_summary_template' => 'clean',
'table_columns' => 'simple',
);
} // end defaults;
}
/**
* List of keys of the default fields we want to display on the builder.
@ -128,8 +121,7 @@ class Signup_Field_Order_Summary extends Base_Signup_Field {
return array(
'name',
);
} // end default_fields;
}
/**
* If you want to force a particular attribute to a value, declare it here.
@ -142,8 +134,7 @@ class Signup_Field_Order_Summary extends Base_Signup_Field {
return array(
'id' => 'order_summary',
);
} // end force_attributes;
}
/**
* Returns the list of available pricing table templates.
@ -156,8 +147,7 @@ class Signup_Field_Order_Summary extends Base_Signup_Field {
$available_templates = Field_Templates_Manager::get_instance()->get_templates_as_options('order_summary');
return $available_templates;
} // end get_templates;
}
/**
* Returns the list of additional fields specific to this type.
@ -176,7 +166,7 @@ class Signup_Field_Order_Summary extends Base_Signup_Field {
'options' => array(
'simple' => __('Simplified', 'wp-ultimo'),
'full' => __('Display All', 'wp-ultimo'),
)
),
);
$editor_fields['order_summary_template'] = array(
@ -206,8 +196,7 @@ class Signup_Field_Order_Summary extends Base_Signup_Field {
// );
return $editor_fields;
} // end get_fields;
}
/**
* Returns the field/element actual field array to be used on the checkout form.
@ -225,10 +214,8 @@ class Signup_Field_Order_Summary extends Base_Signup_Field {
* Backwards compatibility with previous betas
*/
if ($attributes['order_summary_template'] === 'simple') {
$attributes['order_summary_template'] = 'clean';
} // end if;
}
$template_class = Field_Templates_Manager::get_instance()->get_template_class('order_summary', $attributes['order_summary_template']);
@ -245,7 +232,5 @@ class Signup_Field_Order_Summary extends Base_Signup_Field {
);
return $checkout_fields;
} // end to_fields_array;
} // end class Signup_Field_Order_Summary;
}
}

View File

@ -9,7 +9,7 @@
namespace WP_Ultimo\Checkout\Signup_Fields;
use \WP_Ultimo\Checkout\Signup_Fields\Base_Signup_Field;
use WP_Ultimo\Checkout\Signup_Fields\Base_Signup_Field;
// Exit if accessed directly
defined('ABSPATH') || exit;
@ -32,8 +32,7 @@ class Signup_Field_Password extends Base_Signup_Field {
public function get_type() {
return 'password';
} // end get_type;
}
/**
* Returns if this field should be present on the checkout flow or not.
@ -44,8 +43,7 @@ class Signup_Field_Password extends Base_Signup_Field {
public function is_required() {
return true;
} // end is_required;
}
/**
* Is this a user-related field?
@ -59,8 +57,7 @@ class Signup_Field_Password extends Base_Signup_Field {
public function is_user_field() {
return true;
} // end is_user_field;
}
/**
* Requires the title of the field/element type.
@ -73,8 +70,7 @@ class Signup_Field_Password extends Base_Signup_Field {
public function get_title() {
return __('Password', 'wp-ultimo');
} // end get_title;
}
/**
* Returns the description of the field/element.
@ -87,8 +83,7 @@ class Signup_Field_Password extends Base_Signup_Field {
public function get_description() {
return __('Adds a password field, with options for enforcing password strength and adding password confirmation field. This password is then used to create the WordPress user.', 'wp-ultimo');
} // end get_description;
}
/**
* Returns the tooltip of the field/element.
@ -101,8 +96,7 @@ class Signup_Field_Password extends Base_Signup_Field {
public function get_tooltip() {
return __('Adds a password field, with options for enforcing password strength and adding password confirmation field. This password is then used to create the WordPress user.', 'wp-ultimo');
} // end get_tooltip;
}
/**
* Returns the icon to be used on the selector.
@ -115,8 +109,7 @@ class Signup_Field_Password extends Base_Signup_Field {
public function get_icon() {
return 'dashicons-wu-lock1';
} // end get_icon;
}
/**
* Returns the default values for the field-elements.
@ -133,8 +126,7 @@ class Signup_Field_Password extends Base_Signup_Field {
'password_confirm_field' => false,
'password_confirm_label' => __('Confirm Password', 'wp-ultimo'),
);
} // end defaults;
}
/**
* List of keys of the default fields we want to display on the builder.
@ -149,8 +141,7 @@ class Signup_Field_Password extends Base_Signup_Field {
'placeholder',
'tooltip',
);
} // end default_fields;
}
/**
* If you want to force a particular attribute to a value, declare it here.
@ -164,8 +155,7 @@ class Signup_Field_Password extends Base_Signup_Field {
'id' => 'password',
'required' => true,
);
} // end force_attributes;
}
/**
* Returns the list of additional fields specific to this type.
@ -189,8 +179,7 @@ class Signup_Field_Password extends Base_Signup_Field {
'value' => 1,
),
);
} // end get_fields;
}
/**
* Returns the field/element actual field array to be used on the checkout form.
@ -205,10 +194,8 @@ class Signup_Field_Password extends Base_Signup_Field {
* Logged in user, bail.
*/
if (is_user_logged_in()) {
return array();
} // end if;
}
$checkout_fields = array();
@ -231,7 +218,6 @@ class Signup_Field_Password extends Base_Signup_Field {
);
if ($attributes['password_confirm_field']) {
$checkout_fields['password_conf'] = array(
'type' => 'password',
'id' => 'password_conf',
@ -249,11 +235,8 @@ class Signup_Field_Password extends Base_Signup_Field {
'style' => $this->calculate_style_attr(),
),
);
} // end if;
}
return $checkout_fields;
} // end to_fields_array;
} // end class Signup_Field_Password;
}
}

View File

@ -9,8 +9,8 @@
namespace WP_Ultimo\Checkout\Signup_Fields;
use \WP_Ultimo\Checkout\Signup_Fields\Base_Signup_Field;
use \WP_Ultimo\Managers\Gateway_Manager;
use WP_Ultimo\Checkout\Signup_Fields\Base_Signup_Field;
use WP_Ultimo\Managers\Gateway_Manager;
// Exit if accessed directly
defined('ABSPATH') || exit;
@ -33,8 +33,7 @@ class Signup_Field_Payment extends Base_Signup_Field {
public function get_type() {
return 'payment';
} // end get_type;
}
/**
* Returns if this field should be present on the checkout flow or not.
@ -45,8 +44,7 @@ class Signup_Field_Payment extends Base_Signup_Field {
public function is_required() {
return true;
} // end is_required;
}
/**
* Requires the title of the field/element type.
@ -59,8 +57,7 @@ class Signup_Field_Payment extends Base_Signup_Field {
public function get_title() {
return __('Payment', 'wp-ultimo');
} // end get_title;
}
/**
* Returns the description of the field/element.
@ -73,8 +70,7 @@ class Signup_Field_Payment extends Base_Signup_Field {
public function get_description() {
return __('Adds the payment options and the additional fields required to complete a purchase (e.g. credit card field).', 'wp-ultimo');
} // end get_description;
}
/**
* Returns the tooltip of the field/element.
@ -87,8 +83,7 @@ class Signup_Field_Payment extends Base_Signup_Field {
public function get_tooltip() {
return __('Adds the payment options and the additional fields required to complete a purchase (e.g. credit card field).', 'wp-ultimo');
} // end get_tooltip;
}
/**
* Returns the icon to be used on the selector.
@ -101,8 +96,7 @@ class Signup_Field_Payment extends Base_Signup_Field {
public function get_icon() {
return 'dashicons-wu-credit-card2';
} // end get_icon;
}
/**
* Returns the default values for the field-elements.
@ -116,10 +110,9 @@ class Signup_Field_Payment extends Base_Signup_Field {
public function defaults() {
return array(
''
'',
);
} // end defaults;
}
/**
* List of keys of the default fields we want to display on the builder.
@ -132,8 +125,7 @@ class Signup_Field_Payment extends Base_Signup_Field {
return array(
'name',
);
} // end default_fields;
}
/**
* If you want to force a particular attribute to a value, declare it here.
@ -146,8 +138,7 @@ class Signup_Field_Payment extends Base_Signup_Field {
return array(
'id' => 'payment',
);
} // end force_attributes;
}
/**
* Returns the list of additional fields specific to this type.
@ -158,8 +149,7 @@ class Signup_Field_Payment extends Base_Signup_Field {
public function get_fields() {
return array();
} // end get_fields;
}
/**
* Returns the field/element actual field array to be used on the checkout form.
@ -195,7 +185,6 @@ class Signup_Field_Payment extends Base_Signup_Field {
* auto renew field.
*/
if ( ! wu_get_setting('force_auto_renew', 1)) {
$auto_renewable_gateways = Gateway_Manager::get_instance()->get_auto_renewable_gateways();
$fields['auto_renew'] = array(
@ -212,13 +201,10 @@ class Signup_Field_Payment extends Base_Signup_Field {
'wrapper_html_attr' => array(
'v-cloak' => 1,
'v-show' => sprintf('%s.includes(gateway) && order.should_collect_payment && order.has_recurring', json_encode($auto_renewable_gateways)),
)
),
);
} // end if;
}
return $fields;
} // end to_fields_array;
} // end class Signup_Field_Payment;
}
}

View File

@ -9,8 +9,8 @@
namespace WP_Ultimo\Checkout\Signup_Fields;
use \WP_Ultimo\Checkout\Signup_Fields\Base_Signup_Field;
use \WP_Ultimo\Managers\Field_Templates_Manager;
use WP_Ultimo\Checkout\Signup_Fields\Base_Signup_Field;
use WP_Ultimo\Managers\Field_Templates_Manager;
// Exit if accessed directly
defined('ABSPATH') || exit;
@ -32,8 +32,7 @@ class Signup_Field_Period_Selection extends Base_Signup_Field {
public function get_type(): string {
return 'period_selection';
} // end get_type;
}
/**
* Returns if this field should be present on the checkout flow or not.
*
@ -42,8 +41,7 @@ class Signup_Field_Period_Selection extends Base_Signup_Field {
public function is_required(): bool {
return false;
} // end is_required;
}
/**
* Requires the title of the field/element type.
@ -56,8 +54,7 @@ class Signup_Field_Period_Selection extends Base_Signup_Field {
public function get_title() {
return __('Period Select', 'wp-ultimo');
} // end get_title;
}
/**
* Returns the description of the field/element.
@ -70,8 +67,7 @@ class Signup_Field_Period_Selection extends Base_Signup_Field {
public function get_description() {
return __('Adds a period selector, that allows customers to switch between different billing periods.', 'wp-ultimo');
} // end get_description;
}
/**
* Returns the tooltip of the field/element.
@ -84,8 +80,7 @@ class Signup_Field_Period_Selection extends Base_Signup_Field {
public function get_tooltip() {
return __('Adds a period selector, that allows customers to switch between different billing periods.', 'wp-ultimo');
} // end get_tooltip;
}
/**
* Returns the icon to be used on the selector.
*
@ -96,8 +91,7 @@ class Signup_Field_Period_Selection extends Base_Signup_Field {
public function get_icon(): string {
return 'dashicons-wu dashicons-wu-toggle-right';
} // end get_icon;
}
/**
* Returns the default values for the field-elements.
@ -113,8 +107,7 @@ class Signup_Field_Period_Selection extends Base_Signup_Field {
return array(
'period_selection_template' => 'clean',
);
} // end defaults;
}
/**
* List of keys of the default fields we want to display on the builder.
@ -127,8 +120,7 @@ class Signup_Field_Period_Selection extends Base_Signup_Field {
return array(
// 'name',
);
} // end default_fields;
}
/**
* If you want to force a particular attribute to a value, declare it here.
@ -143,8 +135,7 @@ class Signup_Field_Period_Selection extends Base_Signup_Field {
'name' => __('Plan Duration Switch', 'wp-ultimo'),
'required' => true,
);
} // end force_attributes;
}
/**
* Returns the list of available pricing table templates.
@ -157,8 +148,7 @@ class Signup_Field_Period_Selection extends Base_Signup_Field {
$available_templates = Field_Templates_Manager::get_instance()->get_templates_as_options('period_selection');
return $available_templates;
} // end get_template_options;
}
/**
* Returns the list of additional fields specific to this type.
@ -283,8 +273,7 @@ class Signup_Field_Period_Selection extends Base_Signup_Field {
);
return $editor_fields;
} // end get_fields;
}
/**
* Returns the field/element actual field array to be used on the checkout form.
@ -297,14 +286,12 @@ class Signup_Field_Period_Selection extends Base_Signup_Field {
public function to_fields_array($attributes) {
if (wu_get_isset($attributes, 'period_selection_template') === 'legacy') {
wp_register_script('wu-legacy-signup', wu_get_asset('legacy-signup.js', 'js'), array('wu-functions'), wu_get_version());
wp_enqueue_script('wu-legacy-signup');
wp_enqueue_style('legacy-shortcodes', wu_get_asset('legacy-shortcodes.css', 'css'), array('dashicons'), wu_get_version());
} // end if;
}
$template_class = Field_Templates_Manager::get_instance()->get_template_class('period_selection', $attributes['period_selection_template']);
@ -334,7 +321,5 @@ class Signup_Field_Period_Selection extends Base_Signup_Field {
);
return $checkout_fields;
} // end to_fields_array;
} // end class Signup_Field_Period_Selection;
}
}

View File

@ -9,8 +9,8 @@
namespace WP_Ultimo\Checkout\Signup_Fields;
use \WP_Ultimo\Checkout\Signup_Fields\Base_Signup_Field;
use \WP_Ultimo\Managers\Field_Templates_Manager;
use WP_Ultimo\Checkout\Signup_Fields\Base_Signup_Field;
use WP_Ultimo\Managers\Field_Templates_Manager;
// Exit if accessed directly
defined('ABSPATH') || exit;
@ -32,8 +32,7 @@ class Signup_Field_Pricing_Table extends Base_Signup_Field {
public function get_type(): string {
return 'pricing_table';
} // end get_type;
}
/**
* Returns if this field should be present on the checkout flow or not.
*
@ -42,8 +41,7 @@ class Signup_Field_Pricing_Table extends Base_Signup_Field {
public function is_required(): bool {
return false;
} // end is_required;
}
/**
* Requires the title of the field/element type.
@ -56,8 +54,7 @@ class Signup_Field_Pricing_Table extends Base_Signup_Field {
public function get_title() {
return __('Pricing Table', 'wp-ultimo');
} // end get_title;
}
/**
* Returns the description of the field/element.
@ -70,8 +67,7 @@ class Signup_Field_Pricing_Table extends Base_Signup_Field {
public function get_description() {
return __('Adds a pricing table section that customers can use to choose a plan to subscribe to.', 'wp-ultimo');
} // end get_description;
}
/**
* Returns the tooltip of the field/element.
@ -84,8 +80,7 @@ class Signup_Field_Pricing_Table extends Base_Signup_Field {
public function get_tooltip() {
return __('Adds a pricing table section that customers can use to choose a plan to subscribe to.', 'wp-ultimo');
} // end get_tooltip;
}
/**
* Returns the icon to be used on the selector.
*
@ -96,8 +91,7 @@ class Signup_Field_Pricing_Table extends Base_Signup_Field {
public function get_icon(): string {
return 'dashicons-wu dashicons-wu-columns';
} // end get_icon;
}
/**
* Returns the default values for the field-elements.
@ -116,8 +110,7 @@ class Signup_Field_Pricing_Table extends Base_Signup_Field {
'force_different_durations' => false,
'hide_pricing_table_when_pre_selected' => false,
);
} // end defaults;
}
/**
* List of keys of the default fields we want to display on the builder.
@ -130,8 +123,7 @@ class Signup_Field_Pricing_Table extends Base_Signup_Field {
return array(
// 'name',
);
} // end default_fields;
}
/**
* If you want to force a particular attribute to a value, declare it here.
@ -146,8 +138,7 @@ class Signup_Field_Pricing_Table extends Base_Signup_Field {
'name' => __('Plan Selection', 'wp-ultimo'),
'required' => true,
);
} // end force_attributes;
}
/**
* Returns the list of available pricing table templates.
@ -160,8 +151,7 @@ class Signup_Field_Pricing_Table extends Base_Signup_Field {
$available_templates = Field_Templates_Manager::get_instance()->get_templates_as_options('pricing_table');
return $available_templates;
} // end get_pricing_table_templates;
}
/**
* Returns the list of additional fields specific to this type.
@ -242,8 +232,7 @@ class Signup_Field_Pricing_Table extends Base_Signup_Field {
// );
return $editor_fields;
} // end get_fields;
}
/**
* Returns the field/element actual field array to be used on the checkout form.
@ -256,12 +245,10 @@ class Signup_Field_Pricing_Table extends Base_Signup_Field {
public function to_fields_array($attributes) {
if (wu_get_isset($attributes, 'pricing_table_template') === 'legacy') {
wp_enqueue_style('legacy-shortcodes', wu_get_asset('legacy-shortcodes.css', 'css'), array('dashicons'), wu_get_version());
wp_add_inline_style('legacy-shortcodes', \WP_Ultimo\Checkout\Legacy_Checkout::get_instance()->get_legacy_dynamic_styles());
} // end if;
}
$product_list = explode(',', (string) $attributes['pricing_table_products']);
@ -276,10 +263,8 @@ class Signup_Field_Pricing_Table extends Base_Signup_Field {
* Hide when pre-selected.
*/
if (wu_should_hide_form_field($attributes)) {
return array();
} // end if;
}
$template_attributes = array(
'products' => $products,
@ -306,7 +291,5 @@ class Signup_Field_Pricing_Table extends Base_Signup_Field {
);
return $checkout_fields;
} // end to_fields_array;
} // end class Signup_Field_Pricing_Table;
}
}

View File

@ -9,7 +9,7 @@
namespace WP_Ultimo\Checkout\Signup_Fields;
use \WP_Ultimo\Checkout\Signup_Fields\Base_Signup_Field;
use WP_Ultimo\Checkout\Signup_Fields\Base_Signup_Field;
// Exit if accessed directly
defined('ABSPATH') || exit;
@ -31,8 +31,7 @@ class Signup_Field_Products extends Base_Signup_Field {
public function get_type(): string {
return 'products';
} // end get_type;
}
/**
* Returns if this field should be present on the checkout flow or not.
*
@ -41,8 +40,7 @@ class Signup_Field_Products extends Base_Signup_Field {
public function is_required(): bool {
return false;
} // end is_required;
}
/**
* Requires the title of the field/element type.
@ -55,8 +53,7 @@ class Signup_Field_Products extends Base_Signup_Field {
public function get_title() {
return __('Product', 'wp-ultimo');
} // end get_title;
}
/**
* Returns the description of the field/element.
@ -69,8 +66,7 @@ class Signup_Field_Products extends Base_Signup_Field {
public function get_description() {
return __('Hidden field used to pre-select products. This is useful when you have a signup page for specific offering/bundles and do not want your customers to be able to choose plans and products manually.', 'wp-ultimo');
} // end get_description;
}
/**
* Returns the tooltip of the field/element.
@ -83,8 +79,7 @@ class Signup_Field_Products extends Base_Signup_Field {
public function get_tooltip() {
return __('Hidden field used to pre-select products. This is useful when you have a signup page for specific offering/bundles and do not want your customers to be able to choose plans and products manually.', 'wp-ultimo');
} // end get_tooltip;
}
/**
* Returns the icon to be used on the selector.
*
@ -95,8 +90,7 @@ class Signup_Field_Products extends Base_Signup_Field {
public function get_icon(): string {
return 'dashicons-wu dashicons-wu-package';
} // end get_icon;
}
/**
* Returns the default values for the field-elements.
@ -110,10 +104,9 @@ class Signup_Field_Products extends Base_Signup_Field {
public function defaults() {
return array(
''
'',
);
} // end defaults;
}
/**
* List of keys of the default fields we want to display on the builder.
@ -124,8 +117,7 @@ class Signup_Field_Products extends Base_Signup_Field {
public function default_fields() {
return array();
} // end default_fields;
}
/**
* If you want to force a particular attribute to a value, declare it here.
@ -139,8 +131,7 @@ class Signup_Field_Products extends Base_Signup_Field {
'name' => __('Pre-selected Products', 'wp-ultimo'),
'id' => 'products',
);
} // end force_attributes;
}
/**
* Returns the list of additional fields specific to this type.
@ -166,8 +157,7 @@ class Signup_Field_Products extends Base_Signup_Field {
),
),
);
} // end get_fields;
}
/**
* Returns the field/element actual field array to be used on the checkout form.
@ -184,7 +174,6 @@ class Signup_Field_Products extends Base_Signup_Field {
$products = explode(',', (string) $attributes['products']);
foreach ($products as $product_id) {
$checkout_fields[ "products[{$product_id}]" ] = array(
'type' => 'hidden',
'value' => $product_id,
@ -192,14 +181,12 @@ class Signup_Field_Products extends Base_Signup_Field {
'v-bind:name' => "'products[]'",
),
);
} // end foreach;
}
$this->insert_products_in_form($products);
return $checkout_fields;
} // end to_fields_array;
}
/**
* Inserts the products in the form.
@ -212,10 +199,8 @@ class Signup_Field_Products extends Base_Signup_Field {
static $added = false;
if ($added) {
return;
} // end if;
}
$added = true;
@ -224,24 +209,23 @@ class Signup_Field_Products extends Base_Signup_Field {
data.products.push(...%s);
data.products = data.products.map((value) => parseInt(value) || value);
data.products = [...new Set(data.products)];
} // end if;
}
return data;
});";
if (did_action('wu-checkout')) {
wp_add_inline_script('wu-checkout', sprintf($script, json_encode($products)), 'before');
return;
}
} // end if;
add_action('wp_enqueue_scripts', function() use ($script, $products) {
add_action(
'wp_enqueue_scripts',
function () use ($script, $products) {
wp_add_inline_script('wu-checkout', sprintf($script, json_encode($products)), 'before');
}, 11);
} // end insert_products_in_form;
} // end class Signup_Field_Products;
},
11
);
}
}

View File

@ -9,7 +9,7 @@
namespace WP_Ultimo\Checkout\Signup_Fields;
use \WP_Ultimo\Checkout\Signup_Fields\Base_Signup_Field;
use WP_Ultimo\Checkout\Signup_Fields\Base_Signup_Field;
// Exit if accessed directly
defined('ABSPATH') || exit;
@ -32,8 +32,7 @@ class Signup_Field_Select extends Base_Signup_Field {
public function get_type() {
return 'select';
} // end get_type;
}
/**
* Returns if this field should be present on the checkout flow or not.
@ -44,8 +43,7 @@ class Signup_Field_Select extends Base_Signup_Field {
public function is_required() {
return false;
} // end is_required;
}
/**
* Requires the title of the field/element type.
@ -58,8 +56,7 @@ class Signup_Field_Select extends Base_Signup_Field {
public function get_title() {
return __('Select', 'wp-ultimo');
} // end get_title;
}
/**
* Returns the description of the field/element.
@ -72,8 +69,7 @@ class Signup_Field_Select extends Base_Signup_Field {
public function get_description() {
return __('Adds a select field.', 'wp-ultimo');
} // end get_description;
}
/**
* Returns the tooltip of the field/element.
@ -86,8 +82,7 @@ class Signup_Field_Select extends Base_Signup_Field {
public function get_tooltip() {
return __('Adds a select field.', 'wp-ultimo');
} // end get_tooltip;
}
/**
* Returns the icon to be used on the selector.
@ -100,8 +95,7 @@ class Signup_Field_Select extends Base_Signup_Field {
public function get_icon() {
return 'dashicons-wu-list1';
} // end get_icon;
}
/**
* Returns the default values for the field-elements.
@ -115,10 +109,9 @@ class Signup_Field_Select extends Base_Signup_Field {
public function defaults() {
return array(
''
'',
);
} // end defaults;
}
/**
* List of keys of the default fields we want to display on the builder.
@ -137,8 +130,7 @@ class Signup_Field_Select extends Base_Signup_Field {
'required',
'save_as',
);
} // end default_fields;
}
/**
* If you want to force a particular attribute to a value, declare it here.
@ -149,8 +141,7 @@ class Signup_Field_Select extends Base_Signup_Field {
public function force_attributes() {
return array();
} // end force_attributes;
}
/**
* Returns the list of additional fields specific to this type.
@ -237,8 +228,7 @@ class Signup_Field_Select extends Base_Signup_Field {
);
return $editor_fields;
} // end get_fields;
}
/**
* Returns the field/element actual field array to be used on the checkout form.
@ -253,10 +243,8 @@ class Signup_Field_Select extends Base_Signup_Field {
$options = array();
foreach ($attributes['options'] as $_option) {
$options[ $_option['key'] ] = $_option['label'];
} // end foreach;
}
return array(
$attributes['id'] => array(
@ -272,7 +260,5 @@ class Signup_Field_Select extends Base_Signup_Field {
'value' => $this->get_value(),
),
);
} // end to_fields_array;
} // end class Signup_Field_Select;
}
}

View File

@ -9,7 +9,7 @@
namespace WP_Ultimo\Checkout\Signup_Fields;
use \WP_Ultimo\Checkout\Signup_Fields\Base_Signup_Field;
use WP_Ultimo\Checkout\Signup_Fields\Base_Signup_Field;
// Exit if accessed directly
defined('ABSPATH') || exit;
@ -31,8 +31,7 @@ class Signup_Field_Shortcode extends Base_Signup_Field {
public function get_type(): string {
return 'shortcode';
} // end get_type;
}
/**
* Returns if this field should be present on the checkout flow or not.
*
@ -41,8 +40,7 @@ class Signup_Field_Shortcode extends Base_Signup_Field {
public function is_required(): bool {
return false;
} // end is_required;
}
/**
* Requires the title of the field/element type.
@ -55,8 +53,7 @@ class Signup_Field_Shortcode extends Base_Signup_Field {
public function get_title() {
return __('Shortcode', 'wp-ultimo');
} // end get_title;
}
/**
* Returns the description of the field/element.
@ -69,8 +66,7 @@ class Signup_Field_Shortcode extends Base_Signup_Field {
public function get_description() {
return __('Displays the content of a given WordPress shortcode. Can be useful to inset content from other plugins inside a WP Multisite WaaS checkout form.', 'wp-ultimo');
} // end get_description;
}
/**
* Returns the tooltip of the field/element.
@ -83,8 +79,7 @@ class Signup_Field_Shortcode extends Base_Signup_Field {
public function get_tooltip() {
return __('Displays the content of a given WordPress shortcode. Can be useful to insert content from other plugins inside a WP Multisite WaaS checkout form.', 'wp-ultimo');
} // end get_tooltip;
}
/**
* Returns the icon to be used on the selector.
*
@ -95,8 +90,7 @@ class Signup_Field_Shortcode extends Base_Signup_Field {
public function get_icon(): string {
return 'dashicons-wu-terminal';
} // end get_icon;
}
/**
* Returns the default values for the field-elements.
@ -110,10 +104,9 @@ class Signup_Field_Shortcode extends Base_Signup_Field {
public function defaults() {
return array(
''
'',
);
} // end defaults;
}
/**
* List of keys of the default fields we want to display on the builder.
@ -127,8 +120,7 @@ class Signup_Field_Shortcode extends Base_Signup_Field {
// 'id',
// 'name',
);
} // end default_fields;
}
/**
* If you want to force a particular attribute to a value, declare it here.
@ -141,8 +133,7 @@ class Signup_Field_Shortcode extends Base_Signup_Field {
return array(
'name' => __('Shortcode', 'wp-ultimo'),
);
} // end force_attributes;
}
/**
* Returns the list of additional fields specific to this type.
@ -160,8 +151,7 @@ class Signup_Field_Shortcode extends Base_Signup_Field {
'desc' => __('Please, enter the full shortcode, including [].', 'wp-ultimo'),
),
);
} // end get_fields;
}
/**
* Returns the field/element actual field array to be used on the checkout form.
@ -184,7 +174,5 @@ class Signup_Field_Shortcode extends Base_Signup_Field {
),
),
);
} // end to_fields_array;
} // end class Signup_Field_Shortcode;
}
}

View File

@ -9,7 +9,7 @@
namespace WP_Ultimo\Checkout\Signup_Fields;
use \WP_Ultimo\Checkout\Signup_Fields\Base_Signup_Field;
use WP_Ultimo\Checkout\Signup_Fields\Base_Signup_Field;
// Exit if accessed directly
defined('ABSPATH') || exit;
@ -32,8 +32,7 @@ class Signup_Field_Site_Title extends Base_Signup_Field {
public function get_type() {
return 'site_title';
} // end get_type;
}
/**
* Returns if this field should be present on the checkout flow or not.
@ -44,8 +43,7 @@ class Signup_Field_Site_Title extends Base_Signup_Field {
public function is_required() {
return false;
} // end is_required;
}
/**
* Defines if this field/element is related to site creation or not.
@ -56,8 +54,7 @@ class Signup_Field_Site_Title extends Base_Signup_Field {
public function is_site_field() {
return true;
} // end is_site_field;
}
/**
* Requires the title of the field/element type.
@ -70,8 +67,7 @@ class Signup_Field_Site_Title extends Base_Signup_Field {
public function get_title() {
return __('Site Title', 'wp-ultimo');
} // end get_title;
}
/**
* Returns the description of the field/element.
@ -84,8 +80,7 @@ class Signup_Field_Site_Title extends Base_Signup_Field {
public function get_description() {
return __('Adds a Site Title field. This value is used to set the site title for the site being created.', 'wp-ultimo');
} // end get_description;
}
/**
* Returns the tooltip of the field/element.
@ -98,8 +93,7 @@ class Signup_Field_Site_Title extends Base_Signup_Field {
public function get_tooltip() {
return __('Adds a Site Title field. This value is used to set the site title for the site being created.', 'wp-ultimo');
} // end get_tooltip;
}
/**
* Returns the icon to be used on the selector.
@ -112,8 +106,7 @@ class Signup_Field_Site_Title extends Base_Signup_Field {
public function get_icon() {
return 'dashicons-wu-type';
} // end get_icon;
}
/**
* Returns the default values for the field-elements.
@ -129,8 +122,7 @@ class Signup_Field_Site_Title extends Base_Signup_Field {
return array(
'auto_generate_site_title' => false,
);
} // end defaults;
}
/**
* List of keys of the default fields we want to display on the builder.
@ -145,8 +137,7 @@ class Signup_Field_Site_Title extends Base_Signup_Field {
'placeholder',
'tooltip',
);
} // end default_fields;
}
/**
* If you want to force a particular attribute to a value, declare it here.
@ -160,8 +151,7 @@ class Signup_Field_Site_Title extends Base_Signup_Field {
'id' => 'site_title',
'required' => true,
);
} // end force_attributes;
}
/**
* Returns the list of additional fields specific to this type.
@ -183,8 +173,7 @@ class Signup_Field_Site_Title extends Base_Signup_Field {
),
),
);
} // end get_fields;
}
/**
* Returns the field/element actual field array to be used on the checkout form.
@ -199,7 +188,6 @@ class Signup_Field_Site_Title extends Base_Signup_Field {
* If we should auto-generate, add as hidden.
*/
if (isset($attributes['auto_generate_site_title']) && $attributes['auto_generate_site_title']) {
return array(
'auto_generate_site_title' => array(
'type' => 'hidden',
@ -211,11 +199,10 @@ class Signup_Field_Site_Title extends Base_Signup_Field {
'id' => 'site_title',
'html_attr' => array(
'v-bind:value' => 'username',
)
),
),
);
} // end if;
}
return array(
'site_title' => array(
@ -233,7 +220,5 @@ class Signup_Field_Site_Title extends Base_Signup_Field {
),
),
);
} // end to_fields_array;
} // end class Signup_Field_Site_Title;
}
}

View File

@ -9,7 +9,7 @@
namespace WP_Ultimo\Checkout\Signup_Fields;
use \WP_Ultimo\Checkout\Signup_Fields\Base_Signup_Field;
use WP_Ultimo\Checkout\Signup_Fields\Base_Signup_Field;
// Exit if accessed directly
defined('ABSPATH') || exit;
@ -31,8 +31,7 @@ class Signup_Field_Site_Url extends Base_Signup_Field {
public function get_type(): string {
return 'site_url';
} // end get_type;
}
/**
* Returns if this field should be present on the checkout flow or not.
*
@ -41,8 +40,7 @@ class Signup_Field_Site_Url extends Base_Signup_Field {
public function is_required(): bool {
return false;
} // end is_required;
}
/**
* Defines if this field/element is related to site creation or not.
*
@ -51,8 +49,7 @@ class Signup_Field_Site_Url extends Base_Signup_Field {
public function is_site_field(): bool {
return true;
} // end is_site_field;
}
/**
* Requires the title of the field/element type.
@ -65,8 +62,7 @@ class Signup_Field_Site_Url extends Base_Signup_Field {
public function get_title() {
return __('Site URL', 'wp-ultimo');
} // end get_title;
}
/**
* Returns the description of the field/element.
@ -79,8 +75,7 @@ class Signup_Field_Site_Url extends Base_Signup_Field {
public function get_description() {
return __('Adds a Site URL field. This is used to set the URL of the site being created.', 'wp-ultimo');
} // end get_description;
}
/**
* Returns the tooltip of the field/element.
@ -93,8 +88,7 @@ class Signup_Field_Site_Url extends Base_Signup_Field {
public function get_tooltip() {
return __('Adds a Site URL field. This is used to set the URL of the site being created.', 'wp-ultimo');
} // end get_tooltip;
}
/**
* Returns the icon to be used on the selector.
*
@ -105,8 +99,7 @@ class Signup_Field_Site_Url extends Base_Signup_Field {
public function get_icon(): string {
return 'dashicons-wu-globe1';
} // end get_icon;
}
/**
* Returns the default values for the field-elements.
@ -128,8 +121,7 @@ class Signup_Field_Site_Url extends Base_Signup_Field {
'display_field_attachments' => true,
'available_domains' => $current_site->domain . PHP_EOL,
);
} // end defaults;
}
/**
* List of keys of the default fields we want to display on the builder.
@ -144,8 +136,7 @@ class Signup_Field_Site_Url extends Base_Signup_Field {
'placeholder',
'tooltip',
);
} // end default_fields;
}
/**
* If you want to force a particular attribute to a value, declare it here.
@ -159,8 +150,7 @@ class Signup_Field_Site_Url extends Base_Signup_Field {
'id' => 'site_url',
'required' => true,
);
} // end force_attributes;
}
/**
* Returns the list of additional fields specific to this type.
@ -246,8 +236,7 @@ class Signup_Field_Site_Url extends Base_Signup_Field {
),
),
);
} // end get_fields;
}
/**
* Returns the list of available pricing table templates.
@ -263,8 +252,7 @@ class Signup_Field_Site_Url extends Base_Signup_Field {
);
return apply_filters('wu_get_pricing_table_templates', $templates);
} // end get_url_preview_templates;
}
/**
* Returns the field/element actual field array to be used on the checkout form.
@ -279,7 +267,6 @@ class Signup_Field_Site_Url extends Base_Signup_Field {
* If we should auto-generate, add as hidden.
*/
if ($attributes['auto_generate_site_url']) {
return array(
'auto_generate_site_url' => array(
'type' => 'hidden',
@ -292,8 +279,7 @@ class Signup_Field_Site_Url extends Base_Signup_Field {
'value' => uniqid(),
),
);
} // end if;
}
$checkout_fields = array();
@ -316,7 +302,6 @@ class Signup_Field_Site_Url extends Base_Signup_Field {
);
if ($attributes['display_field_attachments']) {
$checkout_fields['site_url']['classes'] .= ' xs:wu-rounded-none';
$checkout_fields['site_url']['prefix'] = ' ';
@ -337,11 +322,9 @@ class Signup_Field_Site_Url extends Base_Signup_Field {
'v-cloak' => 1,
'v-show' => 'is_subdomain',
);
} // end if;
}
if ($attributes['available_domains'] && $attributes['enable_domain_selection']) {
$options = $this->get_domain_options($attributes['available_domains']);
$checkout_fields['site_domain'] = array(
@ -361,11 +344,9 @@ class Signup_Field_Site_Url extends Base_Signup_Field {
'style' => $this->calculate_style_attr(),
),
);
} // end if;
}
if ($attributes['display_url_preview']) {
$content = wu_get_template_contents('legacy/signup/steps/step-domain-url-preview');
$checkout_fields['site_url_preview'] = array(
@ -377,12 +358,10 @@ class Signup_Field_Site_Url extends Base_Signup_Field {
'style' => $this->calculate_style_attr(),
),
);
} // end if;
}
return $checkout_fields;
} // end to_fields_array;
}
/**
* Get the domain options.
*
@ -397,7 +376,5 @@ class Signup_Field_Site_Url extends Base_Signup_Field {
$domains = array_map(fn($item) => trim((string) $item), $domains);
return array_combine($domains, $domains);
} // end get_domain_options;
} // end class Signup_Field_Site_Url;
}
}

View File

@ -9,8 +9,8 @@
namespace WP_Ultimo\Checkout\Signup_Fields;
use \WP_Ultimo\Checkout\Signup_Fields\Base_Signup_Field;
use \WP_Ultimo\Managers\Field_Templates_Manager;
use WP_Ultimo\Checkout\Signup_Fields\Base_Signup_Field;
use WP_Ultimo\Managers\Field_Templates_Manager;
// Exit if accessed directly
defined('ABSPATH') || exit;
@ -32,8 +32,7 @@ class Signup_Field_Steps extends Base_Signup_Field {
public function get_type(): string {
return 'steps';
} // end get_type;
}
/**
* Returns if this field should be present on the checkout flow or not.
*
@ -42,8 +41,7 @@ class Signup_Field_Steps extends Base_Signup_Field {
public function is_required(): bool {
return false;
} // end is_required;
}
/**
* Requires the title of the field/element type.
@ -56,8 +54,7 @@ class Signup_Field_Steps extends Base_Signup_Field {
public function get_title() {
return __('Steps', 'wp-ultimo');
} // end get_title;
}
/**
* Returns the description of the field/element.
@ -70,8 +67,7 @@ class Signup_Field_Steps extends Base_Signup_Field {
public function get_description() {
return __('Adds a list of the steps.', 'wp-ultimo');
} // end get_description;
}
/**
* Returns the tooltip of the field/element.
@ -84,8 +80,7 @@ class Signup_Field_Steps extends Base_Signup_Field {
public function get_tooltip() {
return __('Adds a list of the steps.', 'wp-ultimo');
} // end get_tooltip;
}
/**
* Returns the icon to be used on the selector.
*
@ -96,8 +91,7 @@ class Signup_Field_Steps extends Base_Signup_Field {
public function get_icon(): string {
return 'dashicons-wu-filter_1';
} // end get_icon;
}
/**
* Returns the default values for the field-elements.
@ -113,8 +107,7 @@ class Signup_Field_Steps extends Base_Signup_Field {
return array(
'steps_template' => 'clean',
);
} // end defaults;
}
/**
* List of keys of the default fields we want to display on the builder.
@ -125,8 +118,7 @@ class Signup_Field_Steps extends Base_Signup_Field {
public function default_fields() {
return array();
} // end default_fields;
}
/**
* If you want to force a particular attribute to a value, declare it here.
@ -139,8 +131,7 @@ class Signup_Field_Steps extends Base_Signup_Field {
return array(
'id' => 'steps',
);
} // end force_attributes;
}
/**
* Returns the list of available pricing table templates.
@ -153,8 +144,7 @@ class Signup_Field_Steps extends Base_Signup_Field {
$available_templates = Field_Templates_Manager::get_instance()->get_templates_as_options('steps');
return $available_templates;
} // end get_templates;
}
/**
* Returns the list of additional fields specific to this type.
@ -192,8 +182,7 @@ class Signup_Field_Steps extends Base_Signup_Field {
// );
return $editor_fields;
} // end get_fields;
}
/**
* Returns the field/element actual field array to be used on the checkout form.
@ -206,12 +195,10 @@ class Signup_Field_Steps extends Base_Signup_Field {
public function to_fields_array($attributes) {
if (wu_get_isset($attributes, 'steps_template') === 'legacy') {
wp_enqueue_style('legacy-shortcodes', wu_get_asset('legacy-shortcodes.css', 'css'), array('dashicons'), wu_get_version());
wp_add_inline_style('legacy-shortcodes', \WP_Ultimo\Checkout\Legacy_Checkout::get_instance()->get_legacy_dynamic_styles());
} // end if;
}
$attributes['steps'] = \WP_Ultimo\Checkout\Checkout::get_instance()->steps;
$attributes['current_step'] = \WP_Ultimo\Checkout\Checkout::get_instance()->step_name;
@ -227,7 +214,5 @@ class Signup_Field_Steps extends Base_Signup_Field {
'wrapper_classes' => $attributes['element_classes'],
),
);
} // end to_fields_array;
} // end class Signup_Field_Steps;
}
}

View File

@ -9,7 +9,7 @@
namespace WP_Ultimo\Checkout\Signup_Fields;
use \WP_Ultimo\Checkout\Signup_Fields\Base_Signup_Field;
use WP_Ultimo\Checkout\Signup_Fields\Base_Signup_Field;
// Exit if accessed directly
defined('ABSPATH') || exit;
@ -32,8 +32,7 @@ class Signup_Field_Submit_Button extends Base_Signup_Field {
public function get_type() {
return 'submit_button';
} // end get_type;
}
/**
* Returns if this field should be present on the checkout flow or not.
@ -44,8 +43,7 @@ class Signup_Field_Submit_Button extends Base_Signup_Field {
public function is_required() {
return true;
} // end is_required;
}
/**
* Requires the title of the field/element type.
@ -58,8 +56,7 @@ class Signup_Field_Submit_Button extends Base_Signup_Field {
public function get_title() {
return __('Submit Button', 'wp-ultimo');
} // end get_title;
}
/**
* Returns the description of the field/element.
@ -72,8 +69,7 @@ class Signup_Field_Submit_Button extends Base_Signup_Field {
public function get_description() {
return __('Adds a submit button. This is required to finalize single-step checkout forms or to navigate to the next step on multi-step checkout forms.', 'wp-ultimo');
} // end get_description;
}
/**
* Returns the tooltip of the field/element.
@ -86,8 +82,7 @@ class Signup_Field_Submit_Button extends Base_Signup_Field {
public function get_tooltip() {
return __('Adds a submit button. This is required to finalize single-step checkout forms or to navigate to the next step on multi-step checkout forms.', 'wp-ultimo');
} // end get_tooltip;
}
/**
* Returns the icon to be used on the selector.
@ -100,8 +95,7 @@ class Signup_Field_Submit_Button extends Base_Signup_Field {
public function get_icon() {
return 'dashicons-wu-zap';
} // end get_icon;
}
/**
* Returns the default values for the field-elements.
@ -118,8 +112,7 @@ class Signup_Field_Submit_Button extends Base_Signup_Field {
'enable_go_back_button' => false,
'back_button_label' => __('&larr; Go Back', 'wp-ultimo'),
);
} // end defaults;
}
/**
* List of keys of the default fields we want to display on the builder.
@ -133,8 +126,7 @@ class Signup_Field_Submit_Button extends Base_Signup_Field {
'id',
'name',
);
} // end default_fields;
}
/**
* If you want to force a particular attribute to a value, declare it here.
@ -145,8 +137,7 @@ class Signup_Field_Submit_Button extends Base_Signup_Field {
public function force_attributes() {
return array();
} // end force_attributes;
}
/**
* Returns the list of additional fields specific to this type.
@ -179,8 +170,7 @@ class Signup_Field_Submit_Button extends Base_Signup_Field {
),
),
);
} // end get_fields;
}
/**
* Returns the field/element actual field array to be used on the checkout form.
@ -216,13 +206,11 @@ class Signup_Field_Submit_Button extends Base_Signup_Field {
$button_wrapper_classes = 'wu_submit_button';
if ($attributes['enable_go_back_button']) {
$steps = \WP_Ultimo\Checkout\Checkout::get_instance()->steps;
$is_first_step = isset($steps[0]) && $steps[0]['id'] === $attributes['step'];
if ( ! $is_first_step) {
$fields[ $attributes['id'] . '_group' ]['fields'][ $attributes['id'] . '_go_back' ] = array(
'type' => 'html',
'wrapper_classes' => 'md:wu-w-1/2 wu-box-border wu-float-left wu--mt-4',
@ -231,10 +219,8 @@ class Signup_Field_Submit_Button extends Base_Signup_Field {
);
$button_wrapper_classes .= ' md:wu-w-1/2 wu-box-border wu-float-left wu-text-right';
} // end if;
} // end if;
}
}
$fields[ $attributes['id'] . '_group' ]['fields'][ $attributes['id'] ] = array(
'type' => 'submit',
@ -245,15 +231,11 @@ class Signup_Field_Submit_Button extends Base_Signup_Field {
);
if ($attributes['enable_go_back_button']) {
$fields[ $attributes['id'] . '_clear' ] = array(
'type' => 'clear',
);
} // end if;
}
return $fields;
} // end to_fields_array;
} // end class Signup_Field_Submit_Button;
}
}

View File

@ -9,9 +9,9 @@
namespace WP_Ultimo\Checkout\Signup_Fields;
use \WP_Ultimo\Checkout\Signup_Fields\Base_Signup_Field;
use \WP_Ultimo\Managers\Field_Templates_Manager;
use \WP_Ultimo\Models\Site;
use WP_Ultimo\Checkout\Signup_Fields\Base_Signup_Field;
use WP_Ultimo\Managers\Field_Templates_Manager;
use WP_Ultimo\Models\Site;
// Exit if accessed directly
defined('ABSPATH') || exit;
@ -33,8 +33,7 @@ class Signup_Field_Template_Selection extends Base_Signup_Field {
public function get_type(): string {
return 'template_selection';
} // end get_type;
}
/**
* Returns if this field should be present on the checkout flow or not.
*
@ -43,8 +42,7 @@ class Signup_Field_Template_Selection extends Base_Signup_Field {
public function is_required(): bool {
return false;
} // end is_required;
}
/**
* Requires the title of the field/element type.
@ -57,8 +55,7 @@ class Signup_Field_Template_Selection extends Base_Signup_Field {
public function get_title() {
return __('Templates', 'wp-ultimo');
} // end get_title;
}
/**
* Returns the description of the field/element.
@ -71,8 +68,7 @@ class Signup_Field_Template_Selection extends Base_Signup_Field {
public function get_description() {
return __('Adds a template selection section. This allows the customer to choose a pre-built site to be used as a template for the site being currently created.', 'wp-ultimo');
} // end get_description;
}
/**
* Returns the tooltip of the field/element.
@ -85,8 +81,7 @@ class Signup_Field_Template_Selection extends Base_Signup_Field {
public function get_tooltip() {
return __('Adds a template selection section. This allows the customer to choose a pre-built site to be used as a template for the site being currently created.', 'wp-ultimo');
} // end get_tooltip;
}
/**
* Returns the icon to be used on the selector.
*
@ -97,8 +92,7 @@ class Signup_Field_Template_Selection extends Base_Signup_Field {
public function get_icon(): string {
return 'dashicons-wu-layout';
} // end get_icon;
}
/**
* Returns the default values for the field-elements.
@ -118,8 +112,7 @@ class Signup_Field_Template_Selection extends Base_Signup_Field {
'cols' => 3,
'hide_template_selection_when_pre_selected' => false,
);
} // end defaults;
}
/**
* List of keys of the default fields we want to display on the builder.
@ -132,8 +125,7 @@ class Signup_Field_Template_Selection extends Base_Signup_Field {
return array(
// 'name',
);
} // end default_fields;
}
/**
* If you want to force a particular attribute to a value, declare it here.
@ -148,8 +140,7 @@ class Signup_Field_Template_Selection extends Base_Signup_Field {
'name' => __('Template Selection', 'wp-ultimo'),
'required' => true,
);
} // end force_attributes;
}
/**
* Returns the list of available pricing table templates.
@ -162,8 +153,7 @@ class Signup_Field_Template_Selection extends Base_Signup_Field {
$available_templates = Field_Templates_Manager::get_instance()->get_templates_as_options('template_selection');
return $available_templates;
} // end get_template_selection_templates;
}
/**
* Returns the list of additional fields specific to this type.
@ -223,9 +213,14 @@ class Signup_Field_Template_Selection extends Base_Signup_Field {
'data-label-field' => 'title',
'data-search-field' => 'title',
'data-max-items' => 999,
'data-include' => implode(',', wu_get_site_templates(array(
'data-include' => implode(
',',
wu_get_site_templates(
array(
'fields' => 'blog_id',
))),
)
)
),
),
'wrapper_html_attr' => array(
'v-show' => 'template_selection_type === \'name\'',
@ -272,8 +267,7 @@ class Signup_Field_Template_Selection extends Base_Signup_Field {
// );
return $editor_fields;
} // end get_fields;
}
/**
* Treat the attributes array to avoid reaching the input var limits.
@ -290,8 +284,7 @@ class Signup_Field_Template_Selection extends Base_Signup_Field {
$attributes['sites'] = array_values(array_column($array_sites, 'blog_id'));
return $attributes;
} // end reduce_attributes;
}
/**
* Returns the field/element actual field array to be used on the checkout form.
@ -316,41 +309,33 @@ class Signup_Field_Template_Selection extends Base_Signup_Field {
* Hide when pre-selected.
*/
if (wu_should_hide_form_field($attributes)) {
return $checkout_fields;
} // end if;
}
if (wu_get_isset($attributes, 'template_selection_template') === 'legacy') {
wp_register_script('wu-legacy-signup', wu_get_asset('legacy-signup.js', 'js'), array('wu-functions'), wu_get_version());
wp_enqueue_script('wu-legacy-signup');
wp_enqueue_style('legacy-shortcodes', wu_get_asset('legacy-shortcodes.css', 'css'), array('dashicons'), wu_get_version());
} // end if;
}
$site_list = $this->site_list($attributes);
$customer_sites = array();
if (wu_get_setting('allow_own_site_as_template')) {
$customer = wu_get_current_customer();
if ($customer) {
$customer_sites = $customer->get_sites(array('fields' => 'ids'));
$site_list = array_merge(
$customer_sites,
$site_list
);
} // end if;
} // end if;
}
}
$sites = array_map('wu_get_site', $site_list);
@ -378,8 +363,7 @@ class Signup_Field_Template_Selection extends Base_Signup_Field {
);
return $checkout_fields;
} // end to_fields_array;
}
/**
* Return site list according to selection type used.
@ -392,19 +376,14 @@ class Signup_Field_Template_Selection extends Base_Signup_Field {
$selection_type = wu_get_isset($attributes, 'template_selection_type', 'name');
if ($selection_type === 'name') {
return explode(',', $attributes['template_selection_sites']);
} // end if;
}
if ($selection_type === 'all') {
return wu_get_site_templates(array('fields' => 'blog_id'));
} // end if;
}
if ($selection_type === 'categories') {
return array_column(
\WP_Ultimo\Models\Site::get_all_by_categories(
$attributes['template_selection_categories'],
@ -414,12 +393,8 @@ class Signup_Field_Template_Selection extends Base_Signup_Field {
),
'blog_id'
);
} // end if;
}
return explode(',', $attributes['template_selection_sites']);
} // end site_list;
} // end class Signup_Field_Template_Selection;
}
}

View File

@ -9,7 +9,7 @@
namespace WP_Ultimo\Checkout\Signup_Fields;
use \WP_Ultimo\Checkout\Signup_Fields\Base_Signup_Field;
use WP_Ultimo\Checkout\Signup_Fields\Base_Signup_Field;
// Exit if accessed directly
defined('ABSPATH') || exit;
@ -32,8 +32,7 @@ class Signup_Field_Terms_Of_Use extends Base_Signup_Field {
public function get_type() {
return 'terms_of_use';
} // end get_type;
}
/**
* Returns if this field should be present on the checkout flow or not.
@ -44,8 +43,7 @@ class Signup_Field_Terms_Of_Use extends Base_Signup_Field {
public function is_required() {
return false;
} // end is_required;
}
/**
* Is this a user-related field?
@ -59,8 +57,7 @@ class Signup_Field_Terms_Of_Use extends Base_Signup_Field {
public function is_user_field() {
return false;
} // end is_user_field;
}
/**
* Requires the title of the field/element type.
@ -73,8 +70,7 @@ class Signup_Field_Terms_Of_Use extends Base_Signup_Field {
public function get_title() {
return __('Terms of Use', 'wp-ultimo');
} // end get_title;
}
/**
* Returns the description of the field/element.
@ -87,8 +83,7 @@ class Signup_Field_Terms_Of_Use extends Base_Signup_Field {
public function get_description() {
return __('Adds a terms and conditions checkbox that must be marked before the account/site can be created.', 'wp-ultimo');
} // end get_description;
}
/**
* Returns the tooltip of the field/element.
@ -101,8 +96,7 @@ class Signup_Field_Terms_Of_Use extends Base_Signup_Field {
public function get_tooltip() {
return __('Adds a terms and conditions checkbox that must be marked before the account/site can be created.', 'wp-ultimo');
} // end get_tooltip;
}
/**
* Returns the icon to be used on the selector.
@ -115,8 +109,7 @@ class Signup_Field_Terms_Of_Use extends Base_Signup_Field {
public function get_icon() {
return 'dashicons-wu-file-text';
} // end get_icon;
}
/**
* Returns the default values for the field-elements.
@ -132,8 +125,7 @@ class Signup_Field_Terms_Of_Use extends Base_Signup_Field {
return array(
'tou_name' => __('I agree with the terms of use.', 'wp-ultimo'),
);
} // end defaults;
}
/**
* List of keys of the default fields we want to display on the builder.
@ -144,8 +136,7 @@ class Signup_Field_Terms_Of_Use extends Base_Signup_Field {
public function default_fields() {
return array();
} // end default_fields;
}
/**
* If you want to force a particular attribute to a value, declare it here.
@ -159,8 +150,7 @@ class Signup_Field_Terms_Of_Use extends Base_Signup_Field {
'id' => 'terms_of_use',
'name' => __('Terms of Use', 'wp-ultimo'),
);
} // end force_attributes;
}
/**
* Returns the list of additional fields specific to this type.
@ -185,8 +175,7 @@ class Signup_Field_Terms_Of_Use extends Base_Signup_Field {
'placeholder' => __('e.g. https://yoursite.com/terms', 'wp-ultimo'),
),
);
} // end get_fields;
}
/**
* Returns the field/element actual field array to be used on the checkout form.
@ -212,7 +201,5 @@ class Signup_Field_Terms_Of_Use extends Base_Signup_Field {
);
return $checkout_fields;
} // end to_fields_array;
} // end class Signup_Field_Terms_Of_Use;
}
}

View File

@ -9,7 +9,7 @@
namespace WP_Ultimo\Checkout\Signup_Fields;
use \WP_Ultimo\Checkout\Signup_Fields\Base_Signup_Field;
use WP_Ultimo\Checkout\Signup_Fields\Base_Signup_Field;
// Exit if accessed directly
defined('ABSPATH') || exit;
@ -32,8 +32,7 @@ class Signup_Field_Text extends Base_Signup_Field {
public function get_type() {
return 'text';
} // end get_type;
}
/**
* Returns if this field should be present on the checkout flow or not.
@ -44,8 +43,7 @@ class Signup_Field_Text extends Base_Signup_Field {
public function is_required() {
return false;
} // end is_required;
}
/**
* Requires the title of the field/element type.
@ -58,8 +56,7 @@ class Signup_Field_Text extends Base_Signup_Field {
public function get_title() {
return __('Text', 'wp-ultimo');
} // end get_title;
}
/**
* Returns the description of the field/element.
@ -72,8 +69,7 @@ class Signup_Field_Text extends Base_Signup_Field {
public function get_description() {
return __('Adds a text field that the customer can fill with arbitrary data.', 'wp-ultimo');
} // end get_description;
}
/**
* Returns the tooltip of the field/element.
@ -86,8 +82,7 @@ class Signup_Field_Text extends Base_Signup_Field {
public function get_tooltip() {
return __('Adds a text field that the customer can fill with arbitrary data.', 'wp-ultimo');
} // end get_tooltip;
}
/**
* Returns the icon to be used on the selector.
@ -100,8 +95,7 @@ class Signup_Field_Text extends Base_Signup_Field {
public function get_icon() {
return 'dashicons-wu-edit-3';
} // end get_icon;
}
/**
* Returns the default values for the field-elements.
@ -115,10 +109,9 @@ class Signup_Field_Text extends Base_Signup_Field {
public function defaults() {
return array(
''
'',
);
} // end defaults;
}
/**
* List of keys of the default fields we want to display on the builder.
@ -137,8 +130,7 @@ class Signup_Field_Text extends Base_Signup_Field {
'required',
'save_as',
);
} // end default_fields;
}
/**
* If you want to force a particular attribute to a value, declare it here.
@ -149,8 +141,7 @@ class Signup_Field_Text extends Base_Signup_Field {
public function force_attributes() {
return array();
} // end force_attributes;
}
/**
* Returns the list of additional fields specific to this type.
@ -161,8 +152,7 @@ class Signup_Field_Text extends Base_Signup_Field {
public function get_fields() {
return array();
} // end get_fields;
}
/**
* Returns the field/element actual field array to be used on the checkout form.
@ -188,7 +178,5 @@ class Signup_Field_Text extends Base_Signup_Field {
);
return $fields;
} // end to_fields_array;
} // end class Signup_Field_Text;
}
}

View File

@ -9,7 +9,7 @@
namespace WP_Ultimo\Checkout\Signup_Fields;
use \WP_Ultimo\Checkout\Signup_Fields\Base_Signup_Field;
use WP_Ultimo\Checkout\Signup_Fields\Base_Signup_Field;
// Exit if accessed directly
defined('ABSPATH') || exit;
@ -32,8 +32,7 @@ class Signup_Field_Username extends Base_Signup_Field {
public function get_type() {
return 'username';
} // end get_type;
}
/**
* Returns if this field should be present on the checkout flow or not.
@ -44,8 +43,7 @@ class Signup_Field_Username extends Base_Signup_Field {
public function is_required() {
return true;
} // end is_required;
}
/**
* Is this a user-related field?
@ -59,8 +57,7 @@ class Signup_Field_Username extends Base_Signup_Field {
public function is_user_field() {
return true;
} // end is_user_field;
}
/**
* Requires the title of the field/element type.
@ -73,8 +70,7 @@ class Signup_Field_Username extends Base_Signup_Field {
public function get_title() {
return __('Username', 'wp-ultimo');
} // end get_title;
}
/**
* Returns the description of the field/element.
@ -87,8 +83,7 @@ class Signup_Field_Username extends Base_Signup_Field {
public function get_description() {
return __('Adds an username field. This username will be used to create the WordPress user.', 'wp-ultimo');
} // end get_description;
}
/**
* Returns the tooltip of the field/element.
@ -101,8 +96,7 @@ class Signup_Field_Username extends Base_Signup_Field {
public function get_tooltip() {
return __('Adds an username field. This username will be used to create the WordPress user.', 'wp-ultimo');
} // end get_tooltip;
}
/**
* Returns the icon to be used on the selector.
@ -115,8 +109,7 @@ class Signup_Field_Username extends Base_Signup_Field {
public function get_icon() {
return 'dashicons-wu-user1';
} // end get_icon;
}
/**
* Returns the default values for the field-elements.
@ -132,8 +125,7 @@ class Signup_Field_Username extends Base_Signup_Field {
return array(
'auto_generate_username' => false,
);
} // end defaults;
}
/**
* List of keys of the default fields we want to display on the builder.
@ -148,8 +140,7 @@ class Signup_Field_Username extends Base_Signup_Field {
'placeholder',
'tooltip',
);
} // end default_fields;
}
/**
* If you want to force a particular attribute to a value, declare it here.
@ -163,8 +154,7 @@ class Signup_Field_Username extends Base_Signup_Field {
'id' => 'username',
'required' => true,
);
} // end force_attributes;
}
/**
* Returns the list of additional fields specific to this type.
@ -186,8 +176,7 @@ class Signup_Field_Username extends Base_Signup_Field {
),
),
);
} // end get_fields;
}
/**
* Returns the field/element actual field array to be used on the checkout form.
@ -202,13 +191,10 @@ class Signup_Field_Username extends Base_Signup_Field {
* Logged in user, bail.
*/
if (is_user_logged_in()) {
return array();
} // end if;
}
if (isset($attributes['auto_generate_username']) && $attributes['auto_generate_username']) {
return array(
'auto_generate_username' => array(
'type' => 'hidden',
@ -221,8 +207,7 @@ class Signup_Field_Username extends Base_Signup_Field {
'value' => uniqid(),
),
);
} // end if;
}
return array(
'username' => array(
@ -245,7 +230,5 @@ class Signup_Field_Username extends Base_Signup_Field {
),
),
);
} // end to_fields_array;
} // end class Signup_Field_Username;
}
}

View File

@ -41,10 +41,9 @@ class Base_Field_Template {
*
* @param array $attributes The attributes passed to the field.
*/
public function __construct($attributes = array())
{
public function __construct($attributes = array()) {
$this->attributes = $attributes;
} // end __construct;
}
/**
* The render type for the template.
@ -66,8 +65,7 @@ class Base_Field_Template {
public function get_render_type(): string {
return 'ajax';
} // end get_render_type;
}
/**
* The title of the field template.
@ -80,8 +78,7 @@ class Base_Field_Template {
public function get_title() {
return __('Field Template', 'wp-ultimo');
} // end get_title;
}
/**
* The description of the field template.
@ -94,8 +91,7 @@ class Base_Field_Template {
public function get_description() {
return __('Description', 'wp-ultimo');
} // end get_description;
}
/**
* The preview image of the field template.
*
@ -106,8 +102,7 @@ class Base_Field_Template {
public function get_preview(): string {
return '';
} // end get_preview;
}
/**
* The content of the template.
@ -117,7 +112,7 @@ class Base_Field_Template {
* @param array $attributes The field template attributes.
* @return void
*/
public function output($attributes) {} // end output;
public function output($attributes) {}
/**
* Renders the content.
@ -136,8 +131,7 @@ class Base_Field_Template {
$this->output($attributes);
return ob_get_clean();
} // end render;
}
/**
* Displays the content on the checkout form as a wrapper.
@ -153,23 +147,15 @@ class Base_Field_Template {
public function render_container($attributes, $signup_field = false) {
if ($this->get_render_type() === 'ajax') {
if ($signup_field) {
$attributes = $signup_field->reduce_attributes($attributes);
} // end if;
}
$markup = sprintf('<dynamic :template="get_template(\'%s\', %s)"></dynamic>', esc_js($this->id), esc_attr(json_encode($attributes)));
} else {
$markup = $this->render($attributes);
} // end if;
}
return $markup;
} // end render_container;
} // end class Base_Field_Template;
}
}

View File

@ -12,7 +12,7 @@ namespace WP_Ultimo\Checkout\Signup_Fields\Field_Templates\Order_Bump;
// Exit if accessed directly
defined('ABSPATH') || exit;
use \WP_Ultimo\Checkout\Signup_Fields\Field_Templates\Base_Field_Template;
use WP_Ultimo\Checkout\Signup_Fields\Field_Templates\Base_Field_Template;
/**
* Template Selection Simple
@ -52,8 +52,7 @@ class Simple_Order_Bump_Field_Template extends Base_Field_Template {
public function get_render_type(): string {
return 'ajax';
} // end get_render_type;
}
/**
* The title of the field template.
@ -66,8 +65,7 @@ class Simple_Order_Bump_Field_Template extends Base_Field_Template {
public function get_title() {
return __('Simple', 'wp-ultimo');
} // end get_title;
}
/**
* The description of the field template.
@ -80,8 +78,7 @@ class Simple_Order_Bump_Field_Template extends Base_Field_Template {
public function get_description() {
return __('A simple layout with minimal styling, just enough to make it usable out-of-the-box.', 'wp-ultimo');
} // end get_description;
}
/**
* The preview of the field template.
@ -92,8 +89,7 @@ class Simple_Order_Bump_Field_Template extends Base_Field_Template {
public function get_preview(): string {
return wu_get_asset('checkout-forms/clean-template-selection.png');
} // end get_preview;
}
/**
* The content of the template.
@ -109,7 +105,5 @@ class Simple_Order_Bump_Field_Template extends Base_Field_Template {
* Loads the actual order-bump template
*/
wu_get_template('checkout/templates/order-bump/simple', $attributes);
} // end output;
} // end class Simple_Order_Bump_Field_Template;
}
}

View File

@ -12,7 +12,7 @@ namespace WP_Ultimo\Checkout\Signup_Fields\Field_Templates\Order_Summary;
// Exit if accessed directly
defined('ABSPATH') || exit;
use \WP_Ultimo\Checkout\Signup_Fields\Field_Templates\Base_Field_Template;
use WP_Ultimo\Checkout\Signup_Fields\Field_Templates\Base_Field_Template;
/**
* Order Summary Clean
@ -52,8 +52,7 @@ class Clean_Order_Summary_Field_Template extends Base_Field_Template {
public function get_render_type(): string {
return 'dynamic';
} // end get_render_type;
}
/**
* The title of the field template.
@ -66,8 +65,7 @@ class Clean_Order_Summary_Field_Template extends Base_Field_Template {
public function get_title() {
return __('Clean', 'wp-ultimo');
} // end get_title;
}
/**
* The description of the field template.
@ -80,8 +78,7 @@ class Clean_Order_Summary_Field_Template extends Base_Field_Template {
public function get_description() {
return __('A simple layout with minimal styling, just enough to make it usable out-of-the-box.', 'wp-ultimo');
} // end get_description;
}
/**
* The preview of the field template.
@ -92,8 +89,7 @@ class Clean_Order_Summary_Field_Template extends Base_Field_Template {
public function get_preview(): string {
return wu_get_asset('checkout-forms/clean-order-summary.png');
} // end get_preview;
}
/**
* The content of the template.
@ -109,7 +105,5 @@ class Clean_Order_Summary_Field_Template extends Base_Field_Template {
* Loads the actual order-summary template
*/
wu_get_template('checkout/templates/order-summary/simple', $attributes);
} // end output;
} // end class Clean_Order_Summary_Field_Template;
}
}

View File

@ -12,7 +12,7 @@ namespace WP_Ultimo\Checkout\Signup_Fields\Field_Templates\Period_Selection;
// Exit if accessed directly
defined('ABSPATH') || exit;
use \WP_Ultimo\Checkout\Signup_Fields\Field_Templates\Base_Field_Template;
use WP_Ultimo\Checkout\Signup_Fields\Field_Templates\Base_Field_Template;
/**
* Template Selection Clean
@ -52,8 +52,7 @@ class Clean_Period_Selection_Field_Template extends Base_Field_Template {
public function get_render_type(): string {
return 'dynamic';
} // end get_render_type;
}
/**
* The title of the field template.
@ -66,8 +65,7 @@ class Clean_Period_Selection_Field_Template extends Base_Field_Template {
public function get_title() {
return __('Clean', 'wp-ultimo');
} // end get_title;
}
/**
* The description of the field template.
@ -80,8 +78,7 @@ class Clean_Period_Selection_Field_Template extends Base_Field_Template {
public function get_description() {
return __('A simple template with clean markup and no styling, ready to be customized with custom CSS.', 'wp-ultimo');
} // end get_description;
}
/**
* The preview image of the field template.
@ -94,8 +91,7 @@ class Clean_Period_Selection_Field_Template extends Base_Field_Template {
public function get_preview(): string {
return wu_get_asset('checkout-forms/clean-period-selection.png');
} // end get_preview;
}
/**
* The content of the template.
@ -108,7 +104,5 @@ class Clean_Period_Selection_Field_Template extends Base_Field_Template {
public function output($attributes) {
wu_get_template('checkout/templates/period-selection/clean', $attributes);
} // end output;
} // end class Clean_Period_Selection_Field_Template;
}
}

View File

@ -12,7 +12,7 @@ namespace WP_Ultimo\Checkout\Signup_Fields\Field_Templates\Period_Selection;
// Exit if accessed directly
defined('ABSPATH') || exit;
use \WP_Ultimo\Checkout\Signup_Fields\Field_Templates\Base_Field_Template;
use WP_Ultimo\Checkout\Signup_Fields\Field_Templates\Base_Field_Template;
/**
* Template Selection Clean
@ -52,8 +52,7 @@ class Legacy_Period_Selection_Field_Template extends Base_Field_Template {
public function get_render_type(): string {
return 'dynamic';
} // end get_render_type;
}
/**
* The title of the field template.
@ -66,8 +65,7 @@ class Legacy_Period_Selection_Field_Template extends Base_Field_Template {
public function get_title() {
return __('Legacy', 'wp-ultimo');
} // end get_title;
}
/**
* The description of the field template.
@ -80,8 +78,7 @@ class Legacy_Period_Selection_Field_Template extends Base_Field_Template {
public function get_description() {
return __('Implementation of the layout that shipped with WP Multisite WaaS < 1.10.X.', 'wp-ultimo');
} // end get_description;
}
/**
* The preview image of the field template.
@ -94,8 +91,7 @@ class Legacy_Period_Selection_Field_Template extends Base_Field_Template {
public function get_preview(): string {
return wu_get_asset('checkout-forms/legacy-period-selection.png');
} // end get_preview;
}
/**
* The content of the template.
@ -108,7 +104,5 @@ class Legacy_Period_Selection_Field_Template extends Base_Field_Template {
public function output($attributes) {
wu_get_template('checkout/templates/period-selection/legacy', $attributes);
} // end output;
} // end class Legacy_Period_Selection_Field_Template;
}
}

View File

@ -12,7 +12,7 @@ namespace WP_Ultimo\Checkout\Signup_Fields\Field_Templates\Pricing_Table;
// Exit if accessed directly
defined('ABSPATH') || exit;
use \WP_Ultimo\Checkout\Signup_Fields\Field_Templates\Base_Field_Template;
use WP_Ultimo\Checkout\Signup_Fields\Field_Templates\Base_Field_Template;
/**
* Template Selection Clean
@ -52,8 +52,7 @@ class Legacy_Pricing_Table_Field_Template extends Base_Field_Template {
public function get_render_type(): string {
return 'dynamic';
} // end get_render_type;
}
/**
* The title of the field template.
@ -66,8 +65,7 @@ class Legacy_Pricing_Table_Field_Template extends Base_Field_Template {
public function get_title() {
return __('Legacy', 'wp-ultimo');
} // end get_title;
}
/**
* The description of the field template.
@ -80,8 +78,7 @@ class Legacy_Pricing_Table_Field_Template extends Base_Field_Template {
public function get_description() {
return __('Implementation of the layout that shipped with WP Ultimo < 1.10.X.', 'wp-ultimo');
} // end get_description;
}
/**
* The preview image of the field template.
@ -94,8 +91,7 @@ class Legacy_Pricing_Table_Field_Template extends Base_Field_Template {
public function get_preview(): string {
return wu_get_asset('checkout-forms/legacy-pricing-table.png');
} // end get_preview;
}
/**
* The content of the template.
@ -108,7 +104,5 @@ class Legacy_Pricing_Table_Field_Template extends Base_Field_Template {
public function output($attributes) {
wu_get_template('checkout/templates/pricing-table/legacy', $attributes);
} // end output;
} // end class Legacy_Pricing_Table_Field_Template;
}
}

View File

@ -12,7 +12,7 @@ namespace WP_Ultimo\Checkout\Signup_Fields\Field_Templates\Pricing_Table;
// Exit if accessed directly
defined('ABSPATH') || exit;
use \WP_Ultimo\Checkout\Signup_Fields\Field_Templates\Base_Field_Template;
use WP_Ultimo\Checkout\Signup_Fields\Field_Templates\Base_Field_Template;
/**
* Base Field Template
@ -43,8 +43,7 @@ class List_Pricing_Table_Field_Template extends Base_Field_Template {
public function get_title() {
return __('Simple List', 'wp-ultimo');
} // end get_title;
}
/**
* The description of the field template.
@ -57,8 +56,7 @@ class List_Pricing_Table_Field_Template extends Base_Field_Template {
public function get_description() {
return __('Simple stylized list with price, recurrence, and the plan description.', 'wp-ultimo');
} // end get_description;
}
/**
* The preview image of the field template.
@ -71,8 +69,7 @@ class List_Pricing_Table_Field_Template extends Base_Field_Template {
public function get_preview(): string {
return wu_get_asset('checkout-forms/list-pricing-table.png');
} // end get_preview;
}
/**
* The content of the template.
@ -85,7 +82,5 @@ class List_Pricing_Table_Field_Template extends Base_Field_Template {
public function output($attributes) {
wu_get_template('checkout/templates/pricing-table/list', $attributes);
} // end output;
} // end class List_Pricing_Table_Field_Template;
}
}

View File

@ -12,7 +12,7 @@ namespace WP_Ultimo\Checkout\Signup_Fields\Field_Templates\Steps;
// Exit if accessed directly
defined('ABSPATH') || exit;
use \WP_Ultimo\Checkout\Signup_Fields\Field_Templates\Base_Field_Template;
use WP_Ultimo\Checkout\Signup_Fields\Field_Templates\Base_Field_Template;
/**
* Template Selection Clean
@ -52,8 +52,7 @@ class Clean_Steps_Field_Template extends Base_Field_Template {
public function get_render_type(): string {
return 'dynamic';
} // end get_render_type;
}
/**
* The title of the field template.
@ -66,8 +65,7 @@ class Clean_Steps_Field_Template extends Base_Field_Template {
public function get_title() {
return __('Clean', 'wp-ultimo');
} // end get_title;
}
/**
* The description of the field template.
@ -80,8 +78,7 @@ class Clean_Steps_Field_Template extends Base_Field_Template {
public function get_description() {
return __('A simple layout with minimal styling, just enough to make it usable out-of-the-box.', 'wp-ultimo');
} // end get_description;
}
/**
* The preview of the field template.
@ -92,8 +89,7 @@ class Clean_Steps_Field_Template extends Base_Field_Template {
public function get_preview(): string {
return wu_get_asset('checkout-forms/clean-steps.png');
} // end get_preview;
}
/**
* The content of the template.
@ -106,7 +102,5 @@ class Clean_Steps_Field_Template extends Base_Field_Template {
public function output($attributes) {
wu_get_template('checkout/templates/steps/clean', $attributes);
} // end output;
} // end class Clean_Steps_Field_Template;
}
}

View File

@ -12,7 +12,7 @@ namespace WP_Ultimo\Checkout\Signup_Fields\Field_Templates\Steps;
// Exit if accessed directly
defined('ABSPATH') || exit;
use \WP_Ultimo\Checkout\Signup_Fields\Field_Templates\Base_Field_Template;
use WP_Ultimo\Checkout\Signup_Fields\Field_Templates\Base_Field_Template;
/**
* Template Selection Clean
@ -52,8 +52,7 @@ class Legacy_Steps_Field_Template extends Base_Field_Template {
public function get_render_type(): string {
return 'dynamic';
} // end get_render_type;
}
/**
* The title of the field template.
@ -66,8 +65,7 @@ class Legacy_Steps_Field_Template extends Base_Field_Template {
public function get_title() {
return __('Legacy', 'wp-ultimo');
} // end get_title;
}
/**
* The description of the field template.
@ -80,8 +78,7 @@ class Legacy_Steps_Field_Template extends Base_Field_Template {
public function get_description() {
return __('Implementation of the layout that shipped with WP Ultimo < 1.10.X.', 'wp-ultimo');
} // end get_description;
}
/**
* The preview of the field template.
@ -92,8 +89,7 @@ class Legacy_Steps_Field_Template extends Base_Field_Template {
public function get_preview(): string {
return wu_get_asset('checkout-forms/legacy-steps.png');
} // end get_preview;
}
/**
* The content of the template.
@ -106,7 +102,5 @@ class Legacy_Steps_Field_Template extends Base_Field_Template {
public function output($attributes) {
wu_get_template('checkout/templates/steps/legacy', $attributes);
} // end output;
} // end class Legacy_Steps_Field_Template;
}
}

View File

@ -12,7 +12,7 @@ namespace WP_Ultimo\Checkout\Signup_Fields\Field_Templates\Steps;
// Exit if accessed directly
defined('ABSPATH') || exit;
use \WP_Ultimo\Checkout\Signup_Fields\Field_Templates\Base_Field_Template;
use WP_Ultimo\Checkout\Signup_Fields\Field_Templates\Base_Field_Template;
/**
* Template Selection Clean
@ -52,8 +52,7 @@ class Minimal_Steps_Field_Template extends Base_Field_Template {
public function get_render_type(): string {
return 'dynamic';
} // end get_render_type;
}
/**
* The title of the field template.
@ -66,8 +65,7 @@ class Minimal_Steps_Field_Template extends Base_Field_Template {
public function get_title() {
return __('Minimal', 'wp-ultimo');
} // end get_title;
}
/**
* The description of the field template.
@ -80,8 +78,7 @@ class Minimal_Steps_Field_Template extends Base_Field_Template {
public function get_description() {
return __('A simple template with clean markup and no styling, ready to be customized with custom CSS.', 'wp-ultimo');
} // end get_description;
}
/**
* The preview of the field template.
@ -92,8 +89,7 @@ class Minimal_Steps_Field_Template extends Base_Field_Template {
public function get_preview(): string {
return wu_get_asset('checkout-forms/minimal-steps.png');
} // end get_preview;
}
/**
* The content of the template.
@ -106,7 +102,5 @@ class Minimal_Steps_Field_Template extends Base_Field_Template {
public function output($attributes) {
wu_get_template('checkout/templates/steps/minimal', $attributes);
} // end output;
} // end class Minimal_Steps_Field_Template;
}
}

View File

@ -12,7 +12,7 @@ namespace WP_Ultimo\Checkout\Signup_Fields\Field_Templates\Template_Selection;
// Exit if accessed directly
defined('ABSPATH') || exit;
use \WP_Ultimo\Checkout\Signup_Fields\Field_Templates\Base_Field_Template;
use WP_Ultimo\Checkout\Signup_Fields\Field_Templates\Base_Field_Template;
/**
* Template Selection Clean
@ -52,8 +52,7 @@ class Clean_Template_Selection_Field_Template extends Base_Field_Template {
public function get_render_type(): string {
return 'ajax';
} // end get_render_type;
}
/**
* The title of the field template.
@ -66,8 +65,7 @@ class Clean_Template_Selection_Field_Template extends Base_Field_Template {
public function get_title() {
return __('Clean', 'wp-ultimo');
} // end get_title;
}
/**
* The description of the field template.
@ -80,8 +78,7 @@ class Clean_Template_Selection_Field_Template extends Base_Field_Template {
public function get_description(): string {
return __('A simple layout with minimal styling, just enough to make it usable out-of-the-box.', 'wp-ultimo');
} // end get_description;
}
/**
* The preview of the field template.
@ -92,8 +89,7 @@ class Clean_Template_Selection_Field_Template extends Base_Field_Template {
public function get_preview(): string {
return wu_get_asset('checkout-forms/clean-template-selection.png');
} // end get_preview;
}
/**
* The content of the template.
@ -106,7 +102,5 @@ class Clean_Template_Selection_Field_Template extends Base_Field_Template {
public function output($attributes) {
wu_get_template('checkout/templates/template-selection/clean', $attributes);
} // end output;
} // end class Clean_Template_Selection_Field_Template;
}
}

Some files were not shown because too many files have changed in this diff Show More