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 -->
<!-- https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Customizable-sniff-properties --> <!-- https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Customizable-sniff-properties -->
<config name="minimum_supported_wp_version" value="5.3"/> <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"> <rule ref="WordPress.NamingConventions.PrefixAllGlobals">
<properties> <properties>
<!-- Value: replace the function, class, and variable prefixes used. Separate multiple prefixes with a comma. --> <!-- 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> </properties>
</rule> </rule>
<rule ref="WordPress.WP.I18n"> <rule ref="WordPress.WP.I18n">
@ -45,4 +52,28 @@
<property name="blank_line_check" value="true"/> <property name="blank_line_check" value="true"/>
</properties> </properties>
</rule> </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> </ruleset>

View File

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

View File

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

View File

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

View File

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

View File

@ -12,7 +12,7 @@ namespace WP_Ultimo\Admin_Pages;
// Exit if accessed directly // Exit if accessed directly
defined('ABSPATH') || exit; 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. * 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); 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'), 'render' => array($this, 'render_edit_page'),
'handler' => array($this, 'handle_edit_page'), 'handler' => array($this, 'handle_edit_page'),
'capability' => 'exist', 'capability' => 'exist',
)); )
);
$this->register_page_settings(); $this->register_page_settings();
}
} // end init;
/** /**
* Saves the original parameters and change them with the settings saved. * 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->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->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'] ?? '')); $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. * Renders the edit page form.
@ -127,7 +128,6 @@ abstract class Base_Customer_Facing_Admin_Page extends Base_Admin_Page {
); );
if ($this->menu_settings) { if ($this->menu_settings) {
$fields['position'] = array( $fields['position'] = array(
'type' => 'number', 'type' => 'number',
'title' => __('Menu', 'wp-ultimo'), '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', ''), 'value' => wu_get_isset($settings, 'menu_icon', ''),
'tooltip' => '', 'tooltip' => '',
); );
}
} // end if;
$fields['save_line'] = array( $fields['save_line'] = array(
'type' => 'group', '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); $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', 'views' => 'admin-pages/fields',
'classes' => 'wu-modal-form wu-widget-list wu-striped wu-m-0 wu-mt-0', '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', '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-wu-app' => "{$this->id}_page_customize",
'data-state' => wu_convert_to_state(), 'data-state' => wu_convert_to_state(),
), ),
)); )
);
echo '<div class="wu-styling">'; echo '<div class="wu-styling">';
$form->render(); $form->render();
echo '</div>'; echo '</div>';
}
} // end render_edit_page;
/** /**
* Handles the edit page form and saved changes. * 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); $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']), '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. * 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); $class_name = array_pop($class_name_array);
return wu_replace_dashes(strtolower($class_name)); return wu_replace_dashes(strtolower($class_name));
}
} // end get_page_unique_id;
/** /**
* Grabs the original page parameters. * Grabs the original page parameters.
@ -229,8 +231,7 @@ abstract class Base_Customer_Facing_Admin_Page extends Base_Admin_Page {
public function get_defaults() { public function get_defaults() {
return $this->original_parameters; return $this->original_parameters;
}
} // end get_defaults;
/** /**
* Register the default setting on the core section. * 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() { 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, 'raw' => true,
)); )
);
} // end register_page_settings; }
/** /**
* Get the page settings saved. * 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()); $atts = wu_get_setting($this->get_page_unique_id() . '_settings', array());
return wp_parse_args($atts, $this->get_defaults()); return wp_parse_args($atts, $this->get_defaults());
}
} // end get_page_settings;
/** /**
* Saves the 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. $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); 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. * 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, 'add_additional_body_classes'));
add_action("load-$this->page_hook", array($this, 'additional_on_page_load')); add_action("load-$this->page_hook", array($this, 'additional_on_page_load'));
}
} // end additional_hooks;
/** /**
* Registers additional hooks for the page load. * 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. * @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; $vars['page_title'] = $this->title;
return $vars; return $vars;
},
}, 15); 15
);
} // end additional_on_page_load; }
/** /**
* Adds additional body classes for styling control purposes. * 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() { 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' : ''; $classes .= $this->is_edit_mode() ? ' wu-customize-admin-screen' : '';
return $classes; return $classes;
}
}); );
}
} // end add_additional_body_classes;
/** /**
* Registers and enqueues additional scripts and styles required. * 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'); wp_enqueue_style('wu-admin-screen');
if ($this->is_edit_mode()) { if ($this->is_edit_mode()) {
wp_enqueue_script('dashboard'); wp_enqueue_script('dashboard');
}
} // end if;
if (current_user_can($this->edit_capability)) { 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_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"), 'page_customize_link' => wu_get_form_url("edit_admin_page_$this->id"),
'customize_link' => add_query_arg('customize', 1), 'customize_link' => add_query_arg('customize', 1),
'close_link' => remove_query_arg('customize'), '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'), 'customize_label' => __('Customize Elements', 'wp-ultimo'),
'close_label' => __('Exit Customize Mode', 'wp-ultimo'), 'close_label' => __('Exit Customize Mode', 'wp-ultimo'),
), ),
)); )
);
wp_enqueue_script('wu-admin-screen'); 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. * 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); $saved = wu_get_setting($option);
return empty($saved) ? $result : $saved; return empty($saved) ? $result : $saved;
}
} // end get_settings;
/** /**
* Save the settings globally for columns and order of the widgets. * 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) { public function save_settings($meta_id, $user_id, $meta_key, $_meta_value) {
if (wu_request('action') !== 'meta-box-order') { if (wu_request('action') !== 'meta-box-order') {
return; return;
}
} // end if;
$is_this_page = strpos((string) wu_request('page'), $this->id) !== false; $is_this_page = strpos((string) wu_request('page'), $this->id) !== false;
if ( ! $is_this_page) { if ( ! $is_this_page) {
return; return;
}
} // end if;
if ( ! user_can($user_id, $this->edit_capability)) { if ( ! user_can($user_id, $this->edit_capability)) {
return; return;
}
} // end if;
$meta_key = wu_replace_dashes($meta_key); $meta_key = wu_replace_dashes($meta_key);
wu_save_setting($meta_key, $_meta_value); wu_save_setting($meta_key, $_meta_value);
}
} // end save_settings;
/** /**
* Get the value of editing. * 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() { public function is_edit_mode() {
return $this->editing && current_user_can($this->edit_capability); return $this->editing && current_user_can($this->edit_capability);
}
} // end is_edit_mode;
/** /**
* Adds top-level admin page. * 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() { public function add_toplevel_menu_page() {
if (wu_request('id')) { if (wu_request('id')) {
$this->edit = true; $this->edit = true;
}
} // end if;
return add_menu_page( return add_menu_page(
$this->title, $this->title,
@ -472,7 +464,5 @@ abstract class Base_Customer_Facing_Admin_Page extends Base_Admin_Page {
$this->menu_icon, $this->menu_icon,
$this->position $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 // Exit if accessed directly
defined('ABSPATH') || exit; defined('ABSPATH') || exit;
use \WP_Ultimo\Models\Broadcast; use WP_Ultimo\Models\Broadcast;
/** /**
* WP Multisite WaaS Broadcast Edit/Add New Admin Page. * 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(); parent::register_widgets();
$this->add_list_table_widget('events', array( $this->add_list_table_widget(
'events',
array(
'title' => __('Events', 'wp-ultimo'), 'title' => __('Events', 'wp-ultimo'),
'table' => new \WP_Ultimo\List_Tables\Inside_Events_List_Table(), 'table' => new \WP_Ultimo\List_Tables\Inside_Events_List_Table(),
'query_filter' => array($this, 'events_query_filter'), 'query_filter' => array($this, 'events_query_filter'),
)); )
);
$this->add_save_widget('save', array( $this->add_save_widget(
'save',
array(
'html_attr' => array( 'html_attr' => array(
'data-wu-app' => 'save_broadcast', '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(), 'type' => $this->get_object()->get_type(),
)), )
),
), ),
'fields' => array( 'fields' => array(
'type' => array( 'type' => array(
@ -117,8 +124,8 @@ class Broadcast_Edit_Admin_Page extends Edit_Admin_Page {
'tooltip' => '', 'tooltip' => '',
'html_attr' => array( 'html_attr' => array(
'disabled' => 'disabled', 'disabled' => 'disabled',
'name' => '' 'name' => '',
) ),
), ),
'notice_type' => array( 'notice_type' => array(
'type' => 'select', 'type' => 'select',
@ -136,16 +143,16 @@ class Broadcast_Edit_Admin_Page extends Edit_Admin_Page {
'wrapper_html_attr' => array( 'wrapper_html_attr' => array(
'v-if' => 'type === "broadcast_notice"', 'v-if' => 'type === "broadcast_notice"',
'v-cloak' => 1, '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-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'); 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. * 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', ''); $customer_targets = wu_get_isset($all_targets, 'customers', '');
if ($customer_targets) { if ($customer_targets) {
if (is_array($all_targets['customers'])) { if (is_array($all_targets['customers'])) {
$all_targets['customers'] = $all_targets['customers'][0]; $all_targets['customers'] = $all_targets['customers'][0];
}
} // end if;
$targets = explode(',', (string) $all_targets['customers']); $targets = explode(',', (string) $all_targets['customers']);
}
} // end if;
$targets_count = count($targets); $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); $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, 'force_display' => true,
'class' => 'wu-rounded-full wu-border-solid wu-border-1 wu-border-white hover:wu-border-gray-400', 'class' => 'wu-rounded-full wu-border-solid wu-border-1 wu-border-white hover:wu-border-gray-400',
)); )
);
$display_name = $customer->get_display_name(); $display_name = $customer->get_display_name();
@ -222,16 +231,21 @@ class Broadcast_Edit_Admin_Page extends Edit_Admin_Page {
break; break;
case $targets_count > 1: case $targets_count > 1:
foreach ($targets as $key => $target) { foreach ($targets as $key => $target) {
$customer = wu_get_customer($target); $customer = wu_get_customer($target);
$tooltip_name = $customer->get_display_name(); $tooltip_name = $customer->get_display_name();
$email = $customer->get_email_address(); $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', 'class' => 'wu-rounded-full wu-border-solid wu-border-1 wu-border-white hover:wu-border-gray-400',
)); )
);
$url_atts = array( $url_atts = array(
'id' => $customer->get_id(), '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); $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>"; $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) { if ($targets_count < 7) {
$modal_atts = array( $modal_atts = array(
'action' => 'wu_modal_targets_display', 'action' => 'wu_modal_targets_display',
'object_id' => $object->get_id(), 'object_id' => $object->get_id(),
@ -253,12 +265,16 @@ class Broadcast_Edit_Admin_Page extends Edit_Admin_Page {
'target_type' => 'customers', '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> <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 { } else {
$count = $targets_count - 6; $count = $targets_count - 6;
$modal_atts = array( $modal_atts = array(
@ -269,21 +285,24 @@ class Broadcast_Edit_Admin_Page extends Edit_Admin_Page {
'target_type' => 'customers', '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> <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')); </div>',
wu_get_form_url('view_broadcast_targets', $modal_atts),
} // end if; __('Targets', 'wp-ultimo'),
$targets_count,
__('Targets', 'wp-ultimo')
);
}
break; break;
}
} // end switch;
$html .= '</div></li></ul></div>'; $html .= '</div></li></ul></div>';
echo $html; echo $html;
}
} // end output_default_widget_customer_targets;
/** /**
* Outputs the markup for the products targets widget. * Outputs the markup for the products targets widget.
@ -300,13 +319,10 @@ class Broadcast_Edit_Admin_Page extends Edit_Admin_Page {
$product_targets = array(); $product_targets = array();
if ($targets) { if ($targets) {
foreach ($targets as $key => $value) { foreach ($targets as $key => $value) {
$product = wu_get_product($value); $product = wu_get_product($value);
if ($product) { if ($product) {
$modal_atts = array( $modal_atts = array(
'action' => 'wu_modal_product_targets_display', 'action' => 'wu_modal_product_targets_display',
'product_id' => $product->get_id(), 'product_id' => $product->get_id(),
@ -325,10 +341,8 @@ class Broadcast_Edit_Admin_Page extends Edit_Admin_Page {
$customer_count = (int) 0; $customer_count = (int) 0;
if ($plan_customers) { if ($plan_customers) {
$customer_count = count($plan_customers); $customer_count = count($plan_customers);
}
} // end if;
// translators: %s is the number of customers. // translators: %s is the number of customers.
$description = sprintf(__('%s customer(s) targeted.', 'wp-ultimo'), $customer_count); $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, 'avatar' => $image,
'display_name' => $product->get_name(), 'display_name' => $product->get_name(),
'id' => $product->get_id(), 'id' => $product->get_id(),
'description' => $description 'description' => $description,
); );
}
} // end if; }
}
} // end foreach;
} // end if;
$args = array( $args = array(
'targets' => $product_targets, 'targets' => $product_targets,
@ -355,8 +366,7 @@ class Broadcast_Edit_Admin_Page extends Edit_Admin_Page {
); );
wu_get_template('broadcast/widget-targets', $args); wu_get_template('broadcast/widget-targets', $args);
}
} // end output_default_widget_product_targets;
/** /**
* Returns the title of the page. * Returns the title of the page.
@ -367,8 +377,7 @@ class Broadcast_Edit_Admin_Page extends Edit_Admin_Page {
public function get_title() { public function get_title() {
return $this->edit ? __('Edit Broadcast', 'wp-ultimo') : __('Add new Broadcast', 'wp-ultimo'); return $this->edit ? __('Edit Broadcast', 'wp-ultimo') : __('Add new Broadcast', 'wp-ultimo');
}
} // end get_title;
/** /**
* Returns the title of menu for this page. * 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() { public function get_menu_title() {
return __('Edit Broadcast', 'wp-ultimo'); return __('Edit Broadcast', 'wp-ultimo');
}
} // end get_menu_title;
/** /**
* Returns the action links for that page. * Returns the action links for that page.
@ -391,8 +399,7 @@ class Broadcast_Edit_Admin_Page extends Edit_Admin_Page {
public function action_links() { public function action_links() {
return array(); return array();
}
} // end action_links;
/** /**
* Returns the labels to be used on the admin page. * 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_button_label' => __('Delete Broadcast', 'wp-ultimo'),
'delete_description' => __('Be careful. This action is irreversible.', 'wp-ultimo'), 'delete_description' => __('Be careful. This action is irreversible.', 'wp-ultimo'),
); );
}
} // end get_labels;
/** /**
* Filters the list table to return only relevant events. * 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); return array_merge($args, $extra_args);
}
} // end query_filter;
/** /**
* Returns the object being edit at the moment. * 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() { public function get_object() {
if (isset($_GET['id'])) { 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']); $item = $query->get_item_by('id', $_GET['id']);
if ( ! $item) { if ( ! $item) {
wp_redirect(wu_network_admin_url('wp-ultimo-broadcasts')); wp_redirect(wu_network_admin_url('wp-ultimo-broadcasts'));
exit; exit;
}
} // end if;
return $item; return $item;
}
} // end if; return new Broadcast();
}
return new Broadcast;
} // end get_object;
/** /**
* Broadcasts have titles. * Broadcasts have titles.
@ -473,8 +473,7 @@ class Broadcast_Edit_Admin_Page extends Edit_Admin_Page {
public function has_title(): bool { public function has_title(): bool {
return true; return true;
}
} // end has_title;
/** /**
* Wether or not this pages should have an editor field. * 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 { public function has_editor(): bool {
return true; return true;
}
} // end has_editor;
/** /**
* Filters the list table to return only relevant events. * 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); 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 // Exit if accessed directly
defined('ABSPATH') || exit; defined('ABSPATH') || exit;
use \WP_Ultimo\Managers\Broadcast_Manager; use WP_Ultimo\Managers\Broadcast_Manager;
/** /**
* WP Multisite WaaS Broadcast Admin Page. * WP Multisite WaaS Broadcast Admin Page.
@ -66,11 +66,14 @@ class Broadcast_List_Admin_Page extends List_Admin_Page {
/* /*
* Add new broadcast notice. * 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'), 'render' => array($this, 'render_add_new_broadcast_modal'),
'handler' => array($this, 'handle_add_new_broadcast_modal'), 'handler' => array($this, 'handle_add_new_broadcast_modal'),
'capability' => 'wu_add_broadcasts', 'capability' => 'wu_add_broadcasts',
)); )
);
/** /**
* Ajax to render the broadcast targets modal. * 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. * 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')); add_action('wu_ajax_wu_modal_product_targets_display', array($this, 'display_product_targets_modal'));
}
} // end register_forms;
/** /**
* Enqueue the necessary scripts. * Enqueue the necessary scripts.
@ -95,8 +97,7 @@ class Broadcast_List_Admin_Page extends List_Admin_Page {
parent::register_scripts(); parent::register_scripts();
wp_enqueue_editor(); wp_enqueue_editor();
}
} // end register_scripts;
/** /**
* Renders the broadcast targets modal, when requested. * Renders the broadcast targets modal, when requested.
@ -117,11 +118,8 @@ class Broadcast_List_Admin_Page extends List_Admin_Page {
$display_targets = array(); $display_targets = array();
if ($targets) { if ($targets) {
if ($target_type === 'customers') { if ($target_type === 'customers') {
foreach ($targets as $key => $value) { foreach ($targets as $key => $value) {
$customer = wu_get_customer($value); $customer = wu_get_customer($value);
$url_atts = array( $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); $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, 'force_display' => true,
'class' => 'wu-rounded-full', 'class' => 'wu-rounded-full',
)); )
);
$display_targets[ $key ] = array( $display_targets[ $key ] = array(
'link' => $link, 'link' => $link,
@ -142,15 +146,11 @@ class Broadcast_List_Admin_Page extends List_Admin_Page {
'id' => $customer->get_id(), 'id' => $customer->get_id(),
'description' => $customer->get_email_address(), 'description' => $customer->get_email_address(),
); );
}
} // end foreach; }
} // end if;
if ($target_type === 'products') { if ($target_type === 'products') {
foreach ($targets as $key => $value) { foreach ($targets as $key => $value) {
$product = wu_get_product($value); $product = wu_get_product($value);
$url_atts = array( $url_atts = array(
@ -162,24 +162,18 @@ class Broadcast_List_Admin_Page extends List_Admin_Page {
$avatar = $product->get_featured_image('thumbnail'); $avatar = $product->get_featured_image('thumbnail');
if ($avatar) { 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)); $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 { } else {
$avatar = '<span class="dashicons-wu-image wu-p-1 wu-rounded-full"></span>'; $avatar = '<span class="dashicons-wu-image wu-p-1 wu-rounded-full"></span>';
}
} // end if;
$plan_customers = wu_get_membership_customers($product->get_id()); $plan_customers = wu_get_membership_customers($product->get_id());
$customer_count = (int) 0; $customer_count = (int) 0;
if ($plan_customers) { if ($plan_customers) {
$customer_count = count($plan_customers); $customer_count = count($plan_customers);
}
} // end if;
// translators: %s is the number of customers. // translators: %s is the number of customers.
$description = sprintf(__('%s customer(s) targeted.', 'wp-ultimo'), $customer_count); $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(), 'id' => $product->get_id(),
'description' => $description, 'description' => $description,
); );
}
} // end foreach; }
}
} // end if;
} // end if;
$args = array( $args = array(
'targets' => $display_targets, 'targets' => $display_targets,
@ -207,8 +198,7 @@ class Broadcast_List_Admin_Page extends List_Admin_Page {
wu_get_template('broadcast/widget-targets', $args); wu_get_template('broadcast/widget-targets', $args);
exit; exit;
}
} // end display_targets_modal;
/** /**
* Renders the broadcast targets modal, when requested. * Renders the broadcast targets modal, when requested.
@ -225,9 +215,7 @@ class Broadcast_List_Admin_Page extends List_Admin_Page {
$display_targets = array(); $display_targets = array();
if ($customers) { if ($customers) {
foreach ($customers as $key => $value) { foreach ($customers as $key => $value) {
$customer = wu_get_customer($value); $customer = wu_get_customer($value);
$url_atts = array( $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); $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, 'force_display' => true,
'class' => 'wu-rounded-full', 'class' => 'wu-rounded-full',
)); )
);
$display_targets[ $key ] = array( $display_targets[ $key ] = array(
'link' => $link, 'link' => $link,
@ -248,10 +242,8 @@ class Broadcast_List_Admin_Page extends List_Admin_Page {
'id' => $customer->get_id(), 'id' => $customer->get_id(),
'description' => $customer->get_email_address(), 'description' => $customer->get_email_address(),
); );
}
} // end foreach; }
} // end if;
$args = array( $args = array(
'targets' => $display_targets, 'targets' => $display_targets,
@ -262,8 +254,7 @@ class Broadcast_List_Admin_Page extends List_Admin_Page {
wu_get_template('broadcast/widget-targets', $args); wu_get_template('broadcast/widget-targets', $args);
exit; exit;
}
} // end display_product_targets_modal;
/** /**
* Renders the add new broadcast message 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( 'wrapper_html_attr' => array(
'v-show' => "step === 2 && require('type', 'broadcast_notice')", 'v-show' => "step === 2 && require('type', 'broadcast_notice')",
'v-cloak' => 1 'v-cloak' => 1,
), ),
), ),
'step_note_2' => array( 'step_note_2' => array(
@ -404,7 +395,7 @@ class Broadcast_List_Admin_Page extends List_Admin_Page {
), ),
'html_attr' => array( 'html_attr' => array(
'v-bind:disabled' => 'type === ""', 'v-bind:disabled' => 'type === ""',
'v-on:click.prevent' => 'step = 2' 'v-on:click.prevent' => 'step = 2',
), ),
), ),
'submit_button_2' => array( 'submit_button_2' => array(
@ -418,7 +409,7 @@ class Broadcast_List_Admin_Page extends List_Admin_Page {
), ),
'html_attr' => array( 'html_attr' => array(
'v-bind:disabled' => 'target_customers === "" && target_products === ""', // phpcs:ignore '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( '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', 'views' => 'admin-pages/fields',
'classes' => 'wu-modal-form wu-widget-list wu-striped wu-m-0 wu-mt-0', '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', '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( 'html_attr' => array(
'data-wu-app' => 'add_new_broadcast', 'data-wu-app' => 'add_new_broadcast',
'data-state' => wu_convert_to_state(array( 'data-state' => wu_convert_to_state(
array(
'type' => 'broadcast_notice', 'type' => 'broadcast_notice',
'content' => '', 'content' => '',
'step' => 1, 'step' => 1,
@ -450,13 +445,14 @@ class Broadcast_List_Admin_Page extends List_Admin_Page {
'target_customers' => '', 'target_customers' => '',
'target_products' => '', 'target_products' => '',
'subject' => '', 'subject' => '',
)), )
), ),
)); ),
)
);
$form->render(); $form->render();
}
} // end render_add_new_broadcast_modal;
/** /**
* Handles the 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 = Broadcast_Manager::get_instance();
$broadcast->handle_broadcast(); $broadcast->handle_broadcast();
}
} // end handle_add_new_broadcast_modal;
/** /**
* Allow child classes to register widgets, if they need them. * 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 * @since 1.8.2
* @return void * @return void
*/ */
public function register_widgets() {} // end register_widgets; public function register_widgets() {}
/** /**
* Returns an array with the labels for the edit page. * 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'), 'deleted_message' => __('Broadcast removed successfully.', 'wp-ultimo'),
'search_label' => __('Search Broadcast', 'wp-ultimo'), 'search_label' => __('Search Broadcast', 'wp-ultimo'),
); );
}
} // end get_labels;
/** /**
* Returns the title of the page. * Returns the title of the page.
@ -504,8 +498,7 @@ class Broadcast_List_Admin_Page extends List_Admin_Page {
public function get_title() { public function get_title() {
return __('Broadcast', 'wp-ultimo'); return __('Broadcast', 'wp-ultimo');
}
} // end get_title;
/** /**
* Returns the title of menu for this page. * 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() { public function get_menu_title() {
return __('Broadcasts', 'wp-ultimo'); return __('Broadcasts', 'wp-ultimo');
}
} // end get_menu_title;
/** /**
* Allows admins to rename the sub-menu (first item) for a top-level page. * 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() { public function get_submenu_title() {
return __('Broadcasts', 'wp-ultimo'); return __('Broadcasts', 'wp-ultimo');
}
} // end get_submenu_title;
/** /**
* Returns the action links for that page. * Returns the action links for that page.
@ -552,8 +543,7 @@ class Broadcast_List_Admin_Page extends List_Admin_Page {
'icon' => 'wu-mail', 'icon' => 'wu-mail',
), ),
); );
}
} // end action_links;
/** /**
* Loads the list table for this particular page. * Loads the list table for this particular page.
@ -564,7 +554,5 @@ class Broadcast_List_Admin_Page extends List_Admin_Page {
public function table() { public function table() {
return new \WP_Ultimo\List_Tables\Broadcast_List_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 // Exit if accessed directly
defined('ABSPATH') || exit; defined('ABSPATH') || exit;
use \WP_Ultimo\Models\Checkout_Form; use WP_Ultimo\Models\Checkout_Form;
/** /**
* WP Multisite WaaS Checkout Form Admin Page. * 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() { 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( array(
'id' => 'checkout-form-list', 'id' => 'checkout-form-list',
'title' => __('Checkout Forms', 'wp-ultimo'), 'title' => __('Checkout Forms', 'wp-ultimo'),
@ -84,9 +86,9 @@ class Checkout_Form_List_Admin_Page extends List_Admin_Page {
'on' => 'right', 'on' => 'right',
), ),
), ),
)); )
);
} // end register_widgets; }
/** /**
* Register ajax forms to handle adding new checkout forms. * 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 * 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'), 'render' => array($this, 'render_add_new_checkout_form_modal'),
'handler' => array($this, 'handle_add_new_checkout_form_modal'), 'handler' => array($this, 'handle_add_new_checkout_form_modal'),
'capability' => 'wu_edit_checkout_forms', 'capability' => 'wu_edit_checkout_forms',
)); )
);
} // end register_forms; }
/** /**
* Renders the add new customer modal. * 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', 'views' => 'admin-pages/fields',
'classes' => 'wu-modal-form wu-widget-list wu-striped wu-m-0 wu-mt-0', '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', '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( 'html_attr' => array(
'data-wu-app' => 'add_checkout_form_field', 'data-wu-app' => 'add_checkout_form_field',
'data-state' => json_encode(array( 'data-state' => json_encode(
array(
'template' => 'single-step', 'template' => 'single-step',
)), )
), ),
)); ),
)
);
$form->render(); $form->render();
}
} // end render_add_new_checkout_form_modal;
/** /**
* Handles creation of a new memberships. * Handles creation of a new memberships.
@ -176,7 +185,7 @@ class Checkout_Form_List_Admin_Page extends List_Admin_Page {
$template = wu_request('template'); $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); $checkout_form->use_template($template);
@ -189,20 +198,20 @@ class Checkout_Form_List_Admin_Page extends List_Admin_Page {
$status = $checkout_form->save(); $status = $checkout_form->save();
if (is_wp_error($status)) { if (is_wp_error($status)) {
wp_send_json_error($status); wp_send_json_error($status);
} else { } else {
wp_send_json_success(
wp_send_json_success(array( array(
'redirect_url' => wu_network_admin_url('wp-ultimo-edit-checkout-form', array( 'redirect_url' => wu_network_admin_url(
'wp-ultimo-edit-checkout-form',
array(
'id' => $checkout_form->get_id(), 'id' => $checkout_form->get_id(),
)) )
)); ),
)
} // end if; );
}
} // end handle_add_new_checkout_form_modal; }
/** /**
* Returns an array with the labels for the edit page. * 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'), 'deleted_message' => __('Checkout Form removed successfully.', 'wp-ultimo'),
'search_label' => __('Search Checkout Form', 'wp-ultimo'), 'search_label' => __('Search Checkout Form', 'wp-ultimo'),
); );
}
} // end get_labels;
/** /**
* Returns the title of the page. * Returns the title of the page.
@ -228,8 +236,7 @@ class Checkout_Form_List_Admin_Page extends List_Admin_Page {
public function get_title() { public function get_title() {
return __('Checkout Forms', 'wp-ultimo'); return __('Checkout Forms', 'wp-ultimo');
}
} // end get_title;
/** /**
* Returns the title of menu for this page. * 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() { public function get_menu_title() {
return __('Checkout Forms', 'wp-ultimo'); return __('Checkout Forms', 'wp-ultimo');
}
} // end get_menu_title;
/** /**
* Allows admins to rename the sub-menu (first item) for a top-level page. * 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() { public function get_submenu_title() {
return __('Checkout Forms', 'wp-ultimo'); return __('Checkout Forms', 'wp-ultimo');
}
} // end get_submenu_title;
/** /**
* Returns the action links for that page. * 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'), 'url' => wu_get_form_url('add_new_checkout_form'),
), ),
); );
}
} // end action_links;
/** /**
* Loads the list table for this particular page. * 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() { public function table() {
return new \WP_Ultimo\List_Tables\Checkout_Form_List_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(); parent::init();
add_action('plugins_loaded', array($this, 'export_customers')); add_action('plugins_loaded', array($this, 'export_customers'));
}
} // end init;
/** /**
* Export customers in .csv file * Export customers in .csv file
@ -63,18 +62,15 @@ class Customer_List_Admin_Page extends List_Admin_Page {
public function export_customers() { public function export_customers() {
if (wu_request('wu_action') !== 'wu_export_customers') { if (wu_request('wu_action') !== 'wu_export_customers') {
return; return;
}
} // end if;
if ( ! wp_verify_nonce(wu_request('nonce'), 'wu_export_customers')) { if ( ! wp_verify_nonce(wu_request('nonce'), 'wu_export_customers')) {
wp_die(__('You do not have permissions to access this file.', 'wp-ultimo')); 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(); $memberships = $customer->get_memberships();
@ -104,8 +100,9 @@ class Customer_List_Admin_Page extends List_Admin_Page {
$customer->get_date_registered(), $customer->get_date_registered(),
) )
); );
},
}, wu_get_customers()); wu_get_customers()
);
$billing_fields = array_keys(\WP_Ultimo\Objects\Billing_Address::fields()); $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)); wu_generate_csv($file_name, array_merge(array($headers), $customer_data));
die; die;
}
} // end export_customers;
/** /**
* Holds the admin panels where this page should be displayed, as well as which capability to require. * 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 * 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'), 'render' => array($this, 'render_add_new_customer_modal'),
'handler' => array($this, 'handle_add_new_customer_modal'), 'handler' => array($this, 'handle_add_new_customer_modal'),
'capability' => 'wu_invite_customers', 'capability' => 'wu_invite_customers',
)); )
);
} // end register_forms; }
/** /**
* Renders the add new customer modal. * 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', 'views' => 'admin-pages/fields',
'classes' => 'wu-modal-form wu-widget-list wu-striped wu-m-0 wu-mt-0', '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', '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( 'html_attr' => array(
'data-wu-app' => 'add_new_customer', 'data-wu-app' => 'add_new_customer',
'data-state' => json_encode(array( 'data-state' => json_encode(
array(
'set_password' => false, 'set_password' => false,
'type' => 'existing', 'type' => 'existing',
)), )
), ),
)); ),
)
);
$form->render(); $form->render();
}
} // end render_add_new_customer_modal;
/** /**
* Handles creation of a new customer. * 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() { public function handle_add_new_customer_modal() {
if (wu_request('type', 'existing') === 'new') { if (wu_request('type', 'existing') === 'new') {
$customer_data = array( $customer_data = array(
'email' => wu_request('email_address'), 'email' => wu_request('email_address'),
'username' => wu_request('username'), 'username' => wu_request('username'),
'password' => wu_request('password', false), 'password' => wu_request('password', false),
'meta' => array(), 'meta' => array(),
); );
} else { } else {
$customer_data = array( $customer_data = array(
'user_id' => wu_request('user_id', 0), 'user_id' => wu_request('user_id', 0),
); );
}
} // end if;
/* /*
* Tries to create the customer * Tries to create the customer
@ -301,18 +300,20 @@ class Customer_List_Admin_Page extends List_Admin_Page {
$customer = wu_create_customer($customer_data); $customer = wu_create_customer($customer_data);
if (is_wp_error($customer)) { if (is_wp_error($customer)) {
wp_send_json_error($customer); wp_send_json_error($customer);
}
} // end if; wp_send_json_success(
array(
wp_send_json_success(array( 'redirect_url' => wu_network_admin_url(
'redirect_url' => wu_network_admin_url('wp-ultimo-edit-customer', array( 'wp-ultimo-edit-customer',
array(
'id' => $customer->get_id(), 'id' => $customer->get_id(),
)) )
)); ),
)
} // end handle_add_new_customer_modal; );
}
/** /**
* Allow child classes to register widgets, if they need them. * 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 * @since 1.8.2
* @return void * @return void
*/ */
public function register_widgets() {} // end register_widgets; public function register_widgets() {}
/** /**
* Returns an array with the labels for the edit page. * 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'), 'deleted_message' => __('Customer removed successfully.', 'wp-ultimo'),
'search_label' => __('Search Customer', 'wp-ultimo'), 'search_label' => __('Search Customer', 'wp-ultimo'),
); );
}
} // end get_labels;
/** /**
* Returns the title of the page. * Returns the title of the page.
@ -346,8 +346,7 @@ class Customer_List_Admin_Page extends List_Admin_Page {
public function get_title() { public function get_title() {
return __('Customers', 'wp-ultimo'); return __('Customers', 'wp-ultimo');
}
} // end get_title;
/** /**
* Returns the title of menu for this page. * 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() { public function get_menu_title() {
return __('Customers', 'wp-ultimo'); return __('Customers', 'wp-ultimo');
}
} // end get_menu_title;
/** /**
* Allows admins to rename the sub-menu (first item) for a top-level page. * 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() { public function get_submenu_title() {
return __('Customers', 'wp-ultimo'); return __('Customers', 'wp-ultimo');
}
} // end get_submenu_title;
/** /**
* Returns the action links for that page. * Returns the action links for that page.
@ -391,14 +388,15 @@ class Customer_List_Admin_Page extends List_Admin_Page {
array( array(
'label' => __('Export as CSV', 'wp-ultimo'), 'label' => __('Export as CSV', 'wp-ultimo'),
'icon' => 'wu-export', 'icon' => 'wu-export',
'url' => add_query_arg(array( 'url' => add_query_arg(
array(
'wu_action' => 'wu_export_customers', 'wu_action' => 'wu_export_customers',
'nonce' => wp_create_nonce('wu_export_customers'), 'nonce' => wp_create_nonce('wu_export_customers'),
)), )
),
), ),
); );
}
} // end action_links;
/** /**
* Loads the list table for this particular page. * Loads the list table for this particular page.
@ -409,7 +407,5 @@ class Customer_List_Admin_Page extends List_Admin_Page {
public function table() { public function table() {
return new \WP_Ultimo\List_Tables\Customer_List_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() { public function get_preview_url() {
return get_site_url(null); return get_site_url(null);
}
} // end get_preview_url;
/** /**
* Adds hooks when the page loads. * Adds hooks when the page loads.
@ -61,8 +60,7 @@ abstract class Customizer_Admin_Page extends Edit_Admin_Page {
$screen = get_current_screen(); $screen = get_current_screen();
add_action("wu_edit_{$screen->id}_after_normal", array($this, 'display_preview_window')); add_action("wu_edit_{$screen->id}_after_normal", array($this, 'display_preview_window'));
}
} // end page_loaded;
/** /**
* Adds the preview window. * Adds the preview window.
@ -72,12 +70,14 @@ abstract class Customizer_Admin_Page extends Edit_Admin_Page {
*/ */
public function display_preview_window() { 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_iframe_url' => $this->get_preview_url(),
'preview_height' => $this->preview_height, 'preview_height' => $this->preview_height,
)); )
);
} // end display_preview_window; }
/** /**
* Registers the necessary scripts and styles for this admin page. * 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_script('wp-color-picker');
wp_enqueue_media(); wp_enqueue_media();
}
} // end register_scripts;
/** /**
* Checkout_Forms have titles. * Checkout_Forms have titles.
@ -108,8 +107,7 @@ abstract class Customizer_Admin_Page extends Edit_Admin_Page {
public function has_title() { public function has_title() {
return false; return false;
}
} // end has_title;
/** /**
* Not needed. * Not needed.
@ -117,6 +115,5 @@ abstract class Customizer_Admin_Page extends Edit_Admin_Page {
* @since 2.0.0 * @since 2.0.0
* @return void * @return void
*/ */
public function get_object() {} // end get_object; public function get_object() {}
}
} // end class Customizer_Admin_Page;

View File

@ -12,7 +12,7 @@ namespace WP_Ultimo\Admin_Pages;
// Exit if accessed directly // Exit if accessed directly
defined('ABSPATH') || exit; defined('ABSPATH') || exit;
use \WP_Ultimo\Dashboard_Statistics; use WP_Ultimo\Dashboard_Statistics;
/** /**
* WP Multisite WaaS Dashboard Admin Page. * 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->tab = wu_request('tab', 'general');
$this->start_date = date_i18n('Y-m-d', strtotime((string) wu_request('start_date', '-1 month'))); $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'))); $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. * 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_dash_after_full_metaboxes', array($this, 'render_filter'));
add_action('wu_dashboard_general_widgets', array($this, 'register_general_tab_widgets'), 10, 2); add_action('wu_dashboard_general_widgets', array($this, 'register_general_tab_widgets'), 10, 2);
}
} // end hooks;
/** /**
* Renders the filter. * Renders the filter.
@ -133,13 +131,10 @@ class Dashboard_Admin_Page extends Base_Admin_Page {
public function render_filter($page) { public function render_filter($page) {
if (apply_filters('wu_dashboard_display_filter', true) === false) { if (apply_filters('wu_dashboard_display_filter', true) === false) {
return; return;
}
} // end if;
if ($page->id === 'wp-ultimo') { if ($page->id === 'wp-ultimo') {
$preset_options = array( $preset_options = array(
'last_7_days' => array( 'last_7_days' => array(
'label' => __('Last 7 days', 'wp-ultimo'), '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); wu_get_template('dashboard-statistics/filter', $args);
}
} // end if; }
} // end render_filter;
/** /**
* Returns the views for the filter menu bar. * 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); return apply_filters('wu_dashboard_filter_bar', $dashboard_filters);
}
} // end get_views;
/** /**
* Allow child classes to register widgets, if they need them. * 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(); $screen = get_current_screen();
if ( ! $screen) { if ( ! $screen) {
return; return;
}
} // end if;
/** /**
* Allow plugin developers to add widgets to Network Dashboard Panel. * 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); do_action('wu_dashboard_widgets', $this->tab, $screen, $this);
if (wu_request('tab', 'general') === 'general') { if (wu_request('tab', 'general') === 'general') {
\WP_Ultimo\UI\Tours::get_instance()->create_tour(
\WP_Ultimo\UI\Tours::get_instance()->create_tour('wp-ultimo-dashboard', array( 'wp-ultimo-dashboard',
array(
array( array(
'id' => 'your-dashboard', 'id' => 'your-dashboard',
'title' => __('Our dashboard', 'wp-ultimo'), 'title' => __('Our dashboard', 'wp-ultimo'),
@ -278,11 +269,10 @@ class Dashboard_Admin_Page extends Base_Admin_Page {
'on' => 'bottom', 'on' => 'bottom',
), ),
), ),
)); )
);
} // end if; }
}
} // end register_widgets;
/** /**
* Register the widgets of the default general tab. * 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) { public function register_general_tab_widgets($tab, $screen) {
if (current_user_can('wu_read_financial')) { 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-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'); 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'); 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-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'); 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 * Output the statistics filter widget
@ -322,8 +309,7 @@ class Dashboard_Admin_Page extends Base_Admin_Page {
public function output_widget_mrr_growth() { public function output_widget_mrr_growth() {
wu_get_template('dashboard-statistics/widget-mrr-growth'); wu_get_template('dashboard-statistics/widget-mrr-growth');
}
} // end output_widget_mrr_growth;
/** /**
* Output the statistics filter widget * Output the statistics filter widget
@ -333,12 +319,14 @@ class Dashboard_Admin_Page extends Base_Admin_Page {
*/ */
public function output_widget_countries() { 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), 'countries' => wu_get_countries_of_customers(10, $this->start_date, $this->end_date),
'page' => $this, 'page' => $this,
)); )
);
} // end output_widget_countries; }
/** /**
* Output the statistics filter widget * Output the statistics filter widget
@ -348,12 +336,14 @@ class Dashboard_Admin_Page extends Base_Admin_Page {
*/ */
public function output_widget_forms() { 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), 'forms' => wu_calculate_signups_by_form($this->start_date, $this->end_date),
'page' => $this, 'page' => $this,
)); )
);
} // end output_widget_forms; }
/** /**
* Output the statistics filter widget * 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); $site_results = \WP_Ultimo\Objects\Visits::get_sites_by_visit_count($this->start_date, $this->end_date, 10);
foreach ($site_results as $site_result) { foreach ($site_results as $site_result) {
$site = wu_get_site($site_result->site_id); $site = wu_get_site($site_result->site_id);
if ( ! $site) { if ( ! $site) {
continue; continue;
}
} // end if;
$sites[] = (object) array( $sites[] = (object) array(
'site' => $site, 'site' => $site,
'count' => $site_result->count, 'count' => $site_result->count,
); );
}
} // end foreach; wu_get_template(
'dashboard-statistics/widget-most-visited-sites',
wu_get_template('dashboard-statistics/widget-most-visited-sites', array( array(
'sites' => $sites, 'sites' => $sites,
'page' => $this, 'page' => $this,
)); )
);
} // end output_widget_most_visited_sites; }
/** /**
* Outputs the total refunds widget content. * 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) { 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(), 'mrr' => wu_calculate_mrr(),
'gross_revenue' => wu_calculate_revenue($this->start_date, $this->end_date), 'gross_revenue' => wu_calculate_revenue($this->start_date, $this->end_date),
'refunds' => wu_calculate_refunds($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), 'product_stats' => wu_calculate_financial_data_by_product($this->start_date, $this->end_date),
)); )
);
} // end output_widget_revenues; }
/** /**
* Outputs the total refunds widget content. * 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()) { 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'), 'fields' => array('plan_id'),
'date_query' => array( 'date_query' => array(
'column' => 'date_created', 'column' => 'date_created',
@ -430,24 +421,29 @@ class Dashboard_Admin_Page extends Base_Admin_Page {
'before' => $this->end_date . ' 23:59:59', 'before' => $this->end_date . ' 23:59:59',
'inclusive' => true, 'inclusive' => true,
), ),
)); )
);
$products = wu_get_products(array( $products = wu_get_products(
array(
'type' => 'plan', 'type' => 'plan',
'fields' => array('id', 'name', 'count'), 'fields' => array('id', 'name', 'count'),
)); )
);
$products_ids = array_column($products, 'id'); $products_ids = array_column($products, 'id');
$products = array_combine($products_ids, $products); $products = array_combine($products_ids, $products);
$products = array_map(function($item) { $products = array_map(
function ($item) {
$item->count = 0; $item->count = 0;
return $item; return $item;
},
}, $products); $products
);
/** /**
* Add edge case for no plan. * Add edge case for no plan.
@ -458,25 +454,21 @@ class Dashboard_Admin_Page extends Base_Admin_Page {
); );
foreach ($new_accounts as $new_account) { foreach ($new_accounts as $new_account) {
if (isset($products[ $new_account->plan_id ])) { if (isset($products[ $new_account->plan_id ])) {
$products[ $new_account->plan_id ]->count += 1; $products[ $new_account->plan_id ]->count += 1;
} else { } else {
$products['none']->count += 1; $products['none']->count += 1;
}
}
} // end if; wu_get_template(
'dashboard-statistics/widget-new-accounts',
} // end foreach; array(
wu_get_template('dashboard-statistics/widget-new-accounts', array(
'new_accounts' => count($new_accounts), 'new_accounts' => count($new_accounts),
'products' => $products, 'products' => $products,
)); )
);
} // end output_widget_new_accounts; }
/** /**
* Enqueue the necessary scripts. * 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)); $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, 'start_date' => $this->start_date,
'end_date' => $this->end_date, 'end_date' => $this->end_date,
'types' => array( 'types' => array(
'mrr_growth' => 'mrr_growth', 'mrr_growth' => 'mrr_growth',
), ),
)); )
);
$data = $statistics->statistics_data(); $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_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'], 'mrr_array' => $data['mrr_growth'],
'start_date' => date_i18n('Y-m-d', strtotime((string) wu_request('start_date', '-1 month'))), 'start_date' => date_i18n('Y-m-d', strtotime((string) wu_request('start_date', '-1 month'))),
'end_date' => date_i18n('Y-m-d', strtotime((string) wu_request('end_date', 'tomorrow'))), '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'), 'new_mrr' => __('New MRR', 'wp-ultimo'),
'cancellations' => __('Cancellations', 'wp-ultimo'), 'cancellations' => __('Cancellations', 'wp-ultimo'),
), ),
)); )
);
wp_enqueue_script('wu-dashboard-stats'); 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-apex-charts', wu_get_asset('apexcharts.css', 'css'), array(), wu_get_version());
wp_enqueue_style('wu-flags'); wp_enqueue_style('wu-flags');
}
} // end register_scripts;
/** /**
* Returns the title of the page. * Returns the title of the page.
@ -539,8 +536,7 @@ class Dashboard_Admin_Page extends Base_Admin_Page {
public function get_title() { public function get_title() {
return __('Dashboard', 'wp-ultimo'); return __('Dashboard', 'wp-ultimo');
}
} // end get_title;
/** /**
* Returns the title of menu for this page. * 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() { public function get_menu_title() {
return __('Multisite WaaS', 'wp-ultimo'); return __('Multisite WaaS', 'wp-ultimo');
}
} // end get_menu_title;
/** /**
* Allows admins to rename the sub-menu (first item) for a top-level page. * 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() { public function get_submenu_title() {
return __('Dashboard', 'wp-ultimo'); return __('Dashboard', 'wp-ultimo');
}
} // end get_submenu_title;
/** /**
* Every child class should implement the output method to display the contents of the page. * 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 =) * 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(), 'screen' => get_current_screen(),
'page' => $this, 'page' => $this,
'has_full_position' => true, 'has_full_position' => true,
)); )
);
} // end output; }
/** /**
* Render an export CSV button. * Render an export CSV button.
@ -594,12 +590,15 @@ class Dashboard_Admin_Page extends Base_Admin_Page {
*/ */
public function render_csv_button($args) { public function render_csv_button($args) {
$args = wp_parse_args($args, array( $args = wp_parse_args(
$args,
array(
'slug' => 'csv', 'slug' => 'csv',
'headers' => array(), 'headers' => array(),
'data' => array(), 'data' => array(),
'action' => apply_filters('wu_export_data_table_action', 'wu_generate_csv'), 'action' => apply_filters('wu_export_data_table_action', 'wu_generate_csv'),
)); )
);
$slug = $args['slug']; $slug = $args['slug'];
@ -621,8 +620,6 @@ class Dashboard_Admin_Page extends Base_Admin_Page {
$html = apply_filters('wu_export_html_render', $html, $html); $html = apply_filters('wu_export_html_render', $html, $html);
echo sprintf($html, apply_filters('wu_export_data_table_label', __('CSV', 'wp-ultimo'))); printf($html, apply_filters('wu_export_data_table_label', __('CSV', 'wp-ultimo')));
}
} // end render_csv_button; }
} // end class Dashboard_Admin_Page;

View File

@ -12,8 +12,8 @@ namespace WP_Ultimo\Admin_Pages;
// Exit if accessed directly // Exit if accessed directly
defined('ABSPATH') || exit; defined('ABSPATH') || exit;
use \WP_Ultimo\Models\Discount_Code; use WP_Ultimo\Models\Discount_Code;
use \WP_Ultimo\Managers\Discount_Code_Manager; use WP_Ultimo\Managers\Discount_Code_Manager;
/** /**
* WP Multisite WaaS Discount_Code Edit/Add New Admin Page. * 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(); parent::register_widgets();
$this->add_fields_widget('description', array( $this->add_fields_widget(
'description',
array(
'title' => __('Description', 'wp-ultimo'), 'title' => __('Description', 'wp-ultimo'),
'position' => 'normal', 'position' => 'normal',
'fields' => array( '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')); $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', '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'), 'title' => __('Advanced Options', 'wp-ultimo'),
'position' => 'normal', 'position' => 'normal',
'sections' => apply_filters('wu_discount_code_options_sections', $options, $this->get_object()), 'sections' => apply_filters('wu_discount_code_options_sections', $options, $this->get_object()),
)); )
);
/* /*
* Handle legacy options for back-compat. * Handle legacy options for back-compat.
*/ */
$this->handle_legacy_options(); $this->handle_legacy_options();
$this->add_list_table_widget('events', array( $this->add_list_table_widget(
'events',
array(
'title' => __('Events', 'wp-ultimo'), 'title' => __('Events', 'wp-ultimo'),
'table' => new \WP_Ultimo\List_Tables\Inside_Events_List_Table(), 'table' => new \WP_Ultimo\List_Tables\Inside_Events_List_Table(),
'query_filter' => array($this, 'query_filter'), 'query_filter' => array($this, 'query_filter'),
)); )
);
$this->add_save_widget('save', array( $this->add_save_widget(
'save',
array(
'html_attr' => array( 'html_attr' => array(
'data-wu-app' => 'save_discount_code', '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, 'apply_to_setup_fee' => $this->get_object()->get_setup_fee_value() > 0,
'code' => $this->get_object()->get_code(), 'code' => $this->get_object()->get_code(),
'type' => $this->get_object()->get_type(), 'type' => $this->get_object()->get_type(),
'value' => $this->get_object()->get_value(), 'value' => $this->get_object()->get_value(),
'setup_fee_type' => $this->get_object()->get_setup_fee_type(), 'setup_fee_type' => $this->get_object()->get_setup_fee_type(),
'setup_fee_value' => $this->get_object()->get_setup_fee_value(), 'setup_fee_value' => $this->get_object()->get_setup_fee_value(),
)), )
),
), ),
'fields' => array( 'fields' => array(
'code' => array( 'code' => array(
@ -294,7 +308,7 @@ class Discount_Code_Edit_Admin_Page extends Edit_Admin_Page {
'html_attr' => array( 'html_attr' => array(
'min' => 0, 'min' => 0,
'v-bind:max' => "type === 'percentage' ? 100 : 999999999", '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'), 'title' => __('Active', 'wp-ultimo'),
'fields' => array( 'fields' => array(
'active' => array( 'active' => array(
@ -367,9 +384,9 @@ class Discount_Code_Edit_Admin_Page extends Edit_Admin_Page {
'value' => $this->get_object()->is_active(), 'value' => $this->get_object()->is_active(),
), ),
), ),
)); )
);
} // end register_widgets; }
/** /**
* List of products to apply this coupon to. * List of products to apply this coupon to.
@ -382,7 +399,6 @@ class Discount_Code_Edit_Admin_Page extends Edit_Admin_Page {
$fields = array(); $fields = array();
foreach (wu_get_products() as $product) { foreach (wu_get_products() as $product) {
$product_id = $product->get_id(); $product_id = $product->get_id();
$fields[ "allowed_products_{$product_id}" ] = array( $fields[ "allowed_products_{$product_id}" ] = array(
@ -410,11 +426,9 @@ class Discount_Code_Edit_Admin_Page extends Edit_Admin_Page {
':name' => "'allowed_products[]'", ':name' => "'allowed_products[]'",
), ),
); );
}
} // end foreach;
if (empty($fields)) { if (empty($fields)) {
$fields['allowed_products_no_products'] = array( $fields['allowed_products_no_products'] = array(
'type' => 'note', 'type' => 'note',
'title' => '', 'title' => '',
@ -424,12 +438,10 @@ class Discount_Code_Edit_Admin_Page extends Edit_Admin_Page {
'v-show' => 'limit_products', 'v-show' => 'limit_products',
), ),
); );
}
} // end if;
return $fields; return $fields;
}
} // end get_product_field_list;
/** /**
* Handles legacy advanced options for coupons. * 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')); $tabs = array(__('Legacy Add-ons', 'wp-ultimo'));
if ( ! isset($wp_filter['wp_ultimo_coupon_advanced_options'])) { if ( ! isset($wp_filter['wp_ultimo_coupon_advanced_options'])) {
return; return;
}
} // end if;
wp_enqueue_style('wu-legacy-admin-tabs', wu_get_asset('legacy-admin-tabs.css', 'css'), false, wu_get_version()); 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 ($priorities as $priority => $callbacks) {
foreach ($callbacks as $id => $callable) { foreach ($callbacks as $id => $callable) {
$fields[ $id ] = array( $fields[ $id ] = array(
'type' => 'html', 'type' => 'html',
'classes' => 'wu--mt-2', 'classes' => 'wu--mt-2',
'content' => function () use ($callable) { 'content' => function () use ($callable) {
call_user_func($callable['function'], $this->get_object()); call_user_func($callable['function'], $this->get_object());
}, },
); );
}
}
} // end foreach; $this->add_fields_widget(
'legacy-options',
} // end foreach; array(
$this->add_fields_widget('legacy-options', array(
'title' => __('Legacy Options', 'wp-ultimo'), 'title' => __('Legacy Options', 'wp-ultimo'),
'position' => 'normal', 'position' => 'normal',
'fields' => $fields, 'fields' => $fields,
@ -489,9 +496,9 @@ class Discount_Code_Edit_Admin_Page extends Edit_Admin_Page {
'html_attr' => array( 'html_attr' => array(
'style' => 'margin-top: -5px;', 'style' => 'margin-top: -5px;',
), ),
)); )
);
} // end handle_legacy_options; }
/** /**
* Register ajax forms that we use for discount code. * 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 * Delete Discount code - Confirmation modal
*/ */
add_filter('wu_data_json_success_delete_discount_code_modal', fn($data_json) => array( add_filter(
'redirect_url' => wu_network_admin_url('wp-ultimo-discount-codes', array('deleted' => 1)) '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; )
);
}
/** /**
* Filters the list table to return only relevant events. * 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); return array_merge($args, $extra_args);
}
} // end query_filter;
/** /**
* Returns the title of the page. * Returns the title of the page.
@ -538,8 +546,7 @@ class Discount_Code_Edit_Admin_Page extends Edit_Admin_Page {
public function get_title() { public function get_title() {
return $this->edit ? __('Edit Discount Code', 'wp-ultimo') : __('Add new Discount Code', 'wp-ultimo'); 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. * 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() { public function get_menu_title() {
return __('Edit Discount Code', 'wp-ultimo'); return __('Edit Discount Code', 'wp-ultimo');
}
} // end get_menu_title;
/** /**
* Returns the action links for that page. * 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() { public function action_links() {
return array(); return array();
}
} // end action_links;
/** /**
* Returns the labels to be used on the admin page. * 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_button_label' => __('Delete Discount Code', 'wp-ultimo'),
'delete_description' => __('Be careful. This action is irreversible.', 'wp-ultimo'), 'delete_description' => __('Be careful. This action is irreversible.', 'wp-ultimo'),
); );
}
} // end get_labels;
/** /**
* Returns the object being edit at the moment. * 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() { public function get_object() {
if ($this->object !== null) { if ($this->object !== null) {
return $this->object; return $this->object;
}
} // end if;
if (isset($_GET['id'])) { if (isset($_GET['id'])) {
$item_id = wu_request('id', 0); $item_id = wu_request('id', 0);
$item = wu_get_discount_code($item_id); $item = wu_get_discount_code($item_id);
if ( ! $item) { if ( ! $item) {
wp_redirect(wu_network_admin_url('wp-ultimo-discount_codes')); wp_redirect(wu_network_admin_url('wp-ultimo-discount_codes'));
exit; exit;
}
} // end if;
$this->object = $item; $this->object = $item;
return $this->object; return $this->object;
}
} // end if; $this->object = new Discount_Code();
$this->object = new Discount_Code;
return $this->object; return $this->object;
}
} // end get_object;
/** /**
* Discount_Codes have titles. * Discount_Codes have titles.
* *
@ -634,8 +631,7 @@ class Discount_Code_Edit_Admin_Page extends Edit_Admin_Page {
public function has_title(): bool { public function has_title(): bool {
return true; return true;
}
} // end has_title;
/** /**
* Should implement the processes necessary to save the changes made to the object. * 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. * Set the recurring value to zero if the toggle is disabled.
*/ */
if ( ! wu_request('apply_to_renewals')) { if ( ! wu_request('apply_to_renewals')) {
$_POST['apply_to_renewals'] = false; $_POST['apply_to_renewals'] = false;
}
} // end if;
/* /*
* Set the limit products value. * Set the limit products value.
*/ */
if ( ! wu_request('limit_products')) { if ( ! wu_request('limit_products')) {
$_POST['limit_products'] = false; $_POST['limit_products'] = false;
}
} // end if;
/* /*
* Set the setup fee value to zero if the toggle is disabled. * Set the setup fee value to zero if the toggle is disabled.
*/ */
if ( ! wu_request('apply_to_setup_fee')) { if ( ! wu_request('apply_to_setup_fee')) {
$_POST['setup_fee_value'] = 0; $_POST['setup_fee_value'] = 0;
}
} // end if;
/** /**
* Unset dates to prevent invalid dates * Unset dates to prevent invalid dates
*/ */
if ( ! wu_request('enable_date_start') || ! wu_validate_date(wu_request('date_start'))) { if ( ! wu_request('enable_date_start') || ! wu_validate_date(wu_request('date_start'))) {
$_POST['date_start'] = null; $_POST['date_start'] = null;
}
} // end if;
if ( ! wu_request('enable_date_expiration') || ! wu_validate_date(wu_request('date_expiration'))) { if ( ! wu_request('enable_date_expiration') || ! wu_validate_date(wu_request('date_expiration'))) {
$_POST['date_expiration'] = null; $_POST['date_expiration'] = null;
}
} // end if;
$_POST['code'] = trim((string) wu_request('code')); $_POST['code'] = trim((string) wu_request('code'));
parent::handle_save(); 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 * @since 1.8.2
* @return void * @return void
*/ */
public function register_widgets() {} // end register_widgets; public function register_widgets() {}
/** /**
* Returns an array with the labels for the edit page. * 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'), 'deleted_message' => __('Discount Code removed successfully.', 'wp-ultimo'),
'search_label' => __('Search Discount Code', 'wp-ultimo'), 'search_label' => __('Search Discount Code', 'wp-ultimo'),
); );
}
} // end get_labels;
/** /**
* Returns the title of the page. * Returns the title of the page.
@ -86,8 +85,7 @@ class Discount_Code_List_Admin_Page extends List_Admin_Page {
public function get_title() { public function get_title() {
return __('Discount Codes', 'wp-ultimo'); return __('Discount Codes', 'wp-ultimo');
}
} // end get_title;
/** /**
* Returns the title of menu for this page. * 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() { public function get_menu_title() {
return __('Discount Codes', 'wp-ultimo'); return __('Discount Codes', 'wp-ultimo');
}
} // end get_menu_title;
/** /**
* Allows admins to rename the sub-menu (first item) for a top-level page. * 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() { public function get_submenu_title() {
return __('Discount Codes', 'wp-ultimo'); return __('Discount Codes', 'wp-ultimo');
}
} // end get_submenu_title;
/** /**
* Returns the action links for that page. * 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', 'icon' => 'wu-circle-with-plus',
), ),
); );
}
} // end action_links;
/** /**
* Loads the list table for this particular page. * 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() { public function table() {
return new \WP_Ultimo\List_Tables\Discount_Code_List_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 // Exit if accessed directly
defined('ABSPATH') || exit; 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. * 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_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')); 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. * 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; $has_other_domains = false;
if ($is_primary_domain) { if ($is_primary_domain) {
$other_domains = \WP_Ultimo\Models\Domain::get_by_site($domain->get_blog_id()); $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; $has_other_domains = is_countable($other_domains) ? count($other_domains) - 1 : false;
}
} // end if;
$custom_fields = array( $custom_fields = array(
'set_domain_as_primary' => 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); return array_merge($custom_fields, $fields);
}
} // end domain_extra_delete_fields;
/** /**
* Adds the primary domain handling to the domain deletion. * 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); $new_primary_domain = wu_get_domain($new_primary_domain_name);
if ($new_primary_domain) { if ($new_primary_domain) {
$new_primary_domain->set_primary_domain(true); $new_primary_domain->set_primary_domain(true);
$new_primary_domain->save(); $new_primary_domain->save();
}
} // end if; }
} // end domain_after_delete_actions;
/** /**
* Allow child classes to register widgets, if they need them. * 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(); parent::register_widgets();
$this->add_fields_widget('domain-url', array( $this->add_fields_widget(
'domain-url',
array(
'title' => __('Domain URL', 'wp-ultimo'), 'title' => __('Domain URL', 'wp-ultimo'),
'position' => 'normal', 'position' => 'normal',
'after' => array($this, 'render_dns_widget'), '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>', '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'), 'title' => __('Domain Options', 'wp-ultimo'),
'position' => 'normal', 'position' => 'normal',
'sections' => array( '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'), 'title' => __('Linked Site', 'wp-ultimo'),
'table' => new \WP_Ultimo\List_Tables\Memberships_Site_List_Table(), 'table' => new \WP_Ultimo\List_Tables\Memberships_Site_List_Table(),
'query_filter' => array($this, 'sites_query_filter'), '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); 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'), 'title' => __('Events', 'wp-ultimo'),
'table' => new \WP_Ultimo\List_Tables\Inside_Events_List_Table(), 'table' => new \WP_Ultimo\List_Tables\Inside_Events_List_Table(),
'query_filter' => array($this, 'query_filter'), 'query_filter' => array($this, 'query_filter'),
)); )
);
$this->add_save_widget('save', array( $this->add_save_widget(
'save',
array(
'html_attr' => array( 'html_attr' => array(
'data-wu-app' => 'save', 'data-wu-app' => 'save',
'data-state' => wu_convert_to_state( array( 'data-state' => wu_convert_to_state(
array(
'stage' => $this->get_object()->get_stage(), 'stage' => $this->get_object()->get_stage(),
)), )
),
), ),
'fields' => array( 'fields' => array(
'stage' => 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)); $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'), 'title' => __('Active', 'wp-ultimo'),
'html_attr' => array( 'html_attr' => array(
'data-wu-app' => 'basic', 'data-wu-app' => 'basic',
'data-state' => wu_convert_to_state( array( 'data-state' => wu_convert_to_state(
array(
'stage' => $this->get_object()->get_stage(), 'stage' => $this->get_object()->get_stage(),
)), )
),
), ),
'fields' => array( 'fields' => array(
'active' => array( 'active' => array(
@ -347,8 +361,9 @@ class Domain_Edit_Admin_Page extends Edit_Admin_Page {
), ),
), ),
), ),
)); )
} // end register_widgets; );
}
/** /**
* Renders the DNS widget * Renders the DNS widget
@ -358,11 +373,13 @@ class Domain_Edit_Admin_Page extends Edit_Admin_Page {
*/ */
public function render_dns_widget() { public function render_dns_widget() {
wu_get_template('domain/dns-table', array( wu_get_template(
'domain/dns-table',
array(
'domain' => $this->get_object(), 'domain' => $this->get_object(),
)); )
);
} // end render_dns_widget; }
/** /**
* Renders the DNS widget * Renders the DNS widget
@ -372,12 +389,14 @@ class Domain_Edit_Admin_Page extends Edit_Admin_Page {
*/ */
public function render_log_widget() { public function render_log_widget() {
wu_get_template('domain/log', array( wu_get_template(
'domain/log',
array(
'domain' => $this->get_object(), 'domain' => $this->get_object(),
'log_path' => \WP_Ultimo\Logger::get_logs_folder(), 'log_path' => \WP_Ultimo\Logger::get_logs_folder(),
)); )
);
} // end render_log_widget; }
/** /**
* Returns the title of the page. * Returns the title of the page.
@ -388,8 +407,7 @@ class Domain_Edit_Admin_Page extends Edit_Admin_Page {
public function get_title() { public function get_title() {
return $this->edit ? __('Edit Domain', 'wp-ultimo') : __('Add new Domain', 'wp-ultimo'); return $this->edit ? __('Edit Domain', 'wp-ultimo') : __('Add new Domain', 'wp-ultimo');
}
} // end get_title;
/** /**
* Returns the title of menu for this page. * 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() { public function get_menu_title() {
return __('Edit Domain', 'wp-ultimo'); return __('Edit Domain', 'wp-ultimo');
}
} // end get_menu_title;
/** /**
* Returns the action links for that page. * Returns the action links for that page.
@ -412,8 +429,7 @@ class Domain_Edit_Admin_Page extends Edit_Admin_Page {
public function action_links() { public function action_links() {
return array(); return array();
}
} // end action_links;
/** /**
* Returns the labels to be used on the admin page. * 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_button_label' => __('Delete Domain', 'wp-ultimo'),
'delete_description' => __('Be careful. This action is irreversible.', 'wp-ultimo'), 'delete_description' => __('Be careful. This action is irreversible.', 'wp-ultimo'),
); );
}
} // end get_labels;
/** /**
* Filters the list table to return only relevant events. * 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); return array_merge($args, $extra_args);
}
} // end query_filter;
/** /**
* Filters the list table to return only relevant sites. * 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(); $args['blog_id'] = $this->get_object()->get_site_id();
return $args; return $args;
}
} // end sites_query_filter;
/** /**
* Returns the object being edit at the moment. * 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() { public function get_object() {
if ($this->object !== null) { if ($this->object !== null) {
return $this->object; return $this->object;
}
} // end if;
$item_id = wu_request('id', 0); $item_id = wu_request('id', 0);
$item = wu_get_domain($item_id); $item = wu_get_domain($item_id);
if ( ! $item) { if ( ! $item) {
wp_redirect(wu_network_admin_url('wp-ultimo-domains')); wp_redirect(wu_network_admin_url('wp-ultimo-domains'));
exit; exit;
}
} // end if;
$this->object = $item; $this->object = $item;
return $this->object; return $this->object;
}
} // end get_object;
/** /**
* Domains have titles. * Domains have titles.
* *
@ -511,8 +519,7 @@ class Domain_Edit_Admin_Page extends Edit_Admin_Page {
public function has_title(): bool { public function has_title(): bool {
return false; return false;
}
} // end has_title;
/** /**
* Should implement the processes necessary to save the changes made to the object. * 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() { public function handle_save() {
if ( ! wu_request('primary_domain')) { if ( ! wu_request('primary_domain')) {
$_POST['primary_domain'] = false; $_POST['primary_domain'] = false;
}
} // end if;
if ( ! wu_request('active')) { if ( ! wu_request('active')) {
$_POST['active'] = false; $_POST['active'] = false;
}
} // end if;
if ( ! wu_request('secure')) { if ( ! wu_request('secure')) {
$_POST['secure'] = false; $_POST['secure'] = false;
}
} // end if;
wu_enqueue_async_action('wu_async_process_domain_stage', array('domain_id' => $this->get_object()->get_id()), 'domain'); wu_enqueue_async_action('wu_async_process_domain_stage', array('domain_id' => $this->get_object()->get_id()), 'domain');
parent::handle_save(); 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 // Exit if accessed directly
defined('ABSPATH') || exit; defined('ABSPATH') || exit;
use \WP_Ultimo\Models\Domain; use WP_Ultimo\Models\Domain;
use \WP_Ultimo\Database\Domains\Domain_Stage; use WP_Ultimo\Database\Domains\Domain_Stage;
/** /**
* WP Multisite WaaS Dashboard Admin Page. * WP Multisite WaaS Dashboard Admin Page.
@ -67,13 +67,15 @@ class Domain_List_Admin_Page extends List_Admin_Page {
/* /*
* Add new Domain * 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'), 'render' => array($this, 'render_add_new_domain_modal'),
'handler' => array($this, 'handle_add_new_domain_modal'), 'handler' => array($this, 'handle_add_new_domain_modal'),
'capability' => 'wu_edit_domains', 'capability' => 'wu_edit_domains',
)); )
);
} // end register_forms; }
/** /**
* Renders the add new customer modal. * 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() { public function render_add_new_domain_modal() {
$addon_url = wu_network_admin_url('wp-ultimo-addons', array( $addon_url = wu_network_admin_url(
's' => 'Domain Seller' 'wp-ultimo-addons',
)); array(
's' => 'Domain Seller',
)
);
// translators: %s is the URL to the add-on. // 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); $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', 'views' => 'admin-pages/fields',
'classes' => 'wu-modal-form wu-widget-list wu-striped wu-m-0 wu-mt-0', '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', '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( 'html_attr' => array(
'data-wu-app' => 'add_new_domain', 'data-wu-app' => 'add_new_domain',
'data-state' => json_encode(array( 'data-state' => json_encode(
array(
'type' => 'add', 'type' => 'add',
'primary_domain' => false, 'primary_domain' => false,
)), )
), ),
)); ),
)
);
$form->render(); $form->render();
}
} // end render_add_new_domain_modal;
/** /**
* Handles creation of a new customer. * Handles creation of a new customer.
@ -218,46 +228,49 @@ class Domain_List_Admin_Page extends List_Admin_Page {
/* /*
* Tries to create the domain * Tries to create the domain
*/ */
$domain = wu_create_domain(array( $domain = wu_create_domain(
array(
'domain' => wu_request('domain'), 'domain' => wu_request('domain'),
'stage' => wu_request('stage'), 'stage' => wu_request('stage'),
'blog_id' => (int) wu_request('blog_id'), 'blog_id' => (int) wu_request('blog_id'),
'primary_domain' => (bool) wu_request('primary_domain'), 'primary_domain' => (bool) wu_request('primary_domain'),
)); )
);
if (is_wp_error($domain)) { if (is_wp_error($domain)) {
wp_send_json_error($domain); wp_send_json_error($domain);
}
} // end if;
if (wu_request('primary_domain')) { if (wu_request('primary_domain')) {
$old_primary_domains = wu_get_domains(
$old_primary_domains = wu_get_domains(array( array(
'primary_domain' => true, 'primary_domain' => true,
'blog_id' => wu_request('blog_id'), 'blog_id' => wu_request('blog_id'),
'id__not_in' => array($domain->get_id()), 'id__not_in' => array($domain->get_id()),
'fields' => 'ids', 'fields' => 'ids',
)); )
);
/* /*
* Trigger async action to update the old primary domains. * Trigger async action to update the old primary domains.
*/ */
do_action('wu_async_remove_old_primary_domains', array($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'); wu_enqueue_async_action('wu_async_process_domain_stage', array('domain_id' => $domain->get_id()), 'domain');
wp_send_json_success(array( wp_send_json_success(
'redirect_url' => wu_network_admin_url('wp-ultimo-edit-domain', array( array(
'redirect_url' => wu_network_admin_url(
'wp-ultimo-edit-domain',
array(
'id' => $domain->get_id(), 'id' => $domain->get_id(),
)) )
)); ),
)
} // end if; );
}
} // end handle_add_new_domain_modal; }
/** /**
* Returns an array with the labels for the edit page. * 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'), 'deleted_message' => __('Domains removed successfully.', 'wp-ultimo'),
'search_label' => __('Search Domains', 'wp-ultimo'), 'search_label' => __('Search Domains', 'wp-ultimo'),
); );
}
} // end get_labels;
/** /**
* Returns the title of the page. * Returns the title of the page.
@ -283,8 +295,7 @@ class Domain_List_Admin_Page extends List_Admin_Page {
public function get_title() { public function get_title() {
return __('Domains', 'wp-ultimo'); return __('Domains', 'wp-ultimo');
}
} // end get_title;
/** /**
* Returns the title of menu for this page. * 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() { public function get_menu_title() {
return __('Domains', 'wp-ultimo'); return __('Domains', 'wp-ultimo');
}
} // end get_menu_title;
/** /**
* Allows admins to rename the sub-menu (first item) for a top-level page. * 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() { public function get_submenu_title() {
return __('Domains', 'wp-ultimo'); return __('Domains', 'wp-ultimo');
}
} // end get_submenu_title;
/** /**
* Returns the action links for that page. * 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'), 'url' => wu_get_form_url('add_new_domain'),
), ),
); );
}
} // end action_links;
/** /**
* Loads the list table for this particular page. * Loads the list table for this particular page.
@ -338,7 +346,5 @@ class Domain_List_Admin_Page extends List_Admin_Page {
public function table() { public function table() {
return new \WP_Ultimo\List_Tables\Domain_List_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() { public function get_errors() {
if ($this->errors === null) { if ($this->errors === null) {
$this->errors = new \WP_Error();
$this->errors = new \WP_Error; }
} // end if;
return $this->errors; return $this->errors;
}
} // end get_errors;
/** /**
* Register additional hooks to page load such as the action links and the save processing. * 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(); $this->add_lock_notices();
if (wu_request('submit_button') === 'delete') { if (wu_request('submit_button') === 'delete') {
$this->process_delete(); $this->process_delete();
} elseif (wu_request('remove-lock')) { } elseif (wu_request('remove-lock')) {
$this->remove_lock(); $this->remove_lock();
} else { } else {
/* /*
* Process save, if necessary * Process save, if necessary
*/ */
$this->process_save(); $this->process_save();
}
} // end if; }
} // end page_loaded;
/** /**
* Add some other necessary hooks. * Add some other necessary hooks.
@ -120,8 +111,7 @@ abstract class Edit_Admin_Page extends Base_Admin_Page {
parent::hooks(); parent::hooks();
add_filter('removable_query_args', array($this, 'removable_query_args')); 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. * 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'; $removable_query_args[] = 'wu-new-model';
return $removable_query_args; return $removable_query_args;
}
} // end removable_query_args;
/** /**
* Displays lock notices, if necessary. * Displays lock notices, if necessary.
@ -157,18 +146,18 @@ abstract class Edit_Admin_Page extends Base_Admin_Page {
$actions = array( $actions = array(
'preview' => array( 'preview' => array(
'title' => __('Unlock', 'wp-ultimo'), 'title' => __('Unlock', 'wp-ultimo'),
'url' => add_query_arg(array( 'url' => add_query_arg(
array(
'remove-lock' => 1, 'remove-lock' => 1,
'unlock_wpultimo_nonce' => wp_create_nonce(sprintf('unlocking_%s', $this->object_id)), 'unlock_wpultimo_nonce' => wp_create_nonce(sprintf('unlocking_%s', $this->object_id)),
)), )
),
), ),
); );
WP_Ultimo()->notices->add($message, 'warning', 'network-admin', false, $actions); WP_Ultimo()->notices->add($message, 'warning', 'network-admin', false, $actions);
}
} // end if; }
} // end add_lock_notices;
/** /**
* Remove the lock from the object. * 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}"; $unlock_tag = "unlocking_{$this->object_id}";
if (isset($_REQUEST['remove-lock'])) { if (isset($_REQUEST['remove-lock'])) {
check_admin_referer($unlock_tag, 'unlock_wpultimo_nonce'); 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(); $this->get_object()->unlock();
wp_redirect(remove_query_arg(array( wp_redirect(
remove_query_arg(
array(
'remove-lock', 'remove-lock',
'unlock_wpultimo_nonce', 'unlock_wpultimo_nonce',
))); )
)
);
exit; exit;
}
} // end if; }
} // end remove_lock;
/** /**
* Handles saves, after verifying nonces and such. Should not be rewritten by child classes. * 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}"; $saving_tag = "saving_{$this->object_id}";
if (isset($_REQUEST[ $saving_tag ])) { if (isset($_REQUEST[ $saving_tag ])) {
check_admin_referer($saving_tag, '_wpultimo_nonce'); check_admin_referer($saving_tag, '_wpultimo_nonce');
/** /**
@ -234,14 +223,10 @@ abstract class Edit_Admin_Page extends Base_Admin_Page {
$status = $this->handle_save(); $status = $this->handle_save();
if ($status) { if ($status) {
exit; exit;
}
} // end if; }
}
} // end if;
} // end process_save;
/** /**
* Handles delete, after verifying nonces and such. Should not be rewritten by child classes. * 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}"; $deleting_tag = "deleting_{$this->object_id}";
if (isset($_REQUEST[ $deleting_tag ])) { if (isset($_REQUEST[ $deleting_tag ])) {
check_admin_referer($deleting_tag, 'delete_wpultimo_nonce'); 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 * Calls the deleting function
*/ */
$this->handle_delete(); $this->handle_delete();
}
} // end if; }
} // end process_delete;
/** /**
* Returns the labels to be used on the admin page. * 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); 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. * 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_style('wp-color-picker');
wp_enqueue_script('wu-selectizer'); wp_enqueue_script('wu-selectizer');
}
} // end register_scripts;
/** /**
* Registers widgets to the edit page. * Registers widgets to the edit page.
@ -339,18 +319,18 @@ abstract class Edit_Admin_Page extends Base_Admin_Page {
$screen = get_current_screen(); $screen = get_current_screen();
$this->add_info_widget('info', array( $this->add_info_widget(
'info',
array(
'title' => __('Timestamps', 'wp-ultimo'), 'title' => __('Timestamps', 'wp-ultimo'),
'position' => 'side-bottom', 'position' => 'side-bottom',
)); )
);
if ($this->edit) { if ($this->edit) {
$this->add_delete_widget('delete', array()); $this->add_delete_widget('delete', array());
}
} // end if; }
} // end register_widgets;
/** /**
* Adds a basic widget with info (and fields) to be shown. * 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'; $created_key = 'date_created';
if (method_exists($this->get_object(), 'get_date_registered')) { if (method_exists($this->get_object(), 'get_date_registered')) {
$created_key = 'date_registered'; $created_key = 'date_registered';
}
} // end if;
$created_value = call_user_func(array($this->get_object(), "get_$created_key")); $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); $show_modified = wu_get_isset($atts, 'modified', true);
if ($this->edit && $show_modified === true) { if ($this->edit && $show_modified === true) {
$atts['fields']['date_modified'] = array( $atts['fields']['date_modified'] = array(
'title' => __('Last Modified at', 'wp-ultimo'), 'title' => __('Last Modified at', 'wp-ultimo'),
'type' => 'text-display', 'type' => 'text-display',
@ -404,12 +381,10 @@ abstract class Edit_Admin_Page extends Base_Admin_Page {
'data-allow-time' => 'true', 'data-allow-time' => 'true',
), ),
); );
}
} // end if;
$this->add_fields_widget($id, $atts); $this->add_fields_widget($id, $atts);
}
} // end add_info_widget;
/** /**
* Adds a basic widget to display list tables. * 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()) { protected function add_list_table_widget($id, $atts = array()) {
$atts = wp_parse_args($atts, array( $atts = wp_parse_args(
$atts,
array(
'widget_id' => $id, 'widget_id' => $id,
'before' => '', 'before' => '',
'after' => '', 'after' => '',
@ -435,37 +412,43 @@ abstract class Edit_Admin_Page extends Base_Admin_Page {
'edit' => true, 'edit' => true,
'table' => false, 'table' => false,
'query_filter' => false, 'query_filter' => false,
)); )
);
$atts['table']->set_context('widget'); $atts['table']->set_context('widget');
$table_name = $atts['table']->get_table_id(); $table_name = $atts['table']->get_table_id();
if (is_callable($atts['query_filter'])) { if (is_callable($atts['query_filter'])) {
add_filter("wu_{$table_name}_get_items", $atts['query_filter']); add_filter("wu_{$table_name}_get_items", $atts['query_filter']);
}
} // end if; add_filter(
'wu_events_list_table_get_columns',
add_filter('wu_events_list_table_get_columns', function($columns) { function ($columns) {
unset($columns['object_type']); unset($columns['object_type']);
unset($columns['code']); unset($columns['code']);
return $columns; return $columns;
}
);
}); add_meta_box(
"wp-ultimo-list-table-{$id}",
add_meta_box("wp-ultimo-list-table-{$id}", $atts['title'], function() use ($atts) { $atts['title'],
function () use ($atts) {
wp_enqueue_script('wu-ajax-list-table'); wp_enqueue_script('wu-ajax-list-table');
wu_get_template('base/edit/widget-list-table', $atts); wu_get_template('base/edit/widget-list-table', $atts);
},
}, $atts['screen']->id, $atts['position'], 'default'); $atts['screen']->id,
$atts['position'],
} // end add_list_table_widget; 'default'
);
}
/** /**
* Adds field widgets to edit pages with the same Form/Field APIs used elsewhere. * 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()) { protected function add_fields_widget($id, $atts = array()) {
$atts = wp_parse_args($atts, array( $atts = wp_parse_args(
$atts,
array(
'widget_id' => $id, 'widget_id' => $id,
'before' => '', 'before' => '',
'after' => '', 'after' => '',
@ -490,12 +475,15 @@ abstract class Edit_Admin_Page extends Base_Admin_Page {
'html_attr' => array(), 'html_attr' => array(),
'classes' => '', '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', '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')) { if (wu_get_isset($atts['html_attr'], 'data-wu-app')) {
$atts['fields']['loading'] = array( $atts['fields']['loading'] = array(
'type' => 'note', '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')), '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, 'v-if' => 0,
), ),
); );
}
} // end if;
/** /**
* Instantiate the form for the order details. * Instantiate the form for the order details.
* *
* @since 2.0.0 * @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', 'views' => 'admin-pages/fields',
'classes' => 'wu-widget-list wu-striped wu-m-0 wu--mt-2 wu--mb-3 wu--mx-3 ' . $atts['classes'], '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'], 'field_wrapper_classes' => $atts['field_wrapper_classes'],
'html_attr' => $atts['html_attr'], 'html_attr' => $atts['html_attr'],
'before' => $atts['before'], 'before' => $atts['before'],
'after' => $atts['after'], 'after' => $atts['after'],
)); )
);
$form->render(); $form->render();
},
}, $atts['screen']->id, $atts['position'], 'default'); $atts['screen']->id,
$atts['position'],
} // end add_fields_widget; 'default'
);
}
/** /**
* Adds field widgets to edit pages with the same Form/Field APIs used elsewhere. * 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()) { protected function add_tabs_widget($id, $atts = array()) {
$atts = wp_parse_args($atts, array( $atts = wp_parse_args(
$atts,
array(
'widget_id' => $id, 'widget_id' => $id,
'before' => '', 'before' => '',
'after' => '', 'after' => '',
@ -547,7 +542,8 @@ abstract class Edit_Admin_Page extends Base_Admin_Page {
'screen' => get_current_screen(), 'screen' => get_current_screen(),
'sections' => array(), 'sections' => array(),
'html_attr' => array(), 'html_attr' => array(),
)); )
);
$current_section = wu_request($id, current(array_keys($atts['sections']))); $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, '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) { foreach ($atts['sections'] as $section_id => &$section) {
$section = wp_parse_args(
$section = wp_parse_args($section, array( $section,
array(
'form' => '', 'form' => '',
'before' => '', 'before' => '',
'after' => '', 'after' => '',
@ -571,7 +571,8 @@ abstract class Edit_Admin_Page extends Base_Admin_Page {
'html_attr' => array(), 'html_attr' => array(),
'state' => 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', '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 * Move state ont step up
@ -586,7 +587,8 @@ abstract class Edit_Admin_Page extends Base_Admin_Page {
/** /**
* Adds a header field * Adds a header field
*/ */
$section['fields'] = array_merge(array( $section['fields'] = array_merge(
array(
$section_id => array( $section_id => array(
'title' => $section['title'], 'title' => $section['title'],
'desc' => $section['desc'], 'desc' => $section['desc'],
@ -594,35 +596,45 @@ abstract class Edit_Admin_Page extends Base_Admin_Page {
'wrapper_html_attr' => array( 'wrapper_html_attr' => array(
'v-show' => 'display_all', 'v-show' => 'display_all',
), ),
) ),
), $section['fields']); ),
$section['fields']
);
/** /**
* Instantiate the form for the order details. * Instantiate the form for the order details.
* *
* @since 2.0.0 * @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', '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', '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'], 'field_wrapper_classes' => $section['field_wrapper_classes'],
'html_attr' => $section['html_attr'], 'html_attr' => $section['html_attr'],
'before' => $section['before'], 'before' => $section['before'],
'after' => $section['after'], 'after' => $section['after'],
)); )
);
}
} // end foreach; wu_get_template(
'base/edit/widget-tabs',
wu_get_template('base/edit/widget-tabs', array( array(
'sections' => $atts['sections'], 'sections' => $atts['sections'],
'html_attr' => $atts['html_attr'], 'html_attr' => $atts['html_attr'],
'before' => $atts['before'], 'before' => $atts['before'],
'after' => $atts['after'], 'after' => $atts['after'],
)); )
);
}, $atts['screen']->id, $atts['position'], 'default'); },
$atts['screen']->id,
} // end add_tabs_widget; $atts['position'],
'default'
);
}
/** /**
* Adds a generic widget to the admin page. * 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()) { protected function add_widget($id, $atts = array()) {
$atts = wp_parse_args($atts, array( $atts = wp_parse_args(
$atts,
array(
'widget_id' => $id, 'widget_id' => $id,
'before' => '', 'before' => '',
'after' => '', 'after' => '',
@ -643,11 +657,11 @@ abstract class Edit_Admin_Page extends Base_Admin_Page {
'screen' => get_current_screen(), 'screen' => get_current_screen(),
'position' => 'side', 'position' => 'side',
'display' => '__return_empty_string', 'display' => '__return_empty_string',
)); )
);
add_meta_box("wp-ultimo-{$id}-widget", $atts['title'], $atts['display'], $atts['screen']->id, $atts['position'], 'default'); 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. * 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'])) { if (isset($atts['html_attr']['data-wu-app'])) {
$atts['fields']['submit_save']['wrapper_html_attr']['v-cloak'] = 1; $atts['fields']['submit_save']['wrapper_html_attr']['v-cloak'] = 1;
}
} // end if;
if ($this->get_object() && $this->edit && $this->get_object()->is_locked()) { if ($this->get_object() && $this->edit && $this->get_object()->is_locked()) {
$atts['fields']['submit_save']['title'] = __('Locked', 'wp-ultimo'); $atts['fields']['submit_save']['title'] = __('Locked', 'wp-ultimo');
$atts['fields']['submit_save']['value'] = 'none'; $atts['fields']['submit_save']['value'] = 'none';
$atts['fields']['submit_save']['html_attr']['disabled'] = 'disabled'; $atts['fields']['submit_save']['html_attr']['disabled'] = 'disabled';
}
} // end if;
$this->add_fields_widget('save', $atts); $this->add_fields_widget('save', $atts);
}
} // end add_save_widget;
/** /**
* Adds a basic delete widget. * Adds a basic delete widget.
@ -739,7 +748,7 @@ abstract class Edit_Admin_Page extends Base_Admin_Page {
'delete_modal', 'delete_modal',
array( array(
'id' => $this->get_object()->get_id(), '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); $atts['fields']['delete'] = array_merge($default_delete_field_settings, $custom_delete_field_settings);
$this->add_fields_widget('delete', $atts); $this->add_fields_widget('delete', $atts);
}
} // end add_delete_widget;
/** /**
* Displays the contents of the edit page. * 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 =) * 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(), 'screen' => get_current_screen(),
'page' => $this, 'page' => $this,
'labels' => $this->get_labels(), 'labels' => $this->get_labels(),
'object' => $this->get_object(), 'object' => $this->get_object(),
)); )
);
} // end output; }
/** /**
* Wether or not this pages should have a title field. * 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() { public function has_title() {
return false; return false;
}
} // end has_title;
/** /**
* Wether or not this pages should have an editor field. * 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() { public function has_editor() {
return false; return false;
}
} // end has_editor;
/** /**
* Should return the object being edited, or false. * 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 * @since 2.0.0
* @return \WP_Ultimo\Models\Base_Model * @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. * 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); $object->attributes($_POST);
if (method_exists($object, 'handle_limitations')) { if (method_exists($object, 'handle_limitations')) {
$object->handle_limitations($_POST); // @phpstan-ignore-line $object->handle_limitations($_POST); // @phpstan-ignore-line
} // end if; }
$save = $object->save(); $save = $object->save();
if (is_wp_error($save)) { if (is_wp_error($save)) {
$errors = implode('<br>', $save->get_error_messages()); $errors = implode('<br>', $save->get_error_messages());
WP_Ultimo()->notices->add($errors, 'error', 'network-admin'); WP_Ultimo()->notices->add($errors, 'error', 'network-admin');
return false; return false;
} else { } else {
$array_params = array( $array_params = array(
'updated' => 1, 'updated' => 1,
); );
if ($this->edit === false) { if ($this->edit === false) {
$array_params['id'] = $object->get_id(); $array_params['id'] = $object->get_id();
$array_params['wu-new-model'] = true; $array_params['wu-new-model'] = true;
}
} // end if;
$url = add_query_arg($array_params); $url = add_query_arg($array_params);
wp_redirect($url); wp_redirect($url);
return true; return true;
}
} // end if; }
} // end handle_save;
/** /**
* Should implement the processes necessary to delete the object. * 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(); $saved = $object->delete();
if (is_wp_error($saved)) { if (is_wp_error($saved)) {
$errors = implode('<br>', $saved->get_error_messages()); $errors = implode('<br>', $saved->get_error_messages());
WP_Ultimo()->notices->add($errors, 'error', 'network-admin'); WP_Ultimo()->notices->add($errors, 'error', 'network-admin');
return; return;
} // end if; }
$url = str_replace('_', '-', (string) $object->model); $url = str_replace('_', '-', (string) $object->model);
$url = wu_network_admin_url("wp-ultimo-{$url}s"); $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); wp_redirect($url);
exit; exit;
}
} // end handle_delete; }
} // end class Edit_Admin_Page;

View File

@ -12,8 +12,8 @@ namespace WP_Ultimo\Admin_Pages;
// Exit if accessed directly // Exit if accessed directly
defined('ABSPATH') || exit; defined('ABSPATH') || exit;
use \WP_Ultimo\Models\Email; use WP_Ultimo\Models\Email;
use \WP_Ultimo\Managers\Email_Manager; use WP_Ultimo\Managers\Email_Manager;
/** /**
* WP Multisite WaaS Email Edit/Add New Admin Page. * WP Multisite WaaS Email Edit/Add New Admin Page.
@ -96,8 +96,7 @@ class Email_Edit_Admin_Page extends Edit_Admin_Page {
parent::init(); parent::init();
add_action('wu_page_edit_redirect_handlers', array($this, 'handle_page_redirect'), 10); add_action('wu_page_edit_redirect_handlers', array($this, 'handle_page_redirect'), 10);
}
} // end init;
/** /**
* Registers the necessary scripts. * Registers the necessary scripts.
@ -110,8 +109,7 @@ class Email_Edit_Admin_Page extends Edit_Admin_Page {
parent::register_scripts(); parent::register_scripts();
wp_enqueue_script('wu-email-edit-page', wu_get_asset('email-edit-page.js', 'js'), array('jquery', 'clipboard')); 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. * 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. // 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() }}'); $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(' $desc = sprintf(
<span v-show="schedule && schedule_type == \'days\'">%s</span> '<span v-show="schedule && schedule_type == \'days\'">%s</span>
<span v-show="schedule && schedule_type == \'hours\'">%s</span> <span v-show="schedule && schedule_type == \'hours\'">%s</span>',
', $days_text, $hour_text); $days_text,
$hour_text
);
$this->add_save_widget('save', array( $this->add_save_widget(
'save',
array(
'html_attr' => array( 'html_attr' => array(
'data-wu-app' => 'email_edit_save', '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() : '', 'slug' => $this->edit ? $object->get_slug() : '',
'target' => $this->edit ? $object->get_target() : 'admin', 'target' => $this->edit ? $object->get_target() : 'admin',
'schedule' => $this->edit ? $object->has_schedule() : false, 'schedule' => $this->edit ? $object->has_schedule() : false,
'schedule_type' => $this->edit ? $object->get_schedule_type() : 'days', 'schedule_type' => $this->edit ? $object->get_schedule_type() : 'days',
'days' => $this->edit ? $object->get_send_days() : 1, 'days' => $this->edit ? $object->get_send_days() : 1,
'hours' => $this->edit ? $object->get_send_hours() : '12:00', 'hours' => $this->edit ? $object->get_send_hours() : '12:00',
)), )
),
), ),
'fields' => array( 'fields' => array(
'slug' => array( 'slug' => array(
@ -168,7 +172,7 @@ class Email_Edit_Admin_Page extends Edit_Admin_Page {
'options' => 'wu_get_event_types_as_options', 'options' => 'wu_get_event_types_as_options',
'value' => $this->edit ? $object->get_event() : 0, 'value' => $this->edit ? $object->get_event() : 0,
'html_attr' => array( 'html_attr' => array(
'name' => '' 'name' => '',
), ),
), ),
'target' => array( '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()); 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'), 'title' => __('Active', 'wp-ultimo'),
'fields' => array( 'fields' => array(
'active' => array( 'active' => array(
@ -278,9 +285,12 @@ class Email_Edit_Admin_Page extends Edit_Admin_Page {
'value' => $this->get_object()->is_active(), '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'), 'title' => __('Advanced Options', 'wp-ultimo'),
'position' => 'normal', 'position' => 'normal',
'sections' => array( '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. * 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) { 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'), 'title' => __('Event Payload', 'wp-ultimo'),
'loading_text' => __('Loading Payload', 'wp-ultimo'), 'loading_text' => __('Loading Payload', 'wp-ultimo'),
)); )
);
} // end output_default_widget_placeholders; }
/** /**
* Returns the title of the page. * Returns the title of the page.
@ -376,8 +388,7 @@ class Email_Edit_Admin_Page extends Edit_Admin_Page {
public function get_title() { public function get_title() {
return $this->edit ? __('Edit Email', 'wp-ultimo') : __('Add new Email', 'wp-ultimo'); return $this->edit ? __('Edit Email', 'wp-ultimo') : __('Add new Email', 'wp-ultimo');
}
} // end get_title;
/** /**
* Returns the title of menu for this page. * 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() { public function get_menu_title() {
return __('Edit Email', 'wp-ultimo'); return __('Edit Email', 'wp-ultimo');
}
} // end get_menu_title;
/** /**
* Returns the action links for that page. * Returns the action links for that page.
@ -402,7 +412,7 @@ class Email_Edit_Admin_Page extends Edit_Admin_Page {
$url_atts = array( $url_atts = array(
'id' => $this->get_object()->get_id(), 'id' => $this->get_object()->get_id(),
'model' => 'email', 'model' => 'email',
'page' => 'edit' 'page' => 'edit',
); );
$send_test_link = wu_get_form_url('send_new_test', $url_atts); $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, 'url' => $send_test_link,
'label' => __('Send Test Email', 'wp-ultimo'), 'label' => __('Send Test Email', 'wp-ultimo'),
'icon' => 'wu-mail', 'icon' => 'wu-mail',
'classes' => 'wubox' 'classes' => 'wubox',
), ),
); );
}
} // end action_links;
/** /**
* Returns the labels to be used on the admin page. * 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_button_label' => __('Delete Email', 'wp-ultimo'),
'delete_description' => __('Be careful. This action is irreversible.', 'wp-ultimo'), 'delete_description' => __('Be careful. This action is irreversible.', 'wp-ultimo'),
); );
}
} // end get_labels;
/** /**
* Filters the list table to return only relevant events. * 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); return array_merge($args, $extra_args);
}
} // end query_filter;
/** /**
* Handles the toggles. * Handles the toggles.
@ -479,8 +486,7 @@ class Email_Edit_Admin_Page extends Edit_Admin_Page {
$_POST['custom_sender'] = wu_request('custom_sender'); $_POST['custom_sender'] = wu_request('custom_sender');
parent::handle_save(); parent::handle_save();
}
} // end handle_save;
/** /**
* Handles the redirect notice from sent new test modal. * 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) { public function handle_page_redirect($page) {
if ($page->get_id() === 'wp-ultimo-edit-email') { if ($page->get_id() === 'wp-ultimo-edit-email') {
if (wu_request('test_notice')) { if (wu_request('test_notice')) {
$test_notice = wu_request('test_notice'); $test_notice = wu_request('test_notice');
?> ?>
@ -506,11 +510,9 @@ class Email_Edit_Admin_Page extends Edit_Admin_Page {
<?php <?php
} // end if; }
}
} // end if; }
} // end handle_page_redirect;
/** /**
* Returns the object being edit at the moment. * 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() { public function get_object() {
if (isset($_GET['id'])) { 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']); $item = $query->get_item_by('id', $_GET['id']);
if (! $item) { if (! $item) {
wp_redirect(wu_network_admin_url('wp-ultimo-emails')); wp_redirect(wu_network_admin_url('wp-ultimo-emails'));
exit; exit;
}
} // end if;
return $item; return $item;
}
} // end if; return new Email();
}
return new Email;
} // end get_object;
/** /**
* Emails have titles. * Emails have titles.
* *
@ -549,8 +546,7 @@ class Email_Edit_Admin_Page extends Edit_Admin_Page {
public function has_title(): bool { public function has_title(): bool {
return true; return true;
}
} // end has_title;
/** /**
* Wether or not this pages should have an editor field. * 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 { public function has_editor(): bool {
return true; return true;
}
} // end has_editor;
/** /**
* Filters the list table to return only relevant events. * 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); 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(); parent::init();
add_action('wu_page_list_redirect_handlers', array($this, 'handle_page_redirect'), 10); 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. * 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 * @since 1.8.2
* @return void * @return void
*/ */
public function register_widgets() {} // end register_widgets; public function register_widgets() {}
/** /**
* Returns the title of the page. * Returns the title of the page.
@ -104,8 +103,7 @@ class Email_List_Admin_Page extends List_Admin_Page {
public function get_title() { public function get_title() {
return __('System Emails', 'wp-ultimo'); return __('System Emails', 'wp-ultimo');
}
} // end get_title;
/** /**
* Returns the title of menu for this page. * 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() { public function get_menu_title() {
return __('System Emails', 'wp-ultimo'); return __('System Emails', 'wp-ultimo');
}
} // end get_menu_title;
/** /**
* Allows admins to rename the sub-menu (first item) for a top-level page. * 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() { public function get_submenu_title() {
return __('System Emails', 'wp-ultimo'); return __('System Emails', 'wp-ultimo');
}
} // end get_submenu_title;
/** /**
* Register ajax form that we use for system emails. * 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 * 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'), 'render' => array($this, 'render_send_new_test_modal'),
'handler' => array($this, 'handle_send_new_test_modal'), 'handler' => array($this, 'handle_send_new_test_modal'),
'capability' => 'wu_add_broadcast', 'capability' => 'wu_add_broadcast',
)); )
);
/* /*
* Reset or Import modal. * Reset or Import modal.
*/ */
wu_register_form('reset_import', array( wu_register_form(
'reset_import',
array(
'render' => array($this, 'render_reset_import_modal'), 'render' => array($this, 'render_reset_import_modal'),
'handler' => array($this, 'handle_reset_import_modal'), 'handler' => array($this, 'handle_reset_import_modal'),
'capability' => 'wu_add_broadcasts', 'capability' => 'wu_add_broadcasts',
)); )
);
/* /*
* Reset Confirmation modal. * Reset Confirmation modal.
*/ */
wu_register_form('reset_confirmation', array( wu_register_form(
'reset_confirmation',
array(
'render' => array($this, 'render_reset_confirmation_modal'), 'render' => array($this, 'render_reset_confirmation_modal'),
'handler' => array($this, 'handle_reset_confirmation_modal'), 'handler' => array($this, 'handle_reset_confirmation_modal'),
'capability' => 'wu_add_broadcasts', 'capability' => 'wu_add_broadcasts',
)); )
);
} // end register_forms; }
/** /**
* Renders the modal to send tests with system emails. * 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'), 'value' => get_network_option(null, 'admin_email'),
'html_attr' => array( 'html_attr' => array(
'required' => 'required', 'required' => 'required',
) ),
), ),
'email_id' => array( 'email_id' => array(
'type' => 'hidden', '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', 'views' => 'admin-pages/fields',
'classes' => 'wu-modal-form wu-widget-list wu-striped wu-m-0 wu-mt-0', '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', '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( 'html_attr' => array(
'data-wu-app' => 'send_new_test', 'data-wu-app' => 'send_new_test',
), ),
)); )
);
$form->render(); $form->render();
}
} // end render_send_new_test_modal;
/** /**
* Handles the modal to send tests with system emails. * 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'); $send_to = wu_request('send_to');
if ( ! $email_id || ! $send_to) { if ( ! $email_id || ! $send_to) {
$error = new \WP_Error('error', __('Something wrong happened.', 'wp-ultimo')); $error = new \WP_Error('error', __('Something wrong happened.', 'wp-ultimo'));
return wp_send_json_error($error); return wp_send_json_error($error);
}
} // end if;
$from = array( $from = array(
'name' => wu_get_setting('from_name'), 'name' => wu_get_setting('from_name'),
@ -245,7 +250,7 @@ class Email_List_Admin_Page extends List_Admin_Page {
array( array(
'name' => wu_get_setting('from_name'), 'name' => wu_get_setting('from_name'),
'email' => $send_to, 'email' => $send_to,
) ),
); );
$email = wu_get_email($email_id); $email = wu_get_email($email_id);
@ -257,10 +262,8 @@ class Email_List_Admin_Page extends List_Admin_Page {
$payload = array(); $payload = array();
if ($event_type) { if ($event_type) {
$payload = wu_maybe_lazy_load_payload($event_type['payload']); $payload = wu_maybe_lazy_load_payload($event_type['payload']);
}
} // end if;
$args = array( $args = array(
'style' => $email->get_style(), '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); $send_mail = wu_send_mail($from, $to, $args);
if ( ! $send_mail) { if ( ! $send_mail) {
$error = new \WP_Error('error', __('Something wrong happened with your test.', 'wp-ultimo')); $error = new \WP_Error('error', __('Something wrong happened with your test.', 'wp-ultimo'));
return wp_send_json_error($error); return wp_send_json_error($error);
}
} // end if;
$page = wu_request('page', 'list'); $page = wu_request('page', 'list');
if ($page === 'edit') { if ($page === 'edit') {
wp_send_json_success(
wp_send_json_success(array( array(
'redirect_url' => wu_network_admin_url('wp-ultimo-edit-email', array( 'redirect_url' => wu_network_admin_url(
'wp-ultimo-edit-email',
array(
'id' => $email_id, 'id' => $email_id,
'test_notice' => __('Test sent successfully', 'wp-ultimo') 'test_notice' => __('Test sent successfully', 'wp-ultimo'),
)) )
)); ),
)
);
die(); die();
}
} // end if; wp_send_json_success(
array(
wp_send_json_success(array( 'redirect_url' => wu_network_admin_url(
'redirect_url' => wu_network_admin_url('wp-ultimo-emails', array( 'wp-ultimo-emails',
array(
'notice' => __('Test sent successfully', 'wp-ultimo'), 'notice' => __('Test sent successfully', 'wp-ultimo'),
)) )
)); ),
)
} // end handle_send_new_test_modal; );
}
/** /**
* Renders the modal to reset or import system emails. * 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( 'html_attr' => array(
'v-model' => 'reset_emails', 'v-model' => 'reset_emails',
), ),
) ),
); );
$fields['reset_note'] = array( $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) { foreach ($created_emails as $system_email_key => $system_email_value) {
$system_email_slug = $system_email_value->get_slug(); $system_email_slug = $system_email_value->get_slug();
if (isset($default_system_emails[ $system_email_slug ])) { if (isset($default_system_emails[ $system_email_slug ])) {
$field_name = 'reset_' . $system_email_value->get_slug(); $field_name = 'reset_' . $system_email_value->get_slug();
$system_email_target = $system_email_value->get_target(); $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'])) { if (isset($fields['reset_note'])) {
unset($fields['reset_note']); unset($fields['reset_note']);
}
} // end if; }
}
} // end if;
} // end foreach;
$fields['import_emails'] = array( $fields['import_emails'] = array(
'type' => 'toggle', '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) { foreach ($default_system_emails as $default_email_key => $default_email_value) {
$maybe_is_created = wu_get_email_by('slug', $default_email_key); $maybe_is_created = wu_get_email_by('slug', $default_email_key);
if ( ! $maybe_is_created) { if ( ! $maybe_is_created) {
$field_name = 'import_' . $default_email_key; $field_name = 'import_' . $default_email_key;
$field_title = '<div><strong class="wu-inline-block wu-pr-1">' . $default_email_value['title'] . '</strong> </div>'; $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'])) { if (isset($fields['import_note'])) {
unset($fields['import_note']); unset($fields['import_note']);
}
} // end if; }
}
} // end if;
} // end foreach;
$fields['submit_button'] = array( $fields['submit_button'] = array(
'type' => 'submit', 'type' => 'submit',
@ -439,22 +435,27 @@ class Email_List_Admin_Page extends List_Admin_Page {
'wrapper_classes' => 'wu-items-end wu-text-right', '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', 'views' => 'admin-pages/fields',
'classes' => 'wu-modal-form wu-widget-list wu-striped wu-m-0 wu-mt-0', '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', '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( 'html_attr' => array(
'data-wu-app' => 'reset_import', 'data-wu-app' => 'reset_import',
'data-state' => json_encode(array( 'data-state' => json_encode(
array(
'reset_emails' => false, 'reset_emails' => false,
'import_emails' => false 'import_emails' => false,
)), )
), ),
)); ),
)
);
$form->render(); $form->render();
}
} // end render_reset_import_modal;
/** /**
* Handles the modal to reset or import system emails. * 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(); $created_emails = wu_get_all_system_emails();
if ($reset) { if ($reset) {
foreach ($created_emails as $created_email) { foreach ($created_emails as $created_email) {
$slug = $created_email->get_slug(); $slug = $created_email->get_slug();
$maybe_reset = wu_request('reset_' . $slug, ''); $maybe_reset = wu_request('reset_' . $slug, '');
if ($maybe_reset) { if ($maybe_reset) {
$created_email->delete(); $created_email->delete();
wu_create_default_system_email($slug); wu_create_default_system_email($slug);
}
} // end if; }
}
} // end foreach;
} // end if;
if ($import) { if ($import) {
foreach ($default_system_emails as $default_system_emails_key => $default_system_emails_value) { foreach ($default_system_emails as $default_system_emails_key => $default_system_emails_value) {
$slug = $default_system_emails_value['slug']; $slug = $default_system_emails_value['slug'];
$maybe_import = wu_request('import_' . $slug, ''); $maybe_import = wu_request('import_' . $slug, '');
if ($maybe_import) { if ($maybe_import) {
wu_create_default_system_email($slug); wu_create_default_system_email($slug);
}
}
}
} // end if; wp_send_json_success(
array(
} // end foreach; 'redirect_url' => wu_network_admin_url('wp-ultimo-emails'),
)
} // end if; );
}
wp_send_json_success(array(
'redirect_url' => wu_network_admin_url('wp-ultimo-emails')
));
} // end handle_reset_import_modal;
/** /**
* Handles the redirect notice from sent new test modal. * 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) { public function handle_page_redirect($page) {
if ($page->get_id() === 'wp-ultimo-emails') { if ($page->get_id() === 'wp-ultimo-emails') {
if (wu_request('notice')) { if (wu_request('notice')) {
$notice = wu_request('notice'); $notice = wu_request('notice');
?> ?>
@ -541,11 +529,9 @@ class Email_List_Admin_Page extends List_Admin_Page {
<?php <?php
} // end if; }
}
} // end if; }
} // end handle_page_redirect;
/** /**
* Renders the reset confirmation modal. * Renders the reset confirmation modal.
@ -563,7 +549,7 @@ class Email_List_Admin_Page extends List_Admin_Page {
'default' => 0, 'default' => 0,
'html_attr' => array( 'html_attr' => array(
'required' => 'required', 'required' => 'required',
) ),
), ),
'email_id' => array( 'email_id' => array(
'type' => 'hidden', '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', 'views' => 'admin-pages/fields',
'classes' => 'wu-modal-form wu-widget-list wu-striped wu-m-0 wu-mt-0', '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', '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( 'html_attr' => array(
'data-wu-app' => 'reset_confirmation', 'data-wu-app' => 'reset_confirmation',
), ),
)); )
);
$form->render(); $form->render();
}
} // end render_reset_confirmation_modal;
/** /**
* Handles the 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'); $email_id = wu_request('email_id');
if ( ! $single_reset || ! $email_id) { if ( ! $single_reset || ! $email_id) {
$error = new \WP_Error('error', __('Something wrong happened.', 'wp-ultimo')); $error = new \WP_Error('error', __('Something wrong happened.', 'wp-ultimo'));
return wp_send_json_error($error); return wp_send_json_error($error);
}
} // end if;
$email = wu_get_email($email_id); $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(); $default_system_emails = wu_get_default_system_emails();
if (isset($default_system_emails[ $slug ])) { if (isset($default_system_emails[ $slug ])) {
$email->delete(); $email->delete();
wu_create_default_system_email($slug); 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); $new_email = wu_get_email_by('slug', $slug);
if ( ! $new_email) { if ( ! $new_email) {
$error = new \WP_Error('error', __('Something wrong happened.', 'wp-ultimo')); $error = new \WP_Error('error', __('Something wrong happened.', 'wp-ultimo'));
return wp_send_json_error($error); return wp_send_json_error($error);
}
} // end if; wp_send_json_success(
array(
wp_send_json_success(array( 'redirect_url' => wu_network_admin_url(
'redirect_url' => wu_network_admin_url('wp-ultimo-edit-email', array( 'wp-ultimo-edit-email',
array(
'id' => $new_email->get_id(), 'id' => $new_email->get_id(),
)) )
)); ),
)
} // end if; );
}
} // end handle_reset_confirmation_modal; }
/** /**
* Returns the action links for that page. * Returns the action links for that page.
@ -672,8 +659,7 @@ class Email_List_Admin_Page extends List_Admin_Page {
'icon' => 'wu-cycle', 'icon' => 'wu-cycle',
), ),
); );
}
} // end action_links;
/** /**
* Loads the list table for this particular page. * Loads the list table for this particular page.
@ -684,7 +670,5 @@ class Email_List_Admin_Page extends List_Admin_Page {
public function table() { public function table() {
return new \WP_Ultimo\List_Tables\Email_List_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(); parent::init();
add_action('wp_ajax_wu-email-template-preview', array($this, 'email_template_preview')); add_action('wp_ajax_wu-email-template-preview', array($this, 'email_template_preview'));
}
} // end init;
/** /**
* Return the page object * Return the page object
@ -94,8 +93,7 @@ class Email_Template_Customize_Admin_Page extends Customizer_Admin_Page {
public function get_object() { public function get_object() {
return $this; return $this;
}
} // end get_object;
/** /**
* Renders the preview of a given form being customized. * 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; $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. 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.' 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"> $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'); $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_name' => get_network_option(null, 'site_name'),
'site_url' => get_site_url(), 'site_url' => get_site_url(),
'logo_url' => wu_get_network_logo(), '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_color' => wu_request('footer_color', $object->get_setting('footer_color', '#000000')),
'footer_align' => wu_request('footer_align', $object->get_setting('footer_align', 'center')), '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)), 'display_company_address' => wu_string_to_bool(wu_request('display_company_address', $first_request ? $object->get_setting('display_company_address', true) : false)),
),
) )
)); );
die; die;
}
} // end email_template_preview;
/** /**
* Returns the preview URL. This is then added to the iframe. * 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'); $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', 'action' => 'wu-email-template-preview',
'customizer' => 1, 'customizer' => 1,
), $url); ),
$url
} // end get_preview_url; );
}
/** /**
* Allow child classes to register widgets, if they need them. * 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() { public function register_widgets() {
$this->add_save_widget('save', array( $this->add_save_widget(
'save',
array(
'html_attr' => array( 'html_attr' => array(
'data-wu-app' => 'save', 'data-wu-app' => 'save',
'data-state' => wu_convert_to_state(), 'data-state' => wu_convert_to_state(),
@ -216,8 +220,9 @@ class Email_Template_Customize_Admin_Page extends Customizer_Admin_Page {
'type' => 'note', 'type' => 'note',
'desc' => __('System emails and broadcasts will be sent using this template.', 'wp-ultimo'), 'desc' => __('System emails and broadcasts will be sent using this template.', 'wp-ultimo'),
), ),
),
) )
)); );
$settings = $this->get_attributes(); $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', 'tab' => 'header',
'refresh' => true, 'refresh' => true,
)); )
);
$this->add_fields_widget('customizer', array( $this->add_fields_widget(
'customizer',
array(
'title' => __('Customizer', 'wp-ultimo'), 'title' => __('Customizer', 'wp-ultimo'),
'position' => 'side', 'position' => 'side',
'fields' => $fields, 'fields' => $fields,
@ -488,9 +498,9 @@ class Email_Template_Customize_Admin_Page extends Customizer_Admin_Page {
'data-wu-customizer-panel' => true, 'data-wu-customizer-panel' => true,
'data-state' => json_encode($state), 'data-state' => json_encode($state),
), ),
)); )
);
} // end register_widgets; }
/** /**
* Returns the title of the page. * Returns the title of the page.
@ -501,8 +511,7 @@ class Email_Template_Customize_Admin_Page extends Customizer_Admin_Page {
public function get_title() { public function get_title() {
return __('Customize Email Template:', 'wp-ultimo'); return __('Customize Email Template:', 'wp-ultimo');
}
} // end get_title;
/** /**
* Returns the title of menu for this page. * 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() { public function get_menu_title() {
return __('Customize Email Template', 'wp-ultimo'); return __('Customize Email Template', 'wp-ultimo');
}
} // end get_menu_title;
/** /**
* Returns the action links for that page. * 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() { public function action_links() {
return array(); return array();
}
} // end action_links;
/** /**
* Returns the labels to be used on the admin page. * 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_button_label' => __('Delete Email Template', 'wp-ultimo'),
'delete_description' => __('Be careful. This action is irreversible.', '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. * 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); wp_redirect($url);
exit; exit;
}
} // end handle_save;
/** /**
* Get the value of attributes. * 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()); $attributes = wp_parse_args($saved_atts, $this->get_default_settings());
return $attributes; return $attributes;
}
} // end get_attributes;
/** /**
* Gets the default email template settings. * Gets the default email template settings.
@ -618,8 +622,7 @@ class Email_Template_Customize_Admin_Page extends Customizer_Admin_Page {
'footer_color' => '#000000', 'footer_color' => '#000000',
'footer_align' => 'center', 'footer_align' => 'center',
); );
}
} // end get_default_settings;
/** /**
* Returns the list of saved settings to customize the email template. * 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() { public static function get_settings() {
return wu_get_option('email_template', array()); return wu_get_option('email_template', array());
}
} // end get_settings;
/** /**
* Returns a specitic email template setting. * 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) { public function get_setting($setting, $default = false) {
if ($setting) { if ($setting) {
$return = wu_get_option('email_template', array()); $return = wu_get_option('email_template', array());
if ($return && isset($return[ $setting ])) { if ($return && isset($return[ $setting ])) {
$return = $return[ $setting ]; $return = $return[ $setting ];
} else { } else {
$return = $default; $return = $default;
}
} // end if;
return $return; return $return;
}
} // end if; }
} // end get_setting;
/** /**
* Save settings. * Save settings.
@ -678,17 +673,11 @@ class Email_Template_Customize_Admin_Page extends Customizer_Admin_Page {
$allowed_keys = $this->get_attributes(); $allowed_keys = $this->get_attributes();
foreach ($settings_to_save as $setting_to_save => $value) { foreach ($settings_to_save as $setting_to_save => $value) {
if ( ! array_key_exists($setting_to_save, $allowed_keys)) { if ( ! array_key_exists($setting_to_save, $allowed_keys)) {
unset($settings_to_save[ $setting_to_save ]); unset($settings_to_save[ $setting_to_save ]);
}
} // end if; }
} // end foreach;
return wu_save_option('email_template', $settings_to_save); 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; namespace WP_Ultimo\Admin_Pages;
use \WP_Ultimo\Models\Event; use WP_Ultimo\Models\Event;
// Exit if accessed directly // Exit if accessed directly
defined('ABSPATH') || exit; defined('ABSPATH') || exit;
@ -65,8 +65,7 @@ class Event_List_Admin_Page extends List_Admin_Page {
public function init() { public function init() {
add_action('init', array($this, 'set_badge_count')); add_action('init', array($this, 'set_badge_count'));
}
} // end init;
/** /**
* Adds hooks when the page loads. * Adds hooks when the page loads.
@ -79,8 +78,7 @@ class Event_List_Admin_Page extends List_Admin_Page {
parent::page_loaded(); parent::page_loaded();
add_action('in_admin_header', array($this, 'count_seen_events')); 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. * 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"); $cache = get_site_transient("wu_{$user_id}_unseen_events_count");
if ($cache) { if ($cache) {
$this->badge_count = $cache; $this->badge_count = $cache;
return; return;
}
} // end if;
$table_name = "{$wpdb->base_prefix}wu_events"; $table_name = "{$wpdb->base_prefix}wu_events";
@ -115,8 +111,7 @@ class Event_List_Admin_Page extends List_Admin_Page {
$this->badge_count = $unseen; $this->badge_count = $unseen;
set_site_transient("wu_{$user_id}_unseen_events_count", $unseen, 5 * MINUTE_IN_SECONDS); 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. * 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"); delete_site_transient("wu_{$user_id}_unseen_events_count");
$last_event = wu_get_events(array( $last_event = wu_get_events(
array(
'orderby' => 'id', 'orderby' => 'id',
'fields' => 'ids', 'fields' => 'ids',
'order' => 'DESC', 'order' => 'DESC',
'number' => 1, 'number' => 1,
)); )
);
if ( ! empty($last_event)) { if ( ! empty($last_event)) {
$last_event_id = current($last_event); $last_event_id = current($last_event);
update_user_meta($user_id, 'wu_seen_events', $last_event_id); update_user_meta($user_id, 'wu_seen_events', $last_event_id);
}
} // end if;
$this->badge_count = ''; $this->badge_count = '';
}
} // end count_seen_events;
/** /**
* Allow child classes to register widgets, if they need them. * 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 * @since 1.8.2
* @return void * @return void
*/ */
public function register_widgets() {} // end register_widgets; public function register_widgets() {}
/** /**
* Returns an array with the labels for the edit page. * 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'), 'deleted_message' => __('Event removed successfully.', 'wp-ultimo'),
'search_label' => __('Search Event', 'wp-ultimo'), 'search_label' => __('Search Event', 'wp-ultimo'),
); );
}
} // end get_labels;
/** /**
* Returns the title of the page. * Returns the title of the page.
@ -181,8 +174,7 @@ class Event_List_Admin_Page extends List_Admin_Page {
public function get_title() { public function get_title() {
return __('Events', 'wp-ultimo'); return __('Events', 'wp-ultimo');
}
} // end get_title;
/** /**
* Returns the title of menu for this page. * 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() { public function get_menu_title() {
return __('Events', 'wp-ultimo'); return __('Events', 'wp-ultimo');
}
} // end get_menu_title;
/** /**
* Allows admins to rename the sub-menu (first item) for a top-level page. * 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() { public function get_submenu_title() {
return __('Events', 'wp-ultimo'); return __('Events', 'wp-ultimo');
}
} // end get_submenu_title;
/** /**
* Returns the action links for that page. * 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', 'icon' => 'dashicons dashicons-editor-ol',
), ),
); );
}
} // end action_links;
/** /**
* Loads the list table for this particular page. * Loads the list table for this particular page.
@ -235,7 +224,5 @@ class Event_List_Admin_Page extends List_Admin_Page {
public function table() { public function table() {
return new \WP_Ultimo\List_Tables\Event_List_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 // Exit if accessed directly
defined('ABSPATH') || exit; defined('ABSPATH') || exit;
use \WP_Ultimo\Models\Event; use WP_Ultimo\Models\Event;
/** /**
* WP Multisite WaaS Event View Admin Page. * 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('clipboard');
wp_enqueue_script('wu-vue'); wp_enqueue_script('wu-vue');
}
} // end register_scripts;
/** /**
* Register ajax forms that we use for membership. * 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 * Delete Event - Confirmation modal
*/ */
add_filter('wu_data_json_success_delete_event_modal', fn($data_json) => array( add_filter(
'redirect_url' => wu_network_admin_url('wp-ultimo-events', array('deleted' => 1)) '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; )
);
}
/** /**
* Allow child classes to register widgets, if they need them. * 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'); 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'), 'title' => __('Timestamps', 'wp-ultimo'),
'position' => 'side', 'position' => 'side',
'modified' => false, 'modified' => false,
)); )
);
} // end register_widgets; }
/** /**
* Outputs the markup for the default Save widget. * 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() { public function output_default_widget_message() {
wu_get_template('events/widget-message', array( wu_get_template(
'events/widget-message',
array(
'screen' => get_current_screen(), 'screen' => get_current_screen(),
'page' => $this, 'page' => $this,
'labels' => $this->get_labels(), 'labels' => $this->get_labels(),
'object' => $this->get_object(), 'object' => $this->get_object(),
)); )
);
} // end output_default_widget_message; }
/** /**
* Outputs the markup for the payload widget. * Outputs the markup for the payload widget.
@ -168,13 +173,15 @@ class Event_View_Admin_Page extends Edit_Admin_Page {
$object = $this->get_object(); $object = $this->get_object();
wu_get_template('events/widget-payload', array( wu_get_template(
'events/widget-payload',
array(
'title' => __('Event Payload', 'wp-ultimo'), 'title' => __('Event Payload', 'wp-ultimo'),
'loading_text' => __('Loading Payload', 'wp-ultimo'), 'loading_text' => __('Loading Payload', 'wp-ultimo'),
'payload' => json_encode($object->get_payload(), JSON_PRETTY_PRINT), 'payload' => json_encode($object->get_payload(), JSON_PRETTY_PRINT),
)); )
);
} // end output_default_widget_payload; }
/** /**
* Outputs the markup for the initiator widget. * 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); wu_get_template('events/widget-initiator', $args);
}
} // end output_default_widget_initiator;
/** /**
* Returns the title of the page. * Returns the title of the page.
@ -203,8 +209,7 @@ class Event_View_Admin_Page extends Edit_Admin_Page {
public function get_title() { public function get_title() {
return $this->edit ? __('Edit Event', 'wp-ultimo') : __('Add new Event', 'wp-ultimo'); return $this->edit ? __('Edit Event', 'wp-ultimo') : __('Add new Event', 'wp-ultimo');
}
} // end get_title;
/** /**
* Returns the title of menu for this page. * 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() { public function get_menu_title() {
return __('Edit Event', 'wp-ultimo'); return __('Edit Event', 'wp-ultimo');
}
} // end get_menu_title;
/** /**
* Returns the action links for that page. * Returns the action links for that page.
@ -227,8 +231,7 @@ class Event_View_Admin_Page extends Edit_Admin_Page {
public function action_links() { public function action_links() {
return array(); return array();
}
} // end action_links;
/** /**
* Returns the labels to be used on the admin page. * 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_button_label' => __('Delete Event', 'wp-ultimo'),
'delete_description' => __('Be careful. This action is irreversible.', 'wp-ultimo'), 'delete_description' => __('Be careful. This action is irreversible.', 'wp-ultimo'),
); );
}
} // end get_labels;
/** /**
* Returns the object being edit at the moment. * 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() { public function get_object() {
if (isset($_GET['id'])) { 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']); $item = $query->get_item_by('id', $_GET['id']);
if ($item) { if ($item) {
return $item; return $item;
}
} // end if; }
} // end if;
wp_redirect(wu_network_admin_url('wp-ultimo-events')); wp_redirect(wu_network_admin_url('wp-ultimo-events'));
exit; exit;
}
} // end get_object;
/** /**
* Events have titles. * Events have titles.
* *
@ -287,8 +284,7 @@ class Event_View_Admin_Page extends Edit_Admin_Page {
public function has_title(): bool { public function has_title(): bool {
return false; return false;
}
} // end has_title;
/** /**
* Handles the save of this form. * Handles the save of this form.
* *
@ -297,7 +293,5 @@ class Event_View_Admin_Page extends Edit_Admin_Page {
public function handle_save(): bool { public function handle_save(): bool {
return true; 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() { public function page_loaded() {
if (isset($_GET['integration'])) { if (isset($_GET['integration'])) {
$domain_manager = \WP_Ultimo\Managers\Domain_Manager::get_instance(); $domain_manager = \WP_Ultimo\Managers\Domain_Manager::get_instance();
$this->integration = $domain_manager->get_integration_instance($_GET['integration']); $this->integration = $domain_manager->get_integration_instance($_GET['integration']);
}
} // end if;
if ( ! $this->integration) { if ( ! $this->integration) {
wp_redirect(network_admin_url('admin.php?page=wp-ultimo-settings')); wp_redirect(network_admin_url('admin.php?page=wp-ultimo-settings'));
exit; exit;
}
} // end if;
parent::page_loaded(); parent::page_loaded();
}
} // end page_loaded;
/** /**
* Returns the title of the page. * 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 { public function get_title(): string {
return sprintf(__('Integration Setup', 'wp-ultimo')); return sprintf(__('Integration Setup', 'wp-ultimo'));
}
} // end get_title;
/** /**
* Returns the title of menu for this page. * 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() { public function get_menu_title() {
return __('Host Provider Integration', 'wp-ultimo'); return __('Host Provider Integration', 'wp-ultimo');
}
} // end get_menu_title;
/** /**
* Returns the sections for this Wizard. * 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. * Some host providers require no instructions.
*/ */
if ($this->integration->supports('no-instructions')) { if ($this->integration->supports('no-instructions')) {
unset($sections['instructions']); unset($sections['instructions']);
}
} // end if;
/* /*
* Some host providers require no additional setup. * Some host providers require no additional setup.
*/ */
if ($this->integration->supports('no-config')) { if ($this->integration->supports('no-config')) {
unset($sections['config']); unset($sections['config']);
}
} // end if;
return $sections; return $sections;
}
} // end get_sections;
/** /**
* Displays the content of the activation section. * 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(); $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(), 'screen' => get_current_screen(),
'page' => $this, 'page' => $this,
'integration' => $this->integration, 'integration' => $this->integration,
'will' => $explainer_lines['will'], 'will' => $explainer_lines['will'],
'will_not' => $explainer_lines['will_not'], 'will_not' => $explainer_lines['will_not'],
)); )
);
} // end section_activation; }
/** /**
* Displays the contents of the instructions section. * 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')); call_user_func(array($this->integration, 'get_instructions'));
$this->render_submit_box(); $this->render_submit_box();
}
} // end section_instructions;
/** /**
* Displays the content of the configuration section. * 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(); $fields = $this->integration->get_fields();
foreach ($fields as $field_constant => &$field) { foreach ($fields as $field_constant => &$field) {
$field['value'] = defined($field_constant) && constant($field_constant) ? constant($field_constant) : ''; $field['value'] = defined($field_constant) && constant($field_constant) ? constant($field_constant) : '';
}
} // end foreach; $form = new \WP_Ultimo\UI\Form(
$this->get_current_section(),
$form = new \WP_Ultimo\UI\Form($this->get_current_section(), $fields, array( $fields,
array(
'views' => 'admin-pages/fields', 'views' => 'admin-pages/fields',
'classes' => 'wu-widget-list wu-striped wu-m-0 wu--mt-2 wu--mb-3 wu--mx-3', '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', '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')) { if (wu_request('manual')) {
wu_get_template(
wu_get_template('wizards/host-integrations/configuration-results', array( 'wizards/host-integrations/configuration-results',
array(
'screen' => get_current_screen(), 'screen' => get_current_screen(),
'page' => $this, 'page' => $this,
'integration' => $this->integration, 'integration' => $this->integration,
'form' => $form, 'form' => $form,
'post' => $_GET['post'], 'post' => $_GET['post'],
)); )
);
return; return;
}
} // end if; wu_get_template(
'wizards/host-integrations/configuration',
wu_get_template('wizards/host-integrations/configuration', array( array(
'screen' => get_current_screen(), 'screen' => get_current_screen(),
'page' => $this, 'page' => $this,
'integration' => $this->integration, 'integration' => $this->integration,
'form' => $form, 'form' => $form,
)); )
);
} // end section_configuration; }
/** /**
* Displays the content of the final section. * 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() { public function section_ready() {
wu_get_template('wizards/host-integrations/ready', array( wu_get_template(
'wizards/host-integrations/ready',
array(
'screen' => get_current_screen(), 'screen' => get_current_screen(),
'page' => $this, 'page' => $this,
'integration' => $this->integration, 'integration' => $this->integration,
)); )
);
} // end section_ready; }
/** /**
* Handles the activation of a given integration. * 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(); $is_enabled = $this->integration->is_enabled();
if ($is_enabled) { if ($is_enabled) {
$this->integration->disable(); $this->integration->disable();
return; return;
}
} // end if;
$this->integration->enable(); $this->integration->enable();
wp_redirect($this->get_next_section_link()); wp_redirect($this->get_next_section_link());
exit; exit;
}
} // end handle_activation;
/** /**
* Handles the configuration of a given integration. * 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 if (wu_request('submit') == '0') { // phpcs:ignore
$redirect_url = add_query_arg(array( $redirect_url = add_query_arg(
array(
'manual' => '1', 'manual' => '1',
'post' => $_POST, 'post' => $_POST,
)); )
);
wp_redirect($redirect_url); wp_redirect($redirect_url);
exit; exit;
}
} // end if;
if (wu_request('submit') == '1') { // phpcs:ignore if (wu_request('submit') == '1') { // phpcs:ignore
$this->integration->setup_constants($_POST); $this->integration->setup_constants($_POST);
}
} // end if;
$redirect_url = $this->get_next_section_link(); $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); wp_redirect($redirect_url);
exit; exit;
}
} // end handle_configuration;
/** /**
* Handles the testing of a given 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'); 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(), 'screen' => get_current_screen(),
'page' => $this, 'page' => $this,
'integration' => $this->integration, 'integration' => $this->integration,
)); )
);
} // end section_test; }
}
} // end class Hosting_Integration_Wizard_Admin_Page;

View File

@ -9,7 +9,7 @@
namespace WP_Ultimo\Admin_Pages; namespace WP_Ultimo\Admin_Pages;
use \WP_Ultimo\Invoices\Invoice; use WP_Ultimo\Invoices\Invoice;
// Exit if accessed directly // Exit if accessed directly
defined('ABSPATH') || exit; defined('ABSPATH') || exit;
@ -83,8 +83,7 @@ class Invoice_Template_Customize_Admin_Page extends Customizer_Admin_Page {
parent::init(); parent::init();
add_action('wp_ajax_wu-preview-invoice', array($this, 'generate_invoice_preview')); add_action('wp_ajax_wu-preview-invoice', array($this, 'generate_invoice_preview'));
}
} // end init;
/** /**
* Ajax endpoint to generate the Ajax Preview. * 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() { public function generate_invoice_preview() {
if ( ! current_user_can('wu_manage_invoice')) { if ( ! current_user_can('wu_manage_invoice')) {
return; return;
}
} // end if;
$order = false; $order = false;
@ -109,8 +106,7 @@ class Invoice_Template_Customize_Admin_Page extends Customizer_Admin_Page {
$invoice->print_file(); $invoice->print_file();
die; die;
}
} // end generate_invoice_preview;
/** /**
* Returns the preview URL. This is then added to the iframe. * 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'); $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', 'action' => 'wu-preview-invoice',
'customizer' => 1, 'customizer' => 1,
'invoice-customize' => 1 'invoice-customize' => 1,
), $url); ),
$url
} // end get_preview_url; );
}
/** /**
* Allow child classes to register widgets, if they need them. * 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(); $settings = Invoice::get_settings();
$this->add_save_widget('save', array( $this->add_save_widget(
'save',
array(
'fields' => array( 'fields' => array(
'note' => array( 'note' => array(
'type' => 'note', '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'), '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'); $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'), 'font' => wu_get_isset($settings, 'font', 'DejaVuSansCondensed'),
); );
$state = array_merge($settings, array( $state = array_merge(
$settings,
array(
'tab' => 'general', 'tab' => 'general',
'refresh' => true, 'refresh' => true,
)); )
);
$this->add_fields_widget('customizer', array( $this->add_fields_widget(
'customizer',
array(
'title' => __('Customizer', 'wp-ultimo'), 'title' => __('Customizer', 'wp-ultimo'),
'position' => 'side', 'position' => 'side',
'fields' => $fields, 'fields' => $fields,
@ -282,9 +288,9 @@ class Invoice_Template_Customize_Admin_Page extends Customizer_Admin_Page {
'data-wu-customizer-panel' => true, 'data-wu-customizer-panel' => true,
'data-state' => json_encode($state), 'data-state' => json_encode($state),
), ),
)); )
);
} // end register_widgets; }
/** /**
* Returns the title of the page. * Returns the title of the page.
@ -295,8 +301,7 @@ class Invoice_Template_Customize_Admin_Page extends Customizer_Admin_Page {
public function get_title() { public function get_title() {
return __('Customize Invoice Template', 'wp-ultimo'); return __('Customize Invoice Template', 'wp-ultimo');
}
} // end get_title;
/** /**
* Returns the title of menu for this page. * 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() { public function get_menu_title() {
return __('Customize Invoice Template', 'wp-ultimo'); return __('Customize Invoice Template', 'wp-ultimo');
}
} // end get_menu_title;
/** /**
* Returns the action links for that page. * 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() { public function action_links() {
return array(); return array();
}
} // end action_links;
/** /**
* Returns the labels to be used on the admin page. * 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_button_label' => __('Save Invoice Template', 'wp-ultimo'),
'save_description' => __('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. * 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); wp_redirect($url);
exit; 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(); parent::init();
add_filter('action_scheduler_admin_view_class', array($this, 'hide_as_admin_page'), 9999, 1); 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. * 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) { public function hide_as_admin_page($admin_view_class) {
if (is_network_admin() || class_exists('WooCommerce')) { if (is_network_admin() || class_exists('WooCommerce')) {
return $admin_view_class; return $admin_view_class;
}
} // end if;
return '\WP_Ultimo\Compat\AS_Admin_View'; return '\WP_Ultimo\Compat\AS_Admin_View';
}
} // end hide_as_admin_page;
/** /**
* Returns the title of the page. * Returns the title of the page.
@ -113,8 +109,7 @@ class Jobs_List_Admin_Page extends Base_Admin_Page {
public function get_title() { public function get_title() {
return __('Jobs', 'wp-ultimo'); return __('Jobs', 'wp-ultimo');
}
} // end get_title;
/** /**
* Returns the title of menu for this page. * 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() { public function get_menu_title() {
return __('Jobs', 'wp-ultimo'); return __('Jobs', 'wp-ultimo');
}
} // end get_menu_title;
/** /**
* Allows admins to rename the sub-menu (first item) for a top-level page. * 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() { public function get_submenu_title() {
return __('Jobs', 'wp-ultimo'); return __('Jobs', 'wp-ultimo');
}
} // end get_submenu_title;
/** /**
* Runs the hooks for the admin list table. * 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() { public function page_loaded() {
\ActionScheduler_AdminView::instance()->process_admin_ui(); \ActionScheduler_AdminView::instance()->process_admin_ui();
}
} // end page_loaded;
/** /**
* Calls the Action Scheduler renderer. * Calls the Action Scheduler renderer.
@ -163,7 +155,5 @@ class Jobs_List_Admin_Page extends Base_Admin_Page {
public function output() { public function output() {
\ActionScheduler_AdminView::instance()->render_admin_ui(); \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 * Adds the process for process actions
*/ */
$this->process_single_action(); $this->process_single_action();
}
} // end page_loaded;
/** /**
* Initializes the class * Initializes the class
@ -99,8 +98,7 @@ abstract class List_Admin_Page extends Base_Admin_Page {
parent::init(); parent::init();
add_filter('set-screen-option', array($this, 'save_screen_option'), 8, 3); add_filter('set-screen-option', array($this, 'save_screen_option'), 8, 3);
}
} // end init;
/** /**
* Process lins actions of the tables * Process lins actions of the tables
@ -111,12 +109,9 @@ abstract class List_Admin_Page extends Base_Admin_Page {
public function process_single_action() { public function process_single_action() {
if ($this->table) { if ($this->table) {
$this->table->process_single_action(); $this->table->process_single_action();
}
} // end if; }
} // end process_single_action;
/** /**
* Returns an array with the labels for the edit page. * 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'), 'deleted_message' => __('Object removed successfully.', 'wp-ultimo'),
'search_label' => __('Search Object', '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. * 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_style('wp-color-picker');
wp_enqueue_script('wu-selectizer'); wp_enqueue_script('wu-selectizer');
}
} // end register_scripts;
/** /**
* Sets the default list template * 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 =) * 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, 'page' => $this,
'table' => $this->get_table(), 'table' => $this->get_table(),
'classes' => $this->table->get_filters() ? 'wu-advanced-filters' : 'wu-no-advanced-filters', 'classes' => $this->table->get_filters() ? 'wu-advanced-filters' : 'wu-no-advanced-filters',
)); )
);
} // end output; }
/** /**
* Child classes can to implement to hide the search field * 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() { public function has_search() {
return true; return true;
}
} // end has_search;
/** /**
* Set the screen options to allow users to set the pagination options of the subscriptions list * 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() { public function screen_options() {
if ($this->table) { if ($this->table) {
$args = array( $args = array(
'default' => 20, 'default' => 20,
'label' => $this->table->get_per_page_option_label(), '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); add_screen_option('per_page', $args);
}
} // end if; }
} // end screen_options;
/** /**
* Tells WordPress we want to save screen options on our pages. * 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) { public function save_screen_option($value, $option, $other_value) {
return $value === false && is_numeric($other_value) ? (int) $other_value : $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 * 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() { public function get_table() {
return $this->table; return $this->table;
}
} // end get_table;
/** /**
* Loads the list table for this particular page. * 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 * @return \WP_Ultimo\List_Tables\Base_List_Table
*/ */
abstract function 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 // Exit if accessed directly
defined('ABSPATH') || exit; defined('ABSPATH') || exit;
use \WP_Ultimo\Models\Membership; use WP_Ultimo\Models\Membership;
use \WP_Ultimo\Database\Memberships\Membership_Status; use WP_Ultimo\Database\Memberships\Membership_Status;
/** /**
* WP Multisite WaaS Membership Admin Page. * WP Multisite WaaS Membership Admin Page.
@ -67,13 +67,15 @@ class Membership_List_Admin_Page extends List_Admin_Page {
/* /*
* Add new Membership * 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'), 'render' => array($this, 'render_add_new_membership_modal'),
'handler' => array($this, 'handle_add_new_membership_modal'), 'handler' => array($this, 'handle_add_new_membership_modal'),
'capability' => 'wu_edit_memberships', 'capability' => 'wu_edit_memberships',
)); )
);
} // end register_forms; }
/** /**
* Renders the add new customer modal. * 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', 'views' => 'admin-pages/fields',
'classes' => 'wu-modal-form wu-widget-list wu-striped wu-m-0 wu-mt-0', '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', '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( 'html_attr' => array(
'data-wu-app' => 'add_new_membership', 'data-wu-app' => 'add_new_membership',
'data-on-load' => 'wu_initialize_datepickers', 'data-on-load' => 'wu_initialize_datepickers',
'data-state' => wu_convert_to_state(array( 'data-state' => wu_convert_to_state(
'lifetime' => 1 array(
)), 'lifetime' => 1,
)
), ),
)); ),
)
);
$form->render(); $form->render();
}
} // end render_add_new_membership_modal;
/** /**
* Handles creation of a new memberships. * Handles creation of a new memberships.
@ -187,29 +194,31 @@ class Membership_List_Admin_Page extends List_Admin_Page {
$products = explode(',', (string) $products); $products = explode(',', (string) $products);
if (empty($products)) { if (empty($products)) {
wp_send_json_error(
wp_send_json_error(new \WP_Error( new \WP_Error(
'empty-products', 'empty-products',
__('Products can not be empty.', 'wp-ultimo') __('Products can not be empty.', 'wp-ultimo')
)); )
);
} // end if; }
$customer = wu_get_customer(wu_request('customer_id', 0)); $customer = wu_get_customer(wu_request('customer_id', 0));
if (empty($customer)) { if (empty($customer)) {
wp_send_json_error(
wp_send_json_error(new \WP_Error( new \WP_Error(
'customer-not-found', 'customer-not-found',
__('The selected customer does not exist.', 'wp-ultimo') __('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, 'products' => $products,
'country' => $customer->get_country(), 'country' => $customer->get_country(),
)); )
);
$data = $cart->to_membership_data(); $data = $cart->to_membership_data();
@ -222,28 +231,28 @@ class Membership_List_Admin_Page extends List_Admin_Page {
$maybe_lifetime = wu_request('lifetime'); $maybe_lifetime = wu_request('lifetime');
if ($maybe_lifetime) { if ($maybe_lifetime) {
$date_expiration = null; $date_expiration = null;
}
} // end if;
$data['date_expiration'] = $date_expiration; $data['date_expiration'] = $date_expiration;
$membership = wu_create_membership($data); $membership = wu_create_membership($data);
if (is_wp_error($membership)) { if (is_wp_error($membership)) {
wp_send_json_error($membership); wp_send_json_error($membership);
}
} // end if; wp_send_json_success(
array(
wp_send_json_success(array( 'redirect_url' => wu_network_admin_url(
'redirect_url' => wu_network_admin_url('wp-ultimo-edit-membership', array( 'wp-ultimo-edit-membership',
array(
'id' => $membership->get_id(), 'id' => $membership->get_id(),
)) )
)); ),
)
} // end handle_add_new_membership_modal; );
}
/** /**
* Returns an array with the labels for the edit page. * 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'), 'deleted_message' => __('Membership removed successfully.', 'wp-ultimo'),
'search_label' => __('Search Membership', 'wp-ultimo'), 'search_label' => __('Search Membership', 'wp-ultimo'),
); );
}
} // end get_labels;
/** /**
* Returns the title of the page. * Returns the title of the page.
@ -269,8 +277,7 @@ class Membership_List_Admin_Page extends List_Admin_Page {
public function get_title() { public function get_title() {
return __('Memberships', 'wp-ultimo'); return __('Memberships', 'wp-ultimo');
}
} // end get_title;
/** /**
* Returns the title of menu for this page. * 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() { public function get_menu_title() {
return __('Memberships', 'wp-ultimo'); return __('Memberships', 'wp-ultimo');
}
} // end get_menu_title;
/** /**
* Allows admins to rename the sub-menu (first item) for a top-level page. * 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() { public function get_submenu_title() {
return __('Memberships', 'wp-ultimo'); return __('Memberships', 'wp-ultimo');
}
} // end get_submenu_title;
/** /**
* Returns the action links for that page. * 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'), 'url' => wu_get_form_url('add_new_membership'),
), ),
); );
}
} // end action_links;
/** /**
* Loads the list table for this particular page. * Loads the list table for this particular page.
@ -324,7 +328,5 @@ class Membership_List_Admin_Page extends List_Admin_Page {
public function table() { public function table() {
return new \WP_Ultimo\List_Tables\Membership_List_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() { public function __construct() {
parent::__construct(); parent::__construct();
}
} // end __construct;
/** /**
* Returns the logo for the wizard. * Returns the logo for the wizard.
@ -95,8 +94,7 @@ class Migration_Alert_Admin_Page extends Wizard_Admin_Page {
public function get_logo() { public function get_logo() {
return wu_get_asset('logo.png', 'img'); return wu_get_asset('logo.png', 'img');
}
} // end get_logo;
/** /**
* Returns the title of the page. * Returns the title of the page.
@ -107,8 +105,7 @@ class Migration_Alert_Admin_Page extends Wizard_Admin_Page {
public function get_title(): string { public function get_title(): string {
return sprintf(__('Migration', 'wp-ultimo')); return sprintf(__('Migration', 'wp-ultimo'));
}
} // end get_title;
/** /**
* Returns the title of menu for this page. * 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() { public function get_menu_title() {
return WP_Ultimo()->is_loaded() ? __('WP Multisite WaaS Migration Alert', 'wp-ultimo') : __('WP Multisite WaaS', 'wp-ultimo'); 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. * Returns the sections for this Wizard.
@ -137,8 +133,7 @@ class Migration_Alert_Admin_Page extends Wizard_Admin_Page {
'handler' => array($this, 'handle_proceed'), 'handler' => array($this, 'handle_proceed'),
), ),
); );
}
} // end get_sections;
/** /**
* Displays the content of the final section. * Displays the content of the final section.
@ -148,12 +143,14 @@ class Migration_Alert_Admin_Page extends Wizard_Admin_Page {
*/ */
public function section_alert() { public function section_alert() {
wu_get_template('wizards/setup/alert', array( wu_get_template(
'wizards/setup/alert',
array(
'screen' => get_current_screen(), 'screen' => get_current_screen(),
'page' => $this, 'page' => $this,
)); )
);
} // end section_alert; }
/** /**
* Handles the proceed action. * 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')); wp_redirect(wu_network_admin_url('wp-ultimo-setup'));
exit; 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 // Exit if accessed directly
defined('ABSPATH') || exit; defined('ABSPATH') || exit;
use \WP_Ultimo\Models\Payment; use WP_Ultimo\Models\Payment;
use \WP_Ultimo\Database\Payments\Payment_Status; use WP_Ultimo\Database\Payments\Payment_Status;
/** /**
* WP Multisite WaaS Payment Edit/Add New Admin Page. * 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(); parent::register_scripts();
wp_enqueue_editor(); wp_enqueue_editor();
}
} // end register_scripts;
/** /**
* Register ajax forms that we use for payments. * 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 * 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'), 'render' => array($this, 'render_edit_line_item_modal'),
'handler' => array($this, 'handle_edit_line_item_modal'), 'handler' => array($this, 'handle_edit_line_item_modal'),
'capability' => 'wu_edit_payments', 'capability' => 'wu_edit_payments',
)); )
);
/* /*
* Delete Line Item - Confirmation modal * 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'), 'render' => array($this, 'render_delete_line_item_modal'),
'handler' => array($this, 'handle_delete_line_item_modal'), 'handler' => array($this, 'handle_delete_line_item_modal'),
'capability' => 'wu_delete_payments', 'capability' => 'wu_delete_payments',
)); )
);
/* /*
* Refund Line Item * Refund Line Item
*/ */
wu_register_form('refund_payment', array( wu_register_form(
'refund_payment',
array(
'render' => array($this, 'render_refund_payment_modal'), 'render' => array($this, 'render_refund_payment_modal'),
'handler' => array($this, 'handle_refund_payment_modal'), 'handler' => array($this, 'handle_refund_payment_modal'),
'capability' => 'wu_refund_payments', 'capability' => 'wu_refund_payments',
)); )
);
/* /*
* Delete - Confirmation modal * Delete - Confirmation modal
*/ */
add_filter('wu_data_json_success_delete_payment_modal', fn($data_json) => array( add_filter(
'redirect_url' => wu_network_admin_url('wp-ultimo-payments', array('deleted' => 1)) '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; )
);
}
/** /**
* Renders the deletion confirmation form. * 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()); $line_item = wu_get_line_item(wu_request('line_item_id'), $payment->get_id());
if ( ! $line_item || ! $payment) { if ( ! $line_item || ! $payment) {
return; return;
}
} // end if;
$fields = array( $fields = array(
'confirm' => 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', 'views' => 'admin-pages/fields',
'classes' => 'wu-modal-form wu-widget-list wu-striped wu-m-0 wu-mt-0', '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', '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( 'html_attr' => array(
'data-wu-app' => 'true', 'data-wu-app' => 'true',
'data-state' => wu_convert_to_state(array( 'data-state' => wu_convert_to_state(
array(
'confirmed' => false, 'confirmed' => false,
)), )
), ),
)); ),
)
);
$form->render(); $form->render();
}
} // end render_delete_line_item_modal;
/** /**
* Handles the deletion of line items. * 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()); $line_item = wu_get_line_item(wu_request('line_item_id'), $payment->get_id());
if ( ! $payment || ! $line_item) { if ( ! $payment || ! $line_item) {
wp_send_json_error(new \WP_Error('not-found', __('Payment not found.', 'wp-ultimo'))); wp_send_json_error(new \WP_Error('not-found', __('Payment not found.', 'wp-ultimo')));
}
} // end if;
$line_items = $payment->get_line_items(); $line_items = $payment->get_line_items();
@ -228,16 +239,15 @@ class Payment_Edit_Admin_Page extends Edit_Admin_Page {
$saved = $payment->recalculate_totals()->save(); $saved = $payment->recalculate_totals()->save();
if (is_wp_error($saved)) { if (is_wp_error($saved)) {
wp_send_json_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']), 'redirect_url' => add_query_arg('updated', 1, $_SERVER['HTTP_REFERER']),
)); )
);
} // end handle_delete_line_item_modal; }
/** /**
* Renders the refund 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')); $payment = wu_get_payment(wu_request('id'));
if ( ! $payment) { if ( ! $payment) {
return; return;
}
} // end if;
$fields = array( $fields = array(
'_amount' => array( '_amount' => array(
@ -265,7 +273,7 @@ class Payment_Edit_Admin_Page extends Edit_Admin_Page {
'html_attr' => array( 'html_attr' => array(
'v-model' => 'amount', 'v-model' => 'amount',
'step' => '0.01', 'step' => '0.01',
'v-bind:max' => 'total' 'v-bind:max' => 'total',
), ),
'wrapper_html_attr' => array( 'wrapper_html_attr' => array(
'v-show' => 'step === 1', 'v-show' => 'step === 1',
@ -317,7 +325,7 @@ class Payment_Edit_Admin_Page extends Edit_Admin_Page {
), ),
'html_attr' => array( 'html_attr' => array(
'v-bind:disabled' => 'amount <= 0 || amount > total', 'v-bind:disabled' => 'amount <= 0 || amount > total',
'v-on:click.prevent' => 'step = 2' 'v-on:click.prevent' => 'step = 2',
), ),
), ),
'submit_button_2' => array( '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', 'views' => 'admin-pages/fields',
'classes' => 'wu-modal-form wu-widget-list wu-striped wu-m-0 wu-mt-0', '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', '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( 'html_attr' => array(
'data-wu-app' => 'refund', 'data-wu-app' => 'refund',
'data-state' => wu_convert_to_state(array( 'data-state' => wu_convert_to_state(
array(
'step' => 1, 'step' => 1,
'confirmed' => false, 'confirmed' => false,
'total' => round($payment->get_total(), 2), 'total' => round($payment->get_total(), 2),
'amount' => round($payment->get_total(), 2), 'amount' => round($payment->get_total(), 2),
)), )
), ),
)); ),
)
);
$form->render(); $form->render();
}
} // end render_refund_payment_modal;
/** /**
* Handles the deletion of line items. * 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')); $payment = wu_get_payment(wu_request('id'));
if ( ! $payment) { if ( ! $payment) {
wp_send_json_error(new \WP_Error('not-found', __('Payment not found.', 'wp-ultimo'))); wp_send_json_error(new \WP_Error('not-found', __('Payment not found.', 'wp-ultimo')));
}
} // end if;
/* /*
* Checks for a valid amount. * Checks for a valid amount.
*/ */
if (empty($amount) || $amount > $payment->get_total()) { 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'))); 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 * 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); $is_refundable = in_array($payment->get_status(), wu_get_refundable_payment_types(), true);
if ( ! $is_refundable) { if ( ! $is_refundable) {
wp_send_json_error(new \WP_Error('payment-not-refunded', __('This payment is not in a refundable state.', 'wp-ultimo'))); 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 * 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); $status = $payment->refund($amount, $should_cancel_membership_on_refund);
if (is_wp_error($status)) { if (is_wp_error($status)) {
wp_send_json_error($status); wp_send_json_error($status);
}
} // end if;
/* /*
* Done! Redirect back. * Done! Redirect back.
*/ */
wp_send_json_success(array( wp_send_json_success(
'redirect_url' => wu_network_admin_url('wp-ultimo-edit-payment', array( array(
'redirect_url' => wu_network_admin_url(
'wp-ultimo-edit-payment',
array(
'id' => $payment->get_id(), 'id' => $payment->get_id(),
'updated' => 1, 'updated' => 1,
)), )
)); ),
)
} // end if; );
}
$gateway = wu_get_gateway($gateway_id); $gateway = wu_get_gateway($gateway_id);
if ( ! $gateway) { if ( ! $gateway) {
wp_send_json_error(new \WP_Error('gateway-not-found', __('Payment gateway not found.', 'wp-ultimo'))); wp_send_json_error(new \WP_Error('gateway-not-found', __('Payment gateway not found.', 'wp-ultimo')));
}
} // end if;
/* /*
* Process the refund on the gateway. * 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())); $error = new \WP_Error('refund-error', sprintf(__('An error occurred: %s', 'wp-ultimo'), $status->get_error_message()));
wp_send_json_error($error); wp_send_json_error($error);
}
} // end if;
} catch (\Throwable $e) { } catch (\Throwable $e) {
// translators: %s is the exception error message. // translators: %s is the exception error message.
$error = new \WP_Error('refund-error', sprintf(__('An error occurred: %s', 'wp-ultimo'), $e->getMessage())); $error = new \WP_Error('refund-error', sprintf(__('An error occurred: %s', 'wp-ultimo'), $e->getMessage()));
wp_send_json_error($error); wp_send_json_error($error);
}
} // end try;
/* /*
* Done! Redirect back. * Done! Redirect back.
*/ */
wp_send_json_success(array( wp_send_json_success(
'redirect_url' => wu_network_admin_url('wp-ultimo-edit-payment', array( array(
'redirect_url' => wu_network_admin_url(
'wp-ultimo-edit-payment',
array(
'id' => $payment->get_id(), 'id' => $payment->get_id(),
'updated' => 1, 'updated' => 1,
)), )
)); ),
)
} // end handle_refund_payment_modal; );
}
/** /**
* Handles the add/edit of line items. * 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()); $line_item = wu_get_line_item(wu_request('line_item_id'), $payment->get_id());
if ( ! $line_item) { if ( ! $line_item) {
$line_item = new \WP_Ultimo\Checkout\Line_Item(array()); $line_item = new \WP_Ultimo\Checkout\Line_Item(array());
}
} // end if;
/* /*
* First, we get the type. * First, we get the type.
@ -532,16 +538,13 @@ class Payment_Edit_Admin_Page extends Edit_Admin_Page {
$type = wu_request('type', 'product'); $type = wu_request('type', 'product');
if ($type === 'product') { if ($type === 'product') {
$product = wu_get_product(wu_request('product_id')); $product = wu_get_product(wu_request('product_id'));
if (empty($product)) { if (empty($product)) {
$error = new \WP_Error('missing-product', __('The product was not found.', 'wp-ultimo')); $error = new \WP_Error('missing-product', __('The product was not found.', 'wp-ultimo'));
wp_send_json_error($error); wp_send_json_error($error);
}
} // end if;
/* /*
* Constructs the arguments * Constructs the arguments
@ -557,7 +560,6 @@ class Payment_Edit_Admin_Page extends Edit_Admin_Page {
'tax_type' => wu_request('tax_type', 'percentage'), 'tax_type' => wu_request('tax_type', 'percentage'),
'tax_label' => wu_request('tax_label', ''), 'tax_label' => wu_request('tax_label', ''),
); );
} else { } else {
/** /**
@ -566,19 +568,20 @@ class Payment_Edit_Admin_Page extends Edit_Admin_Page {
* *
* First, check the valid types. * 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', 'fee',
'refund', 'refund',
'credit', 'credit',
)); )
);
if ( ! in_array($type, $allowed_types, true)) { if ( ! in_array($type, $allowed_types, true)) {
$error = new \WP_Error('invalid-type', __('The line item type is invalid.', 'wp-ultimo')); $error = new \WP_Error('invalid-type', __('The line item type is invalid.', 'wp-ultimo'));
wp_send_json_error($error); wp_send_json_error($error);
}
} // end if;
/* /*
* Set the new attributes * Set the new attributes
@ -592,8 +595,7 @@ class Payment_Edit_Admin_Page extends Edit_Admin_Page {
'tax_type' => 'percentage', 'tax_type' => 'percentage',
'tax_label' => '', 'tax_label' => '',
); );
}
} // end if;
$line_item->attributes($atts); $line_item->attributes($atts);
@ -608,22 +610,19 @@ class Payment_Edit_Admin_Page extends Edit_Admin_Page {
$saved = $payment->recalculate_totals()->save(); $saved = $payment->recalculate_totals()->save();
if ( ! $saved) { if ( ! $saved) {
wp_send_json_error(new \WP_Error('error', __('Something wrong happened.', 'wp-ultimo'))); wp_send_json_error(new \WP_Error('error', __('Something wrong happened.', 'wp-ultimo')));
}
} // end if;
if (is_wp_error($saved)) { if (is_wp_error($saved)) {
wp_send_json_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']), 'redirect_url' => add_query_arg('updated', 1, $_SERVER['HTTP_REFERER']),
)); )
);
} // end handle_edit_line_item_modal; }
/** /**
* Renders the add/edit line items form. * 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. * we start a new line.
*/ */
$line_item = new \WP_Ultimo\Checkout\Line_Item(array()); $line_item = new \WP_Ultimo\Checkout\Line_Item(array());
}
} // end if;
$fields = array( $fields = array(
'tab' => 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', 'views' => 'admin-pages/fields',
'classes' => 'wu-modal-form wu-widget-list wu-striped wu-m-0 wu-mt-0', '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', '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( 'html_attr' => array(
'data-wu-app' => 'edit_line_item', 'data-wu-app' => 'edit_line_item',
'data-state' => wu_convert_to_state(array( 'data-state' => wu_convert_to_state(
array(
'tab' => 'type', 'tab' => 'type',
'type' => $line_item->get_type(), 'type' => $line_item->get_type(),
'taxable' => $line_item->get_tax_rate() > 0, 'taxable' => $line_item->get_tax_rate() > 0,
'unit_price' => $line_item->get_unit_price(), 'unit_price' => $line_item->get_unit_price(),
)), )
), ),
)); ),
)
);
$form->render(); $form->render();
}
} // end render_edit_line_item_modal;
/** /**
* Display the payment actions. * 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); $is_refundable = in_array($this->get_object()->get_status(), wu_get_refundable_payment_types(), true);
if ($is_refundable) { if ($is_refundable) {
$actions['refund_payment'] = array( $actions['refund_payment'] = array(
'label' => __('Refund Payment', 'wp-ultimo'), 'label' => __('Refund Payment', 'wp-ultimo'),
'icon_classes' => 'dashicons-wu-ccw wu-align-text-bottom', 'icon_classes' => 'dashicons-wu-ccw wu-align-text-bottom',
'classes' => 'button wubox', '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(), 'id' => $this->get_object()->get_id(),
)), )
),
); );
}
} // end if;
$actions['add_line_item'] = array( $actions['add_line_item'] = array(
'label' => __('Add Line Item', 'wp-ultimo'), 'label' => __('Add Line Item', 'wp-ultimo'),
'icon_classes' => 'dashicons-wu-circle-with-plus wu-align-text-bottom', 'icon_classes' => 'dashicons-wu-circle-with-plus wu-align-text-bottom',
'classes' => 'button wubox', '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(), '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(), 'payment' => $this->get_object(),
'actions' => $actions, 'actions' => $actions,
)); )
);
} // end display_payment_actions; }
/** /**
* Displays the tax tax breakthrough. * 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(); $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, 'tax_breakthrough' => $tax_breakthrough,
'payment' => $this->get_object(), 'payment' => $this->get_object(),
)); )
);
} // end display_tax_breakthrough; }
/** /**
* Allow child classes to register widgets, if they need them. * 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>"; $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'), 'title' => __('At a Glance', 'wp-ultimo'),
'position' => 'normal', 'position' => 'normal',
'classes' => 'wu-overflow-hidden wu-widget-inset', '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', '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'), 'title' => __('Line Items', 'wp-ultimo'),
'table' => new \WP_Ultimo\List_Tables\Payment_Line_Item_List_Table(), 'table' => new \WP_Ultimo\List_Tables\Payment_Line_Item_List_Table(),
'position' => 'normal', 'position' => 'normal',
'query_filter' => array($this, 'payments_query_filter'), 'query_filter' => array($this, 'payments_query_filter'),
'after' => $this->display_payment_actions(), 'after' => $this->display_payment_actions(),
)); )
);
$this->add_widget('tax-rates', array( $this->add_widget(
'tax-rates',
array(
'title' => __('Tax Rate Breakthrough', 'wp-ultimo'), 'title' => __('Tax Rate Breakthrough', 'wp-ultimo'),
'position' => 'normal', 'position' => 'normal',
'display' => array($this, 'display_tax_breakthrough'), 'display' => array($this, 'display_tax_breakthrough'),
)); )
);
$this->add_tabs_widget('options', array( $this->add_tabs_widget(
'options',
array(
'title' => __('Payment Options', 'wp-ultimo'), 'title' => __('Payment Options', 'wp-ultimo'),
'position' => 'normal', 'position' => 'normal',
'sections' => apply_filters('wu_payments_options_sections', array(), $this->get_object()), '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'), 'title' => __('Events', 'wp-ultimo'),
'table' => new \WP_Ultimo\List_Tables\Inside_Events_List_Table(), 'table' => new \WP_Ultimo\List_Tables\Inside_Events_List_Table(),
'query_filter' => array($this, 'events_query_filter'), 'query_filter' => array($this, 'events_query_filter'),
)); )
);
$membership = $this->get_object()->get_membership(); $membership = $this->get_object()->get_membership();
$this->add_save_widget('save', array( $this->add_save_widget(
'save',
array(
'html_attr' => array( 'html_attr' => array(
'data-wu-app' => 'payment_save', '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(), 'status' => $this->get_object()->get_status(),
'original_status' => $this->get_object()->get_status(), 'original_status' => $this->get_object()->get_status(),
'membership_id' => $membership ? $this->get_object()->get_membership_id() : '', 'membership_id' => $membership ? $this->get_object()->get_membership_id() : '',
'membership_status' => $membership ? $membership->get_status() : 'active', 'membership_status' => $membership ? $membership->get_status() : 'active',
'gateway' => $this->get_object()->get_gateway(), 'gateway' => $this->get_object()->get_gateway(),
)), )
),
), ),
'fields' => array( 'fields' => array(
'status' => array( 'status' => array(
@ -1072,21 +1102,16 @@ class Payment_Edit_Admin_Page extends Edit_Admin_Page {
$gateway_id = $this->get_object()->get_gateway(); $gateway_id = $this->get_object()->get_gateway();
if (empty($this->get_object()->get_gateway_payment_id())) { if (empty($this->get_object()->get_gateway_payment_id())) {
return ''; return '';
}
} // end if;
$url = apply_filters("wu_{$gateway_id}_remote_payment_url", $this->get_object()->get_gateway_payment_id()); $url = apply_filters("wu_{$gateway_id}_remote_payment_url", $this->get_object()->get_gateway_payment_id());
if ($url) { 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')); 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 ''; return '';
}, },
'wrapper_html_attr' => array( 'wrapper_html_attr' => array(
'v-cloak' => '1', '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. * Returns the title of the page.
@ -1134,8 +1159,7 @@ class Payment_Edit_Admin_Page extends Edit_Admin_Page {
public function get_title() { public function get_title() {
return $this->edit ? __('Edit Payment', 'wp-ultimo') : __('Add new Payment', 'wp-ultimo'); return $this->edit ? __('Edit Payment', 'wp-ultimo') : __('Add new Payment', 'wp-ultimo');
}
} // end get_title;
/** /**
* Returns the title of menu for this page. * 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() { public function get_menu_title() {
return __('Edit Payment', 'wp-ultimo'); return __('Edit Payment', 'wp-ultimo');
}
} // end get_menu_title;
/** /**
* Returns the action links for that page. * Returns the action links for that page.
@ -1162,7 +1185,6 @@ class Payment_Edit_Admin_Page extends Edit_Admin_Page {
$payment = $this->get_object(); $payment = $this->get_object();
if ($payment) { if ($payment) {
$actions[] = array( $actions[] = array(
'url' => $payment->get_invoice_url(), 'url' => $payment->get_invoice_url(),
'label' => __('Generate Invoice', 'wp-ultimo'), 'label' => __('Generate Invoice', 'wp-ultimo'),
@ -1170,20 +1192,16 @@ class Payment_Edit_Admin_Page extends Edit_Admin_Page {
); );
if ($payment->is_payable()) { if ($payment->is_payable()) {
$actions[] = array( $actions[] = array(
'url' => $payment->get_payment_url(), 'url' => $payment->get_payment_url(),
'label' => __('Payment URL', 'wp-ultimo'), 'label' => __('Payment URL', 'wp-ultimo'),
'icon' => 'wu-credit-card', 'icon' => 'wu-credit-card',
); );
}
} // end if; }
} // end if;
return $actions; return $actions;
}
} // end action_links;
/** /**
* Returns the labels to be used on the admin page. * 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_button_label' => __('Delete Payment', 'wp-ultimo'),
'delete_description' => __('Be careful. This action is irreversible.', 'wp-ultimo'), 'delete_description' => __('Be careful. This action is irreversible.', 'wp-ultimo'),
); );
}
} // end get_labels;
/** /**
* Filters the list table to return only relevant events. * 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); return array_merge($args, $extra_args);
}
} // end events_query_filter;
/** /**
* Filters the list table to return only relevant events. * 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); return array_merge($args, $extra_args);
}
} // end payments_query_filter;
/** /**
* Returns the object being edit at the moment. * Returns the object being edit at the moment.
@ -1256,34 +1271,27 @@ class Payment_Edit_Admin_Page extends Edit_Admin_Page {
static $payment; static $payment;
if ($payment !== null) { if ($payment !== null) {
return $payment; return $payment;
}
} // end if;
if (isset($_GET['id'])) { 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']); $item = $query->get_item_by('id', $_GET['id']);
if ( ! $item || $item->get_parent_id()) { if ( ! $item || $item->get_parent_id()) {
wp_redirect(wu_network_admin_url('wp-ultimo-payments')); wp_redirect(wu_network_admin_url('wp-ultimo-payments'));
exit; exit;
}
} // end if;
$payment = $item; $payment = $item;
return $item; return $item;
}
} // end if; return new Payment();
}
return new Payment;
} // end get_object;
/** /**
* Payments have titles. * Payments have titles.
* *
@ -1292,8 +1300,7 @@ class Payment_Edit_Admin_Page extends Edit_Admin_Page {
public function has_title(): bool { public function has_title(): bool {
return false; return false;
}
} // end has_title;
/** /**
* WIP: Handles saving by recalculating totals for a payment. * 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'); $should_confirm_membership = wu_request('confirm_membership');
if ($should_confirm_membership) { if ($should_confirm_membership) {
$membership = $this->get_object()->get_membership(); $membership = $this->get_object()->get_membership();
if ($membership) { if ($membership) {
$membership->add_to_times_billed(1); $membership->add_to_times_billed(1);
$membership->renew(false, 'active'); $membership->renew(false, 'active');
}
} // end if; }
} // end if;
parent::handle_save(); 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 // Exit if accessed directly
defined('ABSPATH') || exit; defined('ABSPATH') || exit;
use \WP_Ultimo\Database\Payments\Payment_Status; use WP_Ultimo\Database\Payments\Payment_Status;
/** /**
* WP Multisite WaaS Payment Admin Page. * WP Multisite WaaS Payment Admin Page.
@ -66,13 +66,15 @@ class Payment_List_Admin_Page extends List_Admin_Page {
/* /*
* Edit/Add Line Item * 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'), 'render' => array($this, 'render_add_new_payment_modal'),
'handler' => array($this, 'handle_add_new_payment_modal'), 'handler' => array($this, 'handle_add_new_payment_modal'),
'capability' => 'wu_edit_payments', 'capability' => 'wu_edit_payments',
)); )
);
} // end register_forms; }
/** /**
* Renders the add/edit line items form. * 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', 'views' => 'admin-pages/fields',
'classes' => 'wu-modal-form wu-widget-list wu-striped wu-m-0 wu-mt-0', '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', '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( 'html_attr' => array(
'data-wu-app' => 'add_payment', 'data-wu-app' => 'add_payment',
'data-state' => wu_convert_to_state(array( 'data-state' => wu_convert_to_state(
array(
'taxable' => 0, 'taxable' => 0,
'type' => 'product', 'type' => 'product',
)), )
), ),
)); ),
)
);
$form->render(); $form->render();
}
} // end render_add_new_payment_modal;
/** /**
* Handles the add/edit of line items. * 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')); $membership = wu_get_membership(wu_request('membership_id'));
if ( ! $membership) { if ( ! $membership) {
$error = new \WP_Error('invalid-membership', __('Invalid membership.', 'wp-ultimo')); $error = new \WP_Error('invalid-membership', __('Invalid membership.', 'wp-ultimo'));
return wp_send_json_error($error); 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')), 'products' => explode(',', (string) wu_request('products')),
'cart_type' => wu_request('add_setup_fees') ? 'new' : 'renewal', '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'), 'status' => wu_request('status'),
'membership_id' => $membership->get_id(), 'membership_id' => $membership->get_id(),
'customer_id' => $membership->get_customer_id(), 'customer_id' => $membership->get_customer_id(),
)); )
);
$payment = wu_create_payment($payment_data); $payment = wu_create_payment($payment_data);
if (is_wp_error($payment)) { if (is_wp_error($payment)) {
return wp_send_json_error($payment); return wp_send_json_error($payment);
}
} // end if; wp_send_json_success(
array(
wp_send_json_success(array( 'redirect_url' => wu_network_admin_url(
'redirect_url' => wu_network_admin_url('wp-ultimo-edit-payment', array( 'wp-ultimo-edit-payment',
array(
'id' => $payment->get_id(), 'id' => $payment->get_id(),
)) )
)); ),
)
} // end handle_add_new_payment_modal; );
}
/** /**
* Allow child classes to register widgets, if they need them. * 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 * @since 1.8.2
* @return void * @return void
*/ */
public function register_widgets() {} // end register_widgets; public function register_widgets() {}
/** /**
* Returns an array with the labels for the edit page. * 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'), 'deleted_message' => __('Payment removed successfully.', 'wp-ultimo'),
'search_label' => __('Search Payment', 'wp-ultimo'), 'search_label' => __('Search Payment', 'wp-ultimo'),
); );
}
} // end get_labels;
/** /**
* Returns the title of the page. * Returns the title of the page.
@ -231,8 +242,7 @@ class Payment_List_Admin_Page extends List_Admin_Page {
public function get_title() { public function get_title() {
return __('Payments', 'wp-ultimo'); return __('Payments', 'wp-ultimo');
}
} // end get_title;
/** /**
* Returns the title of menu for this page. * 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() { public function get_menu_title() {
return __('Payments', 'wp-ultimo'); return __('Payments', 'wp-ultimo');
}
} // end get_menu_title;
/** /**
* Allows admins to rename the sub-menu (first item) for a top-level page. * 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() { public function get_submenu_title() {
return __('Payments', 'wp-ultimo'); return __('Payments', 'wp-ultimo');
}
} // end get_submenu_title;
/** /**
* Returns the action links for that page. * 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'), 'url' => wu_get_form_url('add_new_payment'),
), ),
); );
}
} // end action_links;
/** /**
* Loads the list table for this particular page. * Loads the list table for this particular page.
@ -286,7 +293,5 @@ class Payment_List_Admin_Page extends List_Admin_Page {
public function table() { public function table() {
return new \WP_Ultimo\List_Tables\Payment_List_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() { public function get_title() {
return __('Edit Template Placeholders', 'wp-ultimo'); return __('Edit Template Placeholders', 'wp-ultimo');
}
} // end get_title;
/** /**
* Returns the title of menu for this page. * 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() { public function get_menu_title() {
return __('Edit Template Placeholders', 'wp-ultimo'); return __('Edit Template Placeholders', 'wp-ultimo');
}
} // end get_menu_title;
/** /**
* Allows admins to rename the sub-menu (first item) for a top-level page. * 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() { public function get_submenu_title() {
return __('Edit Template Placeholders', 'wp-ultimo'); 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. * 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'); 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'), 'placeholder' => __('Placeholder', 'wp-ultimo'),
'content' => __('Content', 'wp-ultimo'), 'content' => __('Content', 'wp-ultimo'),
)); )
);
wu_get_template('sites/edit-placeholders', array( wu_get_template(
'sites/edit-placeholders',
array(
'columns' => $columns, 'columns' => $columns,
'types' => array(), 'types' => array(),
)); )
);
} // end output; }
/** /**
* Adds the cure bg image here as well. * 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_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'), 'name' => __('Tax', 'wp-ultimo'),
'confirm_message' => __('Are you sure you want to delete this rows?', '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'), 'confirm_delete_tax_category_message' => __('Are you sure you want to delete this tax category?', 'wp-ultimo'),
)); )
);
wp_enqueue_script('wu-edit-placeholders'); 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 // Exit if accessed directly
defined('ABSPATH') || exit; defined('ABSPATH') || exit;
use \WP_Ultimo\Models\Product; use WP_Ultimo\Models\Product;
use \WP_Ultimo\Database\Products\Product_Type; use WP_Ultimo\Database\Products\Product_Type;
/** /**
* WP Multisite WaaS Product Edit/Add New Admin Page. * 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_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')); add_filter("wu_page_{$this->id}_load", array($this, 'add_new_product_warning_message'));
}
} // end register_forms;
/** /**
* Adds the new product warning. * 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() { public function add_new_product_warning_message() {
if (wu_request('wu-new-model')) { if (wu_request('wu-new-model')) {
if ( ! $this->get_object() || $this->get_object()->get_type() !== Product_Type::PLAN) { if ( ! $this->get_object() || $this->get_object()->get_type() !== Product_Type::PLAN) {
return; return;
}
} // end if; \WP_Ultimo\UI\Tours::get_instance()->create_tour(
'new_product_warning',
\WP_Ultimo\UI\Tours::get_instance()->create_tour('new_product_warning', array( array(
array( array(
'id' => 'new-product-warning', 'id' => 'new-product-warning',
'title' => __('On adding a new product...', 'wp-ultimo'), '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', 'classes' => 'button wu-text-xs sm:wu-normal-case wu-float-left',
'text' => __('Go to Checkout Forms', 'wp-ultimo'), 'text' => __('Go to Checkout Forms', 'wp-ultimo'),
'url' => wu_network_admin_url('wp-ultimo-checkout-forms'), 'url' => wu_network_admin_url('wp-ultimo-checkout-forms'),
) ),
), ),
'attachTo' => array( 'attachTo' => array(
'element' => '#message.updated', 'element' => '#message.updated',
'on' => 'top', 'on' => 'top',
), ),
), ),
)); )
);
} // end if; }
}
} // end add_new_product_warning_message;
/** /**
* Adds the extra delete fields to the delete form. * 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-label-field' => 'name',
'data-search-field' => 'name', 'data-search-field' => 'name',
'data-max-items' => 1, '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); return array_merge($custom_fields, $fields);
}
} // end product_extra_delete_fields;
/** /**
* Adds the primary domain handling to the product deletion. * 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); $re_assignment_product = wu_get_product($new_product_id);
if ($re_assignment_product) { if ($re_assignment_product) {
$query = $wpdb->prepare( $query = $wpdb->prepare(
"UPDATE {$wpdb->base_prefix}wu_memberships "UPDATE {$wpdb->base_prefix}wu_memberships
SET product_id = %d SET product_id = %d
@ -201,10 +196,8 @@ class Product_Edit_Admin_Page extends Edit_Admin_Page {
); );
$wpdb->query($query); // phpcs:ignore $wpdb->query($query); // phpcs:ignore
}
} // end if; }
} // end product_after_delete_actions;
/** /**
* Registers the necessary scripts and styles for this admin page. * 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(); parent::register_scripts();
wp_enqueue_media(); wp_enqueue_media();
}
} // end register_scripts;
/** /**
* Allow child classes to register widgets, if they need them. * 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(); parent::register_widgets();
$this->add_fields_widget('description', array( $this->add_fields_widget(
'description',
array(
'title' => __('Description', 'wp-ultimo'), 'title' => __('Description', 'wp-ultimo'),
'position' => 'normal', 'position' => 'normal',
'fields' => array( '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'), 'title' => __('Product Options', 'wp-ultimo'),
'position' => 'normal', 'position' => 'normal',
'sections' => $this->get_product_option_sections(), 'sections' => $this->get_product_option_sections(),
)); )
);
/* /*
* Handle legacy options for back-compat. * Handle legacy options for back-compat.
*/ */
$this->handle_legacy_options(); $this->handle_legacy_options();
$this->add_list_table_widget('events', array( $this->add_list_table_widget(
'events',
array(
'title' => __('Events', 'wp-ultimo'), 'title' => __('Events', 'wp-ultimo'),
'table' => new \WP_Ultimo\List_Tables\Inside_Events_List_Table(), 'table' => new \WP_Ultimo\List_Tables\Inside_Events_List_Table(),
'query_filter' => array($this, 'query_filter'), '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( 'html_attr' => array(
'data-wu-app' => 'product_pricing', 'data-wu-app' => 'product_pricing',
'data-state' => json_encode(array( 'data-state' => json_encode(
array(
'is_recurring' => $this->get_object()->is_recurring(), 'is_recurring' => $this->get_object()->is_recurring(),
'pricing_type' => $this->get_object()->get_pricing_type(), 'pricing_type' => $this->get_object()->get_pricing_type(),
'has_trial' => $this->get_object()->get_trial_duration() > 0, '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(), 'amount' => $this->get_object()->get_formatted_amount(),
'duration' => $this->get_object()->get_duration(), 'duration' => $this->get_object()->get_duration(),
'duration_unit' => $this->get_object()->get_duration_unit(), 'duration_unit' => $this->get_object()->get_duration_unit(),
)), )
),
), ),
'fields' => array( 'fields' => array(
// Fields for price // 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_save_widget('save', $save_widget_args);
$this->add_fields_widget('active', array( $this->add_fields_widget(
'active',
array(
'title' => __('Active', 'wp-ultimo'), 'title' => __('Active', 'wp-ultimo'),
'fields' => array( 'fields' => array(
'active' => array( 'active' => array(
@ -510,9 +519,12 @@ class Product_Edit_Admin_Page extends Edit_Admin_Page {
'value' => $this->get_object()->is_active(), 'value' => $this->get_object()->is_active(),
), ),
), ),
)); )
);
$this->add_fields_widget('image', array( $this->add_fields_widget(
'image',
array(
'title' => __('Product Image', 'wp-ultimo'), 'title' => __('Product Image', 'wp-ultimo'),
'fields' => array( 'fields' => array(
'featured_image_id' => 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(), 'img' => $this->get_object()->get_featured_image(),
), ),
), ),
)); )
);
} // end register_widgets; }
/** /**
* Handles legacy advanced options for plans. * Handles legacy advanced options for plans.
@ -538,15 +550,18 @@ class Product_Edit_Admin_Page extends Edit_Admin_Page {
global $wp_filter; global $wp_filter;
$tabs = apply_filters_deprecated('wu_plans_advanced_options_tabs', array( $tabs = apply_filters_deprecated(
'wu_plans_advanced_options_tabs',
array(
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'])) { if ( ! isset($wp_filter['wu_plans_advanced_options_after_panels'])) {
return; return;
}
} // end if;
wp_enqueue_style('wu-legacy-admin-tabs', wu_get_asset('legacy-admin-tabs.css', 'css'), false, wu_get_version()); 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 ($priorities as $priority => $callbacks) {
foreach ($callbacks as $id => $callable) { foreach ($callbacks as $id => $callable) {
$fields[ $id ] = array( $fields[ $id ] = array(
'type' => 'html', 'type' => 'html',
'classes' => 'wu--mt-2', 'classes' => 'wu--mt-2',
'content' => function () use ($callable) { 'content' => function () use ($callable) {
call_user_func($callable['function'], new \WU_Plan($this->get_object())); call_user_func($callable['function'], new \WU_Plan($this->get_object()));
}, },
); );
}
}
} // end foreach; $this->add_fields_widget(
'legacy-options',
} // end foreach; array(
$this->add_fields_widget('legacy-options', array(
'title' => __('Legacy Options', 'wp-ultimo'), 'title' => __('Legacy Options', 'wp-ultimo'),
'position' => 'normal', 'position' => 'normal',
'fields' => $fields, 'fields' => $fields,
@ -588,9 +600,9 @@ class Product_Edit_Admin_Page extends Edit_Admin_Page {
'html_attr' => array( 'html_attr' => array(
'style' => 'margin-top: -5px;', 'style' => 'margin-top: -5px;',
), ),
)); )
);
} // end handle_legacy_options; }
/** /**
* Returns the list of sections and its fields for the product page. * 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-label-field' => 'name',
'data-search-field' => 'name', 'data-search-field' => 'name',
'data-max-items' => 99, '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__in' => $this->get_object()->get_available_addons(),
'id__not_in' => array_keys(wu_get_plans_as_options()), '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', 'type' => 'hidden',
'html_attr' => array( 'html_attr' => array(
'v-bind:value' => 'price_variation.amount', 'v-bind:value' => 'price_variation.amount',
'v-bind:name' => '"price_variations[" + index + "][amount]"' 'v-bind:name' => '"price_variations[" + index + "][amount]"',
), ),
), ),
'_price_variations_amount' => array( '_price_variations_amount' => array(
@ -869,7 +885,7 @@ class Product_Edit_Admin_Page extends Edit_Admin_Page {
'options' => array( 'options' => array(
'default' => __('Default', 'wp-ultimo'), 'default' => __('Default', 'wp-ultimo'),
'assign_template' => __('Assign Site Template', '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( 'html_attr' => array(
'v-model' => 'site_template_selection_mode', '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()); 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. * 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(); $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, 'templates' => $all_templates,
'product' => $product, 'product' => $product,
)); )
);
} // end get_site_template_selection_list; }
/** /**
* Returns the title of the page. * Returns the title of the page.
@ -924,8 +941,7 @@ class Product_Edit_Admin_Page extends Edit_Admin_Page {
public function get_title() { public function get_title() {
return $this->edit ? __('Edit Product', 'wp-ultimo') : __('Add new Product', 'wp-ultimo'); return $this->edit ? __('Edit Product', 'wp-ultimo') : __('Add new Product', 'wp-ultimo');
}
} // end get_title;
/** /**
* Returns the title of menu for this page. * 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() { public function get_menu_title() {
return __('Edit Product', 'wp-ultimo'); return __('Edit Product', 'wp-ultimo');
}
} // end get_menu_title;
/** /**
* Returns the action links for that page. * Returns the action links for that page.
@ -950,7 +965,6 @@ class Product_Edit_Admin_Page extends Edit_Admin_Page {
$actions = array(); $actions = array();
if ($this->get_object()->get_type() === 'plan' && $this->edit) { if ($this->get_object()->get_type() === 'plan' && $this->edit) {
$shareable_link = $this->get_object()->get_shareable_link(); $shareable_link = $this->get_object()->get_shareable_link();
$actions[] = array( $actions[] = array(
@ -960,12 +974,10 @@ class Product_Edit_Admin_Page extends Edit_Admin_Page {
'classes' => 'wu-copy', 'classes' => 'wu-copy',
'attrs' => 'data-clipboard-text="' . esc_attr($shareable_link) . '"', 'attrs' => 'data-clipboard-text="' . esc_attr($shareable_link) . '"',
); );
}
} // end if;
return $actions; return $actions;
}
} // end action_links;
/** /**
* Returns the labels to be used on the admin page. * 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_button_label' => __('Delete Product', 'wp-ultimo'),
'delete_description' => __('Be careful. This action is irreversible.', 'wp-ultimo'), 'delete_description' => __('Be careful. This action is irreversible.', 'wp-ultimo'),
); );
}
} // end get_labels;
/** /**
* Filters the list table to return only relevant events. * 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); return array_merge($args, $extra_args);
}
} // end query_filter;
/** /**
* Returns the object being edit at the moment. * 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() { public function get_object() {
if ($this->object !== null) { if ($this->object !== null) {
return $this->object; return $this->object;
}
} // end if;
if (isset($_GET['id'])) { 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']); $item = $query->get_item_by('id', $_GET['id']);
if ( ! $item) { if ( ! $item) {
wp_redirect(wu_network_admin_url('wp-ultimo-products')); wp_redirect(wu_network_admin_url('wp-ultimo-products'));
exit; exit;
}
} // end if;
$this->object = $item; $this->object = $item;
return $this->object; return $this->object;
}
} // end if; $this->object = new Product();
$this->object = new Product;
return $this->object; return $this->object;
}
} // end get_object;
/** /**
* Products have titles. * Products have titles.
* *
@ -1055,8 +1058,7 @@ class Product_Edit_Admin_Page extends Edit_Admin_Page {
public function has_title(): bool { public function has_title(): bool {
return true; return true;
}
} // end has_title;
/** /**
* Should implement the processes necessary to save the changes made to the object. * 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. * Set the recurring value to zero if the toggle is disabled.
*/ */
if ( ! wu_request('recurring')) { if ( ! wu_request('recurring')) {
$_POST['recurring'] = false; $_POST['recurring'] = false;
}
} // end if;
if ( ! wu_request('legacy_options')) { if ( ! wu_request('legacy_options')) {
$_POST['legacy_options'] = false; $_POST['legacy_options'] = false;
}
} // end if;
if ( ! wu_request('featured_plan')) { if ( ! wu_request('featured_plan')) {
$_POST['featured_plan'] = false; $_POST['featured_plan'] = false;
}
} // end if;
/* /*
* Set the setup fee value to zero if the toggle is disabled. * Set the setup fee value to zero if the toggle is disabled.
*/ */
if ( ! wu_request('has_setup_fee')) { if ( ! wu_request('has_setup_fee')) {
$_POST['setup_fee'] = 0; $_POST['setup_fee'] = 0;
}
} // end if;
/* /*
* Disabled Trial * Disabled Trial
*/ */
if ( ! wu_request('has_trial')) { if ( ! wu_request('has_trial')) {
$_POST['trial_duration'] = 0; $_POST['trial_duration'] = 0;
}
} // end if;
/* /*
* Set the setup fee value to zero if the toggle is disabled. * Set the setup fee value to zero if the toggle is disabled.
*/ */
if ( ! wu_request('price_variations')) { if ( ! wu_request('price_variations')) {
$_POST['price_variations'] = array(); $_POST['price_variations'] = array();
}
} // end if;
/* /*
* Set the taxable value to zero if the toggle is disabled. * Set the taxable value to zero if the toggle is disabled.
*/ */
if ( ! wu_request('taxable')) { if ( ! wu_request('taxable')) {
$_POST['taxable'] = 0; $_POST['taxable'] = 0;
}
} // end if;
parent::handle_save(); 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 * @since 1.8.2
* @return void * @return void
*/ */
public function hooks() {} // end hooks; public function hooks() {}
/** /**
* Returns an array with the labels for the edit page. * 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'), 'deleted_message' => __('Product removed successfully.', 'wp-ultimo'),
'search_label' => __('Search Product', 'wp-ultimo'), 'search_label' => __('Search Product', 'wp-ultimo'),
); );
}
} // end get_labels;
/** /**
* Returns the title of the page. * Returns the title of the page.
@ -86,8 +85,7 @@ class Product_List_Admin_Page extends List_Admin_Page {
public function get_title() { public function get_title() {
return __('Products', 'wp-ultimo'); return __('Products', 'wp-ultimo');
}
} // end get_title;
/** /**
* Returns the title of menu for this page. * 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() { public function get_menu_title() {
return __('Products', 'wp-ultimo'); return __('Products', 'wp-ultimo');
}
} // end get_menu_title;
/** /**
* Allows admins to rename the sub-menu (first item) for a top-level page. * 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() { public function get_submenu_title() {
return __('Products', 'wp-ultimo'); return __('Products', 'wp-ultimo');
}
} // end get_submenu_title;
/** /**
* Returns the action links for that page. * 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', 'icon' => 'wu-circle-with-plus',
), ),
); );
}
} // end action_links;
/** /**
* Loads the list table for this particular page. * Loads the list table for this particular page.
@ -140,7 +135,5 @@ class Product_List_Admin_Page extends List_Admin_Page {
public function table() { public function table() {
return new \WP_Ultimo\List_Tables\Product_List_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; namespace WP_Ultimo\Admin_Pages;
use \WP_Ultimo\Settings; use WP_Ultimo\Settings;
use \WP_Ultimo\UI\Form; use WP_Ultimo\UI\Form;
use \WP_Ultimo\UI\Field; use WP_Ultimo\UI\Field;
// Exit if accessed directly // Exit if accessed directly
defined('ABSPATH') || exit; defined('ABSPATH') || exit;
@ -118,8 +118,7 @@ class Settings_Admin_Page extends Wizard_Admin_Page {
wp_enqueue_script('wu-fields'); wp_enqueue_script('wu-fields');
wp_enqueue_style('wp-color-picker'); wp_enqueue_style('wp-color-picker');
}
} // end register_scripts;
/** /**
* Registers widgets to the edit page. * Registers widgets to the edit page.
@ -135,37 +134,54 @@ class Settings_Admin_Page extends Wizard_Admin_Page {
parent::register_widgets(); 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'), 'title' => __('Checkout Forms', 'wp-ultimo'),
'render' => array($this, 'render_checkout_forms_side_panel'), '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'), 'title' => __('Template Previewer', 'wp-ultimo'),
'render' => array($this, 'render_site_template_side_panel'), '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'), 'title' => __('Placeholder Editor', 'wp-ultimo'),
'render' => array($this, 'render_site_placeholders_side_panel'), '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'), 'title' => __('Invoices', 'wp-ultimo'),
'render' => array($this, 'render_invoice_side_panel'), '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'), 'title' => __('System Emails', 'wp-ultimo'),
'render' => array($this, 'render_system_emails_side_panel'), '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'), 'title' => __('Email Template', 'wp-ultimo'),
'render' => array($this, 'render_email_template_side_panel'), 'render' => array($this, 'render_email_template_side_panel'),
)); )
);
} // end register_widgets; }
/** /**
* Renders the addons side panel * Renders the addons side panel
@ -173,7 +189,8 @@ class Settings_Admin_Page extends Wizard_Admin_Page {
* @since 2.0.0 * @since 2.0.0
* @return void * @return void
*/ */
public function render_checkout_forms_side_panel() { ?> public function render_checkout_forms_side_panel() {
?>
<div class="wu-widget-inset"> <div class="wu-widget-inset">
@ -206,8 +223,7 @@ class Settings_Admin_Page extends Wizard_Admin_Page {
</div> </div>
<?php <?php
}
} // end render_checkout_forms_side_panel;
/** /**
* Renders the site template side panel * Renders the site template side panel
@ -215,7 +231,9 @@ class Settings_Admin_Page extends Wizard_Admin_Page {
* @since 2.0.0 * @since 2.0.0
* @return void * @return void
*/ */
public function render_site_template_side_panel() { ?> public function render_site_template_side_panel() {
?>
<div class="wu-widget-inset"> <div class="wu-widget-inset">
@ -248,8 +266,7 @@ class Settings_Admin_Page extends Wizard_Admin_Page {
</div> </div>
<?php <?php
}
} // end render_site_template_side_panel;
/** /**
* Renders the site placeholder side panel * Renders the site placeholder side panel
@ -257,7 +274,9 @@ class Settings_Admin_Page extends Wizard_Admin_Page {
* @since 2.0.0 * @since 2.0.0
* @return void * @return void
*/ */
public function render_site_placeholders_side_panel() { ?> public function render_site_placeholders_side_panel() {
?>
<div class="wu-widget-inset"> <div class="wu-widget-inset">
@ -290,8 +309,7 @@ class Settings_Admin_Page extends Wizard_Admin_Page {
</div> </div>
<?php <?php
}
} // end render_site_placeholders_side_panel;
/** /**
* Renders the invoice side panel * Renders the invoice side panel
@ -299,7 +317,9 @@ class Settings_Admin_Page extends Wizard_Admin_Page {
* @since 2.0.0 * @since 2.0.0
* @return void * @return void
*/ */
public function render_invoice_side_panel() { ?> public function render_invoice_side_panel() {
?>
<div class="wu-widget-inset"> <div class="wu-widget-inset">
@ -332,8 +352,7 @@ class Settings_Admin_Page extends Wizard_Admin_Page {
</div> </div>
<?php <?php
}
} // end render_invoice_side_panel;
/** /**
* Renders system emails side panel. * Renders system emails side panel.
@ -341,7 +360,9 @@ class Settings_Admin_Page extends Wizard_Admin_Page {
* @since 2.0.0 * @since 2.0.0
* @return void * @return void
*/ */
public function render_system_emails_side_panel() { ?> public function render_system_emails_side_panel() {
?>
<div class="wu-widget-inset"> <div class="wu-widget-inset">
@ -374,8 +395,7 @@ class Settings_Admin_Page extends Wizard_Admin_Page {
</div> </div>
<?php <?php
}
} // end render_system_emails_side_panel;
/** /**
* Renders the email template side panel. * Renders the email template side panel.
@ -383,7 +403,9 @@ class Settings_Admin_Page extends Wizard_Admin_Page {
* @since 2.0.0 * @since 2.0.0
* @return void * @return void
*/ */
public function render_email_template_side_panel() { ?> public function render_email_template_side_panel() {
?>
<div class="wu-widget-inset"> <div class="wu-widget-inset">
@ -416,8 +438,7 @@ class Settings_Admin_Page extends Wizard_Admin_Page {
</div> </div>
<?php <?php
}
} // end render_email_template_side_panel;
// phpcs:enable // phpcs:enable
@ -430,8 +451,7 @@ class Settings_Admin_Page extends Wizard_Admin_Page {
public function get_title() { public function get_title() {
return __('Settings', 'wp-ultimo'); return __('Settings', 'wp-ultimo');
}
} // end get_title;
/** /**
* Returns the title of menu for this page. * 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() { public function get_menu_title() {
return __('Settings', 'wp-ultimo'); return __('Settings', 'wp-ultimo');
}
} // end get_menu_title;
/** /**
* Every child class should implement the output method to display the contents of the page. * 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'); do_action('wu_render_settings');
wu_get_template('base/settings', array( wu_get_template(
'base/settings',
array(
'screen' => get_current_screen(), 'screen' => get_current_screen(),
'page' => $this, 'page' => $this,
'classes' => '', 'classes' => '',
'sections' => $this->get_sections(), 'sections' => $this->get_sections(),
'current_section' => $this->get_current_section(), 'current_section' => $this->get_current_section(),
'clickable_navigation' => $this->clickable_navigation, 'clickable_navigation' => $this->clickable_navigation,
)); )
);
} // end output; }
/** /**
* Returns the list of settings sections. * Returns the list of settings sections.
@ -485,8 +506,7 @@ class Settings_Admin_Page extends Wizard_Admin_Page {
public function get_sections() { public function get_sections() {
return WP_Ultimo()->settings->get_sections(); return WP_Ultimo()->settings->get_sections();
}
} // end get_sections;
/** /**
* Default handler for step submission. Simply redirects to the next step. * 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() { public function default_handler() {
if ( ! current_user_can('wu_edit_settings')) { if ( ! current_user_can('wu_edit_settings')) {
wp_die(__('You do not have the permissions required to change settings.', 'wp-ultimo')); 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') { if ( ! isset($_POST['active_gateways']) && wu_request('tab') === 'payment-gateways') {
$_POST['active_gateways'] = array(); $_POST['active_gateways'] = array();
}
} // end if;
WP_Ultimo()->settings->save_settings($_POST); WP_Ultimo()->settings->save_settings($_POST);
wp_redirect(add_query_arg('updated', 1, wu_get_current_url())); wp_redirect(add_query_arg('updated', 1, wu_get_current_url()));
exit; exit;
}
} // end default_handler;
/** /**
* Default method for views. * 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', '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', 'wrapper_classes' => 'wu-sticky wu-bottom-0 wu-save-button wu-mr-px wu-w-full md:wu-w-auto',
'html_attr' => array( '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')) { if ( ! current_user_can('wu_edit_settings')) {
$fields['save']['html_attr']['disabled'] = 'disabled'; $fields['save']['html_attr']['disabled'] = 'disabled';
}
} // end if; $form = new Form(
$section_slug,
$form = new Form($section_slug, $fields, array( $fields,
array(
'views' => 'admin-pages/fields', 'views' => 'admin-pages/fields',
'classes' => 'wu-modal-form wu-widget-list wu-striped wu--mt-5 wu--mx-in wu--mb-in', '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', '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-wu-app' => str_replace('-', '_', $section_slug),
'data-state' => json_encode(wu_array_map_keys('wu_replace_dashes', Settings::get_instance()->get_all(true))), 'data-state' => json_encode(wu_array_map_keys('wu_replace_dashes', Settings::get_instance()->get_all(true))),
), ),
)); )
);
$form->render(); $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 // Exit if accessed directly
defined('ABSPATH') || exit; defined('ABSPATH') || exit;
use \WP_Ultimo\Installers\Migrator; use WP_Ultimo\Installers\Migrator;
use \WP_Ultimo\Installers\Core_Installer; use WP_Ultimo\Installers\Core_Installer;
use \WP_Ultimo\Installers\Default_Content_Installer; use WP_Ultimo\Installers\Default_Content_Installer;
use \WP_Ultimo\Logger; use WP_Ultimo\Logger;
/** /**
* WP Multisite WaaS Dashboard Admin Page. * WP Multisite WaaS Dashboard Admin Page.
@ -104,7 +104,6 @@ class Setup_Wizard_Admin_Page extends Wizard_Admin_Page {
public function __construct() { public function __construct() {
if ( ! $this->is_core_loaded()) { if ( ! $this->is_core_loaded()) {
require_once wu_path('inc/functions/documentation.php'); 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'; $this->menu_icon = 'dashicons-wu-wp-ultimo';
add_action('admin_enqueue_scripts', array($this, 'register_scripts')); add_action('admin_enqueue_scripts', array($this, 'register_scripts'));
}
} // end if;
parent::__construct(); parent::__construct();
@ -144,8 +142,7 @@ class Setup_Wizard_Admin_Page extends Wizard_Admin_Page {
* Redirect on activation * Redirect on activation
*/ */
add_action('wu_activation', array($this, 'redirect_to_wizard')); add_action('wu_activation', array($this, 'redirect_to_wizard'));
}
} // end __construct;
/** /**
* Download the migration logs. * Download the migration logs.
@ -172,8 +169,7 @@ class Setup_Wizard_Admin_Page extends Wizard_Admin_Page {
readfile($file); readfile($file);
exit; exit;
}
} // end download_migration_logs;
/** /**
* Loads the extra elements we need on the wizard itself. * 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(); parent::page_loaded();
$this->set_settings(); $this->set_settings();
}
} // end page_loaded;
/** /**
* Checks if this is a migration or not. * 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() { public function is_migration() {
if ($this->is_migration === null) { if ($this->is_migration === null) {
$this->is_migration = Migrator::is_legacy_network(); $this->is_migration = Migrator::is_legacy_network();
}
} // end if;
return $this->is_migration; return $this->is_migration;
}
} // end is_migration;
/** /**
* Adds missing setup from settings when WP Multisite WaaS is not fully loaded. * 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() { public function set_settings() {
WP_Ultimo()->settings->default_sections(); WP_Ultimo()->settings->default_sections();
}
} // end set_settings;
/** /**
* Redirects to the wizard, if we need to. * 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() { public function redirect_to_wizard() {
if ( ! \WP_Ultimo\Requirements::run_setup() && wu_request('page') !== 'wp-ultimo-setup') { if ( ! \WP_Ultimo\Requirements::run_setup() && wu_request('page') !== 'wp-ultimo-setup') {
wp_redirect(wu_network_admin_url('wp-ultimo-setup')); wp_redirect(wu_network_admin_url('wp-ultimo-setup'));
exit; exit;
}
} // end if; }
} // end redirect_to_wizard;
/** /**
* Handles the ajax actions for installers and migrators. * Handles the ajax actions for installers and migrators.
@ -248,12 +236,10 @@ class Setup_Wizard_Admin_Page extends Wizard_Admin_Page {
global $wpdb; global $wpdb;
if ( ! current_user_can('manage_network')) { if ( ! current_user_can('manage_network')) {
wp_send_json_error(new \WP_Error('not-allowed', __('Permission denied.', 'wp-ultimo'))); wp_send_json_error(new \WP_Error('not-allowed', __('Permission denied.', 'wp-ultimo')));
exit; exit;
}
} // end if;
/* /*
* Load tables. * 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); $status = apply_filters('wu_handle_ajax_installers', true, $installer, $this);
if (is_wp_error($status)) { if (is_wp_error($status)) {
wp_send_json_error($status); wp_send_json_error($status);
}
} // end if;
wp_send_json_success(); wp_send_json_success();
}
} // end setup_install;
/** /**
* Check if the core was loaded. * Check if the core was loaded.
@ -286,8 +269,7 @@ class Setup_Wizard_Admin_Page extends Wizard_Admin_Page {
public function is_core_loaded() { public function is_core_loaded() {
return \WP_Ultimo\Requirements::met() && \WP_Ultimo\Requirements::run_setup(); return \WP_Ultimo\Requirements::met() && \WP_Ultimo\Requirements::run_setup();
}
} // end is_core_loaded;
/** /**
* Returns the logo for the wizard. * Returns the logo for the wizard.
@ -298,8 +280,7 @@ class Setup_Wizard_Admin_Page extends Wizard_Admin_Page {
public function get_logo() { public function get_logo() {
return wu_get_asset('logo.png', 'img'); return wu_get_asset('logo.png', 'img');
}
} // end get_logo;
/** /**
* Returns the title of the page. * Returns the title of the page.
@ -310,8 +291,7 @@ class Setup_Wizard_Admin_Page extends Wizard_Admin_Page {
public function get_title(): string { public function get_title(): string {
return sprintf(__('Installation', 'wp-ultimo')); return sprintf(__('Installation', 'wp-ultimo'));
}
} // end get_title;
/** /**
* Returns the title of menu for this page. * 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() { public function get_menu_title() {
return WP_Ultimo()->is_loaded() ? __('WP Multisite WaaS Install', 'wp-ultimo') : __('WP Multisite WaaS', 'wp-ultimo'); 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. * Returns the sections for this Wizard.
@ -336,11 +315,14 @@ class Setup_Wizard_Admin_Page extends Wizard_Admin_Page {
$sections = array( $sections = array(
'welcome' => array( 'welcome' => array(
'title' => __('Welcome', 'wp-ultimo'), 'title' => __('Welcome', 'wp-ultimo'),
'description' => implode('<br><br>', array( 'description' => implode(
'<br><br>',
array(
__('...and thanks for choosing WP Multisite WaaS!', 'wp-ultimo'), __('...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'), __('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'), 'next_label' => __('Get Started &rarr;', 'wp-ultimo'),
'back' => false, 'back' => false,
), ),
@ -354,7 +336,7 @@ class Setup_Wizard_Admin_Page extends Wizard_Admin_Page {
'requirements' => array( 'requirements' => array(
'type' => 'note', 'type' => 'note',
'desc' => array($this, 'renders_requirements_table'), 'desc' => array($this, 'renders_requirements_table'),
) ),
), ),
), ),
'installation' => array( 'installation' => array(
@ -374,7 +356,6 @@ class Setup_Wizard_Admin_Page extends Wizard_Admin_Page {
* In case of migrations, add different sections. * In case of migrations, add different sections.
*/ */
if ($this->is_migration()) { if ($this->is_migration()) {
$dry_run = wu_request('dry-run', true); $dry_run = wu_request('dry-run', true);
$next = 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'); $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) { if ($dry_run) {
$next_label = __('Run Check', 'wp-ultimo'); $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'); $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( $fields = array(
'migration' => array( 'migration' => array(
@ -403,7 +382,6 @@ class Setup_Wizard_Admin_Page extends Wizard_Admin_Page {
); );
if ($errors) { if ($errors) {
$subject = 'Errors on migrating my network'; $subject = 'Errors on migrating my network';
$user = wp_get_current_user(); $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:', '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, implode(PHP_EOL, $errors), PHP_EOL),
sprintf('```%s%s%s```', PHP_EOL, $back_traces ? implode(PHP_EOL, $back_traces) : 'No backtraces found.', 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); $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>'; $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', 'action' => 'download_migration_logs',
'nonce' => wp_create_nonce('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', 'page' => 'wp-ultimo-rollback',
'version' => '1.10.13', 'version' => '1.10.13',
'type' => 'select-version', 'type' => 'select-version',
), network_admin_url('admin.php'))); ),
network_admin_url('admin.php')
)
);
$error_list .= implode('<br>', $errors); $error_list .= implode('<br>', $errors);
$fields = array_merge(array( $fields = array_merge(
array(
'errors' => array( 'errors' => array(
'type' => 'note', 'type' => 'note',
'classes' => 'wu-flex-grow', 'classes' => 'wu-flex-grow',
@ -451,12 +444,12 @@ class Setup_Wizard_Admin_Page extends Wizard_Admin_Page {
Migrator::get_instance()->session->set('errors', array()); 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); 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); ),
$fields
} // end if; );
}
$sections['migration'] = array( $sections['migration'] = array(
'title' => __('Migration', 'wp-ultimo'), 'title' => __('Migration', 'wp-ultimo'),
@ -467,9 +460,7 @@ class Setup_Wizard_Admin_Page extends Wizard_Admin_Page {
'handler' => array($this, 'handle_migration'), 'handler' => array($this, 'handle_migration'),
'fields' => $fields, 'fields' => $fields,
); );
} else { } else {
$sections['your-company'] = array( $sections['your-company'] = array(
'title' => __('Your Company', 'wp-ultimo'), 'title' => __('Your Company', 'wp-ultimo'),
'description' => __('Before we move on, let\'s configure the basic settings of your network, shall we?', '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( $sections['done'] = array(
'title' => __('Ready!', 'wp-ultimo'), 'title' => __('Ready!', 'wp-ultimo'),
@ -507,8 +497,7 @@ class Setup_Wizard_Admin_Page extends Wizard_Admin_Page {
* @return array * @return array
*/ */
return apply_filters('wu_setup_wizard', $sections, $this->is_migration(), $this); return apply_filters('wu_setup_wizard', $sections, $this->is_migration(), $this);
}
} // end get_sections;
/** /**
* Returns the general settings to add to the wizard. * 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) { foreach ($fields_to_unset as $field_to_unset) {
unset($general_fields[ $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 // Adds a fake first field to bypass some styling issues with the top-border
$fake_field = array( $fake_field = array(
@ -548,8 +535,7 @@ class Setup_Wizard_Admin_Page extends Wizard_Admin_Page {
$fields = array_merge($fake_field, $general_fields); $fields = array_merge($fake_field, $general_fields);
return apply_filters('wu_setup_get_general_settings', $fields); return apply_filters('wu_setup_get_general_settings', $fields);
}
} // end get_general_settings;
/** /**
* Returns the payment settings to add to the setup wizard. * 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) { foreach ($fields_to_unset as $field_to_unset) {
unset($payment_fields[ $field_to_unset ]); unset($payment_fields[ $field_to_unset ]);
}
} // end foreach;
$fields = array_merge($payment_fields); $fields = array_merge($payment_fields);
return apply_filters('wu_setup_get_payment_settings', $fields); return apply_filters('wu_setup_get_payment_settings', $fields);
}
} // end get_payment_settings;
/** /**
* Render the installation steps table. * 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', $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), 'dry_run' => wu_request('dry-run', true),
'generic_error_message' => __('A server error happened while processing this item.', 'wp-ultimo'), 'generic_error_message' => __('A server error happened while processing this item.', 'wp-ultimo'),
)); )
);
wp_enqueue_script('wu-setup-wizard'); 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, 'page' => $this,
'steps' => $steps, 'steps' => $steps,
'checks' => $checks, 'checks' => $checks,
)); )
);
} // end render_installation_steps; }
/** /**
* Renders the terms of support. * Renders the terms of support.
@ -616,8 +605,7 @@ class Setup_Wizard_Admin_Page extends Wizard_Admin_Page {
public function _terms_of_support() { public function _terms_of_support() {
return wu_get_template_contents('wizards/setup/support_terms'); return wu_get_template_contents('wizards/setup/support_terms');
}
} // end _terms_of_support;
/** /**
* Renders the requirements tables. * 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, 'recommended_version' => \WP_Ultimo\Requirements::$php_recommended_version,
'installed_version' => phpversion(), 'installed_version' => phpversion(),
'pass_requirements' => version_compare(phpversion(), \WP_Ultimo\Requirements::$php_version, '>='), '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( 'wordpress' => array(
'name' => __('WordPress', 'wp-ultimo'), '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, 'recommended_version' => \WP_Ultimo\Requirements::$wp_recommended_version,
'installed_version' => $wp_version, 'installed_version' => $wp_version,
'pass_requirements' => version_compare(phpversion(), \WP_Ultimo\Requirements::$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, 'requirements' => $requirements,
'plugin_requirements' => $plugin_requirements, 'plugin_requirements' => $plugin_requirements,
)); )
);
} // end renders_requirements_table; }
/** /**
* Displays the content of the final section. * Displays the content of the final section.
@ -694,21 +684,25 @@ class Setup_Wizard_Admin_Page extends Wizard_Admin_Page {
* @since 2.0.7 * @since 2.0.7
*/ */
if (Migrator::is_legacy_network()) { if (Migrator::is_legacy_network()) {
update_network_option(null, 'wu_is_migration_done', true); update_network_option(null, 'wu_is_migration_done', true);
}
} // end if; wu_enqueue_async_action(
'wu_async_take_screenshot',
wu_enqueue_async_action('wu_async_take_screenshot', array( array(
'site_id' => wu_get_main_site_id(), '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(), 'screen' => get_current_screen(),
'page' => $this, 'page' => $this,
)); )
);
} // end section_ready; }
/** /**
* Handles the requirements check. * Handles the requirements check.
@ -719,18 +713,15 @@ class Setup_Wizard_Admin_Page extends Wizard_Admin_Page {
public function handle_checks() { public function handle_checks() {
if (\WP_Ultimo\Requirements::met() === false) { if (\WP_Ultimo\Requirements::met() === false) {
wp_redirect(add_query_arg()); wp_redirect(add_query_arg());
exit; exit;
}
} // end if;
wp_redirect($this->get_next_section_link()); wp_redirect($this->get_next_section_link());
exit; exit;
}
} // end handle_checks;
/** /**
* Handles the saving of setting steps. * Handles the saving of setting steps.
@ -745,18 +736,12 @@ class Setup_Wizard_Admin_Page extends Wizard_Admin_Page {
$step = wu_request('step'); $step = wu_request('step');
if ($step === 'your-company') { if ($step === 'your-company') {
$fields_to_save = $this->get_general_settings(); $fields_to_save = $this->get_general_settings();
} elseif ($step === 'payment-gateways') { } elseif ($step === 'payment-gateways') {
$fields_to_save = $this->get_payment_settings(); $fields_to_save = $this->get_payment_settings();
} else { } else {
return; return;
}
} // end if;
$settings_to_save = array_intersect_key($_POST, $fields_to_save); $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()); wp_redirect($this->get_next_section_link());
exit; exit;
}
} // end handle_save_settings;
/** /**
* Handles the migration step and checks for a test run. * 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(); $errors = Migrator::get_instance()->get_errors();
if ($dry_run) { if ($dry_run) {
$url = add_query_arg('dry-run', empty($errors) ? 0 : 1); $url = add_query_arg('dry-run', empty($errors) ? 0 : 1);
} elseif (empty($errors)) {
} else {
if (empty($errors)) {
$url = remove_query_arg('dry-run', $this->get_next_section_link()); $url = remove_query_arg('dry-run', $this->get_next_section_link());
} else { } else {
$url = add_query_arg('dry-run', 0); $url = add_query_arg('dry-run', 0);
}
} // end if;
} // end if;
wp_redirect($url); wp_redirect($url);
exit; exit;
}
} // end handle_migration;
/** /**
* Handles the configuration of a given integration. * Handles the configuration of a given integration.
@ -813,7 +786,6 @@ class Setup_Wizard_Admin_Page extends Wizard_Admin_Page {
public function handle_configuration() { public function handle_configuration() {
if ($_POST['submit'] === '1') { if ($_POST['submit'] === '1') {
$this->integration->setup_constants($_POST); $this->integration->setup_constants($_POST);
$redirect_url = $this->get_next_section_link(); $redirect_url = $this->get_next_section_link();
@ -821,10 +793,8 @@ class Setup_Wizard_Admin_Page extends Wizard_Admin_Page {
wp_redirect($redirect_url); wp_redirect($redirect_url);
exit; exit;
}
} // end if; }
} // end handle_configuration;
/** /**
* Handles the testing of a given 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'); 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(), 'screen' => get_current_screen(),
'page' => $this, 'page' => $this,
'integration' => $this->integration, 'integration' => $this->integration,
)); )
);
} // end section_test; }
/** /**
* Adds the necessary missing scripts if WP Multisite WaaS was not loaded. * 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() { public function register_scripts() {
if (WP_Ultimo()->is_loaded() === false) { 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-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()); 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 * Localize components
*/ */
wp_localize_script('wu-fields', 'wu_fields', array( wp_localize_script(
'wu-fields',
'wu_fields',
array(
'l10n' => array( 'l10n' => array(
'image_picker_title' => __('Select an Image.', 'wp-ultimo'), 'image_picker_title' => __('Select an Image.', 'wp-ultimo'),
'image_picker_button_text' => __('Use this 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('wu-functions', wu_get_asset('functions.js', 'js'), array('jquery'));
wp_register_script('wubox', wu_get_asset('wubox.js', 'js'), array('wu-functions')); 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;'), 'next' => __('Next &gt;'),
'prev' => __('&lt; Prev'), 'prev' => __('&lt; Prev'),
'image' => __('Image'), 'image' => __('Image'),
@ -893,11 +871,11 @@ class Setup_Wizard_Admin_Page extends Wizard_Admin_Page {
'close' => __('Close'), 'close' => __('Close'),
'noiframes' => __('This feature requires inline frames. You have iframes disabled or your browser does not support them.'), 'noiframes' => __('This feature requires inline frames. You have iframes disabled or your browser does not support them.'),
'loadingAnimation' => includes_url('js/thickbox/loadingAnimation.gif'), 'loadingAnimation' => includes_url('js/thickbox/loadingAnimation.gif'),
)); )
);
wp_add_inline_script('wu-setup-wizard-polyfill', 'document.addEventListener("DOMContentLoaded", () => wu_initialize_imagepicker());', 'after'); 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()); 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_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 { body.wu-page-wp-ultimo-setup #wpwrap {
background: url("%s") right bottom no-repeat; background: url("%s") right bottom no-repeat;
background-size: 90%%; background-size: 90%%;
}', wu_get_asset('bg-setup.png', 'img'))); }',
wu_get_asset('bg-setup.png', 'img')
} // end register_scripts; )
);
} // end class Setup_Wizard_Admin_Page; }
}

View File

@ -81,8 +81,7 @@ class Shortcodes_Admin_Page extends Base_Admin_Page {
public function init() { public function init() {
parent::init(); parent::init();
}
} // end init;
/** /**
* Returns the title of the page. * Returns the title of the page.
@ -93,8 +92,7 @@ class Shortcodes_Admin_Page extends Base_Admin_Page {
public function get_title() { public function get_title() {
return __('Available Shortcodes', 'wp-ultimo'); return __('Available Shortcodes', 'wp-ultimo');
}
} // end get_title;
/** /**
* Returns the title of menu for this page. * 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() { public function get_menu_title() {
return __('Available Shortcodes', 'wp-ultimo'); return __('Available Shortcodes', 'wp-ultimo');
}
} // end get_menu_title;
/** /**
* Allows admins to rename the sub-menu (first item) for a top-level page. * 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() { public function get_submenu_title() {
return __('Dashboard', 'wp-ultimo'); return __('Dashboard', 'wp-ultimo');
}
} // end get_submenu_title;
/** /**
* Every child class should implement the output method to display the contents of the page. * 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(); $screen = get_current_screen();
wu_get_template('shortcodes/shortcodes', array( wu_get_template(
'shortcodes/shortcodes',
array(
'screen' => $screen, 'screen' => $screen,
'data' => $this->get_data(), 'data' => $this->get_data(),
)); )
);
} // end output; }
/** /**
* Get data for shortcodes * Get data for shortcodes
@ -150,13 +148,11 @@ class Shortcodes_Admin_Page extends Base_Admin_Page {
$data = array(); $data = array();
foreach ($elements as $element) { foreach ($elements as $element) {
$defaults = $element->defaults(); $defaults = $element->defaults();
$params = array_filter($element->fields(), fn($el) => $el['type'] !== 'note' && $el['type'] !== 'header'); $params = array_filter($element->fields(), fn($el) => $el['type'] !== 'note' && $el['type'] !== 'header');
foreach ($params as $key => $value) { foreach ($params as $key => $value) {
$params[ $key ]['default'] = wu_get_isset($defaults, $key, ''); $params[ $key ]['default'] = wu_get_isset($defaults, $key, '');
$params[ $key ]['desc'] = ! isset($value['desc']) ? '' : $params[ $key ]['desc']; $params[ $key ]['desc'] = ! isset($value['desc']) ? '' : $params[ $key ]['desc'];
@ -183,17 +179,14 @@ class Shortcodes_Admin_Page extends Base_Admin_Page {
default: default:
$params[ $key ]['options'] = $value['type']; $params[ $key ]['options'] = $value['type'];
break; break;
} // end switch; }
}
} // end foreach;
$id = $element->get_id(); $id = $element->get_id();
if (strncmp((string) $id, 'wp-ultimo/', strlen('wp-ultimo/')) === 0) { if (strncmp((string) $id, 'wp-ultimo/', strlen('wp-ultimo/')) === 0) {
$id = substr((string) $element->get_id(), strlen('wp-ultimo/')); $id = substr((string) $element->get_id(), strlen('wp-ultimo/'));
}
} // end if;
$data[] = array( $data[] = array(
'generator_form_url' => wu_get_form_url("shortcode_{$id}"), '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(), 'description' => $element->get_description(),
'params' => $params, 'params' => $params,
); );
}
} // end foreach;
return $data; 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 // Exit if accessed directly
defined('ABSPATH') || exit; defined('ABSPATH') || exit;
use \WP_Ultimo\Database\Sites\Site_Type; use WP_Ultimo\Database\Sites\Site_Type;
use \WP_Ultimo\Models\Site; use WP_Ultimo\Models\Site;
/** /**
* WP Multisite WaaS Site Edit New Admin Page. * 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_media();
wp_enqueue_editor(); wp_enqueue_editor();
}
} // end register_scripts;
/** /**
* Register ajax forms that we use for site. * 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 * Transfer site - Confirmation modal
*/ */
wu_register_form('transfer_site', array( wu_register_form(
'transfer_site',
array(
'render' => array($this, 'render_transfer_site_modal'), 'render' => array($this, 'render_transfer_site_modal'),
'handler' => array($this, 'handle_transfer_site_modal'), 'handler' => array($this, 'handle_transfer_site_modal'),
'capability' => 'wu_transfer_sites', 'capability' => 'wu_transfer_sites',
)); )
);
/* /*
* Delete Site - Confirmation modal * Delete Site - Confirmation modal
*/ */
add_filter('wu_data_json_success_delete_site_modal', fn($data_json) => array( add_filter(
'redirect_url' => wu_network_admin_url('wp-ultimo-sites', array('deleted' => 1)) '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')); add_filter("wu_page_{$this->id}_load", array($this, 'add_new_site_template_warning_message'));
}
} // end register_forms;
/** /**
* Adds the new site_template warning. * 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() { public function add_new_site_template_warning_message() {
if (wu_request('wu-new-model')) { if (wu_request('wu-new-model')) {
if ( ! $this->get_object() || $this->get_object()->get_type() !== Site_Type::SITE_TEMPLATE) { if ( ! $this->get_object() || $this->get_object()->get_type() !== Site_Type::SITE_TEMPLATE) {
return; return;
}
} // end if; \WP_Ultimo\UI\Tours::get_instance()->create_tour(
'new_site_template_warning',
\WP_Ultimo\UI\Tours::get_instance()->create_tour('new_site_template_warning', array( array(
array( array(
'id' => 'new-site-template-warning', 'id' => 'new-site-template-warning',
'title' => __('On adding a new Site Template...', 'wp-ultimo'), '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', 'classes' => 'button wu-text-xs sm:wu-normal-case wu-float-left',
'text' => __('Go to Checkout Forms', 'wp-ultimo'), 'text' => __('Go to Checkout Forms', 'wp-ultimo'),
'url' => wu_network_admin_url('wp-ultimo-checkout-forms'), 'url' => wu_network_admin_url('wp-ultimo-checkout-forms'),
) ),
), ),
'attachTo' => array( 'attachTo' => array(
'element' => '#message.updated', 'element' => '#message.updated',
'on' => 'top', 'on' => 'top',
), ),
), ),
)); )
);
} // end if; }
}
} // end add_new_site_template_warning_message;
/** /**
* Renders the transfer confirmation form. * 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')); $site = wu_get_site(wu_request('id'));
if ( ! $site) { if ( ! $site) {
return; return;
}
} // end if;
$fields = array( $fields = array(
'confirm' => 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', 'views' => 'admin-pages/fields',
'classes' => 'wu-modal-form wu-widget-list wu-striped wu-m-0 wu-mt-0', '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', '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( 'html_attr' => array(
'data-wu-app' => 'transfer_site', 'data-wu-app' => 'transfer_site',
'data-state' => json_encode(array( 'data-state' => json_encode(
array(
'confirmed' => false, 'confirmed' => false,
)), )
), ),
)); ),
)
);
$form->render(); $form->render();
}
} // end render_transfer_site_modal;
/** /**
* Handles the transfer of site. * 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')); $target_membership = wu_get_membership(wu_request('target_membership_id'));
if ( ! $site) { if ( ! $site) {
wp_send_json_error(new \WP_Error('not-found', __('Site not found.', 'wp-ultimo'))); wp_send_json_error(new \WP_Error('not-found', __('Site not found.', 'wp-ultimo')));
}
} // end if;
if ( ! $target_membership) { if ( ! $target_membership) {
wp_send_json_error(new \WP_Error('not-found', __('Membership not found.', 'wp-ultimo'))); wp_send_json_error(new \WP_Error('not-found', __('Membership not found.', 'wp-ultimo')));
}
} // end if;
$site->set_membership_id($target_membership->get_id()); $site->set_membership_id($target_membership->get_id());
@ -269,19 +270,21 @@ class Site_Edit_Admin_Page extends Edit_Admin_Page {
$saved = $site->save(); $saved = $site->save();
if (is_wp_error($saved)) { if (is_wp_error($saved)) {
wp_send_json_error($saved); wp_send_json_error($saved);
}
} // end if; wp_send_json_success(
array(
wp_send_json_success(array( 'redirect_url' => wu_network_admin_url(
'redirect_url' => wu_network_admin_url('wp-ultimo-edit-site', array( 'wp-ultimo-edit-site',
array(
'id' => $site->get_id(), 'id' => $site->get_id(),
'updated' => 1, 'updated' => 1,
)) )
)); ),
)
} // end handle_transfer_site_modal; );
}
/** /**
* Allow child classes to register widgets, if they need them. * 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>"; $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'), 'title' => __('At a Glance', 'wp-ultimo'),
'position' => 'normal', 'position' => 'normal',
'classes' => 'wu-overflow-hidden wu-m-0 wu--mt-1 wu--mx-3 wu--mb-3', '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' => '', 'tooltip' => '',
), ),
), ),
)); )
);
$this->add_fields_widget('description', array( $this->add_fields_widget(
'description',
array(
'title' => __('Description', 'wp-ultimo'), 'title' => __('Description', 'wp-ultimo'),
'position' => 'normal', 'position' => 'normal',
'fields' => array( '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'), 'title' => __('Site Options', 'wp-ultimo'),
'position' => 'normal', 'position' => 'normal',
'sections' => $this->get_site_option_sections(), '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'), 'title' => __('Mapped Domains', 'wp-ultimo'),
'table' => new \WP_Ultimo\List_Tables\Sites_Domain_List_Table(), 'table' => new \WP_Ultimo\List_Tables\Sites_Domain_List_Table(),
'query_filter' => array($this, 'domain_query_filter'), 'query_filter' => array($this, 'domain_query_filter'),
)); )
);
if ($this->get_object()->get_type() === 'customer_owned') { if ($this->get_object()->get_type() === 'customer_owned') {
$this->add_list_table_widget(
$this->add_list_table_widget('membership', array( 'membership',
array(
'title' => __('Linked Membership', 'wp-ultimo'), 'title' => __('Linked Membership', 'wp-ultimo'),
'table' => new \WP_Ultimo\List_Tables\Customers_Membership_List_Table(), 'table' => new \WP_Ultimo\List_Tables\Customers_Membership_List_Table(),
'query_filter' => function ($query) { '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(); $query['id'] = $this->get_object()->get_membership_id();
return $query; return $query;
}, },
)); )
);
$this->add_list_table_widget('customer', array( $this->add_list_table_widget(
'customer',
array(
'title' => __('Linked Customer', 'wp-ultimo'), 'title' => __('Linked Customer', 'wp-ultimo'),
'table' => new \WP_Ultimo\List_Tables\Site_Customer_List_Table(), 'table' => new \WP_Ultimo\List_Tables\Site_Customer_List_Table(),
'query_filter' => function ($query) { '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(); $query['id'] = $this->get_object()->get_customer_id();
return $query; return $query;
}, },
)); )
);
}
} // end if; $this->add_list_table_widget(
'events',
$this->add_list_table_widget('events', array( array(
'title' => __('Events', 'wp-ultimo'), 'title' => __('Events', 'wp-ultimo'),
'table' => new \WP_Ultimo\List_Tables\Inside_Events_List_Table(), 'table' => new \WP_Ultimo\List_Tables\Inside_Events_List_Table(),
'query_filter' => array($this, 'query_filter'), 'query_filter' => array($this, 'query_filter'),
)); )
);
$membership_selected = $this->get_object()->get_membership() ? $this->get_object()->get_membership()->to_search_results() : ''; $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() : ''; $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( 'html_attr' => array(
'data-wu-app' => 'site_type', 'data-wu-app' => 'site_type',
'data-state' => json_encode(array( 'data-state' => json_encode(
array(
'type' => $this->get_object()->get_type(), 'type' => $this->get_object()->get_type(),
'original_membership_id' => $this->get_object()->get_membership_id(), 'original_membership_id' => $this->get_object()->get_membership_id(),
'membership_id' => $this->get_object()->get_membership_id(), 'membership_id' => $this->get_object()->get_membership_id(),
)), )
),
), ),
'fields' => array( 'fields' => array(
// Fields for price // Fields for price
@ -496,17 +520,23 @@ class Site_Edit_Admin_Page extends Edit_Admin_Page {
'v-cloak' => '1', 'v-cloak' => '1',
), ),
'html_attr' => array( '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(), 'id' => $this->get_object()->get_id(),
'target_membership_id' => '', 'target_membership_id' => '',
)) . "=' + membership_id", )
) . "=' + membership_id",
'title' => __('Transfer Site', 'wp-ultimo'), 'title' => __('Transfer Site', 'wp-ultimo'),
), ),
), ),
), ),
)); )
);
$this->add_fields_widget('active', array( $this->add_fields_widget(
'active',
array(
'title' => __('Active', 'wp-ultimo'), 'title' => __('Active', 'wp-ultimo'),
'fields' => array( 'fields' => array(
'active' => array( 'active' => array(
@ -516,9 +546,12 @@ class Site_Edit_Admin_Page extends Edit_Admin_Page {
'value' => $this->get_object()->is_active(), 'value' => $this->get_object()->is_active(),
), ),
), ),
)); )
);
$this->add_fields_widget('image', array( $this->add_fields_widget(
'image',
array(
'title' => __('Site Image', 'wp-ultimo'), 'title' => __('Site Image', 'wp-ultimo'),
'fields' => array( 'fields' => array(
'featured_image_id' => array( 'featured_image_id' => array(
@ -551,9 +584,9 @@ class Site_Edit_Admin_Page extends Edit_Admin_Page {
'classes' => 'button wu-w-full', 'classes' => 'button wu-w-full',
), ),
), ),
)); )
);
} // end register_widgets; }
/** /**
* Returns the list of sections and its fields for the site page. * 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()); $sections = apply_filters('wu_site_options_sections', $sections, $this->get_object());
return $sections; return $sections;
}
} // end get_site_option_sections;
/** /**
* Returns the title of the page. * Returns the title of the page.
@ -584,8 +616,7 @@ class Site_Edit_Admin_Page extends Edit_Admin_Page {
public function get_title() { public function get_title() {
return $this->edit ? __('Edit Site', 'wp-ultimo') : __('Add new Site', 'wp-ultimo'); return $this->edit ? __('Edit Site', 'wp-ultimo') : __('Add new Site', 'wp-ultimo');
}
} // end get_title;
/** /**
* Returns the title of menu for this page. * 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() { public function get_menu_title() {
return __('Edit Site', 'wp-ultimo'); return __('Edit Site', 'wp-ultimo');
}
} // end get_menu_title;
/** /**
* Returns the action links for that page. * Returns the action links for that page.
@ -624,8 +654,7 @@ class Site_Edit_Admin_Page extends Edit_Admin_Page {
'icon' => 'dashboard', 'icon' => 'dashboard',
), ),
); );
}
} // end action_links;
/** /**
* Returns the labels to be used on the admin page. * 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_button_label' => __('Delete Site', 'wp-ultimo'),
'delete_description' => __('Be careful. This action is irreversible.', 'wp-ultimo'), 'delete_description' => __('Be careful. This action is irreversible.', 'wp-ultimo'),
); );
}
} // end get_labels;
/** /**
* Filters the list table to return only relevant events. * 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); return array_merge($args, $extra_args);
}
} // end domain_query_filter;
/** /**
* Filters the list table to return only relevant events. * 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); return array_merge($args, $extra_args);
}
} // end query_filter;
/** /**
* Returns the object being edit at the moment. * 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() { public function get_object() {
if ($this->object !== null) { if ($this->object !== null) {
return $this->object; return $this->object;
}
} // end if;
$item_id = wu_request('id', 0); $item_id = wu_request('id', 0);
$item = wu_get_site($item_id); $item = wu_get_site($item_id);
if ( ! $item) { if ( ! $item) {
wp_redirect(wu_network_admin_url('wp-ultimo-sites')); wp_redirect(wu_network_admin_url('wp-ultimo-sites'));
exit; exit;
}
} // end if;
$this->object = $item; $this->object = $item;
return $this->object; return $this->object;
}
} // end get_object;
/** /**
* Sites have titles. * Sites have titles.
* *
@ -725,8 +746,7 @@ class Site_Edit_Admin_Page extends Edit_Admin_Page {
public function has_title(): bool { public function has_title(): bool {
return true; return true;
}
} // end has_title;
/** /**
* Should implement the processes necessary to save the changes made to the object. * 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()); $_POST['categories'] = wu_get_isset($_POST, 'categories', array());
if ($_POST['type'] !== Site_Type::CUSTOMER_OWNED) { if ($_POST['type'] !== Site_Type::CUSTOMER_OWNED) {
$_POST['membership_id'] = false; $_POST['membership_id'] = false;
$_POST['customer_id'] = false; $_POST['customer_id'] = false;
}
} // end if;
return parent::handle_save(); 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 * 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'), 'render' => array($this, 'render_add_new_site_modal'),
'handler' => array($this, 'handle_add_new_site_modal'), 'handler' => array($this, 'handle_add_new_site_modal'),
'capability' => 'wu_add_sites', 'capability' => 'wu_add_sites',
)); )
);
/* /*
* Publish pending site. * 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'), 'render' => array($this, 'render_publish_pending_site_modal'),
'handler' => array($this, 'handle_publish_pending_site_modal'), 'handler' => array($this, 'handle_publish_pending_site_modal'),
'capability' => 'wu_publish_sites', 'capability' => 'wu_publish_sites',
)); )
);
add_action('wu_handle_bulk_action_form_site_screenshot', array($this, 'handle_bulk_screenshots'), 10, 3); add_action('wu_handle_bulk_action_form_site_screenshot', array($this, 'handle_bulk_screenshots'), 10, 3);
}
} // end register_forms;
/** /**
* Handles the screenshot bulk action. * Handles the screenshot bulk action.
@ -98,14 +103,15 @@ class Site_List_Admin_Page extends List_Admin_Page {
$item_ids = array_filter($ids); $item_ids = array_filter($ids);
foreach ($item_ids as $item_id) { foreach ($item_ids as $item_id) {
wu_enqueue_async_action(
wu_enqueue_async_action('wu_async_take_screenshot', array( 'wu_async_take_screenshot',
array(
'site_id' => $item_id, 'site_id' => $item_id,
), 'site'); ),
'site'
} // end foreach; );
}
} // end handle_bulk_screenshots; }
/** /**
* Renders the deletion confirmation form. * 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')); $membership = wu_get_membership(wu_request('membership_id'));
if ( ! $membership) { if ( ! $membership) {
return; return;
}
} // end if;
$fields = array( $fields = array(
'confirm' => 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', 'views' => 'admin-pages/fields',
'classes' => 'wu-modal-form wu-widget-list wu-striped wu-m-0 wu-mt-0', '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', '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( 'html_attr' => array(
'data-wu-app' => 'true', 'data-wu-app' => 'true',
'data-state' => json_encode(array( 'data-state' => json_encode(
array(
'confirmed' => false, 'confirmed' => false,
)), )
), ),
)); ),
)
);
$form->render(); $form->render();
}
} // end render_publish_pending_site_modal;
/** /**
* Handles the deletion of line items. * 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')); $membership = wu_get_membership(wu_request('membership_id'));
if ( ! $membership) { if ( ! $membership) {
wp_send_json_error(new \WP_Error('not-found', __('Pending site not found.', 'wp-ultimo'))); wp_send_json_error(new \WP_Error('not-found', __('Pending site not found.', 'wp-ultimo')));
}
} // end if;
$pending_site = $membership->get_pending_site(); $pending_site = $membership->get_pending_site();
if ( ! is_a($pending_site, '\\WP_Ultimo\\Models\\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'))); wp_send_json_error(new \WP_Error('not-found', __('Pending site not found.', 'wp-ultimo')));
}
} // end if;
$pending_site->set_type('customer_owned'); $pending_site->set_type('customer_owned');
$saved = $pending_site->save(); $saved = $pending_site->save();
if (is_wp_error($saved)) { if (is_wp_error($saved)) {
wp_send_json_error($saved); wp_send_json_error($saved);
}
} // end if;
$membership->delete_pending_site(); $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'; $redirect = current_user_can('wu_edit_sites') ? 'wp-ultimo-edit-site' : 'wp-ultimo-sites';
wp_send_json_success(array( wp_send_json_success(
'redirect_url' => wu_network_admin_url($redirect, array( array(
'redirect_url' => wu_network_admin_url(
$redirect,
array(
'id' => $pending_site->get_id(), 'id' => $pending_site->get_id(),
)) )
)); ),
)
} // end handle_publish_pending_site_modal; );
}
/** /**
* Handles the add/edit of line items. * 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'); $domain_type = wu_request('tab', is_subdomain_install() ? 'sub-domain' : 'sub-directory');
if ($domain_type === 'domain') { if ($domain_type === 'domain') {
$domain = wu_request('domain', ''); $domain = wu_request('domain', '');
$path = '/'; $path = '/';
} else { } else {
$d = wu_get_site_domain_and_path(wu_request('domain', '')); $d = wu_get_site_domain_and_path(wu_request('domain', ''));
$domain = $d->domain; $domain = $d->domain;
$path = $d->path; $path = $d->path;
}
} // end if;
$atts = array( $atts = array(
'domain' => $domain, 'domain' => $domain,
@ -254,36 +257,36 @@ class Site_List_Admin_Page extends List_Admin_Page {
'membership_id' => wu_request('membership_id', false), 'membership_id' => wu_request('membership_id', false),
'duplication_arguments' => array( 'duplication_arguments' => array(
'copy_media' => wu_request('copy_media'), 'copy_media' => wu_request('copy_media'),
) ),
); );
$site = wu_create_site($atts); $site = wu_create_site($atts);
if (is_wp_error($site)) { if (is_wp_error($site)) {
return wp_send_json_error($site); return wp_send_json_error($site);
}
} // end if;
if ($site->get_blog_id() === false) { if ($site->get_blog_id() === false) {
$error = new \WP_Error('error', __('Something wrong happened.', 'wp-ultimo')); $error = new \WP_Error('error', __('Something wrong happened.', 'wp-ultimo'));
return wp_send_json_error($error); return wp_send_json_error($error);
}
} // end if;
$redirect = current_user_can('wu_edit_sites') ? 'wp-ultimo-edit-site' : 'wp-ultimo-sites'; $redirect = current_user_can('wu_edit_sites') ? 'wp-ultimo-edit-site' : 'wp-ultimo-sites';
wp_send_json_success(array( wp_send_json_success(
'redirect_url' => wu_network_admin_url($redirect, array( array(
'redirect_url' => wu_network_admin_url(
$redirect,
array(
'id' => $site->get_id(), 'id' => $site->get_id(),
'wu-new-model' => 1, 'wu-new-model' => 1,
'updated' => 1, 'updated' => 1,
)) )
)); ),
)
} // end handle_add_new_site_modal; );
}
/** /**
* Renders the add/edit line items form. * Renders the add/edit line items form.
@ -316,8 +319,7 @@ class Site_List_Admin_Page extends List_Admin_Page {
$type = $site->get_type(); $type = $site->get_type();
$template_id = $duplicate_id; $template_id = $duplicate_id;
$membership_id = $site->get_membership_id(); $membership_id = $site->get_membership_id();
}
} // end if;
$save_label = $duplicate_id ? __('Duplicate Site', 'wp-ultimo') : __('Add new Site', 'wp-ultimo'); $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. * Only keep the tab that correspond to the install type.
*/ */
if (is_subdomain_install()) { if (is_subdomain_install()) {
unset($options['sub-directory']); unset($options['sub-directory']);
} else { } else {
unset($options['sub-domain']); unset($options['sub-domain']);
}
} // end if;
$fields = array( $fields = array(
'tab' => array( 'tab' => array(
@ -460,13 +458,17 @@ class Site_List_Admin_Page extends List_Admin_Page {
$d = wu_get_site_domain_and_path('replace'); $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', 'views' => 'admin-pages/fields',
'classes' => 'wu-modal-form wu-widget-list wu-striped wu-m-0 wu-mt-0', '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', '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( 'html_attr' => array(
'data-wu-app' => 'add_new_site', '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', 'tab' => is_subdomain_install() ? 'sub-domain' : 'sub-directory',
'install_type' => is_subdomain_install() ? 'sub-domain' : 'sub-directory', 'install_type' => is_subdomain_install() ? 'sub-domain' : 'sub-directory',
'membership' => $membership_id, 'membership' => $membership_id,
@ -475,13 +477,14 @@ class Site_List_Admin_Page extends List_Admin_Page {
'base_url' => str_replace('replace.', '', (string) $d->domain) . '/', 'base_url' => str_replace('replace.', '', (string) $d->domain) . '/',
'scheme' => is_ssl() ? 'https://' : 'http://', 'scheme' => is_ssl() ? 'https://' : 'http://',
'domain' => $path, 'domain' => $path,
)), )
), ),
)); ),
)
);
$form->render(); $form->render();
}
} // end render_add_new_site_modal;
/** /**
* Allow child classes to register widgets, if they need them. * 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 * @since 1.8.2
* @return void * @return void
*/ */
public function register_widgets() {} // end register_widgets; public function register_widgets() {}
/** /**
* Returns an array with the labels for the edit page. * 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'), 'deleted_message' => __('Site removed successfully.', 'wp-ultimo'),
'search_label' => __('Search Site', 'wp-ultimo'), 'search_label' => __('Search Site', 'wp-ultimo'),
); );
}
} // end get_labels;
/** /**
* Returns the title of the page. * Returns the title of the page.
@ -515,8 +517,7 @@ class Site_List_Admin_Page extends List_Admin_Page {
public function get_title() { public function get_title() {
return __('Sites', 'wp-ultimo'); return __('Sites', 'wp-ultimo');
}
} // end get_title;
/** /**
* Returns the title of menu for this page. * 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() { public function get_menu_title() {
return __('Sites', 'wp-ultimo'); return __('Sites', 'wp-ultimo');
}
} // end get_menu_title;
/** /**
* Allows admins to rename the sub-menu (first item) for a top-level page. * 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() { public function get_submenu_title() {
return __('Sites', 'wp-ultimo'); return __('Sites', 'wp-ultimo');
}
} // end get_submenu_title;
/** /**
* Returns the action links for that page. * 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'), 'url' => wu_get_form_url('add_new_site'),
), ),
); );
}
} // end action_links;
/** /**
* Loads the list table for this particular page. * Loads the list table for this particular page.
@ -570,7 +568,5 @@ class Site_List_Admin_Page extends List_Admin_Page {
public function table() { public function table() {
return new \WP_Ultimo\List_Tables\Site_List_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() { public function init() {
add_action('wp_ajax_wu_generate_text_file_system_info', array($this, 'generate_text_file_system_info')); 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. * 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('dashboard');
wp_enqueue_script('clipboard'); wp_enqueue_script('clipboard');
}
} // end register_scripts;
/** /**
* Allow child classes to register widgets, if they need them. * 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(); $screen = get_current_screen();
foreach ($this->get_data() as $name_type => $data) { foreach ($this->get_data() as $name_type => $data) {
add_meta_box(
add_meta_box('wp-table-system-info-' . sanitize_title($name_type), $name_type, function() use ($data) { 'wp-table-system-info-' . sanitize_title($name_type),
$name_type,
function () use ($data) {
$this->output_table_system_info($data); $this->output_table_system_info($data);
},
}, $screen->id, 'normal', null); $screen->id,
'normal',
} // end foreach; null
);
} // end register_widgets; }
}
/** /**
* Display system info Table * Display system info Table
@ -132,12 +133,14 @@ class System_Info_Admin_Page extends Base_Admin_Page {
$screen = get_current_screen(); $screen = get_current_screen();
wu_get_template('system-info/system-info-table', array( wu_get_template(
'system-info/system-info-table',
array(
'data' => $data, 'data' => $data,
'screen' => $screen, 'screen' => $screen,
)); )
);
} // end output_table_system_info; }
/** /**
* Returns the title of the page. * Returns the title of the page.
@ -148,8 +151,7 @@ class System_Info_Admin_Page extends Base_Admin_Page {
public function get_title() { public function get_title() {
return __('System Info', 'wp-ultimo'); return __('System Info', 'wp-ultimo');
}
} // end get_title;
/** /**
* Returns the title of menu for this page. * 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() { public function get_menu_title() {
return __('System Info', 'wp-ultimo'); return __('System Info', 'wp-ultimo');
}
} // end get_menu_title;
/** /**
* Allows admins to rename the sub-menu (first item) for a top-level page. * 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() { public function get_submenu_title() {
return __('Dashboard', 'wp-ultimo'); return __('Dashboard', 'wp-ultimo');
}
} // end get_submenu_title;
/** /**
* Every child class should implement the output method to display the contents of the page. * 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(); $screen = get_current_screen();
wu_get_template('system-info/system-info', array( wu_get_template(
'system-info/system-info',
array(
'data' => $this->get_data(), 'data' => $this->get_data(),
'screen' => $screen, 'screen' => $screen,
)); )
);
} // end output; }
/** /**
* Get data for system info * Get data for system info
@ -238,96 +240,76 @@ class System_Info_Admin_Page extends Base_Admin_Page {
$array_constants = array(); $array_constants = array();
foreach ($array_constants_options as $constant) { foreach ($array_constants_options as $constant) {
$array_constants[] = array( $array_constants[] = array(
'tooltip' => '', 'tooltip' => '',
'title' => $constant, 'title' => $constant,
'value' => defined($constant) ? (is_bool(constant($constant)) ? __('Enabled', 'wp-ultimo') : constant($constant)) : __('Disabled', 'wp-ultimo'), 'value' => defined($constant) ? (is_bool(constant($constant)) ? __('Enabled', 'wp-ultimo') : constant($constant)) : __('Disabled', 'wp-ultimo'),
); );
}
} // end foreach;
foreach ($plugins as $plugin_path => $plugin) { foreach ($plugins as $plugin_path => $plugin) {
if (in_array($plugin_path, array_keys($active_plugins), true)) { if (in_array($plugin_path, array_keys($active_plugins), true)) {
$plugin_uri = ''; $plugin_uri = '';
if (isset($plugin['PluginURI'])) { if (isset($plugin['PluginURI'])) {
$plugin_uri = ' (' . $plugin['PluginURI'] . ')'; $plugin_uri = ' (' . $plugin['PluginURI'] . ')';
}
} // end if;
$array_active_plugins[] = array( $array_active_plugins[] = array(
'tooltip' => '', 'tooltip' => '',
'title' => $plugin['Name'], 'title' => $plugin['Name'],
'value' => $plugin['Version'] . $plugin_uri 'value' => $plugin['Version'] . $plugin_uri,
); );
}
} // end if; }
} // end foreach;
$array_active_plugins_main_site = array(); $array_active_plugins_main_site = array();
foreach ($plugins as $plugin_path => $plugin) { foreach ($plugins as $plugin_path => $plugin) {
if (in_array($plugin_path, $active_plugins_main_site, true)) { if (in_array($plugin_path, $active_plugins_main_site, true)) {
$plugin_uri = ''; $plugin_uri = '';
if (isset($plugin['PluginURI'])) { if (isset($plugin['PluginURI'])) {
$plugin_uri = ' (' . $plugin['PluginURI'] . ')'; $plugin_uri = ' (' . $plugin['PluginURI'] . ')';
}
} // end if;
$array_active_plugins_main_site[] = array( $array_active_plugins_main_site[] = array(
'tooltip' => '', 'tooltip' => '',
'title' => $plugin['Name'], 'title' => $plugin['Name'],
'value' => $plugin['Version'] . $plugin_uri 'value' => $plugin['Version'] . $plugin_uri,
); );
}
} // end if; }
} // end foreach;
$wpultimo_settings = array(); $wpultimo_settings = array();
foreach ($this->get_all_wp_ultimo_settings() as $setting => $value) { foreach ($this->get_all_wp_ultimo_settings() as $setting => $value) {
if (is_array($value)) { if (is_array($value)) {
continue; continue;
}
} // end if;
$wpultimo_settings[ $setting ] = array( $wpultimo_settings[ $setting ] = array(
'tooltip' => '', 'tooltip' => '',
'title' => $setting, 'title' => $setting,
'value' => $value 'value' => $value,
); );
}
} // end foreach;
$array_wu_tables = array(); $array_wu_tables = array();
foreach ($wpdb->ms_global_tables as $key => $value) { foreach ($wpdb->ms_global_tables as $key => $value) {
if (strncmp((string) $value, 'wu_', strlen('wu_')) === 0 && ! array_key_exists($value, $array_wu_tables)) { if (strncmp((string) $value, 'wu_', strlen('wu_')) === 0 && ! array_key_exists($value, $array_wu_tables)) {
$array_wu_tables[ $value ] = array( $array_wu_tables[ $value ] = array(
'tooltip' => '', 'tooltip' => '',
'title' => $value, 'title' => $value,
'value' => get_network_option(null, "wpdb_{$value}_version") 'value' => get_network_option(null, "wpdb_{$value}_version"),
); );
}
}
} // end if; return apply_filters(
'wu_system_info_data',
} // end foreach; array(
return apply_filters('wu_system_info_data', array(
'WordPress and System Settings' => array( 'WordPress and System Settings' => array(
'wp-ultimo-version' => array( 'wp-ultimo-version' => array(
'tooltip' => 'WP Multisite WaaS current version installed locally', 'tooltip' => 'WP Multisite WaaS current version installed locally',
@ -337,67 +319,67 @@ class System_Info_Admin_Page extends Base_Admin_Page {
'wordpress-version' => array( 'wordpress-version' => array(
'tooltip' => '', 'tooltip' => '',
'title' => 'WordPress Version', 'title' => 'WordPress Version',
'value' => get_bloginfo('version') 'value' => get_bloginfo('version'),
), ),
'php-version' => array( 'php-version' => array(
'tooltip' => '', 'tooltip' => '',
'title' => 'PHP Version', 'title' => 'PHP Version',
'value' => PHP_VERSION 'value' => PHP_VERSION,
), ),
'mysql-version' => array( 'mysql-version' => array(
'tooltip' => '', 'tooltip' => '',
'title' => 'MySQL Version ', 'title' => 'MySQL Version ',
'value' => $wpdb->db_version() 'value' => $wpdb->db_version(),
), ),
'web-server' => array( 'web-server' => array(
'tooltip' => '', 'tooltip' => '',
'title' => 'Web Server', 'title' => 'Web Server',
'value' => $_SERVER['SERVER_SOFTWARE'] 'value' => $_SERVER['SERVER_SOFTWARE'],
), ),
'wordpress-url' => array( 'wordpress-url' => array(
'tooltip' => '', 'tooltip' => '',
'title' => 'WordPress URL', 'title' => 'WordPress URL',
'value' => get_bloginfo('wpurl') 'value' => get_bloginfo('wpurl'),
), ),
'home-url' => array( 'home-url' => array(
'tooltip' => '', 'tooltip' => '',
'title' => 'Home URL', 'title' => 'Home URL',
'value' => get_bloginfo('url') 'value' => get_bloginfo('url'),
), ),
'content-directory' => array( 'content-directory' => array(
'tooltip' => '', 'tooltip' => '',
'title' => 'Content Directory', 'title' => 'Content Directory',
'value' => WP_CONTENT_DIR 'value' => WP_CONTENT_DIR,
), ),
'content-url' => array( 'content-url' => array(
'tooltip' => '', 'tooltip' => '',
'title' => 'Content URL', 'title' => 'Content URL',
'value' => WP_CONTENT_URL 'value' => WP_CONTENT_URL,
), ),
'plugins-directory' => array( 'plugins-directory' => array(
'tooltip' => '', 'tooltip' => '',
'title' => 'Plugins Directory', 'title' => 'Plugins Directory',
'value' => WP_PLUGIN_DIR 'value' => WP_PLUGIN_DIR,
), ),
'pluguins-url' => array( 'pluguins-url' => array(
'tooltip' => '', 'tooltip' => '',
'title' => 'Plugins URL', 'title' => 'Plugins URL',
'value' => WP_PLUGIN_URL 'value' => WP_PLUGIN_URL,
), ),
'uploads-directory' => array( 'uploads-directory' => array(
'tooltip' => '', 'tooltip' => '',
'title' => 'Uploads Directory', 'title' => 'Uploads Directory',
'value' => (defined('UPLOADS') ? UPLOADS : WP_CONTENT_DIR . '/uploads') 'value' => (defined('UPLOADS') ? UPLOADS : WP_CONTENT_DIR . '/uploads'),
), ),
'pluguins-url' => array( 'pluguins-url' => array(
'tooltip' => '', 'tooltip' => '',
'title' => 'Cookie Domain', '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( 'multisite-active' => array(
'tooltip' => '', 'tooltip' => '',
'title' => 'Multi-Site Active', '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( 'php-current-time-gmt' => array(
'tooltip' => '', 'tooltip' => '',
@ -412,132 +394,132 @@ class System_Info_Admin_Page extends Base_Admin_Page {
'php-current-time' => array( 'php-current-time' => array(
'tooltip' => '', 'tooltip' => '',
'title' => 'PHP Current Time - with Timezone', 'title' => 'PHP Current Time - with Timezone',
'value' => wu_get_current_time() 'value' => wu_get_current_time(),
), ),
'database-current-time' => array( 'database-current-time' => array(
'tooltip' => '', 'tooltip' => '',
'title' => 'Database Current Time', '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( 'php-curl-support' => array(
'tooltip' => '', 'tooltip' => '',
'title' => 'PHP cURL Support', '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( 'php-gd-time' => array(
'tooltip' => '', 'tooltip' => '',
'title' => 'PHP GD Support', '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( 'php-memory-limit' => array(
'tooltip' => '', 'tooltip' => '',
'title' => 'PHP Memory Limit', 'title' => 'PHP Memory Limit',
'value' => $memory_limit . 'M' 'value' => $memory_limit . 'M',
), ),
'php-memory-usage' => array( 'php-memory-usage' => array(
'tooltip' => '', 'tooltip' => '',
'title' => 'PHP Memory Usage', '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( 'php-post-max-size' => array(
'tooltip' => '', 'tooltip' => '',
'title' => 'PHP Post Max Size', 'title' => 'PHP Post Max Size',
'value' => ini_get('post_max_size') 'value' => ini_get('post_max_size'),
), ),
'php-upload-max-size' => array( 'php-upload-max-size' => array(
'tooltip' => '', 'tooltip' => '',
'title' => 'PHP Upload Max Size', 'title' => 'PHP Upload Max Size',
'value' => ini_get('upload_max_filesize') 'value' => ini_get('upload_max_filesize'),
), ),
'php-max-execution-time' => array( 'php-max-execution-time' => array(
'tooltip' => '', 'tooltip' => '',
'title' => 'PHP Max Execution Time', 'title' => 'PHP Max Execution Time',
'value' => $max_execution_time 'value' => $max_execution_time,
), ),
'php-allow-url-fopen' => array( 'php-allow-url-fopen' => array(
'tooltip' => '', 'tooltip' => '',
'title' => 'PHP Allow URL Fopen', 'title' => 'PHP Allow URL Fopen',
'value' => ini_get('allow_url_fopen') 'value' => ini_get('allow_url_fopen'),
), ),
'php-max-file-uploads' => array( 'php-max-file-uploads' => array(
'tooltip' => '', 'tooltip' => '',
'title' => 'PHP Max File Uploads', 'title' => 'PHP Max File Uploads',
'value' => ini_get('max_file_uploads') 'value' => ini_get('max_file_uploads'),
), ),
'wp-options-count' => array( 'wp-options-count' => array(
'tooltip' => '', 'tooltip' => '',
'title' => 'WP Options Count', 'title' => 'WP Options Count',
'value' => count($all_options) 'value' => count($all_options),
), ),
'wp-options-size' => array( 'wp-options-size' => array(
'tooltip' => '', 'tooltip' => '',
'title' => 'WP Options Size', 'title' => 'WP Options Size',
'value' => $all_options_bytes . 'kb' 'value' => $all_options_bytes . 'kb',
), ),
'wp-options-transients' => array( 'wp-options-transients' => array(
'tooltip' => '', 'tooltip' => '',
'title' => 'WP Options Transients', 'title' => 'WP Options Transients',
'value' => count($all_options_transients) 'value' => count($all_options_transients),
), ),
'wp-debug' => array( 'wp-debug' => array(
'tooltip' => '', 'tooltip' => '',
'title' => 'WP Options Transients', '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( 'script-debug' => array(
'tooltip' => '', 'tooltip' => '',
'title' => 'WP Options Transients', '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( 'save-queries' => array(
'tooltip' => '', 'tooltip' => '',
'title' => 'WP Options Transients', '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( 'autosave-interval' => array(
'tooltip' => '', 'tooltip' => '',
'title' => 'WP Options Transients', '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( 'wp_post_revisions' => array(
'tooltip' => '', 'tooltip' => '',
'title' => 'WP Options Transients', '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( 'disable_wp_cron' => array(
'tooltip' => '', 'tooltip' => '',
'title' => 'DISABLE_WP_CRON', '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( 'wp_lang' => array(
'tooltip' => '', 'tooltip' => '',
'title' => 'WPLANG', '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( 'wp_memory_limit' => array(
'tooltip' => '', 'tooltip' => '',
'title' => 'WP_MEMORY_LIMIT', '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( 'wp_max_memory_limit' => array(
'tooltip' => '', 'tooltip' => '',
'title' => 'WP_MAX_MEMORY_LIMIT', '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( 'operating-system' => array(
'tooltip' => '', 'tooltip' => '',
'title' => 'Operating System', 'title' => 'Operating System',
'value' => $browser['platform'] 'value' => $browser['platform'],
), ),
'browser' => array( 'browser' => array(
'tooltip' => '', 'tooltip' => '',
'title' => 'Browser', 'title' => 'Browser',
'value' => $browser['name'] . ' ' . $browser['version'] 'value' => $browser['name'] . ' ' . $browser['version'],
), ),
'user-agent' => array( 'user-agent' => array(
'tooltip' => '', 'tooltip' => '',
'title' => 'User Agent', '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( 'active-theme' => array(
'tooltip' => '', 'tooltip' => '',
'title' => 'Active Theme', '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( 'logs-directory' => array(
'tooltip' => '', 'tooltip' => '',
'title' => 'Logs Directory', '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 $wpultimo_settings
), ),
'Defined Constants' => $array_constants, 'Defined Constants' => $array_constants,
)); )
);
} // end get_data; }
/** /**
* Generate text file of system info 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!'); $txt = fopen($file_name, 'w') or die('Unable to open file!');
foreach ($this->get_data() as $type) { foreach ($this->get_data() as $type) {
foreach ($type as $item) { foreach ($type as $item) {
fwrite($txt, $item['title'] . ': ' . $item['value'] . PHP_EOL); fwrite($txt, $item['title'] . ': ' . $item['value'] . PHP_EOL);
}
} // end foreach; }
} // end foreach;
fclose($txt); fclose($txt);
@ -602,8 +580,7 @@ class System_Info_Admin_Page extends Base_Admin_Page {
readfile($file_name); readfile($file_name);
die; die;
}
} // end generate_text_file_system_info;
/** /**
* Get browser data * Get browser data
@ -623,51 +600,33 @@ class System_Info_Admin_Page extends Base_Admin_Page {
// First get the platform // First get the platform
if (preg_match('/linux/i', (string) $user_agent)) { if (preg_match('/linux/i', (string) $user_agent)) {
$platform = 'Linux'; $platform = 'Linux';
} elseif (preg_match('/macintosh|mac os x/i', (string) $user_agent)) { } elseif (preg_match('/macintosh|mac os x/i', (string) $user_agent)) {
$platform = 'Mac'; $platform = 'Mac';
} elseif (preg_match('/windows|win32/i', (string) $user_agent)) { } elseif (preg_match('/windows|win32/i', (string) $user_agent)) {
$platform = 'Windows'; $platform = 'Windows';
}
} // end if;
// Next get the name of the user agent yes seperately and for good reason // 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)) { if (preg_match('/MSIE/i', (string) $user_agent) && ! preg_match('/Opera/i', (string) $user_agent)) {
$browser_name = 'Internet Explorer'; $browser_name = 'Internet Explorer';
$browser_name_short = 'MSIE'; $browser_name_short = 'MSIE';
} elseif (preg_match('/Firefox/i', (string) $user_agent)) { } elseif (preg_match('/Firefox/i', (string) $user_agent)) {
$browser_name = 'Mozilla Firefox'; $browser_name = 'Mozilla Firefox';
$browser_name_short = 'Firefox'; $browser_name_short = 'Firefox';
} elseif (preg_match('/Chrome/i', (string) $user_agent)) { } elseif (preg_match('/Chrome/i', (string) $user_agent)) {
$browser_name = 'Google Chrome'; $browser_name = 'Google Chrome';
$browser_name_short = 'Chrome'; $browser_name_short = 'Chrome';
} elseif (preg_match('/Safari/i', (string) $user_agent)) { } elseif (preg_match('/Safari/i', (string) $user_agent)) {
$browser_name = 'Apple Safari'; $browser_name = 'Apple Safari';
$browser_name_short = 'Safari'; $browser_name_short = 'Safari';
} elseif (preg_match('/Opera/i', (string) $user_agent)) { } elseif (preg_match('/Opera/i', (string) $user_agent)) {
$browser_name = 'Opera'; $browser_name = 'Opera';
$browser_name_short = 'Opera'; $browser_name_short = 'Opera';
} elseif (preg_match('/Netscape/i', (string) $user_agent)) { } elseif (preg_match('/Netscape/i', (string) $user_agent)) {
$browser_name = 'Netscape'; $browser_name = 'Netscape';
$browser_name_short = 'Netscape'; $browser_name_short = 'Netscape';
}
} // end if;
// Finally get the correct version number // Finally get the correct version number
$known = array('Version', $browser_name_short, 'other'); $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)) { if ( ! preg_match_all($pattern, (string) $user_agent, $matches)) {
// We have no matching number just continue // We have no matching number just continue
} // end if; }
// See how many we have // See how many we have
$i = count($matches['browser']); $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 // We will have two since we are not using 'other' argument yet
// See if version is before or after the name // See if version is before or after the name
if (strripos((string) $user_agent, 'Version') < strripos((string) $user_agent, (string) $browser_name_short)) { if (strripos((string) $user_agent, 'Version') < strripos((string) $user_agent, (string) $browser_name_short)) {
$version = $matches['version'][0]; $version = $matches['version'][0];
} else { } else {
$version = $matches['version'][1]; $version = $matches['version'][1];
}
} // end if;
} else { } else {
$version = $matches['version'][0]; $version = $matches['version'][0];
}
} // end if;
// Check if we have a version number // Check if we have a version number
if (empty($version)) { if (empty($version)) {
$version = '?'; $version = '?';
}
} // end if;
return array( return array(
'user_agent' => $user_agent, 'user_agent' => $user_agent,
'name' => $browser_name, 'name' => $browser_name,
'version' => $version, 'version' => $version,
'platform' => $platform, 'platform' => $platform,
'pattern' => $pattern 'pattern' => $pattern,
); );
}
} // end get_browser;
/** /**
* Get list of all the plugins * Get list of all the plugins
@ -725,8 +674,7 @@ class System_Info_Admin_Page extends Base_Admin_Page {
public function get_all_plugins() { public function get_all_plugins() {
return get_plugins(); return get_plugins();
}
} // end get_all_plugins;
/** /**
* Get only the active plugins * Get only the active plugins
@ -736,8 +684,7 @@ class System_Info_Admin_Page extends Base_Admin_Page {
public function get_active_plugins() { public function get_active_plugins() {
return (array) get_site_option('active_sitewide_plugins', array()); return (array) get_site_option('active_sitewide_plugins', array());
}
} // end get_active_plugins;
/** /**
* Get only the active plugins on main site * 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() { public function get_active_plugins_on_main_site() {
return (array) get_option('active_plugins', array()); return (array) get_option('active_plugins', array());
}
} // end get_active_plugins_on_main_site;
/** /**
* Get memory usage * Get memory usage
*/ */
public function get_memory_usage(): float { public function get_memory_usage(): float {
return round(memory_get_usage() / 1024 / 1024, 2); return round(memory_get_usage() / 1024 / 1024, 2);
}
} // end get_memory_usage;
/** /**
* Get all the ioptions * 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 // Not to be confused with the core deprecated get_alloptions
return wp_load_alloptions(); return wp_load_alloptions();
}
} // end get_all_options;
/** /**
* Return all the desired WP Multisite WaaS Settings * Return all the desired WP Multisite WaaS Settings
@ -796,35 +740,26 @@ class System_Info_Admin_Page extends Base_Admin_Page {
$return_settings = array(); $return_settings = array();
$settings = new \WP_Ultimo\Settings; $settings = new \WP_Ultimo\Settings();
foreach ($settings->get_all() as $setting => $value) { foreach ($settings->get_all() as $setting => $value) {
$add = true; $add = true;
foreach ($exclude as $ex) { foreach ($exclude as $ex) {
if (stristr($setting, $ex) !== false) { if (stristr($setting, $ex) !== false) {
$add = false; $add = false;
break; break;
}
} // end if; }
} // end foreach;
if ($add) { if ($add) {
$return_settings[ $setting ] = $value; $return_settings[ $setting ] = $value;
}
} // end if; }
} // end foreach;
return $return_settings; return $return_settings;
}
} // end get_all_wp_ultimo_settings;
/** /**
* Get the transients om the options * Get the transients om the options
@ -837,17 +772,11 @@ class System_Info_Admin_Page extends Base_Admin_Page {
$transients = array(); $transients = array();
foreach ($options as $name => $value) { foreach ($options as $name => $value) {
if (stristr($name, 'transient')) { if (stristr($name, 'transient')) {
$transients[ $name ] = $value; $transients[ $name ] = $value;
}
} // end if; }
} // end foreach;
return $transients; return $transients;
}
} // end get_transients_in_options; }
} // end class System_Info_Admin_Page;

View File

@ -9,7 +9,7 @@
namespace WP_Ultimo\Admin_Pages; namespace WP_Ultimo\Admin_Pages;
use \WP_Ultimo\Tax\Tax; use WP_Ultimo\Tax\Tax;
// Exit if accessed directly // Exit if accessed directly
defined('ABSPATH') || exit; defined('ABSPATH') || exit;
@ -73,8 +73,7 @@ class Tax_Rates_Admin_Page extends Base_Admin_Page {
public function get_title() { public function get_title() {
return __('Tax Rates', 'wp-ultimo'); return __('Tax Rates', 'wp-ultimo');
}
} // end get_title;
/** /**
* Returns the title of menu for this page. * 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() { public function get_menu_title() {
return __('Tax Rates', 'wp-ultimo'); return __('Tax Rates', 'wp-ultimo');
}
} // end get_menu_title;
/** /**
* Allows admins to rename the sub-menu (first item) for a top-level page. * 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() { public function get_submenu_title() {
return __('Tax Rates', 'wp-ultimo'); return __('Tax Rates', 'wp-ultimo');
}
} // end get_submenu_title;
/** /**
* Every child class should implement the output method to display the contents of the page. * 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'); 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'), 'title' => __('Label', 'wp-ultimo'),
'country' => __('Country', 'wp-ultimo'), 'country' => __('Country', 'wp-ultimo'),
'state' => __('State / Province', 'wp-ultimo'), 'state' => __('State / Province', 'wp-ultimo'),
'city' => __('City', 'wp-ultimo'), 'city' => __('City', 'wp-ultimo'),
'tax_rate' => __('Tax Rate (%)', 'wp-ultimo'), 'tax_rate' => __('Tax Rate (%)', 'wp-ultimo'),
'move' => '', 'move' => '',
)); )
);
wu_get_template('taxes/list', array( wu_get_template(
'taxes/list',
array(
'columns' => $columns, 'columns' => $columns,
'screen' => get_current_screen(), 'screen' => get_current_screen(),
'types' => Tax::get_instance()->get_tax_rate_types(), 'types' => Tax::get_instance()->get_tax_rate_types(),
)); )
);
} // end output; }
/** /**
* Adds the cure bg image here as well. * 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_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'), 'name' => __('Tax', 'wp-ultimo'),
'confirm_message' => __('Are you sure you want to delete this rows?', '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'), '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-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-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'); wp_enqueue_script('wu-tax-rates');
}
} // end register_scripts;
/** /**
* Adds field widgets to edit pages with the same Form/Field APIs used elsewhere. * 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()) { protected function add_fields_widget($id, $atts = array()) {
$atts = wp_parse_args($atts, array( $atts = wp_parse_args(
$atts,
array(
'widget_id' => $id, 'widget_id' => $id,
'before' => '', 'before' => '',
'after' => '', 'after' => '',
@ -176,12 +183,15 @@ class Tax_Rates_Admin_Page extends Base_Admin_Page {
'html_attr' => array(), 'html_attr' => array(),
'classes' => '', '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', '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')) { if (wu_get_isset($atts['html_attr'], 'data-wu-app')) {
$atts['fields']['loading'] = array( $atts['fields']['loading'] = array(
'type' => 'note', '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')), '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, 'v-if' => 0,
), ),
); );
}
} // end if;
/** /**
* Instantiate the form for the order details. * Instantiate the form for the order details.
* *
* @since 2.0.0 * @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', 'views' => 'admin-pages/fields',
'classes' => 'wu-widget-list wu-striped wu-m-0 wu--mt-2 wu--mb-3 wu--mx-3 ' . $atts['classes'], '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'], 'field_wrapper_classes' => $atts['field_wrapper_classes'],
'html_attr' => $atts['html_attr'], 'html_attr' => $atts['html_attr'],
'before' => $atts['before'], 'before' => $atts['before'],
'after' => $atts['after'], 'after' => $atts['after'],
)); )
);
$form->render(); $form->render();
},
}, $atts['screen']->id, $atts['position'], null); $atts['screen']->id,
$atts['position'],
} // end add_fields_widget; null
);
} // end class Tax_Rates_Admin_Page; }
}

View File

@ -9,7 +9,7 @@
namespace WP_Ultimo\Admin_Pages; namespace WP_Ultimo\Admin_Pages;
use \WP_Ultimo\UI\Template_Previewer; use WP_Ultimo\UI\Template_Previewer;
// Exit if accessed directly // Exit if accessed directly
defined('ABSPATH') || exit; defined('ABSPATH') || exit;
@ -74,12 +74,14 @@ class Template_Previewer_Customize_Admin_Page extends Customizer_Admin_Page {
$url = get_site_url(null); $url = get_site_url(null);
return add_query_arg(array( return add_query_arg(
array(
'customizer' => 1, 'customizer' => 1,
Template_Previewer::get_instance()->get_preview_parameter() => 1, Template_Previewer::get_instance()->get_preview_parameter() => 1,
), $url); ),
$url
} // end get_preview_url; );
}
/** /**
* Allow child classes to register widgets, if they need them. * 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() { public function register_widgets() {
$this->add_save_widget('save', array( $this->add_save_widget(
'save',
array(
'fields' => array( 'fields' => array(
'preview_url_parameter' => array( 'preview_url_parameter' => array(
'type' => 'text', 'type' => 'text',
@ -102,11 +106,11 @@ class Template_Previewer_Customize_Admin_Page extends Customizer_Admin_Page {
'title' => __('Active', 'wp-ultimo'), 'title' => __('Active', 'wp-ultimo'),
'desc' => __('If your site templates are not loading, you can disable the top-bar using this setting.', '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), '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'); $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(); $settings = Template_Previewer::get_instance()->get_settings();
$state = array_merge($settings, array( $state = array_merge(
$settings,
array(
'tab' => 'general', 'tab' => 'general',
'refresh' => true, 'refresh' => true,
)); )
);
$this->add_fields_widget('customizer', array( $this->add_fields_widget(
'customizer',
array(
'title' => __('Customizer', 'wp-ultimo'), 'title' => __('Customizer', 'wp-ultimo'),
'position' => 'side', 'position' => 'side',
'fields' => $fields, 'fields' => $fields,
@ -226,9 +235,9 @@ class Template_Previewer_Customize_Admin_Page extends Customizer_Admin_Page {
'data-wu-customizer-panel' => true, 'data-wu-customizer-panel' => true,
'data-state' => json_encode($state), 'data-state' => json_encode($state),
), ),
)); )
);
} // end register_widgets; }
/** /**
* Returns the title of the page. * Returns the title of the page.
@ -239,8 +248,7 @@ class Template_Previewer_Customize_Admin_Page extends Customizer_Admin_Page {
public function get_title() { public function get_title() {
return __('Customize Template Previewer', 'wp-ultimo'); return __('Customize Template Previewer', 'wp-ultimo');
}
} // end get_title;
/** /**
* Returns the title of menu for this page. * 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() { public function get_menu_title() {
return __('Customize Template Previewer', 'wp-ultimo'); return __('Customize Template Previewer', 'wp-ultimo');
}
} // end get_menu_title;
/** /**
* Returns the action links for that page. * 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() { public function action_links() {
return array(); return array();
}
} // end action_links;
/** /**
* Returns the labels to be used on the admin page. * 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_button_label' => __('Save Changes', 'wp-ultimo'),
'save_description' => '', 'save_description' => '',
); );
}
} // end get_labels;
/** /**
* Should implement the processes necessary to save the changes made to the object. * 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); wp_redirect($url);
exit; 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() { public function __construct() {
add_action('admin_bar_menu', array($this, 'add_top_bar_menus'), 50); add_action('admin_bar_menu', array($this, 'add_top_bar_menus'), 50);
}
} // end __construct;
/** /**
* Adds the WP Multisite WaaS top-bar shortcut menu * Adds the WP Multisite WaaS top-bar shortcut menu
@ -47,10 +46,8 @@ class Top_Admin_Nav_Menu {
// Only for super admins // Only for super admins
if ( ! current_user_can('manage_network')) { if ( ! current_user_can('manage_network')) {
return; return;
}
} // end if;
// Add Parent element // Add Parent element
$parent = array( $parent = array(
@ -60,7 +57,7 @@ class Top_Admin_Nav_Menu {
'meta' => array( 'meta' => array(
'class' => 'wp-ultimo-top-menu', 'class' => 'wp-ultimo-top-menu',
'title' => __('Go to the dashboard', 'wp-ultimo'), 'title' => __('Go to the dashboard', 'wp-ultimo'),
) ),
); );
// Site // Site
@ -72,7 +69,7 @@ class Top_Admin_Nav_Menu {
'meta' => array( 'meta' => array(
'class' => 'wp-ultimo-top-menu', 'class' => 'wp-ultimo-top-menu',
'title' => __('Go to the sites page', 'wp-ultimo'), 'title' => __('Go to the sites page', 'wp-ultimo'),
) ),
); );
// Memberships // Memberships
@ -84,7 +81,7 @@ class Top_Admin_Nav_Menu {
'meta' => array( 'meta' => array(
'class' => 'wp-ultimo-top-menu', 'class' => 'wp-ultimo-top-menu',
'title' => __('Go to the memberships page', 'wp-ultimo'), 'title' => __('Go to the memberships page', 'wp-ultimo'),
) ),
); );
// Customers // Customers
@ -96,7 +93,7 @@ class Top_Admin_Nav_Menu {
'meta' => array( 'meta' => array(
'class' => 'wp-ultimo-top-menu', 'class' => 'wp-ultimo-top-menu',
'title' => __('Go to the customers page', 'wp-ultimo'), 'title' => __('Go to the customers page', 'wp-ultimo'),
) ),
); );
// Products // Products
@ -108,7 +105,7 @@ class Top_Admin_Nav_Menu {
'meta' => array( 'meta' => array(
'class' => 'wp-ultimo-top-menu', 'class' => 'wp-ultimo-top-menu',
'title' => __('Go to the products page', 'wp-ultimo'), 'title' => __('Go to the products page', 'wp-ultimo'),
) ),
); );
// Payments // Payments
@ -120,7 +117,7 @@ class Top_Admin_Nav_Menu {
'meta' => array( 'meta' => array(
'class' => 'wp-ultimo-top-menu', 'class' => 'wp-ultimo-top-menu',
'title' => __('Go to the payments page', 'wp-ultimo'), 'title' => __('Go to the payments page', 'wp-ultimo'),
) ),
); );
// Discount Codes // Discount Codes
@ -132,7 +129,7 @@ class Top_Admin_Nav_Menu {
'meta' => array( 'meta' => array(
'class' => 'wp-ultimo-top-menu', 'class' => 'wp-ultimo-top-menu',
'title' => __('Go to the discount codes page', 'wp-ultimo'), 'title' => __('Go to the discount codes page', 'wp-ultimo'),
) ),
); );
$container = array( $container = array(
@ -144,7 +141,7 @@ class Top_Admin_Nav_Menu {
'meta' => array( 'meta' => array(
'class' => 'wp-ultimo-top-menu ab-sub-secondary', 'class' => 'wp-ultimo-top-menu ab-sub-secondary',
'title' => __('Go to the settings page', 'wp-ultimo'), 'title' => __('Go to the settings page', 'wp-ultimo'),
) ),
); );
// Settings // Settings
@ -156,7 +153,7 @@ class Top_Admin_Nav_Menu {
'meta' => array( 'meta' => array(
'class' => 'wp-ultimo-top-menu ab-sub-secondary', 'class' => 'wp-ultimo-top-menu ab-sub-secondary',
'title' => __('Go to the settings page', 'wp-ultimo'), 'title' => __('Go to the settings page', 'wp-ultimo'),
) ),
); );
/** /**
@ -165,44 +162,32 @@ class Top_Admin_Nav_Menu {
$wp_admin_bar->add_node($parent); $wp_admin_bar->add_node($parent);
if (current_user_can('wu_read_sites')) { if (current_user_can('wu_read_sites')) {
$wp_admin_bar->add_node($sites); $wp_admin_bar->add_node($sites);
} //end if; } //end if;
if (current_user_can('wu_read_memberships')) { if (current_user_can('wu_read_memberships')) {
$wp_admin_bar->add_node($memberships); $wp_admin_bar->add_node($memberships);
} //end if; } //end if;
if (current_user_can('wu_read_customers')) { if (current_user_can('wu_read_customers')) {
$wp_admin_bar->add_node($customers); $wp_admin_bar->add_node($customers);
} //end if; } //end if;
if (current_user_can('wu_read_products')) { if (current_user_can('wu_read_products')) {
$wp_admin_bar->add_node($products); $wp_admin_bar->add_node($products);
} //end if; } //end if;
if (current_user_can('wu_read_payments')) { if (current_user_can('wu_read_payments')) {
$wp_admin_bar->add_node($payments); $wp_admin_bar->add_node($payments);
} //end if; } //end if;
if (current_user_can('wu_read_discount_codes')) { if (current_user_can('wu_read_discount_codes')) {
$wp_admin_bar->add_node($discount_codes); $wp_admin_bar->add_node($discount_codes);
} //end if; } //end if;
if (current_user_can('wu_read_settings')) { if (current_user_can('wu_read_settings')) {
$wp_admin_bar->add_node($container); $wp_admin_bar->add_node($container);
$wp_admin_bar->add_node($settings); $wp_admin_bar->add_node($settings);
} //end if; } //end if;
/* /*
@ -213,20 +198,15 @@ class Top_Admin_Nav_Menu {
$has_addons = false; $has_addons = false;
foreach ($settings_tabs as $tab => $tab_info) { foreach ($settings_tabs as $tab => $tab_info) {
if (wu_get_isset($tab_info, 'invisible')) { if (wu_get_isset($tab_info, 'invisible')) {
continue; continue;
}
} // end if;
$parent = 'wp-ultimo-settings'; $parent = 'wp-ultimo-settings';
if (wu_get_isset($tab_info, 'addon', false)) { if (wu_get_isset($tab_info, 'addon', false)) {
$parent = 'wp-ultimo-settings-addons'; $parent = 'wp-ultimo-settings-addons';
}
} // end if;
$settings_tab = array( $settings_tab = array(
'id' => 'wp-ultimo-settings-' . $tab, 'id' => 'wp-ultimo-settings-' . $tab,
@ -236,13 +216,10 @@ class Top_Admin_Nav_Menu {
'meta' => array( 'meta' => array(
'class' => 'wp-ultimo-top-menu', 'class' => 'wp-ultimo-top-menu',
'title' => __('Go to the settings page', 'wp-ultimo'), 'title' => __('Go to the settings page', 'wp-ultimo'),
) ),
); );
$wp_admin_bar->add_node($settings_tab); $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() { public function init() {
add_action('wp_ajax_wu_handle_view_logs', array($this, 'handle_view_logs')); add_action('wp_ajax_wu_handle_view_logs', array($this, 'handle_view_logs'));
}
} // end init;
/** /**
* Registers extra scripts needed for this page. * 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_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( 'i18n' => array(
'copied' => __('Copied!', 'wp-ultimo'), 'copied' => __('Copied!', 'wp-ultimo'),
), ),
)); )
);
wp_enqueue_script('wu-view-log'); wp_enqueue_script('wu-view-log');
wp_enqueue_script('clipboard'); wp_enqueue_script('clipboard');
}
} // end register_scripts;
/** /**
* Returns the title of the page. * Returns the title of the page.
@ -117,8 +119,7 @@ class View_Logs_Admin_Page extends Edit_Admin_Page {
public function get_title() { public function get_title() {
return __('View Log', 'wp-ultimo'); return __('View Log', 'wp-ultimo');
}
} // end get_title;
/** /**
* Returns the title of menu for this page. * 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() { public function get_menu_title() {
return __('View Log', 'wp-ultimo'); return __('View Log', 'wp-ultimo');
}
} // end get_menu_title;
/** /**
* Handles the actions for the logs and system info. * 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() { 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', 'index.html',
)); )
);
$logs_list = array_combine(array_values($logs_list), array_map(fn($file) => str_replace(Logger::get_logs_folder(), '', (string) $file), $logs_list)); $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)) { if (empty($logs_list)) {
$logs_list[''] = __('No log files found', 'wp-ultimo'); $logs_list[''] = __('No log files found', 'wp-ultimo');
}
} // end if;
$file = wu_request('file'); $file = wu_request('file');
@ -161,16 +163,12 @@ class View_Logs_Admin_Page extends Edit_Admin_Page {
// Security check // Security check
if ($file && ! stristr((string) $file, Logger::get_logs_folder())) { 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')); wp_die(__('You can see files that are not WP Multisite WaaS\'s logs', 'wp-ultimo'));
}
} // end if;
if ( ! $file && ! empty($logs_list)) { if ( ! $file && ! empty($logs_list)) {
$file = ! $file && ! empty($logs_list) ? current(array_keys($logs_list)) : false; $file = ! $file && ! empty($logs_list) ? current(array_keys($logs_list)) : false;
}
} // end if;
$file_name = str_replace(Logger::get_logs_folder(), '', (string) $file); $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()) { if (wp_doing_ajax()) {
wp_send_json_success($response); wp_send_json_success($response);
} else { } else {
return $response; return $response;
}
} // end if; }
} // end handle_view_logs;
/** /**
* Allow child classes to register widgets, if they need them. * 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); 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'), 'title' => __('Log Files', 'wp-ultimo'),
'fields' => array( 'fields' => array(
'log_file' => array( 'log_file' => array(
@ -227,9 +222,12 @@ class View_Logs_Admin_Page extends Edit_Admin_Page {
'classes' => 'button button-primary wu-w-full', 'classes' => 'button button-primary wu-w-full',
), ),
), ),
)); )
);
$this->add_fields_widget('info', array( $this->add_fields_widget(
'info',
array(
'title' => __('Timestamps', 'wp-ultimo'), 'title' => __('Timestamps', 'wp-ultimo'),
'position' => 'side', 'position' => 'side',
'fields' => array( 'fields' => array(
@ -239,11 +237,11 @@ class View_Logs_Admin_Page extends Edit_Admin_Page {
'date' => true, 'date' => true,
'value' => date_i18n('Y-m-d H:i:s', filemtime($info['file'])), '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'])), 'display_value' => date_i18n('Y-m-d H:i:s', filemtime($info['file'])),
)
), ),
)); ),
)
} // end register_widgets; );
}
/** /**
* Outputs the pre block that shows the content. * 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) { 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'), 'title' => __('Event Payload', 'wp-ultimo'),
'loading_text' => __('Loading Payload', 'wp-ultimo'), 'loading_text' => __('Loading Payload', 'wp-ultimo'),
'payload' => $data['args']['contents'], 'payload' => $data['args']['contents'],
)); )
);
} // end output_default_widget_payload; }
/** /**
* Returns the labels to be used on the admin page. * 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_button_label' => __('Delete Log File', 'wp-ultimo'),
'delete_description' => __('Be careful. This action is irreversible.', 'wp-ultimo'), 'delete_description' => __('Be careful. This action is irreversible.', 'wp-ultimo'),
); );
}
} // end get_labels;
/** /**
* Returns the object being edit at the moment. * 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() { public function get_object() {
return array(); return array();
}
} // end get_object;
/** /**
* Register additional hooks to page load such as the action links and the save processing. * 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 * Process save, if necessary
*/ */
$this->process_save(); $this->process_save();
}
} // end page_loaded;
/** /**
* Should implement the processes necessary to save the changes made to the object. * 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'); $action = wu_request('submit_button', 'none');
if ($action === 'none') { if ($action === 'none') {
WP_Ultimo()->notices->add(__('Something wrong happened', 'wp-ultimo'), 'error', 'network-admin'); WP_Ultimo()->notices->add(__('Something wrong happened', 'wp-ultimo'), 'error', 'network-admin');
return; return;
}
} // end if;
$file = wu_request('log_file', false); $file = wu_request('log_file', false);
if ( ! file_exists($file)) { if ( ! file_exists($file)) {
WP_Ultimo()->notices->add(__('File not found', 'wp-ultimo'), 'error', 'network-admin'); WP_Ultimo()->notices->add(__('File not found', 'wp-ultimo'), 'error', 'network-admin');
return; return;
}
} // end if;
if ($action === 'download') { if ($action === 'download') {
$file_name = str_replace(Logger::get_logs_folder(), '', (string) $file); $file_name = str_replace(Logger::get_logs_folder(), '', (string) $file);
header('Content-Type: application/octet-stream'); header('Content-Type: application/octet-stream');
@ -354,27 +346,20 @@ class View_Logs_Admin_Page extends Edit_Admin_Page {
readfile($file); readfile($file);
exit; exit;
} elseif ($action === 'delete') { } elseif ($action === 'delete') {
$status = unlink($file); $status = unlink($file);
if ( ! $status) { if ( ! $status) {
WP_Ultimo()->notices->add(__('We were unable to delete file', 'wp-ultimo'), 'error', 'network-admin'); WP_Ultimo()->notices->add(__('We were unable to delete file', 'wp-ultimo'), 'error', 'network-admin');
return; return;
}
} // end if; }
} // end if;
$url = remove_query_arg('log_file'); $url = remove_query_arg('log_file');
wp_redirect(add_query_arg('deleted', 1, $url)); wp_redirect(add_query_arg('deleted', 1, $url));
exit; 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 // Exit if accessed directly
defined('ABSPATH') || exit; defined('ABSPATH') || exit;
use \WP_Ultimo\Models\Webhook; use WP_Ultimo\Models\Webhook;
/** /**
* WP Multisite WaaS Webhook Edit/Add New Admin Page. * 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_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( 'i18n' => array(
'error_title' => __('Webhook Test', 'wp-ultimo'), 'error_title' => __('Webhook Test', 'wp-ultimo'),
'error_message' => __('An error occurred when sending the test webhook, please try again.', 'wp-ultimo'), 'error_message' => __('An error occurred when sending the test webhook, please try again.', 'wp-ultimo'),
'copied' => __('Copied!', 'wp-ultimo'), 'copied' => __('Copied!', 'wp-ultimo'),
), ),
)); )
);
wp_enqueue_script('wu-webhook-page'); wp_enqueue_script('wu-webhook-page');
}
} // end register_scripts;
/** /**
* Register ajax forms that we use for webhook. * 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 * Delete Webhook - Confirmation modal
*/ */
add_filter('wu_data_json_success_delete_webhook_modal', fn($data_json) => array( add_filter(
'redirect_url' => wu_network_admin_url('wp-ultimo-webhooks', array('deleted' => 1)) '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; )
);
}
/** /**
* Allow child classes to register widgets, if they need them. * 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(); parent::register_widgets();
$this->add_fields_widget('domain-url', array( $this->add_fields_widget(
'domain-url',
array(
'title' => __('Webhook URL', 'wp-ultimo'), 'title' => __('Webhook URL', 'wp-ultimo'),
'position' => 'normal', 'position' => 'normal',
'fields' => array( 'fields' => array(
@ -158,25 +165,29 @@ class Webhook_Edit_Admin_Page extends Edit_Admin_Page {
'wrapper_classes' => 'wu-items-left wu-justify-start', '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'); 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'), 'title' => __('Events', 'wp-ultimo'),
'table' => new \WP_Ultimo\List_Tables\Inside_Events_List_Table(), 'table' => new \WP_Ultimo\List_Tables\Inside_Events_List_Table(),
'query_filter' => array($this, 'query_filter'), 'query_filter' => array($this, 'query_filter'),
)); )
);
$event_list = array(); $event_list = array();
foreach (wu_get_event_types() as $key => $value) { foreach (wu_get_event_types() as $key => $value) {
$event_list[ $key ] = $value['name']; $event_list[ $key ] = $value['name'];
}
} // end foreach; $this->add_save_widget(
'save',
$this->add_save_widget('save', array( array(
'fields' => array( 'fields' => array(
'event' => array( 'event' => array(
'type' => 'select', 'type' => 'select',
@ -187,9 +198,12 @@ class Webhook_Edit_Admin_Page extends Edit_Admin_Page {
'value' => $this->get_object()->get_event(), 'value' => $this->get_object()->get_event(),
), ),
), ),
)); )
);
$this->add_fields_widget('active', array( $this->add_fields_widget(
'active',
array(
'title' => __('Active', 'wp-ultimo'), 'title' => __('Active', 'wp-ultimo'),
'fields' => array( 'fields' => array(
'active' => array( 'active' => array(
@ -200,9 +214,12 @@ class Webhook_Edit_Admin_Page extends Edit_Admin_Page {
'value' => $this->get_object()->is_active(), 'value' => $this->get_object()->is_active(),
), ),
), ),
)); )
);
$this->add_fields_widget('options', array( $this->add_fields_widget(
'options',
array(
'title' => __('Options', 'wp-ultimo'), 'title' => __('Options', 'wp-ultimo'),
'fields' => array( 'fields' => array(
'integration' => 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'), '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. * 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) : '{}'; $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'), 'title' => __('Event Payload', 'wp-ultimo'),
'loading_text' => __('Loading Payload', 'wp-ultimo'), 'loading_text' => __('Loading Payload', 'wp-ultimo'),
'payload' => $payload, 'payload' => $payload,
)); )
);
} // end output_default_widget_payload; }
/** /**
* Filters the list table to return only relevant events. * 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); return array_merge($args, $extra_args);
}
} // end query_filter;
/** /**
* Returns the title of the page. * Returns the title of the page.
@ -280,8 +298,7 @@ class Webhook_Edit_Admin_Page extends Edit_Admin_Page {
public function get_title() { public function get_title() {
return $this->edit ? __('Edit Webhook', 'wp-ultimo') : __('Add new Webhook', 'wp-ultimo'); return $this->edit ? __('Edit Webhook', 'wp-ultimo') : __('Add new Webhook', 'wp-ultimo');
}
} // end get_title;
/** /**
* Returns the title of menu for this page. * 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() { public function get_menu_title() {
return __('Edit Webhook', 'wp-ultimo'); return __('Edit Webhook', 'wp-ultimo');
}
} // end get_menu_title;
/** /**
* Returns the action links for that page. * Returns the action links for that page.
@ -304,8 +320,7 @@ class Webhook_Edit_Admin_Page extends Edit_Admin_Page {
public function action_links() { public function action_links() {
return array(); return array();
}
} // end action_links;
/** /**
* Returns the labels to be used on the admin page. * 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_button_label' => __('Delete Webhook', 'wp-ultimo'),
'delete_description' => __('Be careful. This action is irreversible.', 'wp-ultimo'), 'delete_description' => __('Be careful. This action is irreversible.', 'wp-ultimo'),
); );
}
} // end get_labels;
/** /**
* Returns the object being edit at the moment. * 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() { public function get_object() {
if (wu_request('id')) { 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')); $item = $query->get_item_by('id', wu_request('id'));
if ( ! $item) { if ( ! $item) {
wp_redirect(wu_network_admin_url('wp-ultimo-webhooks')); wp_redirect(wu_network_admin_url('wp-ultimo-webhooks'));
exit; exit;
}
} // end if;
return $item; return $item;
}
} // end if; return new Webhook();
}
return new Webhook;
} // end get_object;
/** /**
* Webhooks have titles. * Webhooks have titles.
* *
@ -366,8 +375,7 @@ class Webhook_Edit_Admin_Page extends Edit_Admin_Page {
public function has_title(): bool { public function has_title(): bool {
return true; return true;
}
} // end has_title;
/** /**
* Handles the save of this form. * Handles the save of this form.
@ -382,33 +390,25 @@ class Webhook_Edit_Admin_Page extends Edit_Admin_Page {
$object->attributes($_POST); $object->attributes($_POST);
if (is_wp_error($object->save())) { if (is_wp_error($object->save())) {
$errors = implode('<br>', $object->save()->get_error_messages()); $errors = implode('<br>', $object->save()->get_error_messages());
WP_Ultimo()->notices->add($errors, 'error', 'network-admin'); WP_Ultimo()->notices->add($errors, 'error', 'network-admin');
return; return;
} else { } else {
$array_params = array( $array_params = array(
'updated' => 1, 'updated' => 1,
); );
if ($this->edit === false) { if ($this->edit === false) {
$array_params['id'] = $object->get_id(); $array_params['id'] = $object->get_id();
}
} // end if;
$url = add_query_arg($array_params); $url = add_query_arg($array_params);
wp_redirect($url); wp_redirect($url);
exit; 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_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( 'i18n' => array(
'error_title' => __('Webhook Test', 'wp-ultimo'), 'error_title' => __('Webhook Test', 'wp-ultimo'),
'error_message' => __('An error occurred when sending the test webhook, please try again.', 'wp-ultimo'), 'error_message' => __('An error occurred when sending the test webhook, please try again.', 'wp-ultimo'),
'copied' => __('Copied!', 'wp-ultimo'), 'copied' => __('Copied!', 'wp-ultimo'),
), ),
)); )
);
wp_enqueue_script('wu-webhook-page'); wp_enqueue_script('wu-webhook-page');
}
} // end register_scripts;
/** /**
* Register ajax forms that we use for add new webhooks. * 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. * 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'), 'render' => array($this, 'render_add_new_webhook_modal'),
'handler' => array($this, 'handle_add_new_webhook_modal'), 'handler' => array($this, 'handle_add_new_webhook_modal'),
'capability' => 'wu_edit_webhooks', 'capability' => 'wu_edit_webhooks',
)); )
);
} // end register_forms; }
/** /**
* Renders the add new webhook modal. * Renders the add new webhook modal.
@ -109,10 +114,8 @@ class Webhook_List_Admin_Page extends List_Admin_Page {
$event_options = array(); $event_options = array();
foreach ($events as $slug => $event) { foreach ($events as $slug => $event) {
$event_options[ $slug ] = $event['name']; $event_options[ $slug ] = $event['name'];
}
} // end foreach;
$fields = array( $fields = array(
'name' => array( 'name' => array(
@ -125,7 +128,7 @@ class Webhook_List_Admin_Page extends List_Admin_Page {
'title' => __('Event', 'wp-ultimo'), 'title' => __('Event', 'wp-ultimo'),
'type' => 'select', 'type' => 'select',
'desc' => __('The event that will trigger the webhook.', 'wp-ultimo'), 'desc' => __('The event that will trigger the webhook.', 'wp-ultimo'),
'options' => $event_options 'options' => $event_options,
), ),
'webhook_url' => array( 'webhook_url' => array(
'type' => 'url', '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', 'views' => 'admin-pages/fields',
'classes' => 'wu-modal-form wu-widget-list wu-striped wu-m-0 wu-mt-0', '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', '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( 'html_attr' => array(
'data-wu-app' => 'edit_line_item', 'data-wu-app' => 'edit_line_item',
'data-state' => json_encode(array( 'data-state' => json_encode(
'event' => '' array(
)), 'event' => '',
)
), ),
)); ),
)
);
$form->render(); $form->render();
}
} // end render_add_new_webhook_modal;
/** /**
* Handles the 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); $status = wu_create_webhook($_POST);
if (is_wp_error($status)) { if (is_wp_error($status)) {
wp_send_json_error($status); wp_send_json_error($status);
} else { } else {
wp_send_json_success(
wp_send_json_success(array( array(
'redirect_url' => wu_network_admin_url('wp-ultimo-edit-webhook', array( 'redirect_url' => wu_network_admin_url(
'id' => $status->get_id() 'wp-ultimo-edit-webhook',
)) array(
)); 'id' => $status->get_id(),
)
} // end if; ),
)
} // end handle_add_new_webhook_modal; );
}
}
/** /**
* Allow child classes to register widgets, if they need them. * 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 * @since 1.8.2
* @return void * @return void
*/ */
public function register_widgets() {} // end register_widgets; public function register_widgets() {}
/** /**
* Returns an array with the labels for the edit page. * 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'), 'deleted_message' => __('Webhook removed successfully.', 'wp-ultimo'),
'search_label' => __('Search Webhook', 'wp-ultimo'), 'search_label' => __('Search Webhook', 'wp-ultimo'),
); );
}
} // end get_labels;
/** /**
* Returns the title of the page. * Returns the title of the page.
@ -219,8 +226,7 @@ class Webhook_List_Admin_Page extends List_Admin_Page {
public function get_title() { public function get_title() {
return __('Webhooks', 'wp-ultimo'); return __('Webhooks', 'wp-ultimo');
}
} // end get_title;
/** /**
* Returns the title of menu for this page. * 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() { public function get_menu_title() {
return __('Webhooks', 'wp-ultimo'); return __('Webhooks', 'wp-ultimo');
}
} // end get_menu_title;
/** /**
* Allows admins to rename the sub-menu (first item) for a top-level page. * 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() { public function get_submenu_title() {
return __('Webhooks', 'wp-ultimo'); return __('Webhooks', 'wp-ultimo');
}
} // end get_submenu_title;
/** /**
* Returns the action links for that page. * 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'), '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() { public function table() {
return new \WP_Ultimo\List_Tables\Webhook_List_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 * Process save, if necessary
*/ */
$this->process_save(); $this->process_save();
}
} // end page_loaded;
/** /**
* Handles saves, after verifying nonces and such. Should not be rewritten by child classes. * 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()); $saving_tag = sprintf('saving_%s', $this->get_current_section());
if (isset($_REQUEST[ $saving_tag ])) { if (isset($_REQUEST[ $saving_tag ])) {
check_admin_referer($saving_tag, '_wpultimo_nonce'); check_admin_referer($saving_tag, '_wpultimo_nonce');
$handler = isset($this->current_section['handler']) ? $this->current_section['handler'] : array($this, 'default_handler'); $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 * Calls the saving function
*/ */
call_user_func($handler); call_user_func($handler);
}
} // end if; }
} // end process_save;
/** /**
* Returns the labels to be used on the admin page. * 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_button_label' => __('Save', 'wp-ultimo'),
'save_description' => '', 'save_description' => '',
); );
}
} // end get_labels;
/** /**
* Registers widgets to the edit page. * Registers widgets to the edit page.
@ -154,14 +149,11 @@ abstract class Wizard_Admin_Page extends Base_Admin_Page {
$screen = get_current_screen(); $screen = get_current_screen();
if (wu_get_isset($this->current_section, 'separator')) { if (wu_get_isset($this->current_section, 'separator')) {
return; 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); 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. * 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); call_user_func($view);
echo '</div>'; echo '</div>';
}
} // end output_default_widget_body;
/** /**
* Returns the logo to be used on the wizard. * 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() { public function get_logo() {
return ''; return '';
}
} // end get_logo;
/** /**
* Displays the contents of the edit page. * 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 =) * 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(), 'screen' => get_current_screen(),
'page' => $this, 'page' => $this,
'logo' => $this->get_logo(), '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', '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, 'clickable_navigation' => $this->clickable_navigation,
'form_id' => $this->form_id, 'form_id' => $this->form_id,
)); )
);
} // end output; }
/** /**
* Returns the first section of the signup process * 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()); $keys = array_keys($this->get_sections());
if (isset($keys[1])) { if (isset($keys[1])) {
return $keys[1]; return $keys[1];
} else { } else {
return false; return false;
}
} // end if; }
} // end get_first_section;
/** /**
* Get the current 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)); $current_section = isset($_GET[ $this->section_slug ]) ? sanitize_key($_GET[ $this->section_slug ]) : current(array_keys($sections));
return $current_section; return $current_section;
}
} // end get_current_section;
/** /**
* Returns the page link for the 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) { public function get_section_link($section) {
return add_query_arg($this->section_slug, $section); return add_query_arg($this->section_slug, $section);
}
} // end get_section_link;
/** /**
* Returns the link to the next section on the wizard. * 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); $keys = array_keys($sections);
return add_query_arg($this->section_slug, $keys[ array_search($current_section, array_keys($sections), true) + 1 ]); 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. * 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); $keys = array_keys($sections);
return add_query_arg($this->section_slug, $keys[ array_search($current_section, array_keys($sections), true) - 1 ]); 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. * 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()); wp_redirect($this->get_next_section_link());
exit; exit;
}
} // end default_handler;
/** /**
* Default method for views. * Default method for views.
@ -330,7 +312,9 @@ abstract class Wizard_Admin_Page extends Base_Admin_Page {
*/ */
public function default_view() { public function default_view() {
$section = wp_parse_args($this->current_section, array( $section = wp_parse_args(
$this->current_section,
array(
'title' => '', 'title' => '',
'description' => '', 'description' => '',
'content' => '', 'content' => '',
@ -341,38 +325,44 @@ abstract class Wizard_Admin_Page extends Base_Admin_Page {
'back' => false, 'back' => false,
'skip' => false, 'skip' => false,
'next' => true, 'next' => true,
)); )
);
/* /*
* Check if the section has fields * Check if the section has fields
*/ */
if ( ! empty($section['fields'])) { if ( ! empty($section['fields'])) {
if (is_callable($section['fields'])) { if (is_callable($section['fields'])) {
$section['fields'] = call_user_func($section['fields']); $section['fields'] = call_user_func($section['fields']);
}
} // end if; $form = new \WP_Ultimo\UI\Form(
$this->get_current_section(),
$form = new \WP_Ultimo\UI\Form($this->get_current_section(), $section['fields'], array( $section['fields'],
array(
'views' => 'admin-pages/fields', 'views' => 'admin-pages/fields',
'classes' => 'wu-widget-list wu-striped wu-m-0 wu-mt-2 wu--mb-6 wu--mx-6', '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', '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(); ob_start();
$form->render(); $form->render();
$section['content'] = ob_get_clean(); $section['content'] = ob_get_clean();
}
} // end if; wu_get_template(
'wizards/setup/default',
wu_get_template('wizards/setup/default', array_merge($section, array( array_merge(
$section,
array(
'page' => $this, 'page' => $this,
))); )
)
} // end default_view; );
}
/** /**
* Renders the default submit box with action buttons at the bottom of the wizard. * 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() { 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(), 'screen' => get_current_screen(),
'page' => $this, 'page' => $this,
'labels' => $this->get_labels(), 'labels' => $this->get_labels(),
)); )
);
} // end render_submit_box; }
/** /**
* Wizard classes should implement a method that returns an array of sections and subsections. * 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 * @since 2.0.0
* @return array * @return array
*/ */
abstract public function get_sections(); // end get_sections; abstract public function get_sections();
}
} // end class Wizard_Admin_Page;

View File

@ -12,7 +12,7 @@ namespace WP_Ultimo\Admin_Pages\Customer_Panel;
// Exit if accessed directly // Exit if accessed directly
defined('ABSPATH') || exit; 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. * 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(); $this->register_page_settings();
if ($this->current_site->get_type() === 'customer_owned') { if ($this->current_site->get_type() === 'customer_owned') {
parent::__construct(); parent::__construct();
}
} // end if; }
} // end __construct;
/** /**
* Loads the current site and membership. * 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->current_membership = $this->current_site->get_membership();
$this->add_notices(); $this->add_notices();
}
} // end page_loaded;
/** /**
* Adds notices after a membership is changed. * 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'); $update_type = wu_request('updated');
if (empty($update_type)) { if (empty($update_type)) {
return; return;
}
} // end if;
$update_message = apply_filters('wu_account_update_message', __('Your account was successfully updated.', 'wp-ultimo'), $update_type); $update_message = apply_filters('wu_account_update_message', __('Your account was successfully updated.', 'wp-ultimo'), $update_type);
WP_Ultimo()->notices->add($update_message); WP_Ultimo()->notices->add($update_message);
}
} // end add_notices;
/** /**
* Allow child classes to add hooks to be run once the page is loaded. * 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 * @since 1.8.2
* @return void * @return void
*/ */
public function hooks() {} // end hooks; public function hooks() {}
/** /**
* Allow child classes to add screen options; Useful for pages that have list tables. * 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 * @since 1.8.2
* @return void * @return void
*/ */
public function screen_options() {} // end screen_options; public function screen_options() {}
/** /**
* Allow child classes to register widgets, if they need them. * 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\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)); \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. * Returns the title of the page.
@ -206,8 +198,7 @@ class Account_Admin_Page extends Base_Customer_Facing_Admin_Page {
public function get_title() { public function get_title() {
return __('Account', 'wp-ultimo'); return __('Account', 'wp-ultimo');
}
} // end get_title;
/** /**
* Returns the title of menu for this page. * 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() { public function get_menu_title() {
return __('Account', 'wp-ultimo'); return __('Account', 'wp-ultimo');
}
} // end get_menu_title;
/** /**
* Allows admins to rename the sub-menu (first item) for a top-level page. * 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() { public function get_submenu_title() {
return __('Account', 'wp-ultimo'); return __('Account', 'wp-ultimo');
}
} // end get_submenu_title;
/** /**
* Every child class should implement the output method to display the contents of the page. * 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 =) * 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(), 'screen' => get_current_screen(),
'page' => $this, 'page' => $this,
'has_full_position' => false, '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 // Exit if accessed directly
defined('ABSPATH') || exit; 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. * 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(); $this->register_page_settings();
if ($this->current_site->get_type() === 'customer_owned') { if ($this->current_site->get_type() === 'customer_owned') {
parent::__construct(); parent::__construct();
}
} // end if; }
} // end __construct;
/** /**
* Loads the current site and membership. * 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() { public function page_loaded() {
$this->customer = wu_get_current_customer(); $this->customer = wu_get_current_customer();
}
} // end page_loaded;
/** /**
* Allow child classes to add hooks to be run once the page is 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 * @since 1.8.2
* @return void * @return void
*/ */
public function hooks() {} // end hooks; public function hooks() {}
/** /**
* Force the screen options so our customize options show up. * 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() { public function force_screen_options() {
if (get_current_screen()->id !== 'toplevel_page_sites') { if (get_current_screen()->id !== 'toplevel_page_sites') {
return; return;
}
} // end if;
// Forces Screen options so we can add our links. // Forces Screen options so we can add our links.
add_screen_option('wu_fix', array( add_screen_option(
'wu_fix',
array(
'option' => 'test', 'option' => 'test',
'value' => true, 'value' => true,
)); )
);
} // end force_screen_options; }
/** /**
* Allow child classes to add screen options; Useful for pages that have list tables. * 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 * @since 1.8.2
* @return void * @return void
*/ */
public function screen_options() {} // end screen_options; public function screen_options() {}
/** /**
* Allow child classes to register widgets, if they need them. * 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\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', 'slug' => 'wu-add-new-site',
'membership_limitations' => array('sites'), 'membership_limitations' => array('sites'),
)); )
);
} // end register_widgets; }
/** /**
* Returns the title of the page. * 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() { public function get_title() {
return __('Add New Site', 'wp-ultimo'); return __('Add New Site', 'wp-ultimo');
}
} // end get_title;
/** /**
* Returns the title of menu for this page. * 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() { public function get_menu_title() {
return __('Add New Site', 'wp-ultimo'); return __('Add New Site', 'wp-ultimo');
}
} // end get_menu_title;
/** /**
* Allows admins to rename the sub-menu (first item) for a top-level page. * 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() { public function get_submenu_title() {
return __('Add New Site', 'wp-ultimo'); 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. * 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 =) * 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(), 'screen' => get_current_screen(),
'page' => $this, 'page' => $this,
'has_full_position' => false, '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() { public function get_title() {
return sprintf(__('Checkout', 'wp-ultimo')); return sprintf(__('Checkout', 'wp-ultimo'));
}
} // end get_title;
/** /**
* Returns the title of menu for this page. * 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() { public function get_menu_title() {
return __('Checkout', 'wp-ultimo'); return __('Checkout', 'wp-ultimo');
}
} // end get_menu_title;
/** /**
* Registers the necessary scripts. * 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() { public function register_scripts() {
do_action('wu_checkout_scripts', null, null); do_action('wu_checkout_scripts', null, null);
}
} // end register_scripts;
/** /**
* Overrides the page loaded method. * 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); do_action('wu_setup_checkout', null);
parent::page_loaded(); parent::page_loaded();
}
} // end page_loaded;
/** /**
* Returns the sections for this Wizard. * 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; return $sections;
}
} // end get_sections;
/** /**
* Displays the content of the activation section. * 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 =) * 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(), 'screen' => get_current_screen(),
'page' => $this, 'page' => $this,
'content' => do_shortcode('[wu_checkout slug="wu-checkout"]'), 'content' => do_shortcode('[wu_checkout slug="wu-checkout"]'),
)); )
);
} // end output; }
/** /**
* Allow child classes to register widgets, if they need them. * 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\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'); \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 // Exit if accessed directly
defined('ABSPATH') || exit; 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. * 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(); $this->register_page_settings();
if ($this->current_site->get_type() === 'customer_owned') { if ($this->current_site->get_type() === 'customer_owned') {
parent::__construct(); parent::__construct();
add_action('admin_menu', array($this, 'unset_default_my_sites_menu')); 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('admin_bar_menu', array($this, 'change_my_sites_link'), 90);
add_action('current_screen', array($this, 'force_screen_options')); add_action('current_screen', array($this, 'force_screen_options'));
}
} // end if; }
} // end __construct;
/** /**
* Loads the current site and membership. * 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() { public function page_loaded() {
$this->customer = wu_get_current_customer(); $this->customer = wu_get_current_customer();
}
} // end page_loaded;
/** /**
* Allow child classes to add hooks to be run once the page is 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 * @since 1.8.2
* @return void * @return void
*/ */
public function hooks() {} // end hooks; public function hooks() {}
/** /**
* Remove the default my sites link. * Remove the default my sites link.
@ -156,8 +152,7 @@ class My_Sites_Admin_Page extends Base_Customer_Facing_Admin_Page {
global $submenu; global $submenu;
unset($submenu['index.php'][5]); unset($submenu['index.php'][5]);
}
} // end unset_default_my_sites_menu;
/** /**
* Update the my sites link on the top-bar. * 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'); $my_sites = $wp_admin_bar->get_node('my-sites');
if (empty($my_sites)) { if (empty($my_sites)) {
return; return;
}
} // end if;
$args = array( $args = array(
'page' => 'sites', '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')); $my_sites->href = add_query_arg($args, admin_url('admin.php'));
$wp_admin_bar->add_node($my_sites); $wp_admin_bar->add_node($my_sites);
}
} // end change_my_sites_link;
/** /**
* Force the screen options so our customize options show up. * 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() { public function force_screen_options() {
if (get_current_screen()->id !== 'toplevel_page_sites') { if (get_current_screen()->id !== 'toplevel_page_sites') {
return; return;
}
} // end if;
// Forces Screen options so we can add our links. // Forces Screen options so we can add our links.
add_screen_option('wu_fix', array( add_screen_option(
'wu_fix',
array(
'option' => 'test', 'option' => 'test',
'value' => true, 'value' => true,
)); )
);
} // end force_screen_options; }
/** /**
* Allow child classes to add screen options; Useful for pages that have list tables. * 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 * @since 1.8.2
* @return void * @return void
*/ */
public function screen_options() {} // end screen_options; public function screen_options() {}
/** /**
* Allow child classes to register widgets, if they need them. * 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\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'); \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. * 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() { public function get_title() {
return __('My Sites', 'wp-ultimo'); return __('My Sites', 'wp-ultimo');
}
} // end get_title;
/** /**
* Returns the title of menu for this page. * 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() { public function get_menu_title() {
return __('My Sites', 'wp-ultimo'); return __('My Sites', 'wp-ultimo');
}
} // end get_menu_title;
/** /**
* Allows admins to rename the sub-menu (first item) for a top-level page. * 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() { public function get_submenu_title() {
return __('My Sites', 'wp-ultimo'); return __('My Sites', 'wp-ultimo');
}
} // end get_submenu_title;
/** /**
* Every child class should implement the output method to display the contents of the page. * 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 =) * 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(), 'screen' => get_current_screen(),
'page' => $this, 'page' => $this,
'has_full_position' => false, '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() { public function get_title() {
return __('Switch Template', 'wp-ultimo'); return __('Switch Template', 'wp-ultimo');
}
} // end get_title;
/** /**
* Returns the title of menu for this page. * 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() { public function get_menu_title() {
return __('Switch Template', 'wp-ultimo'); return __('Switch Template', 'wp-ultimo');
}
} // end get_menu_title;
/** /**
* Registers the necessary scripts. * Registers the necessary scripts.
@ -128,8 +126,7 @@ class Template_Switching_Admin_Page extends \WP_Ultimo\Admin_Pages\Base_Customer
public function register_scripts() { public function register_scripts() {
do_action('wu_template_switching_admin_page_scripts', null, null); do_action('wu_template_switching_admin_page_scripts', null, null);
}
} // end register_scripts;
/** /**
* Overrides the page loaded method. * 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); do_action('wu_template_switching_admin_page', null);
parent::page_loaded(); parent::page_loaded();
}
} // end page_loaded;
/** /**
* Displays the content of the activation section. * 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 =) * 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(), 'screen' => get_current_screen(),
'page' => $this, 'page' => $this,
'content' => '', 'content' => '',
'labels' => array( '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. * 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() { public function register_widgets() {
\WP_Ultimo\UI\Template_Switching_Element::get_instance()->as_metabox(get_current_screen()->id); \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', 'normal',
null null
); );
}
} // end register_widgets;
/** /**
* Renders the list of WP Multisite WaaS registered pages. * 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">'; echo '<ul class="wu-flex wu-flex-wrap wu--mx-1">';
foreach ($pages as $page_id => $url) { foreach ($pages as $page_id => $url) {
printf(
echo sprintf(' '
<li class="wu-w-1/2 wu-box-border"> <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> <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> </li>
', $url, $page_id); ',
$url,
} // end foreach; $page_id
);
}
echo '</ul>'; echo '</ul>';
}
} // end render_debug_pages;
/** /**
* Returns the title of the page. * Returns the title of the page.
@ -127,8 +127,7 @@ class Debug_Admin_Page extends Base_Admin_Page {
public function get_title() { public function get_title() {
return __('Registered Pages', 'wp-ultimo'); return __('Registered Pages', 'wp-ultimo');
}
} // end get_title;
/** /**
* Returns the title of menu for this page. * 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() { public function get_menu_title() {
return __('Registered Pages', 'wp-ultimo'); return __('Registered Pages', 'wp-ultimo');
}
} // end get_menu_title;
/** /**
* Allows admins to rename the sub-menu (first item) for a top-level page. * 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() { public function get_submenu_title() {
return __('Registered Pages', 'wp-ultimo'); return __('Registered Pages', 'wp-ultimo');
}
} // end get_submenu_title;
/** /**
* Every child class should implement the output method to display the contents of the page. * 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() { public function output() {
wu_get_template('base/dash', array( wu_get_template(
'base/dash',
array(
'page' => $this, 'page' => $this,
'screen' => get_current_screen(), 'screen' => get_current_screen(),
'has_full_position' => false, 'has_full_position' => false,
)); )
);
} // end output; }
}
} // end class Debug_Admin_Page;

View File

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

View File

@ -46,8 +46,7 @@ trait Rest_Api {
public function get_rest_base() { public function get_rest_base() {
return (! empty($this->rest_base)) ? $this->rest_base : $this->slug; return (! empty($this->rest_base)) ? $this->rest_base : $this->slug;
}
} // end get_rest_base;
/** /**
* Registers the routes. Should be called by the entity * 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(); $is_enabled = \WP_Ultimo\API::get_instance()->is_api_enabled();
if ($is_enabled) { if ($is_enabled) {
add_action('rest_api_init', array($this, 'register_routes_general')); add_action('rest_api_init', array($this, 'register_routes_general'));
add_action('rest_api_init', array($this, 'register_routes_with_id')); 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, * Register the endpoints that don't need an ID,
@ -80,7 +76,6 @@ trait Rest_Api {
$routes = array(); $routes = array();
if (in_array('get_items', $this->enabled_rest_endpoints, true)) { if (in_array('get_items', $this->enabled_rest_endpoints, true)) {
$routes = array( $routes = array(
array( array(
'methods' => \WP_REST_Server::READABLE, 'methods' => \WP_REST_Server::READABLE,
@ -88,34 +83,28 @@ trait Rest_Api {
'permission_callback' => array($this, 'get_items_permissions_check'), 'permission_callback' => array($this, 'get_items_permissions_check'),
), ),
); );
}
} // end if;
if (in_array('create_item', $this->enabled_rest_endpoints, true)) { if (in_array('create_item', $this->enabled_rest_endpoints, true)) {
$routes[] = array( $routes[] = array(
'methods' => \WP_REST_Server::CREATABLE, 'methods' => \WP_REST_Server::CREATABLE,
'callback' => array($this, 'create_item_rest'), 'callback' => array($this, 'create_item_rest'),
'permission_callback' => array($this, 'create_item_permissions_check'), 'permission_callback' => array($this, 'create_item_permissions_check'),
'args' => $this->get_arguments_schema() 'args' => $this->get_arguments_schema(),
); );
}
} // end if;
if ( ! empty($routes)) { if ( ! empty($routes)) {
register_rest_route( register_rest_route(
\WP_Ultimo\API::get_instance()->get_namespace(), \WP_Ultimo\API::get_instance()->get_namespace(),
'/' . $this->get_rest_base(), '/' . $this->get_rest_base(),
$routes, $routes,
true true
); );
}
} // end if;
do_action('wu_rest_register_routes_general', $routes, $this->get_rest_base(), 'create', $this); 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, * Register the endpoints that need an ID,
@ -128,50 +117,41 @@ trait Rest_Api {
$routes = array(); $routes = array();
if (in_array('get_item', $this->enabled_rest_endpoints, true)) { if (in_array('get_item', $this->enabled_rest_endpoints, true)) {
$routes[] = array( $routes[] = array(
'methods' => \WP_REST_Server::READABLE, 'methods' => \WP_REST_Server::READABLE,
'callback' => array($this, 'get_item_rest'), 'callback' => array($this, 'get_item_rest'),
'permission_callback' => array($this, 'get_item_permissions_check'), 'permission_callback' => array($this, 'get_item_permissions_check'),
); );
}
} // end if;
if (in_array('update_item', $this->enabled_rest_endpoints, true)) { if (in_array('update_item', $this->enabled_rest_endpoints, true)) {
$routes[] = array( $routes[] = array(
'methods' => \WP_REST_Server::EDITABLE, 'methods' => \WP_REST_Server::EDITABLE,
'callback' => array($this, 'update_item_rest'), 'callback' => array($this, 'update_item_rest'),
'permission_callback' => array($this, 'update_item_permissions_check'), '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)) { if (in_array('delete_item', $this->enabled_rest_endpoints, true)) {
$routes[] = array( $routes[] = array(
'methods' => \WP_REST_Server::DELETABLE, 'methods' => \WP_REST_Server::DELETABLE,
'callback' => array($this, 'delete_item_rest'), 'callback' => array($this, 'delete_item_rest'),
'permission_callback' => array($this, 'delete_item_permissions_check'), 'permission_callback' => array($this, 'delete_item_permissions_check'),
); );
}
} // end if;
if ( ! empty($routes)) { if ( ! empty($routes)) {
register_rest_route( register_rest_route(
\WP_Ultimo\API::get_instance()->get_namespace(), \WP_Ultimo\API::get_instance()->get_namespace(),
'/' . $this->get_rest_base() . '/(?P<id>[\d]+)', '/' . $this->get_rest_base() . '/(?P<id>[\d]+)',
$routes, $routes,
true true
); );
}
} // end if;
do_action('wu_rest_register_routes_with_id', $routes, $this->get_rest_base(), 'update', $this); do_action('wu_rest_register_routes_with_id', $routes, $this->get_rest_base(), 'update', $this);
}
} // end register_routes_with_id;
/** /**
* Returns a specific item. * Returns a specific item.
* *
@ -185,14 +165,11 @@ trait Rest_Api {
$item = $this->model_class::get_by_id($request['id']); $item = $this->model_class::get_by_id($request['id']);
if (empty($item)) { if (empty($item)) {
return new \WP_Error("wu_rest_{$this->slug}_invalid_id", __('Item not found.', 'wp-ultimo'), array('status' => 404)); 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); return rest_ensure_response($item);
}
} // end get_item_rest;
/** /**
* Returns a list of items. * Returns a list of items.
* *
@ -206,8 +183,7 @@ trait Rest_Api {
$items = $this->model_class::query($request->get_params()); $items = $this->model_class::query($request->get_params());
return rest_ensure_response($items); return rest_ensure_response($items);
}
} // end get_items_rest;
/** /**
* Creates an item. * Creates an item.
* *
@ -225,34 +201,25 @@ trait Rest_Api {
$saver_function = "wu_create_{$model_name}"; $saver_function = "wu_create_{$model_name}";
if (function_exists($saver_function)) { if (function_exists($saver_function)) {
$item = call_user_func($saver_function, $body); $item = call_user_func($saver_function, $body);
$saved = is_wp_error($item) ? $item : true; $saved = is_wp_error($item) ? $item : true;
} else { } else {
$item = new $this->model_class($body); $item = new $this->model_class($body);
$saved = $item->save(); $saved = $item->save();
}
} // end if;
if (is_wp_error($saved)) { if (is_wp_error($saved)) {
return rest_ensure_response($saved); return rest_ensure_response($saved);
}
} // end if;
if ( ! $saved) { if ( ! $saved) {
return new \WP_Error("wu_rest_{$this->slug}", __('Something went wrong (Code 1).', 'wp-ultimo'), array('status' => 400)); 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); return rest_ensure_response($item);
}
} // end create_item_rest;
/** /**
* Updates an item. * Updates an item.
* *
@ -268,10 +235,8 @@ trait Rest_Api {
$item = $this->model_class::get_by_id($id); $item = $this->model_class::get_by_id($id);
if (empty($item)) { if (empty($item)) {
return new \WP_Error("wu_rest_{$this->slug}_invalid_id", __('Item not found.', 'wp-ultimo'), array('status' => 404)); return new \WP_Error("wu_rest_{$this->slug}_invalid_id", __('Item not found.', 'wp-ultimo'), array('status' => 404));
}
} // end if;
$params = array_filter( $params = array_filter(
json_decode($request->get_body(), true), json_decode($request->get_body(), true),
@ -280,19 +245,13 @@ trait Rest_Api {
); );
foreach ($params as $param => $value) { foreach ($params as $param => $value) {
$set_method = "set_{$param}"; $set_method = "set_{$param}";
if ($param === 'meta') { if ($param === 'meta') {
$item->update_meta_batch($value); $item->update_meta_batch($value);
} elseif (method_exists($item, $set_method)) { } elseif (method_exists($item, $set_method)) {
call_user_func(array($item, $set_method), $value); call_user_func(array($item, $set_method), $value);
} else { } else {
$error_message = sprintf( $error_message = sprintf(
/* translators: 1. Object class name; 2. Set method name */ /* translators: 1. Object class name; 2. Set method name */
__('The %1$s object does not have a %2$s method', 'wp-ultimo'), __('The %1$s object does not have a %2$s method', 'wp-ultimo'),
@ -305,28 +264,21 @@ trait Rest_Api {
$error_message, $error_message,
array('status' => 400) array('status' => 400)
); );
}
} // end if; }
} // end foreach;
$saved = $item->save(); $saved = $item->save();
if (is_wp_error($saved)) { if (is_wp_error($saved)) {
return rest_ensure_response($saved); return rest_ensure_response($saved);
}
} // end if;
if ( ! $saved) { if ( ! $saved) {
return new \WP_Error("wu_rest_{$this->slug}", __('Something went wrong (Code 2).', 'wp-ultimo')); return new \WP_Error("wu_rest_{$this->slug}", __('Something went wrong (Code 2).', 'wp-ultimo'));
}
} // end if;
return rest_ensure_response($item); return rest_ensure_response($item);
}
} // end update_item_rest;
/** /**
* Deletes an item. * Deletes an item.
* *
@ -340,16 +292,13 @@ trait Rest_Api {
$item = $this->model_class::get_by_id($request['id']); $item = $this->model_class::get_by_id($request['id']);
if (empty($item)) { if (empty($item)) {
return new \WP_Error("wu_rest_{$this->slug}_invalid_id", __('Item not found.', 'wp-ultimo'), array('status' => 404)); return new \WP_Error("wu_rest_{$this->slug}_invalid_id", __('Item not found.', 'wp-ultimo'), array('status' => 404));
}
} // end if;
$result = $item->delete(); $result = $item->delete();
return rest_ensure_response($result); return rest_ensure_response($result);
}
} // end delete_item_rest;
/** /**
* Check permissions to list items. * Check permissions to list items.
@ -362,10 +311,8 @@ trait Rest_Api {
public function get_items_permissions_check($request) { public function get_items_permissions_check($request) {
if ( ! \WP_Ultimo\API::get_instance()->check_authorization($request)) { if ( ! \WP_Ultimo\API::get_instance()->check_authorization($request)) {
return false; return false;
}
} // end if;
/** /**
* Filters if it is allowed to proceed with the request or not. * 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. * @param Base_Manager $this The object instance.
*/ */
return apply_filters('wu_rest_get_items', true, $this->get_rest_base(), $this); return apply_filters('wu_rest_get_items', true, $this->get_rest_base(), $this);
}
} // end get_items_permissions_check;
/** /**
* Check permissions to create an item. * Check permissions to create an item.
@ -391,10 +337,8 @@ trait Rest_Api {
public function create_item_permissions_check($request) { public function create_item_permissions_check($request) {
if ( ! \WP_Ultimo\API::get_instance()->check_authorization($request)) { if ( ! \WP_Ultimo\API::get_instance()->check_authorization($request)) {
return false; return false;
}
} // end if;
/** /**
* Filters if it is allowed to proceed with the request or not. * 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. * @param Base_Manager $this The object instance.
*/ */
return apply_filters('wu_rest_create_item', true, $this->get_rest_base(), $this); return apply_filters('wu_rest_create_item', true, $this->get_rest_base(), $this);
}
} // end create_item_permissions_check;
/** /**
* Check permissions to get an item. * Check permissions to get an item.
@ -420,10 +363,8 @@ trait Rest_Api {
public function get_item_permissions_check($request) { public function get_item_permissions_check($request) {
if ( ! \WP_Ultimo\API::get_instance()->check_authorization($request)) { if ( ! \WP_Ultimo\API::get_instance()->check_authorization($request)) {
return false; return false;
}
} // end if;
/** /**
* Filters if it is allowed to proceed with the request or not. * 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. * @param Base_Manager $this The object instance.
*/ */
return apply_filters('wu_rest_get_item', true, $this->get_rest_base(), $this); return apply_filters('wu_rest_get_item', true, $this->get_rest_base(), $this);
}
} // end get_item_permissions_check;
/** /**
* Check permissions to update an item. * Check permissions to update an item.
@ -449,10 +389,8 @@ trait Rest_Api {
public function update_item_permissions_check($request) { public function update_item_permissions_check($request) {
if ( ! \WP_Ultimo\API::get_instance()->check_authorization($request)) { if ( ! \WP_Ultimo\API::get_instance()->check_authorization($request)) {
return false; return false;
}
} // end if;
/** /**
* Filters if it is allowed to proceed with the request or not. * 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. * @param Base_Manager $this The object instance.
*/ */
return apply_filters('wu_rest_update_item', true, $this->get_rest_base(), $this); return apply_filters('wu_rest_update_item', true, $this->get_rest_base(), $this);
}
} // end update_item_permissions_check;
/** /**
* Check permissions to delete an item. * Check permissions to delete an item.
@ -478,10 +415,8 @@ trait Rest_Api {
public function delete_item_permissions_check($request) { public function delete_item_permissions_check($request) {
if ( ! \WP_Ultimo\API::get_instance()->check_authorization($request)) { if ( ! \WP_Ultimo\API::get_instance()->check_authorization($request)) {
return false; return false;
}
} // end if;
/** /**
* Filters if it is allowed to proceed with the request or not. * 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. * @param Base_Manager $this The object instance.
*/ */
return apply_filters('wu_rest_delete_item', true, $this->get_rest_base(), $this); 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. * Checks if a value is not a credential key.
@ -514,8 +448,7 @@ trait Rest_Api {
); );
return ! in_array($value, $credentials_keys, true); return ! in_array($value, $credentials_keys, true);
}
} // end is_not_credential_key;
/** /**
* Checks if a value is not equal to "id". * Checks if a value is not equal to "id".
@ -532,17 +465,14 @@ trait Rest_Api {
); );
if ($this->slug === 'site') { if ($this->slug === 'site') {
$arr = array( $arr = array(
'id', 'id',
'blog_id', 'blog_id',
); );
}
} // end if;
return ! in_array($value, $arr, true); return ! in_array($value, $arr, true);
}
} // end is_not_id_key;
/** /**
* Get the arguments for an endpoint * 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); $args = array_filter($schema, array($this, 'is_not_id_key'), ARRAY_FILTER_USE_KEY);
return $this->filter_schema_arguments($args); return $this->filter_schema_arguments($args);
}
} // end get_arguments_schema;
/** /**
* Remove some properties from the API 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); apply_filters('wu_before_' . $this->slug . '_api_arguments', $args, $this);
if ($this->slug !== 'broadcast' && isset($args['author_id'])) { if ($this->slug !== 'broadcast' && isset($args['author_id'])) {
unset($args['author_id']); unset($args['author_id']);
}
} // end if;
if (isset($args['list_order'])) { if (isset($args['list_order'])) {
unset($args['list_order']); unset($args['list_order']);
}
} // end if; $remove_status = apply_filters(
"wu_api_{$this->slug}_remove_status",
$remove_status = apply_filters("wu_api_{$this->slug}_remove_status", array( array(
'broadcast', 'broadcast',
'membership', 'membership',
'product', 'product',
'payment', 'payment',
)); )
);
if ( ! in_array($this->slug, $remove_status, true) && isset($args['status'])) { if ( ! in_array($this->slug, $remove_status, true) && isset($args['status'])) {
unset($args['status']); unset($args['status']);
}
} // end if; $remove_slug = apply_filters(
"wu_api_{$this->slug}_remove_slug",
$remove_slug = apply_filters("wu_api_{$this->slug}_remove_slug", array( array(
'broadcast', 'broadcast',
'product', 'product',
'checkout_form', 'checkout_form',
'event', 'event',
)); )
);
if ( ! in_array($this->slug, $remove_slug, true) && isset($args['slug'])) { if ( ! in_array($this->slug, $remove_slug, true) && isset($args['slug'])) {
unset($args['slug']); unset($args['slug']);
}
} // end if;
if ($this->slug === 'product' && isset($args['price_variations'])) { if ($this->slug === 'product' && isset($args['price_variations'])) {
unset($args['price_variations']); unset($args['price_variations']);
}
} // end if;
if ($this->slug === 'payment' && isset($args['line_items'])) { if ($this->slug === 'payment' && isset($args['line_items'])) {
unset($args['line_items']); unset($args['line_items']);
}
} // end if;
if ($this->slug === 'site') { if ($this->slug === 'site') {
if (isset($args['duplication_arguments'])) { if (isset($args['duplication_arguments'])) {
unset($args['duplication_arguments']); unset($args['duplication_arguments']);
}
} // end if;
if (isset($args['transient'])) { if (isset($args['transient'])) {
unset($args['transient']); unset($args['transient']);
}
} // end if; }
} // end if;
if ($this->slug === 'email') { if ($this->slug === 'email') {
if (isset($args['status'])) { if (isset($args['status'])) {
unset($args['status']); unset($args['status']);
}
} // end if;
if (isset($args['email_schedule'])) { if (isset($args['email_schedule'])) {
unset($args['email_schedule']); unset($args['email_schedule']);
}
} // end if; }
} // end if;
if ($this->slug === 'broadcast') { if ($this->slug === 'broadcast') {
if (isset($args['message_targets'])) { if (isset($args['message_targets'])) {
unset($args['message_targets']); unset($args['message_targets']);
}
} // end if; }
} // end if;
if (isset($args['billing_address'])) { if (isset($args['billing_address'])) {
unset($args['billing_address']); unset($args['billing_address']);
}
} // end if;
/** /**
* Filter after being changed. * Filter after being changed.
@ -691,7 +596,5 @@ trait Rest_Api {
apply_filters('wu_after_' . $this->slug . '_api_arguments', $args, $this); apply_filters('wu_after_' . $this->slug . '_api_arguments', $args, $this);
return $args; 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() { public function get_wp_cli_command_base() {
return (! empty($this->wp_cli_command_base)) ? $this->wp_cli_command_base : $this->slug; 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 * Registers the routes. Should be called by the entity
@ -52,17 +51,14 @@ trait WP_CLI {
public function enable_wp_cli() { public function enable_wp_cli() {
if ( ! defined('WP_CLI')) { if ( ! defined('WP_CLI')) {
return; return;
}
} // end if;
$wp_cli_root = 'wu'; $wp_cli_root = 'wu';
$this->set_wp_cli_enabled_sub_commands(); $this->set_wp_cli_enabled_sub_commands();
foreach ($this->wp_cli_enabled_sub_commands as $sub_command => $sub_command_data) { foreach ($this->wp_cli_enabled_sub_commands as $sub_command => $sub_command_data) {
\WP_CLI::add_command( \WP_CLI::add_command(
"{$wp_cli_root} {$this->get_wp_cli_command_base()} {$sub_command}", "{$wp_cli_root} {$this->get_wp_cli_command_base()} {$sub_command}",
$sub_command_data['callback'], $sub_command_data['callback'],
@ -70,10 +66,8 @@ trait WP_CLI {
'synopsis' => $sub_command_data['synopsis'], 'synopsis' => $sub_command_data['synopsis'],
) )
); );
}
} // end foreach; }
} // end enable_wp_cli;
/** /**
* Set wP-CLI Sub-command enabled for this entity. * Set wP-CLI Sub-command enabled for this entity.
@ -105,34 +99,32 @@ trait WP_CLI {
/** /**
* Unset undesired Params. * 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', 'id',
'model', 'model',
)); )
);
$params = array_filter($params, fn($param) => ! in_array($param, $params_to_remove, true)); $params = array_filter($params, fn($param) => ! in_array($param, $params_to_remove, true));
foreach ($sub_commands as $sub_command => &$sub_command_data) { foreach ($sub_commands as $sub_command => &$sub_command_data) {
$sub_command_data['synopsis'] = array(); $sub_command_data['synopsis'] = array();
if (in_array($sub_command, array('get', 'update', 'delete'), true)) { if (in_array($sub_command, array('get', 'update', 'delete'), true)) {
$sub_command_data['synopsis'][] = array( $sub_command_data['synopsis'][] = array(
'name' => 'id', 'name' => 'id',
'type' => 'positional', 'type' => 'positional',
'description' => __('The id for the resource.', 'wp-ultimo'), 'description' => __('The id for the resource.', 'wp-ultimo'),
'optional' => false, 'optional' => false,
); );
}
} // end if;
if (in_array($sub_command, array('list', 'update', 'create'), true)) { if (in_array($sub_command, array('list', 'update', 'create'), true)) {
$explanation_list = wu_rest_get_endpoint_schema($this->model_class, 'update'); $explanation_list = wu_rest_get_endpoint_schema($this->model_class, 'update');
foreach ($params as $name) { foreach ($params as $name) {
$explanation = wu_get_isset($explanation_list, $name, array()); $explanation = wu_get_isset($explanation_list, $name, array());
$type = wu_get_isset($explanation, 'type', 'assoc'); $type = wu_get_isset($explanation, 'type', 'assoc');
@ -147,30 +139,23 @@ trait WP_CLI {
$options = wu_get_isset($explanation, 'options', array()); $options = wu_get_isset($explanation, 'options', array());
if ($options) { if ($options) {
$field['options'] = $options; $field['options'] = $options;
}
} // end if;
$sub_command_data['synopsis'][] = $field; $sub_command_data['synopsis'][] = $field;
}
} // end foreach; }
} // end if;
if (in_array($sub_command, array('create', 'update'), true)) { if (in_array($sub_command, array('create', 'update'), true)) {
$sub_command_data['synopsis'][] = array( $sub_command_data['synopsis'][] = array(
'name' => 'porcelain', 'name' => 'porcelain',
'type' => 'flag', 'type' => 'flag',
'description' => __('Output just the id when the operation is successful.', 'wp-ultimo'), 'description' => __('Output just the id when the operation is successful.', 'wp-ultimo'),
'optional' => true, 'optional' => true,
); );
}
} // end if;
if (in_array($sub_command, array('list', 'get'), true)) { if (in_array($sub_command, array('list', 'get'), true)) {
$sub_command_data['synopsis'][] = array( $sub_command_data['synopsis'][] = array(
'name' => 'format', 'name' => 'format',
'type' => 'assoc', 'type' => 'assoc',
@ -194,10 +179,8 @@ trait WP_CLI {
'optional' => true, 'optional' => true,
'options' => array_merge(array('id'), $params), 'options' => array_merge(array('id'), $params),
); );
}
} // end if; }
} // end foreach;
$this->wp_cli_enabled_sub_commands = $sub_commands; $this->wp_cli_enabled_sub_commands = $sub_commands;
@ -216,8 +199,7 @@ trait WP_CLI {
$this->get_wp_cli_command_base(), $this->get_wp_cli_command_base(),
$this $this
); );
}
} // end set_wp_cli_enabled_sub_commands;
/** /**
* Allows the additional of additional parameters. * Allows the additional of additional parameters.
* *
@ -228,8 +210,7 @@ trait WP_CLI {
$model = new $this->model_class(); $model = new $this->model_class();
return array_keys($model->to_array()); return array_keys($model->to_array());
}
} // end wp_cli_extra_parameters;
/** /**
* Returns the list of default fields, based on the table schema. * Returns the list of default fields, based on the table schema.
@ -242,8 +223,7 @@ trait WP_CLI {
$schema = $this->model_class::get_schema(); $schema = $this->model_class::get_schema();
return array_column($schema, 'name'); return array_column($schema, 'name');
}
} // end wp_cli_get_fields;
/** /**
* Returns a specific item. * Returns a specific item.
@ -258,18 +238,15 @@ trait WP_CLI {
$item = $this->model_class::get_by_id($args[0]); $item = $this->model_class::get_by_id($args[0]);
if (empty($item)) { if (empty($item)) {
\WP_CLI::error('Invalid ID.'); \WP_CLI::error('Invalid ID.');
}
} // end if;
$fields = (! empty($array_assoc['fields'])) ? $array_assoc['fields'] : $this->wp_cli_get_fields(); $fields = (! empty($array_assoc['fields'])) ? $array_assoc['fields'] : $this->wp_cli_get_fields();
$formatter = new \WP_CLI\Formatter($array_assoc, $fields); $formatter = new \WP_CLI\Formatter($array_assoc, $fields);
$formatter->display_item($item->to_array()); $formatter->display_item($item->to_array());
}
} // end wp_cli_get_item;
/** /**
* Returns a list of items. * Returns a list of items.
@ -290,8 +267,7 @@ trait WP_CLI {
$items = array_map(fn($item) => $item->to_array(), $items); $items = array_map(fn($item) => $item->to_array(), $items);
\WP_CLI\Utils\format_items($array_assoc['format'], $items, $fields); \WP_CLI\Utils\format_items($array_assoc['format'], $items, $fields);
}
} // end wp_cli_get_items;
/** /**
* Creates an item. * Creates an item.
@ -308,28 +284,19 @@ trait WP_CLI {
$success = $item->save(); $success = $item->save();
if ($success === true) { if ($success === true) {
$item_id = $item->get_id(); $item_id = $item->get_id();
if ( ! empty($array_assoc['porcelain'])) { if ( ! empty($array_assoc['porcelain'])) {
\WP_CLI::line($item_id); \WP_CLI::line($item_id);
} else { } else {
$message = sprintf('Item created with ID %d', $item_id); $message = sprintf('Item created with ID %d', $item_id);
\WP_CLI::success($message); \WP_CLI::success($message);
}
} // end if;
} else { } else {
\WP_CLI::error($success); \WP_CLI::error($success);
}
} // end if; }
} // end wp_cli_create_item;
/** /**
* Updates an item. * Updates an item.
@ -344,37 +311,27 @@ trait WP_CLI {
$item = $this->model_class::get_by_id($args[0]); $item = $this->model_class::get_by_id($args[0]);
if (empty($item)) { if (empty($item)) {
\WP_CLI::error('Invalid ID.'); \WP_CLI::error('Invalid ID.');
}
} // end if;
$porcelain = false; $porcelain = false;
if ( ! empty($array_assoc['porcelain'])) { if ( ! empty($array_assoc['porcelain'])) {
$porcelain = true; $porcelain = true;
unset($array_assoc['porcelain']); unset($array_assoc['porcelain']);
}
} // end if;
$params = $array_assoc; $params = $array_assoc;
foreach ($params as $param => $value) { foreach ($params as $param => $value) {
$set_method = "set_{$param}"; $set_method = "set_{$param}";
if ($param === 'meta') { if ($param === 'meta') {
$item->update_meta_batch($value); $item->update_meta_batch($value);
} elseif (method_exists($item, $set_method)) { } elseif (method_exists($item, $set_method)) {
call_user_func(array($item, $set_method), $value); call_user_func(array($item, $set_method), $value);
} else { } else {
$error_message = sprintf( $error_message = sprintf(
/* translators: 1. Object class name; 2. Set method name */ /* translators: 1. Object class name; 2. Set method name */
__('The %1$s object does not have a %2$s method', 'wp-ultimo'), __('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); \WP_CLI::error($error_message);
}
} // end if; }
} // end foreach;
$success = $item->save(); $success = $item->save();
if ($success) { if ($success) {
$item_id = $item->get_id(); $item_id = $item->get_id();
if ($porcelain) { if ($porcelain) {
\WP_CLI::line($item_id); \WP_CLI::line($item_id);
} else { } else {
$message = sprintf('Item updated with ID %d', $item_id); $message = sprintf('Item updated with ID %d', $item_id);
\WP_CLI::success($message); \WP_CLI::success($message);
}
} // end if;
} else { } else {
\WP_CLI::error('Unexpected error. The item was not updated.'); \WP_CLI::error('Unexpected error. The item was not updated.');
}
} // end if; }
} // end wp_cli_update_item;
/** /**
* Deletes an item. * Deletes an item.
@ -426,23 +372,15 @@ trait WP_CLI {
$item = $this->model_class::get_by_id($args[0]); $item = $this->model_class::get_by_id($args[0]);
if (empty($item)) { if (empty($item)) {
\WP_CLI::error('Invalid ID.'); \WP_CLI::error('Invalid ID.');
}
} // end if;
$success = $item->delete(); $success = $item->delete();
if (is_wp_error($success) || ! $success) { if (is_wp_error($success) || ! $success) {
\WP_CLI::error('Unexpected error. The item was not deleted.'); \WP_CLI::error('Unexpected error. The item was not deleted.');
} else { } else {
\WP_CLI::success('Item deleted.'); \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) { function wu_fields_to_block_options(fields, props) {
@ -72,7 +72,7 @@
field_slug = _.first(_.keys(sub_fields)); field_slug = _.first(_.keys(sub_fields));
} // end if; }
const component = wu_get_field_component(field.type, field); const component = wu_get_field_component(field.type, field);
@ -80,7 +80,7 @@
field.required = {}; field.required = {};
} // end if; }
let should_display = true; let should_display = true;
@ -113,7 +113,7 @@
}, },
})); }));
} // end if; }
/* /*
* Handle header types differently * Handle header types differently
@ -126,7 +126,7 @@
new_panel = true; new_panel = true;
} // end if; }
if (new_panel) { if (new_panel) {
@ -141,7 +141,7 @@
first_panel = false; first_panel = false;
} // end if; }
current_panel = field; current_panel = field;
@ -149,7 +149,7 @@
gt_fields = []; gt_fields = [];
} // end if; }
}); });
@ -164,7 +164,7 @@
return el(InspectorControls, { key: 'wp-ultimo' }, gt_panels); return el(InspectorControls, { key: 'wp-ultimo' }, gt_panels);
} // end wu_fields_to_block_options; }
function wu_format_options(options) { function wu_format_options(options) {
@ -205,7 +205,7 @@
component = NumberControl; component = NumberControl;
} // end if; }
break; break;
@ -233,7 +233,7 @@
break; break;
} // end switch; }
return component; return component;

View File

@ -12,7 +12,7 @@ namespace WP_Ultimo\Builders\Block_Editor;
// Exit if accessed directly // Exit if accessed directly
defined('ABSPATH') || exit; defined('ABSPATH') || exit;
use \WP_Ultimo\Database\Sites\Site_Type; use WP_Ultimo\Database\Sites\Site_Type;
/** /**
* Handles Block Editor Widget Support. * Handles Block Editor Widget Support.
@ -32,16 +32,13 @@ class Block_Editor_Widget_Manager {
public function init() { public function init() {
if (\WP_Ultimo\Compat\Gutenberg_Support::get_instance()->should_load()) { if (\WP_Ultimo\Compat\Gutenberg_Support::get_instance()->should_load()) {
add_action('wu_element_loaded', array($this, 'handle_element')); add_action('wu_element_loaded', array($this, 'handle_element'));
add_action('init', array($this, 'register_scripts')); add_action('init', array($this, 'register_scripts'));
add_action('wu_element_is_preview', array($this, 'is_block_preview')); add_action('wu_element_is_preview', array($this, 'is_block_preview'));
}
} // end if; }
} // end init;
/** /**
* Adds the required scripts. * Adds the required scripts.
@ -56,8 +53,7 @@ class Block_Editor_Widget_Manager {
$blocks = apply_filters('wu_blocks', array()); $blocks = apply_filters('wu_blocks', array());
wp_localize_script('wu-blocks', 'wu_blocks', $blocks); wp_localize_script('wu-blocks', 'wu_blocks', $blocks);
}
} // end register_scripts;
/** /**
* Checks if we are inside a block preview render. * 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) { public function is_block_preview($is_preview) {
if (defined('REST_REQUEST') && true === REST_REQUEST && 'edit' === filter_input(INPUT_GET, 'context', FILTER_SANITIZE_STRING)) { if (defined('REST_REQUEST') && true === REST_REQUEST && 'edit' === filter_input(INPUT_GET, 'context', FILTER_SANITIZE_STRING)) {
$is_preview = true; $is_preview = true;
}
} // end if;
return $is_preview; return $is_preview;
}
} // end is_block_preview;
/** /**
* Gets called when a new element is registered * Gets called when a new element is registered
@ -89,16 +82,13 @@ class Block_Editor_Widget_Manager {
public function handle_element($element) { public function handle_element($element) {
if (wu_get_current_site()->get_type() === Site_Type::CUSTOMER_OWNED) { if (wu_get_current_site()->get_type() === Site_Type::CUSTOMER_OWNED) {
return; return;
}
} // end if;
$this->register_block($element); $this->register_block($element);
add_filter('wu_blocks', fn($blocks) => $this->load_block_settings($blocks, $element)); add_filter('wu_blocks', fn($blocks) => $this->load_block_settings($blocks, $element));
}
} // end handle_element;
/** /**
* Registers block with WordPress. * Registers block with WordPress.
@ -111,20 +101,20 @@ class Block_Editor_Widget_Manager {
public function register_block($element) { public function register_block($element) {
if (\WP_Block_Type_Registry::get_instance()->is_registered($element->get_id())) { if (\WP_Block_Type_Registry::get_instance()->is_registered($element->get_id())) {
return; return;
}
} // end if;
$attributes = $this->get_attributes_from_fields($element); $attributes = $this->get_attributes_from_fields($element);
register_block_type($element->get_id(), array( register_block_type(
$element->get_id(),
array(
'attributes' => $attributes, 'attributes' => $attributes,
'editor_script' => 'wu-blocks', 'editor_script' => 'wu-blocks',
'render_callback' => \Closure::fromCallable([$element, 'display']), 'render_callback' => \Closure::fromCallable(array($element, 'display')),
)); )
);
} // end register_block; }
/** /**
* Consolidate field attributes that are callables for blocks. * 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 _ * Discard fields that are notes and start with _
*/ */
if (in_array($field['type'], $fields_to_ignore, true) && strncmp($field_slug, '_', strlen('_')) === 0) { if (in_array($field['type'], $fields_to_ignore, true) && strncmp($field_slug, '_', strlen('_')) === 0) {
unset($fields[ $field_slug ]); unset($fields[ $field_slug ]);
}
} // end if;
/* /*
* Deal with the group type. * Deal with the group type.
* On those, we need to loop the sub-fields. * On those, we need to loop the sub-fields.
*/ */
if ($field['type'] === 'group') { if ($field['type'] === 'group') {
foreach ($field['fields'] as &$sub_field) { foreach ($field['fields'] as &$sub_field) {
foreach ($sub_field as $sub_item => &$sub_value) { foreach ($sub_field as $sub_item => &$sub_value) {
if (in_array($sub_item, $callable_keys, true) && is_callable($sub_value)) { if (in_array($sub_item, $callable_keys, true) && is_callable($sub_value)) {
$sub_value = call_user_func($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 * Deal with the regular field types and its
* callables. * callables.
*/ */
foreach ($field as $item => &$value) { foreach ($field as $item => &$value) {
if (in_array($item, $callable_keys, true) && is_callable($value)) { if (in_array($item, $callable_keys, true) && is_callable($value)) {
$value = call_user_func($value); $value = call_user_func($value);
}
} // end if; }
}
} // end foreach;
} // end foreach;
return $fields; return $fields;
}
} // end consolidate_callables;
/** /**
* Registers the block so WP Multisite WaaS can add it on the JS side. * 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; return $blocks;
}
} // end load_block_settings;
/** /**
* Generates the list of attributes supported based on the fields. * Generates the list of attributes supported based on the fields.
@ -238,20 +211,15 @@ class Block_Editor_Widget_Manager {
$_fields = array(); $_fields = array();
foreach ($fields as $field_id => $field) { foreach ($fields as $field_id => $field) {
$type = 'string'; $type = 'string';
if ($field['type'] === 'toggle') { if ($field['type'] === 'toggle') {
$type = 'boolean'; $type = 'boolean';
}
} // end if;
if ($field['type'] === 'number') { if ($field['type'] === 'number') {
$type = 'integer'; $type = 'integer';
}
} // end if;
$default_value = wu_get_isset($defaults, $field_id, ''); $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), 'default' => wu_get_isset($field, 'value', $default_value),
'type' => $type, 'type' => $type,
); );
}
} // end foreach;
return $_fields; 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')); add_filter('lostpassword_redirect', array($this, 'filter_lost_password_redirect'));
if (is_main_site()) { if (is_main_site()) {
add_action('before_signup_header', array($this, 'redirect_to_registration_page')); add_action('before_signup_header', array($this, 'redirect_to_registration_page'));
$use_custom_login = wu_get_setting('enable_custom_login_page', false); $use_custom_login = wu_get_setting('enable_custom_login_page', false);
if ( ! $use_custom_login) { if ( ! $use_custom_login) {
return; return;
}
} // end if;
add_filter('login_url', array($this, 'filter_login_url'), 10, 3); 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('post_submitbox_misc_actions', array($this, 'render_compat_mode_setting'));
add_action('save_post', array($this, 'handle_compat_mode_setting')); add_action('save_post', array($this, 'handle_compat_mode_setting'));
}
} // end if; }
} // end init;
/** /**
* Filters the lost password redirect URL. * Filters the lost password redirect URL.
@ -86,16 +81,13 @@ class Checkout_Pages {
public function filter_lost_password_redirect(string $redirect_to): string { public function filter_lost_password_redirect(string $redirect_to): string {
if ( ! empty($redirect_to)) { if ( ! empty($redirect_to)) {
return $redirect_to; return $redirect_to;
}
} // end if;
$redirect_to = add_query_arg('checkemail', 'confirm', wp_login_url()); $redirect_to = add_query_arg('checkemail', 'confirm', wp_login_url());
return $redirect_to; return $redirect_to;
}
} // end filter_lost_password_redirect;
/** /**
* Renders the compat mode option for pages and posts. * Renders the compat mode option for pages and posts.
@ -127,8 +119,7 @@ class Checkout_Pages {
<?php <?php
// phpcs:enable // phpcs:enable
}
} // end render_compat_mode_setting;
/** /**
* Handles saving the compat mode switch on posts. * Handles saving the compat mode switch on posts.
@ -141,34 +132,23 @@ class Checkout_Pages {
public function handle_compat_mode_setting($post_id) { public function handle_compat_mode_setting($post_id) {
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
return; return;
}
} // end if;
if ( ! isset($_POST['_wu_force_compat']) || ! wp_verify_nonce($_POST['_wu_force_compat'], '_wu_force_compat_' . $post_id)) { if ( ! isset($_POST['_wu_force_compat']) || ! wp_verify_nonce($_POST['_wu_force_compat'], '_wu_force_compat_' . $post_id)) {
return; return;
}
} // end if;
if ( ! current_user_can('edit_post', $post_id)) { if ( ! current_user_can('edit_post', $post_id)) {
return; return;
}
} // end if;
if (isset($_POST['_wu_force_elements_loading'])) { if (isset($_POST['_wu_force_elements_loading'])) {
update_post_meta($post_id, '_wu_force_elements_loading', $_POST['_wu_force_elements_loading']); update_post_meta($post_id, '_wu_force_elements_loading', $_POST['_wu_force_elements_loading']);
} else { } else {
delete_post_meta($post_id, '_wu_force_elements_loading'); delete_post_meta($post_id, '_wu_force_elements_loading');
}
} // end if; }
} // end handle_compat_mode_setting;
/** /**
* Replace wp-login.php in email URLs. * Replace wp-login.php in email URLs.
@ -184,24 +164,19 @@ class Checkout_Pages {
* wp-login.php in it to begin with. * wp-login.php in it to begin with.
*/ */
if (strpos($url, 'wp-login.php') === false) { if (strpos($url, 'wp-login.php') === false) {
return $url; return $url;
}
} // end if;
$post_id = wu_get_setting('default_login_page', 0); $post_id = wu_get_setting('default_login_page', 0);
$post = get_post($post_id); $post = get_post($post_id);
if ($post) { if ($post) {
$url = str_replace('wp-login.php', $post->post_name, $url); $url = str_replace('wp-login.php', $post->post_name, $url);
}
} // end if;
return $url; return $url;
}
} // end maybe_change_wp_login_on_urls;
/** /**
* Get an error message. * Get an error message.
@ -243,8 +218,7 @@ class Checkout_Pages {
$messages = apply_filters('wu_checkout_pages_error_messages', $messages); $messages = apply_filters('wu_checkout_pages_error_messages', $messages);
return wu_get_isset($messages, $error_code, __('Something went wrong', 'wp-ultimo')); return wu_get_isset($messages, $error_code, __('Something went wrong', 'wp-ultimo'));
}
} // end get_error_message;
/** /**
* Handle password reset errors. * Handle password reset errors.
@ -260,20 +234,20 @@ class Checkout_Pages {
public function maybe_handle_password_reset_errors($errors) { public function maybe_handle_password_reset_errors($errors) {
if ($errors->has_errors()) { if ($errors->has_errors()) {
$url = add_query_arg(
$url = add_query_arg(array( array(
'action' => wu_request('action', ''), 'action' => wu_request('action', ''),
'user_login' => wu_request('user_login', ''), 'user_login' => wu_request('user_login', ''),
'error' => $errors->get_error_code(), 'error' => $errors->get_error_code(),
), wp_login_url()); ),
wp_login_url()
);
wp_redirect($url); wp_redirect($url);
exit; exit;
}
} // end if; }
} // end maybe_handle_password_reset_errors;
/** /**
* Maybe redirects users to the confirm screen. * Maybe redirects users to the confirm screen.
@ -289,14 +263,11 @@ class Checkout_Pages {
public function maybe_redirect_to_confirm_screen() { public function maybe_redirect_to_confirm_screen() {
if (wu_request('redirect_to')) { if (wu_request('redirect_to')) {
wp_redirect(wu_request('redirect_to')); wp_redirect(wu_request('redirect_to'));
exit; exit;
}
} // end if; }
} // end maybe_redirect_to_confirm_screen;
/** /**
* Replace the reset password link, if necessary. * 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) { public function replace_reset_password_link($message, $key, $user_login, $user_data) {
if ( ! is_main_site()) { if ( ! is_main_site()) {
return $message; return $message;
}
} // end if;
$results = array(); $results = array();
@ -330,28 +299,27 @@ class Checkout_Pages {
$switched_locale = switch_to_locale($locale); $switched_locale = switch_to_locale($locale);
$new_url = add_query_arg(array( $new_url = add_query_arg(
array(
'action' => 'rp', 'action' => 'rp',
'key' => $key, 'key' => $key,
'login' => rawurlencode($user_login), 'login' => rawurlencode($user_login),
'wp_lang' => $locale 'wp_lang' => $locale,
), wp_login_url()); ),
wp_login_url()
);
$new_url = set_url_scheme($new_url, null); $new_url = set_url_scheme($new_url, null);
$message = str_replace($results[0], $new_url, $message); $message = str_replace($results[0], $new_url, $message);
}
} // end if;
if ($switched_locale) { if ($switched_locale) {
restore_previous_locale(); restore_previous_locale();
}
} // end if;
return $message; return $message;
}
} // end replace_reset_password_link;
/** /**
* Redirect logged users when they reach the login page. * Redirect logged users when they reach the login page.
@ -364,24 +332,18 @@ class Checkout_Pages {
global $post; global $post;
if ( ! is_user_logged_in()) { if ( ! is_user_logged_in()) {
return; return;
}
} // end if;
$custom_login_page = $this->get_signup_page('login'); $custom_login_page = $this->get_signup_page('login');
if (empty($custom_login_page) || empty($post)) { if (empty($custom_login_page) || empty($post)) {
return; return;
}
} // end if;
if ($custom_login_page->ID !== $post->ID) { if ($custom_login_page->ID !== $post->ID) {
return; return;
}
} // end if;
/** /**
* Create an exclusion list of parameters that prevent the auto-redirect. * Create an exclusion list of parameters that prevent the auto-redirect.
@ -392,24 +354,26 @@ class Checkout_Pages {
* @since 2.0.4 * @since 2.0.4
* @return array * @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 'preview', // WordPress Preview
'ct_builder', // Oxygen Builder 'ct_builder', // Oxygen Builder
'fl_builder', // Beaver Builder 'fl_builder', // Beaver Builder
'elementor-preview', // Elementor 'elementor-preview', // Elementor
'brizy-edit', // Brizy 'brizy-edit', // Brizy
'brizy-edit-iframe', // Brizy 'brizy-edit-iframe', // Brizy
), $custom_login_page, $post, $this); ),
$custom_login_page,
$post,
$this
);
foreach ($exclusion_list as $exclusion_param) { foreach ($exclusion_list as $exclusion_param) {
if (wu_request($exclusion_param, null) !== null) { if (wu_request($exclusion_param, null) !== null) {
return; return;
}
} // end if; }
} // end foreach;
$user = wp_get_current_user(); $user = wp_get_current_user();
@ -418,34 +382,23 @@ class Checkout_Pages {
$redirect_to = $active_blog ? get_admin_url($active_blog->blog_id) : false; $redirect_to = $active_blog ? get_admin_url($active_blog->blog_id) : false;
if (isset($_GET['redirect_to'])) { if (isset($_GET['redirect_to'])) {
$redirect_to = $_GET['redirect_to']; $redirect_to = $_GET['redirect_to'];
} elseif (is_multisite() && ! get_active_blog_for_user($user->ID) && ! is_super_admin($user->ID)) { } elseif (is_multisite() && ! get_active_blog_for_user($user->ID) && ! is_super_admin($user->ID)) {
$redirect_to = user_admin_url(); $redirect_to = user_admin_url();
} elseif (is_multisite() && ! $user->has_cap('read')) { } elseif (is_multisite() && ! $user->has_cap('read')) {
$redirect_to = get_dashboard_url($user->ID); $redirect_to = get_dashboard_url($user->ID);
} elseif ( ! $user->has_cap('edit_posts')) { } elseif ( ! $user->has_cap('edit_posts')) {
$redirect_to = $user->has_cap('read') ? admin_url('profile.php') : home_url(); $redirect_to = $user->has_cap('read') ? admin_url('profile.php') : home_url();
}
} // end if;
if ( ! $redirect_to) { if ( ! $redirect_to) {
return; return;
}
} // end if;
wp_redirect($redirect_to); wp_redirect($redirect_to);
exit; exit;
}
} // end maybe_redirect_to_admin_panel;
/** /**
* Adds the unverified email account error message. * Adds the unverified email account error message.
@ -460,7 +413,6 @@ class Checkout_Pages {
public function add_verify_email_notice($payment, $membership, $customer) { public function add_verify_email_notice($payment, $membership, $customer) {
if ($payment->get_total() == 0 && $customer->get_email_verification() === 'pending') { 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>'; $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'); $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')); $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); printf($html, $message);
}
} // end if; }
} // end add_verify_email_notice;
/** /**
* Check if we should obfuscate the login URL. * 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); $use_custom_login = wu_get_setting('enable_custom_login_page', false);
if ( ! $use_custom_login) { if ( ! $use_custom_login) {
return; return;
}
} // end if;
if ($_SERVER['REQUEST_METHOD'] === 'POST') { if ($_SERVER['REQUEST_METHOD'] === 'POST') {
return; return;
}
} // end if;
if (wu_request('interim-login')) { if (wu_request('interim-login')) {
return; return;
}
} // end if;
if (wu_request('action') === 'logout') { if (wu_request('action') === 'logout') {
return; return;
}
} // end if;
$new_login_url = $this->get_page_url('login'); $new_login_url = $this->get_page_url('login');
if ( ! $new_login_url) { if ( ! $new_login_url) {
return; return;
}
} // end if;
$should_obfuscate = wu_get_setting('obfuscate_original_login_url', 1); $should_obfuscate = wu_get_setting('obfuscate_original_login_url', 1);
$bypass_obfuscation = wu_request('wu_bypass_obfuscation'); $bypass_obfuscation = wu_request('wu_bypass_obfuscation');
if ($should_obfuscate && ! $bypass_obfuscation) { if ($should_obfuscate && ! $bypass_obfuscation) {
status_header(404); status_header(404);
nocache_headers(); nocache_headers();
@ -529,19 +468,15 @@ class Checkout_Pages {
$wp_query->set_404(); $wp_query->set_404();
include(get_404_template()); include get_404_template();
die; die;
} else { } else {
wp_redirect($new_login_url); wp_redirect($new_login_url);
exit; exit;
}
} // end if; }
} // end maybe_obfuscate_login_url;
/** /**
* Redirects the customers to the registration page, when one is used. * 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'); $registration_url = $this->get_page_url('register');
if ($registration_url) { if ($registration_url) {
wp_redirect($registration_url); wp_redirect($registration_url);
exit; exit;
}
} // end if; }
} // end redirect_to_registration_page;
/** /**
* Filters the login URL if necessary. * 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. * Fix incompatibility with UIPress, making sure we only filter after wp_loaded ran.
*/ */
if ( ! did_action('wp_loaded')) { if ( ! did_action('wp_loaded')) {
return $login_url; return $login_url;
}
} // end if;
$function_caller = wu_get_function_caller(5); $function_caller = wu_get_function_caller(5);
if ($function_caller === 'wp_auth_check_html') { if ($function_caller === 'wp_auth_check_html') {
return $login_url; return $login_url;
}
} // end if;
$params = array(); $params = array();
@ -601,32 +529,23 @@ class Checkout_Pages {
$new_login_url = $this->get_page_url('login'); $new_login_url = $this->get_page_url('login');
if ( ! $new_login_url) { if ( ! $new_login_url) {
return $login_url; return $login_url;
}
} // end if;
if ($params) { if ($params) {
$new_login_url = add_query_arg($params, $new_login_url); $new_login_url = add_query_arg($params, $new_login_url);
}
} // end if;
if ($redirect) { if ($redirect) {
$new_login_url = add_query_arg('redirect_to', urlencode($redirect), $new_login_url); $new_login_url = add_query_arg('redirect_to', urlencode($redirect), $new_login_url);
}
} // end if;
if ($force_reauth) { if ($force_reauth) {
$new_login_url = add_query_arg('reauth', 1, $new_login_url); $new_login_url = add_query_arg('reauth', 1, $new_login_url);
}
} // end if;
return $new_login_url; return $new_login_url;
}
} // end filter_login_url;
/** /**
* Returns the ID of the pages being used for each WP Multisite WaaS purpose. * 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), 'block_frontend' => wu_get_setting('default_block_frontend_page', false),
'new_site' => wu_get_setting('default_new_site_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. * Returns the WP_Post object for one of the pages.
* *
@ -660,14 +578,11 @@ class Checkout_Pages {
$page_id = wu_get_isset($pages, $page); $page_id = wu_get_isset($pages, $page);
if ( ! $page_id) { if ( ! $page_id) {
return false; return false;
}
} // end if;
return get_blog_post(wu_get_main_site_id(), $page_id); return get_blog_post(wu_get_main_site_id(), $page_id);
}
} // end get_signup_page;
/** /**
* Returns the URL for a particular page type. * Returns the URL for a particular page type.
* *
@ -681,14 +596,11 @@ class Checkout_Pages {
$page = $this->get_signup_page($page_slug); $page = $this->get_signup_page($page_slug);
if ( ! $page) { if ( ! $page) {
return false; return false;
}
} // end if;
return wu_switch_blog_and_run(fn() => get_the_permalink($page)); 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. * 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) { public function add_wp_ultimo_status_annotation($states, $post) {
if ( ! is_main_site()) { if ( ! is_main_site()) {
return $states; return $states;
}
} // end if;
$labels = array( $labels = array(
'register' => __('WP Multisite WaaS - Register Page', 'wp-ultimo'), 'register' => __('WP Multisite WaaS - Register Page', 'wp-ultimo'),
@ -718,16 +628,13 @@ class Checkout_Pages {
$pages = array_map('absint', $this->get_signup_pages()); $pages = array_map('absint', $this->get_signup_pages());
if (in_array($post->ID, $pages, true)) { if (in_array($post->ID, $pages, true)) {
$key = array_search($post->ID, $pages, true); $key = array_search($post->ID, $pages, true);
$states['wp_ultimo_page'] = wu_get_isset($labels, $key); $states['wp_ultimo_page'] = wu_get_isset($labels, $key);
}
} // end if;
return $states; return $states;
}
} // end add_wp_ultimo_status_annotation;
/** /**
* Renders the confirmation page. * Renders the confirmation page.
@ -740,11 +647,12 @@ class Checkout_Pages {
*/ */
public function render_confirmation_page($atts, $content = null) { 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, 'errors' => Checkout::get_instance()->errors,
'membership' => wu_get_membership_by_hash(wu_request('membership')), '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 // template assigned and return it's path
add_filter('template_include', array($this, 'view_legacy_template')); add_filter('template_include', array($this, 'view_legacy_template'));
} // end init; }
/** /**
* Adds our page templates to the page template dropdown. * Adds our page templates to the page template dropdown.
@ -127,11 +127,11 @@ class Legacy_Checkout {
$posts_templates = array_merge($posts_templates, $this->templates); $posts_templates = array_merge($posts_templates, $this->templates);
} // end if; }
return $posts_templates; return $posts_templates;
} // end add_new_template; }
/** /**
* Adds our template to the pages cache in order to trick WordPress * Adds our template to the pages cache in order to trick WordPress
@ -155,7 +155,7 @@ class Legacy_Checkout {
$templates = array(); $templates = array();
} // end if; }
// New cache, therefore remove the old one // New cache, therefore remove the old one
wp_cache_delete($cache_key, 'themes'); wp_cache_delete($cache_key, 'themes');
@ -170,7 +170,7 @@ class Legacy_Checkout {
return $atts; return $atts;
} // end register_legacy_templates; }
/** /**
* Checks if our custom template is assigned to the page and display it. * Checks if our custom template is assigned to the page and display it.
@ -187,7 +187,7 @@ class Legacy_Checkout {
return $template; return $template;
} // end if; }
// Get global post // Get global post
global $post, $signup; global $post, $signup;
@ -197,7 +197,7 @@ class Legacy_Checkout {
return $template; return $template;
} // end if; }
$template_slug = get_post_meta($post->ID, '_wp_page_template', true); $template_slug = get_post_meta($post->ID, '_wp_page_template', true);
@ -206,7 +206,7 @@ class Legacy_Checkout {
return $template; return $template;
} // end if; }
$file = wu_path("views/legacy/signup/$template_slug"); $file = wu_path("views/legacy/signup/$template_slug");
@ -215,12 +215,12 @@ class Legacy_Checkout {
return $file; return $file;
} // end if; }
// Return template // Return template
return $template; return $template;
} // end view_legacy_template; }
/** /**
* Loads the necessary scripts. * Loads the necessary scripts.
@ -251,11 +251,11 @@ class Legacy_Checkout {
wp_enqueue_style('login'); wp_enqueue_style('login');
} // end if; }
wp_enqueue_style('common'); wp_enqueue_style('common');
} // end register_scripts; }
/** /**
* Adds the additional dynamic styles. * Adds the additional dynamic styles.
@ -298,8 +298,7 @@ class Legacy_Checkout {
// phpcs:enable // phpcs:enable
return ob_get_clean(); return ob_get_clean();
}
} // end get_legacy_dynamic_styles;
/** /**
* Checks if we should pre-fill checkout fields based on the request. * 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'] : ''; $page_name = isset($request['pagename']) ? $request['pagename'] : '';
if (strncmp((string) $page_name, $checkout_page_slug, strlen($checkout_page_slug)) === 0) { if (strncmp((string) $page_name, $checkout_page_slug, strlen($checkout_page_slug)) === 0) {
$page = explode('/', (string) $page_name); $page = explode('/', (string) $page_name);
/** /**
@ -328,24 +326,20 @@ class Legacy_Checkout {
* @todo needs to check for frequency and unit. * @todo needs to check for frequency and unit.
*/ */
if (isset($page[1])) { if (isset($page[1])) {
$product_slug = $page[1]; $product_slug = $page[1];
$product = wu_get_product_by_slug($product_slug); $product = wu_get_product_by_slug($product_slug);
$this->product = $product; $this->product = $product;
}
} // end if;
$request['pagename'] = $checkout_page_slug; $request['pagename'] = $checkout_page_slug;
return $this->legacy_signup(); return $this->legacy_signup();
}
} // end if;
return $request; return $request;
}
} // end maybe_render_legacy_signup;
/** /**
* Renders the legacy checkout. * Renders the legacy checkout.
@ -369,13 +363,15 @@ class Legacy_Checkout {
$this->handle_post(); $this->handle_post();
wu_get_template('legacy/signup/signup-main', array( wu_get_template(
'legacy/signup/signup-main',
array(
'signup' => $this, 'signup' => $this,
)); )
);
exit; exit;
}
} // end legacy_signup;
/** /**
* Check Geolocation * Check Geolocation
@ -391,16 +387,11 @@ class Legacy_Checkout {
$allowed_countries = wu_get_setting('allowed_countries'); $allowed_countries = wu_get_setting('allowed_countries');
if (isset($location['country']) && $location['country'] && $allowed_countries) { if (isset($location['country']) && $location['country'] && $allowed_countries) {
if ( ! in_array($location['country'], $allowed_countries, true)) { 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'))); 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. * Gets the info for the current step.
@ -411,8 +402,7 @@ class Legacy_Checkout {
protected function get_current_step_info() { protected function get_current_step_info() {
return $this->steps[ $this->step ]; return $this->steps[ $this->step ];
}
} // end get_current_step_info;
/** /**
* Handles a post submission. * Handles a post submission.
@ -433,23 +423,17 @@ class Legacy_Checkout {
/** Checks if the view has a handler of its own */ /** Checks if the view has a handler of its own */
if (isset($current_step['handler']) && $current_step['handler']) { if (isset($current_step['handler']) && $current_step['handler']) {
$handler_function = $current_step['handler']; $handler_function = $current_step['handler'];
} else { } else {
$handler_function = array($this, 'default_save'); $handler_function = array($this, 'default_save');
}
} // end if;
/** Allows for handler rewrite */ /** Allows for handler rewrite */
$handler_function = apply_filters("wu_signup_step_handler_$this->step", $handler_function); $handler_function = apply_filters("wu_signup_step_handler_$this->step", $handler_function);
call_user_func($handler_function); call_user_func($handler_function);
}
} // end if; }
} // end handle_post;
/** /**
* The first invisible step, handles the creation of the transient saver * The first invisible step, handles the creation of the transient saver
@ -479,19 +463,16 @@ class Legacy_Checkout {
// Adds to the payload // Adds to the payload
$content['coupon'] = $_REQUEST['coupon']; $content['coupon'] = $_REQUEST['coupon'];
}
} // end if;
/** /**
* Check if user came from a pricing select table * 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'])) { if (isset($_REQUEST['plan_id']) && isset($_REQUEST['plan_freq']) && WU_Gateway::check_frequency($_REQUEST['plan_freq'])) {
$content['plan_id'] = $_REQUEST['plan_id']; $content['plan_id'] = $_REQUEST['plan_id'];
$content['plan_freq'] = $_REQUEST['plan_freq']; $content['plan_freq'] = $_REQUEST['plan_freq'];
$content['skip_plan'] = true; $content['skip_plan'] = true;
}
} // end if;
/** /**
* Check if we only have one plan and the skip_plan enabled * Check if we only have one plan and the skip_plan enabled
@ -500,7 +481,6 @@ class Legacy_Checkout {
$plans = wu_get_plans(); $plans = wu_get_plans();
if (wu_get_setting('skip_plan', false) && count($plans) === 1) { if (wu_get_setting('skip_plan', false) && count($plans) === 1) {
$billing_frequency = wu_get_setting('default_pricing_option', 1); $billing_frequency = wu_get_setting('default_pricing_option', 1);
$plan = reset($plans); $plan = reset($plans);
@ -511,8 +491,7 @@ class Legacy_Checkout {
$content['skip_plan'] = true; $content['skip_plan'] = true;
$_REQUEST['skip_plan'] = 1; $_REQUEST['skip_plan'] = 1;
}
} // end if;
/** /**
* Check if we are settings the template via the URL * 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']); $site = new WU_Site_Template($_REQUEST['template_id']);
if ($site->is_template) { if ($site->is_template) {
$content['template'] = $_REQUEST['template_id']; $content['template'] = $_REQUEST['template_id'];
$content['skip_template_selection'] = true; $content['skip_template_selection'] = true;
}
} // end if; }
} // end if;
$this->session->set('form', $content); $this->session->set('form', $content);
/** Go to the next step */ /** Go to the next step */
$this->next_step(); $this->next_step();
}
} // end begin_signup;
/** /**
* Check if the current page is a customizer page. * 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')); $exclude_list = apply_filters('wu_replace_signup_urls_exclude', array('wu-signup-customizer-preview'));
foreach ($exclude_list as $replace_word) { foreach ($exclude_list as $replace_word) {
if (isset($_GET[ $replace_word ])) { if (isset($_GET[ $replace_word ])) {
return true; return true;
}
} // end if; }
} // end foreach;
return false; return false;
}
} // end is_customizer;
/** /**
* Returns the first step of the signup process * Returns the first step of the signup process
@ -570,16 +540,11 @@ class Legacy_Checkout {
$keys = array_keys($this->get_steps()); $keys = array_keys($this->get_steps());
if (isset($keys[1])) { if (isset($keys[1])) {
return $keys[1]; return $keys[1];
} else { } else {
return false; return false;
}
} // end if; }
} // end get_first_step;
/** /**
* Get the current step * Get the current step
@ -592,14 +557,11 @@ class Legacy_Checkout {
// Always get the first step for the customizer // // Always get the first step for the customizer //
if ($this->is_customizer()) { if ($this->is_customizer()) {
$current_step = $this->get_first_step(); $current_step = $this->get_first_step();
}
} // end if;
return apply_filters('wu_current_step', $current_step); 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 * 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 * Set the errors
*/ */
if ($this->results === null) { if ($this->results === null) {
$this->results = array('errors' => new \WP_Error());
$this->results = array('errors' => new \WP_Error); }
} // end if;
if (empty($_POST)) { if (empty($_POST)) {
$this->results = array_merge($this->results, $transient); $this->results = array_merge($this->results, $transient);
}
} // end if;
/** /**
* Builds the array containing the available elements inside the template * 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 * Checks if anything is passed to the view element
*/ */
if (isset($this->steps[ $step ]['view']) && $this->steps[ $step ]['view']) { if (isset($this->steps[ $step ]['view']) && $this->steps[ $step ]['view']) {
wu_get_template('legacy/signup/steps/' . $this->steps[ $step ]['view'], $args); wu_get_template('legacy/signup/steps/' . $this->steps[ $step ]['view'], $args);
} else { } else {
$found = locate_template("wp-ultimo/signup/steps/step-$step.php"); $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 * Let's try to locate a custom template on the user's theme. If it's there, we use it instead
*/ */
if ($found) { if ($found) {
wu_get_template("legacy/signup/steps/step-$step", $args); wu_get_template("legacy/signup/steps/step-$step", $args);
} else { } else {
wu_get_template('legacy/signup/steps/step-default', $args); 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. * 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 // We add template selection if this has template
if ($site_templates) { if ($site_templates) {
$steps['template'] = array( $steps['template'] = array(
'name' => __('Template Selection', 'wp-ultimo'), 'name' => __('Template Selection', 'wp-ultimo'),
'desc' => __('Select the base template of your new site.', 'wp-ultimo'), 'desc' => __('Select the base template of your new site.', 'wp-ultimo'),
@ -705,8 +653,7 @@ class Legacy_Checkout {
'handler' => false, 'handler' => false,
'core' => true, 'core' => true,
); );
}
} // end if;
// Domain registering // Domain registering
$steps['domain'] = array( $steps['domain'] = array(
@ -716,7 +663,9 @@ class Legacy_Checkout {
'view' => false, 'view' => false,
'order' => 30, 'order' => 30,
'core' => true, 'core' => true,
'fields' => apply_filters('wu_signup_fields_domain', array( 'fields' => apply_filters(
'wu_signup_fields_domain',
array(
'blog_title' => array( 'blog_title' => array(
'order' => 10, 'order' => 10,
'name' => apply_filters('wu_signup_site_title_label', __('Site Title', 'wp-ultimo')), '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'), 'name' => __('Continue to the next step', 'wp-ultimo'),
'core' => true, 'core' => true,
), ),
)), )
),
); );
/** /**
@ -818,10 +768,10 @@ class Legacy_Checkout {
), ),
'attributes' => array( 'attributes' => array(
'autocomplete' => 'nope', 'autocomplete' => 'nope',
) ),
), ),
); // end first account fields; );
/** /**
* Check and Add Coupon Code Fields * Check and Add Coupon Code Fields
@ -851,7 +801,7 @@ class Legacy_Checkout {
// 'requires' => array('has_coupon' => true), // 'requires' => array('has_coupon' => true),
// 'core' => true, // 'core' => true,
// ); // );
// } // end if; // }
// /** // /**
// * Check and Add the Terms field // * Check and Add the Terms field
// * @since 1.0.4 // * @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()), // 'name' => sprintf(__('I agree with the <a href="%s" target="_blank">Terms of Service</a>', 'wp-ultimo'), $this->get_terms_url()),
// 'core' => true, // 'core' => true,
// ); // );
// } // end if; // }
/** /**
* Submit Field * Submit Field
@ -896,19 +846,19 @@ class Legacy_Checkout {
// Sorts each of the fields block // Sorts each of the fields block
foreach ($steps as &$step) { foreach ($steps as &$step) {
$step = wp_parse_args(
$step = wp_parse_args($step, array( $step,
array(
'hidden' => false, 'hidden' => false,
)); )
);
if (isset($step['fields']) && is_array($step['fields'])) { if (isset($step['fields']) && is_array($step['fields'])) {
// Sort elements based on their order // Sort elements based on their order
uasort($step['fields'], array($this, 'sort_steps_and_fields')); 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 * Adds the hidden step now responsible for validating data entry and the actual account creation
@ -953,21 +903,16 @@ class Legacy_Checkout {
* @var array * @var array
*/ */
if ( ! $include_hidden) { if ( ! $include_hidden) {
$steps = array_filter($steps, fn($step) => ! (isset($step['hidden']) && $step['hidden'])); $steps = array_filter($steps, fn($step) => ! (isset($step['hidden']) && $step['hidden']));
}
} // end if;
// If we need to add that // If we need to add that
if ( ! $this->has_plan_step()) { if ( ! $this->has_plan_step()) {
unset($steps['plan']); unset($steps['plan']);
}
} // end if;
return $steps; return $steps;
}
} // end get_steps;
/** /**
* Check the transient, and if it does not exists, throw fatal * 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) { public static function get_transient($die = true) {
if (self::is_customizer()) { if (self::is_customizer()) {
$transient = array( $transient = array(
'not-empty' => '', 'not-empty' => '',
); );
} else { } else {
$transient = wu_get_session('signup')->get('form'); $transient = wu_get_session('signup')->get('form');
}
} // end if;
if ($die && empty($transient)) { if ($die && empty($transient)) {
// wp_die(__('Try again', 'wp-ultimo')); // wp_die(__('Try again', 'wp-ultimo'));
}
} // end if;
if (is_null($transient)) { if (is_null($transient)) {
return array(); return array();
}
} // end if;
return $transient; return $transient;
}
} // end get_transient;
/** /**
* Update the transient data in out database * Update the transient data in out database
@ -1015,8 +952,7 @@ class Legacy_Checkout {
$this->session->set('form', $transient); $this->session->set('form', $transient);
$this->session->commit(); $this->session->commit();
}
} // end update_transient;
/** /**
* Checks transient data to see if the plan step is necessary * Checks transient data to see if the plan step is necessary
*/ */
@ -1025,14 +961,11 @@ class Legacy_Checkout {
$transient = $this->get_transient(); $transient = $this->get_transient();
if (isset($transient['skip_plan']) && isset($transient['plan_id']) && isset($transient['plan_freq'])) { if (isset($transient['skip_plan']) && isset($transient['plan_id']) && isset($transient['plan_freq'])) {
return false; return false;
}
} // end if;
return true; return true;
}
} // end has_plan_step;
/** /**
* Get the link for the next step * Get the link for the next step
@ -1044,57 +977,42 @@ class Legacy_Checkout {
// Add CS // Add CS
if (isset($_GET['cs'])) { if (isset($_GET['cs'])) {
$params['cs'] = $_GET['cs']; $params['cs'] = $_GET['cs'];
}
} // end if;
if (isset($_REQUEST['customized'])) { if (isset($_REQUEST['customized'])) {
$params['customized'] = $_REQUEST['customized']; $params['customized'] = $_REQUEST['customized'];
}
} // end if;
if (isset($_REQUEST['skip_plan']) && $_REQUEST['skip_plan'] == 1) { if (isset($_REQUEST['skip_plan']) && $_REQUEST['skip_plan'] == 1) {
unset($this->steps['plan']); unset($this->steps['plan']);
unset($params['skip_plan']); unset($params['skip_plan']);
}
} // end if;
if (isset($_REQUEST['template_id'])) { if (isset($_REQUEST['template_id'])) {
$plan = false; $plan = false;
if (isset($_REQUEST['plan_id'])) { if (isset($_REQUEST['plan_id'])) {
$plan = wu_get_plan($_REQUEST['plan_id']); $plan = wu_get_plan($_REQUEST['plan_id']);
}
} // end if;
$templates = array_keys((array) wu_get_setting('templates')); $templates = array_keys((array) wu_get_setting('templates'));
if ( ($plan && $plan->is_template_available($_REQUEST['template_id'])) || in_array($_REQUEST['template_id'], $templates)) { if ( ($plan && $plan->is_template_available($_REQUEST['template_id'])) || in_array($_REQUEST['template_id'], $templates)) {
unset($this->steps['template']); unset($this->steps['template']);
unset($params['skip_template_selection']); unset($params['skip_template_selection']);
}
} // end if; }
} // end if;
$keys = array_keys($this->steps); $keys = array_keys($this->steps);
$url = add_query_arg('step', $keys[ array_search($this->step, array_keys($this->steps)) + 1 ]); $url = add_query_arg('step', $keys[ array_search($this->step, array_keys($this->steps)) + 1 ]);
foreach ($params as $param => $value) { foreach ($params as $param => $value) {
$url = add_query_arg($param, $value, $url); $url = add_query_arg($param, $value, $url);
}
} // end foreach;
return $url; return $url;
}
} // end get_next_step_link;
/** /**
* Redirects the user to the next step on the signup flow * Redirects the user to the next step on the signup flow
@ -1109,8 +1027,7 @@ class Legacy_Checkout {
/** Kill the execution after the redirect */ /** Kill the execution after the redirect */
exit; exit;
}
} // end next_step;
/** /**
* Get the link for the previous step * Get the link for the previous step
@ -1122,38 +1039,29 @@ class Legacy_Checkout {
// Add CS // Add CS
if (isset($_GET['cs'])) { if (isset($_GET['cs'])) {
$params['cs'] = $_GET['cs']; $params['cs'] = $_GET['cs'];
}
} // end if;
if (isset($_REQUEST['customized'])) { if (isset($_REQUEST['customized'])) {
$params['customized'] = $_REQUEST['customized']; $params['customized'] = $_REQUEST['customized'];
}
} // end if;
$keys = array_keys($this->steps); $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; $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 ]; $key = $search_key === false ? '' : $keys[ $search_key ];
if ( ! $key || $key == 'begin-signup') { if ( ! $key || $key == 'begin-signup') {
return false; return false;
}
} // end if;
$url = add_query_arg('step', $key); $url = add_query_arg('step', $key);
foreach ($params as $param => $value) { foreach ($params as $param => $value) {
$url = add_query_arg($param, $value, $url); $url = add_query_arg($param, $value, $url);
}
} // end foreach;
return $url; return $url;
}
} // end get_prev_step_link;
/** /**
* Sorts the steps. * Sorts the steps.
@ -1169,8 +1077,7 @@ class Legacy_Checkout {
$b['order'] = isset($b['order']) ? (int) $b['order'] : 50; $b['order'] = isset($b['order']) ? (int) $b['order'] : 50;
return $a['order'] - $b['order']; return $a['order'] - $b['order'];
}
} // end sort_steps_and_fields;
/** /**
* Display the necessary fields for the plan template * 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; ?>"> <input type="hidden" id="wu_plan_freq" name="plan_freq" value="<?php echo $freq; ?>">
<?php <?php
} // end if; }
?> ?>
<input type="hidden" name="save_step" value="1"> <input type="hidden" name="save_step" value="1">
@ -1210,8 +1117,7 @@ class Legacy_Checkout {
<?php endif; ?> <?php endif; ?>
<?php <?php
}
} // end form_fields;
/** /**
* Get the primary site URL we will use on the URL previewer, during sign-up * 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; $domain = $site->domain;
if (wu_get_setting('enable_multiple_domains', false) && $domain_options) { if (wu_get_setting('enable_multiple_domains', false) && $domain_options) {
$domain = array_shift($domain_options); $domain = array_shift($domain_options);
}
} // end if;
$domain = rtrim($domain . $site->path, '/'); $domain = rtrim($domain . $site->path, '/');
@ -1244,8 +1148,7 @@ class Legacy_Checkout {
* @return string New domain to be used * @return string New domain to be used
*/ */
return apply_filters('get_site_url_for_previewer', $domain, $domain_options); // phpcs:ignore return apply_filters('get_site_url_for_previewer', $domain, $domain_options); // phpcs:ignore
}
} // end get_site_url_for_previewer;
/** /**
* We pass the following info * We pass the following info
@ -1259,7 +1162,7 @@ class Legacy_Checkout {
check_admin_referer('signup_form_1', '_signup_form'); check_admin_referer('signup_form_1', '_signup_form');
// Errors // Errors
$this->results['errors'] = new \WP_Error; $this->results['errors'] = new \WP_Error();
// We need now to check for plan // We need now to check for plan
if ( ! isset($_POST['plan_id'])) { if ( ! isset($_POST['plan_id'])) {
@ -1270,8 +1173,8 @@ class Legacy_Checkout {
if ( ! $plan->exists()) { if ( ! $plan->exists()) {
$this->results['errors']->add('plan_id', __('The plan you\'ve selected doesn\'t exist.', 'wp-ultimo')); $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); $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 // Stay on the form if we get any errors
if ($this->results['errors']->get_error_code()) { if ($this->results['errors']->get_error_code()) {
return; return;
} // end if; }
/** Update Transient Content */ /** Update Transient Content */
$transient['plan_freq'] = $_POST['plan_freq']; $transient['plan_freq'] = $_POST['plan_freq'];
@ -1292,8 +1195,7 @@ class Legacy_Checkout {
/** Go to the next step */ /** Go to the next step */
$this->next_step(); $this->next_step();
}
} // end plans_save;
/** /**
* Personal Info Settings. * Personal Info Settings.
@ -1324,20 +1226,17 @@ class Legacy_Checkout {
// Stay on the form if we get any errors // Stay on the form if we get any errors
if ($this->results['errors']->get_error_code()) { if ($this->results['errors']->get_error_code()) {
$this->results = array_merge($this->results, $_POST); $this->results = array_merge($this->results, $_POST);
return; return;
}
} // end if;
// Re-saves the transient // Re-saves the transient
$this->update_transient($transient); $this->update_transient($transient);
/** Go to the next step */ /** Go to the next step */
$this->next_step(); $this->next_step();
}
} // end domain_save;
/** /**
* Filters the input variables and sanitizes its contents * 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); $post = array_map(fn($element) => sanitize_text_field($element), $post);
return $post; return $post;
}
} // end filter_post_array;
/** /**
* Helper function to filter based on key. * 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); $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)); 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 * 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')); $active_until->add(new \DateInterval('P' . $trial_days . 'D'));
return $active_until->format('Y-m-d H:i:s'); 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 * Adds a new Step to the sign-up flow
@ -1402,7 +1298,9 @@ class Legacy_Checkout {
*/ */
public function add_signup_step($id, $order, $step) { 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 // Save new order
$step['order'] = $order; $step['order'] = $order;
@ -1413,10 +1311,9 @@ class Legacy_Checkout {
$steps[ $id ] = $step; $steps[ $id ] = $step;
return $steps; return $steps;
}
}); );
}
} // end add_signup_step;
/** /**
* Adds a new field to a step the sign-up flow * 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) { 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 // Checks for honey-trap id
if ($id === 'site_url') { 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')); 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 // Saves the order
$field['order'] = $order; $field['order'] = $order;
@ -1448,9 +1345,7 @@ class Legacy_Checkout {
$steps[ $step ]['fields'][ $id ] = $field; $steps[ $step ]['fields'][ $id ] = $field;
return $steps; return $steps;
}
}); );
}
} // end add_signup_field; }
} // end class Legacy_Checkout;

View File

@ -12,8 +12,8 @@ namespace WP_Ultimo\Checkout;
// Exit if accessed directly // Exit if accessed directly
defined('ABSPATH') || exit; defined('ABSPATH') || exit;
use \WP_Ultimo\Database\Payments\Payment_Status; use WP_Ultimo\Database\Payments\Payment_Status;
use \WP_Ultimo\Models\Product; use WP_Ultimo\Models\Product;
/** /**
* Creates an cart with the parameters of the purchase being placed. * Creates an cart with the parameters of the purchase being placed.
@ -295,8 +295,7 @@ class Line_Item implements \JsonSerializable {
* Refresh totals. * Refresh totals.
*/ */
$this->recalculate_totals(); $this->recalculate_totals();
}
} // end __construct;
/** /**
* Loops through allowed fields and loads them. * Loops through allowed fields and loads them.
@ -313,10 +312,8 @@ class Line_Item implements \JsonSerializable {
$type = wu_get_isset($data, 'type'); $type = wu_get_isset($data, 'type');
if ($type) { if ($type) {
$this->set_type($data['type']); $this->set_type($data['type']);
}
} // end if;
/* /*
* Set product first to allow for overriding the other parameters. * 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'); $product = wu_get_isset($data, 'product');
if ($product) { if ($product) {
$this->set_product($data['product']); $this->set_product($data['product']);
unset($data['product']); unset($data['product']);
}
} // end if;
$allowed_attributes = array_keys(get_object_vars($this)); $allowed_attributes = array_keys(get_object_vars($this));
foreach ($data as $key => $value) { foreach ($data as $key => $value) {
if (in_array($key, $allowed_attributes, true)) { if (in_array($key, $allowed_attributes, true)) {
$this->{$key} = $value; $this->{$key} = $value;
}
} // end if; }
} // end foreach;
$this->id = 'LN_' . strtoupper($this->type) . '_' . $this->hash; $this->id = 'LN_' . strtoupper($this->type) . '_' . $this->hash;
}
} // end attributes;
/** /**
* Get the value of id * Get the value of id
@ -356,8 +346,7 @@ class Line_Item implements \JsonSerializable {
public function get_id() { public function get_id() {
return $this->id; return $this->id;
}
} // end get_id;
/** /**
* Get the value of type * Get the value of type
@ -368,8 +357,7 @@ class Line_Item implements \JsonSerializable {
public function get_type() { public function get_type() {
return $this->type; return $this->type;
}
} // end get_type;
/** /**
* Set the value of type. * Set the value of type.
@ -383,8 +371,7 @@ class Line_Item implements \JsonSerializable {
public function set_type($type) { public function set_type($type) {
$this->type = $type; $this->type = $type;
}
} // end set_type;
/** /**
* Get product associated with this line item. * Get product associated with this line item.
* *
@ -396,29 +383,22 @@ class Line_Item implements \JsonSerializable {
$product = wu_get_product($this->product_id); $product = wu_get_product($this->product_id);
if ( ! $product) { if ( ! $product) {
return false; return false;
}
} // end if;
if ($product->is_recurring() && ($this->duration_unit !== $product->get_duration_unit() || $this->duration !== $product->get_duration())) { 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); $product_variation = $product->get_as_variation($this->duration, $this->duration_unit);
/* /*
* Checks if the variation exists before re-setting the product. * Checks if the variation exists before re-setting the product.
*/ */
if ($product_variation) { if ($product_variation) {
$product = $product_variation; $product = $product_variation;
}
} // end if; }
} // end if;
return $product; return $product;
}
} // end get_product;
/** /**
* Set product associated with this line item. * Set product associated with this line item.
@ -452,8 +432,7 @@ class Line_Item implements \JsonSerializable {
$this->tax_category = $product->get_tax_category(); $this->tax_category = $product->get_tax_category();
$this->discountable = true; $this->discountable = true;
}
} // end set_product;
/** /**
* Calculate the taxes value based on the tax_amount and tax_type. * 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) { 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()); 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. * 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) { public function calculate_discounts($sub_total) {
return wu_get_tax_amount($sub_total, $this->get_discount_rate(), $this->get_discount_type(), false); return wu_get_tax_amount($sub_total, $this->get_discount_rate(), $this->get_discount_type(), false);
}
} // end calculate_discounts;
/** /**
* Recalculate payment totals. * Recalculate payment totals.
@ -496,30 +473,23 @@ class Line_Item implements \JsonSerializable {
$discounted_subtotal = $sub_total - $discounts; $discounted_subtotal = $sub_total - $discounts;
if ($sub_total > 0 && $discounted_subtotal < 0) { if ($sub_total > 0 && $discounted_subtotal < 0) {
$discounted_subtotal = 0; $discounted_subtotal = 0;
$discounts = $sub_total; $discounts = $sub_total;
}
} // end if;
$taxes = $this->calculate_taxes($discounted_subtotal); $taxes = $this->calculate_taxes($discounted_subtotal);
if ($this->get_tax_inclusive()) { if ($this->get_tax_inclusive()) {
$total = $this->is_tax_exempt() ? $discounted_subtotal - $taxes : $discounted_subtotal; $total = $this->is_tax_exempt() ? $discounted_subtotal - $taxes : $discounted_subtotal;
} else { } else {
$total = $this->is_tax_exempt() ? $discounted_subtotal : $discounted_subtotal + $taxes; // tax exclusive $total = $this->is_tax_exempt() ? $discounted_subtotal : $discounted_subtotal + $taxes; // tax exclusive
} // end if; }
if ($this->is_tax_exempt()) { if ($this->is_tax_exempt()) {
$taxes = 0; $taxes = 0;
}
} // end if;
$totals = array( $totals = array(
'subtotal' => $sub_total, 'subtotal' => $sub_total,
@ -531,8 +501,7 @@ class Line_Item implements \JsonSerializable {
$this->attributes($totals); $this->attributes($totals);
return $this; return $this;
}
} // end recalculate_totals;
/** /**
* Get quantity of the given product. * Get quantity of the given product.
@ -543,8 +512,7 @@ class Line_Item implements \JsonSerializable {
public function get_quantity() { public function get_quantity() {
return $this->quantity; return $this->quantity;
}
} // end get_quantity;
/** /**
* Set quantity of the given product. * Set quantity of the given product.
@ -556,8 +524,7 @@ class Line_Item implements \JsonSerializable {
public function set_quantity($quantity) { public function set_quantity($quantity) {
$this->quantity = $quantity; $this->quantity = $quantity;
}
} // end set_quantity;
/** /**
* Get unit price of the product. * Get unit price of the product.
@ -568,8 +535,7 @@ class Line_Item implements \JsonSerializable {
public function get_unit_price() { public function get_unit_price() {
return $this->unit_price; return $this->unit_price;
}
} // end get_unit_price;
/** /**
* Set unit price of the product. * Set unit price of the product.
@ -581,8 +547,7 @@ class Line_Item implements \JsonSerializable {
public function set_unit_price($unit_price) { public function set_unit_price($unit_price) {
$this->unit_price = $unit_price; $this->unit_price = $unit_price;
}
} // end set_unit_price;
/** /**
* Get tax amount, absolute or percentage. * Get tax amount, absolute or percentage.
@ -593,8 +558,7 @@ class Line_Item implements \JsonSerializable {
public function get_tax_rate() { public function get_tax_rate() {
return $this->tax_rate; return $this->tax_rate;
}
} // end get_tax_rate;
/** /**
* Set tax amount, absolute or percentage. * Set tax amount, absolute or percentage.
@ -606,8 +570,7 @@ class Line_Item implements \JsonSerializable {
public function set_tax_rate($tax_rate) { public function set_tax_rate($tax_rate) {
$this->tax_rate = $tax_rate; $this->tax_rate = $tax_rate;
}
} // end set_tax_rate;
/** /**
* Get type of the tax, percentage or absolute. * Get type of the tax, percentage or absolute.
@ -618,8 +581,7 @@ class Line_Item implements \JsonSerializable {
public function get_tax_type() { public function get_tax_type() {
return $this->tax_type; return $this->tax_type;
}
} // end get_tax_type;
/** /**
* Set type of the tax, percentage or absolute. * Set type of the tax, percentage or absolute.
@ -631,8 +593,7 @@ class Line_Item implements \JsonSerializable {
public function set_tax_type($tax_type) { public function set_tax_type($tax_type) {
$this->tax_type = $tax_type; $this->tax_type = $tax_type;
}
} // end set_tax_type;
/** /**
* Get if tax are included in the price or not. * Get if tax are included in the price or not.
@ -643,8 +604,7 @@ class Line_Item implements \JsonSerializable {
public function get_tax_inclusive() { public function get_tax_inclusive() {
return (bool) $this->tax_inclusive; return (bool) $this->tax_inclusive;
}
} // end get_tax_inclusive;
/** /**
* Set if tax are included in the price or not. * 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) { public function set_tax_inclusive($tax_inclusive) {
$this->tax_inclusive = $tax_inclusive; $this->tax_inclusive = $tax_inclusive;
}
} // end set_tax_inclusive;
/** /**
* Get if the line item is tax exempt ot not. * Get if the line item is tax exempt ot not.
@ -668,8 +627,7 @@ class Line_Item implements \JsonSerializable {
public function is_tax_exempt() { public function is_tax_exempt() {
return $this->tax_exempt; return $this->tax_exempt;
}
} // end is_tax_exempt;
/** /**
* Set if the line item is tax exempt ot not. * 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) { public function set_tax_exempt($tax_exempt) {
$this->tax_exempt = $tax_exempt; $this->tax_exempt = $tax_exempt;
}
} // end set_tax_exempt;
/** /**
* Get the amount, in currency, of the tax. * Get the amount, in currency, of the tax.
@ -693,8 +650,7 @@ class Line_Item implements \JsonSerializable {
public function get_tax_total() { public function get_tax_total() {
return $this->tax_total; return $this->tax_total;
}
} // end get_tax_total;
/** /**
* Set the amount, in currency, of the tax. * Set the amount, in currency, of the tax.
@ -706,8 +662,7 @@ class Line_Item implements \JsonSerializable {
public function set_tax_total($tax_total) { public function set_tax_total($tax_total) {
$this->tax_total = $tax_total; $this->tax_total = $tax_total;
}
} // end set_tax_total;
/** /**
* Get the value of total * Get the value of total
@ -718,8 +673,7 @@ class Line_Item implements \JsonSerializable {
public function get_total() { public function get_total() {
return $this->total; return $this->total;
}
} // end get_total;
/** /**
* Set the value of total. * Set the value of total.
@ -731,8 +685,7 @@ class Line_Item implements \JsonSerializable {
public function set_total($total) { public function set_total($total) {
$this->total = $total; $this->total = $total;
}
} // end set_total;
/** /**
* Get the value of recurring. * Get the value of recurring.
@ -743,8 +696,7 @@ class Line_Item implements \JsonSerializable {
public function is_recurring() { public function is_recurring() {
return $this->recurring; return $this->recurring;
}
} // end is_recurring;
/** /**
* Set the value of recurring. * Set the value of recurring.
@ -756,8 +708,7 @@ class Line_Item implements \JsonSerializable {
public function set_recurring($recurring) { public function set_recurring($recurring) {
$this->recurring = $recurring; $this->recurring = $recurring;
}
} // end set_recurring;
/** /**
* Get value before taxes, discounts, fees and etc. * Get value before taxes, discounts, fees and etc.
@ -768,8 +719,7 @@ class Line_Item implements \JsonSerializable {
public function get_subtotal() { public function get_subtotal() {
return $this->subtotal; return $this->subtotal;
}
} // end get_subtotal;
/** /**
* Set value before taxes, discounts, fees and etc. * Set value before taxes, discounts, fees and etc.
@ -781,8 +731,7 @@ class Line_Item implements \JsonSerializable {
public function set_subtotal($subtotal) { public function set_subtotal($subtotal) {
$this->subtotal = $subtotal; $this->subtotal = $subtotal;
}
} // end set_subtotal;
/** /**
* Get the value of duration * Get the value of duration
@ -793,8 +742,7 @@ class Line_Item implements \JsonSerializable {
public function get_duration() { public function get_duration() {
return $this->duration; return $this->duration;
}
} // end get_duration;
/** /**
* Set the value of duration. * Set the value of duration.
@ -806,8 +754,7 @@ class Line_Item implements \JsonSerializable {
public function set_duration($duration) { public function set_duration($duration) {
$this->duration = $duration; $this->duration = $duration;
}
} // end set_duration;
/** /**
* Get the value of duration_unit. * Get the value of duration_unit.
@ -818,8 +765,7 @@ class Line_Item implements \JsonSerializable {
public function get_duration_unit() { public function get_duration_unit() {
return $this->duration_unit; return $this->duration_unit;
}
} // end get_duration_unit;
/** /**
* Set the value of duration_unit. * Set the value of duration_unit.
@ -831,8 +777,7 @@ class Line_Item implements \JsonSerializable {
public function set_duration_unit($duration_unit) { public function set_duration_unit($duration_unit) {
$this->duration_unit = $duration_unit; $this->duration_unit = $duration_unit;
}
} // end set_duration_unit;
/** /**
* Get the value of billing_cycles. * Get the value of billing_cycles.
@ -843,8 +788,7 @@ class Line_Item implements \JsonSerializable {
public function get_billing_cycles() { public function get_billing_cycles() {
return $this->billing_cycles; return $this->billing_cycles;
}
} // end get_billing_cycles;
/** /**
* Set the value of billing_cycles. * Set the value of billing_cycles.
@ -856,8 +800,7 @@ class Line_Item implements \JsonSerializable {
public function set_billing_cycles($billing_cycles) { public function set_billing_cycles($billing_cycles) {
$this->billing_cycles = $billing_cycles; $this->billing_cycles = $billing_cycles;
}
} // end set_billing_cycles;
/** /**
* Get the value of discount_total. * Get the value of discount_total.
@ -868,8 +811,7 @@ class Line_Item implements \JsonSerializable {
public function get_discount_total() { public function get_discount_total() {
return $this->discount_total; return $this->discount_total;
}
} // end get_discount_total;
/** /**
* Set the value of discount_total. * Set the value of discount_total.
@ -881,8 +823,7 @@ class Line_Item implements \JsonSerializable {
public function set_discount_total($discount_total) { public function set_discount_total($discount_total) {
$this->discount_total = $discount_total; $this->discount_total = $discount_total;
}
} // end set_discount_total;
/** /**
* Get the value of tax_category. * Get the value of tax_category.
@ -893,8 +834,7 @@ class Line_Item implements \JsonSerializable {
public function get_tax_category() { public function get_tax_category() {
return $this->tax_category; return $this->tax_category;
}
} // end get_tax_category;
/** /**
* Set the value of tax_category. * Set the value of tax_category.
@ -906,8 +846,7 @@ class Line_Item implements \JsonSerializable {
public function set_tax_category($tax_category) { public function set_tax_category($tax_category) {
$this->tax_category = $tax_category; $this->tax_category = $tax_category;
}
} // end set_tax_category;
/** /**
* Get the value of discountable. * Get the value of discountable.
@ -918,8 +857,7 @@ class Line_Item implements \JsonSerializable {
public function is_discountable() { public function is_discountable() {
return $this->discountable; return $this->discountable;
}
} // end is_discountable;
/** /**
* Set the value of discountable. * Set the value of discountable.
@ -931,8 +869,7 @@ class Line_Item implements \JsonSerializable {
public function set_discountable($discountable) { public function set_discountable($discountable) {
$this->discountable = $discountable; $this->discountable = $discountable;
}
} // end set_discountable;
/** /**
* Get the value of taxable. * Get the value of taxable.
@ -943,8 +880,7 @@ class Line_Item implements \JsonSerializable {
public function is_taxable() { public function is_taxable() {
return $this->taxable; return $this->taxable;
}
} // end is_taxable;
/** /**
* Set the value of taxable. * Set the value of taxable.
@ -956,8 +892,7 @@ class Line_Item implements \JsonSerializable {
public function set_taxable($taxable) { public function set_taxable($taxable) {
$this->taxable = $taxable; $this->taxable = $taxable;
}
} // end set_taxable;
/** /**
* Get the value of discount_rate. * Get the value of discount_rate.
@ -968,8 +903,7 @@ class Line_Item implements \JsonSerializable {
public function get_discount_rate() { public function get_discount_rate() {
return $this->discount_rate; return $this->discount_rate;
}
} // end get_discount_rate;
/** /**
* Set the value of discount_rate. * Set the value of discount_rate.
@ -981,8 +915,7 @@ class Line_Item implements \JsonSerializable {
public function set_discount_rate($discount_rate) { public function set_discount_rate($discount_rate) {
$this->discount_rate = $discount_rate; $this->discount_rate = $discount_rate;
}
} // end set_discount_rate;
/** /**
* Get the value of discount_type. * Get the value of discount_type.
@ -993,8 +926,7 @@ class Line_Item implements \JsonSerializable {
public function get_discount_type() { public function get_discount_type() {
return $this->discount_type; return $this->discount_type;
}
} // end get_discount_type;
/** /**
* Set the value of discount_type. * Set the value of discount_type.
@ -1006,8 +938,7 @@ class Line_Item implements \JsonSerializable {
public function set_discount_type($discount_type) { public function set_discount_type($discount_type) {
$this->discount_type = $discount_type; $this->discount_type = $discount_type;
}
} // end set_discount_type;
/** /**
* Get discount Label. * Get discount Label.
@ -1018,8 +949,7 @@ class Line_Item implements \JsonSerializable {
public function get_discount_label() { public function get_discount_label() {
return $this->discount_label; return $this->discount_label;
}
} // end get_discount_label;
/** /**
* Set discount Label. * Set discount Label.
@ -1031,8 +961,7 @@ class Line_Item implements \JsonSerializable {
public function set_discount_label($discount_label) { public function set_discount_label($discount_label) {
$this->discount_label = $discount_label; $this->discount_label = $discount_label;
}
} // end set_discount_label;
/** /**
* Get if we should apply discount to renewals. * Get if we should apply discount to renewals.
@ -1043,8 +972,7 @@ class Line_Item implements \JsonSerializable {
public function should_apply_discount_to_renewals() { public function should_apply_discount_to_renewals() {
return $this->apply_discount_to_renewals; return $this->apply_discount_to_renewals;
}
} // end should_apply_discount_to_renewals;
/** /**
* Set if we 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) { public function set_apply_discount_to_renewals($apply_discount_to_renewals) {
$this->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. * Get the value of product_id.
@ -1068,8 +995,7 @@ class Line_Item implements \JsonSerializable {
public function get_product_id() { public function get_product_id() {
return $this->product_id; return $this->product_id;
}
} // end get_product_id;
/** /**
* Set the value of product_id. * Set the value of product_id.
@ -1081,8 +1007,7 @@ class Line_Item implements \JsonSerializable {
public function set_product_id($product_id) { public function set_product_id($product_id) {
$this->product_id = $product_id; $this->product_id = $product_id;
}
} // end set_product_id;
/** /**
* Get the value of title * Get the value of title
@ -1093,8 +1018,7 @@ class Line_Item implements \JsonSerializable {
public function get_title() { public function get_title() {
return $this->title; return $this->title;
}
} // end get_title;
/** /**
* Set the value of title. * Set the value of title.
@ -1106,8 +1030,7 @@ class Line_Item implements \JsonSerializable {
public function set_title($title) { public function set_title($title) {
$this->title = $title; $this->title = $title;
}
} // end set_title;
/** /**
* Get the value of description. * Get the value of description.
@ -1118,8 +1041,7 @@ class Line_Item implements \JsonSerializable {
public function get_description() { public function get_description() {
return $this->description; return $this->description;
}
} // end get_description;
/** /**
* Set the value of description. * Set the value of description.
@ -1131,8 +1053,7 @@ class Line_Item implements \JsonSerializable {
public function set_description($description) { public function set_description($description) {
$this->description = $description; $this->description = $description;
}
} // end set_description;
/** /**
* Get label of the tax applied. * Get label of the tax applied.
@ -1143,8 +1064,7 @@ class Line_Item implements \JsonSerializable {
public function get_tax_label() { public function get_tax_label() {
return $this->tax_label; return $this->tax_label;
}
} // end get_tax_label;
/** /**
* Set label of the tax applied. * Set label of the tax applied.
@ -1156,8 +1076,7 @@ class Line_Item implements \JsonSerializable {
public function set_tax_label($tax_label) { public function set_tax_label($tax_label) {
$this->tax_label = $tax_label; $this->tax_label = $tax_label;
}
} // end set_tax_label;
/** /**
* Returns the amount recurring in a human-friendly way. * Returns the amount recurring in a human-friendly way.
@ -1168,10 +1087,8 @@ class Line_Item implements \JsonSerializable {
public function get_recurring_description() { public function get_recurring_description() {
if ( ! $this->is_recurring()) { if ( ! $this->is_recurring()) {
return ''; return '';
}
} // end if;
$description = sprintf( $description = sprintf(
// translators: %1$s the duration, and %2$s the duration unit (day, week, month, etc) // 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; return $description;
}
} // end get_recurring_description;
/** /**
* Converts the line item to an array. * Converts the line item to an array.
@ -1197,8 +1113,7 @@ class Line_Item implements \JsonSerializable {
$array['recurring_description'] = $this->get_recurring_description(); $array['recurring_description'] = $this->get_recurring_description();
return $array; return $array;
}
} // end to_array;
/** /**
* Implements our on json_decode version of this object. Useful for use in vue.js. * 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() { public function jsonSerialize() {
return $this->to_array(); return $this->to_array();
}
} // end jsonSerialize;
/** /**
* Queries the database for Line Items across payments. * Queries the database for Line Items across payments.
@ -1225,11 +1139,14 @@ class Line_Item implements \JsonSerializable {
global $wpdb; global $wpdb;
$query = wp_parse_args($query, array( $query = wp_parse_args(
$query,
array(
'number' => 100, 'number' => 100,
'date_query' => array(), 'date_query' => array(),
'payment_status' => false, 'payment_status' => false,
)); )
);
$query['date_query']['column'] = 'p.date_created'; $query['date_query']['column'] = 'p.date_created';
@ -1241,11 +1158,9 @@ class Line_Item implements \JsonSerializable {
$status_query_sql = ''; $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']}'"; $status_query_sql = "AND p.status = '{$query['payment_status']}'";
}
} // end if;
// phpcs:disable; // phpcs:disable;
$query = $wpdb->prepare(" $query = $wpdb->prepare("
@ -1266,26 +1181,25 @@ class Line_Item implements \JsonSerializable {
$results = $wpdb->get_results($query); // phpcs:ignore $results = $wpdb->get_results($query); // phpcs:ignore
foreach ($results as &$ln) { foreach ($results as &$ln) {
$copy = $ln; $copy = $ln;
$line_items = $ln->line_items; $line_items = $ln->line_items;
$ln = maybe_unserialize($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; $_ln->date_created = $copy->date_created;
return $_ln; return $_ln;
},
}, $ln); $ln
);
} // end foreach; }
return $results; return $results;
}
} // end get_line_items;
/** /**
* Get the product slug, if any. * Get the product slug, if any.
@ -1296,8 +1210,7 @@ class Line_Item implements \JsonSerializable {
public function get_product_slug() { public function get_product_slug() {
return $this->product_slug; return $this->product_slug;
}
} // end get_product_slug;
/** /**
* Set the product slug. * Set the product slug.
@ -1309,7 +1222,5 @@ class Line_Item implements \JsonSerializable {
public function set_product_slug($product_slug) { public function set_product_slug($product_slug) {
$this->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() { public function is_hidden() {
return false; return false;
}
} // end is_hidden;
/** /**
* Defines if this field/element is related to site creation or not. * 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() { public function is_site_field() {
return false; return false;
}
} // end is_site_field;
/** /**
* Defines if this field/element is related to user/customer creation or not. * 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() { public function is_user_field() {
return false; return false;
}
} // end is_user_field;
/** /**
* Returns the field as an array that the form builder can understand. * 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(), 'all_attributes' => $this->get_all_attributes(),
'fields' => array($this, 'get_editor_fields'), 'fields' => array($this, 'get_editor_fields'),
); );
}
} // end get_field_as_type_option;
/** /**
* Modifies the HTML attr array before sending it over to the form. * 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) { public function get_editor_fields_html_attr($html_attr, $field_name) {
return $html_attr; return $html_attr;
}
} // end get_editor_fields_html_attr;
/** /**
* Get the tabs available for this field. * Get the tabs available for this field.
@ -189,8 +184,7 @@ abstract class Base_Signup_Field {
'content', 'content',
'style', 'style',
); );
}
} // end get_tabs;
/** /**
* Gets the pre-filled value for the field. * 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']); $value_session = wu_get_isset($session->get('signup'), $this->attributes['id']);
if ($value_session) { if ($value_session) {
$value = $value_session; $value = $value_session;
}
} // end if;
if (wu_get_isset($this->attributes, 'from_request') && wu_get_isset($this->attributes, 'id')) { if (wu_get_isset($this->attributes, 'from_request') && wu_get_isset($this->attributes, 'id')) {
$value = wu_request($this->attributes['id'], ''); $value = wu_request($this->attributes['id'], '');
}
} // end if;
return $value; return $value;
}
} // end get_value;
/** /**
* Calculate the style attributes for the field. * Calculate the style attributes for the field.
@ -235,24 +224,17 @@ abstract class Base_Signup_Field {
$width = (int) wu_get_isset($this->attributes, 'width'); $width = (int) wu_get_isset($this->attributes, 'width');
if ($width) { if ($width) {
if ($width !== 100) { if ($width !== 100) {
$styles[] = 'float: left'; $styles[] = 'float: left';
$styles[] = sprintf('width: %s%%', $width); $styles[] = sprintf('width: %s%%', $width);
}
} // end if;
} else { } else {
$styles[] = 'clear: both'; $styles[] = 'clear: both';
}
} // end if;
return implode('; ', $styles); return implode('; ', $styles);
}
} // end calculate_style_attr;
/** /**
* Sets the config values for the current field. * Sets the config values for the current field.
@ -265,8 +247,7 @@ abstract class Base_Signup_Field {
public function set_attributes($attributes) { public function set_attributes($attributes) {
$this->attributes = $attributes; $this->attributes = $attributes;
}
} // end set_attributes;
/** /**
* If you want to force a particular attribute to a value, declare it here. * 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() { public function force_attributes() {
return array(); return array();
}
} // end force_attributes;
/** /**
* Default values for the editor fields. * Default values for the editor fields.
@ -289,8 +269,7 @@ abstract class Base_Signup_Field {
public function defaults() { public function defaults() {
return array(); return array();
}
} // end defaults;
/** /**
* List of keys of the default fields we want to display on the builder. * List of keys of the default fields we want to display on the builder.
@ -308,8 +287,7 @@ abstract class Base_Signup_Field {
'default', 'default',
'required', 'required',
); );
}
} // end default_fields;
/** /**
* Returns the editor fields. * Returns the editor fields.
@ -327,32 +305,27 @@ abstract class Base_Signup_Field {
* Checks if this is a site field * Checks if this is a site field
*/ */
if ($this->is_site_field()) { if ($this->is_site_field()) {
$final_field_list[ '_site_notice_field_' . uniqid() ] = array( $final_field_list[ '_site_notice_field_' . uniqid() ] = array(
'type' => 'note', 'type' => 'note',
'classes' => 'wu--mt-px', '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')), '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, 'order' => 98.5,
); );
}
} // end if;
/* /*
* Checks if this is a user field * Checks if this is a user field
*/ */
if ($this->is_user_field()) { if ($this->is_user_field()) {
$final_field_list[ '_user_notice_field_' . uniqid() ] = array( $final_field_list[ '_user_notice_field_' . uniqid() ] = array(
'type' => 'note', 'type' => 'note',
'classes' => 'wu--mt-px', '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')), '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, 'order' => 98.5,
); );
}
} // end if;
foreach ($final_field_list as $key => &$field) { foreach ($final_field_list as $key => &$field) {
$field['html_attr'] = wu_get_isset($field, 'html_attr', array()); $field['html_attr'] = wu_get_isset($field, 'html_attr', array());
$value = wu_get_isset($attributes, $key, null); $value = wu_get_isset($attributes, $key, null);
@ -360,13 +333,10 @@ abstract class Base_Signup_Field {
$field['default'] = wu_get_isset($this->defaults(), $key, ''); $field['default'] = wu_get_isset($this->defaults(), $key, '');
if ($value === null) { if ($value === null) {
$value = $field['default']; $value = $field['default'];
}
} // end if;
if (wu_get_isset($field['html_attr'], 'data-model')) { if (wu_get_isset($field['html_attr'], 'data-model')) {
$model_name = wu_get_isset($field['html_attr'], 'data-model', 'product'); $model_name = wu_get_isset($field['html_attr'], 'data-model', 'product');
$models = explode(',', (string) $value); $models = explode(',', (string) $value);
@ -374,34 +344,29 @@ abstract class Base_Signup_Field {
$func_name = "wu_get_{$model_name}"; $func_name = "wu_get_{$model_name}";
if (function_exists($func_name)) { if (function_exists($func_name)) {
$selected = array_map(
$selected = array_map(function($id) use ($func_name) { function ($id) use ($func_name) {
$model = call_user_func($func_name, absint($id)); $model = call_user_func($func_name, absint($id));
if ( ! $model) { if ( ! $model) {
return false; return false;
}
} // end if;
return $model->to_search_results(); return $model->to_search_results();
},
}, $models); $models
);
$selected = array_filter($selected); $selected = array_filter($selected);
$field['html_attr']['data-selected'] = json_encode($selected); $field['html_attr']['data-selected'] = json_encode($selected);
}
} // end if; }
} // end if;
if ( ! is_null($value)) { if ( ! is_null($value)) {
$field['value'] = $value; $field['value'] = $value;
}
} // end if;
$field['html_attr'] = $this->get_editor_fields_html_attr($field['html_attr'], $field['type']); $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; $show_reqs = false;
if (isset($field['wrapper_html_attr'])) { if (isset($field['wrapper_html_attr'])) {
$show_reqs = wu_get_isset($field['wrapper_html_attr'], 'v-show'); $show_reqs = wu_get_isset($field['wrapper_html_attr'], 'v-show');
}
} // end if;
$tab = wu_get_isset($field, 'tab', 'content'); $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-cloak' => 1,
'v-show' => sprintf('require("type", "%s") && require("tab", "%s")', $this->get_type(), $tab) . ($show_reqs ? " && $show_reqs" : ''), 'v-show' => sprintf('require("type", "%s") && require("tab", "%s")', $this->get_type(), $tab) . ($show_reqs ? " && $show_reqs" : ''),
)); )
);
} // end foreach; }
return $final_field_list; return $final_field_list;
}
} // end get_editor_fields;
/** /**
* Returns a list of all the attributes. * Returns a list of all the attributes.
@ -449,8 +413,7 @@ abstract class Base_Signup_Field {
$field_keys = array_keys($this->get_fields()); $field_keys = array_keys($this->get_fields());
return array_merge($this->default_fields(), $field_keys, $styles); return array_merge($this->default_fields(), $field_keys, $styles);
}
} // end get_all_attributes;
/** /**
* Treat the attributes array to avoid reaching the input var limits. * 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) { public function reduce_attributes($attributes) {
return $attributes; return $attributes;
}
} // end reduce_attributes;
/** /**
* List of all the default fields available. * List of all the default fields available.
@ -608,7 +570,5 @@ abstract class Base_Signup_Field {
); );
return $fields; return $fields;
}
} // end fields_list; }
} // end class Base_Signup_Field;

View File

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

View File

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

View File

@ -9,7 +9,7 @@
namespace WP_Ultimo\Checkout\Signup_Fields; 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 // Exit if accessed directly
defined('ABSPATH') || exit; defined('ABSPATH') || exit;
@ -32,8 +32,7 @@ class Signup_Field_Color extends Base_Signup_Field {
public function get_type() { public function get_type() {
return 'color_picker'; return 'color_picker';
}
} // end get_type;
/** /**
* Returns if this field should be present on the checkout flow or not. * 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() { public function is_required() {
return false; return false;
}
} // end is_required;
/** /**
* Requires the title of the field/element type. * Requires the title of the field/element type.
@ -58,8 +56,7 @@ class Signup_Field_Color extends Base_Signup_Field {
public function get_title() { public function get_title() {
return __('Color', 'wp-ultimo'); return __('Color', 'wp-ultimo');
}
} // end get_title;
/** /**
* Returns the description of the field/element. * Returns the description of the field/element.
@ -72,8 +69,7 @@ class Signup_Field_Color extends Base_Signup_Field {
public function get_description() { public function get_description() {
return __('Adds a color picker field.', 'wp-ultimo'); return __('Adds a color picker field.', 'wp-ultimo');
}
} // end get_description;
/** /**
* Returns the tooltip of the field/element. * Returns the tooltip of the field/element.
@ -86,8 +82,7 @@ class Signup_Field_Color extends Base_Signup_Field {
public function get_tooltip() { public function get_tooltip() {
return __('Adds a color picker field.', 'wp-ultimo'); return __('Adds a color picker field.', 'wp-ultimo');
}
} // end get_tooltip;
/** /**
* Returns the icon to be used on the selector. * 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() { public function get_icon() {
return 'dashicons-wu-droplet'; return 'dashicons-wu-droplet';
}
} // end get_icon;
/** /**
* Returns the default values for the field-elements. * Returns the default values for the field-elements.
@ -115,10 +109,9 @@ class Signup_Field_Color extends Base_Signup_Field {
public function defaults() { public function defaults() {
return array( return array(
'' '',
); );
}
} // end defaults;
/** /**
* List of keys of the default fields we want to display on the builder. * 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', 'required',
'save_as', 'save_as',
); );
}
} // end default_fields;
/** /**
* If you want to force a particular attribute to a value, declare it here. * 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() { public function force_attributes() {
return array(); return array();
}
} // end force_attributes;
/** /**
* Returns the list of additional fields specific to this type. * 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'), '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. * 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; 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 // Exit if accessed directly
defined('ABSPATH') || exit; defined('ABSPATH') || exit;
@ -32,8 +32,7 @@ class Signup_Field_Discount_Code extends Base_Signup_Field {
public function get_type() { public function get_type() {
return 'discount_code'; return 'discount_code';
}
} // end get_type;
/** /**
* Returns if this field should be present on the checkout flow or not. * 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() { public function is_required() {
return false; return false;
}
} // end is_required;
/** /**
* Requires the title of the field/element type. * 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() { public function get_title() {
return __('Coupon Code', 'wp-ultimo'); return __('Coupon Code', 'wp-ultimo');
}
} // end get_title;
/** /**
* Returns the description of the field/element. * Returns the description of the field/element.
@ -72,8 +69,7 @@ class Signup_Field_Discount_Code extends Base_Signup_Field {
public function get_description() { public function get_description() {
return __('Adds an additional field to apply a discount code.', 'wp-ultimo'); return __('Adds an additional field to apply a discount code.', 'wp-ultimo');
}
} // end get_description;
/** /**
* Returns the tooltip of the field/element. * Returns the tooltip of the field/element.
@ -86,8 +82,7 @@ class Signup_Field_Discount_Code extends Base_Signup_Field {
public function get_tooltip() { public function get_tooltip() {
return __('Adds an additional field to apply a discount code.', 'wp-ultimo'); return __('Adds an additional field to apply a discount code.', 'wp-ultimo');
}
} // end get_tooltip;
/** /**
* Returns the icon to be used on the selector. * 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() { public function get_icon() {
return 'dashicons-wu-tag1'; return 'dashicons-wu-tag1';
}
} // end get_icon;
/** /**
* Returns the default values for the field-elements. * Returns the default values for the field-elements.
@ -118,8 +112,7 @@ class Signup_Field_Discount_Code extends Base_Signup_Field {
'placeholder' => '', 'placeholder' => '',
'default' => '', 'default' => '',
); );
}
} // end defaults;
/** /**
* List of keys of the default fields we want to display on the builder. * 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', 'placeholder',
'tooltip', 'tooltip',
); );
}
} // end default_fields;
/** /**
* If you want to force a particular attribute to a value, declare it here. * 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( return array(
'id' => 'discount_code', 'id' => 'discount_code',
); );
}
} // end force_attributes;
/** /**
* Returns the list of additional fields specific to this type. * 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() { public function get_fields() {
return array(); return array();
}
} // end get_fields;
/** /**
* Returns the field/element actual field array to be used on the checkout form. * 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; 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; 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 // Exit if accessed directly
defined('ABSPATH') || exit; defined('ABSPATH') || exit;
@ -31,8 +31,7 @@ class Signup_Field_Email extends Base_Signup_Field {
public function get_type(): string { public function get_type(): string {
return 'email'; return 'email';
}
} // end get_type;
/** /**
* Returns if this field should be present on the checkout flow or not. * 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 { public function is_required(): bool {
return true; return true;
}
} // end is_required;
/** /**
* Is this a user-related field? * Is this a user-related field?
* *
@ -54,8 +52,7 @@ class Signup_Field_Email extends Base_Signup_Field {
public function is_user_field(): bool { public function is_user_field(): bool {
return false; return false;
}
} // end is_user_field;
/** /**
* Requires the title of the field/element type. * Requires the title of the field/element type.
@ -68,8 +65,7 @@ class Signup_Field_Email extends Base_Signup_Field {
public function get_title() { public function get_title() {
return __('Email', 'wp-ultimo'); return __('Email', 'wp-ultimo');
}
} // end get_title;
/** /**
* Returns the description of the field/element. * Returns the description of the field/element.
@ -82,8 +78,7 @@ class Signup_Field_Email extends Base_Signup_Field {
public function get_description() { public function get_description() {
return __('Adds a email address field. This email address will be used to create the WordPress user.', 'wp-ultimo'); 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. * Returns the tooltip of the field/element.
@ -96,8 +91,7 @@ class Signup_Field_Email extends Base_Signup_Field {
public function get_tooltip() { public function get_tooltip() {
return __('Adds a email address field. This email address will be used to create the WordPress user.', 'wp-ultimo'); 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. * 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 { public function get_icon(): string {
return 'dashicons-wu-at-sign'; return 'dashicons-wu-at-sign';
}
} // end get_icon;
/** /**
* Returns the default values for the field-elements. * Returns the default values for the field-elements.
@ -125,8 +118,7 @@ class Signup_Field_Email extends Base_Signup_Field {
return array( return array(
'display_notices' => true, 'display_notices' => true,
); );
}
} // end defaults;
/** /**
* List of keys of the default fields we want to display on the builder. * 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', 'placeholder',
'tooltip', 'tooltip',
); );
}
} // end default_fields;
/** /**
* If you want to force a particular attribute to a value, declare it here. * 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', 'id' => 'email_address',
'required' => true, 'required' => true,
); );
}
} // end force_attributes;
/** /**
* Returns the list of additional fields specific to this type. * 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. * 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(); $checkout_fields = array();
if (is_user_logged_in()) { if (is_user_logged_in()) {
if ($attributes['display_notices']) { if ($attributes['display_notices']) {
$checkout_fields['login_note'] = array( $checkout_fields['login_note'] = array(
'type' => 'note', 'type' => 'note',
'title' => __('Not you?', 'wp-ultimo'), 'title' => __('Not you?', 'wp-ultimo'),
@ -207,13 +194,9 @@ class Signup_Field_Email extends Base_Signup_Field {
'style' => $this->calculate_style_attr(), 'style' => $this->calculate_style_attr(),
), ),
); );
}
} // end if;
} else { } else {
if ($attributes['display_notices']) { if ($attributes['display_notices']) {
$checkout_fields['login_note'] = array( $checkout_fields['login_note'] = array(
'type' => 'note', 'type' => 'note',
'title' => __('Existing customer?', 'wp-ultimo'), 'title' => __('Existing customer?', 'wp-ultimo'),
@ -223,8 +206,7 @@ class Signup_Field_Email extends Base_Signup_Field {
'style' => $this->calculate_style_attr(), 'style' => $this->calculate_style_attr(),
), ),
); );
}
} // end if;
$checkout_fields['email_address'] = array( $checkout_fields['email_address'] = array(
'type' => 'text', 'type' => 'text',
@ -240,12 +222,10 @@ class Signup_Field_Email extends Base_Signup_Field {
'style' => $this->calculate_style_attr(), 'style' => $this->calculate_style_attr(),
), ),
); );
}
} // end if;
return $checkout_fields; return $checkout_fields;
}
} // end to_fields_array;
/** /**
* Renders the login message for users that are not logged in. * 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 <?php // phpcs:enable
return ob_get_clean(); return ob_get_clean();
}
} // end render_existing_customer_message;
/** /**
* Renders the login message for users that are not logged in. * Renders the login message for users that are not logged in.
@ -302,7 +281,5 @@ class Signup_Field_Email extends Base_Signup_Field {
<?php <?php
return ob_get_clean(); 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; 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 // Exit if accessed directly
defined('ABSPATH') || exit; defined('ABSPATH') || exit;
@ -32,8 +32,7 @@ class Signup_Field_Hidden extends Base_Signup_Field {
public function get_type() { public function get_type() {
return 'hidden'; return 'hidden';
}
} // end get_type;
/** /**
* Returns if this field should be present on the checkout flow or not. * 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() { public function is_required() {
return false; return false;
}
} // end is_required;
/** /**
* Requires the title of the field/element type. * Requires the title of the field/element type.
@ -58,8 +56,7 @@ class Signup_Field_Hidden extends Base_Signup_Field {
public function get_title() { public function get_title() {
return __('Hidden Field', 'wp-ultimo'); return __('Hidden Field', 'wp-ultimo');
}
} // end get_title;
/** /**
* Returns the description of the field/element. * Returns the description of the field/element.
@ -72,8 +69,7 @@ class Signup_Field_Hidden extends Base_Signup_Field {
public function get_description() { 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'); 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. * Returns the tooltip of the field/element.
@ -86,8 +82,7 @@ class Signup_Field_Hidden extends Base_Signup_Field {
public function get_tooltip() { 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'); 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. * 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() { public function get_icon() {
return 'dashicons-wu-eye-off'; return 'dashicons-wu-eye-off';
}
} // end get_icon;
/** /**
* Returns the default values for the field-elements. * Returns the default values for the field-elements.
@ -117,8 +111,7 @@ class Signup_Field_Hidden extends Base_Signup_Field {
return array( return array(
'from_request' => true, 'from_request' => true,
); );
}
} // end defaults;
/** /**
* List of keys of the default fields we want to display on the builder. * 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', 'id',
'save_as', 'save_as',
); );
}
} // end default_fields;
/** /**
* If you want to force a particular attribute to a value, declare it here. * 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() { public function force_attributes() {
return array(); return array();
}
} // end force_attributes;
/** /**
* Returns the list of additional fields specific to this type. * Returns the list of additional fields specific to this type.
@ -166,8 +157,7 @@ class Signup_Field_Hidden extends Base_Signup_Field {
'value' => '', 'value' => '',
), ),
); );
}
} // end get_fields;
/** /**
* Gets the pre-filled value for the field. * Gets the pre-filled value for the field.
@ -180,14 +170,11 @@ class Signup_Field_Hidden extends Base_Signup_Field {
$value = parent::get_value(); $value = parent::get_value();
if (empty($value)) { if (empty($value)) {
$value = $this->attributes['fixed_value']; $value = $this->attributes['fixed_value'];
}
} // end if;
return $value; return $value;
}
} // end get_value;
/** /**
* Returns the field/element actual field array to be used on the checkout form. * 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(), '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; namespace WP_Ultimo\Checkout\Signup_Fields;
use \WP_Ultimo\Checkout\Signup_Fields\Base_Signup_Field; use WP_Ultimo\Checkout\Signup_Fields\Base_Signup_Field;
use \WP_Ultimo\Managers\Field_Templates_Manager; use WP_Ultimo\Managers\Field_Templates_Manager;
// Exit if accessed directly // Exit if accessed directly
defined('ABSPATH') || exit; defined('ABSPATH') || exit;
@ -33,8 +33,7 @@ class Signup_Field_Order_Bump extends Base_Signup_Field {
public function get_type() { public function get_type() {
return 'order_bump'; return 'order_bump';
}
} // end get_type;
/** /**
* Returns if this field should be present on the checkout flow or not. * 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() { public function is_required() {
return false; return false;
}
} // end is_required;
/** /**
* Requires the title of the field/element type. * 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() { public function get_title() {
return __('Order Bump', 'wp-ultimo'); return __('Order Bump', 'wp-ultimo');
}
} // end get_title;
/** /**
* Returns the description of the field/element. * Returns the description of the field/element.
@ -73,8 +70,7 @@ class Signup_Field_Order_Bump extends Base_Signup_Field {
public function get_description() { public function get_description() {
return __('Adds a product offer that the customer can click to add to the current cart.', 'wp-ultimo'); 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. * Returns the tooltip of the field/element.
@ -87,8 +83,7 @@ class Signup_Field_Order_Bump extends Base_Signup_Field {
public function get_tooltip() { public function get_tooltip() {
return __('Adds a product offer that the customer can click to add to the current cart.', 'wp-ultimo'); 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. * 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() { public function get_icon() {
return 'dashicons-wu-gift'; return 'dashicons-wu-gift';
}
} // end get_icon;
/** /**
* Returns the default values for the field-elements. * 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', 'order_bump_template' => 'simple',
'display_product_description' => 0, 'display_product_description' => 0,
); );
}
} // end defaults;
/** /**
* List of keys of the default fields we want to display on the builder. * 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', // 'id',
'name', 'name',
); );
}
} // end default_fields;
/** /**
* If you want to force a particular attribute to a value, declare it here. * 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( return array(
'order_bump_template' => 'simple', 'order_bump_template' => 'simple',
); );
}
} // end force_attributes;
/** /**
* Returns the list of available pricing table templates. * 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'); $available_templates = Field_Templates_Manager::get_instance()->get_templates_as_options('order_bump');
return $available_templates; return $available_templates;
}
} // end get_templates;
/** /**
* Returns the list of additional fields specific to this type. * 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; return $editor_fields;
}
} // end get_fields;
/** /**
* Returns the field/element actual field array to be used on the checkout form. * 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); $product = is_numeric($product_id) ? wu_get_product($product_id) : wu_get_product_by_slug($product_id);
if ( ! $product) { if ( ! $product) {
return array(); return array();
}
} // end if;
$attributes['product'] = $product; $attributes['product'] = $product;
@ -269,7 +256,5 @@ class Signup_Field_Order_Bump extends Base_Signup_Field {
'wrapper_classes' => $attributes['element_classes'], '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; namespace WP_Ultimo\Checkout\Signup_Fields;
use \WP_Ultimo\Checkout\Signup_Fields\Base_Signup_Field; use WP_Ultimo\Checkout\Signup_Fields\Base_Signup_Field;
use \WP_Ultimo\Managers\Field_Templates_Manager; use WP_Ultimo\Managers\Field_Templates_Manager;
// Exit if accessed directly // Exit if accessed directly
defined('ABSPATH') || exit; defined('ABSPATH') || exit;
@ -32,8 +32,7 @@ class Signup_Field_Order_Summary extends Base_Signup_Field {
public function get_type(): string { public function get_type(): string {
return 'order_summary'; return 'order_summary';
}
} // end get_type;
/** /**
* Returns if this field should be present on the checkout flow or not. * 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 { public function is_required(): bool {
return true; return true;
}
} // end is_required;
/** /**
* Requires the title of the field/element type. * 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() { public function get_title() {
return __('Order Summary', 'wp-ultimo'); return __('Order Summary', 'wp-ultimo');
}
} // end get_title;
/** /**
* Returns the description of the field/element. * Returns the description of the field/element.
@ -70,8 +67,7 @@ class Signup_Field_Order_Summary extends Base_Signup_Field {
public function get_description() { public function get_description() {
return __('Adds a summary table with prices, key subscription dates, discounts, and taxes.', 'wp-ultimo'); 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. * Returns the tooltip of the field/element.
@ -84,8 +80,7 @@ class Signup_Field_Order_Summary extends Base_Signup_Field {
public function get_tooltip() { public function get_tooltip() {
return __('Adds a summary table with prices, key subscription dates, discounts, and taxes.', 'wp-ultimo'); 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. * 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 { public function get_icon(): string {
return 'dashicons-wu-dollar-sign'; return 'dashicons-wu-dollar-sign';
}
} // end get_icon;
/** /**
* Returns the default values for the field-elements. * 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', 'order_summary_template' => 'clean',
'table_columns' => 'simple', 'table_columns' => 'simple',
); );
}
} // end defaults;
/** /**
* List of keys of the default fields we want to display on the builder. * 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( return array(
'name', 'name',
); );
}
} // end default_fields;
/** /**
* If you want to force a particular attribute to a value, declare it here. * 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( return array(
'id' => 'order_summary', 'id' => 'order_summary',
); );
}
} // end force_attributes;
/** /**
* Returns the list of available pricing table templates. * 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'); $available_templates = Field_Templates_Manager::get_instance()->get_templates_as_options('order_summary');
return $available_templates; return $available_templates;
}
} // end get_templates;
/** /**
* Returns the list of additional fields specific to this type. * 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( 'options' => array(
'simple' => __('Simplified', 'wp-ultimo'), 'simple' => __('Simplified', 'wp-ultimo'),
'full' => __('Display All', 'wp-ultimo'), 'full' => __('Display All', 'wp-ultimo'),
) ),
); );
$editor_fields['order_summary_template'] = array( $editor_fields['order_summary_template'] = array(
@ -206,8 +196,7 @@ class Signup_Field_Order_Summary extends Base_Signup_Field {
// ); // );
return $editor_fields; return $editor_fields;
}
} // end get_fields;
/** /**
* Returns the field/element actual field array to be used on the checkout form. * 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 * Backwards compatibility with previous betas
*/ */
if ($attributes['order_summary_template'] === 'simple') { if ($attributes['order_summary_template'] === 'simple') {
$attributes['order_summary_template'] = 'clean'; $attributes['order_summary_template'] = 'clean';
}
} // end if;
$template_class = Field_Templates_Manager::get_instance()->get_template_class('order_summary', $attributes['order_summary_template']); $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; 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; 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 // Exit if accessed directly
defined('ABSPATH') || exit; defined('ABSPATH') || exit;
@ -32,8 +32,7 @@ class Signup_Field_Password extends Base_Signup_Field {
public function get_type() { public function get_type() {
return 'password'; return 'password';
}
} // end get_type;
/** /**
* Returns if this field should be present on the checkout flow or not. * 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() { public function is_required() {
return true; return true;
}
} // end is_required;
/** /**
* Is this a user-related field? * Is this a user-related field?
@ -59,8 +57,7 @@ class Signup_Field_Password extends Base_Signup_Field {
public function is_user_field() { public function is_user_field() {
return true; return true;
}
} // end is_user_field;
/** /**
* Requires the title of the field/element type. * Requires the title of the field/element type.
@ -73,8 +70,7 @@ class Signup_Field_Password extends Base_Signup_Field {
public function get_title() { public function get_title() {
return __('Password', 'wp-ultimo'); return __('Password', 'wp-ultimo');
}
} // end get_title;
/** /**
* Returns the description of the field/element. * Returns the description of the field/element.
@ -87,8 +83,7 @@ class Signup_Field_Password extends Base_Signup_Field {
public function get_description() { 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'); 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. * Returns the tooltip of the field/element.
@ -101,8 +96,7 @@ class Signup_Field_Password extends Base_Signup_Field {
public function get_tooltip() { 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'); 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. * 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() { public function get_icon() {
return 'dashicons-wu-lock1'; return 'dashicons-wu-lock1';
}
} // end get_icon;
/** /**
* Returns the default values for the field-elements. * 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_field' => false,
'password_confirm_label' => __('Confirm Password', 'wp-ultimo'), 'password_confirm_label' => __('Confirm Password', 'wp-ultimo'),
); );
}
} // end defaults;
/** /**
* List of keys of the default fields we want to display on the builder. * 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', 'placeholder',
'tooltip', 'tooltip',
); );
}
} // end default_fields;
/** /**
* If you want to force a particular attribute to a value, declare it here. * 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', 'id' => 'password',
'required' => true, 'required' => true,
); );
}
} // end force_attributes;
/** /**
* Returns the list of additional fields specific to this type. * Returns the list of additional fields specific to this type.
@ -189,8 +179,7 @@ class Signup_Field_Password extends Base_Signup_Field {
'value' => 1, 'value' => 1,
), ),
); );
}
} // end get_fields;
/** /**
* Returns the field/element actual field array to be used on the checkout form. * 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. * Logged in user, bail.
*/ */
if (is_user_logged_in()) { if (is_user_logged_in()) {
return array(); return array();
}
} // end if;
$checkout_fields = array(); $checkout_fields = array();
@ -231,7 +218,6 @@ class Signup_Field_Password extends Base_Signup_Field {
); );
if ($attributes['password_confirm_field']) { if ($attributes['password_confirm_field']) {
$checkout_fields['password_conf'] = array( $checkout_fields['password_conf'] = array(
'type' => 'password', 'type' => 'password',
'id' => 'password_conf', 'id' => 'password_conf',
@ -249,11 +235,8 @@ class Signup_Field_Password extends Base_Signup_Field {
'style' => $this->calculate_style_attr(), 'style' => $this->calculate_style_attr(),
), ),
); );
}
} // end if;
return $checkout_fields; return $checkout_fields;
}
} // end to_fields_array; }
} // end class Signup_Field_Password;

View File

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

View File

@ -9,8 +9,8 @@
namespace WP_Ultimo\Checkout\Signup_Fields; namespace WP_Ultimo\Checkout\Signup_Fields;
use \WP_Ultimo\Checkout\Signup_Fields\Base_Signup_Field; use WP_Ultimo\Checkout\Signup_Fields\Base_Signup_Field;
use \WP_Ultimo\Managers\Field_Templates_Manager; use WP_Ultimo\Managers\Field_Templates_Manager;
// Exit if accessed directly // Exit if accessed directly
defined('ABSPATH') || exit; defined('ABSPATH') || exit;
@ -32,8 +32,7 @@ class Signup_Field_Period_Selection extends Base_Signup_Field {
public function get_type(): string { public function get_type(): string {
return 'period_selection'; return 'period_selection';
}
} // end get_type;
/** /**
* Returns if this field should be present on the checkout flow or not. * 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 { public function is_required(): bool {
return false; return false;
}
} // end is_required;
/** /**
* Requires the title of the field/element type. * 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() { public function get_title() {
return __('Period Select', 'wp-ultimo'); return __('Period Select', 'wp-ultimo');
}
} // end get_title;
/** /**
* Returns the description of the field/element. * Returns the description of the field/element.
@ -70,8 +67,7 @@ class Signup_Field_Period_Selection extends Base_Signup_Field {
public function get_description() { public function get_description() {
return __('Adds a period selector, that allows customers to switch between different billing periods.', 'wp-ultimo'); 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. * Returns the tooltip of the field/element.
@ -84,8 +80,7 @@ class Signup_Field_Period_Selection extends Base_Signup_Field {
public function get_tooltip() { public function get_tooltip() {
return __('Adds a period selector, that allows customers to switch between different billing periods.', 'wp-ultimo'); 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. * 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 { public function get_icon(): string {
return 'dashicons-wu dashicons-wu-toggle-right'; return 'dashicons-wu dashicons-wu-toggle-right';
}
} // end get_icon;
/** /**
* Returns the default values for the field-elements. * Returns the default values for the field-elements.
@ -113,8 +107,7 @@ class Signup_Field_Period_Selection extends Base_Signup_Field {
return array( return array(
'period_selection_template' => 'clean', 'period_selection_template' => 'clean',
); );
}
} // end defaults;
/** /**
* List of keys of the default fields we want to display on the builder. * 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( return array(
// 'name', // 'name',
); );
}
} // end default_fields;
/** /**
* If you want to force a particular attribute to a value, declare it here. * 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'), 'name' => __('Plan Duration Switch', 'wp-ultimo'),
'required' => true, 'required' => true,
); );
}
} // end force_attributes;
/** /**
* Returns the list of available pricing table templates. * 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'); $available_templates = Field_Templates_Manager::get_instance()->get_templates_as_options('period_selection');
return $available_templates; return $available_templates;
}
} // end get_template_options;
/** /**
* Returns the list of additional fields specific to this type. * 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; return $editor_fields;
}
} // end get_fields;
/** /**
* Returns the field/element actual field array to be used on the checkout form. * 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) { public function to_fields_array($attributes) {
if (wu_get_isset($attributes, 'period_selection_template') === 'legacy') { 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_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_script('wu-legacy-signup');
wp_enqueue_style('legacy-shortcodes', wu_get_asset('legacy-shortcodes.css', 'css'), array('dashicons'), wu_get_version()); 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']); $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; 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; namespace WP_Ultimo\Checkout\Signup_Fields;
use \WP_Ultimo\Checkout\Signup_Fields\Base_Signup_Field; use WP_Ultimo\Checkout\Signup_Fields\Base_Signup_Field;
use \WP_Ultimo\Managers\Field_Templates_Manager; use WP_Ultimo\Managers\Field_Templates_Manager;
// Exit if accessed directly // Exit if accessed directly
defined('ABSPATH') || exit; defined('ABSPATH') || exit;
@ -32,8 +32,7 @@ class Signup_Field_Pricing_Table extends Base_Signup_Field {
public function get_type(): string { public function get_type(): string {
return 'pricing_table'; return 'pricing_table';
}
} // end get_type;
/** /**
* Returns if this field should be present on the checkout flow or not. * 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 { public function is_required(): bool {
return false; return false;
}
} // end is_required;
/** /**
* Requires the title of the field/element type. * 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() { public function get_title() {
return __('Pricing Table', 'wp-ultimo'); return __('Pricing Table', 'wp-ultimo');
}
} // end get_title;
/** /**
* Returns the description of the field/element. * Returns the description of the field/element.
@ -70,8 +67,7 @@ class Signup_Field_Pricing_Table extends Base_Signup_Field {
public function get_description() { public function get_description() {
return __('Adds a pricing table section that customers can use to choose a plan to subscribe to.', 'wp-ultimo'); 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. * Returns the tooltip of the field/element.
@ -84,8 +80,7 @@ class Signup_Field_Pricing_Table extends Base_Signup_Field {
public function get_tooltip() { public function get_tooltip() {
return __('Adds a pricing table section that customers can use to choose a plan to subscribe to.', 'wp-ultimo'); 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. * 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 { public function get_icon(): string {
return 'dashicons-wu dashicons-wu-columns'; return 'dashicons-wu dashicons-wu-columns';
}
} // end get_icon;
/** /**
* Returns the default values for the field-elements. * 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, 'force_different_durations' => false,
'hide_pricing_table_when_pre_selected' => false, 'hide_pricing_table_when_pre_selected' => false,
); );
}
} // end defaults;
/** /**
* List of keys of the default fields we want to display on the builder. * 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( return array(
// 'name', // 'name',
); );
}
} // end default_fields;
/** /**
* If you want to force a particular attribute to a value, declare it here. * 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'), 'name' => __('Plan Selection', 'wp-ultimo'),
'required' => true, 'required' => true,
); );
}
} // end force_attributes;
/** /**
* Returns the list of available pricing table templates. * 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'); $available_templates = Field_Templates_Manager::get_instance()->get_templates_as_options('pricing_table');
return $available_templates; return $available_templates;
}
} // end get_pricing_table_templates;
/** /**
* Returns the list of additional fields specific to this type. * 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; return $editor_fields;
}
} // end get_fields;
/** /**
* Returns the field/element actual field array to be used on the checkout form. * 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) { public function to_fields_array($attributes) {
if (wu_get_isset($attributes, 'pricing_table_template') === 'legacy') { 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_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()); 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']); $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. * Hide when pre-selected.
*/ */
if (wu_should_hide_form_field($attributes)) { if (wu_should_hide_form_field($attributes)) {
return array(); return array();
}
} // end if;
$template_attributes = array( $template_attributes = array(
'products' => $products, 'products' => $products,
@ -306,7 +291,5 @@ class Signup_Field_Pricing_Table extends Base_Signup_Field {
); );
return $checkout_fields; 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; 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 // Exit if accessed directly
defined('ABSPATH') || exit; defined('ABSPATH') || exit;
@ -31,8 +31,7 @@ class Signup_Field_Products extends Base_Signup_Field {
public function get_type(): string { public function get_type(): string {
return 'products'; return 'products';
}
} // end get_type;
/** /**
* Returns if this field should be present on the checkout flow or not. * 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 { public function is_required(): bool {
return false; return false;
}
} // end is_required;
/** /**
* Requires the title of the field/element type. * Requires the title of the field/element type.
@ -55,8 +53,7 @@ class Signup_Field_Products extends Base_Signup_Field {
public function get_title() { public function get_title() {
return __('Product', 'wp-ultimo'); return __('Product', 'wp-ultimo');
}
} // end get_title;
/** /**
* Returns the description of the field/element. * Returns the description of the field/element.
@ -69,8 +66,7 @@ class Signup_Field_Products extends Base_Signup_Field {
public function get_description() { 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'); 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. * Returns the tooltip of the field/element.
@ -83,8 +79,7 @@ class Signup_Field_Products extends Base_Signup_Field {
public function get_tooltip() { 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'); 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. * 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 { public function get_icon(): string {
return 'dashicons-wu dashicons-wu-package'; return 'dashicons-wu dashicons-wu-package';
}
} // end get_icon;
/** /**
* Returns the default values for the field-elements. * Returns the default values for the field-elements.
@ -110,10 +104,9 @@ class Signup_Field_Products extends Base_Signup_Field {
public function defaults() { public function defaults() {
return array( return array(
'' '',
); );
}
} // end defaults;
/** /**
* List of keys of the default fields we want to display on the builder. * 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() { public function default_fields() {
return array(); return array();
}
} // end default_fields;
/** /**
* If you want to force a particular attribute to a value, declare it here. * 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'), 'name' => __('Pre-selected Products', 'wp-ultimo'),
'id' => 'products', 'id' => 'products',
); );
}
} // end force_attributes;
/** /**
* Returns the list of additional fields specific to this type. * 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. * 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']); $products = explode(',', (string) $attributes['products']);
foreach ($products as $product_id) { foreach ($products as $product_id) {
$checkout_fields[ "products[{$product_id}]" ] = array( $checkout_fields[ "products[{$product_id}]" ] = array(
'type' => 'hidden', 'type' => 'hidden',
'value' => $product_id, 'value' => $product_id,
@ -192,14 +181,12 @@ class Signup_Field_Products extends Base_Signup_Field {
'v-bind:name' => "'products[]'", 'v-bind:name' => "'products[]'",
), ),
); );
}
} // end foreach;
$this->insert_products_in_form($products); $this->insert_products_in_form($products);
return $checkout_fields; return $checkout_fields;
}
} // end to_fields_array;
/** /**
* Inserts the products in the form. * Inserts the products in the form.
@ -212,10 +199,8 @@ class Signup_Field_Products extends Base_Signup_Field {
static $added = false; static $added = false;
if ($added) { if ($added) {
return; return;
}
} // end if;
$added = true; $added = true;
@ -224,24 +209,23 @@ class Signup_Field_Products extends Base_Signup_Field {
data.products.push(...%s); data.products.push(...%s);
data.products = data.products.map((value) => parseInt(value) || value); data.products = data.products.map((value) => parseInt(value) || value);
data.products = [...new Set(data.products)]; data.products = [...new Set(data.products)];
} // end if; }
return data; return data;
});"; });";
if (did_action('wu-checkout')) { if (did_action('wu-checkout')) {
wp_add_inline_script('wu-checkout', sprintf($script, json_encode($products)), 'before'); wp_add_inline_script('wu-checkout', sprintf($script, json_encode($products)), 'before');
return; return;
}
} // end if; add_action(
'wp_enqueue_scripts',
add_action('wp_enqueue_scripts', function() use ($script, $products) { function () use ($script, $products) {
wp_add_inline_script('wu-checkout', sprintf($script, json_encode($products)), 'before'); wp_add_inline_script('wu-checkout', sprintf($script, json_encode($products)), 'before');
},
}, 11); 11
);
} // end insert_products_in_form; }
}
} // end class Signup_Field_Products;

View File

@ -9,7 +9,7 @@
namespace WP_Ultimo\Checkout\Signup_Fields; 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 // Exit if accessed directly
defined('ABSPATH') || exit; defined('ABSPATH') || exit;
@ -32,8 +32,7 @@ class Signup_Field_Select extends Base_Signup_Field {
public function get_type() { public function get_type() {
return 'select'; return 'select';
}
} // end get_type;
/** /**
* Returns if this field should be present on the checkout flow or not. * 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() { public function is_required() {
return false; return false;
}
} // end is_required;
/** /**
* Requires the title of the field/element type. * Requires the title of the field/element type.
@ -58,8 +56,7 @@ class Signup_Field_Select extends Base_Signup_Field {
public function get_title() { public function get_title() {
return __('Select', 'wp-ultimo'); return __('Select', 'wp-ultimo');
}
} // end get_title;
/** /**
* Returns the description of the field/element. * Returns the description of the field/element.
@ -72,8 +69,7 @@ class Signup_Field_Select extends Base_Signup_Field {
public function get_description() { public function get_description() {
return __('Adds a select field.', 'wp-ultimo'); return __('Adds a select field.', 'wp-ultimo');
}
} // end get_description;
/** /**
* Returns the tooltip of the field/element. * Returns the tooltip of the field/element.
@ -86,8 +82,7 @@ class Signup_Field_Select extends Base_Signup_Field {
public function get_tooltip() { public function get_tooltip() {
return __('Adds a select field.', 'wp-ultimo'); return __('Adds a select field.', 'wp-ultimo');
}
} // end get_tooltip;
/** /**
* Returns the icon to be used on the selector. * 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() { public function get_icon() {
return 'dashicons-wu-list1'; return 'dashicons-wu-list1';
}
} // end get_icon;
/** /**
* Returns the default values for the field-elements. * Returns the default values for the field-elements.
@ -115,10 +109,9 @@ class Signup_Field_Select extends Base_Signup_Field {
public function defaults() { public function defaults() {
return array( return array(
'' '',
); );
}
} // end defaults;
/** /**
* List of keys of the default fields we want to display on the builder. * 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', 'required',
'save_as', 'save_as',
); );
}
} // end default_fields;
/** /**
* If you want to force a particular attribute to a value, declare it here. * 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() { public function force_attributes() {
return array(); return array();
}
} // end force_attributes;
/** /**
* Returns the list of additional fields specific to this type. * 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; return $editor_fields;
}
} // end get_fields;
/** /**
* Returns the field/element actual field array to be used on the checkout form. * 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(); $options = array();
foreach ($attributes['options'] as $_option) { foreach ($attributes['options'] as $_option) {
$options[ $_option['key'] ] = $_option['label']; $options[ $_option['key'] ] = $_option['label'];
}
} // end foreach;
return array( return array(
$attributes['id'] => array( $attributes['id'] => array(
@ -272,7 +260,5 @@ class Signup_Field_Select extends Base_Signup_Field {
'value' => $this->get_value(), '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; 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 // Exit if accessed directly
defined('ABSPATH') || exit; defined('ABSPATH') || exit;
@ -31,8 +31,7 @@ class Signup_Field_Shortcode extends Base_Signup_Field {
public function get_type(): string { public function get_type(): string {
return 'shortcode'; return 'shortcode';
}
} // end get_type;
/** /**
* Returns if this field should be present on the checkout flow or not. * 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 { public function is_required(): bool {
return false; return false;
}
} // end is_required;
/** /**
* Requires the title of the field/element type. * Requires the title of the field/element type.
@ -55,8 +53,7 @@ class Signup_Field_Shortcode extends Base_Signup_Field {
public function get_title() { public function get_title() {
return __('Shortcode', 'wp-ultimo'); return __('Shortcode', 'wp-ultimo');
}
} // end get_title;
/** /**
* Returns the description of the field/element. * Returns the description of the field/element.
@ -69,8 +66,7 @@ class Signup_Field_Shortcode extends Base_Signup_Field {
public function get_description() { 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'); 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. * Returns the tooltip of the field/element.
@ -83,8 +79,7 @@ class Signup_Field_Shortcode extends Base_Signup_Field {
public function get_tooltip() { 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'); 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. * 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 { public function get_icon(): string {
return 'dashicons-wu-terminal'; return 'dashicons-wu-terminal';
}
} // end get_icon;
/** /**
* Returns the default values for the field-elements. * Returns the default values for the field-elements.
@ -110,10 +104,9 @@ class Signup_Field_Shortcode extends Base_Signup_Field {
public function defaults() { public function defaults() {
return array( return array(
'' '',
); );
}
} // end defaults;
/** /**
* List of keys of the default fields we want to display on the builder. * 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', // 'id',
// 'name', // 'name',
); );
}
} // end default_fields;
/** /**
* If you want to force a particular attribute to a value, declare it here. * 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( return array(
'name' => __('Shortcode', 'wp-ultimo'), 'name' => __('Shortcode', 'wp-ultimo'),
); );
}
} // end force_attributes;
/** /**
* Returns the list of additional fields specific to this type. * 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'), '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. * 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; 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 // Exit if accessed directly
defined('ABSPATH') || exit; defined('ABSPATH') || exit;
@ -32,8 +32,7 @@ class Signup_Field_Site_Title extends Base_Signup_Field {
public function get_type() { public function get_type() {
return 'site_title'; return 'site_title';
}
} // end get_type;
/** /**
* Returns if this field should be present on the checkout flow or not. * 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() { public function is_required() {
return false; return false;
}
} // end is_required;
/** /**
* Defines if this field/element is related to site creation or not. * 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() { public function is_site_field() {
return true; return true;
}
} // end is_site_field;
/** /**
* Requires the title of the field/element type. * 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() { public function get_title() {
return __('Site Title', 'wp-ultimo'); return __('Site Title', 'wp-ultimo');
}
} // end get_title;
/** /**
* Returns the description of the field/element. * Returns the description of the field/element.
@ -84,8 +80,7 @@ class Signup_Field_Site_Title extends Base_Signup_Field {
public function get_description() { 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'); 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. * Returns the tooltip of the field/element.
@ -98,8 +93,7 @@ class Signup_Field_Site_Title extends Base_Signup_Field {
public function get_tooltip() { 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'); 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. * 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() { public function get_icon() {
return 'dashicons-wu-type'; return 'dashicons-wu-type';
}
} // end get_icon;
/** /**
* Returns the default values for the field-elements. * Returns the default values for the field-elements.
@ -129,8 +122,7 @@ class Signup_Field_Site_Title extends Base_Signup_Field {
return array( return array(
'auto_generate_site_title' => false, 'auto_generate_site_title' => false,
); );
}
} // end defaults;
/** /**
* List of keys of the default fields we want to display on the builder. * 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', 'placeholder',
'tooltip', 'tooltip',
); );
}
} // end default_fields;
/** /**
* If you want to force a particular attribute to a value, declare it here. * 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', 'id' => 'site_title',
'required' => true, 'required' => true,
); );
}
} // end force_attributes;
/** /**
* Returns the list of additional fields specific to this type. * 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. * 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 we should auto-generate, add as hidden.
*/ */
if (isset($attributes['auto_generate_site_title']) && $attributes['auto_generate_site_title']) { if (isset($attributes['auto_generate_site_title']) && $attributes['auto_generate_site_title']) {
return array( return array(
'auto_generate_site_title' => array( 'auto_generate_site_title' => array(
'type' => 'hidden', 'type' => 'hidden',
@ -211,11 +199,10 @@ class Signup_Field_Site_Title extends Base_Signup_Field {
'id' => 'site_title', 'id' => 'site_title',
'html_attr' => array( 'html_attr' => array(
'v-bind:value' => 'username', 'v-bind:value' => 'username',
) ),
), ),
); );
}
} // end if;
return array( return array(
'site_title' => 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; 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 // Exit if accessed directly
defined('ABSPATH') || exit; defined('ABSPATH') || exit;
@ -31,8 +31,7 @@ class Signup_Field_Site_Url extends Base_Signup_Field {
public function get_type(): string { public function get_type(): string {
return 'site_url'; return 'site_url';
}
} // end get_type;
/** /**
* Returns if this field should be present on the checkout flow or not. * 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 { public function is_required(): bool {
return false; return false;
}
} // end is_required;
/** /**
* Defines if this field/element is related to site creation or not. * 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 { public function is_site_field(): bool {
return true; return true;
}
} // end is_site_field;
/** /**
* Requires the title of the field/element type. * 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() { public function get_title() {
return __('Site URL', 'wp-ultimo'); return __('Site URL', 'wp-ultimo');
}
} // end get_title;
/** /**
* Returns the description of the field/element. * Returns the description of the field/element.
@ -79,8 +75,7 @@ class Signup_Field_Site_Url extends Base_Signup_Field {
public function get_description() { public function get_description() {
return __('Adds a Site URL field. This is used to set the URL of the site being created.', 'wp-ultimo'); 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. * Returns the tooltip of the field/element.
@ -93,8 +88,7 @@ class Signup_Field_Site_Url extends Base_Signup_Field {
public function get_tooltip() { public function get_tooltip() {
return __('Adds a Site URL field. This is used to set the URL of the site being created.', 'wp-ultimo'); 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. * 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 { public function get_icon(): string {
return 'dashicons-wu-globe1'; return 'dashicons-wu-globe1';
}
} // end get_icon;
/** /**
* Returns the default values for the field-elements. * 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, 'display_field_attachments' => true,
'available_domains' => $current_site->domain . PHP_EOL, 'available_domains' => $current_site->domain . PHP_EOL,
); );
}
} // end defaults;
/** /**
* List of keys of the default fields we want to display on the builder. * 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', 'placeholder',
'tooltip', 'tooltip',
); );
}
} // end default_fields;
/** /**
* If you want to force a particular attribute to a value, declare it here. * 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', 'id' => 'site_url',
'required' => true, 'required' => true,
); );
}
} // end force_attributes;
/** /**
* Returns the list of additional fields specific to this type. * 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. * 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); 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. * 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 we should auto-generate, add as hidden.
*/ */
if ($attributes['auto_generate_site_url']) { if ($attributes['auto_generate_site_url']) {
return array( return array(
'auto_generate_site_url' => array( 'auto_generate_site_url' => array(
'type' => 'hidden', 'type' => 'hidden',
@ -292,8 +279,7 @@ class Signup_Field_Site_Url extends Base_Signup_Field {
'value' => uniqid(), 'value' => uniqid(),
), ),
); );
}
} // end if;
$checkout_fields = array(); $checkout_fields = array();
@ -316,7 +302,6 @@ class Signup_Field_Site_Url extends Base_Signup_Field {
); );
if ($attributes['display_field_attachments']) { if ($attributes['display_field_attachments']) {
$checkout_fields['site_url']['classes'] .= ' xs:wu-rounded-none'; $checkout_fields['site_url']['classes'] .= ' xs:wu-rounded-none';
$checkout_fields['site_url']['prefix'] = ' '; $checkout_fields['site_url']['prefix'] = ' ';
@ -337,11 +322,9 @@ class Signup_Field_Site_Url extends Base_Signup_Field {
'v-cloak' => 1, 'v-cloak' => 1,
'v-show' => 'is_subdomain', 'v-show' => 'is_subdomain',
); );
}
} // end if;
if ($attributes['available_domains'] && $attributes['enable_domain_selection']) { if ($attributes['available_domains'] && $attributes['enable_domain_selection']) {
$options = $this->get_domain_options($attributes['available_domains']); $options = $this->get_domain_options($attributes['available_domains']);
$checkout_fields['site_domain'] = array( $checkout_fields['site_domain'] = array(
@ -361,11 +344,9 @@ class Signup_Field_Site_Url extends Base_Signup_Field {
'style' => $this->calculate_style_attr(), 'style' => $this->calculate_style_attr(),
), ),
); );
}
} // end if;
if ($attributes['display_url_preview']) { if ($attributes['display_url_preview']) {
$content = wu_get_template_contents('legacy/signup/steps/step-domain-url-preview'); $content = wu_get_template_contents('legacy/signup/steps/step-domain-url-preview');
$checkout_fields['site_url_preview'] = array( $checkout_fields['site_url_preview'] = array(
@ -377,12 +358,10 @@ class Signup_Field_Site_Url extends Base_Signup_Field {
'style' => $this->calculate_style_attr(), 'style' => $this->calculate_style_attr(),
), ),
); );
}
} // end if;
return $checkout_fields; return $checkout_fields;
}
} // end to_fields_array;
/** /**
* Get the domain options. * 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); $domains = array_map(fn($item) => trim((string) $item), $domains);
return array_combine($domains, $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; namespace WP_Ultimo\Checkout\Signup_Fields;
use \WP_Ultimo\Checkout\Signup_Fields\Base_Signup_Field; use WP_Ultimo\Checkout\Signup_Fields\Base_Signup_Field;
use \WP_Ultimo\Managers\Field_Templates_Manager; use WP_Ultimo\Managers\Field_Templates_Manager;
// Exit if accessed directly // Exit if accessed directly
defined('ABSPATH') || exit; defined('ABSPATH') || exit;
@ -32,8 +32,7 @@ class Signup_Field_Steps extends Base_Signup_Field {
public function get_type(): string { public function get_type(): string {
return 'steps'; return 'steps';
}
} // end get_type;
/** /**
* Returns if this field should be present on the checkout flow or not. * 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 { public function is_required(): bool {
return false; return false;
}
} // end is_required;
/** /**
* Requires the title of the field/element type. * Requires the title of the field/element type.
@ -56,8 +54,7 @@ class Signup_Field_Steps extends Base_Signup_Field {
public function get_title() { public function get_title() {
return __('Steps', 'wp-ultimo'); return __('Steps', 'wp-ultimo');
}
} // end get_title;
/** /**
* Returns the description of the field/element. * Returns the description of the field/element.
@ -70,8 +67,7 @@ class Signup_Field_Steps extends Base_Signup_Field {
public function get_description() { public function get_description() {
return __('Adds a list of the steps.', 'wp-ultimo'); return __('Adds a list of the steps.', 'wp-ultimo');
}
} // end get_description;
/** /**
* Returns the tooltip of the field/element. * Returns the tooltip of the field/element.
@ -84,8 +80,7 @@ class Signup_Field_Steps extends Base_Signup_Field {
public function get_tooltip() { public function get_tooltip() {
return __('Adds a list of the steps.', 'wp-ultimo'); return __('Adds a list of the steps.', 'wp-ultimo');
}
} // end get_tooltip;
/** /**
* Returns the icon to be used on the selector. * 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 { public function get_icon(): string {
return 'dashicons-wu-filter_1'; return 'dashicons-wu-filter_1';
}
} // end get_icon;
/** /**
* Returns the default values for the field-elements. * Returns the default values for the field-elements.
@ -113,8 +107,7 @@ class Signup_Field_Steps extends Base_Signup_Field {
return array( return array(
'steps_template' => 'clean', 'steps_template' => 'clean',
); );
}
} // end defaults;
/** /**
* List of keys of the default fields we want to display on the builder. * 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() { public function default_fields() {
return array(); return array();
}
} // end default_fields;
/** /**
* If you want to force a particular attribute to a value, declare it here. * 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( return array(
'id' => 'steps', 'id' => 'steps',
); );
}
} // end force_attributes;
/** /**
* Returns the list of available pricing table templates. * 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'); $available_templates = Field_Templates_Manager::get_instance()->get_templates_as_options('steps');
return $available_templates; return $available_templates;
}
} // end get_templates;
/** /**
* Returns the list of additional fields specific to this type. * 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; return $editor_fields;
}
} // end get_fields;
/** /**
* Returns the field/element actual field array to be used on the checkout form. * 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) { public function to_fields_array($attributes) {
if (wu_get_isset($attributes, 'steps_template') === 'legacy') { 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_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()); 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['steps'] = \WP_Ultimo\Checkout\Checkout::get_instance()->steps;
$attributes['current_step'] = \WP_Ultimo\Checkout\Checkout::get_instance()->step_name; $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'], '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; 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 // Exit if accessed directly
defined('ABSPATH') || exit; defined('ABSPATH') || exit;
@ -32,8 +32,7 @@ class Signup_Field_Submit_Button extends Base_Signup_Field {
public function get_type() { public function get_type() {
return 'submit_button'; return 'submit_button';
}
} // end get_type;
/** /**
* Returns if this field should be present on the checkout flow or not. * 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() { public function is_required() {
return true; return true;
}
} // end is_required;
/** /**
* Requires the title of the field/element type. * 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() { public function get_title() {
return __('Submit Button', 'wp-ultimo'); return __('Submit Button', 'wp-ultimo');
}
} // end get_title;
/** /**
* Returns the description of the field/element. * Returns the description of the field/element.
@ -72,8 +69,7 @@ class Signup_Field_Submit_Button extends Base_Signup_Field {
public function get_description() { 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'); 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. * Returns the tooltip of the field/element.
@ -86,8 +82,7 @@ class Signup_Field_Submit_Button extends Base_Signup_Field {
public function get_tooltip() { 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'); 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. * 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() { public function get_icon() {
return 'dashicons-wu-zap'; return 'dashicons-wu-zap';
}
} // end get_icon;
/** /**
* Returns the default values for the field-elements. * 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, 'enable_go_back_button' => false,
'back_button_label' => __('&larr; Go Back', 'wp-ultimo'), 'back_button_label' => __('&larr; Go Back', 'wp-ultimo'),
); );
}
} // end defaults;
/** /**
* List of keys of the default fields we want to display on the builder. * 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', 'id',
'name', 'name',
); );
}
} // end default_fields;
/** /**
* If you want to force a particular attribute to a value, declare it here. * 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() { public function force_attributes() {
return array(); return array();
}
} // end force_attributes;
/** /**
* Returns the list of additional fields specific to this type. * 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. * 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'; $button_wrapper_classes = 'wu_submit_button';
if ($attributes['enable_go_back_button']) { if ($attributes['enable_go_back_button']) {
$steps = \WP_Ultimo\Checkout\Checkout::get_instance()->steps; $steps = \WP_Ultimo\Checkout\Checkout::get_instance()->steps;
$is_first_step = isset($steps[0]) && $steps[0]['id'] === $attributes['step']; $is_first_step = isset($steps[0]) && $steps[0]['id'] === $attributes['step'];
if ( ! $is_first_step) { if ( ! $is_first_step) {
$fields[ $attributes['id'] . '_group' ]['fields'][ $attributes['id'] . '_go_back' ] = array( $fields[ $attributes['id'] . '_group' ]['fields'][ $attributes['id'] . '_go_back' ] = array(
'type' => 'html', 'type' => 'html',
'wrapper_classes' => 'md:wu-w-1/2 wu-box-border wu-float-left wu--mt-4', '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'; $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( $fields[ $attributes['id'] . '_group' ]['fields'][ $attributes['id'] ] = array(
'type' => 'submit', 'type' => 'submit',
@ -245,15 +231,11 @@ class Signup_Field_Submit_Button extends Base_Signup_Field {
); );
if ($attributes['enable_go_back_button']) { if ($attributes['enable_go_back_button']) {
$fields[ $attributes['id'] . '_clear' ] = array( $fields[ $attributes['id'] . '_clear' ] = array(
'type' => 'clear', 'type' => 'clear',
); );
}
} // end if;
return $fields; return $fields;
}
} // end to_fields_array; }
} // end class Signup_Field_Submit_Button;

View File

@ -9,9 +9,9 @@
namespace WP_Ultimo\Checkout\Signup_Fields; namespace WP_Ultimo\Checkout\Signup_Fields;
use \WP_Ultimo\Checkout\Signup_Fields\Base_Signup_Field; use WP_Ultimo\Checkout\Signup_Fields\Base_Signup_Field;
use \WP_Ultimo\Managers\Field_Templates_Manager; use WP_Ultimo\Managers\Field_Templates_Manager;
use \WP_Ultimo\Models\Site; use WP_Ultimo\Models\Site;
// Exit if accessed directly // Exit if accessed directly
defined('ABSPATH') || exit; defined('ABSPATH') || exit;
@ -33,8 +33,7 @@ class Signup_Field_Template_Selection extends Base_Signup_Field {
public function get_type(): string { public function get_type(): string {
return 'template_selection'; return 'template_selection';
}
} // end get_type;
/** /**
* Returns if this field should be present on the checkout flow or not. * 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 { public function is_required(): bool {
return false; return false;
}
} // end is_required;
/** /**
* Requires the title of the field/element type. * 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() { public function get_title() {
return __('Templates', 'wp-ultimo'); return __('Templates', 'wp-ultimo');
}
} // end get_title;
/** /**
* Returns the description of the field/element. * Returns the description of the field/element.
@ -71,8 +68,7 @@ class Signup_Field_Template_Selection extends Base_Signup_Field {
public function get_description() { 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'); 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. * Returns the tooltip of the field/element.
@ -85,8 +81,7 @@ class Signup_Field_Template_Selection extends Base_Signup_Field {
public function get_tooltip() { 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'); 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. * 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 { public function get_icon(): string {
return 'dashicons-wu-layout'; return 'dashicons-wu-layout';
}
} // end get_icon;
/** /**
* Returns the default values for the field-elements. * Returns the default values for the field-elements.
@ -118,8 +112,7 @@ class Signup_Field_Template_Selection extends Base_Signup_Field {
'cols' => 3, 'cols' => 3,
'hide_template_selection_when_pre_selected' => false, 'hide_template_selection_when_pre_selected' => false,
); );
}
} // end defaults;
/** /**
* List of keys of the default fields we want to display on the builder. * 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( return array(
// 'name', // 'name',
); );
}
} // end default_fields;
/** /**
* If you want to force a particular attribute to a value, declare it here. * 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'), 'name' => __('Template Selection', 'wp-ultimo'),
'required' => true, 'required' => true,
); );
}
} // end force_attributes;
/** /**
* Returns the list of available pricing table templates. * 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'); $available_templates = Field_Templates_Manager::get_instance()->get_templates_as_options('template_selection');
return $available_templates; return $available_templates;
}
} // end get_template_selection_templates;
/** /**
* Returns the list of additional fields specific to this type. * 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-label-field' => 'title',
'data-search-field' => 'title', 'data-search-field' => 'title',
'data-max-items' => 999, 'data-max-items' => 999,
'data-include' => implode(',', wu_get_site_templates(array( 'data-include' => implode(
',',
wu_get_site_templates(
array(
'fields' => 'blog_id', 'fields' => 'blog_id',
))), )
)
),
), ),
'wrapper_html_attr' => array( 'wrapper_html_attr' => array(
'v-show' => 'template_selection_type === \'name\'', 'v-show' => 'template_selection_type === \'name\'',
@ -272,8 +267,7 @@ class Signup_Field_Template_Selection extends Base_Signup_Field {
// ); // );
return $editor_fields; return $editor_fields;
}
} // end get_fields;
/** /**
* Treat the attributes array to avoid reaching the input var limits. * 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')); $attributes['sites'] = array_values(array_column($array_sites, 'blog_id'));
return $attributes; return $attributes;
}
} // end reduce_attributes;
/** /**
* Returns the field/element actual field array to be used on the checkout form. * 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. * Hide when pre-selected.
*/ */
if (wu_should_hide_form_field($attributes)) { if (wu_should_hide_form_field($attributes)) {
return $checkout_fields; return $checkout_fields;
}
} // end if;
if (wu_get_isset($attributes, 'template_selection_template') === 'legacy') { 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_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_script('wu-legacy-signup');
wp_enqueue_style('legacy-shortcodes', wu_get_asset('legacy-shortcodes.css', 'css'), array('dashicons'), wu_get_version()); 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); $site_list = $this->site_list($attributes);
$customer_sites = array(); $customer_sites = array();
if (wu_get_setting('allow_own_site_as_template')) { if (wu_get_setting('allow_own_site_as_template')) {
$customer = wu_get_current_customer(); $customer = wu_get_current_customer();
if ($customer) { if ($customer) {
$customer_sites = $customer->get_sites(array('fields' => 'ids')); $customer_sites = $customer->get_sites(array('fields' => 'ids'));
$site_list = array_merge( $site_list = array_merge(
$customer_sites, $customer_sites,
$site_list $site_list
); );
}
} // end if; }
} // end if;
$sites = array_map('wu_get_site', $site_list); $sites = array_map('wu_get_site', $site_list);
@ -378,8 +363,7 @@ class Signup_Field_Template_Selection extends Base_Signup_Field {
); );
return $checkout_fields; return $checkout_fields;
}
} // end to_fields_array;
/** /**
* Return site list according to selection type used. * 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'); $selection_type = wu_get_isset($attributes, 'template_selection_type', 'name');
if ($selection_type === 'name') { if ($selection_type === 'name') {
return explode(',', $attributes['template_selection_sites']); return explode(',', $attributes['template_selection_sites']);
}
} // end if;
if ($selection_type === 'all') { if ($selection_type === 'all') {
return wu_get_site_templates(array('fields' => 'blog_id')); return wu_get_site_templates(array('fields' => 'blog_id'));
}
} // end if;
if ($selection_type === 'categories') { if ($selection_type === 'categories') {
return array_column( return array_column(
\WP_Ultimo\Models\Site::get_all_by_categories( \WP_Ultimo\Models\Site::get_all_by_categories(
$attributes['template_selection_categories'], $attributes['template_selection_categories'],
@ -414,12 +393,8 @@ class Signup_Field_Template_Selection extends Base_Signup_Field {
), ),
'blog_id' 'blog_id'
); );
}
} // end if;
return explode(',', $attributes['template_selection_sites']); 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; 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 // Exit if accessed directly
defined('ABSPATH') || exit; defined('ABSPATH') || exit;
@ -32,8 +32,7 @@ class Signup_Field_Terms_Of_Use extends Base_Signup_Field {
public function get_type() { public function get_type() {
return 'terms_of_use'; return 'terms_of_use';
}
} // end get_type;
/** /**
* Returns if this field should be present on the checkout flow or not. * 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() { public function is_required() {
return false; return false;
}
} // end is_required;
/** /**
* Is this a user-related field? * 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() { public function is_user_field() {
return false; return false;
}
} // end is_user_field;
/** /**
* Requires the title of the field/element type. * 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() { public function get_title() {
return __('Terms of Use', 'wp-ultimo'); return __('Terms of Use', 'wp-ultimo');
}
} // end get_title;
/** /**
* Returns the description of the field/element. * 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() { public function get_description() {
return __('Adds a terms and conditions checkbox that must be marked before the account/site can be created.', 'wp-ultimo'); 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. * 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() { public function get_tooltip() {
return __('Adds a terms and conditions checkbox that must be marked before the account/site can be created.', 'wp-ultimo'); 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. * 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() { public function get_icon() {
return 'dashicons-wu-file-text'; return 'dashicons-wu-file-text';
}
} // end get_icon;
/** /**
* Returns the default values for the field-elements. * Returns the default values for the field-elements.
@ -132,8 +125,7 @@ class Signup_Field_Terms_Of_Use extends Base_Signup_Field {
return array( return array(
'tou_name' => __('I agree with the terms of use.', 'wp-ultimo'), '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. * 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() { public function default_fields() {
return array(); return array();
}
} // end default_fields;
/** /**
* If you want to force a particular attribute to a value, declare it here. * 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', 'id' => 'terms_of_use',
'name' => __('Terms of Use', 'wp-ultimo'), 'name' => __('Terms of Use', 'wp-ultimo'),
); );
}
} // end force_attributes;
/** /**
* Returns the list of additional fields specific to this type. * 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'), '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. * 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; 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; 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 // Exit if accessed directly
defined('ABSPATH') || exit; defined('ABSPATH') || exit;
@ -32,8 +32,7 @@ class Signup_Field_Text extends Base_Signup_Field {
public function get_type() { public function get_type() {
return 'text'; return 'text';
}
} // end get_type;
/** /**
* Returns if this field should be present on the checkout flow or not. * 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() { public function is_required() {
return false; return false;
}
} // end is_required;
/** /**
* Requires the title of the field/element type. * Requires the title of the field/element type.
@ -58,8 +56,7 @@ class Signup_Field_Text extends Base_Signup_Field {
public function get_title() { public function get_title() {
return __('Text', 'wp-ultimo'); return __('Text', 'wp-ultimo');
}
} // end get_title;
/** /**
* Returns the description of the field/element. * Returns the description of the field/element.
@ -72,8 +69,7 @@ class Signup_Field_Text extends Base_Signup_Field {
public function get_description() { public function get_description() {
return __('Adds a text field that the customer can fill with arbitrary data.', 'wp-ultimo'); 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. * Returns the tooltip of the field/element.
@ -86,8 +82,7 @@ class Signup_Field_Text extends Base_Signup_Field {
public function get_tooltip() { public function get_tooltip() {
return __('Adds a text field that the customer can fill with arbitrary data.', 'wp-ultimo'); 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. * 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() { public function get_icon() {
return 'dashicons-wu-edit-3'; return 'dashicons-wu-edit-3';
}
} // end get_icon;
/** /**
* Returns the default values for the field-elements. * Returns the default values for the field-elements.
@ -115,10 +109,9 @@ class Signup_Field_Text extends Base_Signup_Field {
public function defaults() { public function defaults() {
return array( return array(
'' '',
); );
}
} // end defaults;
/** /**
* List of keys of the default fields we want to display on the builder. * 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', 'required',
'save_as', 'save_as',
); );
}
} // end default_fields;
/** /**
* If you want to force a particular attribute to a value, declare it here. * 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() { public function force_attributes() {
return array(); return array();
}
} // end force_attributes;
/** /**
* Returns the list of additional fields specific to this type. * 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() { public function get_fields() {
return array(); return array();
}
} // end get_fields;
/** /**
* Returns the field/element actual field array to be used on the checkout form. * 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; return $fields;
}
} // end to_fields_array; }
} // end class Signup_Field_Text;

View File

@ -9,7 +9,7 @@
namespace WP_Ultimo\Checkout\Signup_Fields; 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 // Exit if accessed directly
defined('ABSPATH') || exit; defined('ABSPATH') || exit;
@ -32,8 +32,7 @@ class Signup_Field_Username extends Base_Signup_Field {
public function get_type() { public function get_type() {
return 'username'; return 'username';
}
} // end get_type;
/** /**
* Returns if this field should be present on the checkout flow or not. * 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() { public function is_required() {
return true; return true;
}
} // end is_required;
/** /**
* Is this a user-related field? * Is this a user-related field?
@ -59,8 +57,7 @@ class Signup_Field_Username extends Base_Signup_Field {
public function is_user_field() { public function is_user_field() {
return true; return true;
}
} // end is_user_field;
/** /**
* Requires the title of the field/element type. * Requires the title of the field/element type.
@ -73,8 +70,7 @@ class Signup_Field_Username extends Base_Signup_Field {
public function get_title() { public function get_title() {
return __('Username', 'wp-ultimo'); return __('Username', 'wp-ultimo');
}
} // end get_title;
/** /**
* Returns the description of the field/element. * Returns the description of the field/element.
@ -87,8 +83,7 @@ class Signup_Field_Username extends Base_Signup_Field {
public function get_description() { public function get_description() {
return __('Adds an username field. This username will be used to create the WordPress user.', 'wp-ultimo'); 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. * Returns the tooltip of the field/element.
@ -101,8 +96,7 @@ class Signup_Field_Username extends Base_Signup_Field {
public function get_tooltip() { public function get_tooltip() {
return __('Adds an username field. This username will be used to create the WordPress user.', 'wp-ultimo'); 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. * 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() { public function get_icon() {
return 'dashicons-wu-user1'; return 'dashicons-wu-user1';
}
} // end get_icon;
/** /**
* Returns the default values for the field-elements. * Returns the default values for the field-elements.
@ -132,8 +125,7 @@ class Signup_Field_Username extends Base_Signup_Field {
return array( return array(
'auto_generate_username' => false, 'auto_generate_username' => false,
); );
}
} // end defaults;
/** /**
* List of keys of the default fields we want to display on the builder. * 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', 'placeholder',
'tooltip', 'tooltip',
); );
}
} // end default_fields;
/** /**
* If you want to force a particular attribute to a value, declare it here. * 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', 'id' => 'username',
'required' => true, 'required' => true,
); );
}
} // end force_attributes;
/** /**
* Returns the list of additional fields specific to this type. * 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. * 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. * Logged in user, bail.
*/ */
if (is_user_logged_in()) { if (is_user_logged_in()) {
return array(); return array();
}
} // end if;
if (isset($attributes['auto_generate_username']) && $attributes['auto_generate_username']) { if (isset($attributes['auto_generate_username']) && $attributes['auto_generate_username']) {
return array( return array(
'auto_generate_username' => array( 'auto_generate_username' => array(
'type' => 'hidden', 'type' => 'hidden',
@ -221,8 +207,7 @@ class Signup_Field_Username extends Base_Signup_Field {
'value' => uniqid(), 'value' => uniqid(),
), ),
); );
}
} // end if;
return array( return array(
'username' => 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. * @param array $attributes The attributes passed to the field.
*/ */
public function __construct($attributes = array()) public function __construct($attributes = array()) {
{
$this->attributes = $attributes; $this->attributes = $attributes;
} // end __construct; }
/** /**
* The render type for the template. * The render type for the template.
@ -66,8 +65,7 @@ class Base_Field_Template {
public function get_render_type(): string { public function get_render_type(): string {
return 'ajax'; return 'ajax';
}
} // end get_render_type;
/** /**
* The title of the field template. * The title of the field template.
@ -80,8 +78,7 @@ class Base_Field_Template {
public function get_title() { public function get_title() {
return __('Field Template', 'wp-ultimo'); return __('Field Template', 'wp-ultimo');
}
} // end get_title;
/** /**
* The description of the field template. * The description of the field template.
@ -94,8 +91,7 @@ class Base_Field_Template {
public function get_description() { public function get_description() {
return __('Description', 'wp-ultimo'); return __('Description', 'wp-ultimo');
}
} // end get_description;
/** /**
* The preview image of the field template. * The preview image of the field template.
* *
@ -106,8 +102,7 @@ class Base_Field_Template {
public function get_preview(): string { public function get_preview(): string {
return ''; return '';
}
} // end get_preview;
/** /**
* The content of the template. * The content of the template.
@ -117,7 +112,7 @@ class Base_Field_Template {
* @param array $attributes The field template attributes. * @param array $attributes The field template attributes.
* @return void * @return void
*/ */
public function output($attributes) {} // end output; public function output($attributes) {}
/** /**
* Renders the content. * Renders the content.
@ -136,8 +131,7 @@ class Base_Field_Template {
$this->output($attributes); $this->output($attributes);
return ob_get_clean(); return ob_get_clean();
}
} // end render;
/** /**
* Displays the content on the checkout form as a wrapper. * 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) { public function render_container($attributes, $signup_field = false) {
if ($this->get_render_type() === 'ajax') { if ($this->get_render_type() === 'ajax') {
if ($signup_field) { if ($signup_field) {
$attributes = $signup_field->reduce_attributes($attributes); $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))); $markup = sprintf('<dynamic :template="get_template(\'%s\', %s)"></dynamic>', esc_js($this->id), esc_attr(json_encode($attributes)));
} else { } else {
$markup = $this->render($attributes); $markup = $this->render($attributes);
}
} // end if;
return $markup; 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 // Exit if accessed directly
defined('ABSPATH') || exit; 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 * Template Selection Simple
@ -52,8 +52,7 @@ class Simple_Order_Bump_Field_Template extends Base_Field_Template {
public function get_render_type(): string { public function get_render_type(): string {
return 'ajax'; return 'ajax';
}
} // end get_render_type;
/** /**
* The title of the field template. * The title of the field template.
@ -66,8 +65,7 @@ class Simple_Order_Bump_Field_Template extends Base_Field_Template {
public function get_title() { public function get_title() {
return __('Simple', 'wp-ultimo'); return __('Simple', 'wp-ultimo');
}
} // end get_title;
/** /**
* The description of the field template. * The description of the field template.
@ -80,8 +78,7 @@ class Simple_Order_Bump_Field_Template extends Base_Field_Template {
public function get_description() { public function get_description() {
return __('A simple layout with minimal styling, just enough to make it usable out-of-the-box.', 'wp-ultimo'); 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. * 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 { public function get_preview(): string {
return wu_get_asset('checkout-forms/clean-template-selection.png'); return wu_get_asset('checkout-forms/clean-template-selection.png');
}
} // end get_preview;
/** /**
* The content of the template. * 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 * Loads the actual order-bump template
*/ */
wu_get_template('checkout/templates/order-bump/simple', $attributes); 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 // Exit if accessed directly
defined('ABSPATH') || exit; 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 * Order Summary Clean
@ -52,8 +52,7 @@ class Clean_Order_Summary_Field_Template extends Base_Field_Template {
public function get_render_type(): string { public function get_render_type(): string {
return 'dynamic'; return 'dynamic';
}
} // end get_render_type;
/** /**
* The title of the field template. * The title of the field template.
@ -66,8 +65,7 @@ class Clean_Order_Summary_Field_Template extends Base_Field_Template {
public function get_title() { public function get_title() {
return __('Clean', 'wp-ultimo'); return __('Clean', 'wp-ultimo');
}
} // end get_title;
/** /**
* The description of the field template. * The description of the field template.
@ -80,8 +78,7 @@ class Clean_Order_Summary_Field_Template extends Base_Field_Template {
public function get_description() { public function get_description() {
return __('A simple layout with minimal styling, just enough to make it usable out-of-the-box.', 'wp-ultimo'); 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. * 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 { public function get_preview(): string {
return wu_get_asset('checkout-forms/clean-order-summary.png'); return wu_get_asset('checkout-forms/clean-order-summary.png');
}
} // end get_preview;
/** /**
* The content of the template. * 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 * Loads the actual order-summary template
*/ */
wu_get_template('checkout/templates/order-summary/simple', $attributes); 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 // Exit if accessed directly
defined('ABSPATH') || exit; 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 * Template Selection Clean
@ -52,8 +52,7 @@ class Clean_Period_Selection_Field_Template extends Base_Field_Template {
public function get_render_type(): string { public function get_render_type(): string {
return 'dynamic'; return 'dynamic';
}
} // end get_render_type;
/** /**
* The title of the field template. * The title of the field template.
@ -66,8 +65,7 @@ class Clean_Period_Selection_Field_Template extends Base_Field_Template {
public function get_title() { public function get_title() {
return __('Clean', 'wp-ultimo'); return __('Clean', 'wp-ultimo');
}
} // end get_title;
/** /**
* The description of the field template. * The description of the field template.
@ -80,8 +78,7 @@ class Clean_Period_Selection_Field_Template extends Base_Field_Template {
public function get_description() { public function get_description() {
return __('A simple template with clean markup and no styling, ready to be customized with custom CSS.', 'wp-ultimo'); 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. * 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 { public function get_preview(): string {
return wu_get_asset('checkout-forms/clean-period-selection.png'); return wu_get_asset('checkout-forms/clean-period-selection.png');
}
} // end get_preview;
/** /**
* The content of the template. * The content of the template.
@ -108,7 +104,5 @@ class Clean_Period_Selection_Field_Template extends Base_Field_Template {
public function output($attributes) { public function output($attributes) {
wu_get_template('checkout/templates/period-selection/clean', $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 // Exit if accessed directly
defined('ABSPATH') || exit; 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 * Template Selection Clean
@ -52,8 +52,7 @@ class Legacy_Period_Selection_Field_Template extends Base_Field_Template {
public function get_render_type(): string { public function get_render_type(): string {
return 'dynamic'; return 'dynamic';
}
} // end get_render_type;
/** /**
* The title of the field template. * The title of the field template.
@ -66,8 +65,7 @@ class Legacy_Period_Selection_Field_Template extends Base_Field_Template {
public function get_title() { public function get_title() {
return __('Legacy', 'wp-ultimo'); return __('Legacy', 'wp-ultimo');
}
} // end get_title;
/** /**
* The description of the field template. * The description of the field template.
@ -80,8 +78,7 @@ class Legacy_Period_Selection_Field_Template extends Base_Field_Template {
public function get_description() { public function get_description() {
return __('Implementation of the layout that shipped with WP Multisite WaaS < 1.10.X.', 'wp-ultimo'); 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. * 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 { public function get_preview(): string {
return wu_get_asset('checkout-forms/legacy-period-selection.png'); return wu_get_asset('checkout-forms/legacy-period-selection.png');
}
} // end get_preview;
/** /**
* The content of the template. * The content of the template.
@ -108,7 +104,5 @@ class Legacy_Period_Selection_Field_Template extends Base_Field_Template {
public function output($attributes) { public function output($attributes) {
wu_get_template('checkout/templates/period-selection/legacy', $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 // Exit if accessed directly
defined('ABSPATH') || exit; 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 * Template Selection Clean
@ -52,8 +52,7 @@ class Legacy_Pricing_Table_Field_Template extends Base_Field_Template {
public function get_render_type(): string { public function get_render_type(): string {
return 'dynamic'; return 'dynamic';
}
} // end get_render_type;
/** /**
* The title of the field template. * The title of the field template.
@ -66,8 +65,7 @@ class Legacy_Pricing_Table_Field_Template extends Base_Field_Template {
public function get_title() { public function get_title() {
return __('Legacy', 'wp-ultimo'); return __('Legacy', 'wp-ultimo');
}
} // end get_title;
/** /**
* The description of the field template. * The description of the field template.
@ -80,8 +78,7 @@ class Legacy_Pricing_Table_Field_Template extends Base_Field_Template {
public function get_description() { public function get_description() {
return __('Implementation of the layout that shipped with WP Ultimo < 1.10.X.', 'wp-ultimo'); 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. * 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 { public function get_preview(): string {
return wu_get_asset('checkout-forms/legacy-pricing-table.png'); return wu_get_asset('checkout-forms/legacy-pricing-table.png');
}
} // end get_preview;
/** /**
* The content of the template. * The content of the template.
@ -108,7 +104,5 @@ class Legacy_Pricing_Table_Field_Template extends Base_Field_Template {
public function output($attributes) { public function output($attributes) {
wu_get_template('checkout/templates/pricing-table/legacy', $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 // Exit if accessed directly
defined('ABSPATH') || exit; 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 * Base Field Template
@ -43,8 +43,7 @@ class List_Pricing_Table_Field_Template extends Base_Field_Template {
public function get_title() { public function get_title() {
return __('Simple List', 'wp-ultimo'); return __('Simple List', 'wp-ultimo');
}
} // end get_title;
/** /**
* The description of the field template. * The description of the field template.
@ -57,8 +56,7 @@ class List_Pricing_Table_Field_Template extends Base_Field_Template {
public function get_description() { public function get_description() {
return __('Simple stylized list with price, recurrence, and the plan description.', 'wp-ultimo'); return __('Simple stylized list with price, recurrence, and the plan description.', 'wp-ultimo');
}
} // end get_description;
/** /**
* The preview image of the field template. * 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 { public function get_preview(): string {
return wu_get_asset('checkout-forms/list-pricing-table.png'); return wu_get_asset('checkout-forms/list-pricing-table.png');
}
} // end get_preview;
/** /**
* The content of the template. * The content of the template.
@ -85,7 +82,5 @@ class List_Pricing_Table_Field_Template extends Base_Field_Template {
public function output($attributes) { public function output($attributes) {
wu_get_template('checkout/templates/pricing-table/list', $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 // Exit if accessed directly
defined('ABSPATH') || exit; 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 * Template Selection Clean
@ -52,8 +52,7 @@ class Clean_Steps_Field_Template extends Base_Field_Template {
public function get_render_type(): string { public function get_render_type(): string {
return 'dynamic'; return 'dynamic';
}
} // end get_render_type;
/** /**
* The title of the field template. * The title of the field template.
@ -66,8 +65,7 @@ class Clean_Steps_Field_Template extends Base_Field_Template {
public function get_title() { public function get_title() {
return __('Clean', 'wp-ultimo'); return __('Clean', 'wp-ultimo');
}
} // end get_title;
/** /**
* The description of the field template. * The description of the field template.
@ -80,8 +78,7 @@ class Clean_Steps_Field_Template extends Base_Field_Template {
public function get_description() { public function get_description() {
return __('A simple layout with minimal styling, just enough to make it usable out-of-the-box.', 'wp-ultimo'); 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. * The preview of the field template.
@ -92,8 +89,7 @@ class Clean_Steps_Field_Template extends Base_Field_Template {
public function get_preview(): string { public function get_preview(): string {
return wu_get_asset('checkout-forms/clean-steps.png'); return wu_get_asset('checkout-forms/clean-steps.png');
}
} // end get_preview;
/** /**
* The content of the template. * The content of the template.
@ -106,7 +102,5 @@ class Clean_Steps_Field_Template extends Base_Field_Template {
public function output($attributes) { public function output($attributes) {
wu_get_template('checkout/templates/steps/clean', $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 // Exit if accessed directly
defined('ABSPATH') || exit; 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 * Template Selection Clean
@ -52,8 +52,7 @@ class Legacy_Steps_Field_Template extends Base_Field_Template {
public function get_render_type(): string { public function get_render_type(): string {
return 'dynamic'; return 'dynamic';
}
} // end get_render_type;
/** /**
* The title of the field template. * The title of the field template.
@ -66,8 +65,7 @@ class Legacy_Steps_Field_Template extends Base_Field_Template {
public function get_title() { public function get_title() {
return __('Legacy', 'wp-ultimo'); return __('Legacy', 'wp-ultimo');
}
} // end get_title;
/** /**
* The description of the field template. * The description of the field template.
@ -80,8 +78,7 @@ class Legacy_Steps_Field_Template extends Base_Field_Template {
public function get_description() { public function get_description() {
return __('Implementation of the layout that shipped with WP Ultimo < 1.10.X.', 'wp-ultimo'); return __('Implementation of the layout that shipped with WP Ultimo < 1.10.X.', 'wp-ultimo');
}
} // end get_description;
/** /**
* The preview of the field template. * The preview of the field template.
@ -92,8 +89,7 @@ class Legacy_Steps_Field_Template extends Base_Field_Template {
public function get_preview(): string { public function get_preview(): string {
return wu_get_asset('checkout-forms/legacy-steps.png'); return wu_get_asset('checkout-forms/legacy-steps.png');
}
} // end get_preview;
/** /**
* The content of the template. * The content of the template.
@ -106,7 +102,5 @@ class Legacy_Steps_Field_Template extends Base_Field_Template {
public function output($attributes) { public function output($attributes) {
wu_get_template('checkout/templates/steps/legacy', $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 // Exit if accessed directly
defined('ABSPATH') || exit; 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 * Template Selection Clean
@ -52,8 +52,7 @@ class Minimal_Steps_Field_Template extends Base_Field_Template {
public function get_render_type(): string { public function get_render_type(): string {
return 'dynamic'; return 'dynamic';
}
} // end get_render_type;
/** /**
* The title of the field template. * The title of the field template.
@ -66,8 +65,7 @@ class Minimal_Steps_Field_Template extends Base_Field_Template {
public function get_title() { public function get_title() {
return __('Minimal', 'wp-ultimo'); return __('Minimal', 'wp-ultimo');
}
} // end get_title;
/** /**
* The description of the field template. * The description of the field template.
@ -80,8 +78,7 @@ class Minimal_Steps_Field_Template extends Base_Field_Template {
public function get_description() { public function get_description() {
return __('A simple template with clean markup and no styling, ready to be customized with custom CSS.', 'wp-ultimo'); 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. * The preview of the field template.
@ -92,8 +89,7 @@ class Minimal_Steps_Field_Template extends Base_Field_Template {
public function get_preview(): string { public function get_preview(): string {
return wu_get_asset('checkout-forms/minimal-steps.png'); return wu_get_asset('checkout-forms/minimal-steps.png');
}
} // end get_preview;
/** /**
* The content of the template. * The content of the template.
@ -106,7 +102,5 @@ class Minimal_Steps_Field_Template extends Base_Field_Template {
public function output($attributes) { public function output($attributes) {
wu_get_template('checkout/templates/steps/minimal', $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 // Exit if accessed directly
defined('ABSPATH') || exit; 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 * Template Selection Clean
@ -52,8 +52,7 @@ class Clean_Template_Selection_Field_Template extends Base_Field_Template {
public function get_render_type(): string { public function get_render_type(): string {
return 'ajax'; return 'ajax';
}
} // end get_render_type;
/** /**
* The title of the field template. * The title of the field template.
@ -66,8 +65,7 @@ class Clean_Template_Selection_Field_Template extends Base_Field_Template {
public function get_title() { public function get_title() {
return __('Clean', 'wp-ultimo'); return __('Clean', 'wp-ultimo');
}
} // end get_title;
/** /**
* The description of the field template. * 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 { public function get_description(): string {
return __('A simple layout with minimal styling, just enough to make it usable out-of-the-box.', 'wp-ultimo'); 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. * 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 { public function get_preview(): string {
return wu_get_asset('checkout-forms/clean-template-selection.png'); return wu_get_asset('checkout-forms/clean-template-selection.png');
}
} // end get_preview;
/** /**
* The content of the template. * The content of the template.
@ -106,7 +102,5 @@ class Clean_Template_Selection_Field_Template extends Base_Field_Template {
public function output($attributes) { public function output($attributes) {
wu_get_template('checkout/templates/template-selection/clean', $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