Use new code style

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

View File

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

View File

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

View File

@ -10,22 +10,16 @@
defined('ABSPATH') || exit;
// 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));
} // end if;
// 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));
} // end if;
// 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));
} // end if;

View File

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

View File

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

View File

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

View File

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

View File

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

File diff suppressed because it is too large Load Diff

View File

@ -12,7 +12,7 @@ namespace WP_Ultimo\Admin_Pages;
// Exit if accessed directly
defined('ABSPATH') || exit;
use \WP_Ultimo\Models\Checkout_Form;
use WP_Ultimo\Models\Checkout_Form;
/**
* WP Multisite WaaS Checkout Form Admin Page.
@ -64,29 +64,31 @@ class Checkout_Form_List_Admin_Page extends List_Admin_Page {
*/
public function register_widgets() {
\WP_Ultimo\UI\Tours::get_instance()->create_tour('checkout-form-list', array(
\WP_Ultimo\UI\Tours::get_instance()->create_tour(
'checkout-form-list',
array(
'id' => 'checkout-form-list',
'title' => __('Checkout Forms', 'wp-ultimo'),
'text' => array(
__('Checkout Forms are an easy and flexible way to experiment with different approaches when trying to convert new customers.', 'wp-ultimo'),
array(
'id' => 'checkout-form-list',
'title' => __('Checkout Forms', 'wp-ultimo'),
'text' => array(
__('Checkout Forms are an easy and flexible way to experiment with different approaches when trying to convert new customers.', 'wp-ultimo'),
),
),
),
array(
'id' => 'default-form',
'title' => __('Experiment!', 'wp-ultimo'),
'text' => array(
__('You can create as many checkout forms as you want, with different fields, products on offer, etc.', 'wp-ultimo'),
__('Planning on running some sort of promotion? Why not create a custom landing page with a tailor-maid checkout form to go with? The possibilities are endless.', 'wp-ultimo'),
array(
'id' => 'default-form',
'title' => __('Experiment!', 'wp-ultimo'),
'text' => array(
__('You can create as many checkout forms as you want, with different fields, products on offer, etc.', 'wp-ultimo'),
__('Planning on running some sort of promotion? Why not create a custom landing page with a tailor-maid checkout form to go with? The possibilities are endless.', 'wp-ultimo'),
),
'attachTo' => array(
'element' => '#wp-ultimo-wrap > h1 > a:first-child',
'on' => 'right',
),
),
'attachTo' => array(
'element' => '#wp-ultimo-wrap > h1 > a:first-child',
'on' => 'right',
),
),
));
} // end register_widgets;
)
);
}
/**
* Register ajax forms to handle adding new checkout forms.
@ -98,13 +100,15 @@ class Checkout_Form_List_Admin_Page extends List_Admin_Page {
/*
* Add new Checkout Form
*/
wu_register_form('add_new_checkout_form', array(
'render' => array($this, 'render_add_new_checkout_form_modal'),
'handler' => array($this, 'handle_add_new_checkout_form_modal'),
'capability' => 'wu_edit_checkout_forms',
));
} // end register_forms;
wu_register_form(
'add_new_checkout_form',
array(
'render' => array($this, 'render_add_new_checkout_form_modal'),
'handler' => array($this, 'handle_add_new_checkout_form_modal'),
'capability' => 'wu_edit_checkout_forms',
)
);
}
/**
* 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(
'views' => 'admin-pages/fields',
'classes' => 'wu-modal-form wu-widget-list wu-striped wu-m-0 wu-mt-0',
'field_wrapper_classes' => 'wu-w-full wu-box-border wu-items-center wu-flex wu-justify-between wu-p-4 wu-m-0 wu-border-t wu-border-l-0 wu-border-r-0 wu-border-b-0 wu-border-gray-300 wu-border-solid',
'html_attr' => array(
'data-wu-app' => 'add_checkout_form_field',
'data-state' => json_encode(array(
'template' => 'single-step',
)),
),
));
$form = new \WP_Ultimo\UI\Form(
'add_new_checkout_form',
$fields,
array(
'views' => 'admin-pages/fields',
'classes' => 'wu-modal-form wu-widget-list wu-striped wu-m-0 wu-mt-0',
'field_wrapper_classes' => 'wu-w-full wu-box-border wu-items-center wu-flex wu-justify-between wu-p-4 wu-m-0 wu-border-t wu-border-l-0 wu-border-r-0 wu-border-b-0 wu-border-gray-300 wu-border-solid',
'html_attr' => array(
'data-wu-app' => 'add_checkout_form_field',
'data-state' => json_encode(
array(
'template' => 'single-step',
)
),
),
)
);
$form->render();
} // end render_add_new_checkout_form_modal;
}
/**
* Handles creation of a new memberships.
@ -176,7 +185,7 @@ class Checkout_Form_List_Admin_Page extends List_Admin_Page {
$template = wu_request('template');
$checkout_form = new \WP_Ultimo\Models\Checkout_Form;
$checkout_form = new \WP_Ultimo\Models\Checkout_Form();
$checkout_form->use_template($template);
@ -189,20 +198,20 @@ class Checkout_Form_List_Admin_Page extends List_Admin_Page {
$status = $checkout_form->save();
if (is_wp_error($status)) {
wp_send_json_error($status);
} else {
wp_send_json_success(array(
'redirect_url' => wu_network_admin_url('wp-ultimo-edit-checkout-form', array(
'id' => $checkout_form->get_id(),
))
));
} // end if;
} // end handle_add_new_checkout_form_modal;
wp_send_json_success(
array(
'redirect_url' => wu_network_admin_url(
'wp-ultimo-edit-checkout-form',
array(
'id' => $checkout_form->get_id(),
)
),
)
);
}
}
/**
* Returns an array with the labels for the edit page.
@ -216,8 +225,7 @@ class Checkout_Form_List_Admin_Page extends List_Admin_Page {
'deleted_message' => __('Checkout Form removed successfully.', 'wp-ultimo'),
'search_label' => __('Search Checkout Form', 'wp-ultimo'),
);
} // end get_labels;
}
/**
* Returns the title of the page.
@ -228,8 +236,7 @@ class Checkout_Form_List_Admin_Page extends List_Admin_Page {
public function get_title() {
return __('Checkout Forms', 'wp-ultimo');
} // end get_title;
}
/**
* Returns the title of menu for this page.
@ -240,8 +247,7 @@ class Checkout_Form_List_Admin_Page extends List_Admin_Page {
public function get_menu_title() {
return __('Checkout Forms', 'wp-ultimo');
} // end get_menu_title;
}
/**
* Allows admins to rename the sub-menu (first item) for a top-level page.
@ -252,8 +258,7 @@ class Checkout_Form_List_Admin_Page extends List_Admin_Page {
public function get_submenu_title() {
return __('Checkout Forms', 'wp-ultimo');
} // end get_submenu_title;
}
/**
* Returns the action links for that page.
@ -271,8 +276,7 @@ class Checkout_Form_List_Admin_Page extends List_Admin_Page {
'url' => wu_get_form_url('add_new_checkout_form'),
),
);
} // end action_links;
}
/**
* Loads the list table for this particular page.
@ -283,7 +287,5 @@ class Checkout_Form_List_Admin_Page extends List_Admin_Page {
public function table() {
return new \WP_Ultimo\List_Tables\Checkout_Form_List_Table();
} // end table;
} // end class Checkout_Form_List_Admin_Page;
}
}

File diff suppressed because it is too large Load Diff

View File

@ -51,8 +51,7 @@ class Customer_List_Admin_Page extends List_Admin_Page {
parent::init();
add_action('plugins_loaded', array($this, 'export_customers'));
} // end init;
}
/**
* Export customers in .csv file
@ -63,49 +62,47 @@ class Customer_List_Admin_Page extends List_Admin_Page {
public function export_customers() {
if (wu_request('wu_action') !== 'wu_export_customers') {
return;
}
} // end if;
if (!wp_verify_nonce(wu_request('nonce'), 'wu_export_customers')) {
if ( ! wp_verify_nonce(wu_request('nonce'), 'wu_export_customers')) {
wp_die(__('You do not have permissions to access this file.', 'wp-ultimo'));
}
} // end if;
$customer_data = array_map(
function ($customer) {
$customer_data = array_map(function($customer) {
$memberships = $customer->get_memberships();
$memberships = $customer->get_memberships();
$membership_amount = count($memberships);
$membership_amount = count($memberships);
$memberships_ids = array_map(fn($membership) => $membership->get_id(), $memberships);
$memberships_ids = array_map(fn($membership) => $membership->get_id(), $memberships);
$billing_address = array_map(fn($field) => $field['value'], $customer->get_billing_address()->get_fields());
$billing_address = array_map(fn($field) => $field['value'], $customer->get_billing_address()->get_fields());
return array_merge(
array(
$customer->get_id(),
$customer->get_user_id(),
$customer->get_hash(),
$customer->get_email_verification(),
$customer->get_user()->user_email,
$customer->has_trialed(),
$customer->get_last_ip(),
$customer->is_vip(),
$customer->get_signup_form(),
$membership_amount,
implode('|', $memberships_ids),
),
$billing_address,
array(
$customer->get_last_login(),
$customer->get_date_registered(),
)
);
}, wu_get_customers());
return array_merge(
array(
$customer->get_id(),
$customer->get_user_id(),
$customer->get_hash(),
$customer->get_email_verification(),
$customer->get_user()->user_email,
$customer->has_trialed(),
$customer->get_last_ip(),
$customer->is_vip(),
$customer->get_signup_form(),
$membership_amount,
implode('|', $memberships_ids),
),
$billing_address,
array(
$customer->get_last_login(),
$customer->get_date_registered(),
)
);
},
wu_get_customers()
);
$billing_fields = array_keys(\WP_Ultimo\Objects\Billing_Address::fields());
@ -135,8 +132,7 @@ class Customer_List_Admin_Page extends List_Admin_Page {
wu_generate_csv($file_name, array_merge(array($headers), $customer_data));
die;
} // end export_customers;
}
/**
* Holds the admin panels where this page should be displayed, as well as which capability to require.
@ -162,13 +158,15 @@ class Customer_List_Admin_Page extends List_Admin_Page {
/*
* Add new Customer
*/
wu_register_form('add_new_customer', array(
'render' => array($this, 'render_add_new_customer_modal'),
'handler' => array($this, 'handle_add_new_customer_modal'),
'capability' => 'wu_invite_customers',
));
} // end register_forms;
wu_register_form(
'add_new_customer',
array(
'render' => array($this, 'render_add_new_customer_modal'),
'handler' => array($this, 'handle_add_new_customer_modal'),
'capability' => 'wu_invite_customers',
)
);
}
/**
* 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(
'views' => 'admin-pages/fields',
'classes' => 'wu-modal-form wu-widget-list wu-striped wu-m-0 wu-mt-0',
'field_wrapper_classes' => 'wu-w-full wu-box-border wu-items-center wu-flex wu-justify-between wu-p-4 wu-m-0 wu-border-t wu-border-l-0 wu-border-r-0 wu-border-b-0 wu-border-gray-300 wu-border-solid',
'html_attr' => array(
'data-wu-app' => 'add_new_customer',
'data-state' => json_encode(array(
'set_password' => false,
'type' => 'existing',
)),
),
));
$form = new \WP_Ultimo\UI\Form(
'add_new_customer',
$fields,
array(
'views' => 'admin-pages/fields',
'classes' => 'wu-modal-form wu-widget-list wu-striped wu-m-0 wu-mt-0',
'field_wrapper_classes' => 'wu-w-full wu-box-border wu-items-center wu-flex wu-justify-between wu-p-4 wu-m-0 wu-border-t wu-border-l-0 wu-border-r-0 wu-border-b-0 wu-border-gray-300 wu-border-solid',
'html_attr' => array(
'data-wu-app' => 'add_new_customer',
'data-state' => json_encode(
array(
'set_password' => false,
'type' => 'existing',
)
),
),
)
);
$form->render();
} // end render_add_new_customer_modal;
}
/**
* Handles creation of a new customer.
@ -279,21 +282,17 @@ class Customer_List_Admin_Page extends List_Admin_Page {
public function handle_add_new_customer_modal() {
if (wu_request('type', 'existing') === 'new') {
$customer_data = array(
'email' => wu_request('email_address'),
'username' => wu_request('username'),
'password' => wu_request('password', false),
'meta' => array(),
);
} else {
$customer_data = array(
'user_id' => wu_request('user_id', 0),
);
} // end if;
}
/*
* Tries to create the customer
@ -301,18 +300,20 @@ class Customer_List_Admin_Page extends List_Admin_Page {
$customer = wu_create_customer($customer_data);
if (is_wp_error($customer)) {
wp_send_json_error($customer);
}
} // end if;
wp_send_json_success(array(
'redirect_url' => wu_network_admin_url('wp-ultimo-edit-customer', array(
'id' => $customer->get_id(),
))
));
} // end handle_add_new_customer_modal;
wp_send_json_success(
array(
'redirect_url' => wu_network_admin_url(
'wp-ultimo-edit-customer',
array(
'id' => $customer->get_id(),
)
),
)
);
}
/**
* Allow child classes to register widgets, if they need them.
@ -320,7 +321,7 @@ class Customer_List_Admin_Page extends List_Admin_Page {
* @since 1.8.2
* @return void
*/
public function register_widgets() {} // end register_widgets;
public function register_widgets() {}
/**
* Returns an array with the labels for the edit page.
@ -334,8 +335,7 @@ class Customer_List_Admin_Page extends List_Admin_Page {
'deleted_message' => __('Customer removed successfully.', 'wp-ultimo'),
'search_label' => __('Search Customer', 'wp-ultimo'),
);
} // end get_labels;
}
/**
* Returns the title of the page.
@ -346,8 +346,7 @@ class Customer_List_Admin_Page extends List_Admin_Page {
public function get_title() {
return __('Customers', 'wp-ultimo');
} // end get_title;
}
/**
* Returns the title of menu for this page.
@ -358,8 +357,7 @@ class Customer_List_Admin_Page extends List_Admin_Page {
public function get_menu_title() {
return __('Customers', 'wp-ultimo');
} // end get_menu_title;
}
/**
* Allows admins to rename the sub-menu (first item) for a top-level page.
@ -370,8 +368,7 @@ class Customer_List_Admin_Page extends List_Admin_Page {
public function get_submenu_title() {
return __('Customers', 'wp-ultimo');
} // end get_submenu_title;
}
/**
* Returns the action links for that page.
@ -391,14 +388,15 @@ class Customer_List_Admin_Page extends List_Admin_Page {
array(
'label' => __('Export as CSV', 'wp-ultimo'),
'icon' => 'wu-export',
'url' => add_query_arg(array(
'wu_action' => 'wu_export_customers',
'nonce' => wp_create_nonce('wu_export_customers'),
)),
'url' => add_query_arg(
array(
'wu_action' => 'wu_export_customers',
'nonce' => wp_create_nonce('wu_export_customers'),
)
),
),
);
} // end action_links;
}
/**
* Loads the list table for this particular page.
@ -409,7 +407,5 @@ class Customer_List_Admin_Page extends List_Admin_Page {
public function table() {
return new \WP_Ultimo\List_Tables\Customer_List_Table();
} // end table;
} // end class Customer_List_Admin_Page;
}
}

View File

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

View File

@ -12,7 +12,7 @@ namespace WP_Ultimo\Admin_Pages;
// Exit if accessed directly
defined('ABSPATH') || exit;
use \WP_Ultimo\Dashboard_Statistics;
use WP_Ultimo\Dashboard_Statistics;
/**
* WP Multisite WaaS Dashboard Admin Page.
@ -20,10 +20,10 @@ use \WP_Ultimo\Dashboard_Statistics;
class Dashboard_Admin_Page extends Base_Admin_Page {
/**
* Holds the ID for this page, this is also used as the page slug.
*
* @var string
*/
* Holds the ID for this page, this is also used as the page slug.
*
* @var string
*/
protected $id = 'wp-ultimo';
/**
@ -104,8 +104,7 @@ class Dashboard_Admin_Page extends Base_Admin_Page {
$this->tab = wu_request('tab', 'general');
$this->start_date = date_i18n('Y-m-d', strtotime((string) wu_request('start_date', '-1 month')));
$this->end_date = date_i18n('Y-m-d', strtotime((string) wu_request('end_date', 'tomorrow')));
} // end init;
}
/**
* Allow child classes to add hooks to be run once the page is loaded.
@ -119,8 +118,7 @@ class Dashboard_Admin_Page extends Base_Admin_Page {
add_action('wu_dash_after_full_metaboxes', array($this, 'render_filter'));
add_action('wu_dashboard_general_widgets', array($this, 'register_general_tab_widgets'), 10, 2);
} // end hooks;
}
/**
* Renders the filter.
@ -133,13 +131,10 @@ class Dashboard_Admin_Page extends Base_Admin_Page {
public function render_filter($page) {
if (apply_filters('wu_dashboard_display_filter', true) === false) {
return;
} // end if;
}
if ($page->id === 'wp-ultimo') {
$preset_options = array(
'last_7_days' => array(
'label' => __('Last 7 days', 'wp-ultimo'),
@ -170,10 +165,8 @@ class Dashboard_Admin_Page extends Base_Admin_Page {
);
wu_get_template('dashboard-statistics/filter', $args);
} // end if;
} // end render_filter;
}
}
/**
* Returns the views for the filter menu bar.
@ -193,8 +186,7 @@ class Dashboard_Admin_Page extends Base_Admin_Page {
);
return apply_filters('wu_dashboard_filter_bar', $dashboard_filters);
} // end get_views;
}
/**
* Allow child classes to register widgets, if they need them.
@ -206,11 +198,9 @@ class Dashboard_Admin_Page extends Base_Admin_Page {
$screen = get_current_screen();
if (!$screen) {
if ( ! $screen) {
return;
} // end if;
}
/**
* Allow plugin developers to add widgets to Network Dashboard Panel.
@ -235,54 +225,54 @@ class Dashboard_Admin_Page extends Base_Admin_Page {
do_action('wu_dashboard_widgets', $this->tab, $screen, $this);
if (wu_request('tab', 'general') === 'general') {
\WP_Ultimo\UI\Tours::get_instance()->create_tour('wp-ultimo-dashboard', array(
\WP_Ultimo\UI\Tours::get_instance()->create_tour(
'wp-ultimo-dashboard',
array(
'id' => 'your-dashboard',
'title' => __('Our dashboard', 'wp-ultimo'),
'text' => array(
__('This is the <strong>WP Multisite WaaS Dashboard</strong>, where you will find most of the important information you will need regarding your business\' performance.', 'wp-ultimo'),
array(
'id' => 'your-dashboard',
'title' => __('Our dashboard', 'wp-ultimo'),
'text' => array(
__('This is the <strong>WP Multisite WaaS Dashboard</strong>, where you will find most of the important information you will need regarding your business\' performance.', 'wp-ultimo'),
),
),
),
array(
'id' => 'documentation',
'title' => __('Learning more', 'wp-ultimo'),
'text' => array(
__('Most of the WP Multisite WaaS admin pages will contain a link like this one at the top. These will link directly to the relevant knowledge base page on the WP Multisite WaaS site.', 'wp-ultimo'),
array(
'id' => 'documentation',
'title' => __('Learning more', 'wp-ultimo'),
'text' => array(
__('Most of the WP Multisite WaaS admin pages will contain a link like this one at the top. These will link directly to the relevant knowledge base page on the WP Multisite WaaS site.', 'wp-ultimo'),
),
'attachTo' => array(
'element' => '#wp-ultimo-wrap > h1 > a:last-child',
'on' => 'left',
),
),
'attachTo' => array(
'element' => '#wp-ultimo-wrap > h1 > a:last-child',
'on' => 'left',
array(
'id' => 'mrr-growth',
'title' => __('It\'s all about growth!', 'wp-ultimo'),
'text' => array(
__('This graph allows you to follow how your monthly recurring revenue is growing this year.', 'wp-ultimo'),
),
'attachTo' => array(
'element' => '#wp-ultimo-mrr-growth',
'on' => 'bottom',
),
),
),
array(
'id' => 'mrr-growth',
'title' => __('It\'s all about growth!', 'wp-ultimo'),
'text' => array(
__('This graph allows you to follow how your monthly recurring revenue is growing this year.', 'wp-ultimo'),
array(
'id' => 'tailor-made',
'title' => __('Date-range support', 'wp-ultimo'),
'text' => array(
__('Checking statistics and comparing data for different periods is key in maintaining a good grasp on your business.', 'wp-ultimo'),
__('You can use the date-range selectors to have access to just the data you need and nothing more.', 'wp-ultimo'),
),
'attachTo' => array(
'element' => '#dashboard-filters',
'on' => 'bottom',
),
),
'attachTo' => array(
'element' => '#wp-ultimo-mrr-growth',
'on' => 'bottom',
),
),
array(
'id' => 'tailor-made',
'title' => __('Date-range support', 'wp-ultimo'),
'text' => array(
__('Checking statistics and comparing data for different periods is key in maintaining a good grasp on your business.', 'wp-ultimo'),
__('You can use the date-range selectors to have access to just the data you need and nothing more.', 'wp-ultimo'),
),
'attachTo' => array(
'element' => '#dashboard-filters',
'on' => 'bottom',
),
),
));
} // end if;
} // end register_widgets;
)
);
}
}
/**
* Register the widgets of the default general tab.
@ -296,12 +286,10 @@ class Dashboard_Admin_Page extends Base_Admin_Page {
public function register_general_tab_widgets($tab, $screen) {
if (current_user_can('wu_read_financial')) {
add_meta_box('wp-ultimo-mrr-growth', __('Monthly Recurring Revenue Growth', 'wp-ultimo'), array($this, 'output_widget_mrr_growth'), $screen->id, 'full', 'high');
add_meta_box('wp-ultimo-revenue', __('Revenue', 'wp-ultimo'), array($this, 'output_widget_revenues'), $screen->id, 'normal', 'high');
} // end if;
}
add_meta_box('wp-ultimo-countries', __('Signups by Countries', 'wp-ultimo'), array($this, 'output_widget_countries'), $screen->id, 'side', 'high');
@ -310,8 +298,7 @@ class Dashboard_Admin_Page extends Base_Admin_Page {
add_meta_box('wp-ultimo-most-visited-sites', __('Most Visited Sites', 'wp-ultimo'), array($this, 'output_widget_most_visited_sites'), $screen->id, 'side', 'low');
add_meta_box('wp-ultimo-new-accounts', __('New Memberships', 'wp-ultimo'), array($this, 'output_widget_new_accounts'), $screen->id, 'normal', 'low');
} // end register_general_tab_widgets;
}
/**
* Output the statistics filter widget
@ -322,8 +309,7 @@ class Dashboard_Admin_Page extends Base_Admin_Page {
public function output_widget_mrr_growth() {
wu_get_template('dashboard-statistics/widget-mrr-growth');
} // end output_widget_mrr_growth;
}
/**
* Output the statistics filter widget
@ -333,12 +319,14 @@ class Dashboard_Admin_Page extends Base_Admin_Page {
*/
public function output_widget_countries() {
wu_get_template('dashboard-statistics/widget-countries', array(
'countries' => wu_get_countries_of_customers(10, $this->start_date, $this->end_date),
'page' => $this,
));
} // end output_widget_countries;
wu_get_template(
'dashboard-statistics/widget-countries',
array(
'countries' => wu_get_countries_of_customers(10, $this->start_date, $this->end_date),
'page' => $this,
)
);
}
/**
* Output the statistics filter widget
@ -348,12 +336,14 @@ class Dashboard_Admin_Page extends Base_Admin_Page {
*/
public function output_widget_forms() {
wu_get_template('dashboard-statistics/widget-forms', array(
'forms' => wu_calculate_signups_by_form($this->start_date, $this->end_date),
'page' => $this,
));
} // end output_widget_forms;
wu_get_template(
'dashboard-statistics/widget-forms',
array(
'forms' => wu_calculate_signups_by_form($this->start_date, $this->end_date),
'page' => $this,
)
);
}
/**
* Output the statistics filter widget
@ -368,28 +358,26 @@ class Dashboard_Admin_Page extends Base_Admin_Page {
$site_results = \WP_Ultimo\Objects\Visits::get_sites_by_visit_count($this->start_date, $this->end_date, 10);
foreach ($site_results as $site_result) {
$site = wu_get_site($site_result->site_id);
if (!$site) {
if ( ! $site) {
continue;
} // end if;
}
$sites[] = (object) array(
'site' => $site,
'count' => $site_result->count,
);
}
} // end foreach;
wu_get_template('dashboard-statistics/widget-most-visited-sites', array(
'sites' => $sites,
'page' => $this,
));
} // end output_widget_most_visited_sites;
wu_get_template(
'dashboard-statistics/widget-most-visited-sites',
array(
'sites' => $sites,
'page' => $this,
)
);
}
/**
* Outputs the total refunds widget content.
@ -402,14 +390,16 @@ class Dashboard_Admin_Page extends Base_Admin_Page {
*/
public function output_widget_revenues($unknown = null, $metabox = null) {
wu_get_template('dashboard-statistics/widget-revenue', array(
'mrr' => wu_calculate_mrr(),
'gross_revenue' => wu_calculate_revenue($this->start_date, $this->end_date),
'refunds' => wu_calculate_refunds($this->start_date, $this->end_date),
'product_stats' => wu_calculate_financial_data_by_product($this->start_date, $this->end_date),
));
} // end output_widget_revenues;
wu_get_template(
'dashboard-statistics/widget-revenue',
array(
'mrr' => wu_calculate_mrr(),
'gross_revenue' => wu_calculate_revenue($this->start_date, $this->end_date),
'refunds' => wu_calculate_refunds($this->start_date, $this->end_date),
'product_stats' => wu_calculate_financial_data_by_product($this->start_date, $this->end_date),
)
);
}
/**
* Outputs the total refunds widget content.
@ -422,32 +412,38 @@ class Dashboard_Admin_Page extends Base_Admin_Page {
*/
public function output_widget_new_accounts($unknown = null, $metabox = array()) {
$new_accounts = wu_get_memberships(array(
'fields' => array('plan_id'),
'date_query' => array(
'column' => 'date_created',
'after' => $this->start_date . ' 00:00:00',
'before' => $this->end_date . ' 23:59:59',
'inclusive' => true,
),
));
$new_accounts = wu_get_memberships(
array(
'fields' => array('plan_id'),
'date_query' => array(
'column' => 'date_created',
'after' => $this->start_date . ' 00:00:00',
'before' => $this->end_date . ' 23:59:59',
'inclusive' => true,
),
)
);
$products = wu_get_products(array(
'type' => 'plan',
'fields' => array('id', 'name', 'count'),
));
$products = wu_get_products(
array(
'type' => 'plan',
'fields' => array('id', 'name', 'count'),
)
);
$products_ids = array_column($products, 'id');
$products = array_combine($products_ids, $products);
$products = array_map(function($item) {
$products = array_map(
function ($item) {
$item->count = 0;
$item->count = 0;
return $item;
}, $products);
return $item;
},
$products
);
/**
* Add edge case for no plan.
@ -458,25 +454,21 @@ class Dashboard_Admin_Page extends Base_Admin_Page {
);
foreach ($new_accounts as $new_account) {
if (isset($products[$new_account->plan_id])) {
$products[$new_account->plan_id]->count += 1;
if (isset($products[ $new_account->plan_id ])) {
$products[ $new_account->plan_id ]->count += 1;
} else {
$products['none']->count += 1;
}
}
} // end if;
} // end foreach;
wu_get_template('dashboard-statistics/widget-new-accounts', array(
'new_accounts' => count($new_accounts),
'products' => $products,
));
} // end output_widget_new_accounts;
wu_get_template(
'dashboard-statistics/widget-new-accounts',
array(
'new_accounts' => count($new_accounts),
'products' => $products,
)
);
}
/**
* Enqueue the necessary scripts.
@ -491,16 +483,18 @@ class Dashboard_Admin_Page extends Base_Admin_Page {
$current_year = date_i18n('Y');
for ($i = 1; $i <= 12; $i++) {
$month_list[] = date_i18n('M y', mktime(0, 0,0,$i,1, $current_year));
$month_list[] = date_i18n('M y', mktime(0, 0, 0, $i, 1, $current_year));
}
$statistics = new Dashboard_Statistics(array(
'start_date' => $this->start_date,
'end_date' => $this->end_date,
'types' => array(
'mrr_growth' => 'mrr_growth',
),
));
$statistics = new Dashboard_Statistics(
array(
'start_date' => $this->start_date,
'end_date' => $this->end_date,
'types' => array(
'mrr_growth' => 'mrr_growth',
),
)
);
$data = $statistics->statistics_data();
@ -510,25 +504,28 @@ class Dashboard_Admin_Page extends Base_Admin_Page {
wp_register_script('wu-dashboard-stats', wu_get_asset('dashboard-statistics.js', 'js'), array('jquery', 'wu-functions', 'wu-ajax-list-table', 'moment', 'wu-block-ui', 'dashboard', 'wu-apex-charts', 'wu-vue-apex-charts'), wu_get_version(), true);
wp_localize_script('wu-dashboard-stats', 'wu_dashboard_statistics_vars', array(
'mrr_array' => $data['mrr_growth'],
'start_date' => date_i18n('Y-m-d', strtotime((string) wu_request('start_date', '-1 month'))),
'end_date' => date_i18n('Y-m-d', strtotime((string) wu_request('end_date', 'tomorrow'))),
'today' => date_i18n('Y-m-d', strtotime('tomorrow')),
'month_list' => $month_list,
'i18n' => array(
'new_mrr' => __('New MRR', 'wp-ultimo'),
'cancellations' => __('Cancellations', 'wp-ultimo'),
),
));
wp_localize_script(
'wu-dashboard-stats',
'wu_dashboard_statistics_vars',
array(
'mrr_array' => $data['mrr_growth'],
'start_date' => date_i18n('Y-m-d', strtotime((string) wu_request('start_date', '-1 month'))),
'end_date' => date_i18n('Y-m-d', strtotime((string) wu_request('end_date', 'tomorrow'))),
'today' => date_i18n('Y-m-d', strtotime('tomorrow')),
'month_list' => $month_list,
'i18n' => array(
'new_mrr' => __('New MRR', 'wp-ultimo'),
'cancellations' => __('Cancellations', 'wp-ultimo'),
),
)
);
wp_enqueue_script('wu-dashboard-stats');
wp_enqueue_style('wu-apex-charts', wu_get_asset('apexcharts.css', 'css'), array(), wu_get_version());
wp_enqueue_style('wu-flags');
} // end register_scripts;
}
/**
* Returns the title of the page.
@ -539,8 +536,7 @@ class Dashboard_Admin_Page extends Base_Admin_Page {
public function get_title() {
return __('Dashboard', 'wp-ultimo');
} // end get_title;
}
/**
* Returns the title of menu for this page.
@ -551,8 +547,7 @@ class Dashboard_Admin_Page extends Base_Admin_Page {
public function get_menu_title() {
return __('Multisite WaaS', 'wp-ultimo');
} // end get_menu_title;
}
/**
* Allows admins to rename the sub-menu (first item) for a top-level page.
@ -563,8 +558,7 @@ class Dashboard_Admin_Page extends Base_Admin_Page {
public function get_submenu_title() {
return __('Dashboard', 'wp-ultimo');
} // end get_submenu_title;
}
/**
* Every child class should implement the output method to display the contents of the page.
@ -576,13 +570,15 @@ class Dashboard_Admin_Page extends Base_Admin_Page {
/*
* Renders the base edit page layout, with the columns and everything else =)
*/
wu_get_template('base/dash', array(
'screen' => get_current_screen(),
'page' => $this,
'has_full_position' => true,
));
} // end output;
wu_get_template(
'base/dash',
array(
'screen' => get_current_screen(),
'page' => $this,
'has_full_position' => true,
)
);
}
/**
* Render an export CSV button.
@ -594,12 +590,15 @@ class Dashboard_Admin_Page extends Base_Admin_Page {
*/
public function render_csv_button($args) {
$args = wp_parse_args($args, array(
'slug' => 'csv',
'headers' => array(),
'data' => array(),
'action' => apply_filters('wu_export_data_table_action', 'wu_generate_csv'),
));
$args = wp_parse_args(
$args,
array(
'slug' => 'csv',
'headers' => array(),
'data' => array(),
'action' => apply_filters('wu_export_data_table_action', 'wu_generate_csv'),
)
);
$slug = $args['slug'];
@ -621,8 +620,6 @@ class Dashboard_Admin_Page extends Base_Admin_Page {
$html = apply_filters('wu_export_html_render', $html, $html);
echo sprintf($html, apply_filters('wu_export_data_table_label', __('CSV', 'wp-ultimo')));
} // end render_csv_button;
} // end class Dashboard_Admin_Page;
printf($html, apply_filters('wu_export_data_table_label', __('CSV', 'wp-ultimo')));
}
}

View File

@ -12,8 +12,8 @@ namespace WP_Ultimo\Admin_Pages;
// Exit if accessed directly
defined('ABSPATH') || exit;
use \WP_Ultimo\Models\Discount_Code;
use \WP_Ultimo\Managers\Discount_Code_Manager;
use WP_Ultimo\Models\Discount_Code;
use WP_Ultimo\Managers\Discount_Code_Manager;
/**
* WP Multisite WaaS Discount_Code Edit/Add New Admin Page.
@ -91,21 +91,24 @@ class Discount_Code_Edit_Admin_Page extends Edit_Admin_Page {
parent::register_widgets();
$this->add_fields_widget('description', array(
'title' => __('Description', 'wp-ultimo'),
'position' => 'normal',
'fields' => array(
'description' => array(
'type' => 'textarea',
'title' => __('Description', 'wp-ultimo'),
'placeholder' => __('Tell your customers what this product is about.', 'wp-ultimo'),
'value' => $this->get_object()->get_description(),
'html_attr' => array(
'rows' => 3,
$this->add_fields_widget(
'description',
array(
'title' => __('Description', 'wp-ultimo'),
'position' => 'normal',
'fields' => array(
'description' => array(
'type' => 'textarea',
'title' => __('Description', 'wp-ultimo'),
'placeholder' => __('Tell your customers what this product is about.', 'wp-ultimo'),
'value' => $this->get_object()->get_description(),
'html_attr' => array(
'rows' => 3,
),
),
),
),
));
)
);
$tz_note = sprintf('The site timezone is <code>%s</code>. The current time is <code>%s</code>', date_i18n('e'), date_i18n('r'));
@ -215,161 +218,175 @@ class Discount_Code_Edit_Admin_Page extends Edit_Admin_Page {
'v-model' => 'limit_products',
),
),
), $this->get_product_field_list()
),
$this->get_product_field_list()
),
),
);
$this->add_tabs_widget('options', array(
'title' => __('Advanced Options', 'wp-ultimo'),
'position' => 'normal',
'sections' => apply_filters('wu_discount_code_options_sections', $options, $this->get_object()),
));
$this->add_tabs_widget(
'options',
array(
'title' => __('Advanced Options', 'wp-ultimo'),
'position' => 'normal',
'sections' => apply_filters('wu_discount_code_options_sections', $options, $this->get_object()),
)
);
/*
* Handle legacy options for back-compat.
*/
$this->handle_legacy_options();
$this->add_list_table_widget('events', array(
'title' => __('Events', 'wp-ultimo'),
'table' => new \WP_Ultimo\List_Tables\Inside_Events_List_Table(),
'query_filter' => array($this, 'query_filter'),
));
$this->add_list_table_widget(
'events',
array(
'title' => __('Events', 'wp-ultimo'),
'table' => new \WP_Ultimo\List_Tables\Inside_Events_List_Table(),
'query_filter' => array($this, 'query_filter'),
)
);
$this->add_save_widget('save', array(
'html_attr' => array(
'data-wu-app' => 'save_discount_code',
'data-state' => wu_convert_to_state(array(
'apply_to_setup_fee' => $this->get_object()->get_setup_fee_value() > 0,
'code' => $this->get_object()->get_code(),
'type' => $this->get_object()->get_type(),
'value' => $this->get_object()->get_value(),
'setup_fee_type' => $this->get_object()->get_setup_fee_type(),
'setup_fee_value' => $this->get_object()->get_setup_fee_value(),
)),
),
'fields' => array(
'code' => array(
'title' => __('Coupon Code', 'wp-ultimo'),
'type' => 'text',
'placeholder' => __('E.g. XMAS10OFF', 'wp-ultimo'),
'desc' => __('The actual code your customers will enter during checkout.', 'wp-ultimo'),
'value' => $this->get_object()->get_code(),
'tooltip' => '',
'wrapper_html_attr' => array(
'v-cloak' => '1',
),
'html_attr' => array(
'v-on:input' => 'code = $event.target.value.toUpperCase().replace(/[^A-Z0-9-_]+/g, "")',
'v-bind:value' => 'code',
$this->add_save_widget(
'save',
array(
'html_attr' => array(
'data-wu-app' => 'save_discount_code',
'data-state' => wu_convert_to_state(
array(
'apply_to_setup_fee' => $this->get_object()->get_setup_fee_value() > 0,
'code' => $this->get_object()->get_code(),
'type' => $this->get_object()->get_type(),
'value' => $this->get_object()->get_value(),
'setup_fee_type' => $this->get_object()->get_setup_fee_type(),
'setup_fee_value' => $this->get_object()->get_setup_fee_value(),
)
),
),
'value_group' => array(
'type' => 'group',
'title' => __('Discount', 'wp-ultimo'),
'wrapper_html_attr' => array(
'v-cloak' => '1',
'fields' => array(
'code' => array(
'title' => __('Coupon Code', 'wp-ultimo'),
'type' => 'text',
'placeholder' => __('E.g. XMAS10OFF', 'wp-ultimo'),
'desc' => __('The actual code your customers will enter during checkout.', 'wp-ultimo'),
'value' => $this->get_object()->get_code(),
'tooltip' => '',
'wrapper_html_attr' => array(
'v-cloak' => '1',
),
'html_attr' => array(
'v-on:input' => 'code = $event.target.value.toUpperCase().replace(/[^A-Z0-9-_]+/g, "")',
'v-bind:value' => 'code',
),
),
'fields' => array(
'type' => array(
'type' => 'select',
'value' => $this->get_object()->get_type(),
'placeholder' => '',
'wrapper_classes' => 'wu-w-2/3',
'options' => array(
'percentage' => __('Percentage (%)', 'wp-ultimo'),
// translators: %s is the currency symbol. e.g. $
'absolute' => sprintf(__('Absolute (%s)', 'wp-ultimo'), wu_get_currency_symbol()),
'value_group' => array(
'type' => 'group',
'title' => __('Discount', 'wp-ultimo'),
'wrapper_html_attr' => array(
'v-cloak' => '1',
),
'fields' => array(
'type' => array(
'type' => 'select',
'value' => $this->get_object()->get_type(),
'placeholder' => '',
'wrapper_classes' => 'wu-w-2/3',
'options' => array(
'percentage' => __('Percentage (%)', 'wp-ultimo'),
// translators: %s is the currency symbol. e.g. $
'absolute' => sprintf(__('Absolute (%s)', 'wp-ultimo'), wu_get_currency_symbol()),
),
'html_attr' => array(
'v-model' => 'type',
),
),
'html_attr' => array(
'v-model' => 'type',
'value' => array(
'type' => 'number',
'value' => $this->get_object()->get_value(),
'placeholder' => '',
'wrapper_classes' => 'wu-ml-2 wu-w-1/3',
'html_attr' => array(
'min' => 0,
'v-bind:max' => "type === 'percentage' ? 100 : 999999999",
'step' => 'any',
),
),
),
'value' => array(
'type' => 'number',
'value' => $this->get_object()->get_value(),
'placeholder' => '',
'wrapper_classes' => 'wu-ml-2 wu-w-1/3',
'html_attr' => array(
'min' => 0,
'v-bind:max' => "type === 'percentage' ? 100 : 999999999",
'step' => 'any'
),
'apply_to_renewals' => array(
'type' => 'toggle',
'title' => __('Apply to Renewals', 'wp-ultimo'),
'desc' => __('By default, discounts are only applied to the first payment.', 'wp-ultimo'),
'value' => $this->get_object()->should_apply_to_renewals(),
'wrapper_html_attr' => array(
'v-cloak' => '1',
),
),
'apply_to_setup_fee' => array(
'type' => 'toggle',
'title' => __('Setup Fee Discount', 'wp-ultimo'),
'desc' => __('Also set a discount for setup fee?', 'wp-ultimo'),
'value' => $this->get_object()->get_setup_fee_value() > 0,
'html_attr' => array(
'v-model' => 'apply_to_setup_fee',
),
'wrapper_html_attr' => array(
'v-cloak' => '1',
),
),
'setup_fee_value_group' => array(
'type' => 'group',
'title' => __('Setup Fee Discount', 'wp-ultimo'),
'wrapper_html_attr' => array(
'v-show' => 'apply_to_setup_fee',
'v-cloak' => '1',
),
'fields' => array(
'setup_fee_type' => array(
'type' => 'select',
'value' => $this->get_object()->get_setup_fee_type(),
'placeholder' => '',
'wrapper_classes' => 'wu-w-2/3',
'options' => array(
'percentage' => __('Percentage (%)', 'wp-ultimo'),
// translators: %s is the currency symbol. e.g $
'absolute' => sprintf(__('Absolute (%s)', 'wp-ultimo'), wu_get_currency_symbol()),
),
'html_attr' => array(
'v-model' => 'setup_fee_type',
),
),
'setup_fee_value' => array(
'type' => 'number',
'value' => $this->get_object()->get_setup_fee_value(),
'placeholder' => '',
'wrapper_classes' => 'wu-ml-2 wu-w-1/3',
'html_attr' => array(
'min' => 0,
'v-bind:max' => "setup_fee_type === 'percentage' ? 100 : 999999999",
),
),
),
),
),
'apply_to_renewals' => array(
'type' => 'toggle',
'title' => __('Apply to Renewals', 'wp-ultimo'),
'desc' => __('By default, discounts are only applied to the first payment.', 'wp-ultimo'),
'value' => $this->get_object()->should_apply_to_renewals(),
'wrapper_html_attr' => array(
'v-cloak' => '1',
),
),
'apply_to_setup_fee' => array(
'type' => 'toggle',
'title' => __('Setup Fee Discount', 'wp-ultimo'),
'desc' => __('Also set a discount for setup fee?', 'wp-ultimo'),
'value' => $this->get_object()->get_setup_fee_value() > 0,
'html_attr' => array(
'v-model' => 'apply_to_setup_fee',
),
'wrapper_html_attr' => array(
'v-cloak' => '1',
),
),
'setup_fee_value_group' => array(
'type' => 'group',
'title' => __('Setup Fee Discount', 'wp-ultimo'),
'wrapper_html_attr' => array(
'v-show' => 'apply_to_setup_fee',
'v-cloak' => '1',
),
'fields' => array(
'setup_fee_type' => array(
'type' => 'select',
'value' => $this->get_object()->get_setup_fee_type(),
'placeholder' => '',
'wrapper_classes' => 'wu-w-2/3',
'options' => array(
'percentage' => __('Percentage (%)', 'wp-ultimo'),
// translators: %s is the currency symbol. e.g $
'absolute' => sprintf(__('Absolute (%s)', 'wp-ultimo'), wu_get_currency_symbol()),
),
'html_attr' => array(
'v-model' => 'setup_fee_type',
),
),
'setup_fee_value' => array(
'type' => 'number',
'value' => $this->get_object()->get_setup_fee_value(),
'placeholder' => '',
'wrapper_classes' => 'wu-ml-2 wu-w-1/3',
'html_attr' => array(
'min' => 0,
'v-bind:max' => "setup_fee_type === 'percentage' ? 100 : 999999999",
),
),
),
),
),
));
)
);
$this->add_fields_widget('active', array(
'title' => __('Active', 'wp-ultimo'),
'fields' => array(
'active' => array(
'type' => 'toggle',
'title' => __('Active', 'wp-ultimo'),
'desc' => __('Use this option to manually enable or disable this discount code for new sign-ups.', 'wp-ultimo'),
'value' => $this->get_object()->is_active(),
$this->add_fields_widget(
'active',
array(
'title' => __('Active', 'wp-ultimo'),
'fields' => array(
'active' => array(
'type' => 'toggle',
'title' => __('Active', 'wp-ultimo'),
'desc' => __('Use this option to manually enable or disable this discount code for new sign-ups.', 'wp-ultimo'),
'value' => $this->get_object()->is_active(),
),
),
),
));
} // end register_widgets;
)
);
}
/**
* List of products to apply this coupon to.
@ -382,10 +399,9 @@ class Discount_Code_Edit_Admin_Page extends Edit_Admin_Page {
$fields = array();
foreach (wu_get_products() as $product) {
$product_id = $product->get_id();
$fields["allowed_products_{$product_id}"] = array(
$fields[ "allowed_products_{$product_id}" ] = array(
'type' => 'toggle',
'title' => $product->get_name(),
'desc' => __('Make applicable to this product.', 'wp-ultimo'),
@ -410,11 +426,9 @@ class Discount_Code_Edit_Admin_Page extends Edit_Admin_Page {
':name' => "'allowed_products[]'",
),
);
} // end foreach;
}
if (empty($fields)) {
$fields['allowed_products_no_products'] = array(
'type' => 'note',
'title' => '',
@ -424,12 +438,10 @@ class Discount_Code_Edit_Admin_Page extends Edit_Admin_Page {
'v-show' => 'limit_products',
),
);
} // end if;
}
return $fields;
} // end get_product_field_list;
}
/**
* Handles legacy advanced options for coupons.
@ -443,11 +455,9 @@ class Discount_Code_Edit_Admin_Page extends Edit_Admin_Page {
$tabs = array(__('Legacy Add-ons', 'wp-ultimo'));
if (!isset($wp_filter['wp_ultimo_coupon_advanced_options'])) {
if ( ! isset($wp_filter['wp_ultimo_coupon_advanced_options'])) {
return;
} // end if;
}
wp_enqueue_style('wu-legacy-admin-tabs', wu_get_asset('legacy-admin-tabs.css', 'css'), false, wu_get_version());
@ -463,35 +473,32 @@ class Discount_Code_Edit_Admin_Page extends Edit_Admin_Page {
);
foreach ($priorities as $priority => $callbacks) {
foreach ($callbacks as $id => $callable) {
$fields[$id] = array(
$fields[ $id ] = array(
'type' => 'html',
'classes' => 'wu--mt-2',
'content' => function() use ($callable) {
'content' => function () use ($callable) {
call_user_func($callable['function'], $this->get_object());
},
);
}
}
} // end foreach;
} // end foreach;
$this->add_fields_widget('legacy-options', array(
'title' => __('Legacy Options', 'wp-ultimo'),
'position' => 'normal',
'fields' => $fields,
'classes' => 'wu-legacy-options-panel',
'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(
'style' => 'margin-top: -5px;',
),
));
} // end handle_legacy_options;
$this->add_fields_widget(
'legacy-options',
array(
'title' => __('Legacy Options', 'wp-ultimo'),
'position' => 'normal',
'fields' => $fields,
'classes' => 'wu-legacy-options-panel',
'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(
'style' => 'margin-top: -5px;',
),
)
);
}
/**
* Register ajax forms that we use for discount code.
@ -504,11 +511,13 @@ class Discount_Code_Edit_Admin_Page extends Edit_Admin_Page {
* Delete Discount code - Confirmation modal
*/
add_filter('wu_data_json_success_delete_discount_code_modal', fn($data_json) => array(
'redirect_url' => wu_network_admin_url('wp-ultimo-discount-codes', array('deleted' => 1))
));
} // end register_forms;
add_filter(
'wu_data_json_success_delete_discount_code_modal',
fn($data_json) => array(
'redirect_url' => wu_network_admin_url('wp-ultimo-discount-codes', array('deleted' => 1)),
)
);
}
/**
* Filters the list table to return only relevant events.
@ -526,8 +535,7 @@ class Discount_Code_Edit_Admin_Page extends Edit_Admin_Page {
);
return array_merge($args, $extra_args);
} // end query_filter;
}
/**
* Returns the title of the page.
@ -538,8 +546,7 @@ class Discount_Code_Edit_Admin_Page extends Edit_Admin_Page {
public function get_title() {
return $this->edit ? __('Edit Discount Code', 'wp-ultimo') : __('Add new Discount Code', 'wp-ultimo');
} // end get_title;
}
/**
* Returns the title of menu for this page.
@ -550,8 +557,7 @@ class Discount_Code_Edit_Admin_Page extends Edit_Admin_Page {
public function get_menu_title() {
return __('Edit Discount Code', 'wp-ultimo');
} // end get_menu_title;
}
/**
* Returns the action links for that page.
@ -562,8 +568,7 @@ class Discount_Code_Edit_Admin_Page extends Edit_Admin_Page {
public function action_links() {
return array();
} // end action_links;
}
/**
* Returns the labels to be used on the admin page.
@ -584,8 +589,7 @@ class Discount_Code_Edit_Admin_Page extends Edit_Admin_Page {
'delete_button_label' => __('Delete Discount Code', 'wp-ultimo'),
'delete_description' => __('Be careful. This action is irreversible.', 'wp-ultimo'),
);
} // end get_labels;
}
/**
* Returns the object being edit at the moment.
@ -596,36 +600,29 @@ class Discount_Code_Edit_Admin_Page extends Edit_Admin_Page {
public function get_object() {
if ($this->object !== null) {
return $this->object;
} // end if;
}
if (isset($_GET['id'])) {
$item_id = wu_request('id', 0);
$item = wu_get_discount_code($item_id);
if (!$item) {
if ( ! $item) {
wp_redirect(wu_network_admin_url('wp-ultimo-discount_codes'));
exit;
} // end if;
}
$this->object = $item;
return $this->object;
}
} // end if;
$this->object = new Discount_Code;
$this->object = new Discount_Code();
return $this->object;
} // end get_object;
}
/**
* Discount_Codes have titles.
*
@ -634,8 +631,7 @@ class Discount_Code_Edit_Admin_Page extends Edit_Admin_Page {
public function has_title(): bool {
return true;
} // end has_title;
}
/**
* Should implement the processes necessary to save the changes made to the object.
@ -647,49 +643,37 @@ class Discount_Code_Edit_Admin_Page extends Edit_Admin_Page {
/*
* Set the recurring value to zero if the toggle is disabled.
*/
if (!wu_request('apply_to_renewals')) {
if ( ! wu_request('apply_to_renewals')) {
$_POST['apply_to_renewals'] = false;
} // end if;
}
/*
* Set the limit products value.
*/
if (!wu_request('limit_products')) {
if ( ! wu_request('limit_products')) {
$_POST['limit_products'] = false;
} // end if;
}
/*
* Set the setup fee value to zero if the toggle is disabled.
*/
if (!wu_request('apply_to_setup_fee')) {
if ( ! wu_request('apply_to_setup_fee')) {
$_POST['setup_fee_value'] = 0;
} // end if;
}
/**
* Unset dates to prevent invalid dates
*/
if (!wu_request('enable_date_start') || !wu_validate_date(wu_request('date_start'))) {
if ( ! wu_request('enable_date_start') || ! wu_validate_date(wu_request('date_start'))) {
$_POST['date_start'] = null;
}
} // end if;
if (!wu_request('enable_date_expiration') || !wu_validate_date(wu_request('date_expiration'))) {
if ( ! wu_request('enable_date_expiration') || ! wu_validate_date(wu_request('date_expiration'))) {
$_POST['date_expiration'] = null;
} // end if;
}
$_POST['code'] = trim((string) wu_request('code'));
parent::handle_save();
} // end handle_save;
} // end class Discount_Code_Edit_Admin_Page;
}
}

View File

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

View File

@ -12,7 +12,7 @@ namespace WP_Ultimo\Admin_Pages;
// Exit if accessed directly
defined('ABSPATH') || exit;
use \WP_Ultimo\Database\Domains\Domain_Stage;
use WP_Ultimo\Database\Domains\Domain_Stage;
/**
* WP Multisite WaaS Domain Edit/Add New Admin Page.
@ -93,8 +93,7 @@ class Domain_Edit_Admin_Page extends Edit_Admin_Page {
add_filter('wu_form_fields_delete_domain_modal', array($this, 'domain_extra_delete_fields'), 10, 2);
add_action('wu_after_delete_domain_modal', array($this, 'domain_after_delete_actions'));
} // end register_forms;
}
/**
* Adds the extra delete fields to the delete form.
@ -112,12 +111,10 @@ class Domain_Edit_Admin_Page extends Edit_Admin_Page {
$has_other_domains = false;
if ($is_primary_domain) {
$other_domains = \WP_Ultimo\Models\Domain::get_by_site($domain->get_blog_id());
$has_other_domains = is_countable($other_domains) ? count($other_domains) - 1 : false;
} // end if;
}
$custom_fields = array(
'set_domain_as_primary' => array(
@ -162,8 +159,7 @@ class Domain_Edit_Admin_Page extends Edit_Admin_Page {
);
return array_merge($custom_fields, $fields);
} // end domain_extra_delete_fields;
}
/**
* Adds the primary domain handling to the domain deletion.
@ -180,14 +176,11 @@ class Domain_Edit_Admin_Page extends Edit_Admin_Page {
$new_primary_domain = wu_get_domain($new_primary_domain_name);
if ($new_primary_domain) {
$new_primary_domain->set_primary_domain(true);
$new_primary_domain->save();
} // end if;
} // end domain_after_delete_actions;
}
}
/**
* Allow child classes to register widgets, if they need them.
@ -199,156 +192,178 @@ class Domain_Edit_Admin_Page extends Edit_Admin_Page {
parent::register_widgets();
$this->add_fields_widget('domain-url', array(
'title' => __('Domain URL', 'wp-ultimo'),
'position' => 'normal',
'after' => array($this, 'render_dns_widget'),
'fields' => array(
'domain' => array(
'type' => 'text-display',
'title' => __('Domain', 'wp-ultimo'),
'tooltip' => __('Editing an existing domain is not possible. If you want to make changes to this domain, first delete it, and then re-add the right domain.', 'wp-ultimo'),
'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(
'title' => __('Domain Options', 'wp-ultimo'),
'position' => 'normal',
'sections' => array(
'general' => array(
'title' => __('General', 'wp-ultimo'),
'desc' => __('General options for the domain.', 'wp-ultimo'),
'icon' => 'dashicons-wu-globe',
'state' => array(
'primary_domain' => $this->get_object()->is_primary_domain(),
$this->add_fields_widget(
'domain-url',
array(
'title' => __('Domain URL', 'wp-ultimo'),
'position' => 'normal',
'after' => array($this, 'render_dns_widget'),
'fields' => array(
'domain' => array(
'type' => 'text-display',
'title' => __('Domain', 'wp-ultimo'),
'tooltip' => __('Editing an existing domain is not possible. If you want to make changes to this domain, first delete it, and then re-add the right domain.', 'wp-ultimo'),
'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>',
),
'fields' => array(
'primary_domain' => array(
'type' => 'toggle',
'title' => __('Is Primary Domain?', 'wp-ultimo'),
'desc' => __('Set as the primary domain.', 'wp-ultimo'),
'tooltip' => __('Setting this as the primary domain will remove any other domain mapping marked as the primary domain for this site.', 'wp-ultimo'),
'value' => $this->get_object()->is_primary_domain(),
'html_attr' => array(
'v-model' => 'primary_domain',
),
),
)
);
$this->add_tabs_widget(
'options',
array(
'title' => __('Domain Options', 'wp-ultimo'),
'position' => 'normal',
'sections' => array(
'general' => array(
'title' => __('General', 'wp-ultimo'),
'desc' => __('General options for the domain.', 'wp-ultimo'),
'icon' => 'dashicons-wu-globe',
'state' => array(
'primary_domain' => $this->get_object()->is_primary_domain(),
),
'primary_note' => array(
'type' => 'note',
'desc' => __('By making this the primary domain, we will convert the previous primary domain for this site, if one exists, into an alias domain.', 'wp-ultimo'),
'wrapper_html_attr' => array(
'v-if' => "require('primary_domain', true)",
'fields' => array(
'primary_domain' => array(
'type' => 'toggle',
'title' => __('Is Primary Domain?', 'wp-ultimo'),
'desc' => __('Set as the primary domain.', 'wp-ultimo'),
'tooltip' => __('Setting this as the primary domain will remove any other domain mapping marked as the primary domain for this site.', 'wp-ultimo'),
'value' => $this->get_object()->is_primary_domain(),
'html_attr' => array(
'v-model' => 'primary_domain',
),
),
'primary_note' => array(
'type' => 'note',
'desc' => __('By making this the primary domain, we will convert the previous primary domain for this site, if one exists, into an alias domain.', 'wp-ultimo'),
'wrapper_html_attr' => array(
'v-if' => "require('primary_domain', true)",
),
),
'secure' => array(
'type' => 'toggle',
'title' => __('Is Secure?', 'wp-ultimo'),
'desc' => __('Force the load using HTTPS.', 'wp-ultimo'),
'value' => $this->get_object()->is_secure(),
),
),
'secure' => array(
'type' => 'toggle',
'title' => __('Is Secure?', 'wp-ultimo'),
'desc' => __('Force the load using HTTPS.', 'wp-ultimo'),
'value' => $this->get_object()->is_secure(),
),
),
),
),
));
)
);
$this->add_list_table_widget('sites', array(
'title' => __('Linked Site', 'wp-ultimo'),
'table' => new \WP_Ultimo\List_Tables\Memberships_Site_List_Table(),
'query_filter' => array($this, 'sites_query_filter'),
));
$this->add_list_table_widget(
'sites',
array(
'title' => __('Linked Site', 'wp-ultimo'),
'table' => new \WP_Ultimo\List_Tables\Memberships_Site_List_Table(),
'query_filter' => array($this, 'sites_query_filter'),
)
);
add_meta_box('wp-ultimo-domain-log', __('Domain Test Log', 'wp-ultimo'), array($this, 'render_log_widget'), get_current_screen()->id, 'normal', null);
$this->add_list_table_widget('events', array(
'title' => __('Events', 'wp-ultimo'),
'table' => new \WP_Ultimo\List_Tables\Inside_Events_List_Table(),
'query_filter' => array($this, 'query_filter'),
));
$this->add_list_table_widget(
'events',
array(
'title' => __('Events', 'wp-ultimo'),
'table' => new \WP_Ultimo\List_Tables\Inside_Events_List_Table(),
'query_filter' => array($this, 'query_filter'),
)
);
$this->add_save_widget('save', array(
'html_attr' => array(
'data-wu-app' => 'save',
'data-state' => wu_convert_to_state( array(
'stage' => $this->get_object()->get_stage(),
)),
),
'fields' => array(
'stage' => array(
'type' => 'select',
'title' => __('Stage', 'wp-ultimo'),
'placeholder' => __('Select Stage', 'wp-ultimo'),
'desc' => __('The stage in the checking lifecycle of this domain.', 'wp-ultimo'),
'options' => Domain_Stage::to_array(),
'value' => $this->get_object()->get_stage(),
'wrapper_html_attr' => array(
'v-cloak' => '1',
),
'html_attr' => array(
'@change' => 'window.wu_basic.stage = $event.target.value',
'v-model' => 'stage',
$this->add_save_widget(
'save',
array(
'html_attr' => array(
'data-wu-app' => 'save',
'data-state' => wu_convert_to_state(
array(
'stage' => $this->get_object()->get_stage(),
)
),
),
'blog_id' => array(
'type' => 'model',
'title' => __('Site', 'wp-ultimo'),
'placeholder' => __('Search Site...', 'wp-ultimo'),
'desc' => __('The target site of this domain.', 'wp-ultimo'),
'value' => $this->get_object()->get_blog_id(),
'tooltip' => '',
'html_attr' => array(
'data-model' => 'site',
'data-value-field' => 'blog_id',
'data-label-field' => 'title',
'data-search-field' => 'title',
'data-max-items' => 1,
'data-selected' => $this->get_object()->get_site() ? json_encode($this->get_object()->get_site()->to_search_results()) : '',
'fields' => array(
'stage' => array(
'type' => 'select',
'title' => __('Stage', 'wp-ultimo'),
'placeholder' => __('Select Stage', 'wp-ultimo'),
'desc' => __('The stage in the checking lifecycle of this domain.', 'wp-ultimo'),
'options' => Domain_Stage::to_array(),
'value' => $this->get_object()->get_stage(),
'wrapper_html_attr' => array(
'v-cloak' => '1',
),
'html_attr' => array(
'@change' => 'window.wu_basic.stage = $event.target.value',
'v-model' => 'stage',
),
),
'wrapper_html_attr' => array(
'v-cloak' => '1',
'blog_id' => array(
'type' => 'model',
'title' => __('Site', 'wp-ultimo'),
'placeholder' => __('Search Site...', 'wp-ultimo'),
'desc' => __('The target site of this domain.', 'wp-ultimo'),
'value' => $this->get_object()->get_blog_id(),
'tooltip' => '',
'html_attr' => array(
'data-model' => 'site',
'data-value-field' => 'blog_id',
'data-label-field' => 'title',
'data-search-field' => 'title',
'data-max-items' => 1,
'data-selected' => $this->get_object()->get_site() ? json_encode($this->get_object()->get_site()->to_search_results()) : '',
),
'wrapper_html_attr' => array(
'v-cloak' => '1',
),
),
),
),
));
)
);
$check_for_active_string = sprintf('%s.includes(stage)', json_encode(\WP_Ultimo\Models\Domain::INACTIVE_STAGES));
$this->add_fields_widget('basic', array(
'title' => __('Active', 'wp-ultimo'),
'html_attr' => array(
'data-wu-app' => 'basic',
'data-state' => wu_convert_to_state( array(
'stage' => $this->get_object()->get_stage(),
)),
),
'fields' => array(
'active' => array(
'type' => 'toggle',
'title' => __('Active', 'wp-ultimo'),
'desc' => __('Use this option to manually enable or disable this domain.', 'wp-ultimo'),
'value' => $this->get_object()->is_active(),
'html_attr' => array(
'v-cloak' => '1',
'v-bind:disabled' => $check_for_active_string,
),
'wrapper_html_attr' => array(
'v-bind:class' => "$check_for_active_string ? 'wu-cursor-not-allowed wu-opacity-75' : ''",
$this->add_fields_widget(
'basic',
array(
'title' => __('Active', 'wp-ultimo'),
'html_attr' => array(
'data-wu-app' => 'basic',
'data-state' => wu_convert_to_state(
array(
'stage' => $this->get_object()->get_stage(),
)
),
),
'fields' => array(
'active' => array(
'type' => 'toggle',
'title' => __('Active', 'wp-ultimo'),
'desc' => __('Use this option to manually enable or disable this domain.', 'wp-ultimo'),
'value' => $this->get_object()->is_active(),
'html_attr' => array(
'v-cloak' => '1',
'v-bind:disabled' => $check_for_active_string,
),
'wrapper_html_attr' => array(
'v-bind:class' => "$check_for_active_string ? 'wu-cursor-not-allowed wu-opacity-75' : ''",
),
),
'note' => array(
'type' => 'note',
'desc' => __('This domain has a domain stage that forces it to be inactive. Change the status to Ready or Ready (without SSL) to be able to control the active status directly.', 'wp-ultimo'),
'classes' => 'wu-p-2 wu-bg-red-100 wu-text-red-600 wu-rounded wu-w-full',
'wrapper_html_attr' => array(
'v-show' => $check_for_active_string,
'v-cloak' => '1',
),
'note' => array(
'type' => 'note',
'desc' => __('This domain has a domain stage that forces it to be inactive. Change the status to Ready or Ready (without SSL) to be able to control the active status directly.', 'wp-ultimo'),
'classes' => 'wu-p-2 wu-bg-red-100 wu-text-red-600 wu-rounded wu-w-full',
'wrapper_html_attr' => array(
'v-show' => $check_for_active_string,
'v-cloak' => '1',
),
),
),
),
));
} // end register_widgets;
)
);
}
/**
* Renders the DNS widget
@ -358,11 +373,13 @@ class Domain_Edit_Admin_Page extends Edit_Admin_Page {
*/
public function render_dns_widget() {
wu_get_template('domain/dns-table', array(
'domain' => $this->get_object(),
));
} // end render_dns_widget;
wu_get_template(
'domain/dns-table',
array(
'domain' => $this->get_object(),
)
);
}
/**
* Renders the DNS widget
@ -372,12 +389,14 @@ class Domain_Edit_Admin_Page extends Edit_Admin_Page {
*/
public function render_log_widget() {
wu_get_template('domain/log', array(
'domain' => $this->get_object(),
'log_path' => \WP_Ultimo\Logger::get_logs_folder(),
));
} // end render_log_widget;
wu_get_template(
'domain/log',
array(
'domain' => $this->get_object(),
'log_path' => \WP_Ultimo\Logger::get_logs_folder(),
)
);
}
/**
* Returns the title of the page.
@ -388,8 +407,7 @@ class Domain_Edit_Admin_Page extends Edit_Admin_Page {
public function get_title() {
return $this->edit ? __('Edit Domain', 'wp-ultimo') : __('Add new Domain', 'wp-ultimo');
} // end get_title;
}
/**
* Returns the title of menu for this page.
@ -400,8 +418,7 @@ class Domain_Edit_Admin_Page extends Edit_Admin_Page {
public function get_menu_title() {
return __('Edit Domain', 'wp-ultimo');
} // end get_menu_title;
}
/**
* Returns the action links for that page.
@ -412,8 +429,7 @@ class Domain_Edit_Admin_Page extends Edit_Admin_Page {
public function action_links() {
return array();
} // end action_links;
}
/**
* Returns the labels to be used on the admin page.
@ -434,8 +450,7 @@ class Domain_Edit_Admin_Page extends Edit_Admin_Page {
'delete_button_label' => __('Delete Domain', 'wp-ultimo'),
'delete_description' => __('Be careful. This action is irreversible.', 'wp-ultimo'),
);
} // end get_labels;
}
/**
* Filters the list table to return only relevant events.
@ -453,8 +468,7 @@ class Domain_Edit_Admin_Page extends Edit_Admin_Page {
);
return array_merge($args, $extra_args);
} // end query_filter;
}
/**
* Filters the list table to return only relevant sites.
@ -469,8 +483,7 @@ class Domain_Edit_Admin_Page extends Edit_Admin_Page {
$args['blog_id'] = $this->get_object()->get_site_id();
return $args;
} // end sites_query_filter;
}
/**
* Returns the object being edit at the moment.
@ -481,28 +494,23 @@ class Domain_Edit_Admin_Page extends Edit_Admin_Page {
public function get_object() {
if ($this->object !== null) {
return $this->object;
} // end if;
}
$item_id = wu_request('id', 0);
$item = wu_get_domain($item_id);
if (!$item) {
if ( ! $item) {
wp_redirect(wu_network_admin_url('wp-ultimo-domains'));
exit;
} // end if;
}
$this->object = $item;
return $this->object;
} // end get_object;
}
/**
* Domains have titles.
*
@ -511,8 +519,7 @@ class Domain_Edit_Admin_Page extends Edit_Admin_Page {
public function has_title(): bool {
return false;
} // end has_title;
}
/**
* Should implement the processes necessary to save the changes made to the object.
@ -522,28 +529,20 @@ class Domain_Edit_Admin_Page extends Edit_Admin_Page {
*/
public function handle_save() {
if (!wu_request('primary_domain')) {
if ( ! wu_request('primary_domain')) {
$_POST['primary_domain'] = false;
}
} // end if;
if (!wu_request('active')) {
if ( ! wu_request('active')) {
$_POST['active'] = false;
}
} // end if;
if (!wu_request('secure')) {
if ( ! wu_request('secure')) {
$_POST['secure'] = false;
} // end if;
}
wu_enqueue_async_action('wu_async_process_domain_stage', array('domain_id' => $this->get_object()->get_id()), 'domain');
parent::handle_save();
} // end handle_save;
} // end class Domain_Edit_Admin_Page;
}
}

View File

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

View File

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

View File

@ -12,8 +12,8 @@ namespace WP_Ultimo\Admin_Pages;
// Exit if accessed directly
defined('ABSPATH') || exit;
use \WP_Ultimo\Models\Email;
use \WP_Ultimo\Managers\Email_Manager;
use WP_Ultimo\Models\Email;
use WP_Ultimo\Managers\Email_Manager;
/**
* WP Multisite WaaS Email Edit/Add New Admin Page.
@ -96,8 +96,7 @@ class Email_Edit_Admin_Page extends Edit_Admin_Page {
parent::init();
add_action('wu_page_edit_redirect_handlers', array($this, 'handle_page_redirect'), 10);
} // end init;
}
/**
* Registers the necessary scripts.
@ -110,8 +109,7 @@ class Email_Edit_Admin_Page extends Edit_Admin_Page {
parent::register_scripts();
wp_enqueue_script('wu-email-edit-page', wu_get_asset('email-edit-page.js', 'js'), array('jquery', 'clipboard'));
} // end register_scripts;
}
/**
* Allow child classes to register widgets, if they need them.
@ -131,223 +129,235 @@ class Email_Edit_Admin_Page extends Edit_Admin_Page {
// translators: %1$s is replaced with the number of hours, %2$s is replaced with the number of minutes.
$hour_text = sprintf(__('Send %1$s hour(s) and %2$s minute(s) after the event.', 'wp-ultimo'), '{{ hours.split(":").shift() }}', '{{ hours.split(":").pop() }}');
$desc = sprintf('
<span v-show="schedule && schedule_type == \'days\'">%s</span>
<span v-show="schedule && schedule_type == \'hours\'">%s</span>
', $days_text, $hour_text);
$desc = sprintf(
'<span v-show="schedule && schedule_type == \'days\'">%s</span>
<span v-show="schedule && schedule_type == \'hours\'">%s</span>',
$days_text,
$hour_text
);
$this->add_save_widget('save', array(
'html_attr' => array(
'data-wu-app' => 'email_edit_save',
'data-state' => wu_convert_to_state(array(
'slug' => $this->edit ? $object->get_slug() : '',
'target' => $this->edit ? $object->get_target() : 'admin',
'schedule' => $this->edit ? $object->has_schedule() : false,
'schedule_type' => $this->edit ? $object->get_schedule_type() : 'days',
'days' => $this->edit ? $object->get_send_days() : 1,
'hours' => $this->edit ? $object->get_send_hours() : '12:00',
)),
),
'fields' => array(
'slug' => array(
'type' => 'text',
'title' => __('Slug', 'wp-ultimo'),
'desc' => __('An unique identifier for this system email.', 'wp-ultimo'),
'value' => $this->edit ? $object->get_slug() : '',
'html_attr' => array(
'required' => 'required',
'v-on:input' => 'slug = $event.target.value.toLowerCase().replace(/[^a-z0-9-_]+/g, "")',
'v-bind:value' => 'slug',
$this->add_save_widget(
'save',
array(
'html_attr' => array(
'data-wu-app' => 'email_edit_save',
'data-state' => wu_convert_to_state(
array(
'slug' => $this->edit ? $object->get_slug() : '',
'target' => $this->edit ? $object->get_target() : 'admin',
'schedule' => $this->edit ? $object->has_schedule() : false,
'schedule_type' => $this->edit ? $object->get_schedule_type() : 'days',
'days' => $this->edit ? $object->get_send_days() : 1,
'hours' => $this->edit ? $object->get_send_hours() : '12:00',
)
),
),
'event' => array(
'type' => 'select',
'title' => __('Event', 'wp-ultimo'),
'desc' => __('The event that will trigger the sending of this email.', 'wp-ultimo'),
'placeholder' => __('Event', 'wp-ultimo'),
'options' => 'wu_get_event_types_as_options',
'value' => $this->edit ? $object->get_event() : 0,
'html_attr' => array(
'name' => ''
),
),
'target' => array(
'type' => 'select',
'title' => __('Target', 'wp-ultimo'),
'desc' => __('To whom this email should be sent.', 'wp-ultimo'),
'placeholder' => __('Network Administrators', 'wp-ultimo'),
'value' => $this->edit ? $object->get_target() : 'admin',
'options' => array(
'admin' => __('Network Administrators', 'wp-ultimo'),
'customer' => __('Customer', 'wp-ultimo'),
),
'html_attr' => array(
'v-model' => 'target',
),
),
'send_copy_to_admin' => array(
'type' => 'toggle',
'title' => __('Send Copy to Admins?', 'wp-ultimo'),
'desc' => __('Checking this options will add the network admins as bcc every time this email is sent to a customer.', 'wp-ultimo'),
'value' => $this->edit ? $object->get_send_copy_to_admin() : false,
'wrapper_html_attr' => array(
'v-show' => 'target == "customer"',
'v-cloak' => 1,
),
),
'schedule' => array(
'type' => 'toggle',
'title' => __('Schedule?', 'wp-ultimo'),
'desc' => __('You can define when the email is sent after the event triggers.', 'wp-ultimo'),
'value' => $this->edit ? $this->get_object()->has_schedule() : 0,
'html_attr' => array(
'v-model' => 'schedule',
),
),
'send_date' => array(
'type' => 'group',
'title' => __('Scheduling Options', 'wp-ultimo'),
'tooltip' => __('When this email will be sent after the event?', 'wp-ultimo'),
'desc' => $desc,
'desc_id' => 'send_date_desc',
'wrapper_html_attr' => array(
'v-show' => 'schedule',
'v-cloak' => 1,
),
'fields' => array(
'schedule_type' => array(
'type' => 'select',
'default' => 'days',
'wrapper_classes' => 'wu-w-2/3',
'value' => $this->edit ? $object->get_schedule_type() : 'days',
'options' => array(
'hours' => __('Delay for hours', 'wp-ultimo'),
'days' => __('Delay for days', 'wp-ultimo'),
),
'html_attr' => array(
'v-model' => 'schedule_type',
),
'fields' => array(
'slug' => array(
'type' => 'text',
'title' => __('Slug', 'wp-ultimo'),
'desc' => __('An unique identifier for this system email.', 'wp-ultimo'),
'value' => $this->edit ? $object->get_slug() : '',
'html_attr' => array(
'required' => 'required',
'v-on:input' => 'slug = $event.target.value.toLowerCase().replace(/[^a-z0-9-_]+/g, "")',
'v-bind:value' => 'slug',
),
'send_days' => array(
'type' => 'number',
'value' => $this->edit && $object->get_send_days() ? $object->get_send_days() : 1,
'placeholder' => 1,
'min' => 0,
'wrapper_classes' => 'wu-ml-2 wu-w-1/3',
'wrapper_html_attr' => array(
'v-show' => "schedule_type == 'days'",
'v-cloak' => '1',
),
'html_attr' => array(
'v-model' => 'days',
),
),
'event' => array(
'type' => 'select',
'title' => __('Event', 'wp-ultimo'),
'desc' => __('The event that will trigger the sending of this email.', 'wp-ultimo'),
'placeholder' => __('Event', 'wp-ultimo'),
'options' => 'wu_get_event_types_as_options',
'value' => $this->edit ? $object->get_event() : 0,
'html_attr' => array(
'name' => '',
),
'send_hours' => array(
'type' => 'text',
'date' => true,
'placeholder' => $this->edit ? $object->get_send_hours() : '12:00',
'value' => $this->edit ? $object->get_send_hours() : '',
'wrapper_classes' => 'wu-ml-2 wu-w-1/3',
'html_attr' => array(
'data-no-calendar' => 'true',
'wu-datepicker' => 'true',
'data-format' => 'H:i',
'data-allow-time' => 'true',
'v-model' => 'hours',
),
'target' => array(
'type' => 'select',
'title' => __('Target', 'wp-ultimo'),
'desc' => __('To whom this email should be sent.', 'wp-ultimo'),
'placeholder' => __('Network Administrators', 'wp-ultimo'),
'value' => $this->edit ? $object->get_target() : 'admin',
'options' => array(
'admin' => __('Network Administrators', 'wp-ultimo'),
'customer' => __('Customer', 'wp-ultimo'),
),
'html_attr' => array(
'v-model' => 'target',
),
),
'send_copy_to_admin' => array(
'type' => 'toggle',
'title' => __('Send Copy to Admins?', 'wp-ultimo'),
'desc' => __('Checking this options will add the network admins as bcc every time this email is sent to a customer.', 'wp-ultimo'),
'value' => $this->edit ? $object->get_send_copy_to_admin() : false,
'wrapper_html_attr' => array(
'v-show' => 'target == "customer"',
'v-cloak' => 1,
),
),
'schedule' => array(
'type' => 'toggle',
'title' => __('Schedule?', 'wp-ultimo'),
'desc' => __('You can define when the email is sent after the event triggers.', 'wp-ultimo'),
'value' => $this->edit ? $this->get_object()->has_schedule() : 0,
'html_attr' => array(
'v-model' => 'schedule',
),
),
'send_date' => array(
'type' => 'group',
'title' => __('Scheduling Options', 'wp-ultimo'),
'tooltip' => __('When this email will be sent after the event?', 'wp-ultimo'),
'desc' => $desc,
'desc_id' => 'send_date_desc',
'wrapper_html_attr' => array(
'v-show' => 'schedule',
'v-cloak' => 1,
),
'fields' => array(
'schedule_type' => array(
'type' => 'select',
'default' => 'days',
'wrapper_classes' => 'wu-w-2/3',
'value' => $this->edit ? $object->get_schedule_type() : 'days',
'options' => array(
'hours' => __('Delay for hours', 'wp-ultimo'),
'days' => __('Delay for days', 'wp-ultimo'),
),
'html_attr' => array(
'v-model' => 'schedule_type',
),
),
'wrapper_html_attr' => array(
'v-show' => "schedule_type == 'hours'",
'v-cloak' => '1',
'send_days' => array(
'type' => 'number',
'value' => $this->edit && $object->get_send_days() ? $object->get_send_days() : 1,
'placeholder' => 1,
'min' => 0,
'wrapper_classes' => 'wu-ml-2 wu-w-1/3',
'wrapper_html_attr' => array(
'v-show' => "schedule_type == 'days'",
'v-cloak' => '1',
),
'html_attr' => array(
'v-model' => 'days',
),
),
'send_hours' => array(
'type' => 'text',
'date' => true,
'placeholder' => $this->edit ? $object->get_send_hours() : '12:00',
'value' => $this->edit ? $object->get_send_hours() : '',
'wrapper_classes' => 'wu-ml-2 wu-w-1/3',
'html_attr' => array(
'data-no-calendar' => 'true',
'wu-datepicker' => 'true',
'data-format' => 'H:i',
'data-allow-time' => 'true',
'v-model' => 'hours',
),
'wrapper_html_attr' => array(
'v-show' => "schedule_type == 'hours'",
'v-cloak' => '1',
),
),
),
),
),
),
));
),
)
);
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(
'title' => __('Active', 'wp-ultimo'),
'fields' => array(
'active' => array(
'type' => 'toggle',
'title' => __('Active', 'wp-ultimo'),
'desc' => __('Use this option to manually enable or disable this email.', 'wp-ultimo'),
'value' => $this->get_object()->is_active(),
),
),
));
$this->add_tabs_widget('email_edit_options', array(
'title' => __('Advanced Options', 'wp-ultimo'),
'position' => 'normal',
'sections' => array(
'general' => array(
'title' => __('General', 'wp-ultimo'),
'icon' => 'dashicons-wu-lock',
'desc' => __('Rules and limitations to the applicability of this discount code.', 'wp-ultimo'),
'state' => array(
'sender' => $this->edit ? $object->get_custom_sender() : 0,
),
'fields' => array(
'style' => array(
'type' => 'select',
'title' => __('Email Style', 'wp-ultimo'),
'desc' => __('Choose if email body will be sent using the HTML template or in plain text.', 'wp-ultimo'),
'placeholder' => __('Style', 'wp-ultimo'),
'options' => array(
'default' => __('Use Default', 'wp-ultimo'),
'html' => __('HTML Emails', 'wp-ultimo'),
'plain' => __('Plain Emails', 'wp-ultimo'),
),
'value' => $this->edit ? $object->get_style() : 'html',
),
$this->add_fields_widget(
'active',
array(
'title' => __('Active', 'wp-ultimo'),
'fields' => array(
'active' => array(
'type' => 'toggle',
'title' => __('Active', 'wp-ultimo'),
'desc' => __('Use this option to manually enable or disable this email.', 'wp-ultimo'),
'value' => $this->get_object()->is_active(),
),
),
'sender' => array(
'title' => __('Custom Sender', 'wp-ultimo'),
'icon' => 'dashicons-wu-mail',
'desc' => __('You can define an email and a name that will only be used when this email is sent.', 'wp-ultimo'),
'fields' => array(
'custom_sender' => array(
'type' => 'toggle',
'title' => __('Use a custom sender?', 'wp-ultimo'),
'desc' => __('You can define an email and a name that will only be used when this email is sent.', 'wp-ultimo'),
'value' => $this->edit ? $object->get_custom_sender() : 0,
'html_attr' => array(
'v-model' => 'sender',
),
),
'custom_sender_name' => array(
'type' => 'text',
'title' => __('From "Name"', 'wp-ultimo'),
'desc' => __('Override the global from name for this particular email.', 'wp-ultimo'),
'wrapper_classes' => 'wu-full',
'value' => $this->edit ? $object->get_custom_sender_name() : '',
'wrapper_html_attr' => array(
'v-show' => 'sender',
'v-cloak' => 1,
),
),
'custom_sender_email' => array(
'type' => 'email',
'title' => __('From "Email"', 'wp-ultimo'),
'desc' => __('Override the global from email for this particular email.', 'wp-ultimo'),
'wrapper_classes' => 'wu-full',
'value' => $this->edit ? $object->get_custom_sender_email() : '',
'wrapper_html_attr' => array(
'v-show' => 'sender',
'v-cloak' => 1,
),
),
),
)
)
));
);
} // end register_widgets;
$this->add_tabs_widget(
'email_edit_options',
array(
'title' => __('Advanced Options', 'wp-ultimo'),
'position' => 'normal',
'sections' => array(
'general' => array(
'title' => __('General', 'wp-ultimo'),
'icon' => 'dashicons-wu-lock',
'desc' => __('Rules and limitations to the applicability of this discount code.', 'wp-ultimo'),
'state' => array(
'sender' => $this->edit ? $object->get_custom_sender() : 0,
),
'fields' => array(
'style' => array(
'type' => 'select',
'title' => __('Email Style', 'wp-ultimo'),
'desc' => __('Choose if email body will be sent using the HTML template or in plain text.', 'wp-ultimo'),
'placeholder' => __('Style', 'wp-ultimo'),
'options' => array(
'default' => __('Use Default', 'wp-ultimo'),
'html' => __('HTML Emails', 'wp-ultimo'),
'plain' => __('Plain Emails', 'wp-ultimo'),
),
'value' => $this->edit ? $object->get_style() : 'html',
),
),
),
'sender' => array(
'title' => __('Custom Sender', 'wp-ultimo'),
'icon' => 'dashicons-wu-mail',
'desc' => __('You can define an email and a name that will only be used when this email is sent.', 'wp-ultimo'),
'fields' => array(
'custom_sender' => array(
'type' => 'toggle',
'title' => __('Use a custom sender?', 'wp-ultimo'),
'desc' => __('You can define an email and a name that will only be used when this email is sent.', 'wp-ultimo'),
'value' => $this->edit ? $object->get_custom_sender() : 0,
'html_attr' => array(
'v-model' => 'sender',
),
),
'custom_sender_name' => array(
'type' => 'text',
'title' => __('From "Name"', 'wp-ultimo'),
'desc' => __('Override the global from name for this particular email.', 'wp-ultimo'),
'wrapper_classes' => 'wu-full',
'value' => $this->edit ? $object->get_custom_sender_name() : '',
'wrapper_html_attr' => array(
'v-show' => 'sender',
'v-cloak' => 1,
),
),
'custom_sender_email' => array(
'type' => 'email',
'title' => __('From "Email"', 'wp-ultimo'),
'desc' => __('Override the global from email for this particular email.', 'wp-ultimo'),
'wrapper_classes' => 'wu-full',
'value' => $this->edit ? $object->get_custom_sender_email() : '',
'wrapper_html_attr' => array(
'v-show' => 'sender',
'v-cloak' => 1,
),
),
),
),
),
)
);
}
/**
* Outputs the block that shows the event payload placeholders.
@ -360,12 +370,14 @@ class Email_Edit_Admin_Page extends Edit_Admin_Page {
*/
public function output_default_widget_placeholders($unused, $data) {
wu_get_template('email/widget-placeholders', array(
'title' => __('Event Payload', 'wp-ultimo'),
'loading_text' => __('Loading Payload', 'wp-ultimo'),
));
} // end output_default_widget_placeholders;
wu_get_template(
'email/widget-placeholders',
array(
'title' => __('Event Payload', 'wp-ultimo'),
'loading_text' => __('Loading Payload', 'wp-ultimo'),
)
);
}
/**
* Returns the title of the page.
@ -376,8 +388,7 @@ class Email_Edit_Admin_Page extends Edit_Admin_Page {
public function get_title() {
return $this->edit ? __('Edit Email', 'wp-ultimo') : __('Add new Email', 'wp-ultimo');
} // end get_title;
}
/**
* Returns the title of menu for this page.
@ -388,8 +399,7 @@ class Email_Edit_Admin_Page extends Edit_Admin_Page {
public function get_menu_title() {
return __('Edit Email', 'wp-ultimo');
} // end get_menu_title;
}
/**
* Returns the action links for that page.
@ -402,7 +412,7 @@ class Email_Edit_Admin_Page extends Edit_Admin_Page {
$url_atts = array(
'id' => $this->get_object()->get_id(),
'model' => 'email',
'page' => 'edit'
'page' => 'edit',
);
$send_test_link = wu_get_form_url('send_new_test', $url_atts);
@ -417,11 +427,10 @@ class Email_Edit_Admin_Page extends Edit_Admin_Page {
'url' => $send_test_link,
'label' => __('Send Test Email', 'wp-ultimo'),
'icon' => 'wu-mail',
'classes' => 'wubox'
'classes' => 'wubox',
),
);
} // end action_links;
}
/**
* Returns the labels to be used on the admin page.
@ -442,8 +451,7 @@ class Email_Edit_Admin_Page extends Edit_Admin_Page {
'delete_button_label' => __('Delete Email', 'wp-ultimo'),
'delete_description' => __('Be careful. This action is irreversible.', 'wp-ultimo'),
);
} // end get_labels;
}
/**
* Filters the list table to return only relevant events.
@ -461,8 +469,7 @@ class Email_Edit_Admin_Page extends Edit_Admin_Page {
);
return array_merge($args, $extra_args);
} // end query_filter;
}
/**
* Handles the toggles.
@ -479,8 +486,7 @@ class Email_Edit_Admin_Page extends Edit_Admin_Page {
$_POST['custom_sender'] = wu_request('custom_sender');
parent::handle_save();
} // end handle_save;
}
/**
* Handles the redirect notice from sent new test modal.
@ -491,9 +497,7 @@ class Email_Edit_Admin_Page extends Edit_Admin_Page {
public function handle_page_redirect($page) {
if ($page->get_id() === 'wp-ultimo-edit-email') {
if (wu_request('test_notice')) {
$test_notice = wu_request('test_notice');
?>
@ -506,11 +510,9 @@ class Email_Edit_Admin_Page extends Edit_Admin_Page {
<?php
} // end if;
} // end if;
} // end handle_page_redirect;
}
}
}
/**
* Returns the object being edit at the moment.
@ -521,26 +523,21 @@ class Email_Edit_Admin_Page extends Edit_Admin_Page {
public function get_object() {
if (isset($_GET['id'])) {
$query = new \WP_Ultimo\Database\Emails\Email_Query;
$query = new \WP_Ultimo\Database\Emails\Email_Query();
$item = $query->get_item_by('id', $_GET['id']);
if (!$item) {
if (! $item) {
wp_redirect(wu_network_admin_url('wp-ultimo-emails'));
exit;
} // end if;
}
return $item;
}
} // end if;
return new Email;
} // end get_object;
return new Email();
}
/**
* Emails have titles.
*
@ -549,8 +546,7 @@ class Email_Edit_Admin_Page extends Edit_Admin_Page {
public function has_title(): bool {
return true;
} // end has_title;
}
/**
* Wether or not this pages should have an editor field.
*
@ -559,8 +555,7 @@ class Email_Edit_Admin_Page extends Edit_Admin_Page {
public function has_editor(): bool {
return true;
} // end has_editor;
}
/**
* Filters the list table to return only relevant events.
@ -578,7 +573,5 @@ class Email_Edit_Admin_Page extends Edit_Admin_Page {
);
return array_merge($args, $extra_args);
} // end events_query_filter;
} // end class Email_Edit_Admin_Page;
}
}

View File

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

View File

@ -81,8 +81,7 @@ class Email_Template_Customize_Admin_Page extends Customizer_Admin_Page {
parent::init();
add_action('wp_ajax_wu-email-template-preview', array($this, 'email_template_preview'));
} // end init;
}
/**
* Return the page object
@ -94,8 +93,7 @@ class Email_Template_Customize_Admin_Page extends Customizer_Admin_Page {
public function get_object() {
return $this;
} // end get_object;
}
/**
* Renders the preview of a given form being customized.
@ -107,12 +105,12 @@ class Email_Template_Customize_Admin_Page extends Customizer_Admin_Page {
$object = $this;
$content = wpautop('
$content = wpautop(
'
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam nulla diam, iaculis sit amet tellus sit amet, tempus hendrerit risus. Proin elementum aliquet lorem ut cursus. Ut varius pharetra magna, eu malesuada metus feugiat id. Aenean cursus purus et massa commodo pretium id ut erat. Suspendisse erat odio, auctor ac elit eget, rhoncus iaculis nulla. Aliquam turpis leo, egestas eget dui a, imperdiet ullamcorper felis. Suspendisse ut lacinia mauris.
Phasellus vitae diam euismod diam tristique faucibus. Proin gravida, augue in molestie porttitor, orci justo aliquam mauris, et commodo mauris nisi vitae tortor. Mauris vulputate fringilla purus et finibus. Duis lacus turpis, tincidunt vel dui ac, fermentum aliquet dolor. Donec auctor tristique consequat. In pharetra lacus quis mi dictum, ut dapibus eros bibendum. Donec tristique nibh ac sem bibendum, at feugiat turpis molestie. Suspendisse eget eleifend nunc. Sed tempor varius nisi non tincidunt. Sed leo arcu, feugiat dapibus sollicitudin a, tincidunt eu ligula. Nam ut arcu id arcu auctor vulputate non molestie quam. Nunc non diam mauris. Praesent erat est, posuere sit amet hendrerit non, molestie eget sem. Cras ac tempor est.'
);
$content .= '<table cellpadding="0" cellspacing="0" style="width:100%; font-family:Roboto,HelveticaNeue,sans-serif; font-size: 15px">
@ -149,37 +147,39 @@ class Email_Template_Customize_Admin_Page extends Customizer_Admin_Page {
/*
* use arbitrary field to determine if this is the first request for the preview.
*/
$first_request = !wu_request('background_color');
$first_request = ! wu_request('background_color');
wu_get_template('broadcast/emails/base', array(
'site_name' => get_network_option(null, 'site_name'),
'site_url' => get_site_url(),
'logo_url' => wu_get_network_logo(),
'content' => $content,
'subject' => __('Sample Subject', 'wp-ultimo'),
'is_editor' => true,
'template_settings' => array(
'use_custom_logo' => wu_string_to_bool(wu_request('use_custom_logo', $first_request ? $object->get_setting('use_custom_logo', false) : false)),
'custom_logo' => wu_request('custom_logo', $object->get_setting('custom_logo', false)),
'background_color' => wu_request('background_color', $object->get_setting('background_color', '#f9f9f9')),
'title_color' => wu_request('title_color', $object->get_setting('title_color', '#000000')),
'title_size' => wu_request('title_size', $object->get_setting('title_size', 'h3')),
'title_align' => wu_request('title_align', $object->get_setting('title_align', 'center')),
'title_font' => wu_request('title_font', $object->get_setting('title_font', 'Helvetica Neue, Helvetica, Helvetica, Arial, sans-serif')),
'content_color' => wu_request('content_color', $object->get_setting('content_color', '#000000')),
'content_align' => wu_request('content_align', $object->get_setting('content_align', 'left')),
'content_font' => wu_request('content_font', $object->get_setting('content_font', 'Helvetica Neue, Helvetica, Helvetica, Arial, sans-serif')),
'footer_text' => wu_request('footer_text', $object->get_setting('footer_text', '')),
'footer_font' => wu_request('footer_font', $object->get_setting('footer_font', 'Helvetica Neue, Helvetica, Helvetica, Arial, sans-serif')),
'footer_color' => wu_request('footer_color', $object->get_setting('footer_color', '#000000')),
'footer_align' => wu_request('footer_align', $object->get_setting('footer_align', 'center')),
'display_company_address' => wu_string_to_bool(wu_request('display_company_address', $first_request ? $object->get_setting('display_company_address', true) : false)),
wu_get_template(
'broadcast/emails/base',
array(
'site_name' => get_network_option(null, 'site_name'),
'site_url' => get_site_url(),
'logo_url' => wu_get_network_logo(),
'content' => $content,
'subject' => __('Sample Subject', 'wp-ultimo'),
'is_editor' => true,
'template_settings' => array(
'use_custom_logo' => wu_string_to_bool(wu_request('use_custom_logo', $first_request ? $object->get_setting('use_custom_logo', false) : false)),
'custom_logo' => wu_request('custom_logo', $object->get_setting('custom_logo', false)),
'background_color' => wu_request('background_color', $object->get_setting('background_color', '#f9f9f9')),
'title_color' => wu_request('title_color', $object->get_setting('title_color', '#000000')),
'title_size' => wu_request('title_size', $object->get_setting('title_size', 'h3')),
'title_align' => wu_request('title_align', $object->get_setting('title_align', 'center')),
'title_font' => wu_request('title_font', $object->get_setting('title_font', 'Helvetica Neue, Helvetica, Helvetica, Arial, sans-serif')),
'content_color' => wu_request('content_color', $object->get_setting('content_color', '#000000')),
'content_align' => wu_request('content_align', $object->get_setting('content_align', 'left')),
'content_font' => wu_request('content_font', $object->get_setting('content_font', 'Helvetica Neue, Helvetica, Helvetica, Arial, sans-serif')),
'footer_text' => wu_request('footer_text', $object->get_setting('footer_text', '')),
'footer_font' => wu_request('footer_font', $object->get_setting('footer_font', 'Helvetica Neue, Helvetica, Helvetica, Arial, sans-serif')),
'footer_color' => wu_request('footer_color', $object->get_setting('footer_color', '#000000')),
'footer_align' => wu_request('footer_align', $object->get_setting('footer_align', 'center')),
'display_company_address' => wu_string_to_bool(wu_request('display_company_address', $first_request ? $object->get_setting('display_company_address', true) : false)),
),
)
));
);
die;
} // end email_template_preview;
}
/**
* Returns the preview URL. This is then added to the iframe.
@ -191,12 +191,14 @@ class Email_Template_Customize_Admin_Page extends Customizer_Admin_Page {
$url = get_admin_url(wu_get_main_site_id(), 'admin-ajax.php');
return add_query_arg(array(
'action' => 'wu-email-template-preview',
'customizer' => 1,
), $url);
} // end get_preview_url;
return add_query_arg(
array(
'action' => 'wu-email-template-preview',
'customizer' => 1,
),
$url
);
}
/**
* Allow child classes to register widgets, if they need them.
@ -206,18 +208,21 @@ class Email_Template_Customize_Admin_Page extends Customizer_Admin_Page {
*/
public function register_widgets() {
$this->add_save_widget('save', array(
'html_attr' => array(
'data-wu-app' => 'save',
'data-state' => wu_convert_to_state(),
),
'fields' => array(
'note' => array(
'type' => 'note',
'desc' => __('System emails and broadcasts will be sent using this template.', 'wp-ultimo'),
$this->add_save_widget(
'save',
array(
'html_attr' => array(
'data-wu-app' => 'save',
'data-state' => wu_convert_to_state(),
),
'fields' => array(
'note' => array(
'type' => 'note',
'desc' => __('System emails and broadcasts will be sent using this template.', 'wp-ultimo'),
),
),
)
));
);
$settings = $this->get_attributes();
@ -473,24 +478,29 @@ class Email_Template_Customize_Admin_Page extends Customizer_Admin_Page {
),
);
$state = array_merge($settings, array(
'tab' => 'header',
'refresh' => true,
));
$state = array_merge(
$settings,
array(
'tab' => 'header',
'refresh' => true,
)
);
$this->add_fields_widget('customizer', array(
'title' => __('Customizer', 'wp-ultimo'),
'position' => 'side',
'fields' => $fields,
'html_attr' => array(
'style' => 'margin-top: -6px;',
'data-wu-app' => 'email_template_customizer',
'data-wu-customizer-panel' => true,
'data-state' => json_encode($state),
),
));
} // end register_widgets;
$this->add_fields_widget(
'customizer',
array(
'title' => __('Customizer', 'wp-ultimo'),
'position' => 'side',
'fields' => $fields,
'html_attr' => array(
'style' => 'margin-top: -6px;',
'data-wu-app' => 'email_template_customizer',
'data-wu-customizer-panel' => true,
'data-state' => json_encode($state),
),
)
);
}
/**
* Returns the title of the page.
@ -501,8 +511,7 @@ class Email_Template_Customize_Admin_Page extends Customizer_Admin_Page {
public function get_title() {
return __('Customize Email Template:', 'wp-ultimo');
} // end get_title;
}
/**
* Returns the title of menu for this page.
@ -513,8 +522,7 @@ class Email_Template_Customize_Admin_Page extends Customizer_Admin_Page {
public function get_menu_title() {
return __('Customize Email Template', 'wp-ultimo');
} // end get_menu_title;
}
/**
* Returns the action links for that page.
@ -525,8 +533,7 @@ class Email_Template_Customize_Admin_Page extends Customizer_Admin_Page {
public function action_links() {
return array();
} // end action_links;
}
/**
* Returns the labels to be used on the admin page.
@ -548,8 +555,7 @@ class Email_Template_Customize_Admin_Page extends Customizer_Admin_Page {
'delete_button_label' => __('Delete Email Template', 'wp-ultimo'),
'delete_description' => __('Be careful. This action is irreversible.', 'wp-ultimo'),
);
} // end get_labels;
}
/**
* Should implement the processes necessary to save the changes made to the object.
@ -574,8 +580,7 @@ class Email_Template_Customize_Admin_Page extends Customizer_Admin_Page {
wp_redirect($url);
exit;
} // end handle_save;
}
/**
* Get the value of attributes.
@ -590,8 +595,7 @@ class Email_Template_Customize_Admin_Page extends Customizer_Admin_Page {
$attributes = wp_parse_args($saved_atts, $this->get_default_settings());
return $attributes;
} // end get_attributes;
}
/**
* Gets the default email template settings.
@ -618,8 +622,7 @@ class Email_Template_Customize_Admin_Page extends Customizer_Admin_Page {
'footer_color' => '#000000',
'footer_align' => 'center',
);
} // end get_default_settings;
}
/**
* Returns the list of saved settings to customize the email template.
@ -631,8 +634,7 @@ class Email_Template_Customize_Admin_Page extends Customizer_Admin_Page {
public static function get_settings() {
return wu_get_option('email_template', array());
} // end get_settings;
}
/**
* Returns a specitic email template setting.
@ -646,24 +648,17 @@ class Email_Template_Customize_Admin_Page extends Customizer_Admin_Page {
public function get_setting($setting, $default = false) {
if ($setting) {
$return = wu_get_option('email_template', array());
if ($return && isset($return[$setting])) {
$return = $return[$setting];
if ($return && isset($return[ $setting ])) {
$return = $return[ $setting ];
} else {
$return = $default;
} // end if;
}
return $return;
} // end if;
} // end get_setting;
}
}
/**
* Save settings.
@ -678,17 +673,11 @@ class Email_Template_Customize_Admin_Page extends Customizer_Admin_Page {
$allowed_keys = $this->get_attributes();
foreach ($settings_to_save as $setting_to_save => $value) {
if (!array_key_exists($setting_to_save, $allowed_keys)) {
unset($settings_to_save[$setting_to_save]);
} // end if;
} // end foreach;
if ( ! array_key_exists($setting_to_save, $allowed_keys)) {
unset($settings_to_save[ $setting_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;
use \WP_Ultimo\Models\Event;
use WP_Ultimo\Models\Event;
// Exit if accessed directly
defined('ABSPATH') || exit;
@ -65,8 +65,7 @@ class Event_List_Admin_Page extends List_Admin_Page {
public function init() {
add_action('init', array($this, 'set_badge_count'));
} // end init;
}
/**
* Adds hooks when the page loads.
@ -79,8 +78,7 @@ class Event_List_Admin_Page extends List_Admin_Page {
parent::page_loaded();
add_action('in_admin_header', array($this, 'count_seen_events'));
} // end page_loaded;
}
/**
* Sets events badge notification subtracting the total number of events from the seen events in the user meta.
@ -97,12 +95,10 @@ class Event_List_Admin_Page extends List_Admin_Page {
$cache = get_site_transient("wu_{$user_id}_unseen_events_count");
if ($cache) {
$this->badge_count = $cache;
return;
} // end if;
}
$table_name = "{$wpdb->base_prefix}wu_events";
@ -115,8 +111,7 @@ class Event_List_Admin_Page extends List_Admin_Page {
$this->badge_count = $unseen;
set_site_transient("wu_{$user_id}_unseen_events_count", $unseen, 5 * MINUTE_IN_SECONDS);
} // end set_badge_count;
}
/**
* Sets the seen events in the current user meta.
@ -130,24 +125,23 @@ class Event_List_Admin_Page extends List_Admin_Page {
delete_site_transient("wu_{$user_id}_unseen_events_count");
$last_event = wu_get_events(array(
'orderby' => 'id',
'fields' => 'ids',
'order' => 'DESC',
'number' => 1,
));
if (!empty($last_event)) {
$last_event = wu_get_events(
array(
'orderby' => 'id',
'fields' => 'ids',
'order' => 'DESC',
'number' => 1,
)
);
if ( ! empty($last_event)) {
$last_event_id = current($last_event);
update_user_meta($user_id, 'wu_seen_events', $last_event_id);
} // end if;
}
$this->badge_count = '';
} // end count_seen_events;
}
/**
* Allow child classes to register widgets, if they need them.
@ -155,7 +149,7 @@ class Event_List_Admin_Page extends List_Admin_Page {
* @since 1.8.2
* @return void
*/
public function register_widgets() {} // end register_widgets;
public function register_widgets() {}
/**
* Returns an array with the labels for the edit page.
@ -169,8 +163,7 @@ class Event_List_Admin_Page extends List_Admin_Page {
'deleted_message' => __('Event removed successfully.', 'wp-ultimo'),
'search_label' => __('Search Event', 'wp-ultimo'),
);
} // end get_labels;
}
/**
* Returns the title of the page.
@ -181,8 +174,7 @@ class Event_List_Admin_Page extends List_Admin_Page {
public function get_title() {
return __('Events', 'wp-ultimo');
} // end get_title;
}
/**
* Returns the title of menu for this page.
@ -193,8 +185,7 @@ class Event_List_Admin_Page extends List_Admin_Page {
public function get_menu_title() {
return __('Events', 'wp-ultimo');
} // end get_menu_title;
}
/**
* Allows admins to rename the sub-menu (first item) for a top-level page.
@ -205,8 +196,7 @@ class Event_List_Admin_Page extends List_Admin_Page {
public function get_submenu_title() {
return __('Events', 'wp-ultimo');
} // end get_submenu_title;
}
/**
* Returns the action links for that page.
@ -223,8 +213,7 @@ class Event_List_Admin_Page extends List_Admin_Page {
'icon' => 'dashicons dashicons-editor-ol',
),
);
} // end action_links;
}
/**
* Loads the list table for this particular page.
@ -235,7 +224,5 @@ class Event_List_Admin_Page extends List_Admin_Page {
public function table() {
return new \WP_Ultimo\List_Tables\Event_List_Table();
} // end table;
} // end class Event_List_Admin_Page;
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

File diff suppressed because it is too large Load Diff

View File

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

View File

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

File diff suppressed because it is too large Load Diff

View File

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

View File

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

File diff suppressed because it is too large Load Diff

View File

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

View File

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

View File

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

View File

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

View File

@ -12,8 +12,8 @@ namespace WP_Ultimo\Admin_Pages;
// Exit if accessed directly
defined('ABSPATH') || exit;
use \WP_Ultimo\Database\Sites\Site_Type;
use \WP_Ultimo\Models\Site;
use WP_Ultimo\Database\Sites\Site_Type;
use WP_Ultimo\Models\Site;
/**
* WP Multisite WaaS Site Edit New Admin Page.
@ -98,8 +98,7 @@ class Site_Edit_Admin_Page extends Edit_Admin_Page {
wp_enqueue_media();
wp_enqueue_editor();
} // end register_scripts;
}
/**
* Register ajax forms that we use for site.
@ -111,23 +110,28 @@ class Site_Edit_Admin_Page extends Edit_Admin_Page {
/*
* Transfer site - Confirmation modal
*/
wu_register_form('transfer_site', array(
'render' => array($this, 'render_transfer_site_modal'),
'handler' => array($this, 'handle_transfer_site_modal'),
'capability' => 'wu_transfer_sites',
));
wu_register_form(
'transfer_site',
array(
'render' => array($this, 'render_transfer_site_modal'),
'handler' => array($this, 'handle_transfer_site_modal'),
'capability' => 'wu_transfer_sites',
)
);
/*
* Delete Site - Confirmation modal
*/
add_filter('wu_data_json_success_delete_site_modal', fn($data_json) => array(
'redirect_url' => wu_network_admin_url('wp-ultimo-sites', array('deleted' => 1))
));
add_filter(
'wu_data_json_success_delete_site_modal',
fn($data_json) => array(
'redirect_url' => wu_network_admin_url('wp-ultimo-sites', array('deleted' => 1)),
)
);
add_filter("wu_page_{$this->id}_load", array($this, 'add_new_site_template_warning_message'));
} // end register_forms;
}
/**
* Adds the new site_template warning.
@ -138,39 +142,37 @@ class Site_Edit_Admin_Page extends Edit_Admin_Page {
public function add_new_site_template_warning_message() {
if (wu_request('wu-new-model')) {
if (!$this->get_object() || $this->get_object()->get_type() !== Site_Type::SITE_TEMPLATE) {
if ( ! $this->get_object() || $this->get_object()->get_type() !== Site_Type::SITE_TEMPLATE) {
return;
}
} // end if;
\WP_Ultimo\UI\Tours::get_instance()->create_tour('new_site_template_warning', array(
\WP_Ultimo\UI\Tours::get_instance()->create_tour(
'new_site_template_warning',
array(
'id' => 'new-site-template-warning',
'title' => __('On adding a new Site Template...', 'wp-ultimo'),
'text' => array(
__("You just successfully added a new site template to your WP Multisite WaaS network and that's awesome!", 'wp-ultimo'),
__('Keep in mind that newly created site templates do not appear automatically in your checkout forms.', 'wp-ultimo'),
__('To make a site template available on registration, you will need to manually add it to the template selection field of your checkout forms.', 'wp-ultimo'),
array(
'id' => 'new-site-template-warning',
'title' => __('On adding a new Site Template...', 'wp-ultimo'),
'text' => array(
__("You just successfully added a new site template to your WP Multisite WaaS network and that's awesome!", 'wp-ultimo'),
__('Keep in mind that newly created site templates do not appear automatically in your checkout forms.', 'wp-ultimo'),
__('To make a site template available on registration, you will need to manually add it to the template selection field of your checkout forms.', 'wp-ultimo'),
),
'buttons' => array(
array(
'classes' => 'button wu-text-xs sm:wu-normal-case wu-float-left',
'text' => __('Go to Checkout Forms', 'wp-ultimo'),
'url' => wu_network_admin_url('wp-ultimo-checkout-forms'),
),
),
'attachTo' => array(
'element' => '#message.updated',
'on' => 'top',
),
),
'buttons' => array(
array(
'classes' => 'button wu-text-xs sm:wu-normal-case wu-float-left',
'text' => __('Go to Checkout Forms', 'wp-ultimo'),
'url' => wu_network_admin_url('wp-ultimo-checkout-forms'),
)
),
'attachTo' => array(
'element' => '#message.updated',
'on' => 'top',
),
),
));
} // end if;
} // end add_new_site_template_warning_message;
)
);
}
}
/**
* Renders the transfer confirmation form.
@ -182,11 +184,9 @@ class Site_Edit_Admin_Page extends Edit_Admin_Page {
$site = wu_get_site(wu_request('id'));
if (!$site) {
if ( ! $site) {
return;
} // end if;
}
$fields = array(
'confirm' => array(
@ -218,21 +218,26 @@ class Site_Edit_Admin_Page extends Edit_Admin_Page {
),
);
$form = new \WP_Ultimo\UI\Form('total-actions', $fields, array(
'views' => 'admin-pages/fields',
'classes' => 'wu-modal-form wu-widget-list wu-striped wu-m-0 wu-mt-0',
'field_wrapper_classes' => 'wu-w-full wu-box-border wu-items-center wu-flex wu-justify-between wu-p-4 wu-m-0 wu-border-t wu-border-l-0 wu-border-r-0 wu-border-b-0 wu-border-gray-300 wu-border-solid',
'html_attr' => array(
'data-wu-app' => 'transfer_site',
'data-state' => json_encode(array(
'confirmed' => false,
)),
),
));
$form = new \WP_Ultimo\UI\Form(
'total-actions',
$fields,
array(
'views' => 'admin-pages/fields',
'classes' => 'wu-modal-form wu-widget-list wu-striped wu-m-0 wu-mt-0',
'field_wrapper_classes' => 'wu-w-full wu-box-border wu-items-center wu-flex wu-justify-between wu-p-4 wu-m-0 wu-border-t wu-border-l-0 wu-border-r-0 wu-border-b-0 wu-border-gray-300 wu-border-solid',
'html_attr' => array(
'data-wu-app' => 'transfer_site',
'data-state' => json_encode(
array(
'confirmed' => false,
)
),
),
)
);
$form->render();
} // end render_transfer_site_modal;
}
/**
* Handles the transfer of site.
@ -248,17 +253,13 @@ class Site_Edit_Admin_Page extends Edit_Admin_Page {
$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')));
}
} // end if;
if (!$target_membership) {
if ( ! $target_membership) {
wp_send_json_error(new \WP_Error('not-found', __('Membership not found.', 'wp-ultimo')));
} // end if;
}
$site->set_membership_id($target_membership->get_id());
@ -269,19 +270,21 @@ class Site_Edit_Admin_Page extends Edit_Admin_Page {
$saved = $site->save();
if (is_wp_error($saved)) {
wp_send_json_error($saved);
}
} // end if;
wp_send_json_success(array(
'redirect_url' => wu_network_admin_url('wp-ultimo-edit-site', array(
'id' => $site->get_id(),
'updated' => 1,
))
));
} // end handle_transfer_site_modal;
wp_send_json_success(
array(
'redirect_url' => wu_network_admin_url(
'wp-ultimo-edit-site',
array(
'id' => $site->get_id(),
'updated' => 1,
)
),
)
);
}
/**
* Allow child classes to register widgets, if they need them.
@ -299,261 +302,291 @@ class Site_Edit_Admin_Page extends Edit_Admin_Page {
$tag = "<span class='wu-bg-gray-200 wu-py-1 wu-px-2 wu-rounded-sm wu-text-xs wu-font-mono $class'>{$label}</span>";
$this->add_fields_widget('at_a_glance', array(
'title' => __('At a Glance', 'wp-ultimo'),
'position' => 'normal',
'classes' => 'wu-overflow-hidden wu-m-0 wu--mt-1 wu--mx-3 wu--mb-3',
'field_wrapper_classes' => 'wu-w-1/4 wu-box-border wu-items-center wu-flex wu-justify-between wu-p-4 wu-m-0 wu-border-t-0 wu-border-l-0 wu-border-r wu-border-b-0 wu-border-gray-300 wu-border-solid wu-float-left wu-relative',
'html_attr' => array(
'style' => 'margin-top: -6px;',
),
'fields' => array(
'type' => array(
'type' => 'text-display',
'title' => __('Site Type', 'wp-ultimo'),
'display_value' => $tag,
'tooltip' => '',
$this->add_fields_widget(
'at_a_glance',
array(
'title' => __('At a Glance', 'wp-ultimo'),
'position' => 'normal',
'classes' => 'wu-overflow-hidden wu-m-0 wu--mt-1 wu--mx-3 wu--mb-3',
'field_wrapper_classes' => 'wu-w-1/4 wu-box-border wu-items-center wu-flex wu-justify-between wu-p-4 wu-m-0 wu-border-t-0 wu-border-l-0 wu-border-r wu-border-b-0 wu-border-gray-300 wu-border-solid wu-float-left wu-relative',
'html_attr' => array(
'style' => 'margin-top: -6px;',
),
'id' => array(
'type' => 'text-display',
'copy' => true,
'title' => __('Site ID', 'wp-ultimo'),
'display_value' => $this->get_object()->get_id(),
'tooltip' => '',
),
),
));
$this->add_fields_widget('description', array(
'title' => __('Description', 'wp-ultimo'),
'position' => 'normal',
'fields' => array(
'description' => array(
'type' => 'textarea',
'title' => __('Site Description', 'wp-ultimo'),
'placeholder' => __('Tell your customers what this site is about.', 'wp-ultimo'),
'value' => $this->get_object()->get_option_blogdescription(),
'html_attr' => array(
'rows' => 3,
'fields' => array(
'type' => array(
'type' => 'text-display',
'title' => __('Site Type', 'wp-ultimo'),
'display_value' => $tag,
'tooltip' => '',
),
'id' => array(
'type' => 'text-display',
'copy' => true,
'title' => __('Site ID', 'wp-ultimo'),
'display_value' => $this->get_object()->get_id(),
'tooltip' => '',
),
),
),
));
)
);
$this->add_tabs_widget('options', array(
'title' => __('Site Options', 'wp-ultimo'),
'position' => 'normal',
'sections' => $this->get_site_option_sections(),
));
$this->add_fields_widget(
'description',
array(
'title' => __('Description', 'wp-ultimo'),
'position' => 'normal',
'fields' => array(
'description' => array(
'type' => 'textarea',
'title' => __('Site Description', 'wp-ultimo'),
'placeholder' => __('Tell your customers what this site is about.', 'wp-ultimo'),
'value' => $this->get_object()->get_option_blogdescription(),
'html_attr' => array(
'rows' => 3,
),
),
),
)
);
$this->add_list_table_widget('domains', array(
'title' => __('Mapped Domains', 'wp-ultimo'),
'table' => new \WP_Ultimo\List_Tables\Sites_Domain_List_Table(),
'query_filter' => array($this, 'domain_query_filter'),
));
$this->add_tabs_widget(
'options',
array(
'title' => __('Site Options', 'wp-ultimo'),
'position' => 'normal',
'sections' => $this->get_site_option_sections(),
)
);
$this->add_list_table_widget(
'domains',
array(
'title' => __('Mapped Domains', 'wp-ultimo'),
'table' => new \WP_Ultimo\List_Tables\Sites_Domain_List_Table(),
'query_filter' => array($this, 'domain_query_filter'),
)
);
if ($this->get_object()->get_type() === 'customer_owned') {
$this->add_list_table_widget(
'membership',
array(
'title' => __('Linked Membership', 'wp-ultimo'),
'table' => new \WP_Ultimo\List_Tables\Customers_Membership_List_Table(),
'query_filter' => function ($query) {
$this->add_list_table_widget('membership', array(
'title' => __('Linked Membership', 'wp-ultimo'),
'table' => new \WP_Ultimo\List_Tables\Customers_Membership_List_Table(),
'query_filter' => function($query) {
$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(
'title' => __('Linked Customer', 'wp-ultimo'),
'table' => new \WP_Ultimo\List_Tables\Site_Customer_List_Table(),
'query_filter' => function ($query) {
},
));
$query['id'] = $this->get_object()->get_customer_id();
$this->add_list_table_widget('customer', array(
'title' => __('Linked Customer', 'wp-ultimo'),
'table' => new \WP_Ultimo\List_Tables\Site_Customer_List_Table(),
'query_filter' => function($query) {
return $query;
},
)
);
}
$query['id'] = $this->get_object()->get_customer_id();
return $query;
},
));
} // end if;
$this->add_list_table_widget('events', array(
'title' => __('Events', 'wp-ultimo'),
'table' => new \WP_Ultimo\List_Tables\Inside_Events_List_Table(),
'query_filter' => array($this, 'query_filter'),
));
$this->add_list_table_widget(
'events',
array(
'title' => __('Events', 'wp-ultimo'),
'table' => new \WP_Ultimo\List_Tables\Inside_Events_List_Table(),
'query_filter' => array($this, 'query_filter'),
)
);
$membership_selected = $this->get_object()->get_membership() ? $this->get_object()->get_membership()->to_search_results() : '';
$template_selected = $this->get_object()->get_template() ? $this->get_object()->get_template()->to_search_results() : '';
$this->add_fields_widget('save', array(
'html_attr' => array(
'data-wu-app' => 'site_type',
'data-state' => json_encode(array(
'type' => $this->get_object()->get_type(),
'original_membership_id' => $this->get_object()->get_membership_id(),
'membership_id' => $this->get_object()->get_membership_id(),
)),
),
'fields' => array(
// Fields for price
'type_main' => array(
'type' => 'text-display',
'title' => __('Site Type', 'wp-ultimo'),
'display_value' => __('Main Site', 'wp-ultimo'),
'tooltip' => __('You can\'t change the main site type.', 'wp-ultimo'),
'wrapper_html_attr' => array(
'v-cloak' => '1',
'v-show' => 'type === "main"',
$this->add_fields_widget(
'save',
array(
'html_attr' => array(
'data-wu-app' => 'site_type',
'data-state' => json_encode(
array(
'type' => $this->get_object()->get_type(),
'original_membership_id' => $this->get_object()->get_membership_id(),
'membership_id' => $this->get_object()->get_membership_id(),
)
),
),
'type' => array(
'type' => 'select',
'title' => __('Site Type', 'wp-ultimo'),
'placeholder' => __('Select Site Type', 'wp-ultimo'),
'desc' => __('Different site types have different options and settings.', 'wp-ultimo'),
'value' => $this->get_object()->get_type(),
'tooltip' => '',
'options' => array(
'default' => __('Regular WordPress', 'wp-ultimo'),
'site_template' => __('Site Template', 'wp-ultimo'),
'customer_owned' => __('Customer-owned', 'wp-ultimo'),
'fields' => array(
// Fields for price
'type_main' => array(
'type' => 'text-display',
'title' => __('Site Type', 'wp-ultimo'),
'display_value' => __('Main Site', 'wp-ultimo'),
'tooltip' => __('You can\'t change the main site type.', 'wp-ultimo'),
'wrapper_html_attr' => array(
'v-cloak' => '1',
'v-show' => 'type === "main"',
),
),
'html_attr' => array(
'v-model' => 'type',
'type' => array(
'type' => 'select',
'title' => __('Site Type', 'wp-ultimo'),
'placeholder' => __('Select Site Type', 'wp-ultimo'),
'desc' => __('Different site types have different options and settings.', 'wp-ultimo'),
'value' => $this->get_object()->get_type(),
'tooltip' => '',
'options' => array(
'default' => __('Regular WordPress', 'wp-ultimo'),
'site_template' => __('Site Template', 'wp-ultimo'),
'customer_owned' => __('Customer-owned', 'wp-ultimo'),
),
'html_attr' => array(
'v-model' => 'type',
),
'wrapper_html_attr' => array(
'v-cloak' => '1',
'v-show' => 'type !== "main"',
),
),
'wrapper_html_attr' => array(
'v-cloak' => '1',
'v-show' => 'type !== "main"',
'categories' => array(
'type' => 'select',
'title' => __('Template Categories', 'wp-ultimo'),
'placeholder' => __('e.g.: Landing Page, Health...', 'wp-ultimo'),
'desc' => __('Customers will be able to filter by categories during signup.', 'wp-ultimo'),
'value' => $this->get_object()->get_categories(),
'options' => Site::get_all_categories(),
'html_attr' => array(
'data-selectize-categories' => 1,
'multiple' => 1,
),
'wrapper_html_attr' => array(
'v-show' => "type === 'site_template'",
'v-cloak' => '1',
),
),
'membership_id' => array(
'type' => 'model',
'title' => __('Associated Membership', 'wp-ultimo'),
'placeholder' => __('Search Membership...', 'wp-ultimo'),
'desc' => __('The membership that owns this site.', 'wp-ultimo'),
'value' => $this->get_object()->get_membership_id(),
'tooltip' => '',
'wrapper_html_attr' => array(
'v-show' => "type === 'customer_owned'",
'v-cloak' => 1,
),
'html_attr' => array(
'data-model' => 'membership',
'data-value-field' => 'id',
'data-label-field' => 'reference_code',
'data-search-field' => 'reference_code',
'data-max-items' => 1,
'data-selected' => json_encode($membership_selected),
),
),
'transfer_note' => array(
'type' => 'note',
'desc' => __('Changing the membership will transfer the site and all its assets to the new membership.', 'wp-ultimo'),
'classes' => 'wu-p-2 wu-bg-red-100 wu-text-red-600 wu-rounded wu-w-full',
'wrapper_html_attr' => array(
'v-show' => '(original_membership_id != membership_id) && membership_id',
'v-cloak' => '1',
),
),
'submit_save' => array(
'type' => 'submit',
'title' => __('Save Site', 'wp-ultimo'),
'placeholder' => __('Save Site', 'wp-ultimo'),
'value' => 'save',
'classes' => 'button button-primary wu-w-full',
'wrapper_html_attr' => array(
'v-show' => 'original_membership_id == membership_id || !membership_id',
'v-cloak' => 1,
),
),
'transfer' => array(
'type' => 'link',
'display_value' => __('Transfer Site', 'wp-ultimo'),
'wrapper_classes' => 'wu-bg-gray-200',
'classes' => 'button wubox wu-w-full wu-text-center',
'wrapper_html_attr' => array(
'v-show' => 'original_membership_id != membership_id && membership_id',
'v-cloak' => '1',
),
'html_attr' => array(
'v-bind:href' => "'" . wu_get_form_url(
'transfer_site',
array(
'id' => $this->get_object()->get_id(),
'target_membership_id' => '',
)
) . "=' + membership_id",
'title' => __('Transfer Site', 'wp-ultimo'),
),
),
),
'categories' => array(
'type' => 'select',
'title' => __('Template Categories', 'wp-ultimo'),
'placeholder' => __('e.g.: Landing Page, Health...', 'wp-ultimo'),
'desc' => __('Customers will be able to filter by categories during signup.', 'wp-ultimo'),
'value' => $this->get_object()->get_categories(),
'options' => Site::get_all_categories(),
'html_attr' => array(
'data-selectize-categories' => 1,
'multiple' => 1,
),
'wrapper_html_attr' => array(
'v-show' => "type === 'site_template'",
'v-cloak' => '1',
),
),
'membership_id' => array(
'type' => 'model',
'title' => __('Associated Membership', 'wp-ultimo'),
'placeholder' => __('Search Membership...', 'wp-ultimo'),
'desc' => __('The membership that owns this site.', 'wp-ultimo'),
'value' => $this->get_object()->get_membership_id(),
'tooltip' => '',
'wrapper_html_attr' => array(
'v-show' => "type === 'customer_owned'",
'v-cloak' => 1,
),
'html_attr' => array(
'data-model' => 'membership',
'data-value-field' => 'id',
'data-label-field' => 'reference_code',
'data-search-field' => 'reference_code',
'data-max-items' => 1,
'data-selected' => json_encode($membership_selected),
),
),
'transfer_note' => array(
'type' => 'note',
'desc' => __('Changing the membership will transfer the site and all its assets to the new membership.', 'wp-ultimo'),
'classes' => 'wu-p-2 wu-bg-red-100 wu-text-red-600 wu-rounded wu-w-full',
'wrapper_html_attr' => array(
'v-show' => '(original_membership_id != membership_id) && membership_id',
'v-cloak' => '1',
),
),
'submit_save' => array(
'type' => 'submit',
'title' => __('Save Site', 'wp-ultimo'),
'placeholder' => __('Save Site', 'wp-ultimo'),
'value' => 'save',
'classes' => 'button button-primary wu-w-full',
'wrapper_html_attr' => array(
'v-show' => 'original_membership_id == membership_id || !membership_id',
'v-cloak' => 1,
),
),
'transfer' => array(
'type' => 'link',
'display_value' => __('Transfer Site', 'wp-ultimo'),
'wrapper_classes' => 'wu-bg-gray-200',
'classes' => 'button wubox wu-w-full wu-text-center',
'wrapper_html_attr' => array(
'v-show' => 'original_membership_id != membership_id && membership_id',
'v-cloak' => '1',
),
'html_attr' => array(
'v-bind:href' => "'" . wu_get_form_url('transfer_site', array(
'id' => $this->get_object()->get_id(),
'target_membership_id' => '',
)) . "=' + membership_id",
'title' => __('Transfer Site', 'wp-ultimo'),
),
),
),
));
)
);
$this->add_fields_widget('active', array(
'title' => __('Active', 'wp-ultimo'),
'fields' => array(
'active' => array(
'type' => 'toggle',
'title' => __('Active', 'wp-ultimo'),
'desc' => __('Use this option to manually enable or disable this site.', 'wp-ultimo'),
'value' => $this->get_object()->is_active(),
$this->add_fields_widget(
'active',
array(
'title' => __('Active', 'wp-ultimo'),
'fields' => array(
'active' => array(
'type' => 'toggle',
'title' => __('Active', 'wp-ultimo'),
'desc' => __('Use this option to manually enable or disable this site.', 'wp-ultimo'),
'value' => $this->get_object()->is_active(),
),
),
),
));
)
);
$this->add_fields_widget('image', array(
'title' => __('Site Image', 'wp-ultimo'),
'fields' => array(
'featured_image_id' => array(
'type' => 'image',
'stacked' => true,
'title' => __('Site Image', 'wp-ultimo'),
'desc' => __('This image is used on lists of sites and other places. It can be automatically generated by the screenshot scraper.', 'wp-ultimo'),
'value' => $this->get_object()->get_featured_image_id(),
'img' => $this->get_object()->get_featured_image(),
$this->add_fields_widget(
'image',
array(
'title' => __('Site Image', 'wp-ultimo'),
'fields' => array(
'featured_image_id' => array(
'type' => 'image',
'stacked' => true,
'title' => __('Site Image', 'wp-ultimo'),
'desc' => __('This image is used on lists of sites and other places. It can be automatically generated by the screenshot scraper.', 'wp-ultimo'),
'value' => $this->get_object()->get_featured_image_id(),
'img' => $this->get_object()->get_featured_image(),
),
'scraper_note' => array(
'type' => 'note',
'desc' => __('You need to save the site for the change to take effect.', 'wp-ultimo'),
'wrapper_classes' => 'wu-hidden wu-scraper-note',
),
'scraper_error' => array(
'type' => 'note',
'desc' => '<span class="wu-scraper-error-message wu-p-2 wu-bg-red-100 wu-text-red-600 wu-rounded wu-block"></span>',
'wrapper_classes' => 'wu-hidden wu-scraper-error',
),
'scraper_message' => array(
'type' => 'note',
'desc' => sprintf('<span class="wu-p-2 wu-bg-red-100 wu-text-red-600 wu-rounded wu-block">%s</span>', __('We detected that this network might be running locally. If that\'s the case, WP Multisite WaaS will not be able to take a screenshot of the site. A site needs to be publicly available to the outside world in order for this feature to work.', 'wp-ultimo')),
'wrapper_classes' => \WP_Ultimo\Domain_Mapping\Helper::is_development_mode() ? '' : 'wu-hidden',
),
'scraper' => array(
'type' => 'submit',
'title' => __('Take Screenshot', 'wp-ultimo'),
'title' => __('Take Screenshot', 'wp-ultimo'),
'classes' => 'button wu-w-full',
),
),
'scraper_note' => array(
'type' => 'note',
'desc' => __('You need to save the site for the change to take effect.', 'wp-ultimo'),
'wrapper_classes' => 'wu-hidden wu-scraper-note',
),
'scraper_error' => array(
'type' => 'note',
'desc' => '<span class="wu-scraper-error-message wu-p-2 wu-bg-red-100 wu-text-red-600 wu-rounded wu-block"></span>',
'wrapper_classes' => 'wu-hidden wu-scraper-error',
),
'scraper_message' => array(
'type' => 'note',
'desc' => sprintf('<span class="wu-p-2 wu-bg-red-100 wu-text-red-600 wu-rounded wu-block">%s</span>', __('We detected that this network might be running locally. If that\'s the case, WP Multisite WaaS will not be able to take a screenshot of the site. A site needs to be publicly available to the outside world in order for this feature to work.', 'wp-ultimo')),
'wrapper_classes' => \WP_Ultimo\Domain_Mapping\Helper::is_development_mode() ? '' : 'wu-hidden',
),
'scraper' => array(
'type' => 'submit',
'title' => __('Take Screenshot', 'wp-ultimo'),
'title' => __('Take Screenshot', 'wp-ultimo'),
'classes' => 'button wu-w-full',
),
),
));
} // end register_widgets;
)
);
}
/**
* Returns the list of sections and its fields for the site page.
@ -572,8 +605,7 @@ class Site_Edit_Admin_Page extends Edit_Admin_Page {
$sections = apply_filters('wu_site_options_sections', $sections, $this->get_object());
return $sections;
} // end get_site_option_sections;
}
/**
* Returns the title of the page.
@ -584,8 +616,7 @@ class Site_Edit_Admin_Page extends Edit_Admin_Page {
public function get_title() {
return $this->edit ? __('Edit Site', 'wp-ultimo') : __('Add new Site', 'wp-ultimo');
} // end get_title;
}
/**
* Returns the title of menu for this page.
@ -596,8 +627,7 @@ class Site_Edit_Admin_Page extends Edit_Admin_Page {
public function get_menu_title() {
return __('Edit Site', 'wp-ultimo');
} // end get_menu_title;
}
/**
* Returns the action links for that page.
@ -624,8 +654,7 @@ class Site_Edit_Admin_Page extends Edit_Admin_Page {
'icon' => 'dashboard',
),
);
} // end action_links;
}
/**
* Returns the labels to be used on the admin page.
@ -646,8 +675,7 @@ class Site_Edit_Admin_Page extends Edit_Admin_Page {
'delete_button_label' => __('Delete Site', 'wp-ultimo'),
'delete_description' => __('Be careful. This action is irreversible.', 'wp-ultimo'),
);
} // end get_labels;
}
/**
* Filters the list table to return only relevant events.
@ -664,8 +692,7 @@ class Site_Edit_Admin_Page extends Edit_Admin_Page {
);
return array_merge($args, $extra_args);
} // end domain_query_filter;
}
/**
* Filters the list table to return only relevant events.
@ -683,8 +710,7 @@ class Site_Edit_Admin_Page extends Edit_Admin_Page {
);
return array_merge($args, $extra_args);
} // end query_filter;
}
/**
* Returns the object being edit at the moment.
@ -695,28 +721,23 @@ class Site_Edit_Admin_Page extends Edit_Admin_Page {
public function get_object() {
if ($this->object !== null) {
return $this->object;
} // end if;
}
$item_id = wu_request('id', 0);
$item = wu_get_site($item_id);
if (!$item) {
if ( ! $item) {
wp_redirect(wu_network_admin_url('wp-ultimo-sites'));
exit;
} // end if;
}
$this->object = $item;
return $this->object;
} // end get_object;
}
/**
* Sites have titles.
*
@ -725,8 +746,7 @@ class Site_Edit_Admin_Page extends Edit_Admin_Page {
public function has_title(): bool {
return true;
} // end has_title;
}
/**
* Should implement the processes necessary to save the changes made to the object.
@ -739,14 +759,10 @@ class Site_Edit_Admin_Page extends Edit_Admin_Page {
$_POST['categories'] = wu_get_isset($_POST, 'categories', array());
if ($_POST['type'] !== Site_Type::CUSTOMER_OWNED) {
$_POST['membership_id'] = false;
$_POST['customer_id'] = false;
} // end if;
}
return parent::handle_save();
} // end handle_save;
} // end class Site_Edit_Admin_Page;
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

File diff suppressed because it is too large Load Diff

View File

@ -38,16 +38,13 @@ class Checkout_Pages {
add_filter('lostpassword_redirect', array($this, 'filter_lost_password_redirect'));
if (is_main_site()) {
add_action('before_signup_header', array($this, 'redirect_to_registration_page'));
$use_custom_login = wu_get_setting('enable_custom_login_page', false);
if (!$use_custom_login) {
if ( ! $use_custom_login) {
return;
} // end if;
}
add_filter('login_url', array($this, 'filter_login_url'), 10, 3);
@ -73,10 +70,8 @@ class Checkout_Pages {
add_action('post_submitbox_misc_actions', array($this, 'render_compat_mode_setting'));
add_action('save_post', array($this, 'handle_compat_mode_setting'));
} // end if;
} // end init;
}
}
/**
* Filters the lost password redirect URL.
@ -85,17 +80,14 @@ class Checkout_Pages {
*/
public function filter_lost_password_redirect(string $redirect_to): string {
if (!empty($redirect_to)) {
if ( ! empty($redirect_to)) {
return $redirect_to;
} // end if;
}
$redirect_to = add_query_arg('checkemail', 'confirm', wp_login_url());
return $redirect_to;
} // end filter_lost_password_redirect;
}
/**
* Renders the compat mode option for pages and posts.
@ -127,8 +119,7 @@ class Checkout_Pages {
<?php
// phpcs:enable
} // end render_compat_mode_setting;
}
/**
* Handles saving the compat mode switch on posts.
@ -141,34 +132,23 @@ class Checkout_Pages {
public function handle_compat_mode_setting($post_id) {
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
return;
}
} // end if;
if (!isset($_POST['_wu_force_compat']) || !wp_verify_nonce($_POST['_wu_force_compat'], '_wu_force_compat_' . $post_id)) {
if ( ! isset($_POST['_wu_force_compat']) || ! wp_verify_nonce($_POST['_wu_force_compat'], '_wu_force_compat_' . $post_id)) {
return;
}
} // end if;
if (!current_user_can('edit_post', $post_id)) {
if ( ! current_user_can('edit_post', $post_id)) {
return;
} // end if;
}
if (isset($_POST['_wu_force_elements_loading'])) {
update_post_meta($post_id, '_wu_force_elements_loading', $_POST['_wu_force_elements_loading']);
} else {
delete_post_meta($post_id, '_wu_force_elements_loading');
} // end if;
} // end handle_compat_mode_setting;
}
}
/**
* Replace wp-login.php in email URLs.
@ -184,24 +164,19 @@ class Checkout_Pages {
* wp-login.php in it to begin with.
*/
if (strpos($url, 'wp-login.php') === false) {
return $url;
} // end if;
}
$post_id = wu_get_setting('default_login_page', 0);
$post = get_post($post_id);
if ($post) {
$url = str_replace('wp-login.php', $post->post_name, $url);
} // end if;
}
return $url;
} // end maybe_change_wp_login_on_urls;
}
/**
* Get an error message.
@ -215,11 +190,11 @@ class Checkout_Pages {
public function get_error_message($error_code, $username = '') {
$messages = array(
'incorrect_password' => sprintf(__( '<strong>Error:</strong> The password you entered is incorrect.', 'wp-ultimo')),
'incorrect_password' => sprintf(__('<strong>Error:</strong> The password you entered is incorrect.', 'wp-ultimo')),
// From here we are using the same messages as WordPress core.
'expired' => __('Your session has expired. Please log in to continue where you left off.'),
'confirm' => sprintf(__('Check your email for the confirmation link, then visit the <a href="%s">login page</a>.'), wp_login_url()),
'registered' => sprintf(__( 'Registration complete. Please check your email, then visit the <a href="%s">login page</a>.' ), wp_login_url()),
'registered' => sprintf(__('Registration complete. Please check your email, then visit the <a href="%s">login page</a>.'), wp_login_url()),
'loggedout' => __('You are now logged out.'),
'registerdisabled' => __('<strong>Error:</strong> User registration is currently not allowed.'),
'empty_username' => __('<strong>Error:</strong> The username field is empty.'),
@ -243,8 +218,7 @@ class Checkout_Pages {
$messages = apply_filters('wu_checkout_pages_error_messages', $messages);
return wu_get_isset($messages, $error_code, __('Something went wrong', 'wp-ultimo'));
} // end get_error_message;
}
/**
* Handle password reset errors.
@ -260,20 +234,20 @@ class Checkout_Pages {
public function maybe_handle_password_reset_errors($errors) {
if ($errors->has_errors()) {
$url = add_query_arg(array(
'action' => wu_request('action', ''),
'user_login' => wu_request('user_login', ''),
'error' => $errors->get_error_code(),
), wp_login_url());
$url = add_query_arg(
array(
'action' => wu_request('action', ''),
'user_login' => wu_request('user_login', ''),
'error' => $errors->get_error_code(),
),
wp_login_url()
);
wp_redirect($url);
exit;
} // end if;
} // end maybe_handle_password_reset_errors;
}
}
/**
* Maybe redirects users to the confirm screen.
@ -289,14 +263,11 @@ class Checkout_Pages {
public function maybe_redirect_to_confirm_screen() {
if (wu_request('redirect_to')) {
wp_redirect(wu_request('redirect_to'));
exit;
} // end if;
} // end maybe_redirect_to_confirm_screen;
}
}
/**
* Replace the reset password link, if necessary.
@ -311,11 +282,9 @@ class Checkout_Pages {
*/
public function replace_reset_password_link($message, $key, $user_login, $user_data) {
if (!is_main_site()) {
if ( ! is_main_site()) {
return $message;
} // end if;
}
$results = array();
@ -330,28 +299,27 @@ class Checkout_Pages {
$switched_locale = switch_to_locale($locale);
$new_url = add_query_arg(array(
'action' => 'rp',
'key' => $key,
'login' => rawurlencode($user_login),
'wp_lang' => $locale
), wp_login_url());
$new_url = add_query_arg(
array(
'action' => 'rp',
'key' => $key,
'login' => rawurlencode($user_login),
'wp_lang' => $locale,
),
wp_login_url()
);
$new_url = set_url_scheme($new_url, null);
$message = str_replace($results[0], $new_url, $message);
} // end if;
}
if ($switched_locale) {
restore_previous_locale();
} // end if;
}
return $message;
} // end replace_reset_password_link;
}
/**
* Redirect logged users when they reach the login page.
@ -363,25 +331,19 @@ class Checkout_Pages {
global $post;
if (!is_user_logged_in()) {
if ( ! is_user_logged_in()) {
return;
} // end if;
}
$custom_login_page = $this->get_signup_page('login');
if (empty($custom_login_page) || empty($post)) {
return;
} // end if;
}
if ($custom_login_page->ID !== $post->ID) {
return;
} // end if;
}
/**
* Create an exclusion list of parameters that prevent the auto-redirect.
@ -392,24 +354,26 @@ class Checkout_Pages {
* @since 2.0.4
* @return array
*/
$exclusion_list = apply_filters('wu_maybe_redirect_to_admin_panel_exclusion_list', array(
'preview', // WordPress Preview
'ct_builder', // Oxygen Builder
'fl_builder', // Beaver Builder
'elementor-preview', // Elementor
'brizy-edit', // Brizy
'brizy-edit-iframe', // Brizy
), $custom_login_page, $post, $this);
$exclusion_list = apply_filters(
'wu_maybe_redirect_to_admin_panel_exclusion_list',
array(
'preview', // WordPress Preview
'ct_builder', // Oxygen Builder
'fl_builder', // Beaver Builder
'elementor-preview', // Elementor
'brizy-edit', // Brizy
'brizy-edit-iframe', // Brizy
),
$custom_login_page,
$post,
$this
);
foreach ($exclusion_list as $exclusion_param) {
if (wu_request($exclusion_param, null) !== null) {
return;
} // end if;
} // end foreach;
}
}
$user = wp_get_current_user();
@ -418,34 +382,23 @@ class Checkout_Pages {
$redirect_to = $active_blog ? get_admin_url($active_blog->blog_id) : false;
if (isset($_GET['redirect_to'])) {
$redirect_to = $_GET['redirect_to'];
} elseif (is_multisite() && !get_active_blog_for_user($user->ID) && !is_super_admin($user->ID)) {
} elseif (is_multisite() && ! get_active_blog_for_user($user->ID) && ! is_super_admin($user->ID)) {
$redirect_to = user_admin_url();
} elseif (is_multisite() && !$user->has_cap('read')) {
} elseif (is_multisite() && ! $user->has_cap('read')) {
$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();
}
} // end if;
if (!$redirect_to) {
if ( ! $redirect_to) {
return;
} // end if;
}
wp_redirect($redirect_to);
exit;
} // end maybe_redirect_to_admin_panel;
}
/**
* Adds the unverified email account error message.
@ -460,7 +413,6 @@ class Checkout_Pages {
public function add_verify_email_notice($payment, $membership, $customer) {
if ($payment->get_total() == 0 && $customer->get_email_verification() === 'pending') {
$html = '<div class="wu-p-4 wu-bg-yellow-200 wu-mb-2 wu-text-yellow-700 wu-rounded">%s</div>';
$message = __('Your email address is not yet verified. Your site <strong>will only be activated</strong> after your email address is verified. Check your inbox and verify your email address.', 'wp-ultimo');
@ -468,10 +420,8 @@ class Checkout_Pages {
$message .= sprintf('<br><a href="#" class="wu-resend-verification-email wu-text-gray-700">%s</a>', __('Resend verification email &rarr;', 'wp-ultimo'));
printf($html, $message);
} // end if;
} // end add_verify_email_notice;
}
}
/**
* Check if we should obfuscate the login URL.
@ -483,44 +433,33 @@ class Checkout_Pages {
$use_custom_login = wu_get_setting('enable_custom_login_page', false);
if (!$use_custom_login) {
if ( ! $use_custom_login) {
return;
} // end if;
}
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
return;
} // end if;
}
if (wu_request('interim-login')) {
return;
} // end if;
}
if (wu_request('action') === 'logout') {
return;
} // end if;
}
$new_login_url = $this->get_page_url('login');
if (!$new_login_url) {
if ( ! $new_login_url) {
return;
} // end if;
}
$should_obfuscate = wu_get_setting('obfuscate_original_login_url', 1);
$bypass_obfuscation = wu_request('wu_bypass_obfuscation');
if ($should_obfuscate && !$bypass_obfuscation) {
if ($should_obfuscate && ! $bypass_obfuscation) {
status_header(404);
nocache_headers();
@ -529,19 +468,15 @@ class Checkout_Pages {
$wp_query->set_404();
include(get_404_template());
include get_404_template();
die;
} else {
wp_redirect($new_login_url);
exit;
} // end if;
} // end maybe_obfuscate_login_url;
}
}
/**
* Redirects the customers to the registration page, when one is used.
@ -554,14 +489,11 @@ class Checkout_Pages {
$registration_url = $this->get_page_url('register');
if ($registration_url) {
wp_redirect($registration_url);
exit;
} // end if;
} // end redirect_to_registration_page;
}
}
/**
* Filters the login URL if necessary.
@ -578,19 +510,15 @@ class Checkout_Pages {
/**
* 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;
} // end if;
}
$function_caller = wu_get_function_caller(5);
if ($function_caller === 'wp_auth_check_html') {
return $login_url;
} // end if;
}
$params = array();
@ -600,33 +528,24 @@ class Checkout_Pages {
$new_login_url = $this->get_page_url('login');
if (!$new_login_url) {
if ( ! $new_login_url) {
return $login_url;
} // end if;
}
if ($params) {
$new_login_url = add_query_arg($params, $new_login_url);
} // end if;
}
if ($redirect) {
$new_login_url = add_query_arg('redirect_to', urlencode( $redirect ), $new_login_url);
} // end if;
$new_login_url = add_query_arg('redirect_to', urlencode($redirect), $new_login_url);
}
if ($force_reauth) {
$new_login_url = add_query_arg('reauth', 1, $new_login_url);
} // end if;
}
return $new_login_url;
} // end filter_login_url;
}
/**
* Returns the ID of the pages being used for each WP Multisite WaaS purpose.
@ -643,52 +562,45 @@ class Checkout_Pages {
'block_frontend' => wu_get_setting('default_block_frontend_page', false),
'new_site' => wu_get_setting('default_new_site_page', false),
);
} // end get_signup_pages;
/**
* Returns the WP_Post object for one of the pages.
*
* @since 2.0.0
*
* @param string $page The slug of the page to retrieve.
* @return \WP_Post|false
*/
public function get_signup_page($page) {
}
/**
* Returns the WP_Post object for one of the pages.
*
* @since 2.0.0
*
* @param string $page The slug of the page to retrieve.
* @return \WP_Post|false
*/
public function get_signup_page($page) {
$pages = $this->get_signup_pages();
$page_id = wu_get_isset($pages, $page);
if (!$page_id) {
if ( ! $page_id) {
return false;
} // end if;
}
return get_blog_post(wu_get_main_site_id(), $page_id);
} // end get_signup_page;
/**
* Returns the URL for a particular page type.
*
* @since 2.0.0
*
* @param string $page_slug The signup page to get.
* @return string|false
*/
public function get_page_url($page_slug = 'login') {
}
/**
* Returns the URL for a particular page type.
*
* @since 2.0.0
*
* @param string $page_slug The signup page to get.
* @return string|false
*/
public function get_page_url($page_slug = 'login') {
$page = $this->get_signup_page($page_slug);
if (!$page) {
if ( ! $page) {
return false;
} // end if;
}
return wu_switch_blog_and_run(fn() => get_the_permalink($page));
} // end get_page_url;
}
/**
* Tags the WP Multisite WaaS pages on the main site.
@ -701,11 +613,9 @@ class Checkout_Pages {
*/
public function add_wp_ultimo_status_annotation($states, $post) {
if (!is_main_site()) {
if ( ! is_main_site()) {
return $states;
} // end if;
}
$labels = array(
'register' => __('WP Multisite WaaS - Register Page', 'wp-ultimo'),
@ -718,16 +628,13 @@ class Checkout_Pages {
$pages = array_map('absint', $this->get_signup_pages());
if (in_array($post->ID, $pages, true)) {
$key = array_search($post->ID, $pages, true);
$states['wp_ultimo_page'] = wu_get_isset($labels, $key);
} // end if;
}
return $states;
} // end add_wp_ultimo_status_annotation;
}
/**
* Renders the confirmation page.
@ -740,11 +647,12 @@ class Checkout_Pages {
*/
public function render_confirmation_page($atts, $content = null) {
return wu_get_template_contents('checkout/confirmation', array(
'errors' => Checkout::get_instance()->errors,
'membership' => wu_get_membership_by_hash(wu_request('membership')),
));
} // end render_confirmation_page;
} // end class Checkout_Pages;
return wu_get_template_contents(
'checkout/confirmation',
array(
'errors' => Checkout::get_instance()->errors,
'membership' => wu_get_membership_by_hash(wu_request('membership')),
)
);
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

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